aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/hw/xfree86
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2011-10-10 17:43:39 +0200
committerReinhard Tartler <siretart@tauware.de>2011-10-10 17:43:39 +0200
commitf4092abdf94af6a99aff944d6264bc1284e8bdd4 (patch)
tree2ac1c9cc16ceb93edb2c4382c088dac5aeafdf0f /nx-X11/programs/Xserver/hw/xfree86
parenta840692edc9c6d19cd7c057f68e39c7d95eb767d (diff)
downloadnx-libs-f4092abdf94af6a99aff944d6264bc1284e8bdd4.tar.gz
nx-libs-f4092abdf94af6a99aff944d6264bc1284e8bdd4.tar.bz2
nx-libs-f4092abdf94af6a99aff944d6264bc1284e8bdd4.zip
Imported nx-X11-3.1.0-1.tar.gznx-X11/3.1.0-1
Summary: Imported nx-X11-3.1.0-1.tar.gz Keywords: Imported nx-X11-3.1.0-1.tar.gz into Git repository
Diffstat (limited to 'nx-X11/programs/Xserver/hw/xfree86')
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/Imakefile275
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/atKeynames.h298
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/compiler.h1863
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/fourcc.h161
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/modeline2c.pl110
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/scoasm.h143
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86.h447
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86AutoConfig.c368
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Bus.c3317
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Bus.h162
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Config.c2740
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Config.h63
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Configure.c1049
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Cursor.c788
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86DGA.c1267
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86DPMS.c222
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Debug.c197
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86DefModes.c160
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86DoProbe.c129
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86DoScanPci.c130
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Events.c1865
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Globals.c254
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Helper.c2983
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86InPriv.h48
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Init.c2035
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Io.c507
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Kbd.c395
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdBSD.c1266
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdLnx.c651
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdMach.c317
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Keymap.h455
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86MiscExt.c656
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Mode.c2185
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Module.h226
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Opt.h114
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Option.c884
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86PM.c225
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86PciInfo.h726
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Priv.h228
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Privstr.h234
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86RandR.c438
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Resources.h140
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Versions.c81
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86VidMode.c722
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86XKB.c82
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Xinput.c1513
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86Xinput.h220
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86cmap.c1123
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86cmap.h76
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86fbBus.c97
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86fbman.c1445
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86fbman.h227
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86isaBus.c142
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86noBus.c75
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86pciBus.c3506
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86pciBus.h99
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86sbusBus.c709
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86sbusBus.h98
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86str.h1140
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86xv.c2050
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86xv.h271
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86xvmc.c243
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86xvmc.h164
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xf86xvpriv.h86
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xisb.c180
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xisb.h64
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/common/xorgHelper.c24
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/Imakefile130
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/README.OS-lib506
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/assyntax.h753
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile242
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c735
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c690
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsdResource.c194
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_KbdMap.c1087
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_VTsw.c96
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_apm.c141
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_axp.c73
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_ev56.c91
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c738
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_io.c294
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_jstk.c189
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.c573
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.h5
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kmod.c31
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c203
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_mouse.c792
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/drm/Imakefile63
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c999
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/Imakefile10
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/data.c95
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/descr.c76
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/parse.c404
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usage.c199
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb.3191
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb.h95
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb_hid_usages1079
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usbvar.h34
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/memrange.h72
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/ppc_video.c141
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/sparc64_video.c113
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/Imakefile46
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_init.c156
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_io.c110
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_mouse.c34
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_video.c182
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.c470
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.h42
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Imakefile165
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Pci.c1453
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Pci.h449
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Sbus.c637
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/altixPCI.c120
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/altixPCI.h20
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/axpPci.c478
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.c64
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.h42
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/freebsdPci.c171
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/ix86Pci.c704
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c894
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/netbsdPci.c132
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c311
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/sparcPci.c1052
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/xf86Pci.h807
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/xf86Sbus.h70
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.c1133
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.h40
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/Imakefile35
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/bios_DGmmap.c70
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_init.c182
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_io.c96
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_kbd.c120
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_kbdEv.c47
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_tty.c175
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_video.c441
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/Imakefile40
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/bios_mmap.c95
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_init.c90
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_io.c139
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_mouse.c300
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_video.c181
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/int10Defines.h90
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/Imakefile142
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/Imakefile64
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c60
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile77
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c649
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile55
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c302
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile86
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx.h55
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c291
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_KbdMap.c606
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c170
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c371
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c192
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c200
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c151
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c291
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ia64.c74
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c415
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c275
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c188
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c559
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.h5
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c113
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c206
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c230
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c1169
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/Imakefile62
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_init.c193
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_io.c166
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mmap.c73
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mouse.c34
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_noinline.c178
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.S70
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.c52
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c711
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.S153
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.c413
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/Delay.c44
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/IODelay.S53
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/IODelay.c28
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/Imakefile54
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/PortIO.S57
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.S108
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.c114
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/xf86_IlHack.c19
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/misc/xf86_Util.c96
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/nto/Imakefile37
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/nto/README29
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_init.c104
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_io.c118
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_ioperm.c48
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_kbdEv.c53
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_mouse.c210
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_video.c170
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/Imakefile45
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/README78
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/int10/Imakefile110
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/int10/os2.c452
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_VTsw.c340
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_bios.c143
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_diag.c263
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_init.c244
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_io.c257
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c140
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_kbd.c158
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_kbdEv.c511
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_mouse.c653
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_select.c497
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_select.h62
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_serial.c517
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_stubs.c403
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_video.c241
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/Imakefile48
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_devs.c126
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_init.c473
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_map.c239
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_mouse.c60
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_pci.c1072
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_ppc.c251
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/Imakefile37
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_VTsw.c116
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_init.c175
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_io.c110
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_kbd.c104
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_mouse.c267
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_select.c75
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_utils.c30
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_video.c183
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/Imakefile56
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/VTsw_sco.c119
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_KbdMap.c304
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_init.c296
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_io.c269
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_iop.c136
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_kbd.c530
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_kbd.h20
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_mouse.c261
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_video.c296
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/VTsw_noop.c56
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/VTsw_usl.c92
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/agp_noop.c107
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/at_scancode.c132
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/bios_devmem.c77
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/bios_mmap.c164
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ia64Pci.c244
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ia64Pci.h46
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/inout.S111
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c51
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/kbd.c39
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/kmod_noop.c39
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/libc_wrapper.c2153
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/pm_noop.c48
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/posix_tty.c689
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sigio.c312
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sigiostubs.c86
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/stdPci.c52
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/stdResource.c182
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/std_kbdEv.c50
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sysv_kbd.c106
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/vidmem.c300
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/xf86Axp.c50
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/shared/xf86Axp.h36
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/Imakefile119
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/agpgart.h109
-rwxr-xr-xnx-X11/programs/Xserver/hw/xfree86/os-support/sunos/find_deps.pl150
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-amd64.S73
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-ia32.S73
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-sparcv8plus.S144
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_agp.c339
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_bios.c104
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_init.c393
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_inout.s124
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_io.c160
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.c662
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.h72
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbdEv.c892
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_mouse.c719
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c237
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/Imakefile58
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_init.c254
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_io.c78
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_mouse.c64
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c369
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/xqueue.c543
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/xqueue.h12
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/Imakefile40
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_KbdMap.c304
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_init.c359
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_io.c172
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_iop.c108
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.c456
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.h14
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_mouse.c181
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_video.c111
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_vtsw.c97
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.c360
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.h9
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSKbd.h133
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSmouse.h295
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSpriv.h57
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_OSlib.h759
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h277
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h354
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_libc.h726
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Configint.h226
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/DRI.c187
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Device.c403
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Extensions.c111
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Files.c295
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Flags.c525
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Imakefile51
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Input.c215
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Keyboard.c306
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Layout.c513
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Module.c261
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Monitor.c907
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Pointer.c236
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Screen.c578
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Vendor.c258
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/Video.c297
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/configProcs.h132
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/cpconfig.c123
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/read.c321
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/scan.c949
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/write.c220
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/xf86Optrec.h113
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/xf86Parser.h483
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/parser/xf86tokens.h280
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/xf86Date.h38
-rw-r--r--nx-X11/programs/Xserver/hw/xfree86/xf86Version.h62
333 files changed, 113257 insertions, 0 deletions
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/common/Imakefile
new file mode 100644
index 000000000..41bc6781e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/Imakefile
@@ -0,0 +1,275 @@
+XCOMM $XConsortium: Imakefile /main/34 1996/10/27 11:05:08 kaleb $
+
+
+
+
+
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/common/Imakefile,v 3.154 2003/10/08 14:58:26 dawes Exp $
+
+
+
+#include <Server.tmpl>
+
+#ifdef i386MachArchitecture
+#ifdef GNUMachArchitecture
+ KBD = xf86Kbd
+#else
+ KBD = xf86KbdMach
+#endif /* GNUMachArchitecture */
+#else
+# if defined(i386BsdArchitecture) || defined(AlphaBsdArchitecture) \
+ || defined(OpenBSDArchitecture) || defined(NetBSDArchitecture) \
+ || defined(KFreeBSDArchitecture)
+ KBD = xf86KbdBSD
+# else
+# ifdef LinuxArchitecture
+ KBD = xf86KbdLnx
+# else
+ KBD = xf86Kbd
+# endif
+# endif
+#endif
+
+#if UseDeprecatedKeyboardDriver
+KEYBOARD_DEFS = -DUSE_DEPRECATED_KEYBOARD_DRIVER
+#endif
+
+#if defined(SparcArchitecture) || defined(Sparc64Architecture)
+ SBUSSRC = xf86sbusBus.c
+ SBUSOBJ = xf86sbusBus.o
+#endif
+
+#if BuildXKB
+ XKBDDXSRC = xf86XKB.c
+ XKBDDXOBJ = xf86XKB.o
+#endif
+
+#if BuildDebug
+ DEBUGSRC = xf86Debug.c
+ DEBUGOBJ = xf86Debug.o
+#endif
+
+#if BuildXInputExt
+ XF86_XINPUT_SRC = xf86Xinput.c xisb.c
+ XF86_XINPUT_OBJ = xf86Xinput.o xisb.o
+#endif
+
+#if BuildRandR
+ RANDRINCS = -I../../../randr
+ RANDRSRC = xf86RandR.c
+ RANDROBJ = xf86RandR.o
+#endif
+
+MODPATHDEFINES = -DDEFAULT_MODULE_PATH=\"$(MODULEDIR)\"
+LOGDEFINES = -DDEFAULT_LOGPREFIX=\"$(LOGDIRECTORY)/XLogFile.\"
+
+#if DoLoadableServer
+EXT_MODULES_DEFINES = $(GLX_DEFINES)
+#endif
+
+#if UseMemLeak
+MDEBUGDEFS = -DMEMDEBUG
+#endif
+
+#if defined(SunArchitecture) && ((OSMajorVersion == 5) && (OSMinorVersion >= 9))
+BACKTRACE_DEFS = -DHAVE_WALKCONTEXT
+#elif defined(LinuxCLibMajorVersion) && ((LinuxCLibMajorVersion == 6) && (LinuxCLibMinorVersion >= 1))
+BACKTRACE_DEFS = -DHAVE_EXECINFO_H
+#endif
+
+SRCS = \
+ xf86Configure.c \
+ xf86Bus.c \
+ xf86isaBus.c \
+ xf86pciBus.c \
+ xf86fbBus.c \
+ xf86noBus.c \
+ xf86IniExt.c \
+ xf86Config.c \
+ xf86AutoConfig.c \
+ xf86Cursor.c \
+ xf86DGA.c \
+ xf86DPMS.c \
+ xf86DefModeSet.c \
+ xf86DoProbe.c \
+ xf86DoScanPci.c \
+ xf86Events.c \
+ xf86Globals.c \
+ xf86Helper.c \
+ xf86Init.c \
+ xf86Io.c \
+ xf86MiscExt.c \
+ xf86Mode.c \
+ xf86Option.c \
+ xf86VidMode.c \
+ xf86fbman.c \
+ xf86xv.c \
+ xf86xvmc.c \
+ xf86cmap.c\
+ xf86PM.c \
+ xf86Versions.c \
+ xorgHelper.c \
+ $(DEBUGSRC) \
+ $(KBD).c \
+ $(SBUSSRC) \
+ $(XF86_XINPUT_SRC) \
+ $(XINPUT_DEV_SRCS) \
+ $(XKBDDXSRC) \
+ $(SERVERSRCS) \
+ $(RANDRSRC)
+
+OBJS = \
+ xf86Configure.o \
+ xf86Bus.o \
+ xf86isaBus.o \
+ xf86pciBus.o \
+ xf86fbBus.o \
+ xf86noBus.o \
+ xf86Config.o \
+ xf86AutoConfig.o \
+ xf86Cursor.o \
+ xf86DGA.o \
+ xf86DPMS.o \
+ xf86DefModeSet.o \
+ xf86DoProbe.o \
+ xf86DoScanPci.o \
+ xf86Events.o \
+ xf86Globals.o \
+ xf86Helper.o \
+ xf86Io.o \
+ xf86MiscExt.o \
+ xf86Mode.o \
+ xf86Option.o \
+ xf86VidMode.o \
+ xf86fbman.o \
+ xf86xv.o \
+ xf86xvmc.o \
+ xf86cmap.o\
+ xf86PM.o \
+ xf86Versions.o \
+ xorgHelper.o \
+ $(DEBUGOBJ) \
+ $(SBUSOBJ) \
+ $(XF86_XINPUT_OBJ) \
+ $(XKBDDXOBJ) \
+ $(KBD).o \
+ $(RANDROBJ)
+
+OFILES = \
+ xf86Init.o \
+ xf86IniExt.o
+
+ VGAINCLUDES = -I$(XF86SRC)/vgahw
+ INCLUDES = -I. -I$(XF86OSSRC) -I$(XF86OSSRC)/bus -I$(SERVERSRC)/mfb \
+ -I$(SERVERSRC)/mi -I$(SERVERSRC)/include -I$(SERVERSRC)/os \
+ -I$(XINCLUDESRC) -I$(SERVERSRC)/Xext -I$(EXTINCSRC) \
+ -I$(SERVERSRC)/Xi -I$(XF86SRC)/ddc -I$(XF86SRC)/i2c \
+ -I$(FONTLIBSRC)/include -I$(FONTINCSRC) \
+ -I$(XF86SRC) -I$(XF86PARSERSRC) \
+ -I$(XF86SRC)/loader $(VGAINCLUDES) -I$(XF86SRC)/rac \
+ -I$(XF86SRC)/scanpci -I$(XF86SRC)/vbe -I$(XF86SRC)/int10 \
+ -I$(XF86SRC)/ddc -I$(SERVERSRC)/render $(RANDRINCS)
+
+ OSNAME = OSName
+ OSVENDOR = OSVendor
+ OSNAMEDEF = -DOSNAME='" $(OSNAME)"' -DOSVENDOR='" $(OSVENDOR)"'
+#if defined(XorgCustomVersion) || defined(XFree86CustomVersion)
+# if defined(XorgCustomVersion)
+CUSTOMVERSION = XorgCustomVersion
+# else
+CUSTOMVERSION = XFree86CustomVersion
+# endif /* XorgCustomVersion */
+ CUSTOMVERDEF = -DXORG_CUSTOM_VERSION='$(CUSTOMVERSION)'
+#endif /* XorgCustomVersion || XFree86CustomVersion */
+#if defined(BuilderString)
+ BUILDERSTRING = BuilderString
+ BUILDERMSG = -DBUILDERSTRING='$(BUILDERSTRING)'
+#endif
+ XORGREL = XOrgReleaseString
+ XORGREL_DEF = -DXORG_RELEASE="\"$(XORGREL)\""
+#if defined(XorgDateString)
+ XORGDATE = XorgDateString
+ XORGDATE_DEF = -DXORG_DATE='$(XORGDATE)'
+#endif
+
+CONSDEFINES = XFree86ConsoleDefines
+EXP_DEFINES = -DEXPIRY_TIME=XorgServerExpiry $(EXP_FORCE_DEFINES)
+ DRIVERS = XF86CardDrivers
+ IDRIVERS = XInputDrivers
+XCONFIGDEFINES = -DPROJECTROOT='"$(PROJECTROOT)"' \
+ -DBINDIR='"$(BINDIR)"' \
+ -DDRIVERS='"$(DRIVERS)"' \
+ -DIDRIVERS='"$(IDRIVERS)"'
+XF86CONFIGFILE = XConfigFile
+XCONFIGUREDEFINES = -DXF86CONFIGFILE='"$(XF86CONFIGFILE)"'
+
+ DEFINES = $(CONSDEFINES) $(KBDDEFINES) $(EXT_DEFINES) $(OS_DEFINES) \
+ $(CONFIG_DEFINES) $(XKBDEFRULESDEFS) $(VENDORSUPPORTDEFS) \
+ $(VENDOR_DEFINES) -DXF86PM
+
+AllTarget($(OFILES))
+
+SpecialCObjectRule(xf86Bus,NullParameter,$(BUGMSG) $(VGAINCLUDES))
+SpecialCObjectRule(xf86Init,$(ICONFIGFILES),$(OSNAMEDEF) $(BUILDERMSG) $(BUGMSG) $(CUSTOMVERDEF) $(XORGREL_DEF) $(XORGDATE_DEF) $(EXT_DEFINES) $(MDEBUGDEFS) $(KEYBOARD_DEFS))
+SpecialCObjectRule(xf86Events,$(ICONFIGFILES),$(EXT_DEFINES) $(MDEBUGDEFS) $(BACKTRACE_DEFS))
+SpecialCObjectRule(xf86Globals,$(ICONFIGFILES),$(EXT_DEFINES) $(MODPATHDEFINES) $(LOGDEFINES))
+SpecialCObjectRule(xf86AutoConfig,$(ICONFIGFILES),$(XCONFIGDEFINES))
+SpecialCObjectRule(xf86Config,$(ICONFIGFILES),$(XCONFIGDEFINES) $(KEYBOARD_DEFS))
+SpecialCObjectRule(xf86Configure,$(ICONFIGFILES),$(XCONFIGUREDEFINES) $(KEYBOARD_DEFS))
+
+SpecialCObjectRule(xf86IniExt,$(ICONFIGFILES),$(EXT_DEFINES) $(EXT_MODULES_DEFINES))
+
+NormalLibraryObjectRule()
+NormalLibraryTarget(xf86,$(OBJS))
+
+LinkFile(xf86IniExt.c,$(SERVERSRC)/mi/miinitext.c)
+LinkSourceFile(xf86Version.h,..)
+LinkSourceFile(xorgVersion.h,..)
+LinkSourceFile(xf86Pci.h,$(XF86OSSRC)/bus)
+#ifdef SparcArchitecture
+LinkSourceFile(xf86Sbus.h,$(XF86OSSRC)/bus)
+#endif
+
+#if HasPerl
+MODEDEFSRCS = ../etc/vesamodes ../etc/extramodes
+
+MODEDEFS = modedefs
+
+$(MODEDEFS): $(MODEDEFSRCS)
+ RemoveFile($@)
+ cat $(MODEDEFSRCS) > $@
+
+includes:: xf86DefModeSet.c
+
+xf86DefModeSet.c: $(MODEDEFS) modeline2c.pl
+ RemoveFile($@)
+ RunPerlScript(modeline2c.pl, < $(MODEDEFS) > $@)
+
+clean::
+ RemoveFile($(MODEDEFS))
+ RemoveFile(xf86DefModeSet.c)
+#else
+LinkFile(xf86DefModeSet.c,xf86DefModes.c)
+#endif
+
+DependTarget()
+
+InstallDriverSDKNonExecFile(compiler.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(fourcc.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86Module.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86Opt.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86Pci.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86PciInfo.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86Priv.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86Privstr.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86Resources.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86Version.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xorgVersion.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86Xinput.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86cmap.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86fbman.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86str.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86xv.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86xvmc.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xisb.h,$(DRIVERSDKINCLUDEDIR))
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/atKeynames.h b/nx-X11/programs/Xserver/hw/xfree86/common/atKeynames.h
new file mode 100644
index 000000000..d37f5b0f0
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/atKeynames.h
@@ -0,0 +1,298 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/atKeynames.h,v 3.21 2003/10/09 11:43:59 pascal Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
+ * Copyright (c) 1994-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).
+ */
+
+/* $XConsortium: atKeynames.h /main/11 1996/03/09 11:17:41 kaleb $ */
+
+#ifndef _ATKEYNAMES_H
+#define _ATKEYNAMES_H
+
+#define XK_TECHNICAL
+#define XK_KATAKANA
+#include <X11/keysym.h>
+#include <X11/XF86keysym.h>
+
+#define GLYPHS_PER_KEY 4
+#define NUM_KEYCODES 248
+#define MIN_KEYCODE 8
+#define MAX_KEYCODE (NUM_KEYCODES + MIN_KEYCODE - 1)
+
+#define AltMask Mod1Mask
+#define NumLockMask Mod2Mask
+#define AltLangMask Mod3Mask
+#define KanaMask Mod4Mask
+#define ScrollLockMask Mod5Mask
+
+#define KeyPressed(k) (keyc->down[k >> 3] & (1 << (k & 7)))
+#define ModifierDown(k) ((keyc->state & (k)) == (k))
+
+/*
+ * NOTE: The AT/MF keyboards can generate (via the 8042) two (MF: three)
+ * sets of scancodes. Set3 can only be generated by a MF keyboard.
+ * Set2 sends a makecode for keypress, and the same code prefixed by a
+ * F0 for keyrelease. This is a little bit ugly to handle. Thus we use
+ * here for X386 the PC/XT compatible Set1. This set uses 8bit scancodes.
+ * Bit 7 ist set if the key is released. The code E0 switches to a
+ * different meaning to add the new MF cursorkeys, while not breaking old
+ * applications. E1 is another special prefix. Since I assume that there
+ * will be further versions of PC/XT scancode compatible keyboards, we
+ * may be in trouble one day.
+ *
+ * IDEA: 1) Use Set2 on AT84 keyboards and translate it to MF Set3.
+ * 2) Use the keyboards native set and translate it to common keysyms.
+ */
+
+/*
+ * definition of the AT84/MF101/MF102 Keyboard:
+ * ============================================================
+ * Defined Key Cap Glyphs Pressed value
+ * Key Name Main Also (hex) (dec)
+ * ---------------- ---------- ------- ------ ------
+ */
+
+#define KEY_Escape /* Escape 0x01 */ 1
+#define KEY_1 /* 1 ! 0x02 */ 2
+#define KEY_2 /* 2 @ 0x03 */ 3
+#define KEY_3 /* 3 # 0x04 */ 4
+#define KEY_4 /* 4 $ 0x05 */ 5
+#define KEY_5 /* 5 % 0x06 */ 6
+#define KEY_6 /* 6 ^ 0x07 */ 7
+#define KEY_7 /* 7 & 0x08 */ 8
+#define KEY_8 /* 8 * 0x09 */ 9
+#define KEY_9 /* 9 ( 0x0a */ 10
+#define KEY_0 /* 0 ) 0x0b */ 11
+#define KEY_Minus /* - (Minus) _ (Under) 0x0c */ 12
+#define KEY_Equal /* = (Equal) + 0x0d */ 13
+#define KEY_BackSpace /* Back Space 0x0e */ 14
+#define KEY_Tab /* Tab 0x0f */ 15
+#define KEY_Q /* Q 0x10 */ 16
+#define KEY_W /* W 0x11 */ 17
+#define KEY_E /* E 0x12 */ 18
+#define KEY_R /* R 0x13 */ 19
+#define KEY_T /* T 0x14 */ 20
+#define KEY_Y /* Y 0x15 */ 21
+#define KEY_U /* U 0x16 */ 22
+#define KEY_I /* I 0x17 */ 23
+#define KEY_O /* O 0x18 */ 24
+#define KEY_P /* P 0x19 */ 25
+#define KEY_LBrace /* [ { 0x1a */ 26
+#define KEY_RBrace /* ] } 0x1b */ 27
+#define KEY_Enter /* Enter 0x1c */ 28
+#define KEY_LCtrl /* Ctrl(left) 0x1d */ 29
+#define KEY_A /* A 0x1e */ 30
+#define KEY_S /* S 0x1f */ 31
+#define KEY_D /* D 0x20 */ 32
+#define KEY_F /* F 0x21 */ 33
+#define KEY_G /* G 0x22 */ 34
+#define KEY_H /* H 0x23 */ 35
+#define KEY_J /* J 0x24 */ 36
+#define KEY_K /* K 0x25 */ 37
+#define KEY_L /* L 0x26 */ 38
+#define KEY_SemiColon /* ;(SemiColon) :(Colon) 0x27 */ 39
+#define KEY_Quote /* ' (Apostr) " (Quote) 0x28 */ 40
+#define KEY_Tilde /* ` (Accent) ~ (Tilde) 0x29 */ 41
+#define KEY_ShiftL /* Shift(left) 0x2a */ 42
+#define KEY_BSlash /* \(BckSlash) |(VertBar)0x2b */ 43
+#define KEY_Z /* Z 0x2c */ 44
+#define KEY_X /* X 0x2d */ 45
+#define KEY_C /* C 0x2e */ 46
+#define KEY_V /* V 0x2f */ 47
+#define KEY_B /* B 0x30 */ 48
+#define KEY_N /* N 0x31 */ 49
+#define KEY_M /* M 0x32 */ 50
+#define KEY_Comma /* , (Comma) < (Less) 0x33 */ 51
+#define KEY_Period /* . (Period) >(Greater)0x34 */ 52
+#define KEY_Slash /* / (Slash) ? 0x35 */ 53
+#define KEY_ShiftR /* Shift(right) 0x36 */ 54
+#define KEY_KP_Multiply /* * 0x37 */ 55
+#define KEY_Alt /* Alt(left) 0x38 */ 56
+#define KEY_Space /* (SpaceBar) 0x39 */ 57
+#define KEY_CapsLock /* CapsLock 0x3a */ 58
+#define KEY_F1 /* F1 0x3b */ 59
+#define KEY_F2 /* F2 0x3c */ 60
+#define KEY_F3 /* F3 0x3d */ 61
+#define KEY_F4 /* F4 0x3e */ 62
+#define KEY_F5 /* F5 0x3f */ 63
+#define KEY_F6 /* F6 0x40 */ 64
+#define KEY_F7 /* F7 0x41 */ 65
+#define KEY_F8 /* F8 0x42 */ 66
+#define KEY_F9 /* F9 0x43 */ 67
+#define KEY_F10 /* F10 0x44 */ 68
+#define KEY_NumLock /* NumLock 0x45 */ 69
+#define KEY_ScrollLock /* ScrollLock 0x46 */ 70
+#define KEY_KP_7 /* 7 Home 0x47 */ 71
+#define KEY_KP_8 /* 8 Up 0x48 */ 72
+#define KEY_KP_9 /* 9 PgUp 0x49 */ 73
+#define KEY_KP_Minus /* - (Minus) 0x4a */ 74
+#define KEY_KP_4 /* 4 Left 0x4b */ 75
+#define KEY_KP_5 /* 5 0x4c */ 76
+#define KEY_KP_6 /* 6 Right 0x4d */ 77
+#define KEY_KP_Plus /* + (Plus) 0x4e */ 78
+#define KEY_KP_1 /* 1 End 0x4f */ 79
+#define KEY_KP_2 /* 2 Down 0x50 */ 80
+#define KEY_KP_3 /* 3 PgDown 0x51 */ 81
+#define KEY_KP_0 /* 0 Insert 0x52 */ 82
+#define KEY_KP_Decimal /* . (Decimal) Delete 0x53 */ 83
+#define KEY_SysReqest /* SysReqest 0x54 */ 84
+ /* NOTUSED 0x55 */
+#define KEY_Less /* < (Less) >(Greater) 0x56 */ 86
+#define KEY_F11 /* F11 0x57 */ 87
+#define KEY_F12 /* F12 0x58 */ 88
+
+#define KEY_Prefix0 /* special 0x60 */ 96
+#define KEY_Prefix1 /* specail 0x61 */ 97
+
+/*
+ * The 'scancodes' below are generated by the server, because the MF101/102
+ * keyboard sends them as sequence of other scancodes
+ */
+#define KEY_Home /* Home 0x59 */ 89
+#define KEY_Up /* Up 0x5a */ 90
+#define KEY_PgUp /* PgUp 0x5b */ 91
+#define KEY_Left /* Left 0x5c */ 92
+#define KEY_Begin /* Begin 0x5d */ 93
+#define KEY_Right /* Right 0x5e */ 94
+#define KEY_End /* End 0x5f */ 95
+#define KEY_Down /* Down 0x60 */ 96
+#define KEY_PgDown /* PgDown 0x61 */ 97
+#define KEY_Insert /* Insert 0x62 */ 98
+#define KEY_Delete /* Delete 0x63 */ 99
+#define KEY_KP_Enter /* Enter 0x64 */ 100
+#define KEY_RCtrl /* Ctrl(right) 0x65 */ 101
+#define KEY_Pause /* Pause 0x66 */ 102
+#define KEY_Print /* Print 0x67 */ 103
+#define KEY_KP_Divide /* Divide 0x68 */ 104
+#define KEY_AltLang /* AtlLang(right) 0x69 */ 105
+#define KEY_Break /* Break 0x6a */ 106
+#define KEY_LMeta /* Left Meta 0x6b */ 107
+#define KEY_RMeta /* Right Meta 0x6c */ 108
+#define KEY_Menu /* Menu 0x6d */ 109
+#define KEY_F13 /* F13 0x6e */ 110
+#define KEY_F14 /* F14 0x6f */ 111
+#define KEY_F15 /* F15 0x70 */ 112
+#define KEY_HKTG /* Hirugana/Katakana tog 0x70 */ 112
+#define KEY_F16 /* F16 0x71 */ 113
+#define KEY_F17 /* F17 0x72 */ 114
+#define KEY_KP_DEC /* KP_DEC 0x73 */ 115
+#define KEY_BSlash2 /* \ _ 0x73 */ 115
+#define KEY_KP_Equal /* Equal (Keypad) 0x76 */ 118
+#define KEY_XFER /* Kanji Transfer 0x79 */ 121
+#define KEY_NFER /* No Kanji Transfer 0x7b */ 123
+#define KEY_Yen /* Yen 0x7d */ 125
+
+#define KEY_Power /* Power Key 0x84 */ 132
+#define KEY_Mute /* Audio Mute 0x85 */ 133
+#define KEY_AudioLower /* Audio Lower 0x86 */ 134
+#define KEY_AudioRaise /* Audio Raise 0x87 */ 135
+#define KEY_Help /* Help 0x88 */ 136
+#define KEY_L1 /* Stop 0x89 */ 137
+#define KEY_L2 /* Again 0x8a */ 138
+#define KEY_L3 /* Props 0x8b */ 139
+#define KEY_L4 /* Undo 0x8c */ 140
+#define KEY_L5 /* Front 0x8d */ 141
+#define KEY_L6 /* Copy 0x8e */ 142
+#define KEY_L7 /* Open 0x8f */ 143
+#define KEY_L8 /* Paste 0x90 */ 144
+#define KEY_L9 /* Find 0x91 */ 145
+#define KEY_L10 /* Cut 0x92 */ 146
+
+/*
+ * Fake 'scancodes' in the following ranges are generated for 2-byte
+ * codes not handled elsewhere. These correspond to most extended keys
+ * on so-called "Internet" keyboards:
+ *
+ * 0x79-0x93
+ * 0x96-0xa1
+ * 0xa3-0xac
+ * 0xb1-0xb4
+ * 0xba-0xbd
+ * 0xc2
+ * 0xcc-0xd2
+ * 0xd6-0xf7
+ */
+
+/*
+ * Remapped 'scancodes' are generated for single-byte codes in the range
+ * 0x59-0x5f,0x62-0x76. These are used for some extra keys on some keyboards.
+ */
+
+#define KEY_0x59 0x95
+#define KEY_0x5A 0xA2
+#define KEY_0x5B 0xAD
+#define KEY_0x5C KEY_KP_EQUAL
+#define KEY_0x5D 0xAE
+#define KEY_0x5E 0xAF
+#define KEY_0x5F 0xB0
+#define KEY_0x62 0xB5
+#define KEY_0x63 0xB6
+#define KEY_0x64 0xB7
+#define KEY_0x65 0xB8
+#define KEY_0x66 0xB9
+#define KEY_0x67 0xBE
+#define KEY_0x68 0xBF
+#define KEY_0x69 0xC0
+#define KEY_0x6A 0xC1
+#define KEY_0x6B 0xC3
+#define KEY_0x6C 0xC4
+#define KEY_0x6D 0xC5
+#define KEY_0x6E 0xC6
+#define KEY_0x6F 0xC7
+#define KEY_0x70 0xC8
+#define KEY_0x71 0xC9
+#define KEY_0x72 0xCA
+#define KEY_0x73 0xCB
+#define KEY_0x74 0xD3
+#define KEY_0x75 0xD4
+#define KEY_0x76 0xD5
+
+/* These are for "notused" and "unknown" entries in translation maps. */
+#define KEY_NOTUSED 0
+#define KEY_UNKNOWN 255
+
+#endif /* _ATKEYNAMES_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/compiler.h b/nx-X11/programs/Xserver/hw/xfree86/common/compiler.h
new file mode 100644
index 000000000..d323f677b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/compiler.h
@@ -0,0 +1,1863 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/compiler.h,v 3.106 2004/02/02 03:55:28 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
+ * Copyright (c) 1994-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).
+ */
+
+/* $XConsortium: compiler.h /main/16 1996/10/25 15:38:34 kaleb $ */
+
+#ifndef _COMPILER_H
+
+# if !defined(_XF86_ANSIC_H) && defined(XFree86Module)
+# error missing #include "xf86_ansic.h" before #include "compiler.h"
+# endif
+
+# define _COMPILER_H
+
+#if defined(__SUNPRO_C)
+# define DO_PROTOTYPES
+#endif
+
+/* Allow drivers to use the GCC-supported __inline__ and/or __inline. */
+# ifndef __inline__
+# if defined(__GNUC__)
+ /* gcc has __inline__ */
+# elif defined(__HIGHC__)
+# define __inline__ _Inline
+# else
+# define __inline__ /**/
+# endif
+# endif /* __inline__ */
+# ifndef __inline
+# if defined(__GNUC__)
+ /* gcc has __inline */
+# elif defined(__HIGHC__)
+# define __inline _Inline
+# else
+# define __inline /**/
+# endif
+# endif /* __inline */
+
+# if defined(IODEBUG) && defined(__GNUC__)
+# define outb RealOutb
+# define outw RealOutw
+# define outl RealOutl
+# define inb RealInb
+# define inw RealInw
+# define inl RealInl
+# endif
+
+# if defined(QNX4) /* Do this for now to keep Watcom happy */
+# define outb outp
+# define outw outpw
+# define outl outpd
+# define inb inp
+# define inw inpw
+# define inl inpd
+
+/* Define the ffs function for inlining */
+extern int ffs(unsigned long);
+# pragma aux ffs_ = \
+ "bsf edx, eax" \
+ "jnz bits_set" \
+ "xor eax, eax" \
+ "jmp exit1" \
+ "bits_set:" \
+ "mov eax, edx" \
+ "inc eax" \
+ "exit1:" \
+ __parm [eax] \
+ __modify [eax edx] \
+ __value [eax] \
+ ;
+# endif
+
+# if defined(__SUNPRO_C)
+# define DO_PROTOTYPES
+# endif
+
+# if defined(NO_INLINE) || defined(DO_PROTOTYPES)
+
+# if !defined(__arm__)
+# if !defined(__sparc__) && !defined(__arm32__) \
+ && !(defined(__alpha__) && defined(linux)) \
+ && !(defined(__ia64__) && defined(linux)) \
+
+extern void outb(unsigned short, unsigned char);
+extern void outw(unsigned short, unsigned short);
+extern void outl(unsigned short, unsigned int);
+extern unsigned int inb(unsigned short);
+extern unsigned int inw(unsigned short);
+extern unsigned int inl(unsigned short);
+
+# else /* __sparc__, __arm32__, __alpha__*/
+
+extern void outb(unsigned long, unsigned char);
+extern void outw(unsigned long, unsigned short);
+extern void outl(unsigned long, unsigned int);
+extern unsigned int inb(unsigned long);
+extern unsigned int inw(unsigned long);
+extern unsigned int inl(unsigned long);
+
+# endif /* __sparc__, __arm32__, __alpha__ */
+# endif /* __arm__ */
+
+extern unsigned long ldq_u(unsigned long *);
+extern unsigned long ldl_u(unsigned int *);
+extern unsigned long ldw_u(unsigned short *);
+extern void stq_u(unsigned long, unsigned long *);
+extern void stl_u(unsigned long, unsigned int *);
+extern void stw_u(unsigned long, unsigned short *);
+extern void mem_barrier(void);
+extern void write_mem_barrier(void);
+extern void stl_brx(unsigned long, volatile unsigned char *, int);
+extern void stw_brx(unsigned short, volatile unsigned char *, int);
+extern unsigned long ldl_brx(volatile unsigned char *, int);
+extern unsigned short ldw_brx(volatile unsigned char *, int);
+
+# endif
+
+# ifndef NO_INLINE
+# ifdef __GNUC__
+# if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && (defined(__alpha__))
+
+# ifdef linux
+/* for Linux on Alpha, we use the LIBC _inx/_outx routines */
+/* note that the appropriate setup via "ioperm" needs to be done */
+/* *before* any inx/outx is done. */
+
+extern void (*_alpha_outb)(char val, unsigned long port);
+static __inline__ void
+outb(unsigned long port, unsigned char val)
+{
+ _alpha_outb(val, port);
+}
+
+extern void (*_alpha_outw)(short val, unsigned long port);
+static __inline__ void
+outw(unsigned long port, unsigned short val)
+{
+ _alpha_outw(val, port);
+}
+
+extern void (*_alpha_outl)(int val, unsigned long port);
+static __inline__ void
+outl(unsigned long port, unsigned int val)
+{
+ _alpha_outl(val, port);
+}
+
+extern unsigned int (*_alpha_inb)(unsigned long port);
+static __inline__ unsigned int
+inb(unsigned long port)
+{
+ return _alpha_inb(port);
+}
+
+extern unsigned int (*_alpha_inw)(unsigned long port);
+static __inline__ unsigned int
+inw(unsigned long port)
+{
+ return _alpha_inw(port);
+}
+
+extern unsigned int (*_alpha_inl)(unsigned long port);
+static __inline__ unsigned int
+inl(unsigned long port)
+{
+ return _alpha_inl(port);
+}
+
+# endif /* linux */
+
+# if (defined(__FreeBSD__) || defined(__OpenBSD__)) \
+ && !defined(DO_PROTOTYPES)
+
+/* for FreeBSD and OpenBSD on Alpha, we use the libio (resp. libalpha) */
+/* inx/outx routines */
+/* note that the appropriate setup via "ioperm" needs to be done */
+/* *before* any inx/outx is done. */
+
+extern void outb(unsigned int port, unsigned char val);
+extern void outw(unsigned int port, unsigned short val);
+extern void outl(unsigned int port, unsigned int val);
+extern unsigned char inb(unsigned int port);
+extern unsigned short inw(unsigned int port);
+extern unsigned int inl(unsigned int port);
+
+# endif /* (__FreeBSD__ || __OpenBSD__ ) && !DO_PROTOTYPES */
+
+
+#if defined(__NetBSD__)
+#include <machine/pio.h>
+#endif /* __NetBSD__ */
+
+/*
+ * inline functions to do unaligned accesses
+ * from linux/include/asm-alpha/unaligned.h
+ */
+
+/*
+ * EGCS 1.1 knows about arbitrary unaligned loads. Define some
+ * packed structures to talk about such things with.
+ */
+
+struct __una_u64 { unsigned long x __attribute__((packed)); };
+struct __una_u32 { unsigned int x __attribute__((packed)); };
+struct __una_u16 { unsigned short x __attribute__((packed)); };
+
+/*
+ * Elemental unaligned loads
+ */
+/* let's try making these things static */
+
+static __inline__ unsigned long ldq_u(unsigned long * r11)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
+ return ptr->x;
+# else
+ unsigned long r1,r2;
+ __asm__("ldq_u %0,%3\n\t"
+ "ldq_u %1,%4\n\t"
+ "extql %0,%2,%0\n\t"
+ "extqh %1,%2,%1"
+ :"=&r" (r1), "=&r" (r2)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(const unsigned long *)(7+(char *) r11)));
+ return r1 | r2;
+# endif
+}
+
+static __inline__ unsigned long ldl_u(unsigned int * r11)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
+ return ptr->x;
+# else
+ unsigned long r1,r2;
+ __asm__("ldq_u %0,%3\n\t"
+ "ldq_u %1,%4\n\t"
+ "extll %0,%2,%0\n\t"
+ "extlh %1,%2,%1"
+ :"=&r" (r1), "=&r" (r2)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(const unsigned long *)(3+(char *) r11)));
+ return r1 | r2;
+# endif
+}
+
+static __inline__ unsigned long ldw_u(unsigned short * r11)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
+ return ptr->x;
+# else
+ unsigned long r1,r2;
+ __asm__("ldq_u %0,%3\n\t"
+ "ldq_u %1,%4\n\t"
+ "extwl %0,%2,%0\n\t"
+ "extwh %1,%2,%1"
+ :"=&r" (r1), "=&r" (r2)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(const unsigned long *)(1+(char *) r11)));
+ return r1 | r2;
+# endif
+}
+
+/*
+ * Elemental unaligned stores
+ */
+
+static __inline__ void stq_u(unsigned long r5, unsigned long * r11)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ struct __una_u64 *ptr = (struct __una_u64 *) r11;
+ ptr->x = r5;
+# else
+ unsigned long r1,r2,r3,r4;
+
+ __asm__("ldq_u %3,%1\n\t"
+ "ldq_u %2,%0\n\t"
+ "insqh %6,%7,%5\n\t"
+ "insql %6,%7,%4\n\t"
+ "mskqh %3,%7,%3\n\t"
+ "mskql %2,%7,%2\n\t"
+ "bis %3,%5,%3\n\t"
+ "bis %2,%4,%2\n\t"
+ "stq_u %3,%1\n\t"
+ "stq_u %2,%0"
+ :"=m" (*r11),
+ "=m" (*(unsigned long *)(7+(char *) r11)),
+ "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+ :"r" (r5), "r" (r11));
+# endif
+}
+
+static __inline__ void stl_u(unsigned long r5, unsigned int * r11)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ struct __una_u32 *ptr = (struct __una_u32 *) r11;
+ ptr->x = r5;
+# else
+ unsigned long r1,r2,r3,r4;
+
+ __asm__("ldq_u %3,%1\n\t"
+ "ldq_u %2,%0\n\t"
+ "inslh %6,%7,%5\n\t"
+ "insll %6,%7,%4\n\t"
+ "msklh %3,%7,%3\n\t"
+ "mskll %2,%7,%2\n\t"
+ "bis %3,%5,%3\n\t"
+ "bis %2,%4,%2\n\t"
+ "stq_u %3,%1\n\t"
+ "stq_u %2,%0"
+ :"=m" (*r11),
+ "=m" (*(unsigned long *)(3+(char *) r11)),
+ "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+ :"r" (r5), "r" (r11));
+# endif
+}
+
+static __inline__ void stw_u(unsigned long r5, unsigned short * r11)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ struct __una_u16 *ptr = (struct __una_u16 *) r11;
+ ptr->x = r5;
+# else
+ unsigned long r1,r2,r3,r4;
+
+ __asm__("ldq_u %3,%1\n\t"
+ "ldq_u %2,%0\n\t"
+ "inswh %6,%7,%5\n\t"
+ "inswl %6,%7,%4\n\t"
+ "mskwh %3,%7,%3\n\t"
+ "mskwl %2,%7,%2\n\t"
+ "bis %3,%5,%3\n\t"
+ "bis %2,%4,%2\n\t"
+ "stq_u %3,%1\n\t"
+ "stq_u %2,%0"
+ :"=m" (*r11),
+ "=m" (*(unsigned long *)(1+(char *) r11)),
+ "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+ :"r" (r5), "r" (r11));
+# endif
+}
+
+/* to flush the I-cache before jumping to code which just got loaded */
+# define PAL_imb 134
+# define istream_mem_barrier() \
+ __asm__ __volatile__("call_pal %0 #imb" : : "i" (PAL_imb) : "memory")
+# define mem_barrier() __asm__ __volatile__("mb" : : : "memory")
+# ifdef __ELF__
+# define write_mem_barrier() __asm__ __volatile__("wmb" : : : "memory")
+# else /* ECOFF gas 2.6 doesn't know "wmb" :-( */
+# define write_mem_barrier() mem_barrier()
+# endif
+
+
+# elif defined(linux) && defined(__ia64__)
+
+# include <inttypes.h>
+
+# include <sys/io.h>
+
+struct __una_u64 { uint64_t x __attribute__((packed)); };
+struct __una_u32 { uint32_t x __attribute__((packed)); };
+struct __una_u16 { uint16_t x __attribute__((packed)); };
+
+static __inline__ unsigned long
+__uldq (const unsigned long * r11)
+{
+ const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
+ return ptr->x;
+}
+
+static __inline__ unsigned long
+__uldl (const unsigned int * r11)
+{
+ const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
+ return ptr->x;
+}
+
+static __inline__ unsigned long
+__uldw (const unsigned short * r11)
+{
+ const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
+ return ptr->x;
+}
+
+static __inline__ void
+__ustq (unsigned long r5, unsigned long * r11)
+{
+ struct __una_u64 *ptr = (struct __una_u64 *) r11;
+ ptr->x = r5;
+}
+
+static __inline__ void
+__ustl (unsigned long r5, unsigned int * r11)
+{
+ struct __una_u32 *ptr = (struct __una_u32 *) r11;
+ ptr->x = r5;
+}
+
+static __inline__ void
+__ustw (unsigned long r5, unsigned short * r11)
+{
+ struct __una_u16 *ptr = (struct __una_u16 *) r11;
+ ptr->x = r5;
+}
+
+# define ldq_u(p) __uldq(p)
+# define ldl_u(p) __uldl(p)
+# define ldw_u(p) __uldw(p)
+# define stq_u(v,p) __ustq(v,p)
+# define stl_u(v,p) __ustl(v,p)
+# define stw_u(v,p) __ustw(v,p)
+
+# ifndef __INTEL_COMPILER
+# define mem_barrier() __asm__ __volatile__ ("mf" ::: "memory")
+# define write_mem_barrier() __asm__ __volatile__ ("mf" ::: "memory")
+# else
+# include "ia64intrin.h"
+# define mem_barrier() __mf()
+# define write_mem_barrier() __mf()
+# endif
+
+/*
+ * This is overkill, but for different reasons depending on where it is used.
+ * This is thus general enough to be used everywhere cache flushes are needed.
+ * It doesn't handle memory access serialisation by other processors, though.
+ */
+# ifndef __INTEL_COMPILER
+# define ia64_flush_cache(Addr) \
+ __asm__ __volatile__ ( \
+ "fc.i %0;;;" \
+ "sync.i;;;" \
+ "mf;;;" \
+ "srlz.i;;;" \
+ :: "r"(Addr) : "memory")
+# else
+# define ia64_flush_cache(Addr) { \
+ __fc(Addr);\
+ __synci();\
+ __mf();\
+ __isrlz();\
+ }
+# endif
+# undef outb
+# undef outw
+# undef outl
+# undef inb
+# undef inw
+# undef inl
+extern void outb(unsigned long port, unsigned char val);
+extern void outw(unsigned long port, unsigned short val);
+extern void outl(unsigned long port, unsigned int val);
+extern unsigned int inb(unsigned long port);
+extern unsigned int inw(unsigned long port);
+extern unsigned int inl(unsigned long port);
+
+# elif defined(linux) && defined(__amd64__)
+
+# include <inttypes.h>
+
+# define ldq_u(p) (*((unsigned long *)(p)))
+# define ldl_u(p) (*((unsigned int *)(p)))
+# define ldw_u(p) (*((unsigned short *)(p)))
+# define stq_u(v,p) (*(unsigned long *)(p)) = (v)
+# define stl_u(v,p) (*(unsigned int *)(p)) = (v)
+# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
+
+# define mem_barrier() \
+ __asm__ __volatile__ ("lock; addl $0,0(%%rsp)": : :"memory")
+# define write_mem_barrier() \
+ __asm__ __volatile__ ("": : :"memory")
+
+
+static __inline__ void
+outb(unsigned short port, unsigned char val)
+{
+ __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
+}
+
+
+static __inline__ void
+outw(unsigned short port, unsigned short val)
+{
+ __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+outl(unsigned short port, unsigned int val)
+{
+ __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ unsigned int
+inb(unsigned short port)
+{
+ unsigned char ret;
+ __asm__ __volatile__("inb %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+inw(unsigned short port)
+{
+ unsigned short ret;
+ __asm__ __volatile__("inw %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+inl(unsigned short port)
+{
+ unsigned int ret;
+ __asm__ __volatile__("inl %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+# elif (defined(linux) || defined(Lynx) || defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(__sparc__)
+
+# if !defined(Lynx)
+# ifndef ASI_PL
+# define ASI_PL 0x88
+# endif
+
+# define barrier() __asm__ __volatile__(".word 0x8143e00a": : :"memory")
+
+static __inline__ void
+outb(unsigned long port, unsigned char val)
+{
+ __asm__ __volatile__("stba %0, [%1] %2"
+ : /* No outputs */
+ : "r" (val), "r" (port), "i" (ASI_PL));
+ barrier();
+}
+
+static __inline__ void
+outw(unsigned long port, unsigned short val)
+{
+ __asm__ __volatile__("stha %0, [%1] %2"
+ : /* No outputs */
+ : "r" (val), "r" (port), "i" (ASI_PL));
+ barrier();
+}
+
+static __inline__ void
+outl(unsigned long port, unsigned int val)
+{
+ __asm__ __volatile__("sta %0, [%1] %2"
+ : /* No outputs */
+ : "r" (val), "r" (port), "i" (ASI_PL));
+ barrier();
+}
+
+static __inline__ unsigned int
+inb(unsigned long port)
+{
+ unsigned int ret;
+ __asm__ __volatile__("lduba [%1] %2, %0"
+ : "=r" (ret)
+ : "r" (port), "i" (ASI_PL));
+ return ret;
+}
+
+static __inline__ unsigned int
+inw(unsigned long port)
+{
+ unsigned int ret;
+ __asm__ __volatile__("lduha [%1] %2, %0"
+ : "=r" (ret)
+ : "r" (port), "i" (ASI_PL));
+ return ret;
+}
+
+static __inline__ unsigned int
+inl(unsigned long port)
+{
+ unsigned int ret;
+ __asm__ __volatile__("lda [%1] %2, %0"
+ : "=r" (ret)
+ : "r" (port), "i" (ASI_PL));
+ return ret;
+}
+
+static __inline__ unsigned char
+xf86ReadMmio8(__volatile__ void *base, const unsigned long offset)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+ unsigned char ret;
+
+ __asm__ __volatile__("lduba [%1] %2, %0"
+ : "=r" (ret)
+ : "r" (addr), "i" (ASI_PL));
+ return ret;
+}
+
+static __inline__ unsigned short
+xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+ unsigned short ret;
+
+ __asm__ __volatile__("lduh [%1], %0"
+ : "=r" (ret)
+ : "r" (addr));
+ return ret;
+}
+
+static __inline__ unsigned short
+xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+ unsigned short ret;
+
+ __asm__ __volatile__("lduha [%1] %2, %0"
+ : "=r" (ret)
+ : "r" (addr), "i" (ASI_PL));
+ return ret;
+}
+
+static __inline__ unsigned int
+xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+ unsigned int ret;
+
+ __asm__ __volatile__("ld [%1], %0"
+ : "=r" (ret)
+ : "r" (addr));
+ return ret;
+}
+
+static __inline__ unsigned int
+xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+ unsigned int ret;
+
+ __asm__ __volatile__("lda [%1] %2, %0"
+ : "=r" (ret)
+ : "r" (addr), "i" (ASI_PL));
+ return ret;
+}
+
+static __inline__ void
+xf86WriteMmio8(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("stba %0, [%1] %2"
+ : /* No outputs */
+ : "r" (val), "r" (addr), "i" (ASI_PL));
+ barrier();
+}
+
+static __inline__ void
+xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("sth %0, [%1]"
+ : /* No outputs */
+ : "r" (val), "r" (addr));
+ barrier();
+}
+
+static __inline__ void
+xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("stha %0, [%1] %2"
+ : /* No outputs */
+ : "r" (val), "r" (addr), "i" (ASI_PL));
+ barrier();
+}
+
+static __inline__ void
+xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("st %0, [%1]"
+ : /* No outputs */
+ : "r" (val), "r" (addr));
+ barrier();
+}
+
+static __inline__ void
+xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("sta %0, [%1] %2"
+ : /* No outputs */
+ : "r" (val), "r" (addr), "i" (ASI_PL));
+ barrier();
+}
+
+static __inline__ void
+xf86WriteMmio8NB(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("stba %0, [%1] %2"
+ : /* No outputs */
+ : "r" (val), "r" (addr), "i" (ASI_PL));
+}
+
+static __inline__ void
+xf86WriteMmio16BeNB(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("sth %0, [%1]"
+ : /* No outputs */
+ : "r" (val), "r" (addr));
+}
+
+static __inline__ void
+xf86WriteMmio16LeNB(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("stha %0, [%1] %2"
+ : /* No outputs */
+ : "r" (val), "r" (addr), "i" (ASI_PL));
+}
+
+static __inline__ void
+xf86WriteMmio32BeNB(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("st %0, [%1]"
+ : /* No outputs */
+ : "r" (val), "r" (addr));
+}
+
+static __inline__ void
+xf86WriteMmio32LeNB(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("sta %0, [%1] %2"
+ : /* No outputs */
+ : "r" (val), "r" (addr), "i" (ASI_PL));
+}
+
+# endif /* !Lynx */
+
+/*
+ * EGCS 1.1 knows about arbitrary unaligned loads. Define some
+ * packed structures to talk about such things with.
+ */
+
+# if defined(__arch64__) || defined(__sparcv9)
+struct __una_u64 { unsigned long x __attribute__((packed)); };
+# endif
+struct __una_u32 { unsigned int x __attribute__((packed)); };
+struct __una_u16 { unsigned short x __attribute__((packed)); };
+
+static __inline__ unsigned long ldq_u(unsigned long *p)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+# if defined(__arch64__) || defined(__sparcv9)
+ const struct __una_u64 *ptr = (const struct __una_u64 *) p;
+# else
+ const struct __una_u32 *ptr = (const struct __una_u32 *) p;
+# endif
+ return ptr->x;
+# else
+ unsigned long ret;
+ memmove(&ret, p, sizeof(*p));
+ return ret;
+# endif
+}
+
+static __inline__ unsigned long ldl_u(unsigned int *p)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ const struct __una_u32 *ptr = (const struct __una_u32 *) p;
+ return ptr->x;
+# else
+ unsigned int ret;
+ memmove(&ret, p, sizeof(*p));
+ return ret;
+# endif
+}
+
+static __inline__ unsigned long ldw_u(unsigned short *p)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ const struct __una_u16 *ptr = (const struct __una_u16 *) p;
+ return ptr->x;
+# else
+ unsigned short ret;
+ memmove(&ret, p, sizeof(*p));
+ return ret;
+# endif
+}
+
+static __inline__ void stq_u(unsigned long val, unsigned long *p)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+# if defined(__arch64__) || defined(__sparcv9)
+ struct __una_u64 *ptr = (struct __una_u64 *) p;
+# else
+ struct __una_u32 *ptr = (struct __una_u32 *) p;
+# endif
+ ptr->x = val;
+# else
+ unsigned long tmp = val;
+ memmove(p, &tmp, sizeof(*p));
+# endif
+}
+
+static __inline__ void stl_u(unsigned long val, unsigned int *p)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ struct __una_u32 *ptr = (struct __una_u32 *) p;
+ ptr->x = val;
+# else
+ unsigned int tmp = val;
+ memmove(p, &tmp, sizeof(*p));
+# endif
+}
+
+static __inline__ void stw_u(unsigned long val, unsigned short *p)
+{
+# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
+ struct __una_u16 *ptr = (struct __una_u16 *) p;
+ ptr->x = val;
+# else
+ unsigned short tmp = val;
+ memmove(p, &tmp, sizeof(*p));
+# endif
+}
+
+# define mem_barrier() /* XXX: nop for now */
+# define write_mem_barrier() /* XXX: nop for now */
+
+# elif defined(__mips__) || (defined(__arm32__) && !defined(__linux__))
+# ifdef __arm32__
+# define PORT_SIZE long
+# else
+# define PORT_SIZE short
+# endif
+
+unsigned int IOPortBase; /* Memory mapped I/O port area */
+
+static __inline__ void
+outb(unsigned PORT_SIZE port, unsigned char val)
+{
+ *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val;
+}
+
+static __inline__ void
+outw(unsigned PORT_SIZE port, unsigned short val)
+{
+ *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val;
+}
+
+static __inline__ void
+outl(unsigned PORT_SIZE port, unsigned int val)
+{
+ *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val;
+}
+
+static __inline__ unsigned int
+inb(unsigned PORT_SIZE port)
+{
+ return *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))+IOPortBase);
+}
+
+static __inline__ unsigned int
+inw(unsigned PORT_SIZE port)
+{
+ return *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))+IOPortBase);
+}
+
+static __inline__ unsigned int
+inl(unsigned PORT_SIZE port)
+{
+ return *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))+IOPortBase);
+}
+
+
+# if defined(__mips__)
+static __inline__ unsigned long ldq_u(unsigned long * r11)
+{
+ unsigned long r1;
+ __asm__("lwr %0,%2\n\t"
+ "lwl %0,%3\n\t"
+ :"=&r" (r1)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(unsigned long *)(3+(char *) r11)));
+ return r1;
+}
+
+static __inline__ unsigned long ldl_u(unsigned int * r11)
+{
+ unsigned long r1;
+ __asm__("lwr %0,%2\n\t"
+ "lwl %0,%3\n\t"
+ :"=&r" (r1)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(unsigned long *)(3+(char *) r11)));
+ return r1;
+}
+
+static __inline__ unsigned long ldw_u(unsigned short * r11)
+{
+ unsigned long r1;
+ __asm__("lwr %0,%2\n\t"
+ "lwl %0,%3\n\t"
+ :"=&r" (r1)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(unsigned long *)(1+(char *) r11)));
+ return r1;
+}
+
+# ifdef linux /* don't mess with other OSs */
+
+/*
+ * EGCS 1.1 knows about arbitrary unaligned loads (and we don't support older
+ * versions anyway. Define some packed structures to talk about such things
+ * with.
+ */
+
+struct __una_u32 { unsigned int x __attribute__((packed)); };
+struct __una_u16 { unsigned short x __attribute__((packed)); };
+
+static __inline__ void stw_u(unsigned long val, unsigned short *p)
+{
+ struct __una_u16 *ptr = (struct __una_u16 *) p;
+ ptr->x = val;
+}
+
+static __inline__ void stl_u(unsigned long val, unsigned int *p)
+{
+ struct __una_u32 *ptr = (struct __una_u32 *) p;
+ ptr->x = val;
+}
+
+# if X_BYTE_ORDER == X_BIG_ENDIAN
+static __inline__ unsigned int
+xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+ unsigned int ret;
+
+ __asm__ __volatile__("lw %0, 0(%1)"
+ : "=r" (ret)
+ : "r" (addr));
+ return ret;
+}
+
+static __inline__ void
+xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ unsigned long addr = ((unsigned long)base) + offset;
+
+ __asm__ __volatile__("sw %0, 0(%1)"
+ : /* No outputs */
+ : "r" (val), "r" (addr));
+}
+# endif
+
+# define mem_barrier() \
+ __asm__ __volatile__( \
+ "# prevent instructions being moved around\n\t" \
+ ".set\tnoreorder\n\t" \
+ "# 8 nops to fool the R4400 pipeline\n\t" \
+ "nop;nop;nop;nop;nop;nop;nop;nop\n\t" \
+ ".set\treorder" \
+ : /* no output */ \
+ : /* no input */ \
+ : "memory")
+# define write_mem_barrier() mem_barrier()
+
+# else /* !linux */
+
+# define stq_u(v,p) stl_u(v,p)
+# define stl_u(v,p) (*(unsigned char *)(p)) = (v); \
+ (*(unsigned char *)(p)+1) = ((v) >> 8); \
+ (*(unsigned char *)(p)+2) = ((v) >> 16); \
+ (*(unsigned char *)(p)+3) = ((v) >> 24)
+
+# define stw_u(v,p) (*(unsigned char *)(p)) = (v); \
+ (*(unsigned char *)(p)+1) = ((v) >> 8)
+
+# define mem_barrier() /* NOP */
+# endif /* !linux */
+# endif /* __mips__ */
+
+# if defined(__arm32__)
+# define ldq_u(p) (*((unsigned long *)(p)))
+# define ldl_u(p) (*((unsigned int *)(p)))
+# define ldw_u(p) (*((unsigned short *)(p)))
+# define stq_u(v,p) (*(unsigned long *)(p)) = (v)
+# define stl_u(v,p) (*(unsigned int *)(p)) = (v)
+# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
+# define mem_barrier() /* NOP */
+# define write_mem_barrier() /* NOP */
+# endif /* __arm32__ */
+
+# elif (defined(Lynx) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)) && defined(__powerpc__)
+
+# ifndef MAP_FAILED
+# define MAP_FAILED ((void *)-1)
+# endif
+
+extern volatile unsigned char *ioBase;
+
+#if defined(linux) && defined(__powerpc64__)
+# include <asm/memory.h>
+#endif /* defined(linux) && defined(__powerpc64__) */
+#ifndef eieio /* We deal with arch-specific eieio() routines above... */
+# define eieio() __asm__ __volatile__ ("eieio" ::: "memory")
+#endif /* eieio */
+
+static __inline__ unsigned char
+xf86ReadMmio8(__volatile__ void *base, const unsigned long offset)
+{
+ register unsigned char val;
+ __asm__ __volatile__(
+ "lbzx %0,%1,%2\n\t"
+ "eieio"
+ : "=r" (val)
+ : "b" (base), "r" (offset),
+ "m" (*((volatile unsigned char *)base+offset)));
+ return val;
+}
+
+static __inline__ unsigned short
+xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset)
+{
+ register unsigned short val;
+ __asm__ __volatile__(
+ "lhzx %0,%1,%2\n\t"
+ "eieio"
+ : "=r" (val)
+ : "b" (base), "r" (offset),
+ "m" (*((volatile unsigned char *)base+offset)));
+ return val;
+}
+
+static __inline__ unsigned short
+xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset)
+{
+ register unsigned short val;
+ __asm__ __volatile__(
+ "lhbrx %0,%1,%2\n\t"
+ "eieio"
+ : "=r" (val)
+ : "b" (base), "r" (offset),
+ "m" (*((volatile unsigned char *)base+offset)));
+ return val;
+}
+
+static __inline__ unsigned int
+xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset)
+{
+ register unsigned int val;
+ __asm__ __volatile__(
+ "lwzx %0,%1,%2\n\t"
+ "eieio"
+ : "=r" (val)
+ : "b" (base), "r" (offset),
+ "m" (*((volatile unsigned char *)base+offset)));
+ return val;
+}
+
+static __inline__ unsigned int
+xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset)
+{
+ register unsigned int val;
+ __asm__ __volatile__(
+ "lwbrx %0,%1,%2\n\t"
+ "eieio"
+ : "=r" (val)
+ : "b" (base), "r" (offset),
+ "m" (*((volatile unsigned char *)base+offset)));
+ return val;
+}
+
+static __inline__ void
+xf86WriteMmioNB8(__volatile__ void *base, const unsigned long offset,
+ const unsigned char val)
+{
+ __asm__ __volatile__(
+ "stbx %1,%2,%3\n\t"
+ : "=m" (*((volatile unsigned char *)base+offset))
+ : "r" (val), "b" (base), "r" (offset));
+}
+
+static __inline__ void
+xf86WriteMmioNB16Le(__volatile__ void *base, const unsigned long offset,
+ const unsigned short val)
+{
+ __asm__ __volatile__(
+ "sthbrx %1,%2,%3\n\t"
+ : "=m" (*((volatile unsigned char *)base+offset))
+ : "r" (val), "b" (base), "r" (offset));
+}
+
+static __inline__ void
+xf86WriteMmioNB16Be(__volatile__ void *base, const unsigned long offset,
+ const unsigned short val)
+{
+ __asm__ __volatile__(
+ "sthx %1,%2,%3\n\t"
+ : "=m" (*((volatile unsigned char *)base+offset))
+ : "r" (val), "b" (base), "r" (offset));
+}
+
+static __inline__ void
+xf86WriteMmioNB32Le(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ __asm__ __volatile__(
+ "stwbrx %1,%2,%3\n\t"
+ : "=m" (*((volatile unsigned char *)base+offset))
+ : "r" (val), "b" (base), "r" (offset));
+}
+
+static __inline__ void
+xf86WriteMmioNB32Be(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ __asm__ __volatile__(
+ "stwx %1,%2,%3\n\t"
+ : "=m" (*((volatile unsigned char *)base+offset))
+ : "r" (val), "b" (base), "r" (offset));
+}
+
+static __inline__ void
+xf86WriteMmio8(__volatile__ void *base, const unsigned long offset,
+ const unsigned char val)
+{
+ xf86WriteMmioNB8(base, offset, val);
+ eieio();
+}
+
+static __inline__ void
+xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset,
+ const unsigned short val)
+{
+ xf86WriteMmioNB16Le(base, offset, val);
+ eieio();
+}
+
+static __inline__ void
+xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset,
+ const unsigned short val)
+{
+ xf86WriteMmioNB16Be(base, offset, val);
+ eieio();
+}
+
+static __inline__ void
+xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ xf86WriteMmioNB32Le(base, offset, val);
+ eieio();
+}
+
+static __inline__ void
+xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset,
+ const unsigned int val)
+{
+ xf86WriteMmioNB32Be(base, offset, val);
+ eieio();
+}
+
+
+static __inline__ void
+outb(unsigned short port, unsigned char value)
+{
+ if(ioBase == MAP_FAILED) return;
+ xf86WriteMmio8((void *)ioBase, port, value);
+}
+
+static __inline__ void
+outw(unsigned short port, unsigned short value)
+{
+ if(ioBase == MAP_FAILED) return;
+ xf86WriteMmio16Le((void *)ioBase, port, value);
+}
+
+static __inline__ void
+outl(unsigned short port, unsigned int value)
+{
+ if(ioBase == MAP_FAILED) return;
+ xf86WriteMmio32Le((void *)ioBase, port, value);
+}
+
+static __inline__ unsigned int
+inb(unsigned short port)
+{
+ if(ioBase == MAP_FAILED) return 0;
+ return xf86ReadMmio8((void *)ioBase, port);
+}
+
+static __inline__ unsigned int
+inw(unsigned short port)
+{
+ if(ioBase == MAP_FAILED) return 0;
+ return xf86ReadMmio16Le((void *)ioBase, port);
+}
+
+static __inline__ unsigned int
+inl(unsigned short port)
+{
+ if(ioBase == MAP_FAILED) return 0;
+ return xf86ReadMmio32Le((void *)ioBase, port);
+}
+
+# define ldq_u(p) ldl_u(p)
+# define ldl_u(p) ((*(unsigned char *)(p)) | \
+ (*((unsigned char *)(p)+1)<<8) | \
+ (*((unsigned char *)(p)+2)<<16) | \
+ (*((unsigned char *)(p)+3)<<24))
+# define ldw_u(p) ((*(unsigned char *)(p)) | \
+ (*((unsigned char *)(p)+1)<<8))
+
+# define stq_u(v,p) stl_u(v,p)
+# define stl_u(v,p) (*(unsigned char *)(p)) = (v); \
+ (*((unsigned char *)(p)+1)) = ((v) >> 8); \
+ (*((unsigned char *)(p)+2)) = ((v) >> 16); \
+ (*((unsigned char *)(p)+3)) = ((v) >> 24)
+# define stw_u(v,p) (*(unsigned char *)(p)) = (v); \
+ (*((unsigned char *)(p)+1)) = ((v) >> 8)
+
+# define mem_barrier() eieio()
+# define write_mem_barrier() eieio()
+
+#elif defined(__arm__) && defined(__linux__)
+
+#define ldq_u(p) (*((unsigned long *)(p)))
+#define ldl_u(p) (*((unsigned int *)(p)))
+#define ldw_u(p) (*((unsigned short *)(p)))
+#define stq_u(v,p) (*(unsigned long *)(p)) = (v)
+#define stl_u(v,p) (*(unsigned int *)(p)) = (v)
+#define stw_u(v,p) (*(unsigned short *)(p)) = (v)
+#define mem_barrier() /* NOP */
+#define write_mem_barrier() /* NOP */
+
+/* for Linux on ARM, we use the LIBC inx/outx routines */
+/* note that the appropriate setup via "ioperm" needs to be done */
+/* *before* any inx/outx is done. */
+
+#include <sys/io.h>
+
+static __inline__ void
+xf_outb(unsigned short port, unsigned char val)
+{
+ outb(val, port);
+}
+
+static __inline__ void
+xf_outw(unsigned short port, unsigned short val)
+{
+ outw(val, port);
+}
+
+static __inline__ void
+xf_outl(unsigned short port, unsigned int val)
+{
+ outl(val, port);
+}
+
+#define outb xf_outb
+#define outw xf_outw
+#define outl xf_outl
+
+#define arm_flush_cache(addr) \
+do { \
+ register unsigned long _beg __asm ("a1") = (unsigned long) (addr); \
+ register unsigned long _end __asm ("a2") = (unsigned long) (addr) + 4;\
+ register unsigned long _flg __asm ("a3") = 0; \
+ __asm __volatile ("swi 0x9f0002 @ sys_cacheflush" \
+ : "=r" (_beg) \
+ : "0" (_beg), "r" (_end), "r" (_flg)); \
+} while (0)
+
+# else /* ix86 */
+
+# define ldq_u(p) (*((unsigned long *)(p)))
+# define ldl_u(p) (*((unsigned int *)(p)))
+# define ldw_u(p) (*((unsigned short *)(p)))
+# define stq_u(v,p) (*(unsigned long *)(p)) = (v)
+# define stl_u(v,p) (*(unsigned int *)(p)) = (v)
+# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
+# define mem_barrier() /* NOP */
+# define write_mem_barrier() /* NOP */
+
+# if !defined(__SUNPRO_C)
+# if !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__)
+# ifdef GCCUSESGAS
+
+/*
+ * If gcc uses gas rather than the native assembler, the syntax of these
+ * inlines has to be different. DHD
+ */
+
+static __inline__ void
+outb(unsigned short port, unsigned char val)
+{
+ __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
+}
+
+
+static __inline__ void
+outw(unsigned short port, unsigned short val)
+{
+ __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+outl(unsigned short port, unsigned int val)
+{
+ __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ unsigned int
+inb(unsigned short port)
+{
+ unsigned char ret;
+ __asm__ __volatile__("inb %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+inw(unsigned short port)
+{
+ unsigned short ret;
+ __asm__ __volatile__("inw %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+inl(unsigned short port)
+{
+ unsigned int ret;
+ __asm__ __volatile__("inl %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+# else /* GCCUSESGAS */
+
+static __inline__ void
+outb(unsigned short port, unsigned char val)
+{
+ __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+outw(unsigned short port, unsigned short val)
+{
+ __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+outl(unsigned short port, unsigned int val)
+{
+ __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
+}
+
+static __inline__ unsigned int
+inb(unsigned short port)
+{
+ unsigned char ret;
+ __asm__ __volatile__("in%B0 (%1)" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+inw(unsigned short port)
+{
+ unsigned short ret;
+ __asm__ __volatile__("in%W0 (%1)" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+inl(unsigned short port)
+{
+ unsigned int ret;
+ __asm__ __volatile__("in%L0 (%1)" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+# endif /* GCCUSESGAS */
+
+# else /* !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__)*/
+
+static __inline__ void
+outb(unsigned short port, unsigned char val)
+{
+}
+
+static __inline__ void
+outw(unsigned short port, unsigned short val)
+{
+}
+
+static __inline__ void
+outl(unsigned short port, unsigned int val)
+{
+}
+
+static __inline__ unsigned int
+inb(unsigned short port)
+{
+ return 0;
+}
+
+static __inline__ unsigned int
+inw(unsigned short port)
+{
+ return 0;
+}
+
+static __inline__ unsigned int
+inl(unsigned short port)
+{
+ return 0;
+}
+
+# endif /* FAKEIT */
+# endif /* __SUNPRO_C */
+
+# endif /* ix86 */
+
+# elif defined(__powerpc__) /* && !__GNUC__ */
+/*
+ * NON-GCC PowerPC - Presumed to be PowerMAX OS for now
+ */
+# ifndef PowerMAX_OS
+# error - Non-gcc PowerPC and !PowerMAXOS ???
+# endif
+
+# define PPCIO_DEBUG 0
+# define PPCIO_INLINE 1
+# define USE_ABS_MACRO 1
+/*
+ * Use compiler intrinsics to access certain PPC machine instructions
+ */
+# define eieio() __inst_eieio()
+# define stw_brx(val,base,ndx) __inst_sthbrx(val,base,ndx)
+# define stl_brx(val,base,ndx) __inst_stwbrx(val,base,ndx)
+# define ldw_brx(base,ndx) __inst_lhbrx(base,ndx)
+# define ldl_brx(base,ndx) __inst_lwbrx(base,ndx)
+
+# define ldq_u(p) (*((unsigned long long *)(p)))
+# define ldl_u(p) (*((unsigned long *)(p)))
+# define ldw_u(p) (*((unsigned short *)(p)))
+# define stq_u(v,p) (*(unsigned long long *)(p)) = (v)
+# define stl_u(v,p) (*(unsigned long *)(p)) = (v)
+# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
+# define mem_barrier() eieio()
+# define write_mem_barrier() eieio()
+
+extern volatile unsigned char *ioBase;
+
+# if !defined(abs) && defined(USE_ABS_MACRO)
+# define abs(x) ((x) >= 0 ? (x) : -(x))
+# endif
+
+# undef inb
+# undef inw
+# undef inl
+# undef outb
+# undef outw
+# undef outl
+
+# if PPCIO_DEBUG
+
+extern void debug_outb(unsigned int a, unsigned char b, int line, char *file);
+extern void debug_outw(unsigned int a, unsigned short w, int line, char *file);
+extern void debug_outl(unsigned int a, unsigned int l, int line, char *file);
+extern unsigned char debug_inb(unsigned int a, int line, char *file);
+extern unsigned short debug_inw(unsigned int a, int line, char *file);
+extern unsigned int debug_inl(unsigned int a, int line, char *file);
+
+# define outb(a,b) debug_outb(a,b, __LINE__, __FILE__)
+# define outw(a,w) debug_outw(a,w, __LINE__, __FILE__)
+# define outl(a,l) debug_outl(a,l, __LINE__, __FILE__)
+# define inb(a) debug_inb(a, __LINE__, __FILE__)
+# define inw(a) debug_inw(a, __LINE__, __FILE__)
+# define inl(a) debug_inl(a, __LINE__, __FILE__)
+
+# else /* !PPCIO_DEBUG */
+
+extern unsigned char inb(unsigned int a);
+extern unsigned short inw(unsigned int a);
+extern unsigned int inl(unsigned int a);
+
+# if PPCIO_INLINE
+
+# define outb(a,b) \
+ (*((volatile unsigned char *)(ioBase + (a))) = (b), eieio())
+# define outw(a,w) (stw_brx((w),ioBase,(a)), eieio())
+# define outl(a,l) (stl_brx((l),ioBase,(a)), eieio())
+
+# else /* !PPCIO_INLINE */
+
+extern void outb(unsigned int a, unsigned char b);
+extern void outw(unsigned int a, unsigned short w);
+extern void outl(unsigned int a, unsigned int l);
+
+# endif /* PPCIO_INLINE */
+
+# endif /* !PPCIO_DEBUG */
+
+# else /* !GNUC && !PPC */
+# if !defined(QNX4)
+# if defined(__STDC__) && (__STDC__ == 1)
+# ifndef asm
+# define asm __asm
+# endif
+# endif
+# ifndef SCO325
+# if defined(__UNIXWARE__)
+# if defined(IN_MODULE)
+# /* avoid including <sys/types.h> for <sys/inline.h> on UnixWare */
+# define ushort unsigned short
+# define ushort_t unsigned short
+# define ulong unsigned long
+# define ulong_t unsigned long
+# define uint_t unsigned int
+# define uchar_t unsigned char
+# else
+# include <sys/types.h>
+# endif /* IN_MODULE */
+# endif /* __UNIXWARE__ */
+# if !defined(sgi) && !defined(__SUNPRO_C)
+# include <sys/inline.h>
+# endif
+# else
+# include "scoasm.h"
+# endif
+# if (!defined(__HIGHC__) && !defined(sgi) && !defined(__SUNPRO_C)) || \
+ defined(__USLC__)
+# pragma asm partial_optimization outl
+# pragma asm partial_optimization outw
+# pragma asm partial_optimization outb
+# pragma asm partial_optimization inl
+# pragma asm partial_optimization inw
+# pragma asm partial_optimization inb
+# endif
+# endif
+# define ldq_u(p) (*((unsigned long *)(p)))
+# define ldl_u(p) (*((unsigned int *)(p)))
+# define ldw_u(p) (*((unsigned short *)(p)))
+# define stq_u(v,p) (*(unsigned long *)(p)) = (v)
+# define stl_u(v,p) (*(unsigned int *)(p)) = (v)
+# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
+# define mem_barrier() /* NOP */
+# define write_mem_barrier() /* NOP */
+# endif /* __GNUC__ */
+
+# if defined(QNX4)
+# include <sys/types.h>
+extern unsigned inb(unsigned port);
+extern unsigned inw(unsigned port);
+extern unsigned inl(unsigned port);
+extern void outb(unsigned port, unsigned val);
+extern void outw(unsigned port, unsigned val);
+extern void outl(unsigned port, unsigned val);
+# endif /* QNX4 */
+
+# if defined(IODEBUG) && defined(__GNUC__)
+# undef inb
+# undef inw
+# undef inl
+# undef outb
+# undef outw
+# undef outl
+# define inb(a) __extension__ ({unsigned char __c=RealInb(a); ErrorF("inb(0x%03x) = 0x%02x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
+# define inw(a) __extension__ ({unsigned short __c=RealInw(a); ErrorF("inw(0x%03x) = 0x%04x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
+# define inl(a) __extension__ ({unsigned int __c=RealInl(a); ErrorF("inl(0x%03x) = 0x%08x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
+
+# define outb(a,b) (ErrorF("outb(0x%03x, 0x%02x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutb(a,b))
+# define outw(a,b) (ErrorF("outw(0x%03x, 0x%04x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutw(a,b))
+# define outl(a,b) (ErrorF("outl(0x%03x, 0x%08x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutl(a,b))
+# endif
+
+# endif /* NO_INLINE */
+
+# ifdef __alpha__
+/* entry points for Mmio memory access routines */
+extern int (*xf86ReadMmio8)(void *, unsigned long);
+extern int (*xf86ReadMmio16)(void *, unsigned long);
+# ifndef STANDALONE_MMIO
+extern int (*xf86ReadMmio32)(void *, unsigned long);
+# else
+/* Some DRI 3D drivers need MMIO_IN32. */
+static __inline__ int
+xf86ReadMmio32(void *Base, unsigned long Offset)
+{
+ __asm__ __volatile__("mb" : : : "memory");
+ return *(volatile unsigned int*)((unsigned long)Base+(Offset));
+}
+# endif
+extern void (*xf86WriteMmio8)(int, void *, unsigned long);
+extern void (*xf86WriteMmio16)(int, void *, unsigned long);
+extern void (*xf86WriteMmio32)(int, void *, unsigned long);
+extern void (*xf86WriteMmioNB8)(int, void *, unsigned long);
+extern void (*xf86WriteMmioNB16)(int, void *, unsigned long);
+extern void (*xf86WriteMmioNB32)(int, void *, unsigned long);
+extern void xf86JensenMemToBus(char *, long, long, int);
+extern void xf86JensenBusToMem(char *, char *, unsigned long, int);
+extern void xf86SlowBCopyFromBus(unsigned char *, unsigned char *, int);
+extern void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
+
+/* Some macros to hide the system dependencies for MMIO accesses */
+/* Changed to kill noise generated by gcc's -Wcast-align */
+# define MMIO_IN8(base, offset) (*xf86ReadMmio8)(base, offset)
+# define MMIO_IN16(base, offset) (*xf86ReadMmio16)(base, offset)
+# ifndef STANDALONE_MMIO
+# define MMIO_IN32(base, offset) (*xf86ReadMmio32)(base, offset)
+# else
+# define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset)
+# endif
+
+# if defined (JENSEN_SUPPORT)
+# define MMIO_OUT32(base, offset, val) \
+ (*xf86WriteMmio32)((CARD32)(val), base, offset)
+# define MMIO_ONB32(base, offset, val) \
+ (*xf86WriteMmioNB32)((CARD32)(val), base, offset)
+# else
+# define MMIO_OUT32(base, offset, val) \
+ do { \
+ write_mem_barrier(); \
+ *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val); \
+ } while (0)
+# define MMIO_ONB32(base, offset, val) \
+ *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val)
+# endif
+
+# define MMIO_OUT8(base, offset, val) \
+ (*xf86WriteMmio8)((CARD8)(val), base, offset)
+# define MMIO_OUT16(base, offset, val) \
+ (*xf86WriteMmio16)((CARD16)(val), base, offset)
+# define MMIO_ONB8(base, offset, val) \
+ (*xf86WriteMmioNB8)((CARD8)(val), base, offset)
+# define MMIO_ONB16(base, offset, val) \
+ (*xf86WriteMmioNB16)((CARD16)(val), base, offset)
+# define MMIO_MOVE32(base, offset, val) \
+ MMIO_OUT32(base, offset, val)
+
+# elif defined(__powerpc__)
+ /*
+ * we provide byteswapping and no byteswapping functions here
+ * with byteswapping as default,
+ * drivers that don't need byteswapping should define PPC_MMIO_IS_BE
+ */
+# define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset)
+# define MMIO_OUT8(base, offset, val) \
+ xf86WriteMmio8(base, offset, (CARD8)(val))
+# define MMIO_ONB8(base, offset, val) \
+ xf86WriteMmioNB8(base, offset, (CARD8)(val))
+
+# if defined(PPC_MMIO_IS_BE) /* No byteswapping */
+# define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset)
+# define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset)
+# define MMIO_OUT16(base, offset, val) \
+ xf86WriteMmio16Be(base, offset, (CARD16)(val))
+# define MMIO_OUT32(base, offset, val) \
+ xf86WriteMmio32Be(base, offset, (CARD32)(val))
+# define MMIO_ONB16(base, offset, val) \
+ xf86WriteMmioNB16Be(base, offset, (CARD16)(val))
+# define MMIO_ONB32(base, offset, val) \
+ xf86WriteMmioNB32Be(base, offset, (CARD32)(val))
+# else /* byteswapping is the default */
+# define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset)
+# define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset)
+# define MMIO_OUT16(base, offset, val) \
+ xf86WriteMmio16Le(base, offset, (CARD16)(val))
+# define MMIO_OUT32(base, offset, val) \
+ xf86WriteMmio32Le(base, offset, (CARD32)(val))
+# define MMIO_ONB16(base, offset, val) \
+ xf86WriteMmioNB16Le(base, offset, (CARD16)(val))
+# define MMIO_ONB32(base, offset, val) \
+ xf86WriteMmioNB32Le(base, offset, (CARD32)(val))
+# endif
+
+# define MMIO_MOVE32(base, offset, val) \
+ xf86WriteMmio32Be(base, offset, (CARD32)(val))
+
+static __inline__ void ppc_flush_icache(char *addr)
+{
+ __asm__ volatile (
+ "dcbf 0,%0;"
+ "sync;"
+ "icbi 0,%0;"
+ "sync;"
+ "isync;"
+ : : "r"(addr) : "memory");
+}
+
+# elif defined(__sparc__) || defined(sparc)
+ /*
+ * Like powerpc, we provide byteswapping and no byteswapping functions
+ * here with byteswapping as default, drivers that don't need byteswapping
+ * should define SPARC_MMIO_IS_BE (perhaps create a generic macro so that we
+ * do not need to use PPC_MMIO_IS_BE and the sparc one in all the same places
+ * of drivers?).
+ */
+# define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset)
+# define MMIO_OUT8(base, offset, val) \
+ xf86WriteMmio8(base, offset, (CARD8)(val))
+# define MMIO_ONB8(base, offset, val) \
+ xf86WriteMmio8NB(base, offset, (CARD8)(val))
+
+# if defined(SPARC_MMIO_IS_BE) /* No byteswapping */
+# define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset)
+# define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset)
+# define MMIO_OUT16(base, offset, val) \
+ xf86WriteMmio16Be(base, offset, (CARD16)(val))
+# define MMIO_OUT32(base, offset, val) \
+ xf86WriteMmio32Be(base, offset, (CARD32)(val))
+# define MMIO_ONB16(base, offset, val) \
+ xf86WriteMmio16BeNB(base, offset, (CARD16)(val))
+# define MMIO_ONB32(base, offset, val) \
+ xf86WriteMmio32BeNB(base, offset, (CARD32)(val))
+# else /* byteswapping is the default */
+# define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset)
+# define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset)
+# define MMIO_OUT16(base, offset, val) \
+ xf86WriteMmio16Le(base, offset, (CARD16)(val))
+# define MMIO_OUT32(base, offset, val) \
+ xf86WriteMmio32Le(base, offset, (CARD32)(val))
+# define MMIO_ONB16(base, offset, val) \
+ xf86WriteMmio16LeNB(base, offset, (CARD16)(val))
+# define MMIO_ONB32(base, offset, val) \
+ xf86WriteMmio32LeNB(base, offset, (CARD32)(val))
+# endif
+
+# define MMIO_MOVE32(base, offset, val) \
+ xf86WriteMmio32Be(base, offset, (CARD32)(val))
+
+# else /* !__alpha__ && !__powerpc__ && !__sparc__ */
+
+# define MMIO_IN8(base, offset) \
+ *(volatile CARD8 *)(((CARD8*)(base)) + (offset))
+# define MMIO_IN16(base, offset) \
+ *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset))
+# define MMIO_IN32(base, offset) \
+ *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset))
+# define MMIO_OUT8(base, offset, val) \
+ *(volatile CARD8 *)(((CARD8*)(base)) + (offset)) = (val)
+# define MMIO_OUT16(base, offset, val) \
+ *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset)) = (val)
+# define MMIO_OUT32(base, offset, val) \
+ *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val)
+# define MMIO_ONB8(base, offset, val) MMIO_OUT8(base, offset, val)
+# define MMIO_ONB16(base, offset, val) MMIO_OUT16(base, offset, val)
+# define MMIO_ONB32(base, offset, val) MMIO_OUT32(base, offset, val)
+
+# define MMIO_MOVE32(base, offset, val) MMIO_OUT32(base, offset, val)
+
+# endif /* __alpha__ */
+
+/*
+ * With Intel, the version in os-support/misc/SlowBcopy.s is used.
+ * This avoids port I/O during the copy (which causes problems with
+ * some hardware).
+ */
+# ifdef __alpha__
+# define slowbcopy_tobus(src,dst,count) xf86SlowBCopyToBus(src,dst,count)
+# define slowbcopy_frombus(src,dst,count) xf86SlowBCopyFromBus(src,dst,count)
+# else /* __alpha__ */
+# define slowbcopy_tobus(src,dst,count) xf86SlowBcopy(src,dst,count)
+# define slowbcopy_frombus(src,dst,count) xf86SlowBcopy(src,dst,count)
+# endif /* __alpha__ */
+
+#endif /* _COMPILER_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/fourcc.h b/nx-X11/programs/Xserver/hw/xfree86/common/fourcc.h
new file mode 100644
index 000000000..e60aa4e83
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/fourcc.h
@@ -0,0 +1,161 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/fourcc.h,v 1.5 2003/08/24 17:36:48 dawes Exp $ */
+
+/*
+ * Copyright (c) 2000-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 header file contains listings of STANDARD guids for video formats.
+ Please do not place non-registered, or incomplete entries in this file.
+ A list of some popular fourcc's are at: http://www.webartz.com/fourcc/
+ For an explanation of fourcc <-> guid mappings see RFC2361.
+*/
+
+#ifndef _XF86_FOURCC_H_
+#define _XF86_FOURCC_H_ 1
+
+#define FOURCC_YUY2 0x32595559
+#define XVIMAGE_YUY2 \
+ { \
+ FOURCC_YUY2, \
+ XvYUV, \
+ LSBFirst, \
+ {'Y','U','Y','2', \
+ 0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71}, \
+ 16, \
+ XvPacked, \
+ 1, \
+ 0, 0, 0, 0, \
+ 8, 8, 8, \
+ 1, 2, 2, \
+ 1, 1, 1, \
+ {'Y','U','Y','V', \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \
+ XvTopToBottom \
+ }
+
+#define FOURCC_YV12 0x32315659
+#define XVIMAGE_YV12 \
+ { \
+ FOURCC_YV12, \
+ XvYUV, \
+ LSBFirst, \
+ {'Y','V','1','2', \
+ 0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71}, \
+ 12, \
+ XvPlanar, \
+ 3, \
+ 0, 0, 0, 0, \
+ 8, 8, 8, \
+ 1, 2, 2, \
+ 1, 2, 2, \
+ {'Y','V','U', \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \
+ XvTopToBottom \
+ }
+
+#define FOURCC_I420 0x30323449
+#define XVIMAGE_I420 \
+ { \
+ FOURCC_I420, \
+ XvYUV, \
+ LSBFirst, \
+ {'I','4','2','0', \
+ 0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71}, \
+ 12, \
+ XvPlanar, \
+ 3, \
+ 0, 0, 0, 0, \
+ 8, 8, 8, \
+ 1, 2, 2, \
+ 1, 2, 2, \
+ {'Y','U','V', \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \
+ XvTopToBottom \
+ }
+
+
+#define FOURCC_UYVY 0x59565955
+#define XVIMAGE_UYVY \
+ { \
+ FOURCC_UYVY, \
+ XvYUV, \
+ LSBFirst, \
+ {'U','Y','V','Y', \
+ 0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71}, \
+ 16, \
+ XvPacked, \
+ 1, \
+ 0, 0, 0, 0, \
+ 8, 8, 8, \
+ 1, 2, 2, \
+ 1, 1, 1, \
+ {'U','Y','V','Y', \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \
+ XvTopToBottom \
+ }
+
+#define FOURCC_IA44 0x34344149
+#define XVIMAGE_IA44 \
+ { \
+ FOURCC_IA44, \
+ XvYUV, \
+ LSBFirst, \
+ {'I','A','4','4', \
+ 0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71}, \
+ 8, \
+ XvPacked, \
+ 1, \
+ 0, 0, 0, 0, \
+ 8, 8, 8, \
+ 1, 1, 1, \
+ 1, 1, 1, \
+ {'A','I', \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \
+ XvTopToBottom \
+ }
+
+#define FOURCC_AI44 0x34344941
+#define XVIMAGE_AI44 \
+ { \
+ FOURCC_AI44, \
+ XvYUV, \
+ LSBFirst, \
+ {'A','I','4','4', \
+ 0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71}, \
+ 8, \
+ XvPacked, \
+ 1, \
+ 0, 0, 0, 0, \
+ 8, 8, 8, \
+ 1, 1, 1, \
+ 1, 1, 1, \
+ {'I','A', \
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \
+ XvTopToBottom \
+ }
+
+#endif /* _XF86_FOURCC_H_ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/modeline2c.pl b/nx-X11/programs/Xserver/hw/xfree86/common/modeline2c.pl
new file mode 100644
index 000000000..cc6c6925e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/modeline2c.pl
@@ -0,0 +1,110 @@
+#!/usr/bin/perl
+
+# automatically generate the xf86DefModeSet.c file from a normal
+# XF86Config style file of Modelines
+#
+# run as
+#
+# perl /modeline2c.pl < [modesfile] > xf86DefModes.c
+#
+# hackish perl - author Dirk Hohndel
+#
+# Copyright 1999-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).
+#
+# $XFree86: xc/programs/Xserver/hw/xfree86/common/modeline2c.pl,v 1.10tsi Exp $
+
+#my %flagshash;
+$flagshash{""} = "0";
+# $flagshash{"Interlace"} = "V_INTERLACE";
+# $flagshash{"+hsync"} = "V_PHSYNC";
+# $flagshash{"-hsync"} = "V_NHSYNC";
+# $flagshash{"+vsync"} = "V_PVSYNC";
+# $flagshash{"-vsync"} = "V_NVSYNC";
+# XXX I'm definitely not a perl guru... -- tsi
+$flagshash{"+hsync +vsync"} = "V_PHSYNC | V_PVSYNC";
+$flagshash{"+hsync -vsync"} = "V_PHSYNC | V_NVSYNC";
+$flagshash{"-hsync +vsync"} = "V_NHSYNC | V_PVSYNC";
+$flagshash{"-hsync -vsync"} = "V_NHSYNC | V_NVSYNC";
+$flagshash{"+hsync +vsync interlace"} = "V_PHSYNC | V_PVSYNC | V_INTERLACE";
+$flagshash{"+hsync -vsync interlace"} = "V_PHSYNC | V_NVSYNC | V_INTERLACE";
+$flagshash{"-hsync +vsync interlace"} = "V_NHSYNC | V_PVSYNC | V_INTERLACE";
+$flagshash{"-hsync -vsync interlace"} = "V_NHSYNC | V_NVSYNC | V_INTERLACE";
+
+# stop CVS from expanding the XFree86 Id here...
+
+$proj = "XFree86";
+printf("/* \$$proj\$ */
+
+/* THIS FILE IS AUTOMATICALLY GENERATED -- DO NOT EDIT -- LOOK at
+ * modeline2c.pl */
+
+/*
+ * Copyright 1999-2003 by The XFree86 Project, Inc.
+ *
+ * Author: Dirk Hohndel <hohndel\@XFree86.Org>
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+#include \"xf86.h\"
+#include \"xf86Config.h\"
+#include \"xf86Priv.h\"
+#include \"xf86_OSlib.h\"
+
+#include \"globals.h\"
+
+#define MODEPREFIX(name) NULL, NULL, name, MODE_OK, M_T_DEFAULT
+#define MODESUFFIX 0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0
+
+DisplayModeRec xf86DefaultModes [] = {
+");
+while (<>) {
+ if (/^\#/) {
+ s/^\#//;
+ chop;
+ print "/*" . $_ . " */\n";
+ }
+ if (/^ModeLine\s+(\S+)\s+([\d.\s]+)(.*)/i) {
+ $name = $1;
+ $values = $2;
+ $flags = $3;
+ $flags =~ y/A-Z/a-z/;
+ $values =~ /([\d.]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
+ printf("\t{MODEPREFIX(%s),%d, %d,%d,%d,%d,0, %d,%d,%d,%d,0, %s, MODESUFFIX},\n",
+ $name,$1*1000,$2,$3,$4,$5,$6,$7,$8,$9,$flagshash{$flags});
+# Also generate half-width doublescanned modes
+ printf("\t{MODEPREFIX(\"%dx%d\"),%d, %d,%d,%d,%d,0, %d,%d,%d,%d,0, %s | V_DBLSCAN, MODESUFFIX},\n",
+ $2/2,$6/2,$1*500,$2/2,$3/2,$4/2,$5/2,$6/2,$7/2,$8/2,$9/2,$flagshash{$flags});
+ }
+
+
+}
+printf("\t{MODEPREFIX(NULL),0,0,0,0,0,0,0,0,0,0,0,0,MODESUFFIX}\n};\n");
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/scoasm.h b/nx-X11/programs/Xserver/hw/xfree86/common/scoasm.h
new file mode 100644
index 000000000..5a5af8eb9
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/scoasm.h
@@ -0,0 +1,143 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/scoasm.h,v 3.1 2003/08/24 17:36:49 dawes Exp $ */
+
+/*
+ * Copyright (c) 1996 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).
+ */
+
+/*
+ * scoasm.h - used to define inline versions of certain functions which
+ * do NOT appear in sys/inline.h.
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#if defined(__SCO__) && defined(__USLC__)
+#ifndef _SCOASM_HDR_INC
+#define _SCOASM_HDR_INC
+
+asm void outl(port,val)
+{
+%reg port,val;
+ movl port, %edx
+ movl val, %eax
+ outl (%dx)
+%reg port; mem val;
+ movl port, %edx
+ movl val, %eax
+ outl (%dx)
+%mem port; reg val;
+ movw port, %dx
+ movl val, %eax
+ outl (%dx)
+%mem port,val;
+ movw port, %dx
+ movl val, %eax
+ outl (%dx)
+}
+
+asm void outw(port,val)
+{
+%reg port,val;
+ movl port, %edx
+ movl val, %eax
+ data16
+ outl (%dx)
+%reg port; mem val;
+ movl port, %edx
+ movw val, %ax
+ data16
+ outl (%dx)
+%mem port; reg val;
+ movw port, %dx
+ movl val, %eax
+ data16
+ outl (%dx)
+%mem port,val;
+ movw port, %dx
+ movw val, %ax
+ data16
+ outl (%dx)
+}
+
+asm void outb(port,val)
+{
+%reg port,val;
+ movl port, %edx
+ movl val, %eax
+ outb (%dx)
+%reg port; mem val;
+ movl port, %edx
+ movb val, %al
+ outb (%dx)
+%mem port; reg val;
+ movw port, %dx
+ movl val, %eax
+ outb (%dx)
+%mem port,val;
+ movw port, %dx
+ movb val, %al
+ outb (%dx)
+}
+
+asm int inl(port)
+{
+%reg port;
+ movl port, %edx
+ inl (%dx)
+%mem port;
+ movw port, %dx
+ inl (%dx)
+}
+
+asm int inw(port)
+{
+%reg port;
+ subl %eax, %eax
+ movl port, %edx
+ data16
+ inl (%dx)
+%mem port;
+ subl %eax, %eax
+ movw port, %dx
+ data16
+ inl (%dx)
+}
+
+asm int inb(port)
+{
+%reg port;
+ subl %eax, %eax
+ movl port, %edx
+ inb (%dx)
+%mem port;
+ subl %eax, %eax
+ movw port, %dx
+ inb (%dx)
+}
+
+#endif /* _SCOASM_HDR_INC */
+#endif /* __SCO__ && __USLC__ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86.h
new file mode 100644
index 000000000..010360cf3
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86.h
@@ -0,0 +1,447 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86.h,v 3.173 2004/01/27 01:31:44 dawes Exp $ */
+
+/*
+ * 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 declarations for public XFree86 functions and variables,
+ * and definitions of public macros.
+ *
+ * "public" means available to video drivers.
+ */
+
+#ifndef _XF86_H
+#define _XF86_H
+
+#include "xf86str.h"
+#include "xf86Opt.h"
+#include <X11/Xfuncproto.h>
+#ifndef IN_MODULE
+#include <stdarg.h>
+#else
+#include "xf86_ansic.h"
+#endif
+#ifdef RANDR
+#include <X11/extensions/randr.h>
+#endif
+
+#include "propertyst.h"
+
+/* General parameters */
+extern int xf86DoConfigure;
+extern Bool xf86DoConfigurePass1;
+extern int xf86ScreenIndex; /* Index into pScreen.devPrivates */
+extern int xf86CreateRootWindowIndex; /* Index into pScreen.devPrivates */
+extern int xf86PixmapIndex;
+extern Bool xf86ResAccessEnter;
+extern ScrnInfoPtr *xf86Screens; /* List of pointers to ScrnInfoRecs */
+extern const unsigned char byte_reversed[256];
+extern ScrnInfoPtr xf86CurrentScreen;
+extern Bool pciSlotClaimed;
+extern Bool isaSlotClaimed;
+extern Bool fbSlotClaimed;
+#ifdef __sparc__
+extern Bool sbusSlotClaimed;
+#endif
+extern confDRIRec xf86ConfigDRI;
+extern Bool xf86inSuspend;
+
+#define XF86SCRNINFO(p) ((ScrnInfoPtr)((p)->devPrivates[xf86ScreenIndex].ptr))
+
+#define XF86FLIP_PIXELS() \
+ do { \
+ if (xf86GetFlipPixels()) { \
+ pScreen->whitePixel = (pScreen->whitePixel) ? 0 : 1; \
+ pScreen->blackPixel = (pScreen->blackPixel) ? 0 : 1; \
+ } \
+ while (0)
+
+#define BOOLTOSTRING(b) ((b) ? "TRUE" : "FALSE")
+
+#define PIX24TOBPP(p) (((p) == Pix24Use24) ? 24 : \
+ (((p) == Pix24Use32) ? 32 : 0))
+
+/* variables for debugging */
+#ifdef BUILDDEBUG
+extern char* xf86p8bit[];
+extern CARD32 xf86DummyVar1;
+extern CARD32 xf86DummyVar2;
+extern CARD32 xf86DummyVar3;
+#endif
+
+/* Function Prototypes */
+#ifndef _NO_XF86_PROTOTYPES
+
+/* xf86Bus.c */
+
+Bool xf86CheckPciSlot(int bus, int device, int func);
+int xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp,
+ int chipset, GDevPtr dev, Bool active);
+Bool xf86ParsePciBusString(const char *busID, int *bus, int *device,
+ int *func);
+Bool xf86ComparePciBusString(const char *busID, int bus, int device, int func);
+void xf86FormatPciBusNumber(int busnum, char *buffer);
+pciVideoPtr *xf86GetPciVideoInfo(void);
+pciConfigPtr *xf86GetPciConfigInfo(void);
+void xf86SetPciVideo(pciVideoPtr, resType);
+void xf86PrintResList(int verb, resPtr list);
+resPtr xf86AddRangesToList(resPtr list, resRange *pRange, int entityIndex);
+int xf86ClaimIsaSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active);
+int xf86GetIsaInfoForScreen(int scrnIndex);
+int xf86GetFbInfoForScreen(int scrnIndex);
+Bool xf86ParseIsaBusString(const char *busID);
+int xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active);
+int xf86ClaimNoSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active);
+void xf86EnableAccess(ScrnInfoPtr pScrn);
+void xf86SetCurrentAccess(Bool Enable, ScrnInfoPtr pScrn);
+Bool xf86IsPrimaryPci(pciVideoPtr pPci);
+Bool xf86IsPrimaryIsa(void);
+int xf86CheckPciGAType(pciVideoPtr pPci);
+/* new RAC */
+resPtr xf86AddResToList(resPtr rlist, resRange *Range, int entityIndex);
+resPtr xf86JoinResLists(resPtr rlist1, resPtr rlist2);
+resPtr xf86DupResList(const resPtr rlist);
+void xf86FreeResList(resPtr rlist);
+void xf86ClaimFixedResources(resList list, int entityIndex);
+Bool xf86DriverHasEntities(DriverPtr drvp);
+void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex);
+void xf86SetEntityInstanceForScreen(ScrnInfoPtr pScrn, int entityIndex,
+ int instance);
+int xf86GetNumEntityInstances(int entityIndex);
+GDevPtr xf86GetDevFromEntity(int entityIndex, int instance);
+void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex);
+EntityInfoPtr xf86GetEntityInfo(int entityIndex);
+pciVideoPtr xf86GetPciInfoForEntity(int entityIndex);
+int xf86GetPciEntity(int bus, int dev, int func);
+Bool xf86SetEntityFuncs(int entityIndex, EntityProc init,
+ EntityProc enter, EntityProc leave, pointer);
+void xf86DeallocateResourcesForEntity(int entityIndex, unsigned long type);
+resPtr xf86RegisterResources(int entityIndex, resList list,
+ unsigned long Access);
+Bool xf86CheckPciMemBase(pciVideoPtr pPci, memType base);
+void xf86SetAccessFuncs(EntityInfoPtr pEnt, xf86SetAccessFuncPtr funcs,
+ xf86SetAccessFuncPtr oldFuncs);
+Bool xf86IsEntityPrimary(int entityIndex);
+Bool xf86FixPciResource(int entityIndex, int prt, memType alignment,
+ unsigned long type);
+resPtr xf86ReallocatePciResources(int entityIndex, resPtr pRes);
+resPtr xf86SetOperatingState(resList list, int entityIndex, int mask);
+void xf86EnterServerState(xf86State state);
+resRange xf86GetBlock(unsigned long type, memType size,
+ memType window_start, memType window_end,
+ memType align_mask, resPtr avoid);
+resRange xf86GetSparse(unsigned long type, memType fixed_bits,
+ memType decode_mask, memType address_mask,
+ resPtr avoid);
+memType xf86ChkConflict(resRange *rgp, int entityIndex);
+Bool xf86IsPciDevPresent(int bus, int dev, int func);
+ScrnInfoPtr xf86FindScreenForEntity(int entityIndex);
+Bool xf86NoSharedResources(int screenIndex, resType res);
+resPtr xf86FindIntersectOfLists(resPtr l1, resPtr l2);
+pciVideoPtr xf86FindPciDeviceVendor(CARD16 vendorID, CARD16 deviceID,
+ char n, pciVideoPtr pvp_exclude);
+pciVideoPtr xf86FindPciClass(CARD8 intf, CARD8 subClass, CARD16 class,
+ char n, pciVideoPtr pvp_exclude);
+#ifdef INCLUDE_DEPRECATED
+void xf86EnablePciBusMaster(pciVideoPtr pPci, Bool enable);
+#endif
+void xf86RegisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func, pointer arg);
+Bool xf86DeregisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func);
+#ifdef async
+Bool xf86QueueAsyncEvent(void (*func)(pointer),pointer arg);
+#endif
+
+int xf86GetLastScrnFlag(int entityIndex);
+void xf86SetLastScrnFlag(int entityIndex, int scrnIndex);
+Bool xf86IsEntityShared(int entityIndex);
+void xf86SetEntityShared(int entityIndex);
+Bool xf86IsEntitySharable(int entityIndex);
+void xf86SetEntitySharable(int entityIndex);
+Bool xf86IsPrimInitDone(int entityIndex);
+void xf86SetPrimInitDone(int entityIndex);
+void xf86ClearPrimInitDone(int entityIndex);
+int xf86AllocateEntityPrivateIndex(void);
+DevUnion *xf86GetEntityPrivate(int entityIndex, int privIndex);
+
+/* xf86Configure.c */
+GDevPtr xf86AddBusDeviceToConfigure(const char *driver, BusType bus,
+ void *busData, int chipset);
+GDevPtr xf86AddDeviceToConfigure(const char *driver, pciVideoPtr pVideo,
+ int chipset);
+
+/* xf86Cursor.c */
+
+void xf86LockZoom(ScreenPtr pScreen, int lock);
+void xf86InitViewport(ScrnInfoPtr pScr);
+void xf86SetViewport(ScreenPtr pScreen, int x, int y);
+void xf86ZoomViewport(ScreenPtr pScreen, int zoom);
+Bool xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode);
+void *xf86GetPointerScreenFuncs(void);
+void xf86InitOrigins(void);
+void xf86ReconfigureLayout(void);
+
+/* xf86DPMS.c */
+
+Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags);
+
+/* xf86DGA.c */
+
+Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs, DGAModePtr modes,
+ int num);
+Bool DGAReInitModes(ScreenPtr pScreen, DGAModePtr modes, int num);
+xf86SetDGAModeProc xf86SetDGAMode;
+
+/* xf86Events.c */
+
+void SetTimeSinceLastInputEvent(void);
+pointer xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data);
+int xf86RemoveInputHandler(pointer handler);
+void xf86DisableInputHandler(pointer handler);
+void xf86EnableInputHandler(pointer handler);
+void xf86InterceptSignals(int *signo);
+void xf86InterceptSigIll(void (*sigillhandler)(void));
+Bool xf86EnableVTSwitch(Bool new);
+Bool xf86CommonSpecialKey(int key, Bool down, int modifiers);
+void xf86ProcessActionEvent(ActionEvent action, void *arg);
+
+/* xf86Helper.c */
+
+void xf86AddDriver(DriverPtr driver, pointer module, int flags);
+void xf86DeleteDriver(int drvIndex);
+ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags);
+void xf86DeleteScreen(int scrnIndex, int flags);
+int xf86AllocateScrnInfoPrivateIndex(void);
+Bool xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad);
+Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp, int fbbpp,
+ int depth24flags);
+void xf86PrintDepthBpp(ScrnInfoPtr scrp);
+Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask);
+Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual);
+Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma newGamma);
+void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y);
+void xf86SetBlackWhitePixels(ScreenPtr pScreen);
+void xf86EnableDisableFBAccess(int scrnIndex, Bool enable);
+void xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb,
+ const char *format, va_list args);
+void xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb,
+ const char *format, ...) _printf_attribute(4,5);
+void xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...)
+ _printf_attribute(3,4);
+void xf86MsgVerb(MessageType type, int verb, const char *format, ...)
+ _printf_attribute(3,4);
+void xf86Msg(MessageType type, const char *format, ...) _printf_attribute(2,3);
+void xf86ErrorFVerb(int verb, const char *format, ...) _printf_attribute(2,3);
+void xf86ErrorF(const char *format, ...) _printf_attribute(1,2);
+const char *xf86TokenToString(SymTabPtr table, int token);
+int xf86StringToToken(SymTabPtr table, const char *string);
+void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from);
+void xf86PrintChipsets(const char *drvname, const char *drvmsg,
+ SymTabPtr chips);
+int xf86MatchDevice(const char *drivername, GDevPtr **driversectlist);
+int xf86MatchPciInstances(const char *driverName, int vendorID,
+ SymTabPtr chipsets, PciChipsets *PCIchipsets,
+ GDevPtr *devList, int numDevs, DriverPtr drvp,
+ int **foundEntities);
+int xf86MatchIsaInstances(const char *driverName, SymTabPtr chipsets,
+ IsaChipsets *ISAchipsets, DriverPtr drvp,
+ FindIsaDevProc FindIsaDevice, GDevPtr *devList,
+ int numDevs, int **foundEntities);
+void xf86GetClocks(ScrnInfoPtr pScrn, int num,
+ Bool (*ClockFunc)(ScrnInfoPtr, int),
+ void (*ProtectRegs)(ScrnInfoPtr, Bool),
+ void (*BlankScreen)(ScrnInfoPtr, Bool),
+ IOADDRESS vertsyncreg, int maskval,
+ int knownclkindex, int knownclkvalue);
+void xf86SetPriority(Bool up);
+const char *xf86GetVisualName(int visual);
+int xf86GetVerbosity(void);
+Pix24Flags xf86GetPix24(void);
+int xf86GetDepth(void);
+rgb xf86GetWeight(void);
+Gamma xf86GetGamma(void);
+Bool xf86GetFlipPixels(void);
+const char *xf86GetServerName(void);
+Bool xf86ServerIsExiting(void);
+Bool xf86ServerIsResetting(void);
+Bool xf86ServerIsInitialising(void);
+Bool xf86ServerIsOnlyDetecting(void);
+Bool xf86ServerIsOnlyProbing(void);
+Bool xf86CaughtSignal(void);
+Bool xf86GetVidModeAllowNonLocal(void);
+Bool xf86GetVidModeEnabled(void);
+Bool xf86GetModInDevAllowNonLocal(void);
+Bool xf86GetModInDevEnabled(void);
+Bool xf86GetAllowMouseOpenFail(void);
+Bool xf86IsPc98(void);
+void xf86DisableRandR(void);
+CARD32 xf86GetVersion(void);
+CARD32 xorgGetVersion(void);
+CARD32 xf86GetModuleVersion(pointer module);
+pointer xf86LoadDrvSubModule(DriverPtr drv, const char *name);
+pointer xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name);
+pointer xf86LoadOneModule(char *name, pointer optlist);
+void xf86UnloadSubModule(pointer mod);
+Bool xf86LoaderCheckSymbol(const char *name);
+void xf86LoaderReqSymLists(const char **, ...);
+void xf86LoaderReqSymbols(const char *, ...);
+void xf86LoaderRefSymLists(const char **, ...);
+void xf86LoaderRefSymbols(const char *, ...);
+void xf86SetBackingStore(ScreenPtr pScreen);
+void xf86SetSilkenMouse(ScreenPtr pScreen);
+int xf86NewSerialNumber(WindowPtr p, pointer unused);
+pointer xf86FindXvOptions(int scrnIndex, int adapt_index, char *port_name,
+ char **adaptor_name, pointer *adaptor_options);
+void xf86GetOS(const char **name, int *major, int *minor, int *teeny);
+ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn, int scrnFlag,
+ int entityIndex,PciChipsets *p_chip,
+ resList res, EntityProc init,
+ EntityProc enter, EntityProc leave,
+ pointer private);
+ScrnInfoPtr xf86ConfigIsaEntity(ScrnInfoPtr pScrn, int scrnFlag,
+ int entityIndex, IsaChipsets *i_chip,
+ resList res, EntityProc init,
+ EntityProc enter, EntityProc leave,
+ pointer private);
+ScrnInfoPtr xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag,
+ int entityIndex, EntityProc init,
+ EntityProc enter, EntityProc leave,
+ pointer private);
+/* Obsolete! don't use */
+Bool xf86ConfigActivePciEntity(ScrnInfoPtr pScrn,
+ int entityIndex,PciChipsets *p_chip,
+ resList res, EntityProc init,
+ EntityProc enter, EntityProc leave,
+ pointer private);
+/* Obsolete! don't use */
+Bool xf86ConfigActiveIsaEntity(ScrnInfoPtr pScrn,
+ int entityIndex, IsaChipsets *i_chip,
+ resList res, EntityProc init,
+ EntityProc enter, EntityProc leave,
+ pointer private);
+void xf86ConfigPciEntityInactive(EntityInfoPtr pEnt, PciChipsets *p_chip,
+ resList res, EntityProc init,
+ EntityProc enter, EntityProc leave,
+ pointer private);
+void xf86ConfigIsaEntityInactive(EntityInfoPtr pEnt, IsaChipsets *i_chip,
+ resList res, EntityProc init,
+ EntityProc enter, EntityProc leave,
+ pointer private);
+void xf86ConfigFbEntityInactive(EntityInfoPtr pEnt, EntityProc init,
+ EntityProc enter, EntityProc leave,
+ pointer private);
+Bool xf86IsScreenPrimary(int scrnIndex);
+int xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type,
+ int format, unsigned long len,
+ pointer value);
+Bool xf86IsUnblank(int mode);
+
+#ifdef XFree86LOADER
+void xf86AddModuleInfo(ModuleInfoPtr info, pointer module);
+void xf86DeleteModuleInfo(int idx);
+#endif
+
+/* xf86Debug.c */
+#ifdef BUILDDEBUG
+ void xf86Break1(void);
+void xf86Break2(void);
+void xf86Break3(void);
+CARD8 xf86PeekFb8(CARD8 *p);
+CARD16 xf86PeekFb16(CARD16 *p);
+CARD32 xf86PeekFb32(CARD32 *p);
+void xf86PokeFb8(CARD8 *p, CARD8 v);
+void xf86PokeFb16(CARD16 *p, CARD16 v);
+void xf86PokeFb32(CARD16 *p, CARD32 v);
+CARD8 xf86PeekMmio8(pointer Base, unsigned long Offset);
+CARD16 xf86PeekMmio16(pointer Base, unsigned long Offset);
+CARD32 xf86PeekMmio32(pointer Base, unsigned long Offset);
+void xf86PokeMmio8(pointer Base, unsigned long Offset, CARD8 v);
+void xf86PokeMmio16(pointer Base, unsigned long Offset, CARD16 v);
+void xf86PokeMmio32(pointer Base, unsigned long Offset, CARD32 v);
+extern void xf86SPTimestamp(xf86TsPtr* timestamp, char* string);
+extern void xf86STimestamp(xf86TsPtr* timestamp);
+#endif
+
+/* xf86Init.c */
+
+PixmapFormatPtr xf86GetPixFormat(ScrnInfoPtr pScrn, int depth);
+int xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth);
+
+/* xf86Mode.c */
+
+int xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
+ int DivFactor, int MulFactor, int *divider);
+const char *xf86ModeStatusToString(ModeStatus status);
+ModeStatus xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
+ ClockRangePtr clockRanges, LookupModeFlags strategy);
+ModeStatus xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor);
+ModeStatus xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode,
+ ClockRangePtr clockRanges,
+ LookupModeFlags strategy,
+ int maxPitch, int virtualX,
+ int virtualY);
+ModeStatus xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode,
+ int flags);
+int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
+ char **modeNames, ClockRangePtr clockRanges,
+ int *linePitches, int minPitch, int maxPitch,
+ int minHeight, int maxHeight, int pitchInc,
+ int virtualX, int virtualY, int apertureSize,
+ LookupModeFlags strategy);
+void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode);
+void xf86PruneDriverModes(ScrnInfoPtr scrp);
+void xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags);
+void xf86PrintModes(ScrnInfoPtr scrp);
+void xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges);
+
+/* xf86Option.c */
+
+void xf86CollectOptions(ScrnInfoPtr pScrn, pointer extraOpts);
+
+
+/* xf86RandR.c */
+#ifdef RANDR
+Bool xf86RandRInit (ScreenPtr pScreen);
+void xf86RandRSetInitialMode (ScreenPtr pScreen);
+Rotation xf86GetRotation(ScreenPtr pScreen);
+Bool xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen,
+ int newvirtX, int newvirtY,
+ int newmmWidth, int newmmHeight, Bool resetMode);
+#endif
+
+/* xf86VidModeExtentionInit.c */
+
+Bool VidModeExtensionInit(ScreenPtr pScreen);
+
+/* xf86Versions.c */
+CARD32 xf86GetBuiltinInterfaceVersion(BuiltinInterface iface, int flag);
+Bool xf86RegisterBuiltinInterfaceVersion(BuiltinInterface iface,
+ CARD32 version, int flags);
+
+
+#endif /* _NO_XF86_PROTOTYPES */
+
+#endif /* _XF86_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86AutoConfig.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86AutoConfig.c
new file mode 100644
index 000000000..36e400cd1
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86AutoConfig.c
@@ -0,0 +1,368 @@
+/* $DHD: xc/programs/Xserver/hw/xfree86/common/xf86AutoConfig.c,v 1.15 2003/09/24 19:39:36 dawes Exp $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86AutoConfig.c,v 1.4 2005/08/23 20:12:26 alanc Exp $ */
+
+/*
+ * Copyright 2003 by David H. Dawes.
+ * Copyright 2003 by X-Oz Technologies.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * 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).
+ *
+ * Author: David Dawes <dawes@XFree86.Org>.
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86AutoConfig.c,v 1.2 2003/11/03 05:11:01 tsi Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "xf86Config.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * Sections for the default built-in configuration.
+ */
+
+#define BUILTIN_MODULE_SECTION \
+ "Section \"Module\"\n" \
+ "\tLoad\t\"extmod\"\n" \
+ "\tLoad\t\"dbe\"\n" \
+ "\tLoad\t\"glx\"\n" \
+ "\tLoad\t\"freetype\"\n" \
+ "EndSection\n\n"
+
+#define BUILTIN_DEVICE_NAME \
+ "\"Builtin Default %s Device %d\""
+
+#define BUILTIN_DEVICE_SECTION_PRE \
+ "Section \"Device\"\n" \
+ "\tIdentifier\t" BUILTIN_DEVICE_NAME "\n" \
+ "\tDriver\t\"%s\"\n"
+
+#define BUILTIN_DEVICE_SECTION_POST \
+ "EndSection\n\n"
+
+#define BUILTIN_DEVICE_SECTION \
+ BUILTIN_DEVICE_SECTION_PRE \
+ BUILTIN_DEVICE_SECTION_POST
+
+#define BUILTIN_MONITOR_NAME \
+ "\"Builtin Default Monitor\""
+
+#define BUILTIN_MONITOR_SECTION \
+ "Section \"Monitor\"\n" \
+ "\tIdentifier\t" BUILTIN_MONITOR_NAME "\n" \
+ "\tOption\t\"TargetRefresh\"\t\"75.0\"\n" \
+ "EndSection\n\n"
+
+#define BUILTIN_SCREEN_NAME \
+ "\"Builtin Default %s Screen %d\""
+
+#define BUILTIN_SCREEN_SECTION \
+ "Section \"Screen\"\n" \
+ "\tIdentifier\t" BUILTIN_SCREEN_NAME "\n" \
+ "\tDevice\t" BUILTIN_DEVICE_NAME "\n" \
+ "\tMonitor\t" BUILTIN_MONITOR_NAME "\n" \
+ "EndSection\n\n"
+
+#define BUILTIN_LAYOUT_SECTION_PRE \
+ "Section \"ServerLayout\"\n" \
+ "\tIdentifier\t\"Builtin Default Layout\"\n"
+
+#define BUILTIN_LAYOUT_SCREEN_LINE \
+ "\tScreen\t" BUILTIN_SCREEN_NAME "\n"
+
+#define BUILTIN_LAYOUT_SECTION_POST \
+ "EndSection\n\n"
+
+
+#ifndef GET_CONFIG_CMD
+#define GET_CONFIG_CMD "getconfig"
+#endif
+
+#ifndef GETCONFIG_DIR
+#define GETCONFIG_DIR PROJECTROOT "/lib/X11/getconfig"
+#endif
+
+#define GETCONFIG_WHITESPACE " \t\n"
+
+static const char **builtinConfig = NULL;
+static int builtinLines = 0;
+static const char *deviceList[] = {
+ "fbdev",
+ "vesa",
+ "vga",
+ NULL
+};
+
+/*
+ * A built-in config file is stored as an array of strings, with each string
+ * representing a single line. AppendToConfig() breaks up the string "s"
+ * into lines, and appends those lines it to builtinConfig.
+ */
+
+static void
+AppendToList(const char *s, const char ***list, int *lines)
+{
+ char *str, *newstr, *p;
+
+ str = xnfstrdup(s);
+ for (p = strtok(str, "\n"); p; p = strtok(NULL, "\n")) {
+ (*lines)++;
+ *list = xnfrealloc(*list, (*lines + 1) * sizeof(**list));
+ newstr = xnfalloc(strlen(p) + 2);
+ strcpy(newstr, p);
+ strcat(newstr, "\n");
+ (*list)[*lines - 1] = newstr;
+ (*list)[*lines] = NULL;
+ }
+ xfree(str);
+}
+
+static void
+FreeList(const char ***list, int *lines)
+{
+ int i;
+
+ for (i = 0; i < *lines; i++) {
+ if ((*list)[i])
+ xfree((*list)[i]);
+ }
+ xfree(*list);
+ *list = NULL;
+ *lines = 0;
+}
+
+static void
+FreeConfig(void)
+{
+ FreeList(&builtinConfig, &builtinLines);
+}
+
+static void
+AppendToConfig(const char *s)
+{
+ AppendToList(s, &builtinConfig, &builtinLines);
+}
+
+Bool
+xf86AutoConfig(void)
+{
+ const char **p;
+ char buf[1024];
+ pciVideoPtr *pciptr, info = NULL;
+ char *driver = NULL;
+ FILE *gp = NULL;
+ ConfigStatus ret;
+
+ /* Find the primary device, and get some information about it. */
+ if (xf86PciVideoInfo) {
+ for (pciptr = xf86PciVideoInfo; (info = *pciptr); pciptr++) {
+ if (xf86IsPrimaryPci(info)) {
+ break;
+ }
+ }
+ if (!info) {
+ ErrorF("Primary device is not PCI\n");
+ }
+ } else {
+ ErrorF("xf86PciVideoInfo is not set\n");
+ }
+
+ if (info) {
+ char *tmp;
+ char *path = NULL, *a, *b;
+ char *searchPath = NULL;
+
+ /*
+ * Look for the getconfig program first in the xf86ModulePath
+ * directories, then in GETCONFIG_DIR, then in BINDIR. If it
+ * isn't found in any of those locations, just use the normal
+ * search path.
+ */
+
+ if (xf86ModulePath) {
+ a = xnfstrdup(xf86ModulePath);
+ b = strtok(a, ",");
+ while (b) {
+ path = xnfrealloc(path,
+ strlen(b) + 1 + strlen(GET_CONFIG_CMD) + 1);
+ sprintf(path, "%s/%s", b, GET_CONFIG_CMD);
+ if (access(path, X_OK) == 0)
+ break;
+ b = strtok(NULL, ",");
+ }
+ if (!b) {
+ xfree(path);
+ path = NULL;
+ }
+ xfree(a);
+ }
+
+ if (!path) {
+ path = xnfstrdup(GETCONFIG_DIR "/" GET_CONFIG_CMD);
+ if (access(path, X_OK) != 0) {
+ xfree(path);
+ path = NULL;
+ }
+ }
+
+#ifdef BINDIR
+ if (!path) {
+ path = xnfstrdup(BINDIR "/" GET_CONFIG_CMD);
+ if (access(path, X_OK) != 0) {
+ xfree(path);
+ path = NULL;
+ }
+ }
+#endif
+
+ if (!path)
+ path = xnfstrdup(GET_CONFIG_CMD);
+
+ /*
+ * Build up the config file directory search path:
+ *
+ * /etc/X11
+ * PROJECTROOT/etc/X11
+ * xf86ModulePath
+ * PROJECTROOT/lib/X11/getconfig (GETCONFIG_DIR)
+ */
+
+ searchPath = xnfalloc(strlen("/etc/X11") + 1 +
+ strlen(PROJECTROOT "/etc/X11") + 1 +
+ (xf86ModulePath ? strlen(xf86ModulePath) : 0)
+ + 1 +
+ strlen(GETCONFIG_DIR) + 1);
+ strcpy(searchPath, "/etc/X11," PROJECTROOT "/etc/X11,");
+ if (xf86ModulePath && *xf86ModulePath) {
+ strcat(searchPath, xf86ModulePath);
+ strcat(searchPath, ",");
+ }
+ strcat(searchPath, GETCONFIG_DIR);
+
+ ErrorF("xf86AutoConfig: Primary PCI is %d:%d:%d\n",
+ info->bus, info->device, info->func);
+
+ snprintf(buf, sizeof(buf), "%s"
+#ifdef DEBUG
+ " -D"
+#endif
+ " -X %d"
+ " -I %s"
+ " -v 0x%04x -d 0x%04x -r 0x%02x -s 0x%04x"
+ " -b 0x%04x -c 0x%04x",
+ path,
+ (unsigned int)xorgGetVersion(),
+ searchPath,
+ info->vendor, info->chipType, info->chipRev,
+ info->subsysVendor, info->subsysCard,
+ info->class << 8 | info->subclass);
+ ErrorF("Running \"%s\"\n", buf);
+ gp = Popen(buf, "r");
+ if (gp) {
+ if (fgets(buf, sizeof(buf) - 1, gp)) {
+ buf[strlen(buf) - 1] = '\0';
+ tmp = strtok(buf, GETCONFIG_WHITESPACE);
+ if (tmp)
+ driver = xnfstrdup(tmp);
+ }
+ }
+ xfree(path);
+ xfree(searchPath);
+ }
+
+ AppendToConfig(BUILTIN_MODULE_SECTION);
+ AppendToConfig(BUILTIN_MONITOR_SECTION);
+
+ if (driver) {
+ snprintf(buf, sizeof(buf), BUILTIN_DEVICE_SECTION_PRE,
+ driver, 0, driver);
+ AppendToConfig(buf);
+ ErrorF("New driver is \"%s\"\n", driver);
+ buf[0] = '\t';
+ while (fgets(buf + 1, sizeof(buf) - 2, gp)) {
+ AppendToConfig(buf);
+ ErrorF("Extra line: %s", buf);
+ }
+ AppendToConfig(BUILTIN_DEVICE_SECTION_POST);
+ snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION,
+ driver, 0, driver, 0);
+ AppendToConfig(buf);
+ }
+
+ if (gp)
+ Pclose(gp);
+
+ for (p = deviceList; *p; p++) {
+ snprintf(buf, sizeof(buf), BUILTIN_DEVICE_SECTION, *p, 0, *p);
+ AppendToConfig(buf);
+ snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION, *p, 0, *p, 0);
+ AppendToConfig(buf);
+ }
+
+ AppendToConfig(BUILTIN_LAYOUT_SECTION_PRE);
+ if (driver) {
+ snprintf(buf, sizeof(buf), BUILTIN_LAYOUT_SCREEN_LINE, driver, 0);
+ AppendToConfig(buf);
+ }
+ for (p = deviceList; *p; p++) {
+ snprintf(buf, sizeof(buf), BUILTIN_LAYOUT_SCREEN_LINE, *p, 0);
+ AppendToConfig(buf);
+ }
+ AppendToConfig(BUILTIN_LAYOUT_SECTION_POST);
+
+#ifdef BUILTIN_EXTRA
+ AppendToConfig(BUILTIN_EXTRA);
+#endif
+
+ if (driver)
+ xfree(driver);
+
+ xf86MsgVerb(X_DEFAULT, 0,
+ "Using default built-in configuration (%d lines)\n",
+ builtinLines);
+
+ xf86MsgVerb(X_DEFAULT, 3, "--- Start of built-in configuration ---\n");
+ for (p = builtinConfig; *p; p++)
+ xf86ErrorFVerb(3, "\t%s", *p);
+ xf86MsgVerb(X_DEFAULT, 3, "--- End of built-in configuration ---\n");
+
+ xf86setBuiltinConfig(builtinConfig);
+ ret = xf86HandleConfigFile(TRUE);
+ FreeConfig();
+ switch(ret) {
+ case CONFIG_OK:
+ return TRUE;
+ default:
+ xf86Msg(X_ERROR, "Error parsing the built-in default configuration.\n");
+ return FALSE;
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Bus.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Bus.c
new file mode 100644
index 000000000..e0cc4dd65
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Bus.c
@@ -0,0 +1,3317 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Bus.c,v 1.80 2004/02/05 18:24:59 eich Exp $ */
+/*
+ * 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).
+ */
+
+#define REDUCER
+/*
+ * This file contains the interfaces to the bus-specific code
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Resources.h"
+
+/* Bus-specific headers */
+
+#include "xf86Bus.h"
+
+#define XF86_OS_PRIVS
+#define NEED_OS_RAC_PROTOS
+#include "xf86_OSproc.h"
+
+#include "xf86RAC.h"
+
+/* Entity data */
+EntityPtr *xf86Entities = NULL; /* Bus slots claimed by drivers */
+int xf86NumEntities = 0;
+static int xf86EntityPrivateCount = 0;
+BusAccPtr xf86BusAccInfo = NULL;
+
+xf86AccessRec AccessNULL = {NULL,NULL,NULL};
+
+xf86CurrentAccessRec xf86CurrentAccess = {NULL,NULL};
+
+BusRec primaryBus = { BUS_NONE, {{0}}};
+
+Bool xf86ResAccessEnter = FALSE;
+
+#ifdef REDUCER
+/* Resources that temporarily conflict with estimated resources */
+static resPtr AccReducers = NULL;
+#endif
+
+/* resource lists */
+resPtr Acc = NULL;
+resPtr osRes = NULL;
+
+/* allocatable ranges */
+resPtr ResRange = NULL;
+
+/* predefined special resources */
+resRange resVgaExclusive[] = {_VGA_EXCLUSIVE, _END};
+resRange resVgaShared[] = {_VGA_SHARED, _END};
+resRange resVgaMemShared[] = {_VGA_SHARED_MEM,_END};
+resRange resVgaIoShared[] = {_VGA_SHARED_IO,_END};
+resRange resVgaUnusedExclusive[] = {_VGA_EXCLUSIVE_UNUSED, _END};
+resRange resVgaUnusedShared[] = {_VGA_SHARED_UNUSED, _END};
+resRange resVgaSparseExclusive[] = {_VGA_EXCLUSIVE_SPARSE, _END};
+resRange resVgaSparseShared[] = {_VGA_SHARED_SPARSE, _END};
+resRange res8514Exclusive[] = {_8514_EXCLUSIVE, _END};
+resRange res8514Shared[] = {_8514_SHARED, _END};
+
+/* Flag: do we need RAC ? */
+static Bool needRAC = FALSE;
+static Bool doFramebufferMode = FALSE;
+
+/* state change notification callback list */
+static StateChangeNotificationPtr StateChangeNotificationList;
+static void notifyStateChange(xf86NotifyState state);
+
+#undef MIN
+#define MIN(x,y) ((x<y)?x:y)
+
+
+/*
+ * Call the bus probes relevant to the architecture.
+ *
+ * The only one available so far is for PCI and SBUS.
+ */
+
+void
+xf86BusProbe(void)
+{
+ xf86PciProbe();
+#if defined(__sparc__) && !defined(__OpenBSD__)
+ xf86SbusProbe();
+#endif
+}
+
+/*
+ * Determine what bus type the busID string represents. The start of the
+ * bus-dependent part of the string is returned as retID.
+ */
+
+BusType
+StringToBusType(const char* busID, const char **retID)
+{
+ char *p, *s;
+ BusType ret = BUS_NONE;
+
+ /* If no type field, Default to PCI */
+ if (isdigit(busID[0])) {
+ if (retID)
+ *retID = busID;
+ return BUS_PCI;
+ }
+
+ s = xstrdup(busID);
+ p = strtok(s, ":");
+ if (p == NULL || *p == 0) {
+ xfree(s);
+ return BUS_NONE;
+ }
+ if (!xf86NameCmp(p, "pci") || !xf86NameCmp(p, "agp"))
+ ret = BUS_PCI;
+ if (!xf86NameCmp(p, "isa"))
+ ret = BUS_ISA;
+ if (!xf86NameCmp(p, "sbus"))
+ ret = BUS_SBUS;
+ if (ret != BUS_NONE)
+ if (retID)
+ *retID = busID + strlen(p) + 1;
+ xfree(s);
+ return ret;
+}
+
+/*
+ * Entity related code.
+ */
+
+void
+xf86EntityInit(void)
+{
+ int i;
+ resPtr *pprev_next;
+ resPtr res;
+ xf86AccessPtr pacc;
+
+ for (i = 0; i < xf86NumEntities; i++)
+ if (xf86Entities[i]->entityInit) {
+ if (xf86Entities[i]->access->busAcc)
+ ((BusAccPtr)xf86Entities[i]->access->busAcc)->set_f
+ (xf86Entities[i]->access->busAcc);
+ pacc = xf86Entities[i]->access->fallback;
+ if (pacc->AccessEnable)
+ pacc->AccessEnable(pacc->arg);
+ xf86Entities[i]->entityInit(i,xf86Entities[i]->private);
+ if (pacc->AccessDisable)
+ pacc->AccessDisable(pacc->arg);
+ /* remove init resources after init is processed */
+ pprev_next = &Acc;
+ res = Acc;
+ while (res) {
+ if (res->res_type & ResInit && (res->entityIndex == i)) {
+ (*pprev_next) = res->next;
+ xfree(res);
+ } else
+ pprev_next = &(res->next);
+ res = (*pprev_next);
+ }
+ }
+}
+
+int
+xf86AllocateEntity(void)
+{
+ xf86NumEntities++;
+ xf86Entities = xnfrealloc(xf86Entities,
+ sizeof(EntityPtr) * xf86NumEntities);
+ xf86Entities[xf86NumEntities - 1] = xnfcalloc(1,sizeof(EntityRec));
+ xf86Entities[xf86NumEntities - 1]->entityPrivates =
+ xnfcalloc(sizeof(DevUnion) * xf86EntityPrivateCount, 1);
+ return (xf86NumEntities - 1);
+}
+
+static void
+EntityEnter(void)
+{
+ int i;
+ xf86AccessPtr pacc;
+
+ for (i = 0; i < xf86NumEntities; i++)
+ if (xf86Entities[i]->entityEnter) {
+ if (xf86Entities[i]->access->busAcc)
+ ((BusAccPtr)xf86Entities[i]->access->busAcc)->set_f
+ (xf86Entities[i]->access->busAcc);
+ pacc = xf86Entities[i]->access->fallback;
+ if (pacc->AccessEnable)
+ pacc->AccessEnable(pacc->arg);
+ xf86Entities[i]->entityEnter(i,xf86Entities[i]->private);
+ if (pacc->AccessDisable)
+ pacc->AccessDisable(pacc->arg);
+ }
+}
+
+static void
+EntityLeave(void)
+{
+ int i;
+ xf86AccessPtr pacc;
+
+ for (i = 0; i < xf86NumEntities; i++)
+ if (xf86Entities[i]->entityLeave) {
+ if (xf86Entities[i]->access->busAcc)
+ ((BusAccPtr)xf86Entities[i]->access->busAcc)->set_f
+ (xf86Entities[i]->access->busAcc);
+ pacc = xf86Entities[i]->access->fallback;
+ if (pacc->AccessEnable)
+ pacc->AccessEnable(pacc->arg);
+ xf86Entities[i]->entityLeave(i,xf86Entities[i]->private);
+ if (pacc->AccessDisable)
+ pacc->AccessDisable(pacc->arg);
+ }
+}
+
+Bool
+xf86IsEntityPrimary(int entityIndex)
+{
+ EntityPtr pEnt = xf86Entities[entityIndex];
+
+ if (primaryBus.type != pEnt->busType) return FALSE;
+
+ switch (pEnt->busType) {
+ case BUS_PCI:
+ return (pEnt->pciBusId.bus == primaryBus.id.pci.bus &&
+ pEnt->pciBusId.device == primaryBus.id.pci.device &&
+ pEnt->pciBusId.func == primaryBus.id.pci.func);
+ case BUS_ISA:
+ return TRUE;
+ case BUS_SBUS:
+ return (pEnt->sbusBusId.fbNum == primaryBus.id.sbus.fbNum);
+ default:
+ return FALSE;
+ }
+}
+
+Bool
+xf86SetEntityFuncs(int entityIndex, EntityProc init, EntityProc enter,
+ EntityProc leave, pointer private)
+{
+ if (entityIndex >= xf86NumEntities)
+ return FALSE;
+ xf86Entities[entityIndex]->entityInit = init;
+ xf86Entities[entityIndex]->entityEnter = enter;
+ xf86Entities[entityIndex]->entityLeave = leave;
+ xf86Entities[entityIndex]->private = private;
+ return TRUE;
+}
+
+Bool
+xf86DriverHasEntities(DriverPtr drvp)
+{
+ int i;
+ for (i = 0; i < xf86NumEntities; i++) {
+ if (xf86Entities[i]->driver == drvp)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void
+xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex)
+{
+ if (entityIndex == -1)
+ return;
+ if (xf86Entities[entityIndex]->inUse &&
+ !(xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL))
+ FatalError("Requested Entity already in use!\n");
+
+ pScrn->numEntities++;
+ pScrn->entityList = xnfrealloc(pScrn->entityList,
+ pScrn->numEntities * sizeof(int));
+ pScrn->entityList[pScrn->numEntities - 1] = entityIndex;
+ xf86Entities[entityIndex]->access->next = pScrn->access;
+ pScrn->access = xf86Entities[entityIndex]->access;
+ xf86Entities[entityIndex]->inUse = TRUE;
+ pScrn->entityInstanceList = xnfrealloc(pScrn->entityInstanceList,
+ pScrn->numEntities * sizeof(int));
+ pScrn->entityInstanceList[pScrn->numEntities - 1] = 0;
+ pScrn->domainIOBase = xf86Entities[entityIndex]->domainIO;
+}
+
+void
+xf86SetEntityInstanceForScreen(ScrnInfoPtr pScrn, int entityIndex, int instance)
+{
+ int i;
+
+ if (entityIndex == -1 || entityIndex >= xf86NumEntities)
+ return;
+
+ for (i = 0; i < pScrn->numEntities; i++) {
+ if (pScrn->entityList[i] == entityIndex) {
+ pScrn->entityInstanceList[i] = instance;
+ break;
+ }
+ }
+}
+
+/*
+ * XXX This needs to be updated for the case where a single entity may have
+ * instances associated with more than one screen.
+ */
+ScrnInfoPtr
+xf86FindScreenForEntity(int entityIndex)
+{
+ int i,j;
+
+ if (entityIndex == -1) return NULL;
+
+ if (xf86Screens) {
+ for (i = 0; i < xf86NumScreens; i++) {
+ for (j = 0; j < xf86Screens[i]->numEntities; j++) {
+ if ( xf86Screens[i]->entityList[j] == entityIndex )
+ return (xf86Screens[i]);
+ }
+ }
+ }
+ return NULL;
+}
+
+void
+xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex)
+{
+ int i;
+ EntityAccessPtr *ptr = (EntityAccessPtr *)&pScrn->access;
+ EntityAccessPtr peacc;
+
+ for (i = 0; i < pScrn->numEntities; i++) {
+ if (pScrn->entityList[i] == entityIndex) {
+ peacc = xf86Entities[pScrn->entityList[i]]->access;
+ (*ptr) = peacc->next;
+ /* disable entity: call disable func */
+ if (peacc->pAccess && peacc->pAccess->AccessDisable)
+ peacc->pAccess->AccessDisable(peacc->pAccess->arg);
+ /* also disable fallback - just in case */
+ if (peacc->fallback && peacc->fallback->AccessDisable)
+ peacc->fallback->AccessDisable(peacc->fallback->arg);
+ for (i++; i < pScrn->numEntities; i++)
+ pScrn->entityList[i-1] = pScrn->entityList[i];
+ pScrn->numEntities--;
+ xf86Entities[entityIndex]->inUse = FALSE;
+ break;
+ }
+ ptr = &(xf86Entities[pScrn->entityList[i]]->access->next);
+ }
+}
+
+/*
+ * xf86ClearEntitiesForScreen() - called when a screen is deleted
+ * to mark it's entities unused. Called by xf86DeleteScreen().
+ */
+void
+xf86ClearEntityListForScreen(int scrnIndex)
+{
+ ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+ EntityAccessPtr peacc;
+ int i, entityIndex;
+
+ if (pScrn->entityList == NULL || pScrn->numEntities == 0) return;
+
+ for (i = 0; i < pScrn->numEntities; i++) {
+ entityIndex = pScrn->entityList[i];
+ xf86Entities[entityIndex]->inUse = FALSE;
+ /* disable resource: call the disable function */
+ peacc = xf86Entities[entityIndex]->access;
+ if (peacc->pAccess && peacc->pAccess->AccessDisable)
+ peacc->pAccess->AccessDisable(peacc->pAccess->arg);
+ /* and the fallback function */
+ if (peacc->fallback && peacc->fallback->AccessDisable)
+ peacc->fallback->AccessDisable(peacc->fallback->arg);
+ /* shared resources are only needed when entity is active: remove */
+ xf86DeallocateResourcesForEntity(entityIndex, ResShared);
+ }
+ xfree(pScrn->entityList);
+ xfree(pScrn->entityInstanceList);
+ if (pScrn->CurrentAccess->pIoAccess == (EntityAccessPtr)pScrn->access)
+ pScrn->CurrentAccess->pIoAccess = NULL;
+ if (pScrn->CurrentAccess->pMemAccess == (EntityAccessPtr)pScrn->access)
+ pScrn->CurrentAccess->pMemAccess = NULL;
+ pScrn->entityList = NULL;
+ pScrn->entityInstanceList = NULL;
+}
+
+void
+xf86DeallocateResourcesForEntity(int entityIndex, unsigned long type)
+{
+ resPtr *pprev_next = &Acc;
+ resPtr res = Acc;
+
+ while (res) {
+ if (res->entityIndex == entityIndex &&
+ (type & ResAccMask & res->res_type))
+ {
+ (*pprev_next) = res->next;
+ xfree(res);
+ } else
+ pprev_next = &(res->next);
+ res = (*pprev_next);
+ }
+}
+
+/*
+ * Add an extra device section (GDevPtr) to an entity.
+ */
+
+void
+xf86AddDevToEntity(int entityIndex, GDevPtr dev)
+{
+ EntityPtr pEnt;
+
+ if (entityIndex >= xf86NumEntities)
+ return;
+
+ pEnt = xf86Entities[entityIndex];
+ pEnt->numInstances++;
+ pEnt->devices = xnfrealloc(pEnt->devices,
+ pEnt->numInstances * sizeof(GDevPtr));
+ pEnt->devices[pEnt->numInstances - 1] = dev;
+ dev->claimed = TRUE;
+}
+
+/*
+ * xf86GetEntityInfo() -- This function hands information from the
+ * EntityRec struct to the drivers. The EntityRec structure itself
+ * remains invisible to the driver.
+ */
+EntityInfoPtr
+xf86GetEntityInfo(int entityIndex)
+{
+ EntityInfoPtr pEnt;
+ int i;
+
+ if (entityIndex >= xf86NumEntities)
+ return NULL;
+
+ pEnt = xnfcalloc(1,sizeof(EntityInfoRec));
+ pEnt->index = entityIndex;
+ pEnt->location = xf86Entities[entityIndex]->bus;
+ pEnt->active = xf86Entities[entityIndex]->active;
+ pEnt->chipset = xf86Entities[entityIndex]->chipset;
+ pEnt->resources = xf86Entities[entityIndex]->resources;
+ pEnt->driver = xf86Entities[entityIndex]->driver;
+ if ( (xf86Entities[entityIndex]->devices) &&
+ (xf86Entities[entityIndex]->devices[0]) ) {
+ for (i = 0; i < xf86Entities[entityIndex]->numInstances; i++)
+ if (xf86Entities[entityIndex]->devices[i]->screen == 0)
+ break;
+ pEnt->device = xf86Entities[entityIndex]->devices[i];
+ } else
+ pEnt->device = NULL;
+
+ return pEnt;
+}
+
+int
+xf86GetNumEntityInstances(int entityIndex)
+{
+ if (entityIndex >= xf86NumEntities)
+ return -1;
+
+ return xf86Entities[entityIndex]->numInstances;
+}
+
+GDevPtr
+xf86GetDevFromEntity(int entityIndex, int instance)
+{
+ int i;
+
+ /* We might not use AddDevtoEntity */
+ if ( (!xf86Entities[entityIndex]->devices) ||
+ (!xf86Entities[entityIndex]->devices[0]) )
+ return NULL;
+
+ if (entityIndex >= xf86NumEntities ||
+ instance >= xf86Entities[entityIndex]->numInstances)
+ return NULL;
+
+ for (i = 0; i < xf86Entities[entityIndex]->numInstances; i++)
+ if (xf86Entities[entityIndex]->devices[i]->screen == instance)
+ break;
+ return xf86Entities[entityIndex]->devices[i];
+}
+
+/*
+ * general generic disable function.
+ */
+static void
+disableAccess(void)
+{
+ int i;
+ xf86AccessPtr pacc;
+ EntityAccessPtr peacc;
+
+ /* call disable funcs and reset current access pointer */
+ /* the entity specific access funcs are in an enabled */
+ /* state - driver must restore their state explicitely */
+ for (i = 0; i < xf86NumScreens; i++) {
+ peacc = xf86Screens[i]->CurrentAccess->pIoAccess;
+ while (peacc) {
+ if (peacc->pAccess && peacc->pAccess->AccessDisable)
+ peacc->pAccess->AccessDisable(peacc->pAccess->arg);
+ peacc = peacc->next;
+ }
+ xf86Screens[i]->CurrentAccess->pIoAccess = NULL;
+ peacc = xf86Screens[i]->CurrentAccess->pMemAccess;
+ while (peacc) {
+ if (peacc->pAccess && peacc->pAccess->AccessDisable)
+ peacc->pAccess->AccessDisable(peacc->pAccess->arg);
+ peacc = peacc->next;
+ }
+ xf86Screens[i]->CurrentAccess->pMemAccess = NULL;
+ }
+ /* then call the generic entity disable funcs */
+ for (i = 0; i < xf86NumEntities; i++) {
+ pacc = xf86Entities[i]->access->fallback;
+ if (pacc->AccessDisable)
+ pacc->AccessDisable(pacc->arg);
+ }
+}
+
+static void
+clearAccess(void)
+{
+ int i;
+
+ /* call disable funcs and reset current access pointer */
+ /* the entity specific access funcs are in an enabled */
+ /* state - driver must restore their state explicitely */
+ for (i = 0; i < xf86NumScreens; i++) {
+ xf86Screens[i]->CurrentAccess->pIoAccess = NULL;
+ xf86Screens[i]->CurrentAccess->pMemAccess = NULL;
+ }
+
+}
+
+/*
+ * Generic interface to bus specific code - add other buses here
+ */
+
+/*
+ * xf86AccessInit() - set up everything needed for access control
+ * called only once on first server generation.
+ */
+void
+xf86AccessInit(void)
+{
+ initPciState();
+ initPciBusState();
+ DisablePciBusAccess();
+ DisablePciAccess();
+
+ xf86ResAccessEnter = TRUE;
+}
+
+/*
+ * xf86AccessEnter() -- gets called to save the text mode VGA IO
+ * resources when reentering the server after a VT switch.
+ */
+void
+xf86AccessEnter(void)
+{
+ if (xf86ResAccessEnter)
+ return;
+
+ /*
+ * on enter we simply disable routing of special resources
+ * to any bus and let the RAC code to "open" the right bridges.
+ */
+ PciBusStateEnter();
+ DisablePciBusAccess();
+ PciStateEnter();
+ disableAccess();
+ EntityEnter();
+ notifyStateChange(NOTIFY_ENTER);
+ xf86EnterServerState(SETUP);
+ xf86ResAccessEnter = TRUE;
+}
+
+/*
+ * xf86AccessLeave() -- prepares access for and calls the
+ * entityLeave() functions.
+ * xf86AccessLeaveState() --- gets called to restore the
+ * access to the VGA IO resources when switching VT or on
+ * server exit.
+ * This was split to call xf86AccessLeaveState() from
+ * ddxGiveUp().
+ */
+void
+xf86AccessLeave(void)
+{
+ if (!xf86ResAccessEnter)
+ return;
+ notifyStateChange(NOTIFY_LEAVE);
+ disableAccess();
+ DisablePciBusAccess();
+ EntityLeave();
+}
+
+void
+xf86AccessLeaveState(void)
+{
+ if (!xf86ResAccessEnter)
+ return;
+ xf86ResAccessEnter = FALSE;
+ PciStateLeave();
+ PciBusStateLeave();
+}
+
+/*
+ * xf86AccessRestoreState() - Restore the access registers to the
+ * state before X was started. This is handy for framebuffers.
+ */
+static void
+xf86AccessRestoreState(void)
+{
+ if (!xf86ResAccessEnter)
+ return;
+ PciStateLeave();
+ PciBusStateLeave();
+}
+
+/*
+ * xf86EnableAccess() -- enable access to controlled resources.
+ * To reduce latency when switching access the ScrnInfoRec has
+ * a linked list of the EntityAccPtr of all screen entities.
+ */
+/*
+ * switching access needs to be done in te following oder:
+ * disable
+ * 1. disable old entity
+ * 2. reroute bus
+ * 3. enable new entity
+ * Otherwise resources needed for access control might be shadowed
+ * by other resources!
+ */
+#ifdef async
+
+static AsyncQPtr *AsyncQ = NULL;
+ScrnInfoPtr xf86CurrentScreen = NULL;
+
+#define SETUP_Q org = AsyncQ; \
+ AsyncQ = &new;
+
+#define PROCESS_Q xf86CurrentScreen = pScrn;
+ if (!new) AsyncQ = org; \
+ else { \
+ AsyncQPtr tmp_Q; \
+ while (1) {\
+ new->func(new->arg);\
+ if (!(new->next)) {\
+ AsyncQ = org; xfree(new); break; \
+ } \
+ tmp_Q = new->next; \
+ xfree(new); \
+ new = tmp_Q; \
+ } \
+ }
+#else
+#define SETUP_Q
+#define PROCESS_Q
+#endif
+
+void
+xf86EnableAccess(ScrnInfoPtr pScrn)
+{
+ register EntityAccessPtr peAcc = (EntityAccessPtr) pScrn->access;
+ register EntityAccessPtr pceAcc;
+ register xf86AccessPtr pAcc;
+ EntityAccessPtr tmp;
+#ifdef async
+ AsyncQPtr *org, new = NULL;
+#endif
+
+#ifdef DEBUG
+ ErrorF("Enable access %i\n",pScrn->scrnIndex);
+#endif
+
+ /* Entity is not under access control or currently enabled */
+ if (!pScrn->access) {
+ if (pScrn->busAccess) {
+ SETUP_Q;
+ ((BusAccPtr)pScrn->busAccess)->set_f(pScrn->busAccess);
+ PROCESS_Q;
+ }
+ return;
+ }
+
+ switch (pScrn->resourceType) {
+ case IO:
+ pceAcc = pScrn->CurrentAccess->pIoAccess;
+ if (peAcc == pceAcc) {
+ return;
+ }
+ SETUP_Q;
+ if (pScrn->CurrentAccess->pMemAccess == pceAcc)
+ pScrn->CurrentAccess->pMemAccess = NULL;
+ while (pceAcc) {
+ pAcc = pceAcc->pAccess;
+ if ( pAcc && pAcc->AccessDisable)
+ (*pAcc->AccessDisable)(pAcc->arg);
+ pceAcc = pceAcc->next;
+ }
+ if (pScrn->busAccess)
+ ((BusAccPtr)pScrn->busAccess)->set_f(pScrn->busAccess);
+ while (peAcc) {
+ pAcc = peAcc->pAccess;
+ if (pAcc && pAcc->AccessEnable)
+ (*pAcc->AccessEnable)(pAcc->arg);
+ peAcc = peAcc->next;
+ }
+ pScrn->CurrentAccess->pIoAccess = (EntityAccessPtr) pScrn->access;
+ PROCESS_Q;
+ return;
+
+ case MEM_IO:
+ pceAcc = pScrn->CurrentAccess->pIoAccess;
+ if (peAcc != pceAcc) { /* current Io != pAccess */
+ SETUP_Q;
+ tmp = pceAcc;
+ while (pceAcc) {
+ pAcc = pceAcc->pAccess;
+ if (pAcc && pAcc->AccessDisable)
+ (*pAcc->AccessDisable)(pAcc->arg);
+ pceAcc = pceAcc->next;
+ }
+ pceAcc = pScrn->CurrentAccess->pMemAccess;
+ if (peAcc != pceAcc /* current Mem != pAccess */
+ && tmp !=pceAcc) {
+ while (pceAcc) {
+ pAcc = pceAcc->pAccess;
+ if (pAcc && pAcc->AccessDisable)
+ (*pAcc->AccessDisable)(pAcc->arg);
+ pceAcc = pceAcc->next;
+ }
+ }
+ } else { /* current Io == pAccess */
+ pceAcc = pScrn->CurrentAccess->pMemAccess;
+ if (pceAcc == peAcc) { /* current Mem == pAccess */
+ return;
+ }
+ SETUP_Q;
+ while (pceAcc) { /* current Mem != pAccess */
+ pAcc = pceAcc->pAccess;
+ if (pAcc && pAcc->AccessDisable)
+ (*pAcc->AccessDisable)(pAcc->arg);
+ pceAcc = pceAcc->next;
+ }
+ }
+ if (pScrn->busAccess)
+ ((BusAccPtr)pScrn->busAccess)->set_f(pScrn->busAccess);
+ while (peAcc) {
+ pAcc = peAcc->pAccess;
+ if (pAcc && pAcc->AccessEnable)
+ (*pAcc->AccessEnable)(pAcc->arg);
+ peAcc = peAcc->next;
+ }
+ pScrn->CurrentAccess->pMemAccess =
+ pScrn->CurrentAccess->pIoAccess = (EntityAccessPtr) pScrn->access;
+ PROCESS_Q;
+ return;
+
+ case MEM:
+ pceAcc = pScrn->CurrentAccess->pMemAccess;
+ if (peAcc == pceAcc) {
+ return;
+ }
+ SETUP_Q;
+ if (pScrn->CurrentAccess->pIoAccess == pceAcc)
+ pScrn->CurrentAccess->pIoAccess = NULL;
+ while (pceAcc) {
+ pAcc = pceAcc->pAccess;
+ if ( pAcc && pAcc->AccessDisable)
+ (*pAcc->AccessDisable)(pAcc->arg);
+ pceAcc = pceAcc->next;
+ }
+ if (pScrn->busAccess)
+ ((BusAccPtr)pScrn->busAccess)->set_f(pScrn->busAccess);
+ while (peAcc) {
+ pAcc = peAcc->pAccess;
+ if (pAcc && pAcc->AccessEnable)
+ (*pAcc->AccessEnable)(pAcc->arg);
+ peAcc = peAcc->next;
+ }
+ pScrn->CurrentAccess->pMemAccess = (EntityAccessPtr) pScrn->access;
+ PROCESS_Q;
+ return;
+
+ case NONE:
+ if (pScrn->busAccess) {
+ SETUP_Q;
+ ((BusAccPtr)pScrn->busAccess)->set_f(pScrn->busAccess);
+ PROCESS_Q;
+ }
+ return;
+ }
+}
+
+void
+xf86SetCurrentAccess(Bool Enable, ScrnInfoPtr pScrn)
+{
+ EntityAccessPtr pceAcc2 = NULL;
+ register EntityAccessPtr pceAcc = NULL;
+ register xf86AccessPtr pAcc;
+
+
+ switch(pScrn->resourceType) {
+ case IO:
+ pceAcc = pScrn->CurrentAccess->pIoAccess;
+ break;
+ case MEM:
+ pceAcc = pScrn->CurrentAccess->pMemAccess;
+ break;
+ case MEM_IO:
+ pceAcc = pScrn->CurrentAccess->pMemAccess;
+ pceAcc2 = pScrn->CurrentAccess->pIoAccess;
+ break;
+ default:
+ break;
+ }
+
+ while (pceAcc) {
+ pAcc = pceAcc->pAccess;
+ if ( pAcc) {
+ if (!Enable) {
+ if (pAcc->AccessDisable)
+ (*pAcc->AccessDisable)(pAcc->arg);
+ } else {
+ if (pAcc->AccessEnable)
+ (*pAcc->AccessEnable)(pAcc->arg);
+ }
+ }
+ pceAcc = pceAcc->next;
+ if (!pceAcc) {
+ pceAcc = pceAcc2;
+ pceAcc2 = NULL;
+ }
+ }
+}
+
+void
+xf86SetAccessFuncs(EntityInfoPtr pEnt, xf86SetAccessFuncPtr funcs,
+ xf86SetAccessFuncPtr oldFuncs)
+{
+ AccessFuncPtr rac;
+
+ if (!xf86Entities[pEnt->index]->rac)
+ xf86Entities[pEnt->index]->rac = xnfcalloc(1,sizeof(AccessFuncRec));
+
+ rac = xf86Entities[pEnt->index]->rac;
+
+ if (funcs->mem == funcs->io_mem && funcs->mem && funcs->io)
+ xf86Entities[pEnt->index]->entityProp |= NO_SEPARATE_MEM_FROM_IO;
+ if (funcs->io == funcs->io_mem && funcs->mem && funcs->io)
+ xf86Entities[pEnt->index]->entityProp |= NO_SEPARATE_IO_FROM_MEM;
+
+ rac->mem_new = funcs->mem;
+ rac->io_new = funcs->io;
+ rac->io_mem_new = funcs->io_mem;
+
+ rac->old = oldFuncs;
+}
+
+/*
+ * Conflict checking
+ */
+
+static memType
+getMask(memType val)
+{
+ memType mask = 0;
+ memType tmp = 0;
+
+ mask=~mask;
+ tmp = ~((~tmp) >> 1);
+
+ while (!(val & tmp)) {
+ mask = mask >> 1;
+ val = val << 1;
+ }
+ return mask;
+}
+
+/*
+ * checkConflictBlock() -- check for conflicts of a block resource range.
+ * If conflict is found return end of conflicting range. Else return 0.
+ */
+static memType
+checkConflictBlock(resRange *range, resPtr pRes)
+{
+ memType val,tmp,prev;
+ int i;
+
+ switch (pRes->res_type & ResExtMask) {
+ case ResBlock:
+ if (range->rBegin < pRes->block_end &&
+ range->rEnd > pRes->block_begin) {
+#ifdef DEBUG
+ ErrorF("b-b conflict w: %lx %lx\n",
+ pRes->block_begin,pRes->block_end);
+#endif
+ return pRes->block_end < range->rEnd ?
+ pRes->block_end : range->rEnd;
+ }
+ return 0;
+ case ResSparse:
+ if (pRes->sparse_base > range->rEnd) return 0;
+
+ val = (~pRes->sparse_mask | pRes->sparse_base) & getMask(range->rEnd);
+#ifdef DEBUG
+ ErrorF("base = 0x%lx, mask = 0x%lx, begin = 0x%lx, end = 0x%lx ,"
+ "val = 0x%lx\n",
+ pRes->sparse_base, pRes->sparse_mask, range->rBegin,
+ range->rEnd, val);
+#endif
+ i = sizeof(memType) * 8;
+ tmp = prev = pRes->sparse_base;
+
+ while (i) {
+ tmp |= 1<< (--i) & val;
+ if (tmp > range->rEnd)
+ tmp = prev;
+ else
+ prev = tmp;
+ }
+ if (tmp >= range->rBegin) {
+#ifdef DEBUG
+ ErrorF("conflict found at: 0x%lx\n",tmp);
+ ErrorF("b-d conflict w: %lx %lx\n",
+ pRes->sparse_base,pRes->sparse_mask);
+#endif
+ return tmp;
+ }
+ else
+ return 0;
+ }
+ return 0;
+}
+
+/*
+ * checkConflictSparse() -- check for conflicts of a sparse resource range.
+ * If conflict is found return base of conflicting region. Else return 0.
+ */
+#define mt_max ~(memType)0
+#define length sizeof(memType) * 8
+static memType
+checkConflictSparse(resRange *range, resPtr pRes)
+{
+ memType val, tmp, prev;
+ int i;
+
+ switch (pRes->res_type & ResExtMask) {
+ case ResSparse:
+ tmp = pRes->sparse_mask & range->rMask;
+ if ((tmp & pRes->sparse_base) == (tmp & range->rBase)) {
+#ifdef DEBUG
+ ErrorF("s-b conflict w: %lx %lx\n",
+ pRes->sparse_base,pRes->sparse_mask);
+#endif
+ return pRes->sparse_mask;
+ }
+ return 0;
+
+ case ResBlock:
+ if (pRes->block_end < range->rBase) return 0;
+
+ val = (~range->rMask | range->rBase) & getMask(pRes->block_end);
+ i = length;
+ tmp = prev = range->rBase;
+
+ while (i) {
+#ifdef DEBUG
+ ErrorF("tmp = 0x%lx\n",tmp);
+#endif
+ tmp |= 1<< (--i) & val;
+ if (tmp > pRes->block_end)
+ tmp = prev;
+ else
+ prev = tmp;
+ }
+ if (tmp < pRes->block_begin)
+ return 0;
+ else {
+ /*
+ * now we subdivide the block region in sparse regions
+ * with base values = 2^n and find the smallest mask.
+ * This might be done in a simpler way....
+ */
+ memType mask, m_mask = 0, base = pRes->block_begin;
+ int i;
+ while (base < pRes->block_end) {
+ for (i = 1; i < length; i++)
+ if ( base != (base & (mt_max << i))) break;
+ mask = mt_max >> (length - i);
+ do mask >>= 1;
+ while ((mask + base + 1) > pRes->block_end);
+ /* m_mask and are _inverted_ sparse masks */
+ m_mask = mask > m_mask ? mask : m_mask;
+ base = base + mask + 1;
+ }
+#ifdef DEBUG
+ ErrorF("conflict found at: 0x%lx\n",tmp);
+ ErrorF("b-b conflict w: %lx %lx\n",
+ pRes->block_begin,pRes->block_end);
+#endif
+ return ~m_mask;
+ }
+ }
+ return 0;
+}
+#undef mt_max
+#undef length
+
+/*
+ * needCheck() -- this function decides whether to check for conflicts
+ * depending on the types of the resource ranges and their locations
+ */
+static Bool
+needCheck(resPtr pRes, unsigned long type, int entityIndex, xf86State state)
+{
+ /* the same entity shouldn't conflict with itself */
+ ScrnInfoPtr pScrn;
+ int i;
+ BusType loc = BUS_NONE;
+ BusType r_loc = BUS_NONE;
+
+ /* Ignore overlapped ranges that have been nullified */
+ if ((pRes->res_type & ResOverlap) && (pRes->block_begin > pRes->block_end))
+ return FALSE;
+
+ if ((pRes->res_type & ResTypeMask) != (type & ResTypeMask))
+ return FALSE;
+
+ /*
+ * Resources set by BIOS (ResBios) are allowed to conflict
+ * with resources marked (ResBios).
+ */
+ if (pRes->res_type & type & ResBios)
+ return FALSE;
+
+ /*If requested, skip over estimated resources */
+ if (pRes->res_type & type & ResEstimated)
+ return FALSE;
+
+ if (type & pRes->res_type & ResUnused)
+ return FALSE;
+
+ if (state == OPERATING) {
+ if (type & ResDisableOpr || pRes->res_type & ResDisableOpr)
+ return FALSE;
+ if (type & pRes->res_type & ResUnusedOpr) return FALSE;
+ /*
+ * Maybe we should have ResUnused set The resUnusedOpr
+ * bit, too. This way we could avoid this confusion
+ */
+ if ((type & ResUnusedOpr && pRes->res_type & ResUnused) ||
+ (type & ResUnused && pRes->res_type & ResUnusedOpr))
+ return FALSE;
+ }
+
+ if (entityIndex > -1)
+ loc = xf86Entities[entityIndex]->busType;
+ if (pRes->entityIndex > -1)
+ r_loc = xf86Entities[pRes->entityIndex]->busType;
+
+ switch (type & ResAccMask) {
+ case ResExclusive:
+ switch (pRes->res_type & ResAccMask) {
+ case ResExclusive:
+ break;
+ case ResShared:
+ /* ISA buses are only locally exclusive on a PCI system */
+ if (loc == BUS_ISA && r_loc == BUS_PCI)
+ return FALSE;
+ break;
+ }
+ break;
+ case ResShared:
+ switch (pRes->res_type & ResAccMask) {
+ case ResExclusive:
+ /* ISA buses are only locally exclusive on a PCI system */
+ if (loc == BUS_PCI && r_loc == BUS_ISA)
+ return FALSE;
+ break;
+ case ResShared:
+ return FALSE;
+ }
+ break;
+ case ResAny:
+ break;
+ }
+
+ if (pRes->entityIndex == entityIndex) return FALSE;
+
+ if (pRes->entityIndex > -1 &&
+ (pScrn = xf86FindScreenForEntity(entityIndex))) {
+ for (i = 0; i < pScrn->numEntities; i++)
+ if (pScrn->entityList[i] == pRes->entityIndex) return FALSE;
+ }
+ return TRUE;
+}
+
+/*
+ * checkConflict() - main conflict checking function which all other
+ * function call.
+ */
+static memType
+checkConflict(resRange *rgp, resPtr pRes, int entityIndex,
+ xf86State state, Bool ignoreIdentical)
+{
+ memType ret;
+
+ while(pRes) {
+ if (!needCheck(pRes,rgp->type, entityIndex ,state)) {
+ pRes = pRes->next;
+ continue;
+ }
+ switch (rgp->type & ResExtMask) {
+ case ResBlock:
+ if (rgp->rEnd < rgp->rBegin) {
+ xf86Msg(X_ERROR,"end of block range 0x%lx < begin 0x%lx\n",
+ rgp->rEnd,rgp->rBegin);
+ return 0;
+ }
+ if ((ret = checkConflictBlock(rgp, pRes))) {
+ if (!ignoreIdentical || (rgp->rBegin != pRes->block_begin)
+ || (rgp->rEnd != pRes->block_end))
+ return ret;
+ }
+ break;
+ case ResSparse:
+ if ((rgp->rBase & rgp->rMask) != rgp->rBase) {
+ xf86Msg(X_ERROR,"sparse io range (base: 0x%lx mask: 0x%lx)"
+ "doesn't satisfy (base & mask = mask)\n",
+ rgp->rBase, rgp->rMask);
+ return 0;
+ }
+ if ((ret = checkConflictSparse(rgp, pRes))) {
+ if (!ignoreIdentical || (rgp->rBase != pRes->sparse_base)
+ || (rgp->rMask != pRes->sparse_mask))
+ return ret;
+ }
+ break;
+ }
+ pRes = pRes->next;
+ }
+ return 0;
+}
+
+/*
+ * ChkConflict() -- used within xxxBus ; find conflict with any location.
+ */
+memType
+ChkConflict(resRange *rgp, resPtr res, xf86State state)
+{
+ return checkConflict(rgp, res, -2, state,FALSE);
+}
+
+/*
+ * xf86ChkConflict() - This function is the low level interface to
+ * the resource broker that gets exported. Tests all resources ie.
+ * performs test with SETUP flag.
+ */
+memType
+xf86ChkConflict(resRange *rgp, int entityIndex)
+{
+ return checkConflict(rgp, Acc, entityIndex, SETUP,FALSE);
+}
+
+/*
+ * Resources List handling
+ */
+
+resPtr
+xf86JoinResLists(resPtr rlist1, resPtr rlist2)
+{
+ resPtr pRes;
+
+ if (!rlist1)
+ return rlist2;
+
+ if (!rlist2)
+ return rlist1;
+
+ for (pRes = rlist1; pRes->next; pRes = pRes->next)
+ ;
+ pRes->next = rlist2;
+ return rlist1;
+}
+
+resPtr
+xf86AddResToList(resPtr rlist, resRange *range, int entityIndex)
+{
+ resPtr new;
+
+ switch (range->type & ResExtMask) {
+ case ResBlock:
+ if (range->rEnd < range->rBegin) {
+ xf86Msg(X_ERROR,"end of block range 0x%lx < begin 0x%lx\n",
+ range->rEnd,range->rBegin);
+ return rlist;
+ }
+ break;
+ case ResSparse:
+ if ((range->rBase & range->rMask) != range->rBase) {
+ xf86Msg(X_ERROR,"sparse io range (base: 0x%lx mask: 0x%lx)"
+ "doesn't satisfy (base & mask = mask)\n",
+ range->rBase, range->rMask);
+ return rlist;
+ }
+ break;
+ }
+
+ new = xnfalloc(sizeof(resRec));
+ /*
+ * Only background resources may be registered with ResBios
+ * and ResEstimated set. Other resources only set it for
+ * testing.
+ */
+ if (entityIndex != (-1))
+ range->type &= ~(ResBios | ResEstimated);
+ new->val = *range;
+ new->entityIndex = entityIndex;
+ new->next = rlist;
+ return new;
+}
+
+void
+xf86FreeResList(resPtr rlist)
+{
+ resPtr pRes;
+
+ if (!rlist)
+ return;
+
+ for (pRes = rlist->next; pRes; rlist = pRes, pRes = pRes->next)
+ xfree(rlist);
+ xfree(rlist);
+}
+
+resPtr
+xf86DupResList(const resPtr rlist)
+{
+ resPtr pRes, ret, prev, new;
+
+ if (!rlist)
+ return NULL;
+
+ ret = xnfalloc(sizeof(resRec));
+ *ret = *rlist;
+ prev = ret;
+ for (pRes = rlist->next; pRes; pRes = pRes->next) {
+ new = xnfalloc(sizeof(resRec));
+ *new = *pRes;
+ prev->next = new;
+ prev = new;
+ }
+ return ret;
+}
+
+void
+xf86PrintResList(int verb, resPtr list)
+{
+ int i = 0;
+ const char *s, *r;
+ resPtr tmp = list;
+ unsigned long type;
+
+ if (!list)
+ return;
+
+ type = ResMem;
+ r = "M";
+ while (1) {
+ while (list) {
+ if ((list->res_type & ResPhysMask) == type) {
+ switch (list->res_type & ResExtMask) {
+ case ResBlock:
+ xf86ErrorFVerb(verb,
+ "\t[%d] %d\t%ld\t0x%08lx - 0x%08lx (0x%lx)",
+ i, list->entityIndex,
+ (list->res_type & ResDomain) >> 24,
+ list->block_begin, list->block_end,
+ list->block_end - list->block_begin + 1);
+ break;
+ case ResSparse:
+ xf86ErrorFVerb(verb, "\t[%d] %d\t%ld\t0x%08lx - 0x%08lx ",
+ i, list->entityIndex,
+ (list->res_type & ResDomain) >> 24,
+ list->sparse_base,list->sparse_mask);
+ break;
+ default:
+ list = list->next;
+ continue;
+ }
+ xf86ErrorFVerb(verb, " %s", r);
+ switch (list->res_type & ResAccMask) {
+ case ResExclusive:
+ if (list->res_type & ResUnused)
+ s = "x";
+ else
+ s = "X";
+ break;
+ case ResShared:
+ if (list->res_type & ResUnused)
+ s = "s";
+ else
+ s = "S";
+ break;
+ default:
+ s = "?";
+ }
+ xf86ErrorFVerb(verb, "%s", s);
+ switch (list->res_type & ResExtMask) {
+ case ResBlock:
+ s = "[B]";
+ break;
+ case ResSparse:
+ s = "[S]";
+ break;
+ default:
+ s = "[?]";
+ }
+ xf86ErrorFVerb(verb, "%s", s);
+ if (list->res_type & ResEstimated)
+ xf86ErrorFVerb(verb, "E");
+ if (list->res_type & ResOverlap)
+ xf86ErrorFVerb(verb, "O");
+ if (list->res_type & ResInit)
+ xf86ErrorFVerb(verb, "t");
+ if (list->res_type & ResBios)
+ xf86ErrorFVerb(verb, "(B)");
+ if (list->res_type & ResBus)
+ xf86ErrorFVerb(verb, "(b)");
+ if (list->res_type & ResOprMask) {
+ switch (list->res_type & ResOprMask) {
+ case ResUnusedOpr:
+ s = "(OprU)";
+ break;
+ case ResDisableOpr:
+ s = "(OprD)";
+ break;
+ default:
+ s = "(Opr?)";
+ break;
+ }
+ xf86ErrorFVerb(verb, "%s", s);
+ }
+ xf86ErrorFVerb(verb, "\n");
+ i++;
+ }
+ list = list->next;
+ }
+ if (type == ResIo) break;
+ type = ResIo;
+ r = "I";
+ list = tmp;
+ }
+}
+
+resPtr
+xf86AddRangesToList(resPtr list, resRange *pRange, int entityIndex)
+{
+ while(pRange && pRange->type != ResEnd) {
+ list = xf86AddResToList(list,pRange,entityIndex);
+ pRange++;
+ }
+ return list;
+}
+
+void
+xf86ResourceBrokerInit(void)
+{
+ resPtr resPci;
+
+ osRes = NULL;
+
+ /* Get the addressable ranges */
+ ResRange = xf86BusAccWindowsFromOS();
+ xf86MsgVerb(X_INFO, 3, "Addressable bus resource ranges are\n");
+ xf86PrintResList(3, ResRange);
+
+ /* Get the ranges used exclusively by the system */
+ osRes = xf86AccResFromOS(osRes);
+ xf86MsgVerb(X_INFO, 3, "OS-reported resource ranges:\n");
+ xf86PrintResList(3, osRes);
+
+ /* Bus dep initialization */
+ resPci = ResourceBrokerInitPci(&osRes);
+ Acc = xf86JoinResLists(xf86DupResList(osRes), resPci);
+
+ xf86MsgVerb(X_INFO, 3, "All system resource ranges:\n");
+ xf86PrintResList(3, Acc);
+
+}
+
+#define MEM_ALIGN (1024 * 1024)
+
+/*
+ * RemoveOverlaps() -- remove overlaps between resources of the
+ * same kind.
+ * Beware: This function doesn't check for access attributes.
+ * At resource broker initialization this is no problem as this
+ * only deals with exclusive resources.
+ */
+#if 0
+void
+RemoveOverlaps(resPtr target, resPtr list, Bool pow2Alignment, Bool useEstimated)
+{
+ resPtr pRes;
+ memType size, newsize, adjust;
+
+ if (!target)
+ return;
+
+ for (pRes = list; pRes; pRes = pRes->next) {
+ if (pRes != target
+ && ((pRes->res_type & ResTypeMask) ==
+ (target->res_type & ResTypeMask))
+ && pRes->block_begin <= target->block_end
+ && pRes->block_end >= target->block_begin) {
+ /* Possibly ignore estimated resources */
+ if (!useEstimated && (pRes->res_type & ResEstimated)) continue;
+ /*
+ * Target should be a larger region than pRes. If pRes fully
+ * contains target, don't do anything unless target can overlap.
+ */
+ if (pRes->block_begin <= target->block_begin &&
+ pRes->block_end >= target->block_end) {
+ if (target->res_type & ResOverlap) {
+ /* Nullify range but keep its ResOverlap bit on */
+ target->block_end = target->block_begin - 1;
+ return;
+ }
+ continue;
+ }
+ /*
+ * In cases where the target and pRes have the same starting
+ * address, reduce the size of the target (given it's an estimate).
+ */
+ if (pRes->block_begin == target->block_begin) {
+ if (target->res_type & ResOverlap)
+ target->block_end = target->block_begin - 1;
+ else
+ target->block_end = pRes->block_end;
+ }
+ /* Otherwise, trim target to remove the overlap */
+ else if (pRes->block_begin <= target->block_end) {
+ target->block_end = pRes->block_begin - 1;
+ } else if (!pow2Alignment &&
+ pRes->block_end >= target->block_begin) {
+ target->block_begin = pRes->block_end + 1;
+ }
+ if (pow2Alignment) {
+ /*
+ * Align to a power of two. This requires finding the
+ * largest power of two that is smaller than the adjusted
+ * size.
+ */
+ size = target->block_end - target->block_begin + 1;
+ newsize = 1UL << (sizeof(memType) * 8 - 1);
+ while (!(newsize & size))
+ newsize >>= 1;
+ target->block_end = target->block_begin + newsize - 1;
+ } else if (target->block_end > MEM_ALIGN) {
+ /* Align the end to MEM_ALIGN */
+ if ((adjust = (target->block_end + 1) % MEM_ALIGN))
+ target->block_end -= adjust;
+ }
+ }
+ }
+}
+#else
+
+void
+RemoveOverlaps(resPtr target, resPtr list, Bool pow2Alignment, Bool useEstimated)
+{
+ resPtr pRes;
+ memType size, newsize, adjust;
+
+ if (!target)
+ return;
+
+ if (!(target->res_type & ResEstimated) /* Don't touch sure resources */
+ && !(target->res_type & ResOverlap)) /* Unless they may overlap */
+ return;
+
+ for (pRes = list; pRes; pRes = pRes->next) {
+ if (pRes == target
+ || ((pRes->res_type & ResTypeMask) !=
+ (target->res_type & ResTypeMask))
+ || pRes->block_begin > target->block_end
+ || pRes->block_end < target->block_begin)
+ continue;
+
+ if (pRes->block_begin <= target->block_begin) {
+ /* Possibly ignore estimated resources */
+ if (!useEstimated && (pRes->res_type & ResEstimated))
+ continue;
+
+ /* Special cases */
+ if (pRes->block_end >= target->block_end) {
+ /*
+ * If pRes fully contains target, don't do anything
+ * unless target can overlap.
+ */
+ if (target->res_type & ResOverlap) {
+ /* Nullify range but keep its ResOverlap bit on */
+ target->block_end = target->block_begin - 1;
+ return;
+ } else
+ continue;
+ } else {
+#if 0 /* Don't trim start address - we trust what we got */
+ /*
+ * If !pow2Alignment trim start address: !pow2Alingment
+ * is only set when estimated OS addresses are handled.
+ * In cases where the target and pRes have the same
+ * starting address, reduce the size of the target
+ * (given it's an estimate).
+ */
+ if (!pow2Alignment)
+ target->block_begin = pRes->block_end + 1;
+ else
+#endif
+ if (pRes->block_begin == target->block_begin)
+ target->block_end = pRes->block_end;
+ else
+ continue;
+ }
+ } else {
+ /* Trim target to remove the overlap */
+ target->block_end = pRes->block_begin - 1;
+ }
+ if (pow2Alignment) {
+ /*
+ * Align to a power of two. This requires finding the
+ * largest power of two that is smaller than the adjusted
+ * size.
+ */
+ size = target->block_end - target->block_begin + 1;
+ newsize = 1UL << (sizeof(memType) * 8 - 1);
+ while (!(newsize & size))
+ newsize >>= 1;
+ target->block_end = target->block_begin + newsize - 1;
+ } else if (target->block_end > MEM_ALIGN) {
+ /* Align the end to MEM_ALIGN */
+ if ((adjust = (target->block_end + 1) % MEM_ALIGN))
+ target->block_end -= adjust;
+ }
+ }
+}
+
+#endif
+
+/*
+ * Resource request code
+ */
+
+#define ALIGN(x,a) ((x) + a) &~(a)
+
+resRange
+xf86GetBlock(unsigned long type, memType size,
+ memType window_start, memType window_end,
+ memType align_mask, resPtr avoid)
+{
+ memType min, max, tmp;
+ resRange r = {ResEnd,0,0};
+ resPtr res_range = ResRange;
+
+ if (!size) return r;
+ if (window_end < window_start || (window_end - window_start) < (size - 1)) {
+ ErrorF("Requesting insufficient memory window!:"
+ " start: 0x%lx end: 0x%lx size 0x%lx\n",
+ window_start,window_end,size);
+ return r;
+ }
+ type = (type & ~(ResExtMask | ResBios | ResEstimated)) | ResBlock;
+
+ while (res_range) {
+ if ((type & ResTypeMask) == (res_range->res_type & ResTypeMask)) {
+ if (res_range->block_begin > window_start)
+ min = res_range->block_begin;
+ else
+ min = window_start;
+ if (res_range->block_end < window_end)
+ max = res_range->block_end;
+ else
+ max = window_end;
+ min = ALIGN(min,align_mask);
+ /* do not produce an overflow! */
+ while (min < max && (max - min) >= (size - 1)) {
+ RANGE(r,min,min + size - 1,type);
+ tmp = ChkConflict(&r,Acc,SETUP);
+ if (!tmp) {
+ tmp = ChkConflict(&r,avoid,SETUP);
+ if (!tmp) {
+ return r;
+ }
+ }
+ min = ALIGN(tmp,align_mask);
+ }
+ }
+ res_range = res_range->next;
+ }
+ RANGE(r,0,0,ResEnd);
+ return r;
+}
+
+#define mt_max ~(memType)0
+#define length sizeof(memType) * 8
+/*
+ * make_base() -- assign the lowest bits to the bits set in mask.
+ * example: mask 011010 val 0000110 -> 011000
+ */
+static memType
+make_base(memType val, memType mask)
+{
+ int i,j = 0;
+ memType ret = 0
+ ;
+ for (i = 0;i<length;i++) {
+ if ((1 << i) & mask) {
+ ret |= (((val >> j) & 1) << i);
+ j++;
+ }
+ }
+ return ret;
+}
+
+/*
+ * make_base() -- assign the bits set in mask to the lowest bits.
+ * example: mask 011010 , val 010010 -> 000011
+ */
+static memType
+unmake_base(memType val, memType mask)
+{
+ int i,j = 0;
+ memType ret = 0;
+
+ for (i = 0;i<length;i++) {
+ if ((1 << i) & mask) {
+ ret |= (((val >> i) & 1) << j);
+ j++;
+ }
+ }
+ return ret;
+}
+
+static memType
+fix_counter(memType val, memType old_mask, memType mask)
+{
+ mask = old_mask & mask;
+
+ val = make_base(val,old_mask);
+ return unmake_base(val,mask);
+}
+
+resRange
+xf86GetSparse(unsigned long type, memType fixed_bits,
+ memType decode_mask, memType address_mask, resPtr avoid)
+{
+ resRange r = {ResEnd,0,0};
+ memType new_mask;
+ memType mask1;
+ memType base;
+ memType counter = 0;
+ memType counter1;
+ memType max_counter = ~(memType)0;
+ memType max_counter1;
+ memType conflict = 0;
+
+ /* for sanity */
+ type = (type & ~(ResExtMask | ResBios | ResEstimated)) | ResSparse;
+
+ /*
+ * a sparse address consists of 3 parts:
+ * fixed_bits: F bits which hard decoded by the hardware
+ * decode_bits: D bits which are used to decode address
+ * but which may be set by software
+ * address_bits: A bits which are used to address the
+ * sparse range.
+ * the decode_mask marks all decode bits while the address_mask
+ * masks out all address_bits:
+ * F D A
+ * decode_mask: 0 1 0
+ * address_mask: 1 1 0
+ */
+ decode_mask &= address_mask;
+ new_mask = decode_mask;
+
+ /*
+ * We start by setting the decode_mask bits to different values
+ * when a conflict is found the address_mask of the conflicting
+ * resource is returned. We remove those bits from decode_mask
+ * that are also set in the returned address_mask as they always
+ * conflict with resources which use them as address masks.
+ * The resoulting mask is stored in new_mask.
+ * We continue until no conflict is found or until we have
+ * tried all possible settings of new_mask.
+ */
+ while (1) {
+ base = make_base(counter,new_mask) | fixed_bits;
+ RANGE(r,base,address_mask,type);
+ conflict = ChkConflict(&r,Acc,SETUP);
+ if (!conflict) {
+ conflict = ChkConflict(&r,avoid,SETUP);
+ if (!conflict) {
+ return r;
+ }
+ }
+ counter = fix_counter(counter,new_mask,conflict);
+ max_counter = fix_counter(max_counter,new_mask,conflict);
+ new_mask &= conflict;
+ counter ++;
+ if (counter > max_counter) break;
+ }
+ if (!new_mask && (new_mask == decode_mask)) {
+ RANGE(r,0,0,ResEnd);
+ return r;
+ }
+ /*
+ * if we haven't been successful we also try to modify those
+ * bits in decode_mask that are not at the same time set in
+ * new mask. These bits overlap with address_bits of some
+ * resources. If a conflict with a resource of this kind is
+ * found (ie. returned_mask & mask1 != mask1) with
+ * mask1 = decode_mask & ~new_mask we cannot
+ * use our choice of bits in the new_mask part. We try
+ * another choice.
+ */
+ max_counter = fix_counter(mt_max,mt_max,new_mask);
+ mask1 = decode_mask & ~new_mask;
+ max_counter1 = fix_counter(mt_max,mt_max,mask1);
+ counter = 0;
+
+ while (1) {
+ counter1 = 0;
+ while (1) {
+ base = make_base(counter1,mask1);
+ RANGE(r,base,address_mask,type);
+ conflict = ChkConflict(&r,Acc,SETUP);
+ if (!conflict) {
+ conflict = ChkConflict(&r,avoid,SETUP);
+ if (!conflict) {
+ return r;
+ }
+ }
+ counter1 ++;
+ if ((mask1 & conflict) != mask1 || counter1 > max_counter1)
+ break;
+ }
+ counter ++;
+ if (counter > max_counter) break;
+ }
+ RANGE(r,0,0,ResEnd);
+ return r;
+}
+
+#undef length
+#undef mt_max
+
+/*
+ * Resource registrarion
+ */
+
+static resList
+xf86GetResourcesImplicitly(int entityIndex)
+{
+ if (entityIndex >= xf86NumEntities) return NULL;
+
+ switch (xf86Entities[entityIndex]->bus.type) {
+ case BUS_ISA:
+ case BUS_NONE:
+ case BUS_SBUS:
+ return NULL;
+ case BUS_PCI:
+ return GetImplicitPciResources(entityIndex);
+ case BUS_last:
+ return NULL;
+ }
+ return NULL;
+}
+
+static void
+convertRange2Host(int entityIndex, resRange *pRange)
+{
+ if (pRange->type & ResBus) {
+ switch (xf86Entities[entityIndex]->busType) {
+ case BUS_PCI:
+ pciConvertRange2Host(entityIndex,pRange);
+ break;
+ case BUS_ISA:
+ isaConvertRange2Host(pRange);
+ break;
+ default:
+ break;
+ }
+
+ pRange->type &= ~ResBus;
+ }
+}
+
+/*
+ * xf86RegisterResources() -- attempts to register listed resources.
+ * If list is NULL it tries to obtain resources implicitly. Function
+ * returns a resPtr listing all resources not successfully registered.
+ */
+
+resPtr
+xf86RegisterResources(int entityIndex, resList list, unsigned long access)
+{
+ resPtr res = NULL;
+ resRange range;
+ resList list_f = NULL;
+
+ if (!list) {
+ list = xf86GetResourcesImplicitly(entityIndex);
+ /* these resources have to be in host address space already */
+ if (!list) return NULL;
+ list_f = list;
+ }
+
+ while(list->type != ResEnd) {
+ range = *list;
+
+ convertRange2Host(entityIndex,&range);
+
+ if ((access != ResNone) && (access & ResAccMask)) {
+ range.type = (range.type & ~ResAccMask) | (access & ResAccMask);
+ }
+ range.type &= ~ResEstimated; /* Not allowed for drivers */
+#if !((defined(__alpha__) || (defined(__ia64__))) && defined(linux))
+ /* On Alpha Linux, do not check for conflicts, trust the kernel. */
+ if (checkConflict(&range, Acc, entityIndex, SETUP,TRUE))
+ res = xf86AddResToList(res,&range,entityIndex);
+ else
+#endif
+ {
+ Acc = xf86AddResToList(Acc,&range,entityIndex);
+ }
+ list++;
+ }
+ if (list_f)
+ xfree(list_f);
+
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3,"Resources after driver initialization\n");
+ xf86PrintResList(3, Acc);
+ if (res) xf86MsgVerb(X_INFO, 3,
+ "Failed Resources after driver initialization "
+ "for Entity: %i\n",entityIndex);
+ xf86PrintResList(3, res);
+#endif
+ return res;
+
+}
+
+static void
+busTypeSpecific(EntityPtr pEnt, xf86State state, xf86AccessPtr *acc_mem,
+ xf86AccessPtr *acc_io, xf86AccessPtr *acc_mem_io)
+{
+ pciAccPtr *ppaccp;
+
+ switch (pEnt->bus.type) {
+ case BUS_ISA:
+ case BUS_SBUS:
+ *acc_mem = *acc_io = *acc_mem_io = &AccessNULL;
+ break;
+ break;
+ case BUS_PCI:
+ ppaccp = xf86PciAccInfo;
+ while (*ppaccp) {
+ if ((*ppaccp)->busnum == pEnt->pciBusId.bus
+ && (*ppaccp)->devnum == pEnt->pciBusId.device
+ && (*ppaccp)->funcnum == pEnt->pciBusId.func) {
+ *acc_io = &(*ppaccp)->ioAccess;
+ *acc_mem = &(*ppaccp)->memAccess;
+ *acc_mem_io = &(*ppaccp)->io_memAccess;
+ break;
+ }
+ ppaccp++;
+ }
+ break;
+ default:
+ *acc_mem = *acc_io = *acc_mem_io = NULL;
+ break;
+ }
+ return;
+}
+
+static void
+setAccess(EntityPtr pEnt, xf86State state)
+{
+
+ xf86AccessPtr acc_mem, acc_io, acc_mem_io;
+ xf86AccessPtr org_mem = NULL, org_io = NULL, org_mem_io = NULL;
+ int prop;
+
+ busTypeSpecific(pEnt,state,&acc_mem,&acc_io,&acc_mem_io);
+
+ /* The replacement function needs to handle _all_ shared resources */
+ /* unless they are handeled locally and disabled otherwise */
+ if (pEnt->rac) {
+ if (pEnt->rac->io_new) {
+ org_io = acc_io;
+ acc_io = pEnt->rac->io_new;
+ }
+ if (pEnt->rac->mem_new) {
+ org_mem = acc_mem;
+ acc_mem = pEnt->rac->mem_new;
+ }
+ if (pEnt->rac->io_mem_new) {
+ org_mem_io = acc_mem_io;
+ acc_mem_io = pEnt->rac->io_mem_new;
+ }
+ }
+
+ if (state == OPERATING) {
+ prop = pEnt->entityProp;
+ switch(pEnt->entityProp & NEED_SHARED) {
+ case NEED_SHARED:
+ pEnt->access->rt = MEM_IO;
+ break;
+ case NEED_IO_SHARED:
+ pEnt->access->rt = IO;
+ break;
+ case NEED_MEM_SHARED:
+ pEnt->access->rt = MEM;
+ break;
+ default:
+ pEnt->access->rt = NONE;
+ }
+ } else {
+ prop = NEED_SHARED | NEED_MEM | NEED_IO;
+ pEnt->access->rt = MEM_IO;
+ }
+
+ switch(pEnt->access->rt) {
+ case IO:
+ pEnt->access->pAccess = acc_io;
+ break;
+ case MEM:
+ pEnt->access->pAccess = acc_mem;
+ break;
+ case MEM_IO:
+ pEnt->access->pAccess = acc_mem_io;
+ break;
+ default: /* no conflicts at all */
+ pEnt->access->pAccess = NULL; /* remove from RAC */
+ break;
+ }
+
+ if (org_io) {
+ /* does the driver want the old access func? */
+ if (pEnt->rac->old) {
+ /* give it to the driver, leave state disabled */
+ pEnt->rac->old->io = org_io;
+ } else if (org_io->AccessEnable) {
+ /* driver doesn't want it - enable generic access */
+ org_io->AccessEnable(org_io->arg);
+ }
+ }
+
+ if (org_mem_io) {
+ /* does the driver want the old access func? */
+ if (pEnt->rac->old) {
+ /* give it to the driver, leave state disabled */
+ pEnt->rac->old->io_mem = org_mem_io;
+ } else if (org_mem_io->AccessEnable) {
+ /* driver doesn't want it - enable generic access */
+ org_mem_io->AccessEnable(org_mem_io->arg);
+ }
+ }
+
+ if (org_mem) {
+ /* does the driver want the old access func? */
+ if (pEnt->rac->old) {
+ /* give it to the driver, leave state disabled */
+ pEnt->rac->old->mem = org_mem;
+ } else if (org_mem->AccessEnable) {
+ /* driver doesn't want it - enable generic access */
+ org_mem->AccessEnable(org_mem->arg);
+ }
+ }
+
+ if (!(prop & NEED_MEM_SHARED)){
+ if (prop & NEED_MEM) {
+ if (acc_mem && acc_mem->AccessEnable)
+ acc_mem->AccessEnable(acc_mem->arg);
+ } else {
+ if (acc_mem && acc_mem->AccessDisable)
+ acc_mem->AccessDisable(acc_mem->arg);
+ }
+ }
+
+ if (!(prop & NEED_IO_SHARED)) {
+ if (prop & NEED_IO) {
+ if (acc_io && acc_io->AccessEnable)
+ acc_io->AccessEnable(acc_io->arg);
+ } else {
+ if (acc_io && acc_io->AccessDisable)
+ acc_io->AccessDisable(acc_io->arg);
+ }
+ }
+
+ /* disable shared resources */
+ if (pEnt->access->pAccess
+ && pEnt->access->pAccess->AccessDisable)
+ pEnt->access->pAccess->AccessDisable(pEnt->access->pAccess->arg);
+
+ /*
+ * If device is not under access control it is enabled.
+ * If it needs bus routing do it here as it isn't bus
+ * type specific. Any conflicts should be checked at this
+ * stage
+ */
+ if (!pEnt->access->pAccess
+ && (pEnt->entityProp & (state == SETUP ? NEED_VGA_ROUTED_SETUP :
+ NEED_VGA_ROUTED)))
+ ((BusAccPtr)pEnt->busAcc)->set_f(pEnt->busAcc);
+}
+
+
+/*
+ * xf86EnterServerState() -- set state the server is in.
+ */
+
+typedef enum { TRI_UNSET, TRI_TRUE, TRI_FALSE } TriState;
+
+static void
+SetSIGIOForState(xf86State state)
+{
+ static int sigio_state;
+ static TriState sigio_blocked = TRI_UNSET;
+
+ if ((state == SETUP) && (sigio_blocked != TRI_TRUE)) {
+ sigio_state = xf86BlockSIGIO();
+ sigio_blocked = TRI_TRUE;
+ } else if ((state == OPERATING) && (sigio_blocked != TRI_UNSET)) {
+ xf86UnblockSIGIO(sigio_state);
+ sigio_blocked = TRI_FALSE;
+ }
+}
+
+void
+xf86EnterServerState(xf86State state)
+{
+ EntityPtr pEnt;
+ ScrnInfoPtr pScrn;
+ int i,j;
+ int needVGA = 0;
+ resType rt;
+ /*
+ * This is a good place to block SIGIO during SETUP state.
+ * SIGIO should be blocked in SETUP state otherwise (u)sleep()
+ * might get interrupted early.
+ * We take care not to call xf86BlockSIGIO() twice.
+ */
+ SetSIGIOForState(state);
+#ifdef DEBUG
+ if (state == SETUP)
+ ErrorF("Entering SETUP state\n");
+ else
+ ErrorF("Entering OPERATING state\n");
+#endif
+
+ /* When servicing a dumb framebuffer we don't need to do anything */
+ if (doFramebufferMode) return;
+
+ for (i=0; i<xf86NumScreens; i++) {
+ pScrn = xf86Screens[i];
+ j = pScrn->entityList[pScrn->numEntities - 1];
+ pScrn->access = xf86Entities[j]->access;
+
+ for (j = 0; j<xf86Screens[i]->numEntities; j++) {
+ pEnt = xf86Entities[xf86Screens[i]->entityList[j]];
+ if (pEnt->entityProp & (state == SETUP ? NEED_VGA_ROUTED_SETUP
+ : NEED_VGA_ROUTED))
+ xf86Screens[i]->busAccess = pEnt->busAcc;
+ }
+ if (xf86Screens[i]->busAccess)
+ needVGA ++;
+ }
+
+ /*
+ * if we just have one screen we don't have RAC.
+ * Therefore just enable the screen and return.
+ */
+ if (!needRAC) {
+ xf86EnableAccess(xf86Screens[0]);
+ notifyStateChange(NOTIFY_ENABLE);
+ return;
+ }
+
+ if (state == SETUP)
+ notifyStateChange(NOTIFY_SETUP_TRANSITION);
+ else
+ notifyStateChange(NOTIFY_OPERATING_TRANSITION);
+
+ clearAccess();
+ for (i=0; i<xf86NumScreens;i++) {
+
+ rt = NONE;
+
+ for (j = 0; j<xf86Screens[i]->numEntities; j++) {
+ pEnt = xf86Entities[xf86Screens[i]->entityList[j]];
+ setAccess(pEnt,state);
+
+ if (pEnt->access->rt != NONE) {
+ if (rt != NONE && rt != pEnt->access->rt)
+ rt = MEM_IO;
+ else
+ rt = pEnt->access->rt;
+ }
+ }
+ xf86Screens[i]->resourceType = rt;
+ if (rt == NONE) {
+ xf86Screens[i]->access = NULL;
+ if (needVGA < 2)
+ xf86Screens[i]->busAccess = NULL;
+ }
+
+#ifdef DEBUG
+ if (xf86Screens[i]->busAccess)
+ ErrorF("Screen %i setting vga route\n",i);
+#endif
+ switch (rt) {
+ case MEM_IO:
+ xf86MsgVerb(X_INFO, 3, "Screen %i shares mem & io resources\n",i);
+ break;
+ case IO:
+ xf86MsgVerb(X_INFO, 3, "Screen %i shares io resources\n",i);
+ break;
+ case MEM:
+ xf86MsgVerb(X_INFO, 3, "Screen %i shares mem resources\n",i);
+ break;
+ default:
+ xf86MsgVerb(X_INFO, 3, "Entity %i shares no resources\n",i);
+ break;
+ }
+ }
+ if (state == SETUP)
+ notifyStateChange(NOTIFY_SETUP);
+ else
+ notifyStateChange(NOTIFY_OPERATING);
+}
+
+/*
+ * xf86SetOperatingState() -- Set ResOperMask for resources listed.
+ */
+resPtr
+xf86SetOperatingState(resList list, int entityIndex, int mask)
+{
+ resPtr acc;
+ resPtr r_fail = NULL;
+ resRange range;
+
+ while (list->type != ResEnd) {
+ range = *list;
+ convertRange2Host(entityIndex,&range);
+
+ acc = Acc;
+ while (acc) {
+#define MASK (ResTypeMask | ResExtMask)
+ if ((acc->entityIndex == entityIndex)
+ && (acc->val.a == range.a) && (acc->val.b == range.b)
+ && ((acc->val.type & MASK) == (range.type & MASK)))
+ break;
+#undef MASK
+ acc = acc->next;
+ }
+ if (acc)
+ acc->val.type = (acc->val.type & ~ResOprMask)
+ | (mask & ResOprMask);
+ else {
+ r_fail = xf86AddResToList(r_fail,&range,entityIndex);
+ }
+ list ++;
+ }
+
+ return r_fail;
+}
+
+/*
+ * Stage specific code
+ */
+ /*
+ * ProcessEstimatedConflicts() -- Do something about driver-registered
+ * resources that conflict with estimated resources. For now, just register
+ * them with a logged warning.
+ */
+#ifdef REDUCER
+static void
+ProcessEstimatedConflicts(void)
+{
+ if (!AccReducers)
+ return;
+
+ /* Temporary */
+ xf86MsgVerb(X_WARNING, 3,
+ "Registering the following despite conflicts with estimated"
+ " resources:\n");
+ xf86PrintResList(3, AccReducers);
+ Acc = xf86JoinResLists(Acc, AccReducers);
+ AccReducers = NULL;
+}
+#endif
+
+/*
+ * xf86ClaimFixedResources() -- This function gets called from the
+ * driver Probe() function to claim fixed resources.
+ */
+static void
+resError(resList list)
+{
+ FatalError("A driver tried to allocate the %s %sresource at \n"
+ "0x%lx:0x%lx which conflicted with another resource. Send the\n"
+ "output of the server to %s. Please \n"
+ "specify your computer hardware as closely as possible.\n",
+ ResIsBlock(list)?"Block":"Sparse",
+ ResIsMem(list)?"Mem":"Io",
+ ResIsBlock(list)?list->rBegin:list->rBase,
+ ResIsBlock(list)?list->rEnd:list->rMask,BUILDERADDR);
+}
+
+/*
+ * xf86ClaimFixedResources() is used to allocate non-relocatable resources.
+ * This should only be done by a driver's Probe() function.
+ */
+void
+xf86ClaimFixedResources(resList list, int entityIndex)
+{
+ resPtr ptr = NULL;
+ resRange range;
+
+ if (!list) return;
+
+ while (list->type !=ResEnd) {
+ range = *list;
+
+ convertRange2Host(entityIndex,&range);
+
+ range.type &= ~ResEstimated; /* Not allowed for drivers */
+ switch (range.type & ResAccMask) {
+ case ResExclusive:
+ if (!xf86ChkConflict(&range, entityIndex)) {
+ Acc = xf86AddResToList(Acc, &range, entityIndex);
+#ifdef REDUCER
+ } else {
+ range.type |= ResEstimated;
+ if (!xf86ChkConflict(&range, entityIndex) &&
+ !checkConflict(&range, AccReducers, entityIndex,
+ SETUP, FALSE)) {
+ range.type &= ~(ResEstimated | ResBios);
+ AccReducers =
+ xf86AddResToList(AccReducers, &range, entityIndex);
+#endif
+ } else resError(&range); /* no return */
+#ifdef REDUCER
+ }
+#endif
+ break;
+ case ResShared:
+ /* at this stage the resources are just added to the
+ * EntityRec. After the Probe() phase this list is checked by
+ * xf86PostProbe(). All resources which don't
+ * conflict with already allocated ones are allocated
+ * and removed from the EntityRec. Thus a non-empty resource
+ * list in the EntityRec indicates resource conflicts the
+ * driver should either handle or fail.
+ */
+ if (xf86Entities[entityIndex]->active)
+ ptr = xf86AddResToList(ptr,&range,entityIndex);
+ break;
+ }
+ list++;
+ }
+ xf86Entities[entityIndex]->resources =
+ xf86JoinResLists(xf86Entities[entityIndex]->resources,ptr);
+ xf86MsgVerb(X_INFO, 3,
+ "resource ranges after xf86ClaimFixedResources() call:\n");
+ xf86PrintResList(3,Acc);
+#ifdef REDUCER
+ ProcessEstimatedConflicts();
+#endif
+#ifdef DEBUG
+ if (ptr) {
+ xf86MsgVerb(X_INFO, 3, "to be registered later:\n");
+ xf86PrintResList(3,ptr);
+ }
+#endif
+}
+
+static void
+checkRoutingForScreens(xf86State state)
+{
+ resList list = resVgaUnusedExclusive;
+ resPtr pResVGA = NULL;
+ resPtr pResVGAHost;
+ pointer vga = NULL;
+ int i,j;
+ int entityIndex;
+ EntityPtr pEnt;
+ resPtr pAcc;
+ resRange range;
+
+ /*
+ * find devices that need VGA routed: ie the ones that have
+ * registered VGA resources without ResUnused. ResUnused
+ * doesn't conflict with itself therefore use it here.
+ */
+ while (list->type != ResEnd) { /* create resPtr from resList for VGA */
+ range = *list;
+ range.type &= ~(ResBios | ResEstimated); /* if set remove them */
+ pResVGA = xf86AddResToList(pResVGA, &range, -1);
+ list++;
+ }
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ for (j = 0; j < xf86Screens[i]->numEntities; j++) {
+ entityIndex = xf86Screens[i]->entityList[j];
+ pEnt = xf86Entities[entityIndex];
+ pAcc = Acc;
+ vga = NULL;
+ pResVGAHost = xf86DupResList(pResVGA);
+ xf86ConvertListToHost(entityIndex,pResVGAHost);
+ while (pAcc) {
+ if (pAcc->entityIndex == entityIndex)
+ if (checkConflict(&pAcc->val, pResVGAHost,
+ entityIndex, state, FALSE)) {
+ if (vga && vga != pEnt->busAcc) {
+ xf86Msg(X_ERROR, "Screen %i needs vga routed to"
+ "different buses - deleting\n",i);
+ xf86DeleteScreen(i--,0);
+ }
+#ifdef DEBUG
+ {
+ resPtr rlist = xf86AddResToList(NULL,&pAcc->val,
+ pAcc->entityIndex);
+ xf86MsgVerb(X_INFO,3,"====== %s\n",
+ state == OPERATING ? "OPERATING"
+ : "SETUP");
+ xf86MsgVerb(X_INFO,3,"%s Resource:\n",
+ (pAcc->val.type) & ResMem ? "Mem" :"Io");
+ xf86PrintResList(3,rlist);
+ xf86FreeResList(rlist);
+ xf86MsgVerb(X_INFO,3,"Conflicts with:\n");
+ xf86PrintResList(3,pResVGAHost);
+ xf86MsgVerb(X_INFO,3,"=====\n");
+ }
+#endif
+ vga = pEnt->busAcc;
+ pEnt->entityProp |= (state == SETUP
+ ? NEED_VGA_ROUTED_SETUP : NEED_VGA_ROUTED);
+ if (state == OPERATING) {
+ if (pAcc->val.type & ResMem)
+ pEnt->entityProp |= NEED_VGA_MEM;
+ else
+ pEnt->entityProp |= NEED_VGA_IO;
+ }
+ }
+ pAcc = pAcc->next;
+ }
+ if (vga)
+ xf86MsgVerb(X_INFO, 3,"Setting vga for screen %i.\n",i);
+ xf86FreeResList(pResVGAHost);
+ }
+ }
+ xf86FreeResList(pResVGA);
+}
+
+/*
+ * xf86PostProbe() -- Allocate all non conflicting resources
+ * This function gets called by xf86Init().
+ */
+void
+xf86PostProbe(void)
+{
+ memType val;
+ int i,j;
+ resPtr resp, acc, tmp, resp_x, *pprev_next;
+
+ if (fbSlotClaimed) {
+ if (pciSlotClaimed || isaSlotClaimed
+#if defined(__sparc__) && !defined(__OpenBSD__)
+ || sbusSlotClaimed
+#endif
+ ) {
+ FatalError("Cannot run in framebuffer mode. Please specify busIDs "
+ " for all framebuffer devices\n");
+ return;
+ } else {
+ xf86Msg(X_INFO,"Running in FRAMEBUFFER Mode\n");
+ xf86AccessRestoreState();
+ notifyStateChange(NOTIFY_ENABLE);
+ doFramebufferMode = TRUE;
+
+ return;
+ }
+ }
+ /* don't compare against ResInit - remove it from clone.*/
+ acc = tmp = xf86DupResList(Acc);
+ pprev_next = &acc;
+ while (tmp) {
+ if (tmp->res_type & ResInit) {
+ (*pprev_next) = tmp->next;
+ xfree(tmp);
+ } else
+ pprev_next = &(tmp->next);
+ tmp = (*pprev_next);
+ }
+
+ for (i=0; i<xf86NumEntities; i++) {
+ resp = xf86Entities[i]->resources;
+ xf86Entities[i]->resources = NULL;
+ resp_x = NULL;
+ while (resp) {
+ if (! (val = checkConflict(&resp->val,acc,i,SETUP,FALSE))) {
+ resp->res_type &= ~(ResBios); /* just used for chkConflict() */
+ tmp = resp_x;
+ resp_x = resp;
+ resp = resp->next;
+ resp_x->next = tmp;
+#ifdef REDUCER
+ } else {
+ resp->res_type |= ResEstimated;
+ if (!checkConflict(&resp->val, acc, i, SETUP, FALSE)) {
+ resp->res_type &= ~(ResEstimated | ResBios);
+ tmp = AccReducers;
+ AccReducers = resp;
+ resp = resp->next;
+ AccReducers->next = tmp;
+#endif
+ } else {
+ xf86MsgVerb(X_INFO, 3, "Found conflict at: 0x%lx\n",val);
+ resp->res_type &= ~ResEstimated;
+ tmp = xf86Entities[i]->resources;
+ xf86Entities[i]->resources = resp;
+ resp = resp->next;
+ xf86Entities[i]->resources->next = tmp;
+ }
+#ifdef REDUCER
+ }
+#endif
+ }
+ xf86JoinResLists(Acc,resp_x);
+#ifdef REDUCER
+ ProcessEstimatedConflicts();
+#endif
+ }
+ xf86FreeResList(acc);
+#if !(defined(__alpha__) && defined(linux)) && \
+ !(defined(__ia64__) && defined(linux)) && \
+ !(defined(__sparc64__) && defined(__OpenBSD__))
+ /*
+ * No need to validate on Alpha Linux or OpenBSD/sparc64,
+ * trust the kernel.
+ */
+ ValidatePci();
+#endif
+
+ xf86MsgVerb(X_INFO, 3, "resource ranges after probing:\n");
+ xf86PrintResList(3, Acc);
+ checkRoutingForScreens(SETUP);
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ for (j = 0; j<xf86Screens[i]->numEntities; j++) {
+ EntityPtr pEnt = xf86Entities[xf86Screens[i]->entityList[j]];
+ if ((pEnt->entityProp & NEED_VGA_ROUTED_SETUP) &&
+ ((xf86Screens[i]->busAccess = pEnt->busAcc)))
+ break;
+ }
+ }
+}
+
+static void
+checkRequiredResources(int entityIndex)
+{
+ resRange range;
+ resPtr pAcc = Acc;
+ const EntityPtr pEnt = xf86Entities[entityIndex];
+ while (pAcc) {
+ if (pAcc->entityIndex == entityIndex) {
+ range = pAcc->val;
+ /* ResAny to find conflicts with anything. */
+ range.type = (range.type & ~ResAccMask) | ResAny | ResBios;
+ if (checkConflict(&range,Acc,entityIndex,OPERATING,FALSE))
+ switch (pAcc->res_type & ResPhysMask) {
+ case ResMem:
+ pEnt->entityProp |= NEED_MEM_SHARED;
+ break;
+ case ResIo:
+ pEnt->entityProp |= NEED_IO_SHARED;
+ break;
+ }
+ if (!(pAcc->res_type & ResOprMask)) {
+ switch (pAcc->res_type & ResPhysMask) {
+ case ResMem:
+ pEnt->entityProp |= NEED_MEM;
+ break;
+ case ResIo:
+ pEnt->entityProp |= NEED_IO;
+ break;
+ }
+ }
+ }
+ pAcc = pAcc->next;
+ }
+
+ /* check if we can separately enable mem/io resources */
+ /* XXX we still need to find out how to set this yet */
+ if ( ((pEnt->entityProp & NO_SEPARATE_MEM_FROM_IO)
+ && (pEnt->entityProp & NEED_MEM_SHARED))
+ || ((pEnt->entityProp & NO_SEPARATE_IO_FROM_MEM)
+ && (pEnt->entityProp & NEED_IO_SHARED)) )
+ pEnt->entityProp |= NEED_SHARED;
+ /*
+ * After we have checked all resources of an entity agains any
+ * other resource we know if the entity need this resource type
+ * (ie. mem/io) at all. if not we can disable this type completely,
+ * so no need to share it either.
+ */
+ if ((pEnt->entityProp & NEED_MEM_SHARED)
+ && (!(pEnt->entityProp & NEED_MEM))
+ && (!(pEnt->entityProp & NO_SEPARATE_MEM_FROM_IO)))
+ pEnt->entityProp &= ~(unsigned long)NEED_MEM_SHARED;
+
+ if ((pEnt->entityProp & NEED_IO_SHARED)
+ && (!(pEnt->entityProp & NEED_IO))
+ && (!(pEnt->entityProp & NO_SEPARATE_IO_FROM_MEM)))
+ pEnt->entityProp &= ~(unsigned long)NEED_IO_SHARED;
+}
+
+void
+xf86PostPreInit()
+{
+ if (doFramebufferMode) return;
+
+ if (xf86NumScreens > 1)
+ needRAC = TRUE;
+
+#ifdef XFree86LOADER
+ xf86MsgVerb(X_INFO, 3, "do I need RAC?");
+
+ if (needRAC) {
+ xf86ErrorFVerb(3, " Yes, I do.\n");
+
+ if (!xf86LoadOneModule("rac",NULL))
+ FatalError("Cannot load RAC module\n");
+ } else
+ xf86ErrorFVerb(3, " No, I don't.\n");
+#endif
+
+ xf86MsgVerb(X_INFO, 3, "resource ranges after preInit:\n");
+ xf86PrintResList(3, Acc);
+}
+
+void
+xf86PostScreenInit(void)
+{
+ int i,j;
+ ScreenPtr pScreen;
+ unsigned int flags;
+ int nummem = 0, numio = 0;
+#ifdef XFree86LOADER
+ pointer xf86RACInit = NULL;
+#endif
+
+ if (doFramebufferMode) {
+ SetSIGIOForState(OPERATING);
+ return;
+ }
+
+#ifdef XFree86LOADER
+ if (needRAC) {
+ xf86RACInit = LoaderSymbol("xf86RACInit");
+ if (!xf86RACInit)
+ FatalError("Cannot resolve symbol \"xf86RACInit\"\n");
+ }
+#endif
+#ifdef DEBUG
+ ErrorF("PostScreenInit generation: %i\n",serverGeneration);
+#endif
+ if (serverGeneration == 1) {
+ checkRoutingForScreens(OPERATING);
+ for (i=0; i<xf86NumEntities; i++) {
+ checkRequiredResources(i);
+ }
+
+ /*
+ * after removing NEED_XXX_SHARED from entities that
+ * don't need need XXX resources at all we might have
+ * a single entity left that has NEED_XXX_SHARED set.
+ * In this case we can delete that, too.
+ */
+ for (i = 0; i < xf86NumEntities; i++) {
+ if (xf86Entities[i]->entityProp & NEED_MEM_SHARED)
+ nummem++;
+ if (xf86Entities[i]->entityProp & NEED_IO_SHARED)
+ numio++;
+ }
+ for (i = 0; i < xf86NumEntities; i++) {
+ if (nummem < 2)
+ xf86Entities[i]->entityProp &= ~NEED_MEM_SHARED;
+ if (numio < 2)
+ xf86Entities[i]->entityProp &= ~NEED_IO_SHARED;
+ }
+ }
+
+ if (xf86Screens && needRAC) {
+ int needRACforVga = 0;
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ for (j = 0; j < xf86Screens[i]->numEntities; j++) {
+ if (xf86Entities[xf86Screens[i]->entityList[j]]->entityProp
+ & NEED_VGA_ROUTED) {
+ needRACforVga ++;
+ break; /* only count each screen once */
+ }
+ }
+ }
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ Bool needRACforMem = FALSE, needRACforIo = FALSE;
+
+ for (j = 0; j < xf86Screens[i]->numEntities; j++) {
+ if (xf86Entities[xf86Screens[i]->entityList[j]]->entityProp
+ & NEED_MEM_SHARED)
+ needRACforMem = TRUE;
+ if (xf86Entities[xf86Screens[i]->entityList[j]]->entityProp
+ & NEED_IO_SHARED)
+ needRACforIo = TRUE;
+ /*
+ * We may need RAC although we don't share any resources
+ * as we need to route VGA to the correct bus. This can
+ * only be done simultaniously for MEM and IO.
+ */
+ if (needRACforVga > 1) {
+ if (xf86Entities[xf86Screens[i]->entityList[j]]->entityProp
+ & NEED_VGA_MEM)
+ needRACforMem = TRUE;
+ if (xf86Entities[xf86Screens[i]->entityList[j]]->entityProp
+ & NEED_VGA_IO)
+ needRACforIo = TRUE;
+ }
+ }
+
+ pScreen = xf86Screens[i]->pScreen;
+ flags = 0;
+ if (needRACforMem) {
+ flags |= xf86Screens[i]->racMemFlags;
+ xf86ErrorFVerb(3, "Screen %d is using RAC for mem\n", i);
+ }
+ if (needRACforIo) {
+ flags |= xf86Screens[i]->racIoFlags;
+ xf86ErrorFVerb(3, "Screen %d is using RAC for io\n", i);
+ }
+
+#ifdef XFree86LOADER
+ ((Bool(*)(ScreenPtr,unsigned int))xf86RACInit)
+ (pScreen,flags);
+#else
+ xf86RACInit(pScreen,flags);
+#endif
+ }
+ }
+
+ xf86EnterServerState(OPERATING);
+
+}
+
+/*
+ * Sets
+ */
+
+
+static resPtr
+decomposeSparse(resRange range)
+{
+ resRange new;
+ resPtr ret = NULL;
+ memType val = range.rBegin;
+ int i = 0;
+
+ new.type = (range.type & ~ResExtMask) | ResSparse;
+
+ while (1) {
+ if (val & 0x01) {
+ new.rBase = (val << i);
+ new.rMask = ~((1 << i) - 1);
+ ret = xf86AddResToList(ret,&new,-1);
+ val ++;
+ }
+ i++;
+ val >>= 1;
+ if ((((val + 1) << i) - 1) > range.rEnd)
+ break;
+ }
+ i--;
+ val <<= 1;
+
+ while (1) {
+ if((((val + 1) << i) - 1)> range.rEnd) {
+ if (--i < 0) break;
+ val <<= 1;
+ } else {
+ new.rBase = (val << i);
+ new.rMask = ~((1 << i) - 1);
+ val++;
+ ret = xf86AddResToList(ret,&new,-1);
+ }
+ }
+ return ret;
+}
+
+static Bool
+x_isSubsetOf(resRange range, resPtr list1, resPtr list2)
+{
+ resRange range1, range2;
+ memType m1_A_m2;
+ Bool ret;
+ resPtr list;
+
+ if (list1) {
+ list = list1;
+ if ((range.type & ResTypeMask) == (list->res_type & ResTypeMask)) {
+ switch (range.type & ResExtMask) {
+ case ResBlock:
+ if ((list->res_type & ResExtMask) == ResBlock) {
+ if (range.rBegin >= list->block_begin
+ && range.rEnd <= list->block_end)
+ return TRUE;
+ else if (range.rBegin < list->block_begin
+ && range.rEnd > list->block_end) {
+ RANGE(range1, range.rBegin, list->block_begin - 1,
+ range.type);
+ RANGE(range2, list->block_end + 1, range.rEnd,
+ range.type);
+ return (x_isSubsetOf(range1,list->next,list2) &&
+ x_isSubsetOf(range2,list->next,list2));
+ }
+ else if (range.rBegin >= list->block_begin
+ && range.rBegin <= list->block_end) {
+ RANGE(range1, list->block_end + 1, range.rEnd,
+ range.type);
+ return (x_isSubsetOf(range1,list->next,list2));
+ } else if (range.rEnd >= list->block_begin
+ && range.rEnd <= list->block_end) {
+ RANGE(range1,range.rBegin, list->block_begin - 1,
+ range.type);
+ return (x_isSubsetOf(range1,list->next,list2));
+ }
+ }
+ break;
+ case ResSparse:
+ if ((list->res_type & ResExtMask) == ResSparse) {
+ memType test;
+ int i;
+
+ m1_A_m2 = range.rMask & list->sparse_mask;
+ if ((range.rBase ^ list->sparse_base) & m1_A_m2)
+ break;
+ /*
+ * We use the following system:
+ * let 0 ^= mask:1 base:0, 1 ^= mask:1 base:1,
+ * X mask:0 ; S: set TSS: test set for subset
+ * NTSS: new test set after test
+ * S: 1 0 1 0 X X 0 1 X
+ * TSS: 1 0 0 1 1 0 X X X
+ * T: 0 0 1 1 0 0 0 0 0
+ * NTSS: 1 0 0/X 1/X 1 0 1 0 X
+ * R: 0 0 0 0 0 0 1 1 0
+ * If R != 0 TSS and S are disjunct
+ * If R == 0 TSS is subset of S
+ * If R != 0 NTSS contains elements from TSS
+ * which are not also members of S.
+ * If a T is set one of the correspondig bits
+ * in NTSS must be set to the specified value
+ * all other are X
+ */
+ test = list->sparse_mask & ~range.rMask;
+ if (test == 0)
+ return TRUE;
+ for (i = 0; i < sizeof(memType); i++) {
+ if ((test >> i) & 0x1) {
+ RANGE(range1, ((range.rBase & list->sparse_base)
+ | (range.rBase & ~list->sparse_mask)
+ | ((~list->sparse_base & list->sparse_mask)
+ & ~range.rMask)) & range1.rMask,
+ ((range.rMask | list->sparse_mask) & ~test)
+ | (1 << i), range.type);
+ return (x_isSubsetOf(range1,list->next,list2));
+ }
+ }
+ }
+ break;
+ }
+ }
+ return (x_isSubsetOf(range,list->next,list2));
+ } else if (list2) {
+ resPtr tmpList = NULL;
+ switch (range.type & ResExtMask) {
+ case ResBlock:
+ tmpList = decomposeSparse(range);
+ while (tmpList) {
+ if (!x_isSubsetOf(tmpList->val,list2,NULL)) {
+ xf86FreeResList(tmpList);
+ return FALSE;
+ }
+ tmpList = tmpList->next;
+ }
+ xf86FreeResList(tmpList);
+ return TRUE;
+ break;
+ case ResSparse:
+ while (list2) {
+ tmpList = xf86JoinResLists(tmpList,decomposeSparse(list2->val));
+ list2 = list2->next;
+ }
+ ret = x_isSubsetOf(range,tmpList,NULL);
+ xf86FreeResList(tmpList);
+ return ret;
+ break;
+ }
+ } else
+ return FALSE;
+
+ return FALSE;
+}
+
+Bool
+xf86IsSubsetOf(resRange range, resPtr list)
+{
+ resPtr dup = xf86DupResList(list);
+ resPtr r_sp = NULL, r = NULL, tmp = NULL;
+ Bool ret = FALSE;
+
+ while (dup) {
+ tmp = dup;
+ dup = dup->next;
+ switch (tmp->res_type & ResExtMask) {
+ case ResBlock:
+ tmp->next = r;
+ r = tmp;
+ break;
+ case ResSparse:
+ tmp->next = r_sp;
+ r_sp = tmp;
+ break;
+ }
+ }
+
+ switch (range.type & ResExtMask) {
+ case ResBlock:
+ ret = x_isSubsetOf(range,r,r_sp);
+ break;
+ case ResSparse:
+ ret = x_isSubsetOf(range,r_sp,r);
+ break;
+ }
+ xf86FreeResList(r);
+ xf86FreeResList(r_sp);
+
+ return ret;
+}
+
+Bool
+xf86IsListSubsetOf(resPtr list, resPtr BaseList)
+{
+ while (list) {
+ if (! xf86IsSubsetOf(list->val,BaseList))
+ return FALSE;
+ list = list->next;
+ }
+ return TRUE;
+}
+
+resPtr
+findIntersect(resRange Range, resPtr list)
+{
+ resRange range;
+ resPtr new = NULL;
+
+ while (list) {
+ if ((Range.type & ResTypeMask) == (list->res_type & ResTypeMask)) {
+ switch (Range.type & ResExtMask) {
+ case ResBlock:
+ switch (list->res_type & ResExtMask) {
+ case ResBlock:
+ if (Range.rBegin >= list->block_begin)
+ range.rBegin = Range.rBegin;
+ else
+ range.rBegin = list->block_begin;
+ if (Range.rEnd <= list->block_end)
+ range.rEnd = Range.rEnd;
+ else
+ range.rEnd = list->block_end;
+ if (range.rEnd > range.rBegin) {
+ range.type = Range.type;
+ new = xf86AddResToList(new,&range,-1);
+ }
+ break;
+ case ResSparse:
+ new = xf86JoinResLists(new,xf86FindIntersectOfLists(new,decomposeSparse(list->val)));
+ break;
+ }
+ break;
+ case ResSparse:
+ switch (list->res_type & ResExtMask) {
+ case ResSparse:
+ if (!((~(range.rBase ^ list->sparse_base)
+ & (range.rMask & list->sparse_mask)))) {
+ RANGE(range, (range.rBase & list->sparse_base)
+ | (~range.rMask & list->sparse_base)
+ | (~list->sparse_mask & range.rBase),
+ range.rMask | list->sparse_mask,
+ Range.type);
+ new = xf86AddResToList(new,&range,-1);
+ }
+ break;
+ case ResBlock:
+ new = xf86JoinResLists(new,xf86FindIntersectOfLists(
+ decomposeSparse(range),list));
+ break;
+ }
+ }
+ }
+ list = list->next;
+ }
+ return new;
+}
+
+resPtr
+xf86FindIntersectOfLists(resPtr l1, resPtr l2)
+{
+ resPtr ret = NULL;
+
+ while (l1) {
+ ret = xf86JoinResLists(ret,findIntersect(l1->val,l2));
+ l1 = l1->next;
+ }
+ return ret;
+}
+
+#if 0 /* Not used */
+static resPtr
+xf86FindComplement(resRange Range)
+{
+ resRange range;
+ memType tmp;
+ resPtr new = NULL;
+ int i;
+
+ switch (Range.type & ResExtMask) {
+ case ResBlock:
+ if (Range.rBegin > 0) {
+ RANGE(range, 0, Range.rBegin - 1, Range.type);
+ new = xf86AddResToList(new,&range,-1);
+ }
+ if (Range.rEnd < (memType)~0) {
+ RANGE(range,Range.rEnd + 1, (memType)~0, Range.type);
+ new = xf86AddResToList(new,&range,-1);
+ }
+ break;
+ case ResSparse:
+ tmp = Range.rMask;
+ for (i = 0; i < sizeof(memType); i++) {
+ if (tmp & 0x1) {
+ RANGE(range,(~Range.rMask & range.rMask),(1 << i), Range.type);
+ new = xf86AddResToList(new,&range,-1);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return new;
+}
+#endif
+
+resPtr
+xf86ExtractTypeFromList(resPtr list, unsigned long type)
+{
+ resPtr ret = NULL;
+
+ while (list) {
+ if ((list->res_type & ResTypeMask) == type)
+ ret = xf86AddResToList(ret,&(list->val),list->entityIndex);
+ list = list->next;
+ }
+ return ret;
+}
+
+/*------------------------------------------------------------*/
+static void CheckGenericGA(void);
+
+/*
+ * xf86FindPrimaryDevice() - Find the display device which
+ * was active when the server was started.
+ */
+void
+xf86FindPrimaryDevice()
+{
+ /* if no VGA device is found check for primary PCI device */
+ if (primaryBus.type == BUS_NONE && xorgHWAccess)
+ CheckGenericGA();
+ if (primaryBus.type != BUS_NONE) {
+ char *bus;
+ char *loc = xnfcalloc(1,9);
+ if (loc == NULL) return;
+
+ switch (primaryBus.type) {
+ case BUS_PCI:
+ bus = "PCI";
+ sprintf(loc," %2.2x:%2.2x:%1.1x",primaryBus.id.pci.bus,
+ primaryBus.id.pci.device,primaryBus.id.pci.func);
+ break;
+ case BUS_ISA:
+ bus = "ISA";
+ loc[0] = '\0';
+ break;
+ case BUS_SBUS:
+ bus = "SBUS";
+ sprintf(loc," %2.2x",primaryBus.id.sbus.fbNum);
+ break;
+ default:
+ bus = "";
+ loc[0] = '\0';
+ }
+
+ xf86MsgVerb(X_INFO, 2, "Primary Device is: %s%s\n",bus,loc);
+ xfree(loc);
+ }
+
+}
+
+#if !defined(__sparc__) && !defined(__powerpc__) && !defined(__mips__)
+#include "vgaHW.h"
+#include "compiler.h"
+#endif
+
+/*
+ * CheckGenericGA() - Check for presence of a VGA device.
+ */
+static void
+CheckGenericGA()
+{
+/* This needs to be changed for multiple domains */
+#if !defined(__sparc__) && !defined(__powerpc__) && !defined(__mips__) && !defined(__ia64__)
+ IOADDRESS GenericIOBase = VGAHW_GET_IOBASE();
+ CARD8 CurrentValue, TestValue;
+
+ /* VGA CRTC registers are not used here, so don't bother unlocking them */
+
+ /* VGA has one more read/write attribute register than EGA */
+ (void) inb(GenericIOBase + VGA_IN_STAT_1_OFFSET); /* Reset flip-flop */
+ outb(VGA_ATTR_INDEX, 0x14 | 0x20);
+ CurrentValue = inb(VGA_ATTR_DATA_R);
+ outb(VGA_ATTR_DATA_W, CurrentValue ^ 0x0F);
+ outb(VGA_ATTR_INDEX, 0x14 | 0x20);
+ TestValue = inb(VGA_ATTR_DATA_R);
+ outb(VGA_ATTR_DATA_W, CurrentValue);
+
+ if ((CurrentValue ^ 0x0F) == TestValue) {
+ primaryBus.type = BUS_ISA;
+ }
+#endif
+}
+
+Bool
+xf86NoSharedResources(int screenIndex,resType res)
+{
+ int j;
+
+ if (screenIndex > xf86NumScreens)
+ return TRUE;
+
+ for (j = 0; j < xf86Screens[screenIndex]->numEntities; j++) {
+ switch (res) {
+ case IO:
+ if ( xf86Entities[xf86Screens[screenIndex]->entityList[j]]->entityProp
+ & NEED_IO_SHARED)
+ return FALSE;
+ break;
+ case MEM:
+ if ( xf86Entities[xf86Screens[screenIndex]->entityList[j]]->entityProp
+ & NEED_MEM_SHARED)
+ return FALSE;
+ break;
+ case MEM_IO:
+ if ( xf86Entities[xf86Screens[screenIndex]->entityList[j]]->entityProp
+ & NEED_SHARED)
+ return FALSE;
+ break;
+ case NONE:
+ break;
+ }
+ }
+ return TRUE;
+}
+
+void
+xf86ConvertListToHost(int entityIndex, resPtr list)
+{
+ while (list) {
+ convertRange2Host(entityIndex, &list->val);
+ list = list->next;
+ }
+}
+
+void
+xf86RegisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func, pointer arg)
+{
+ StateChangeNotificationPtr ptr =
+ (StateChangeNotificationPtr)xnfalloc(sizeof(StateChangeNotificationRec));
+
+ ptr->func = func;
+ ptr->arg = arg;
+ ptr->next = StateChangeNotificationList;
+ StateChangeNotificationList = ptr;
+}
+
+Bool
+xf86DeregisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func)
+{
+ StateChangeNotificationPtr *ptr = &StateChangeNotificationList;
+ StateChangeNotificationPtr tmp;
+
+ while (*ptr) {
+ if ((*ptr)->func == func) {
+ tmp = (*ptr);
+ (*ptr) = (*ptr)->next;
+ xfree(tmp);
+ return TRUE;
+ }
+ ptr = &((*ptr)->next);
+ }
+ return FALSE;
+}
+
+static void
+notifyStateChange(xf86NotifyState state)
+{
+ StateChangeNotificationPtr ptr = StateChangeNotificationList;
+ while (ptr) {
+ ptr->func(state,ptr->arg);
+ ptr = ptr->next;
+ }
+}
+
+#ifdef async
+Bool
+xf86QueueAsyncEvent(void (*func)(pointer),pointer arg)
+{
+ AsyncQPtr new;
+
+ if (!AsyncQ) return FALSE;
+
+ new = (AsyncQPtr)xfnalloc(sizeof(AsyncQRec));
+ new->func = func;
+ new->arg = arg;
+ (*AsyncQPtr)->next = new;
+ AsyncQPtr = &new;
+ return TRUE;
+}
+#endif
+
+/* Multihead accel sharing accessor functions and entity Private handling */
+
+int
+xf86GetLastScrnFlag(int entityIndex)
+{
+ if(entityIndex < xf86NumEntities) {
+ return(xf86Entities[entityIndex]->lastScrnFlag);
+ } else {
+ return -1;
+ }
+}
+
+void
+xf86SetLastScrnFlag(int entityIndex, int scrnIndex)
+{
+ if(entityIndex < xf86NumEntities) {
+ xf86Entities[entityIndex]->lastScrnFlag = scrnIndex;
+ }
+}
+
+Bool
+xf86IsEntityShared(int entityIndex)
+{
+ if(entityIndex < xf86NumEntities) {
+ if(xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void
+xf86SetEntityShared(int entityIndex)
+{
+ if(entityIndex < xf86NumEntities) {
+ xf86Entities[entityIndex]->entityProp |= IS_SHARED_ACCEL;
+ }
+}
+
+Bool
+xf86IsEntitySharable(int entityIndex)
+{
+ if(entityIndex < xf86NumEntities) {
+ if(xf86Entities[entityIndex]->entityProp & ACCEL_IS_SHARABLE) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void
+xf86SetEntitySharable(int entityIndex)
+{
+ if(entityIndex < xf86NumEntities) {
+ xf86Entities[entityIndex]->entityProp |= ACCEL_IS_SHARABLE;
+ }
+}
+
+Bool
+xf86IsPrimInitDone(int entityIndex)
+{
+ if(entityIndex < xf86NumEntities) {
+ if(xf86Entities[entityIndex]->entityProp & SA_PRIM_INIT_DONE) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void
+xf86SetPrimInitDone(int entityIndex)
+{
+ if(entityIndex < xf86NumEntities) {
+ xf86Entities[entityIndex]->entityProp |= SA_PRIM_INIT_DONE;
+ }
+}
+
+void
+xf86ClearPrimInitDone(int entityIndex)
+{
+ if(entityIndex < xf86NumEntities) {
+ xf86Entities[entityIndex]->entityProp &= ~SA_PRIM_INIT_DONE;
+ }
+}
+
+
+/*
+ * Allocate a private in the entities.
+ */
+
+int
+xf86AllocateEntityPrivateIndex(void)
+{
+ int idx, i;
+ EntityPtr pEnt;
+ DevUnion *nprivs;
+
+ idx = xf86EntityPrivateCount++;
+ for (i = 0; i < xf86NumEntities; i++) {
+ pEnt = xf86Entities[i];
+ nprivs = xnfrealloc(pEnt->entityPrivates,
+ xf86EntityPrivateCount * sizeof(DevUnion));
+ /* Zero the new private */
+ bzero(&nprivs[idx], sizeof(DevUnion));
+ pEnt->entityPrivates = nprivs;
+ }
+ return idx;
+}
+
+DevUnion *
+xf86GetEntityPrivate(int entityIndex, int privIndex)
+{
+ if (entityIndex >= xf86NumEntities || privIndex >= xf86EntityPrivateCount)
+ return NULL;
+
+ return &(xf86Entities[entityIndex]->entityPrivates[privIndex]);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Bus.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Bus.h
new file mode 100644
index 000000000..96da6e6a9
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Bus.h
@@ -0,0 +1,162 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Bus.h,v 1.23 2003/08/24 17:36:50 dawes Exp $ */
+
+/*
+ * 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 definitions of the bus-related data structures/types.
+ * Everything contained here is private to xf86Bus.c. In particular the
+ * video drivers must not include this file.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _XF86_BUS_H
+#define _XF86_BUS_H
+
+#include "xf86pciBus.h"
+#ifdef __sparc__
+#include "xf86sbusBus.h"
+#endif
+
+typedef struct racInfo {
+ xf86AccessPtr mem_new;
+ xf86AccessPtr io_new;
+ xf86AccessPtr io_mem_new;
+ xf86SetAccessFuncPtr old;
+} AccessFuncRec, *AccessFuncPtr;
+
+
+typedef struct {
+ DriverPtr driver;
+ int chipset;
+ int entityProp;
+ EntityProc entityInit;
+ EntityProc entityEnter;
+ EntityProc entityLeave;
+ pointer private;
+ resPtr resources;
+ Bool active;
+ Bool inUse;
+ BusRec bus;
+ EntityAccessPtr access;
+ AccessFuncPtr rac;
+ pointer busAcc;
+ int lastScrnFlag;
+ DevUnion * entityPrivates;
+ int numInstances;
+ GDevPtr * devices;
+ IOADDRESS domainIO;
+} EntityRec, *EntityPtr;
+
+/* asynchronous event handling */
+#ifdef async
+typedef struct _AsyncQRec {
+ void (*func)(pointer);
+ pointer arg;
+ struct _AsyncQRec *next;
+} AsyncQRec, *AsyncQPtr;
+#endif
+
+#define NO_SEPARATE_IO_FROM_MEM 0x0001
+#define NO_SEPARATE_MEM_FROM_IO 0x0002
+#define NEED_VGA_ROUTED 0x0004
+#define NEED_VGA_ROUTED_SETUP 0x0008
+#define NEED_MEM 0x0010
+#define NEED_IO 0x0020
+#define NEED_MEM_SHARED 0x0040
+#define NEED_IO_SHARED 0x0080
+#define ACCEL_IS_SHARABLE 0x0100
+#define IS_SHARED_ACCEL 0x0200
+#define SA_PRIM_INIT_DONE 0x0400
+#define NEED_VGA_MEM 0x1000
+#define NEED_VGA_IO 0x2000
+
+#define NEED_SHARED (NEED_MEM_SHARED | NEED_IO_SHARED)
+
+#define busType bus.type
+#define pciBusId bus.id.pci
+#define isaBusId bus.id.isa
+#define sbusBusId bus.id.sbus
+
+struct x_BusAccRec;
+typedef void (*BusAccProcPtr)(struct x_BusAccRec *ptr);
+
+typedef struct x_BusAccRec {
+ BusAccProcPtr set_f;
+ BusAccProcPtr enable_f;
+ BusAccProcPtr disable_f;
+ BusAccProcPtr save_f;
+ BusAccProcPtr restore_f;
+ struct x_BusAccRec *current; /* pointer to bridge open on this bus */
+ struct x_BusAccRec *primary; /* pointer to the bus connecting to this */
+ struct x_BusAccRec *next; /* this links the different buses together */
+ BusType type;
+ BusType busdep_type;
+ /* Bus-specific fields */
+ union {
+ struct {
+ int bus;
+ int primary_bus;
+ PCITAG acc;
+ pciBridgesSave save;
+ } pci;
+ } busdep;
+} BusAccRec, *BusAccPtr;
+
+/* state change notification callback */
+typedef struct _stateChange {
+ xf86StateChangeNotificationCallbackFunc func;
+ pointer arg;
+ struct _stateChange *next;
+} StateChangeNotificationRec, *StateChangeNotificationPtr;
+
+
+extern EntityPtr *xf86Entities;
+extern int xf86NumEntities;
+extern xf86AccessRec AccessNULL;
+extern BusRec primaryBus;
+extern resPtr Acc;
+extern resPtr osRes;
+extern resPtr ResRange;
+extern BusAccPtr xf86BusAccInfo;
+
+int xf86AllocateEntity(void);
+BusType StringToBusType(const char* busID, const char **retID);
+memType ChkConflict(resRange *rgp, resPtr res, xf86State state);
+Bool xf86IsSubsetOf(resRange range, resPtr list);
+Bool xf86IsListSubsetOf(resPtr list, resPtr BaseList);
+resPtr xf86ExtractTypeFromList(resPtr list, unsigned long type);
+resPtr findIntersect(resRange Range, resPtr list);
+resPtr xf86FindIntersect(resRange Range, resPtr list);
+void RemoveOverlaps(resPtr target, resPtr list, Bool pow2Alignment,
+ Bool useEstimated);
+void xf86ConvertListToHost(int entityIndex, resPtr list);
+
+#endif /* _XF86_BUS_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Config.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Config.c
new file mode 100644
index 000000000..0f03560a7
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Config.c
@@ -0,0 +1,2740 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 1.21 2005/12/20 22:30:50 alanc Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 3.276 2003/10/08 14:58:26 dawes Exp $ */
+
+
+/*
+ * Loosely based on code bearing the following copyright:
+ *
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ */
+
+/*
+ * Copyright 1992-2003 by The XFree86 Project, Inc.
+ * Copyright 1997 by Metro Link, 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).
+ */
+
+/*
+ *
+ * Authors:
+ * Dirk Hohndel <hohndel@XFree86.Org>
+ * David Dawes <dawes@XFree86.Org>
+ * Marc La France <tsi@XFree86.Org>
+ * Egbert Eich <eich@XFree86.Org>
+ * ... and others
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef XF86DRI
+#include <sys/types.h>
+#include <grp.h>
+#endif
+
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+
+#include "xf86.h"
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "xf86Config.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include "globals.h"
+
+#ifdef XINPUT
+#include "xf86Xinput.h"
+extern DeviceAssocRec mouse_assoc;
+#endif
+
+#ifdef XKB
+#define XKB_IN_SERVER
+#include <X11/extensions/XKBsrv.h>
+#endif
+
+#ifdef RENDER
+#include "picture.h"
+#endif
+
+#if (defined(i386) || defined(__i386__)) && \
+ (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
+ defined(__NetBSD__) || defined(linux) || \
+ (defined(SVR4) && !defined(sun)) || defined(__GNU__))
+#define SUPPORT_PC98
+#endif
+
+/*
+ * These paths define the way the config file search is done. The escape
+ * sequences are documented in parser/scan.c.
+ */
+#ifndef ROOT_CONFIGPATH
+#define ROOT_CONFIGPATH "%A," "%R," \
+ "/etc/X11/%R," "%P/etc/X11/%R," \
+ "%E," "%F," \
+ "/etc/X11/%F," "%P/etc/X11/%F," \
+ "%D/%X," \
+ "/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
+#ifndef USER_CONFIGPATH
+#define USER_CONFIGPATH "/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
+#ifndef PROJECTROOT
+#define PROJECTROOT "/usr/X11R6"
+#endif
+
+static char *fontPath = NULL;
+
+/* Forward declarations */
+static Bool configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen,
+ int scrnum, MessageType from);
+static Bool configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor);
+static Bool configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device,
+ Bool active);
+static Bool configInput(IDevPtr inputp, XF86ConfInputPtr conf_input,
+ MessageType from);
+static Bool configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display);
+static Bool addDefaultModes(MonPtr monitorp);
+#ifdef XF86DRI
+static Bool configDRI(XF86ConfDRIPtr drip);
+#endif
+static Bool configExtensions(XF86ConfExtensionsPtr conf_ext);
+
+/*
+ * xf86GetPathElem --
+ * Extract a single element from the font path string starting at
+ * pnt. The font path element will be returned, and pnt will be
+ * updated to point to the start of the next element, or set to
+ * NULL if there are no more.
+ */
+static char *
+xf86GetPathElem(char **pnt)
+{
+ char *p1;
+
+ p1 = *pnt;
+ *pnt = index(*pnt, ',');
+ if (*pnt != NULL) {
+ **pnt = '\0';
+ *pnt += 1;
+ }
+ return(p1);
+}
+
+/*
+ * xf86ValidateFontPath --
+ * Validates the user-specified font path. Each element that
+ * begins with a '/' is checked to make sure the directory exists.
+ * If the directory exists, the existence of a file named 'fonts.dir'
+ * is checked. If either check fails, an error is printed and the
+ * element is removed from the font path.
+ */
+
+#define DIR_FILE "/fonts.dir"
+static char *
+xf86ValidateFontPath(char *path)
+{
+ char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem;
+ struct stat stat_buf;
+ int flag;
+ int dirlen;
+
+ tmp_path = xcalloc(1,strlen(path)+1);
+ out_pnt = tmp_path;
+ path_elem = NULL;
+ next = path;
+ while (next != NULL) {
+ path_elem = xf86GetPathElem(&next);
+ if (*path_elem == '/') {
+#ifndef __UNIXOS2__
+ dir_elem = xnfcalloc(1, strlen(path_elem) + 1);
+ if ((p1 = strchr(path_elem, ':')) != 0)
+#else
+ /* OS/2 must prepend X11ROOT */
+ path_elem = (char*)__XOS2RedirRoot(path_elem);
+ dir_elem = xnfcalloc(1, strlen(path_elem) + 1);
+ if (p1 = strchr(path_elem+2, ':'))
+#endif
+ dirlen = p1 - path_elem;
+ else
+ dirlen = strlen(path_elem);
+ strncpy(dir_elem, path_elem, dirlen);
+ dir_elem[dirlen] = '\0';
+ flag = stat(dir_elem, &stat_buf);
+ if (flag == 0)
+ if (!S_ISDIR(stat_buf.st_mode))
+ flag = -1;
+ if (flag != 0) {
+ xf86Msg(X_WARNING, "The directory \"%s\" does not exist.\n", dir_elem);
+ xf86ErrorF("\tEntry deleted from font path.\n");
+ xfree(dir_elem);
+ continue;
+ }
+ else {
+ p1 = xnfalloc(strlen(dir_elem)+strlen(DIR_FILE)+1);
+ strcpy(p1, dir_elem);
+ strcat(p1, DIR_FILE);
+ flag = stat(p1, &stat_buf);
+ if (flag == 0)
+ if (!S_ISREG(stat_buf.st_mode))
+ flag = -1;
+#ifndef __UNIXOS2__
+ xfree(p1);
+#endif
+ if (flag != 0) {
+ xf86Msg(X_WARNING,
+ "`fonts.dir' not found (or not valid) in \"%s\".\n",
+ dir_elem);
+ xf86ErrorF("\tEntry deleted from font path.\n");
+ xf86ErrorF("\t(Run 'mkfontdir' on \"%s\").\n", dir_elem);
+ xfree(dir_elem);
+ continue;
+ }
+ }
+ xfree(dir_elem);
+ }
+
+ /*
+ * Either an OK directory, or a font server name. So add it to
+ * the path.
+ */
+ if (out_pnt != tmp_path)
+ *out_pnt++ = ',';
+ strcat(out_pnt, path_elem);
+ out_pnt += strlen(path_elem);
+ }
+ return(tmp_path);
+}
+
+
+/*
+ * use the datastructure that the parser provides and pick out the parts
+ * that we need at this point
+ */
+char **
+xf86ModulelistFromConfig(pointer **optlist)
+{
+ int count = 0;
+ char **modulearray;
+ pointer *optarray;
+ XF86LoadPtr modp;
+
+ /*
+ * make sure the config file has been parsed and that we have a
+ * ModulePath set; if no ModulePath was given, use the default
+ * ModulePath
+ */
+ if (xf86configptr == NULL) {
+ xf86Msg(X_ERROR, "Cannot access global config data structure\n");
+ return NULL;
+ }
+
+ if (xf86configptr->conf_modules) {
+ /*
+ * Walk the list of modules in the "Module" section to determine how
+ * many we have.
+ */
+ modp = xf86configptr->conf_modules->mod_load_lst;
+ while (modp) {
+ count++;
+ modp = (XF86LoadPtr) modp->list.next;
+ }
+ }
+ if (count == 0)
+ return NULL;
+
+ /*
+ * allocate the memory and walk the list again to fill in the pointers
+ */
+ modulearray = xnfalloc((count + 1) * sizeof(char*));
+ optarray = xnfalloc((count + 1) * sizeof(pointer));
+ count = 0;
+ if (xf86configptr->conf_modules) {
+ modp = xf86configptr->conf_modules->mod_load_lst;
+ while (modp) {
+ modulearray[count] = modp->load_name;
+ optarray[count] = modp->load_opt;
+ count++;
+ modp = (XF86LoadPtr) modp->list.next;
+ }
+ }
+ modulearray[count] = NULL;
+ optarray[count] = NULL;
+ if (optlist)
+ *optlist = optarray;
+ else
+ xfree(optarray);
+ return modulearray;
+}
+
+
+char **
+xf86DriverlistFromConfig()
+{
+ int count = 0;
+ int j;
+ char **modulearray;
+ screenLayoutPtr slp;
+
+ /*
+ * make sure the config file has been parsed and that we have a
+ * ModulePath set; if no ModulePath was given, use the default
+ * ModulePath
+ */
+ if (xf86configptr == NULL) {
+ xf86Msg(X_ERROR, "Cannot access global config data structure\n");
+ return NULL;
+ }
+
+ /*
+ * Walk the list of driver lines in active "Device" sections to
+ * determine now many implicitly loaded modules there are.
+ *
+ */
+ if (xf86ConfigLayout.screens) {
+ slp = xf86ConfigLayout.screens;
+ while ((slp++)->screen) {
+ count++;
+ }
+ }
+
+ /*
+ * Handle the set of inactive "Device" sections.
+ */
+ j = 0;
+ while (xf86ConfigLayout.inactives[j++].identifier)
+ count++;
+
+ if (count == 0)
+ return NULL;
+
+ /*
+ * allocate the memory and walk the list again to fill in the pointers
+ */
+ modulearray = xnfalloc((count + 1) * sizeof(char*));
+ count = 0;
+ slp = xf86ConfigLayout.screens;
+ while (slp->screen) {
+ modulearray[count] = slp->screen->device->driver;
+ count++;
+ slp++;
+ }
+
+ j = 0;
+
+ while (xf86ConfigLayout.inactives[j].identifier)
+ modulearray[count++] = xf86ConfigLayout.inactives[j++].driver;
+
+ modulearray[count] = NULL;
+
+ /* Remove duplicates */
+ for (count = 0; modulearray[count] != NULL; count++) {
+ int i;
+
+ for (i = 0; i < count; i++)
+ if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
+ modulearray[count] = "";
+ break;
+ }
+ }
+ return modulearray;
+}
+
+
+Bool
+xf86BuiltinInputDriver(const char *name)
+{
+#ifdef USE_DEPRECATED_KEYBOARD_DRIVER
+ if (xf86NameCmp(name, "keyboard") == 0)
+ return TRUE;
+ else
+#endif
+ return FALSE;
+}
+
+char **
+xf86InputDriverlistFromConfig()
+{
+ int count = 0;
+ char **modulearray;
+ IDevPtr idp;
+
+ /*
+ * make sure the config file has been parsed and that we have a
+ * ModulePath set; if no ModulePath was given, use the default
+ * ModulePath
+ */
+ if (xf86configptr == NULL) {
+ xf86Msg(X_ERROR, "Cannot access global config data structure\n");
+ return NULL;
+ }
+
+ /*
+ * Walk the list of driver lines in active "InputDevice" sections to
+ * determine now many implicitly loaded modules there are.
+ */
+ if (xf86ConfigLayout.inputs) {
+ idp = xf86ConfigLayout.inputs;
+ while (idp->identifier) {
+ if (!xf86BuiltinInputDriver(idp->driver))
+ count++;
+ idp++;
+ }
+ }
+
+ if (count == 0)
+ return NULL;
+
+ /*
+ * allocate the memory and walk the list again to fill in the pointers
+ */
+ modulearray = xnfalloc((count + 1) * sizeof(char*));
+ count = 0;
+ idp = xf86ConfigLayout.inputs;
+ while (idp->identifier) {
+ if (!xf86BuiltinInputDriver(idp->driver)) {
+ modulearray[count] = idp->driver;
+ count++;
+ }
+ idp++;
+ }
+ modulearray[count] = NULL;
+
+ /* Remove duplicates */
+ for (count = 0; modulearray[count] != NULL; count++) {
+ int i;
+
+ for (i = 0; i < count; i++)
+ if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
+ modulearray[count] = "";
+ break;
+ }
+ }
+ return modulearray;
+}
+
+static void
+fixup_video_driver_list(char **drivers)
+{
+ static const char *fallback[5] = { "vga", "vesa", "fbdev", "wsfb", NULL };
+ char **end, **drv;
+ char *x;
+ char **ati, **atimisc;
+ int i;
+
+ /* walk to the end of the list */
+ for (end = drivers; *end && **end; end++) ;
+ end--;
+
+ /*
+ * for each of the fallback drivers, if we find it in the list,
+ * swap it with the last available non-fallback driver.
+ */
+ for (i = 0; fallback[i]; i++) {
+ for (drv = drivers; drv != end; drv++) {
+ if (strstr(*drv, fallback[i])) {
+ x = *drv; *drv = *end; *end = x;
+ end--;
+ break;
+ }
+ }
+ }
+ /*
+ * since the ati wrapper driver is gross and awful, sort ati before
+ * atimisc, which makes sure all the ati symbols are visible in xorgcfg.
+ */
+ for (drv = drivers; drv != end; drv++) {
+ if (!strcmp(*drv, "atimisc")) {
+ atimisc = drv;
+ for (drv = atimisc; drv != end; drv++) {
+ if (!strcmp(*drv, "ati")) {
+ ati = drv;
+ x = *ati; *ati = *atimisc; *atimisc = x;
+ return;
+ }
+ }
+ /* if we get here, ati was already ahead of atimisc */
+ return;
+ }
+ }
+}
+
+
+/*
+ * Generate a compiled-in list of driver names. This is used to produce a
+ * consistent probe order. For the loader server, we also look for vendor-
+ * provided modules, pre-pending them to our own list.
+ */
+static char **
+GenerateDriverlist(char * dirname, char * drivernames)
+{
+#ifdef XFree86LOADER
+ char **ret;
+ char *subdirs[] = { dirname, NULL };
+ static const char *patlist[] = {"(.*)_drv\\.so", "(.*)_drv\\.o", NULL};
+ ret = LoaderListDirs(subdirs, patlist);
+
+ /* fix up the probe order for video drivers */
+ if (strstr(dirname, "drivers"))
+ fixup_video_driver_list(ret);
+
+ return ret;
+#else /* non-loadable server */
+ char *cp, **driverlist;
+ int count;
+
+ /* Count the number needed */
+ count = 0;
+ cp = drivernames;
+ while (*cp) {
+ while (*cp && isspace(*cp)) cp++;
+ if (!*cp) break;
+ count++;
+ while (*cp && !isspace(*cp)) cp++;
+ }
+
+ if (!count)
+ return NULL;
+
+ /* Now allocate the array of pointers to 0-terminated driver names */
+ driverlist = (char **)xnfalloc((count + 1) * sizeof(char *));
+ count = 0;
+ cp = drivernames;
+ while (*cp) {
+ while (*cp && isspace(*cp)) cp++;
+ if (!*cp) break;
+ driverlist[count++] = cp;
+ while (*cp && !isspace(*cp)) cp++;
+ if (!*cp) break;
+ *cp++ = 0;
+ }
+ driverlist[count] = NULL;
+
+ return driverlist;
+#endif
+}
+
+
+char **
+xf86DriverlistFromCompile(void)
+{
+ static char **driverlist = NULL;
+ static Bool generated = FALSE;
+
+ /* This string is modified in-place */
+ static char drivernames[] = DRIVERS;
+
+ if (!generated) {
+ generated = TRUE;
+ driverlist = GenerateDriverlist("drivers", drivernames);
+ }
+
+ return driverlist;
+}
+
+
+char **
+xf86InputDriverlistFromCompile(void)
+{
+ static char **driverlist = NULL;
+ static Bool generated = FALSE;
+
+ /* This string is modified in-place */
+ static char drivernames[] = IDRIVERS;
+
+ if (!generated) {
+ generated = TRUE;
+ driverlist = GenerateDriverlist("input", drivernames);
+ }
+
+ return driverlist;
+}
+
+
+/*
+ * xf86ConfigError --
+ * Print a READABLE ErrorMessage!!! All information that is
+ * available is printed.
+ */
+static void
+xf86ConfigError(char *msg, ...)
+{
+ va_list ap;
+
+ ErrorF("\nConfig Error:\n");
+ va_start(ap, msg);
+ VErrorF(msg, ap);
+ va_end(ap);
+ ErrorF("\n");
+ return;
+}
+
+static Bool
+configFiles(XF86ConfFilesPtr fileconf)
+{
+ MessageType pathFrom = X_DEFAULT;
+
+ /* FontPath */
+
+ /* Try XF86Config FontPath first */
+ if (!xf86fpFlag) {
+ if (fileconf) {
+ if (fileconf->file_fontpath) {
+ char *f = xf86ValidateFontPath(fileconf->file_fontpath);
+ pathFrom = X_CONFIG;
+ if (*f)
+ defaultFontPath = f;
+ else {
+ xf86Msg(X_WARNING,
+ "FontPath is completely invalid. Using compiled-in default.\n");
+ fontPath = NULL;
+ pathFrom = X_DEFAULT;
+ }
+ }
+ } else {
+ xf86Msg(X_WARNING,
+ "No FontPath specified. Using compiled-in default.\n");
+ pathFrom = X_DEFAULT;
+ }
+ } else {
+ /* Use fontpath specified with '-fp' */
+ if (fontPath)
+ {
+ fontPath = NULL;
+ }
+ pathFrom = X_CMDLINE;
+ }
+ if (!fileconf) {
+ /* xf86ValidateFontPath will write into it's arg, but defaultFontPath
+ could be static, so we make a copy. */
+ char *f = xnfalloc(strlen(defaultFontPath) + 1);
+ f[0] = '\0';
+ strcpy (f, defaultFontPath);
+ defaultFontPath = xf86ValidateFontPath(f);
+ xfree(f);
+ } else {
+ if (fileconf) {
+ if (!fileconf->file_fontpath) {
+ /* xf86ValidateFontPath will write into it's arg, but defaultFontPath
+ could be static, so we make a copy. */
+ char *f = xnfalloc(strlen(defaultFontPath) + 1);
+ f[0] = '\0';
+ strcpy (f, defaultFontPath);
+ defaultFontPath = xf86ValidateFontPath(f);
+ xfree(f);
+ }
+ }
+ }
+
+ /* If defaultFontPath is still empty, exit here */
+
+ if (! *defaultFontPath)
+ FatalError("No valid FontPath could be found.");
+
+ xf86Msg(pathFrom, "FontPath set to \"%s\"\n", defaultFontPath);
+
+ /* RgbPath */
+
+ pathFrom = X_DEFAULT;
+
+ if (xf86coFlag)
+ pathFrom = X_CMDLINE;
+ else if (fileconf) {
+ if (fileconf->file_rgbpath) {
+ rgbPath = fileconf->file_rgbpath;
+ pathFrom = X_CONFIG;
+ }
+ }
+
+ xf86Msg(pathFrom, "RgbPath set to \"%s\"\n", rgbPath);
+
+ if (fileconf && fileconf->file_inputdevs) {
+ xf86InputDeviceList = fileconf->file_inputdevs;
+ xf86Msg(X_CONFIG, "Input device list set to \"%s\"\n",
+ xf86InputDeviceList);
+ }
+
+
+#ifdef XFree86LOADER
+ /* ModulePath */
+
+ if (fileconf) {
+ if (xf86ModPathFrom != X_CMDLINE && fileconf->file_modulepath) {
+ xf86ModulePath = fileconf->file_modulepath;
+ xf86ModPathFrom = X_CONFIG;
+ }
+ }
+
+ xf86Msg(xf86ModPathFrom, "ModulePath set to \"%s\"\n", xf86ModulePath);
+#endif
+
+#if 0
+ /* LogFile */
+ /*
+ * XXX The problem with this is that the log file is already open.
+ * One option might be to copy the exiting contents to the new location.
+ * and re-open it. The down side is that the default location would
+ * already have been overwritten. Another option would be to start with
+ * unique temporary location, then copy it once the correct name is known.
+ * A problem with this is what happens if the server exits before that
+ * happens.
+ */
+ if (xf86LogFileFrom == X_DEFAULT && fileconf->file_logfile) {
+ xf86LogFile = fileconf->file_logfile;
+ xf86LogFileFrom = X_CONFIG;
+ }
+#endif
+
+ return TRUE;
+}
+
+typedef enum {
+ FLAG_NOTRAPSIGNALS,
+ FLAG_DONTVTSWITCH,
+ FLAG_DONTZAP,
+ FLAG_DONTZOOM,
+ FLAG_DISABLEVIDMODE,
+ FLAG_ALLOWNONLOCAL,
+ FLAG_DISABLEMODINDEV,
+ FLAG_MODINDEVALLOWNONLOCAL,
+ FLAG_ALLOWMOUSEOPENFAIL,
+ FLAG_VTINIT,
+ FLAG_VTSYSREQ,
+ FLAG_XKBDISABLE,
+ FLAG_PCIPROBE1,
+ FLAG_PCIPROBE2,
+ FLAG_PCIFORCECONFIG1,
+ FLAG_PCIFORCECONFIG2,
+ FLAG_PCIFORCENONE,
+ FLAG_PCIOSCONFIG,
+ FLAG_SAVER_BLANKTIME,
+ FLAG_DPMS_STANDBYTIME,
+ FLAG_DPMS_SUSPENDTIME,
+ FLAG_DPMS_OFFTIME,
+ FLAG_PIXMAP,
+ FLAG_PC98,
+ FLAG_ESTIMATE_SIZES_AGGRESSIVELY,
+ FLAG_NOPM,
+ FLAG_XINERAMA,
+ FLAG_ALLOW_DEACTIVATE_GRABS,
+ FLAG_ALLOW_CLOSEDOWN_GRABS,
+ FLAG_LOG,
+ FLAG_RENDER_COLORMAP_MODE,
+ FLAG_HANDLE_SPECIAL_KEYS,
+ FLAG_RANDR
+} FlagValues;
+
+static OptionInfoRec FlagOptions[] = {
+ { FLAG_NOTRAPSIGNALS, "NoTrapSignals", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_DONTVTSWITCH, "DontVTSwitch", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_DONTZAP, "DontZap", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_DONTZOOM, "DontZoom", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_DISABLEVIDMODE, "DisableVidModeExtension", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_ALLOWNONLOCAL, "AllowNonLocalXvidtune", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_DISABLEMODINDEV, "DisableModInDev", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_MODINDEVALLOWNONLOCAL, "AllowNonLocalModInDev", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_ALLOWMOUSEOPENFAIL, "AllowMouseOpenFail", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_VTINIT, "VTInit", OPTV_STRING,
+ {0}, FALSE },
+ { FLAG_VTSYSREQ, "VTSysReq", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_XKBDISABLE, "XkbDisable", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_PCIPROBE1, "PciProbe1" , OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_PCIPROBE2, "PciProbe2", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_PCIFORCECONFIG1, "PciForceConfig1", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_PCIFORCECONFIG2, "PciForceConfig2", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_PCIFORCENONE, "PciForceNone", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_PCIOSCONFIG, "PciOsConfig", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_SAVER_BLANKTIME, "BlankTime" , OPTV_INTEGER,
+ {0}, FALSE },
+ { FLAG_DPMS_STANDBYTIME, "StandbyTime", OPTV_INTEGER,
+ {0}, FALSE },
+ { FLAG_DPMS_SUSPENDTIME, "SuspendTime", OPTV_INTEGER,
+ {0}, FALSE },
+ { FLAG_DPMS_OFFTIME, "OffTime", OPTV_INTEGER,
+ {0}, FALSE },
+ { FLAG_PIXMAP, "Pixmap", OPTV_INTEGER,
+ {0}, FALSE },
+ { FLAG_PC98, "PC98", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_ESTIMATE_SIZES_AGGRESSIVELY,"EstimateSizesAggressively",OPTV_INTEGER,
+ {0}, FALSE },
+ { FLAG_NOPM, "NoPM", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_XINERAMA, "Xinerama", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_ALLOW_DEACTIVATE_GRABS,"AllowDeactivateGrabs", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_ALLOW_CLOSEDOWN_GRABS, "AllowClosedownGrabs", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_LOG, "Log", OPTV_STRING,
+ {0}, FALSE },
+ { FLAG_RENDER_COLORMAP_MODE, "RenderColormapMode", OPTV_STRING,
+ {0}, FALSE },
+ { FLAG_HANDLE_SPECIAL_KEYS, "HandleSpecialKeys", OPTV_STRING,
+ {0}, FALSE },
+ { FLAG_RANDR, "RandR", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { -1, NULL, OPTV_NONE,
+ {0}, FALSE },
+};
+
+#if defined(i386) || defined(__i386__)
+static Bool
+detectPC98(void)
+{
+#ifdef SUPPORT_PC98
+ unsigned char buf[2];
+
+ if (xf86ReadBIOS(0xf8000, 0xe80, buf, 2) != 2)
+ return FALSE;
+ if ((buf[0] == 0x98) && (buf[1] == 0x21))
+ return TRUE;
+ else
+ return FALSE;
+#else
+ return FALSE;
+#endif
+}
+#endif /* __i386__ */
+
+static Bool
+configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
+{
+ XF86OptionPtr optp, tmp;
+ int i;
+ Pix24Flags pix24 = Pix24DontCare;
+ Bool value;
+ MessageType from;
+
+ /*
+ * Merge the ServerLayout and ServerFlags options. The former have
+ * precedence over the latter.
+ */
+ optp = NULL;
+ if (flagsconf && flagsconf->flg_option_lst)
+ optp = xf86optionListDup(flagsconf->flg_option_lst);
+ if (layoutopts) {
+ tmp = xf86optionListDup(layoutopts);
+ if (optp)
+ optp = xf86optionListMerge(optp, tmp);
+ else
+ optp = tmp;
+ }
+
+ xf86ProcessOptions(-1, optp, FlagOptions);
+
+ xf86GetOptValBool(FlagOptions, FLAG_NOTRAPSIGNALS, &xf86Info.notrapSignals);
+ xf86GetOptValBool(FlagOptions, FLAG_DONTVTSWITCH, &xf86Info.dontVTSwitch);
+ xf86GetOptValBool(FlagOptions, FLAG_DONTZAP, &xf86Info.dontZap);
+ xf86GetOptValBool(FlagOptions, FLAG_DONTZOOM, &xf86Info.dontZoom);
+
+ xf86GetOptValBool(FlagOptions, FLAG_ALLOW_DEACTIVATE_GRABS,
+ &(xf86Info.grabInfo.allowDeactivate));
+ xf86GetOptValBool(FlagOptions, FLAG_ALLOW_CLOSEDOWN_GRABS,
+ &(xf86Info.grabInfo.allowClosedown));
+
+ /*
+ * Set things up based on the config file information. Some of these
+ * settings may be overridden later when the command line options are
+ * checked.
+ */
+#ifdef XF86VIDMODE
+ if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEVIDMODE, &value))
+ xf86Info.vidModeEnabled = !value;
+ if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWNONLOCAL, &value))
+ xf86Info.vidModeAllowNonLocal = value;
+#endif
+
+#ifdef XF86MISC
+ if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEMODINDEV, &value))
+ xf86Info.miscModInDevEnabled = !value;
+ if (xf86GetOptValBool(FlagOptions, FLAG_MODINDEVALLOWNONLOCAL, &value))
+ xf86Info.miscModInDevAllowNonLocal = value;
+#endif
+
+ if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWMOUSEOPENFAIL, &value))
+ xf86Info.allowMouseOpenFail = value;
+
+ if (xf86GetOptValBool(FlagOptions, FLAG_VTSYSREQ, &value)) {
+#ifdef USE_VT_SYSREQ
+ xf86Info.vtSysreq = value;
+ xf86Msg(X_CONFIG, "VTSysReq %s\n", value ? "enabled" : "disabled");
+#else
+ if (value)
+ xf86Msg(X_WARNING, "VTSysReq is not supported on this OS\n");
+#endif
+ }
+
+ if (xf86GetOptValBool(FlagOptions, FLAG_XKBDISABLE, &value)) {
+#ifdef XKB
+ noXkbExtension = value;
+ xf86Msg(X_CONFIG, "Xkb %s\n", value ? "disabled" : "enabled");
+#else
+ if (!value)
+ xf86Msg(X_WARNING, "Xserver doesn't support XKB\n");
+#endif
+ }
+
+ xf86Info.vtinit = xf86GetOptValString(FlagOptions, FLAG_VTINIT);
+
+ if (xf86IsOptionSet(FlagOptions, FLAG_PCIPROBE1))
+ xf86Info.pciFlags = PCIProbe1;
+ if (xf86IsOptionSet(FlagOptions, FLAG_PCIPROBE2))
+ xf86Info.pciFlags = PCIProbe2;
+ if (xf86IsOptionSet(FlagOptions, FLAG_PCIFORCECONFIG1))
+ xf86Info.pciFlags = PCIForceConfig1;
+ if (xf86IsOptionSet(FlagOptions, FLAG_PCIFORCECONFIG2))
+ xf86Info.pciFlags = PCIForceConfig2;
+ if (xf86IsOptionSet(FlagOptions, FLAG_PCIOSCONFIG))
+ xf86Info.pciFlags = PCIOsConfig;
+ if (xf86IsOptionSet(FlagOptions, FLAG_PCIFORCENONE))
+ xf86Info.pciFlags = PCIForceNone;
+
+ xf86Info.pmFlag = TRUE;
+ if (xf86GetOptValBool(FlagOptions, FLAG_NOPM, &value))
+ xf86Info.pmFlag = !value;
+ {
+ const char *s;
+ if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) {
+ if (!xf86NameCmp(s,"flush")) {
+ xf86Msg(X_CONFIG, "Flushing logfile enabled\n");
+ xf86Info.log = LogFlush;
+ LogSetParameter(XLOG_FLUSH, TRUE);
+ } else if (!xf86NameCmp(s,"sync")) {
+ xf86Msg(X_CONFIG, "Syncing logfile enabled\n");
+ xf86Info.log = LogSync;
+ LogSetParameter(XLOG_SYNC, TRUE);
+ } else {
+ xf86Msg(X_WARNING,"Unknown Log option\n");
+ }
+ }
+ }
+
+#ifdef RENDER
+ {
+ const char *s;
+
+ if ((s = xf86GetOptValString(FlagOptions, FLAG_RENDER_COLORMAP_MODE))){
+ int policy = PictureParseCmapPolicy (s);
+ if (policy == PictureCmapPolicyInvalid)
+ xf86Msg(X_WARNING, "Unknown colormap policy \"%s\"\n", s);
+ else
+ {
+ xf86Msg(X_CONFIG, "Render colormap policy set to %s\n", s);
+ PictureCmapPolicy = policy;
+ }
+ }
+ }
+#endif
+ {
+ const char *s;
+ if ((s = xf86GetOptValString(FlagOptions, FLAG_HANDLE_SPECIAL_KEYS))) {
+ if (!xf86NameCmp(s,"always")) {
+ xf86Msg(X_CONFIG, "Always handling special keys in DDX\n");
+ xf86Info.ddxSpecialKeys = SKAlways;
+ } else if (!xf86NameCmp(s,"whenneeded")) {
+ xf86Msg(X_CONFIG, "Special keys handled in DDX only if needed\n");
+ xf86Info.ddxSpecialKeys = SKWhenNeeded;
+ } else if (!xf86NameCmp(s,"never")) {
+ xf86Msg(X_CONFIG, "Never handling special keys in DDX\n");
+ xf86Info.ddxSpecialKeys = SKNever;
+ } else {
+ xf86Msg(X_WARNING,"Unknown HandleSpecialKeys option\n");
+ }
+ }
+ }
+#ifdef RANDR
+ xf86Info.disableRandR = FALSE;
+ xf86Info.randRFrom = X_DEFAULT;
+ if (xf86GetOptValBool(FlagOptions, FLAG_RANDR, &value)) {
+ xf86Info.disableRandR = !value;
+ xf86Info.randRFrom = X_CONFIG;
+ }
+#endif
+ i = -1;
+ xf86GetOptValInteger(FlagOptions, FLAG_ESTIMATE_SIZES_AGGRESSIVELY, &i);
+ if (i >= 0)
+ xf86Info.estimateSizesAggressively = i;
+ else
+ xf86Info.estimateSizesAggressively = 0;
+
+/* Make sure that timers don't overflow CARD32's after multiplying */
+#define MAX_TIME_IN_MIN (0x7fffffff / MILLI_PER_MIN)
+
+ i = -1;
+ xf86GetOptValInteger(FlagOptions, FLAG_SAVER_BLANKTIME, &i);
+ if ((i >= 0) && (i < MAX_TIME_IN_MIN))
+ ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN;
+ else if (i != -1)
+ xf86ConfigError("BlankTime value %d outside legal range of 0 - %d minutes",
+ i, MAX_TIME_IN_MIN);
+
+#ifdef DPMSExtension
+ i = -1;
+ xf86GetOptValInteger(FlagOptions, FLAG_DPMS_STANDBYTIME, &i);
+ if ((i >= 0) && (i < MAX_TIME_IN_MIN))
+ DPMSStandbyTime = defaultDPMSStandbyTime = i * MILLI_PER_MIN;
+ else if (i != -1)
+ xf86ConfigError("StandbyTime value %d outside legal range of 0 - %d minutes",
+ i, MAX_TIME_IN_MIN);
+ i = -1;
+ xf86GetOptValInteger(FlagOptions, FLAG_DPMS_SUSPENDTIME, &i);
+ if ((i >= 0) && (i < MAX_TIME_IN_MIN))
+ DPMSSuspendTime = defaultDPMSSuspendTime = i * MILLI_PER_MIN;
+ else if (i != -1)
+ xf86ConfigError("SuspendTime value %d outside legal range of 0 - %d minutes",
+ i, MAX_TIME_IN_MIN);
+ i = -1;
+ xf86GetOptValInteger(FlagOptions, FLAG_DPMS_OFFTIME, &i);
+ if ((i >= 0) && (i < MAX_TIME_IN_MIN))
+ DPMSOffTime = defaultDPMSOffTime = i * MILLI_PER_MIN;
+ else if (i != -1)
+ xf86ConfigError("OffTime value %d outside legal range of 0 - %d minutes",
+ i, MAX_TIME_IN_MIN);
+#endif
+
+ i = -1;
+ xf86GetOptValInteger(FlagOptions, FLAG_PIXMAP, &i);
+ switch (i) {
+ case 24:
+ pix24 = Pix24Use24;
+ break;
+ case 32:
+ pix24 = Pix24Use32;
+ break;
+ case -1:
+ break;
+ default:
+ xf86ConfigError("Pixmap option's value (%d) must be 24 or 32\n", i);
+ return FALSE;
+ }
+ if (xf86Pix24 != Pix24DontCare) {
+ xf86Info.pixmap24 = xf86Pix24;
+ xf86Info.pix24From = X_CMDLINE;
+ } else if (pix24 != Pix24DontCare) {
+ xf86Info.pixmap24 = pix24;
+ xf86Info.pix24From = X_CONFIG;
+ } else {
+ xf86Info.pixmap24 = Pix24DontCare;
+ xf86Info.pix24From = X_DEFAULT;
+ }
+#if defined(i386) || defined(__i386__)
+ if (xf86GetOptValBool(FlagOptions, FLAG_PC98, &value)) {
+ xf86Info.pc98 = value;
+ if (value) {
+ xf86Msg(X_CONFIG, "Japanese PC98 architecture\n");
+ }
+ } else
+ if (detectPC98()) {
+ xf86Info.pc98 = TRUE;
+ xf86Msg(X_PROBED, "Japanese PC98 architecture\n");
+ }
+#endif
+
+#ifdef PANORAMIX
+ from = X_DEFAULT;
+ if (!noPanoramiXExtension)
+ from = X_CMDLINE;
+ else if (xf86GetOptValBool(FlagOptions, FLAG_XINERAMA, &value)) {
+ noPanoramiXExtension = !value;
+ from = X_CONFIG;
+ }
+ if (!noPanoramiXExtension)
+ xf86Msg(from, "Xinerama: enabled\n");
+#endif
+
+ return TRUE;
+}
+
+/*
+ * XXX This function is temporary, and will be removed when the keyboard
+ * driver is converted into a regular input driver.
+ */
+static Bool
+configInputKbd(IDevPtr inputp)
+{
+ char *s;
+ MessageType from = X_DEFAULT;
+ Bool customKeycodesDefault = FALSE;
+ int verb = 0;
+#if defined(XQUEUE)
+ char *kbdproto = "Xqueue";
+#else
+ char *kbdproto = "standard";
+#endif
+
+ /* Initialize defaults */
+ xf86Info.xleds = 0L;
+ xf86Info.kbdDelay = 500;
+ xf86Info.kbdRate = 30;
+
+ xf86Info.kbdProc = NULL;
+ xf86Info.vtinit = NULL;
+ xf86Info.vtSysreq = VT_SYSREQ_DEFAULT;
+#if defined(SVR4) && defined(i386)
+ xf86Info.panix106 = FALSE;
+#endif
+ xf86Info.kbdCustomKeycodes = FALSE;
+#ifdef WSCONS_SUPPORT
+ xf86Info.kbdFd = -1;
+#endif
+#ifdef XKB
+ if (!xf86IsPc98()) {
+ xf86Info.xkbrules = __XKBDEFRULES__;
+ xf86Info.xkbmodel = "pc105";
+ xf86Info.xkblayout = "us";
+ xf86Info.xkbvariant = NULL;
+ xf86Info.xkboptions = NULL;
+ } else {
+ xf86Info.xkbrules = "xfree98";
+ xf86Info.xkbmodel = "pc98";
+ xf86Info.xkblayout = "nec/jp";
+ xf86Info.xkbvariant = NULL;
+ xf86Info.xkboptions = NULL;
+ }
+ xf86Info.xkbcomponents_specified = FALSE;
+ /* Should discourage the use of these. */
+ xf86Info.xkbkeymap = NULL;
+ xf86Info.xkbtypes = NULL;
+ xf86Info.xkbcompat = NULL;
+ xf86Info.xkbkeycodes = NULL;
+ xf86Info.xkbsymbols = NULL;
+ xf86Info.xkbgeometry = NULL;
+#endif
+
+ s = xf86SetStrOption(inputp->commonOptions, "Protocol", kbdproto);
+ if (xf86NameCmp(s, "standard") == 0) {
+ xf86Info.kbdProc = xf86KbdProc;
+ xf86Info.kbdEvents = xf86KbdEvents;
+ xfree(s);
+ } else if (xf86NameCmp(s, "xqueue") == 0) {
+#ifdef __UNIXWARE__
+ /*
+ * To retain compatibility with older config files, on UnixWare, we
+ * accept the xqueue protocol but use the normal keyboard procs.
+ */
+ xf86Info.kbdProc = xf86KbdProc;
+ xf86Info.kbdEvents = xf86KbdEvents;
+#else
+#ifdef XQUEUE
+ xf86Info.kbdProc = xf86XqueKbdProc;
+ xf86Info.kbdEvents = xf86XqueEvents;
+ xf86Msg(X_CONFIG, "Xqueue selected for keyboard input\n");
+#endif
+#endif
+ xfree(s);
+#ifdef WSCONS_SUPPORT
+ } else if (xf86NameCmp(s, "wskbd") == 0) {
+ xf86Info.kbdProc = xf86KbdProc;
+ xf86Info.kbdEvents = xf86WSKbdEvents;
+ xfree(s);
+ s = xf86SetStrOption(inputp->commonOptions, "Device", NULL);
+ xf86Msg(X_CONFIG, "Keyboard: Protocol: wskbd\n");
+ if (s == NULL) {
+ xf86ConfigError("A \"device\" option is required with"
+ " the \"wskbd\" keyboard protocol");
+ return FALSE;
+ }
+ xf86Info.kbdFd = open(s, O_RDWR | O_NONBLOCK | O_EXCL);
+ if (xf86Info.kbdFd == -1) {
+ xf86ConfigError("cannot open \"%s\"", s);
+ xfree(s);
+ return FALSE;
+ }
+ xfree(s);
+ /* Find out keyboard type */
+ if (ioctl(xf86Info.kbdFd, WSKBDIO_GTYPE, &xf86Info.wsKbdType) == -1) {
+ xf86ConfigError("cannot get keyboard type");
+ close(xf86Info.kbdFd);
+ return FALSE;
+ }
+ switch (xf86Info.wsKbdType) {
+ case WSKBD_TYPE_PC_XT:
+ xf86Msg(X_PROBED, "Keyboard type: XT\n");
+ break;
+ case WSKBD_TYPE_PC_AT:
+ xf86Msg(X_PROBED, "Keyboard type: AT\n");
+ break;
+ case WSKBD_TYPE_USB:
+ xf86Msg(X_PROBED, "Keyboard type: USB\n");
+ break;
+#ifdef WSKBD_TYPE_ADB
+ case WSKBD_TYPE_ADB:
+ xf86Msg(X_PROBED, "Keyboard type: ADB\n");
+ break;
+#endif
+#ifdef WSKBD_TYPE_SUN
+ case WSKBD_TYPE_SUN:
+ xf86Msg(X_PROBED, "Keyboard type: Sun\n");
+ break;
+#endif
+#ifdef WSKBD_TYPE_SUN5
+ case WSKBD_TYPE_SUN5:
+ xf86Msg(X_PROBED, "Keyboard type: Sun5\n");
+ break;
+#endif
+ default:
+ xf86ConfigError("Unsupported wskbd type \"%d\"",
+ xf86Info.wsKbdType);
+ close(xf86Info.kbdFd);
+ return FALSE;
+ }
+#endif
+ } else {
+ xf86ConfigError("\"%s\" is not a valid keyboard protocol name", s);
+ xfree(s);
+ return FALSE;
+ }
+
+ s = xf86SetStrOption(inputp->commonOptions, "AutoRepeat", NULL);
+ if (s) {
+ if (sscanf(s, "%d %d", &xf86Info.kbdDelay, &xf86Info.kbdRate) != 2) {
+ xf86ConfigError("\"%s\" is not a valid AutoRepeat value", s);
+ xfree(s);
+ return FALSE;
+ }
+ xfree(s);
+ }
+
+ s = xf86SetStrOption(inputp->commonOptions, "XLeds", NULL);
+ if (s) {
+ char *l, *end;
+ unsigned int i;
+ l = strtok(s, " \t\n");
+ while (l) {
+ i = strtoul(l, &end, 0);
+ if (*end == '\0')
+ xf86Info.xleds |= 1L << (i - 1);
+ else {
+ xf86ConfigError("\"%s\" is not a valid XLeds value", l);
+ xfree(s);
+ return FALSE;
+ }
+ l = strtok(NULL, " \t\n");
+ }
+ xfree(s);
+ }
+
+#ifdef XKB
+ from = X_DEFAULT;
+ if (noXkbExtension)
+ from = X_CMDLINE;
+ else if (xf86FindOption(inputp->commonOptions, "XkbDisable")) {
+ xf86Msg(X_WARNING, "KEYBOARD: XKB should be disabled in the "
+ "ServerFlags section instead\n"
+ "\tof in the \"keyboard\" InputDevice section.\n");
+ noXkbExtension =
+ xf86SetBoolOption(inputp->commonOptions, "XkbDisable", FALSE);
+ from = X_CONFIG;
+ }
+ if (noXkbExtension)
+ xf86Msg(from, "XKB: disabled\n");
+
+#define NULL_IF_EMPTY(s) (s[0] ? s : (xfree(s), (char *)NULL))
+
+ if (!noXkbExtension && !XkbInitialMap) {
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbKeymap", NULL))) {
+ xf86Info.xkbkeymap = NULL_IF_EMPTY(s);
+ xf86Msg(X_CONFIG, "XKB: keymap: \"%s\" "
+ "(overrides other XKB settings)\n", xf86Info.xkbkeymap);
+ } else {
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbCompat", NULL))) {
+ xf86Info.xkbcompat = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: compat: \"%s\"\n", s);
+ }
+
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbTypes", NULL))) {
+ xf86Info.xkbtypes = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: types: \"%s\"\n", s);
+ }
+
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbKeycodes", NULL))) {
+ xf86Info.xkbkeycodes = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: keycodes: \"%s\"\n", s);
+ }
+
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbGeometry", NULL))) {
+ xf86Info.xkbgeometry = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: geometry: \"%s\"\n", s);
+ }
+
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbSymbols", NULL))) {
+ xf86Info.xkbsymbols = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: symbols: \"%s\"\n", s);
+ }
+
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbRules", NULL))) {
+ xf86Info.xkbrules = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: rules: \"%s\"\n", s);
+ }
+
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbModel", NULL))) {
+ xf86Info.xkbmodel = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: model: \"%s\"\n", s);
+ }
+
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbLayout", NULL))) {
+ xf86Info.xkblayout = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: layout: \"%s\"\n", s);
+ }
+
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbVariant", NULL))) {
+ xf86Info.xkbvariant = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: variant: \"%s\"\n", s);
+ }
+
+ if ((s = xf86SetStrOption(inputp->commonOptions, "XkbOptions", NULL))) {
+ xf86Info.xkboptions = NULL_IF_EMPTY(s);
+ xf86Info.xkbcomponents_specified = TRUE;
+ xf86Msg(X_CONFIG, "XKB: options: \"%s\"\n", s);
+ }
+ }
+ }
+#undef NULL_IF_EMPTY
+#endif
+#if defined(SVR4) && defined(i386)
+ if ((xf86Info.panix106 =
+ xf86SetBoolOption(inputp->commonOptions, "Panix106", FALSE))) {
+ xf86Msg(X_CONFIG, "PANIX106: enabled\n");
+ }
+#endif
+
+ /*
+ * This was once a compile time option (ASSUME_CUSTOM_KEYCODES)
+ * defaulting to 1 on Linux/PPC. It is no longer necessary, but for
+ * backwards compatibility we provide 'Option "CustomKeycodes"'
+ * and try to autoprobe on Linux/PPC.
+ */
+ from = X_DEFAULT;
+ verb = 2;
+#if defined(__linux__) && defined(__powerpc__)
+ {
+ FILE *f;
+
+ f = fopen("/proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes","r");
+ if (f) {
+ if (fgetc(f) == '0') {
+ customKeycodesDefault = TRUE;
+ from = X_PROBED;
+ verb = 1;
+ }
+ fclose(f);
+ }
+ }
+#endif
+ if (xf86FindOption(inputp->commonOptions, "CustomKeycodes")) {
+ from = X_CONFIG;
+ verb = 1;
+ }
+ xf86Info.kbdCustomKeycodes =
+ xf86SetBoolOption(inputp->commonOptions, "CustomKeycodes",
+ customKeycodesDefault);
+ xf86MsgVerb(from, verb, "Keyboard: CustomKeycode %s\n",
+ xf86Info.kbdCustomKeycodes ? "enabled" : "disabled");
+
+ return TRUE;
+}
+
+/*
+ * Locate the core input devices. These can be specified/located in
+ * the following ways, in order of priority:
+ *
+ * 1. The InputDevices named by the -pointer and -keyboard command line
+ * options.
+ * 2. The "CorePointer" and "CoreKeyboard" InputDevices referred to by
+ * the active ServerLayout.
+ * 3. The first InputDevices marked as "CorePointer" and "CoreKeyboard".
+ * 4. The first InputDevices that use the 'mouse' and 'keyboard' or 'kbd'
+ * drivers.
+ * 5. Default devices with an empty (default) configuration. These defaults
+ * will reference the 'mouse' and 'keyboard' drivers.
+ */
+
+static Bool
+checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
+{
+ IDevPtr corePointer = NULL, coreKeyboard = NULL;
+ Bool foundPointer = FALSE, foundKeyboard = FALSE;
+ const char *pointerMsg = NULL, *keyboardMsg = NULL;
+ IDevPtr indp;
+ IDevRec Pointer, Keyboard;
+ XF86ConfInputPtr confInput;
+ XF86ConfInputRec defPtr, defKbd;
+ int count = 0;
+ MessageType from = X_DEFAULT;
+
+ /*
+ * First check if a core pointer or core keyboard have been specified
+ * in the active ServerLayout. If more than one is specified for either,
+ * remove the core attribute from the later ones.
+ */
+ for (indp = servlayoutp->inputs; indp->identifier; indp++) {
+ pointer opt1 = NULL, opt2 = NULL;
+ if (indp->commonOptions &&
+ xf86CheckBoolOption(indp->commonOptions, "CorePointer", FALSE)) {
+ opt1 = indp->commonOptions;
+ }
+ if (indp->extraOptions &&
+ xf86CheckBoolOption(indp->extraOptions, "CorePointer", FALSE)) {
+ opt2 = indp->extraOptions;
+ }
+ if (opt1 || opt2) {
+ if (!corePointer) {
+ corePointer = indp;
+ } else {
+ if (opt1)
+ xf86ReplaceBoolOption(opt1, "CorePointer", FALSE);
+ if (opt2)
+ xf86ReplaceBoolOption(opt2, "CorePointer", FALSE);
+ xf86Msg(X_WARNING, "Duplicate core pointer devices. "
+ "Removing core pointer attribute from \"%s\"\n",
+ indp->identifier);
+ }
+ }
+ opt1 = opt2 = NULL;
+ if (indp->commonOptions &&
+ xf86CheckBoolOption(indp->commonOptions, "CoreKeyboard", FALSE)) {
+ opt1 = indp->commonOptions;
+ }
+ if (indp->extraOptions &&
+ xf86CheckBoolOption(indp->extraOptions, "CoreKeyboard", FALSE)) {
+ opt2 = indp->extraOptions;
+ }
+ if (opt1 || opt2) {
+ if (!coreKeyboard) {
+ coreKeyboard = indp;
+ } else {
+ if (opt1)
+ xf86ReplaceBoolOption(opt1, "CoreKeyboard", FALSE);
+ if (opt2)
+ xf86ReplaceBoolOption(opt2, "CoreKeyboard", FALSE);
+ xf86Msg(X_WARNING, "Duplicate core keyboard devices. "
+ "Removing core keyboard attribute from \"%s\"\n",
+ indp->identifier);
+ }
+ }
+ count++;
+ }
+
+ confInput = NULL;
+
+ /* 1. Check for the -pointer command line option. */
+ if (xf86PointerName) {
+ confInput = xf86findInput(xf86PointerName,
+ xf86configptr->conf_input_lst);
+ if (!confInput) {
+ xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n",
+ xf86PointerName);
+ return FALSE;
+ }
+ from = X_CMDLINE;
+ /*
+ * If one was already specified in the ServerLayout, it needs to be
+ * removed.
+ */
+ if (corePointer) {
+ for (indp = servlayoutp->inputs; indp->identifier; indp++)
+ if (indp == corePointer)
+ break;
+ for (; indp->identifier; indp++)
+ indp[0] = indp[1];
+ count--;
+ }
+ corePointer = NULL;
+ foundPointer = TRUE;
+ }
+
+ /* 2. ServerLayout-specified core pointer. */
+ if (corePointer) {
+ foundPointer = TRUE;
+ from = X_CONFIG;
+ }
+
+ /* 3. First core pointer device. */
+ if (!foundPointer) {
+ XF86ConfInputPtr p;
+
+ for (p = xf86configptr->conf_input_lst; p; p = p->list.next) {
+ if (p->inp_option_lst &&
+ xf86CheckBoolOption(p->inp_option_lst, "CorePointer", FALSE)) {
+ confInput = p;
+ foundPointer = TRUE;
+ from = X_DEFAULT;
+ pointerMsg = "first core pointer device";
+ break;
+ }
+ }
+ }
+
+ /* 4. First pointer with 'mouse' as the driver. */
+ if (!foundPointer) {
+ confInput = xf86findInput(CONF_IMPLICIT_POINTER,
+ xf86configptr->conf_input_lst);
+ if (!confInput) {
+ confInput = xf86findInputByDriver("mouse",
+ xf86configptr->conf_input_lst);
+ }
+ if (confInput) {
+ foundPointer = TRUE;
+ from = X_DEFAULT;
+ pointerMsg = "first mouse device";
+ }
+ }
+
+ /* 5. Built-in default. */
+ if (!foundPointer) {
+ bzero(&defPtr, sizeof(defPtr));
+ defPtr.inp_identifier = "<default pointer>";
+ defPtr.inp_driver = "mouse";
+ confInput = &defPtr;
+ foundPointer = TRUE;
+ from = X_DEFAULT;
+ pointerMsg = "default mouse configuration";
+ }
+
+ /* Add the core pointer device to the layout, and set it to Core. */
+ if (foundPointer && confInput) {
+ foundPointer = configInput(&Pointer, confInput, from);
+ if (foundPointer) {
+ count++;
+ indp = xnfrealloc(servlayoutp->inputs,
+ (count + 1) * sizeof(IDevRec));
+ indp[count - 1] = Pointer;
+ indp[count - 1].extraOptions =
+ xf86addNewOption(NULL, "CorePointer", NULL);
+ indp[count].identifier = NULL;
+ servlayoutp->inputs = indp;
+ }
+ }
+
+ if (!foundPointer) {
+ /* This shouldn't happen. */
+ xf86Msg(X_ERROR, "Cannot locate a core pointer device.\n");
+ return FALSE;
+ }
+
+ confInput = NULL;
+
+ /* 1. Check for the -keyboard command line option. */
+ if (xf86KeyboardName) {
+ confInput = xf86findInput(xf86KeyboardName,
+ xf86configptr->conf_input_lst);
+ if (!confInput) {
+ xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n",
+ xf86KeyboardName);
+ return FALSE;
+ }
+ from = X_CMDLINE;
+ /*
+ * If one was already specified in the ServerLayout, it needs to be
+ * removed.
+ */
+ if (coreKeyboard) {
+ for (indp = servlayoutp->inputs; indp->identifier; indp++)
+ if (indp == coreKeyboard)
+ break;
+ for (; indp->identifier; indp++)
+ indp[0] = indp[1];
+ count--;
+ }
+ coreKeyboard = NULL;
+ foundKeyboard = TRUE;
+ }
+
+ /* 2. ServerLayout-specified core keyboard. */
+ if (coreKeyboard) {
+ foundKeyboard = TRUE;
+ from = X_CONFIG;
+ }
+
+ /* 3. First core keyboard device. */
+ if (!foundKeyboard) {
+ XF86ConfInputPtr p;
+
+ for (p = xf86configptr->conf_input_lst; p; p = p->list.next) {
+ if (p->inp_option_lst &&
+ xf86CheckBoolOption(p->inp_option_lst, "CoreKeyboard", FALSE)) {
+ confInput = p;
+ foundKeyboard = TRUE;
+ from = X_DEFAULT;
+ keyboardMsg = "first core keyboard device";
+ break;
+ }
+ }
+ }
+
+ /* 4. First keyboard with 'keyboard' or 'kbd' as the driver. */
+ if (!foundKeyboard) {
+ confInput = xf86findInput(CONF_IMPLICIT_KEYBOARD,
+ xf86configptr->conf_input_lst);
+ if (!confInput) {
+ confInput = xf86findInputByDriver("kbd",
+ xf86configptr->conf_input_lst);
+ }
+ if (!confInput) {
+ confInput = xf86findInputByDriver("keyboard",
+ xf86configptr->conf_input_lst);
+ }
+ if (confInput) {
+ foundKeyboard = TRUE;
+ from = X_DEFAULT;
+ keyboardMsg = "first keyboard device";
+ }
+ }
+
+ /* 5. Built-in default. */
+ if (!foundKeyboard) {
+ bzero(&defKbd, sizeof(defKbd));
+ defKbd.inp_identifier = "<default keyboard>";
+ defKbd.inp_driver = "kbd";
+ confInput = &defKbd;
+ foundKeyboard = TRUE;
+ keyboardMsg = "default keyboard configuration";
+ from = X_DEFAULT;
+ }
+
+ /* Add the core keyboard device to the layout, and set it to Core. */
+ if (foundKeyboard && confInput) {
+ foundKeyboard = configInput(&Keyboard, confInput, from);
+ if (foundKeyboard) {
+ count++;
+ indp = xnfrealloc(servlayoutp->inputs,
+ (count + 1) * sizeof(IDevRec));
+ indp[count - 1] = Keyboard;
+ indp[count - 1].extraOptions =
+ xf86addNewOption(NULL, "CoreKeyboard", NULL);
+ indp[count].identifier = NULL;
+ servlayoutp->inputs = indp;
+ }
+ }
+
+ if (!foundKeyboard) {
+ /* This shouldn't happen. */
+ xf86Msg(X_ERROR, "Cannot locate a core keyboard device.\n");
+ return FALSE;
+ }
+
+ if (pointerMsg) {
+ xf86Msg(X_WARNING, "The core pointer device wasn't specified "
+ "explicitly in the layout.\n"
+ "\tUsing the %s.\n", pointerMsg);
+ }
+
+ if (keyboardMsg) {
+ xf86Msg(X_WARNING, "The core keyboard device wasn't specified "
+ "explicitly in the layout.\n"
+ "\tUsing the %s.\n", keyboardMsg);
+ }
+
+ return TRUE;
+}
+
+typedef enum {
+ LAYOUT_ISOLATEDEVICE,
+ LAYOUT_SINGLECARD
+} LayoutValues;
+
+static OptionInfoRec LayoutOptions[] = {
+ { LAYOUT_ISOLATEDEVICE, "IsolateDevice", OPTV_STRING,
+ {0}, FALSE },
+ { LAYOUT_SINGLECARD, "SingleCard", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { -1, NULL, OPTV_NONE,
+ {0}, FALSE },
+};
+
+/*
+ * figure out which layout is active, which screens are used in that layout,
+ * which drivers and monitors are used in these screens
+ */
+static Bool
+configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
+ char *default_layout)
+{
+ XF86ConfAdjacencyPtr adjp;
+ XF86ConfInactivePtr idp;
+ XF86ConfInputrefPtr irp;
+ int count = 0;
+ int scrnum;
+ XF86ConfLayoutPtr l;
+ MessageType from;
+ screenLayoutPtr slp;
+ GDevPtr gdp;
+ IDevPtr indp;
+ int i = 0, j;
+
+ if (!servlayoutp)
+ return FALSE;
+
+ /*
+ * which layout section is the active one?
+ *
+ * If there is a -layout command line option, use that one, otherwise
+ * pick the first one.
+ */
+ from = X_DEFAULT;
+ if (xf86LayoutName != NULL)
+ from = X_CMDLINE;
+ else if (default_layout) {
+ xf86LayoutName = default_layout;
+ from = X_CONFIG;
+ }
+ if (xf86LayoutName != NULL) {
+ if ((l = xf86findLayout(xf86LayoutName, conf_layout)) == NULL) {
+ xf86Msg(X_ERROR, "No ServerLayout section called \"%s\"\n",
+ xf86LayoutName);
+ return FALSE;
+ }
+ conf_layout = l;
+ }
+ xf86Msg(from, "ServerLayout \"%s\"\n", conf_layout->lay_identifier);
+ adjp = conf_layout->lay_adjacency_lst;
+
+ /*
+ * we know that each screen is referenced exactly once on the left side
+ * of a layout statement in the Layout section. So to allocate the right
+ * size for the array we do a quick walk of the list to figure out how
+ * many sections we have
+ */
+ while (adjp) {
+ count++;
+ adjp = (XF86ConfAdjacencyPtr)adjp->list.next;
+ }
+#ifdef DEBUG
+ ErrorF("Found %d screens in the layout section %s",
+ count, conf_layout->lay_identifier);
+#endif
+ slp = xnfcalloc(1, (count + 1) * sizeof(screenLayoutRec));
+ slp[count].screen = NULL;
+ /*
+ * now that we have storage, loop over the list again and fill in our
+ * data structure; at this point we do not fill in the adjacency
+ * information as it is not clear if we need it at all
+ */
+ adjp = conf_layout->lay_adjacency_lst;
+ count = 0;
+ while (adjp) {
+ slp[count].screen = xnfcalloc(1, sizeof(confScreenRec));
+ if (adjp->adj_scrnum < 0)
+ scrnum = count;
+ else
+ scrnum = adjp->adj_scrnum;
+ if (!configScreen(slp[count].screen, adjp->adj_screen, scrnum,
+ X_CONFIG))
+ return FALSE;
+ slp[count].x = adjp->adj_x;
+ slp[count].y = adjp->adj_y;
+ slp[count].refname = adjp->adj_refscreen;
+ switch (adjp->adj_where) {
+ case CONF_ADJ_OBSOLETE:
+ slp[count].where = PosObsolete;
+ slp[count].topname = adjp->adj_top_str;
+ slp[count].bottomname = adjp->adj_bottom_str;
+ slp[count].leftname = adjp->adj_left_str;
+ slp[count].rightname = adjp->adj_right_str;
+ break;
+ case CONF_ADJ_ABSOLUTE:
+ slp[count].where = PosAbsolute;
+ break;
+ case CONF_ADJ_RIGHTOF:
+ slp[count].where = PosRightOf;
+ break;
+ case CONF_ADJ_LEFTOF:
+ slp[count].where = PosLeftOf;
+ break;
+ case CONF_ADJ_ABOVE:
+ slp[count].where = PosAbove;
+ break;
+ case CONF_ADJ_BELOW:
+ slp[count].where = PosBelow;
+ break;
+ case CONF_ADJ_RELATIVE:
+ slp[count].where = PosRelative;
+ break;
+ }
+ count++;
+ adjp = (XF86ConfAdjacencyPtr)adjp->list.next;
+ }
+
+ /* XXX Need to tie down the upper left screen. */
+
+ /* Fill in the refscreen and top/bottom/left/right values */
+ for (i = 0; i < count; i++) {
+ for (j = 0; j < count; j++) {
+ if (slp[i].refname &&
+ strcmp(slp[i].refname, slp[j].screen->id) == 0) {
+ slp[i].refscreen = slp[j].screen;
+ }
+ if (slp[i].topname &&
+ strcmp(slp[i].topname, slp[j].screen->id) == 0) {
+ slp[i].top = slp[j].screen;
+ }
+ if (slp[i].bottomname &&
+ strcmp(slp[i].bottomname, slp[j].screen->id) == 0) {
+ slp[i].bottom = slp[j].screen;
+ }
+ if (slp[i].leftname &&
+ strcmp(slp[i].leftname, slp[j].screen->id) == 0) {
+ slp[i].left = slp[j].screen;
+ }
+ if (slp[i].rightname &&
+ strcmp(slp[i].rightname, slp[j].screen->id) == 0) {
+ slp[i].right = slp[j].screen;
+ }
+ }
+ if (slp[i].where != PosObsolete
+ && slp[i].where != PosAbsolute
+ && !slp[i].refscreen) {
+ xf86Msg(X_ERROR,"Screen %s doesn't exist: deleting placement\n",
+ slp[i].refname);
+ slp[i].where = PosAbsolute;
+ slp[i].x = 0;
+ slp[i].y = 0;
+ }
+ }
+
+#ifdef LAYOUT_DEBUG
+ ErrorF("Layout \"%s\"\n", conf_layout->lay_identifier);
+ for (i = 0; i < count; i++) {
+ ErrorF("Screen: \"%s\" (%d):\n", slp[i].screen->id,
+ slp[i].screen->screennum);
+ switch (slp[i].where) {
+ case PosObsolete:
+ ErrorF("\tObsolete format: \"%s\" \"%s\" \"%s\" \"%s\"\n",
+ slp[i].top, slp[i].bottom, slp[i].left, slp[i].right);
+ break;
+ case PosAbsolute:
+ if (slp[i].x == -1)
+ if (slp[i].screen->screennum == 0)
+ ErrorF("\tImplicitly left-most\n");
+ else
+ ErrorF("\tImplicitly right of screen %d\n",
+ slp[i].screen->screennum - 1);
+ else
+ ErrorF("\t%d %d\n", slp[i].x, slp[i].y);
+ break;
+ case PosRightOf:
+ ErrorF("\tRight of \"%s\"\n", slp[i].refscreen->id);
+ break;
+ case PosLeftOf:
+ ErrorF("\tLeft of \"%s\"\n", slp[i].refscreen->id);
+ break;
+ case PosAbove:
+ ErrorF("\tAbove \"%s\"\n", slp[i].refscreen->id);
+ break;
+ case PosBelow:
+ ErrorF("\tBelow \"%s\"\n", slp[i].refscreen->id);
+ break;
+ case PosRelative:
+ ErrorF("\t%d %d relative to \"%s\"\n", slp[i].x, slp[i].y,
+ slp[i].refscreen->id);
+ break;
+ }
+ }
+#endif
+ /*
+ * Count the number of inactive devices.
+ */
+ count = 0;
+ idp = conf_layout->lay_inactive_lst;
+ while (idp) {
+ count++;
+ idp = (XF86ConfInactivePtr)idp->list.next;
+ }
+#ifdef DEBUG
+ ErrorF("Found %d inactive devices in the layout section %s",
+ count, conf_layout->lay_identifier);
+#endif
+ gdp = xnfalloc((count + 1) * sizeof(GDevRec));
+ gdp[count].identifier = NULL;
+ idp = conf_layout->lay_inactive_lst;
+ count = 0;
+ while (idp) {
+ if (!configDevice(&gdp[count], idp->inactive_device, FALSE))
+ return FALSE;
+ count++;
+ idp = (XF86ConfInactivePtr)idp->list.next;
+ }
+ /*
+ * Count the number of input devices.
+ */
+ count = 0;
+ irp = conf_layout->lay_input_lst;
+ while (irp) {
+ count++;
+ irp = (XF86ConfInputrefPtr)irp->list.next;
+ }
+#ifdef DEBUG
+ ErrorF("Found %d input devices in the layout section %s",
+ count, conf_layout->lay_identifier);
+#endif
+ indp = xnfalloc((count + 1) * sizeof(IDevRec));
+ indp[count].identifier = NULL;
+ irp = conf_layout->lay_input_lst;
+ count = 0;
+ while (irp) {
+ if (!configInput(&indp[count], irp->iref_inputdev, X_CONFIG))
+ return FALSE;
+ indp[count].extraOptions = irp->iref_option_lst;
+ count++;
+ irp = (XF86ConfInputrefPtr)irp->list.next;
+ }
+ servlayoutp->id = conf_layout->lay_identifier;
+ servlayoutp->screens = slp;
+ servlayoutp->inactives = gdp;
+ servlayoutp->inputs = indp;
+ servlayoutp->options = conf_layout->lay_option_lst;
+ from = X_DEFAULT;
+
+ if (!checkCoreInputDevices(servlayoutp, FALSE))
+ return FALSE;
+ return TRUE;
+}
+
+/*
+ * No layout section, so find the first Screen section and set that up as
+ * the only active screen.
+ */
+static Bool
+configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen)
+{
+ MessageType from;
+ XF86ConfScreenPtr s;
+ screenLayoutPtr slp;
+ IDevPtr indp;
+
+ if (!servlayoutp)
+ return FALSE;
+
+ if (conf_screen == NULL) {
+ xf86ConfigError("No Screen sections present\n");
+ return FALSE;
+ }
+
+ /*
+ * which screen section is the active one?
+ *
+ * If there is a -screen option, use that one, otherwise use the first
+ * one.
+ */
+
+ from = X_CONFIG;
+ if (xf86ScreenName != NULL) {
+ if ((s = xf86findScreen(xf86ScreenName, conf_screen)) == NULL) {
+ xf86Msg(X_ERROR, "No Screen section called \"%s\"\n",
+ xf86ScreenName);
+ return FALSE;
+ }
+ conf_screen = s;
+ from = X_CMDLINE;
+ }
+
+ /* We have exactly one screen */
+
+ slp = xnfcalloc(1, 2 * sizeof(screenLayoutRec));
+ slp[0].screen = xnfcalloc(1, sizeof(confScreenRec));
+ slp[1].screen = NULL;
+ if (!configScreen(slp[0].screen, conf_screen, 0, from))
+ return FALSE;
+ servlayoutp->id = "(implicit)";
+ servlayoutp->screens = slp;
+ servlayoutp->inactives = xnfcalloc(1, sizeof(GDevRec));
+ servlayoutp->options = NULL;
+ /* Set up an empty input device list, then look for some core devices. */
+ indp = xnfalloc(sizeof(IDevRec));
+ indp->identifier = NULL;
+ servlayoutp->inputs = indp;
+ if (!checkCoreInputDevices(servlayoutp, TRUE))
+ return FALSE;
+
+ return TRUE;
+}
+
+static Bool
+configXvAdaptor(confXvAdaptorPtr adaptor, XF86ConfVideoAdaptorPtr conf_adaptor)
+{
+ int count = 0;
+ XF86ConfVideoPortPtr conf_port;
+
+ xf86Msg(X_CONFIG, "| |-->VideoAdaptor \"%s\"\n",
+ conf_adaptor->va_identifier);
+ adaptor->identifier = conf_adaptor->va_identifier;
+ adaptor->options = conf_adaptor->va_option_lst;
+ if (conf_adaptor->va_busid || conf_adaptor->va_driver) {
+ xf86Msg(X_CONFIG, "| | Unsupported device type, skipping entry\n");
+ return FALSE;
+ }
+
+ /*
+ * figure out how many videoport subsections there are and fill them in
+ */
+ conf_port = conf_adaptor->va_port_lst;
+ while(conf_port) {
+ count++;
+ conf_port = (XF86ConfVideoPortPtr)conf_port->list.next;
+ }
+ adaptor->ports = xnfalloc((count) * sizeof(confXvPortRec));
+ adaptor->numports = count;
+ count = 0;
+ conf_port = conf_adaptor->va_port_lst;
+ while(conf_port) {
+ adaptor->ports[count].identifier = conf_port->vp_identifier;
+ adaptor->ports[count].options = conf_port->vp_option_lst;
+ count++;
+ conf_port = (XF86ConfVideoPortPtr)conf_port->list.next;
+ }
+
+ return TRUE;
+}
+
+static Bool
+configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
+ MessageType from)
+{
+ int count = 0;
+ XF86ConfDisplayPtr dispptr;
+ XF86ConfAdaptorLinkPtr conf_adaptor;
+ Bool defaultMonitor = FALSE;
+
+ xf86Msg(from, "|-->Screen \"%s\" (%d)\n", conf_screen->scrn_identifier,
+ scrnum);
+ /*
+ * now we fill in the elements of the screen
+ */
+ screenp->id = conf_screen->scrn_identifier;
+ screenp->screennum = scrnum;
+ screenp->defaultdepth = conf_screen->scrn_defaultdepth;
+ screenp->defaultbpp = conf_screen->scrn_defaultbpp;
+ screenp->defaultfbbpp = conf_screen->scrn_defaultfbbpp;
+ screenp->monitor = xnfcalloc(1, sizeof(MonRec));
+ /* If no monitor is specified, create a default one. */
+ if (!conf_screen->scrn_monitor) {
+ XF86ConfMonitorRec defMon;
+
+ bzero(&defMon, sizeof(defMon));
+ defMon.mon_identifier = "<default monitor>";
+ /*
+ * TARGET_REFRESH_RATE may be defined to effectively limit the
+ * default resolution to the largest that has a "good" refresh
+ * rate.
+ */
+#ifdef TARGET_REFRESH_RATE
+ defMon.mon_option_lst = xf86ReplaceRealOption(defMon.mon_option_lst,
+ "TargetRefresh",
+ TARGET_REFRESH_RATE);
+#endif
+ if (!configMonitor(screenp->monitor, &defMon))
+ return FALSE;
+ defaultMonitor = TRUE;
+ } else {
+ if (!configMonitor(screenp->monitor,conf_screen->scrn_monitor))
+ return FALSE;
+ }
+ screenp->device = xnfcalloc(1, sizeof(GDevRec));
+ configDevice(screenp->device,conf_screen->scrn_device, TRUE);
+ screenp->device->myScreenSection = screenp;
+ screenp->options = conf_screen->scrn_option_lst;
+
+ /*
+ * figure out how many display subsections there are and fill them in
+ */
+ dispptr = conf_screen->scrn_display_lst;
+ while(dispptr) {
+ count++;
+ dispptr = (XF86ConfDisplayPtr)dispptr->list.next;
+ }
+ screenp->displays = xnfalloc((count) * sizeof(DispRec));
+ screenp->numdisplays = count;
+ count = 0;
+ dispptr = conf_screen->scrn_display_lst;
+ while(dispptr) {
+ configDisplay(&(screenp->displays[count]),dispptr);
+ count++;
+ dispptr = (XF86ConfDisplayPtr)dispptr->list.next;
+ }
+
+ /*
+ * figure out how many videoadaptor references there are and fill them in
+ */
+ conf_adaptor = conf_screen->scrn_adaptor_lst;
+ while(conf_adaptor) {
+ count++;
+ conf_adaptor = (XF86ConfAdaptorLinkPtr)conf_adaptor->list.next;
+ }
+ screenp->xvadaptors = xnfalloc((count) * sizeof(confXvAdaptorRec));
+ screenp->numxvadaptors = 0;
+ conf_adaptor = conf_screen->scrn_adaptor_lst;
+ while(conf_adaptor) {
+ if (configXvAdaptor(&(screenp->xvadaptors[screenp->numxvadaptors]),
+ conf_adaptor->al_adaptor))
+ screenp->numxvadaptors++;
+ conf_adaptor = (XF86ConfAdaptorLinkPtr)conf_adaptor->list.next;
+ }
+
+ if (defaultMonitor) {
+ xf86Msg(X_WARNING, "No monitor specified for screen \"%s\".\n"
+ "\tUsing a default monitor configuration.\n", screenp->id);
+ }
+ return TRUE;
+}
+
+static Bool
+configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor)
+{
+ int count;
+ DisplayModePtr mode,last = NULL;
+ XF86ConfModeLinePtr cmodep;
+ XF86ConfModesPtr modes;
+ XF86ConfModesLinkPtr modeslnk = conf_monitor->mon_modes_sect_lst;
+ Gamma zeros = {0.0, 0.0, 0.0};
+ float badgamma = 0.0;
+
+ xf86Msg(X_CONFIG, "| |-->Monitor \"%s\"\n",
+ conf_monitor->mon_identifier);
+ monitorp->id = conf_monitor->mon_identifier;
+ monitorp->vendor = conf_monitor->mon_vendor;
+ monitorp->model = conf_monitor->mon_modelname;
+ monitorp->Modes = NULL;
+ monitorp->Last = NULL;
+ monitorp->gamma = zeros;
+ monitorp->widthmm = conf_monitor->mon_width;
+ monitorp->heightmm = conf_monitor->mon_height;
+ monitorp->options = conf_monitor->mon_option_lst;
+
+ /*
+ * fill in the monitor structure
+ */
+ for( count = 0 ;
+ count < conf_monitor->mon_n_hsync && count < MAX_HSYNC;
+ count++) {
+ monitorp->hsync[count].hi = conf_monitor->mon_hsync[count].hi;
+ monitorp->hsync[count].lo = conf_monitor->mon_hsync[count].lo;
+ }
+ monitorp->nHsync = count;
+ for( count = 0 ;
+ count < conf_monitor->mon_n_vrefresh && count < MAX_VREFRESH;
+ count++) {
+ monitorp->vrefresh[count].hi = conf_monitor->mon_vrefresh[count].hi;
+ monitorp->vrefresh[count].lo = conf_monitor->mon_vrefresh[count].lo;
+ }
+ monitorp->nVrefresh = count;
+
+ /*
+ * first we collect the mode lines from the UseModes directive
+ */
+ while(modeslnk)
+ {
+ modes = xf86findModes (modeslnk->ml_modes_str,
+ xf86configptr->conf_modes_lst);
+ modeslnk->ml_modes = modes;
+
+
+ /* now add the modes found in the modes
+ section to the list of modes for this
+ monitor unless it has been added before
+ because we are reusing the same section
+ for another screen */
+ if (xf86itemNotSublist(
+ (GenericListPtr)conf_monitor->mon_modeline_lst,
+ (GenericListPtr)modes->mon_modeline_lst)) {
+ conf_monitor->mon_modeline_lst = (XF86ConfModeLinePtr)
+ xf86addListItem(
+ (GenericListPtr)conf_monitor->mon_modeline_lst,
+ (GenericListPtr)modes->mon_modeline_lst);
+ }
+ modeslnk = modeslnk->list.next;
+ }
+
+ /*
+ * we need to hook in the mode lines now
+ * here both data structures use lists, only our internal one
+ * is double linked
+ */
+ cmodep = conf_monitor->mon_modeline_lst;
+ while( cmodep ) {
+ mode = xnfalloc(sizeof(DisplayModeRec));
+ memset(mode,'\0',sizeof(DisplayModeRec));
+ mode->type = 0;
+ mode->Clock = cmodep->ml_clock;
+ mode->HDisplay = cmodep->ml_hdisplay;
+ mode->HSyncStart = cmodep->ml_hsyncstart;
+ mode->HSyncEnd = cmodep->ml_hsyncend;
+ mode->HTotal = cmodep->ml_htotal;
+ mode->VDisplay = cmodep->ml_vdisplay;
+ mode->VSyncStart = cmodep->ml_vsyncstart;
+ mode->VSyncEnd = cmodep->ml_vsyncend;
+ mode->VTotal = cmodep->ml_vtotal;
+ mode->Flags = cmodep->ml_flags;
+ mode->HSkew = cmodep->ml_hskew;
+ mode->VScan = cmodep->ml_vscan;
+ mode->name = xnfstrdup(cmodep->ml_identifier);
+ if( last ) {
+ mode->prev = last;
+ last->next = mode;
+ }
+ else {
+ /*
+ * this is the first mode
+ */
+ monitorp->Modes = mode;
+ mode->prev = NULL;
+ }
+ last = mode;
+ cmodep = (XF86ConfModeLinePtr)cmodep->list.next;
+ }
+ if(last){
+ last->next = NULL;
+ }
+ monitorp->Last = last;
+
+ /* add the (VESA) default modes */
+ if (! addDefaultModes(monitorp) )
+ return FALSE;
+
+ if (conf_monitor->mon_gamma_red > GAMMA_ZERO)
+ monitorp->gamma.red = conf_monitor->mon_gamma_red;
+ if (conf_monitor->mon_gamma_green > GAMMA_ZERO)
+ monitorp->gamma.green = conf_monitor->mon_gamma_green;
+ if (conf_monitor->mon_gamma_blue > GAMMA_ZERO)
+ monitorp->gamma.blue = conf_monitor->mon_gamma_blue;
+
+ /* Check that the gamma values are within range */
+ if (monitorp->gamma.red > GAMMA_ZERO &&
+ (monitorp->gamma.red < GAMMA_MIN ||
+ monitorp->gamma.red > GAMMA_MAX)) {
+ badgamma = monitorp->gamma.red;
+ } else if (monitorp->gamma.green > GAMMA_ZERO &&
+ (monitorp->gamma.green < GAMMA_MIN ||
+ monitorp->gamma.green > GAMMA_MAX)) {
+ badgamma = monitorp->gamma.green;
+ } else if (monitorp->gamma.blue > GAMMA_ZERO &&
+ (monitorp->gamma.blue < GAMMA_MIN ||
+ monitorp->gamma.blue > GAMMA_MAX)) {
+ badgamma = monitorp->gamma.blue;
+ }
+ if (badgamma > GAMMA_ZERO) {
+ xf86ConfigError("Gamma value %.f is out of range (%.2f - %.1f)\n",
+ badgamma, GAMMA_MIN, GAMMA_MAX);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static int
+lookupVisual(const char *visname)
+{
+ int i;
+
+ if (!visname || !*visname)
+ return -1;
+
+ for (i = 0; i <= DirectColor; i++) {
+ if (!xf86nameCompare(visname, xf86VisualNames[i]))
+ break;
+ }
+
+ if (i <= DirectColor)
+ return i;
+
+ return -1;
+}
+
+
+static Bool
+configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display)
+{
+ int count = 0;
+ XF86ModePtr modep;
+
+ displayp->frameX0 = conf_display->disp_frameX0;
+ displayp->frameY0 = conf_display->disp_frameY0;
+ displayp->virtualX = conf_display->disp_virtualX;
+ displayp->virtualY = conf_display->disp_virtualY;
+ displayp->depth = conf_display->disp_depth;
+ displayp->fbbpp = conf_display->disp_bpp;
+ displayp->weight.red = conf_display->disp_weight.red;
+ displayp->weight.green = conf_display->disp_weight.green;
+ displayp->weight.blue = conf_display->disp_weight.blue;
+ displayp->blackColour.red = conf_display->disp_black.red;
+ displayp->blackColour.green = conf_display->disp_black.green;
+ displayp->blackColour.blue = conf_display->disp_black.blue;
+ displayp->whiteColour.red = conf_display->disp_white.red;
+ displayp->whiteColour.green = conf_display->disp_white.green;
+ displayp->whiteColour.blue = conf_display->disp_white.blue;
+ displayp->options = conf_display->disp_option_lst;
+ if (conf_display->disp_visual) {
+ displayp->defaultVisual = lookupVisual(conf_display->disp_visual);
+ if (displayp->defaultVisual == -1) {
+ xf86ConfigError("Invalid visual name: \"%s\"",
+ conf_display->disp_visual);
+ return FALSE;
+ }
+ } else {
+ displayp->defaultVisual = -1;
+ }
+
+ /*
+ * now hook in the modes
+ */
+ modep = conf_display->disp_mode_lst;
+ while(modep) {
+ count++;
+ modep = (XF86ModePtr)modep->list.next;
+ }
+ displayp->modes = xnfalloc((count+1) * sizeof(char*));
+ modep = conf_display->disp_mode_lst;
+ count = 0;
+ while(modep) {
+ displayp->modes[count] = modep->mode_name;
+ count++;
+ modep = (XF86ModePtr)modep->list.next;
+ }
+ displayp->modes[count] = NULL;
+
+ return TRUE;
+}
+
+static Bool
+configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, Bool active)
+{
+ int i;
+
+ if (active)
+ xf86Msg(X_CONFIG, "| |-->Device \"%s\"\n",
+ conf_device->dev_identifier);
+ else
+ xf86Msg(X_CONFIG, "|-->Inactive Device \"%s\"\n",
+ conf_device->dev_identifier);
+
+ devicep->identifier = conf_device->dev_identifier;
+ devicep->vendor = conf_device->dev_vendor;
+ devicep->board = conf_device->dev_board;
+ devicep->chipset = conf_device->dev_chipset;
+ devicep->ramdac = conf_device->dev_ramdac;
+ devicep->driver = conf_device->dev_driver;
+ devicep->active = active;
+ devicep->videoRam = conf_device->dev_videoram;
+ devicep->BiosBase = conf_device->dev_bios_base;
+ devicep->MemBase = conf_device->dev_mem_base;
+ devicep->IOBase = conf_device->dev_io_base;
+ devicep->clockchip = conf_device->dev_clockchip;
+ devicep->busID = conf_device->dev_busid;
+ devicep->textClockFreq = conf_device->dev_textclockfreq;
+ devicep->chipID = conf_device->dev_chipid;
+ devicep->chipRev = conf_device->dev_chiprev;
+ devicep->options = conf_device->dev_option_lst;
+ devicep->irq = conf_device->dev_irq;
+ devicep->screen = conf_device->dev_screen;
+
+ for (i = 0; i < MAXDACSPEEDS; i++) {
+ if (i < CONF_MAXDACSPEEDS)
+ devicep->dacSpeeds[i] = conf_device->dev_dacSpeeds[i];
+ else
+ devicep->dacSpeeds[i] = 0;
+ }
+ devicep->numclocks = conf_device->dev_clocks;
+ if (devicep->numclocks > MAXCLOCKS)
+ devicep->numclocks = MAXCLOCKS;
+ for (i = 0; i < devicep->numclocks; i++) {
+ devicep->clock[i] = conf_device->dev_clock[i];
+ }
+ devicep->claimed = FALSE;
+
+ return TRUE;
+}
+
+#ifdef XF86DRI
+static Bool
+configDRI(XF86ConfDRIPtr drip)
+{
+ int count = 0;
+ XF86ConfBuffersPtr bufs;
+ int i;
+ struct group *grp;
+
+ xf86ConfigDRI.group = -1;
+ xf86ConfigDRI.mode = 0;
+ xf86ConfigDRI.bufs_count = 0;
+ xf86ConfigDRI.bufs = NULL;
+
+ if (drip) {
+ if (drip->dri_group_name) {
+ if ((grp = getgrnam(drip->dri_group_name)))
+ xf86ConfigDRI.group = grp->gr_gid;
+ } else {
+ if (drip->dri_group >= 0)
+ xf86ConfigDRI.group = drip->dri_group;
+ }
+ xf86ConfigDRI.mode = drip->dri_mode;
+ for (bufs = drip->dri_buffers_lst; bufs; bufs = bufs->list.next)
+ ++count;
+
+ xf86ConfigDRI.bufs_count = count;
+ xf86ConfigDRI.bufs = xnfalloc(count * sizeof(*xf86ConfigDRI.bufs));
+
+ for (i = 0, bufs = drip->dri_buffers_lst;
+ i < count;
+ i++, bufs = bufs->list.next) {
+
+ xf86ConfigDRI.bufs[i].count = bufs->buf_count;
+ xf86ConfigDRI.bufs[i].size = bufs->buf_size;
+ /* FIXME: Flags not implemented. These
+ could be used, for example, to specify a
+ contiguous block and/or write-combining
+ cache policy. */
+ xf86ConfigDRI.bufs[i].flags = 0;
+ }
+ }
+
+ return TRUE;
+}
+#endif
+
+static Bool
+configExtensions(XF86ConfExtensionsPtr conf_ext)
+{
+ XF86OptionPtr o;
+
+ /* Extension enable/disable in miinitext.c */
+ extern Bool EnableDisableExtension(char *name, Bool enable);
+
+ if (conf_ext && conf_ext->ext_option_lst) {
+ for (o = conf_ext->ext_option_lst; o; o = xf86NextOption(o)) {
+ char *name = xf86OptionName(o);
+ char *val = xf86OptionValue(o);
+ char *n;
+ Bool enable = TRUE;
+
+ /* Handle "No<ExtensionName>" */
+ n = xf86NormalizeName(name);
+ if (strncmp(n, "no", 2) == 0) {
+ name += 2;
+ enable = FALSE;
+ }
+
+ if (!val ||
+ xf86NameCmp(val, "enable") == 0 ||
+ xf86NameCmp(val, "enabled") == 0 ||
+ xf86NameCmp(val, "on") == 0 ||
+ xf86NameCmp(val, "1") == 0 ||
+ xf86NameCmp(val, "yes") == 0 ||
+ xf86NameCmp(val, "true") == 0) {
+ /* NOTHING NEEDED -- enabling is handled below */
+ } else if (xf86NameCmp(val, "disable") == 0 ||
+ xf86NameCmp(val, "disabled") == 0 ||
+ xf86NameCmp(val, "off") == 0 ||
+ xf86NameCmp(val, "0") == 0 ||
+ xf86NameCmp(val, "no") == 0 ||
+ xf86NameCmp(val, "false") == 0) {
+ enable = !enable;
+ } else {
+ xf86Msg(X_ERROR,
+ "%s is not a valid value for the Extension option\n",
+ val);
+ return FALSE;
+ }
+
+ if (EnableDisableExtension(name, enable)) {
+ xf86Msg(X_CONFIG, "Extension \"%s\" is %s\n",
+ name, enable ? "enabled" : "disabled");
+ } else {
+ xf86Msg(X_WARNING, "Ignoring unrecognized extension \"%s\"\n",
+ name);
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+static Bool
+configInput(IDevPtr inputp, XF86ConfInputPtr conf_input, MessageType from)
+{
+ xf86Msg(from, "|-->Input Device \"%s\"\n", conf_input->inp_identifier);
+ inputp->identifier = conf_input->inp_identifier;
+ inputp->driver = conf_input->inp_driver;
+ inputp->commonOptions = conf_input->inp_option_lst;
+ inputp->extraOptions = NULL;
+
+ /* XXX This is required until the keyboard driver is converted */
+ if (!xf86NameCmp(inputp->driver, "keyboard"))
+ return configInputKbd(inputp);
+
+ return TRUE;
+}
+
+static Bool
+modeIsPresent(char * modename,MonPtr monitorp)
+{
+ DisplayModePtr knownmodes = monitorp->Modes;
+
+ /* all I can think of is a linear search... */
+ while(knownmodes != NULL)
+ {
+ if(!strcmp(modename,knownmodes->name) &&
+ !(knownmodes->type & M_T_DEFAULT))
+ return TRUE;
+ knownmodes = knownmodes->next;
+ }
+ return FALSE;
+}
+
+static Bool
+addDefaultModes(MonPtr monitorp)
+{
+ DisplayModePtr mode;
+ DisplayModePtr last = monitorp->Last;
+ int i = 0;
+
+ while (xf86DefaultModes[i].name != NULL)
+ {
+ if ( ! modeIsPresent(xf86DefaultModes[i].name,monitorp) )
+ do
+ {
+ mode = xnfalloc(sizeof(DisplayModeRec));
+ memcpy(mode,&xf86DefaultModes[i],sizeof(DisplayModeRec));
+ if (xf86DefaultModes[i].name)
+ mode->name = xnfstrdup(xf86DefaultModes[i].name);
+ if( last ) {
+ mode->prev = last;
+ last->next = mode;
+ }
+ else {
+ /* this is the first mode */
+ monitorp->Modes = mode;
+ mode->prev = NULL;
+ }
+ last = mode;
+ i++;
+ }
+ while((xf86DefaultModes[i].name != NULL) &&
+ (!strcmp(xf86DefaultModes[i].name,xf86DefaultModes[i-1].name)));
+ else
+ i++;
+ }
+ monitorp->Last = last;
+
+ return TRUE;
+}
+
+/*
+ * load the config file and fill the global data structure
+ */
+ConfigStatus
+xf86HandleConfigFile(Bool autoconfig)
+{
+ const char *filename;
+ char *searchpath;
+ MessageType from = X_DEFAULT;
+ char *scanptr;
+ Bool singlecard = 0;
+
+ if (!autoconfig) {
+ if (getuid() == 0)
+ searchpath = ROOT_CONFIGPATH;
+ else
+ searchpath = USER_CONFIGPATH;
+
+ if (xf86ConfigFile)
+ from = X_CMDLINE;
+
+ filename = xf86openConfigFile(searchpath, xf86ConfigFile, PROJECTROOT);
+ if (filename) {
+ xf86MsgVerb(from, 0, "Using config file: \"%s\"\n", filename);
+ xf86ConfigFile = xnfstrdup(filename);
+ } else {
+ xf86Msg(X_ERROR, "Unable to locate/open config file");
+ if (xf86ConfigFile)
+ xf86ErrorFVerb(0, ": \"%s\"", xf86ConfigFile);
+ xf86ErrorFVerb(0, "\n");
+ return CONFIG_NOFILE;
+ }
+ }
+
+ if ((xf86configptr = xf86readConfigFile ()) == NULL) {
+ xf86Msg(X_ERROR, "Problem parsing the config file\n");
+ return CONFIG_PARSE_ERROR;
+ }
+ xf86closeConfigFile ();
+
+ /* Initialise a few things. */
+
+ /*
+ * now we convert part of the information contained in the parser
+ * structures into our own structures.
+ * The important part here is to figure out which Screen Sections
+ * in the XF86Config file are active so that we can piece together
+ * the modes that we need later down the road.
+ * And while we are at it, we'll decode the rest of the stuff as well
+ */
+
+ /* First check if a layout section is present, and if it is valid. */
+
+ if (xf86configptr->conf_layout_lst == NULL || xf86ScreenName != NULL) {
+ if (xf86ScreenName == NULL) {
+ xf86Msg(X_WARNING,
+ "No Layout section. Using the first Screen section.\n");
+ }
+ if (!configImpliedLayout(&xf86ConfigLayout,
+ xf86configptr->conf_screen_lst)) {
+ xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
+ return CONFIG_PARSE_ERROR;
+ }
+ } else {
+ if (xf86configptr->conf_flags != NULL) {
+ char *dfltlayout = NULL;
+ pointer optlist = xf86configptr->conf_flags->flg_option_lst;
+
+ if (optlist && xf86FindOption(optlist, "defaultserverlayout"))
+ dfltlayout = xf86SetStrOption(optlist, "defaultserverlayout", NULL);
+ if (!configLayout(&xf86ConfigLayout, xf86configptr->conf_layout_lst,
+ dfltlayout)) {
+ xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
+ return CONFIG_PARSE_ERROR;
+ }
+ } else {
+ if (!configLayout(&xf86ConfigLayout, xf86configptr->conf_layout_lst,
+ NULL)) {
+ xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
+ return CONFIG_PARSE_ERROR;
+ }
+ }
+ }
+
+ xf86ProcessOptions(-1, xf86ConfigLayout.options, LayoutOptions);
+
+ if ((scanptr = xf86GetOptValString(LayoutOptions, LAYOUT_ISOLATEDEVICE))) {
+ ; /* IsolateDevice specified; overrides SingleCard */
+ } else {
+ xf86GetOptValBool(LayoutOptions, LAYOUT_SINGLECARD, &singlecard);
+ if (singlecard)
+ scanptr = xf86ConfigLayout.screens->screen->device->busID;
+ }
+ if (scanptr) {
+ int bus, device, func, stroffset = 0;
+ if (strncmp(scanptr, "PCI:", 4) != 0) {
+ xf86Msg(X_WARNING, "Bus types other than PCI not yet isolable.\n"
+ "\tIgnoring IsolateDevice option.\n");
+ } else if (sscanf(scanptr, "PCI:%d:%d:%d", &bus, &device, &func) == 3) {
+ xf86IsolateDevice.bus = bus;
+ xf86IsolateDevice.device = device;
+ xf86IsolateDevice.func = func;
+ xf86Msg(X_INFO,
+ "Isolating PCI bus \"%d:%d:%d\"\n", bus, device, func);
+ }
+ }
+
+ /* Now process everything else */
+
+ if (!configFiles(xf86configptr->conf_files) ||
+ !configServerFlags(xf86configptr->conf_flags,
+ xf86ConfigLayout.options) ||
+ !configExtensions(xf86configptr->conf_extensions)
+#ifdef XF86DRI
+ || !configDRI(xf86configptr->conf_dri)
+#endif
+ ) {
+ ErrorF ("Problem when converting the config data structures\n");
+ return CONFIG_PARSE_ERROR;
+ }
+
+ /*
+ * Handle some command line options that can override some of the
+ * ServerFlags settings.
+ */
+#ifdef XF86VIDMODE
+ if (xf86VidModeDisabled)
+ xf86Info.vidModeEnabled = FALSE;
+ if (xf86VidModeAllowNonLocal)
+ xf86Info.vidModeAllowNonLocal = TRUE;
+#endif
+
+#ifdef XF86MISC
+ if (xf86MiscModInDevDisabled)
+ xf86Info.miscModInDevEnabled = FALSE;
+ if (xf86MiscModInDevAllowNonLocal)
+ xf86Info.miscModInDevAllowNonLocal = TRUE;
+#endif
+
+ if (xf86AllowMouseOpenFail)
+ xf86Info.allowMouseOpenFail = TRUE;
+
+ return CONFIG_OK;
+}
+
+
+/* These make the equivalent parser functions visible to the common layer. */
+Bool
+xf86PathIsAbsolute(const char *path)
+{
+ return (xf86pathIsAbsolute(path) != 0);
+}
+
+Bool
+xf86PathIsSafe(const char *path)
+{
+ return (xf86pathIsSafe(path) != 0);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Config.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Config.h
new file mode 100644
index 000000000..77b25ed32
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Config.h
@@ -0,0 +1,63 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Config.h,v 1.7 2003/10/08 14:58:27 dawes Exp $ */
+
+/*
+ * Copyright (c) 1997-2000 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_config_h
+#define _xf86_config_h
+
+#ifdef HAVE_PARSER_DECLS
+/*
+ * global structure that holds the result of parsing the config file
+ */
+extern XF86ConfigPtr xf86configptr;
+#endif
+
+typedef enum _ConfigStatus {
+ CONFIG_OK = 0,
+ CONFIG_PARSE_ERROR,
+ CONFIG_NOFILE
+} ConfigStatus;
+
+/*
+ * prototypes
+ */
+char ** xf86ModulelistFromConfig(pointer **);
+char ** xf86DriverlistFromConfig(void);
+char ** xf86DriverlistFromCompile(void);
+char ** xf86InputDriverlistFromConfig(void);
+char ** xf86InputDriverlistFromCompile(void);
+Bool xf86BuiltinInputDriver(const char *);
+ConfigStatus xf86HandleConfigFile(Bool);
+
+Bool xf86AutoConfig(void);
+
+#endif /* _xf86_config_h */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Configure.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Configure.c
new file mode 100644
index 000000000..208961f6a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Configure.c
@@ -0,0 +1,1049 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Configure.c,v 3.80 2003/10/08 14:58:27 dawes Exp $ */
+/*
+ * Copyright 2000-2002 by Alan Hourihane, Flint Mountain, North Wales.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Alan Hourihane not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Alan Hourihane makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Alan Hourihane, alanh@fairlite.demon.co.uk
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "os.h"
+#ifdef XFree86LOADER
+#include "loaderProcs.h"
+#endif
+#include "xf86.h"
+#include "xf86Config.h"
+#include "xf86_OSlib.h"
+#include "xf86Priv.h"
+#include "xf86PciData.h"
+#define IN_XSERVER
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "vbe.h"
+#include "xf86DDC.h"
+#if defined(__sparc__) && !defined(__OpenBSD__)
+#include "xf86Bus.h"
+#include "xf86Sbus.h"
+#endif
+#include "globals.h"
+
+typedef struct _DevToConfig {
+ GDevRec GDev;
+ pciVideoPtr pVideo;
+#if defined(__sparc__) && !defined(__OpenBSD__)
+ sbusDevicePtr sVideo;
+#endif
+ int iDriver;
+} DevToConfigRec, *DevToConfigPtr;
+
+static DevToConfigPtr DevToConfig = NULL;
+static int nDevToConfig = 0, CurrentDriver;
+
+xf86MonPtr ConfiguredMonitor;
+Bool xf86DoConfigurePass1 = TRUE;
+Bool foundMouse = FALSE;
+
+#if defined(__UNIXOS2__)
+#define DFLT_MOUSE_DEV "mouse$"
+#define DFLT_MOUSE_PROTO "OS2Mouse"
+#elif defined(__SCO__)
+static char *DFLT_MOUSE_PROTO = "OSMouse";
+#elif defined(__UNIXWARE__)
+static char *DFLT_MOUSE_PROTO = "Xqueue";
+static char *DFLT_MOUSE_DEV = "/dev/mouse";
+#elif defined(QNX4)
+static char *DFLT_MOUSE_PROTO = "OSMouse";
+static char *DFLT_MOUSE_DEV = "/dev/mouse";
+#elif defined(__QNXNTO__)
+static char *DFLT_MOUSE_PROTO = "OSMouse";
+static char *DFLT_MOUSE_DEV = "/dev/devi/mouse0";
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+static char *DFLT_MOUSE_DEV = "/dev/sysmouse";
+static char *DFLT_MOUSE_PROTO = "auto";
+#else
+static char *DFLT_MOUSE_DEV = "/dev/mouse";
+static char *DFLT_MOUSE_PROTO = "auto";
+#endif
+
+/*
+ * This is called by the driver, either through xf86Match???Instances() or
+ * directly. We allocate a GDevRec and fill it in as much as we can, letting
+ * the caller fill in the rest and/or change it as it sees fit.
+ */
+GDevPtr
+xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int chipset)
+{
+ int i, j;
+ pciVideoPtr pVideo = NULL;
+ Bool isPrimary = FALSE;
+
+ if (xf86DoProbe || !xf86DoConfigure || !xf86DoConfigurePass1)
+ return NULL;
+
+ /* Check for duplicates */
+ switch (bus) {
+ case BUS_PCI:
+ pVideo = (pciVideoPtr) busData;
+ for (i = 0; i < nDevToConfig; i++)
+ if (DevToConfig[i].pVideo &&
+ (DevToConfig[i].pVideo->bus == pVideo->bus) &&
+ (DevToConfig[i].pVideo->device == pVideo->device) &&
+ (DevToConfig[i].pVideo->func == pVideo->func))
+ return NULL;
+ isPrimary = xf86IsPrimaryPci(pVideo);
+ break;
+ case BUS_ISA:
+ /*
+ * This needs to be revisited as it doesn't allow for non-PCI
+ * multihead.
+ */
+ if (!xf86IsPrimaryIsa())
+ return NULL;
+ isPrimary = TRUE;
+ for (i = 0; i < nDevToConfig; i++)
+ if (!DevToConfig[i].pVideo)
+ return NULL;
+ break;
+#if defined(__sparc__) && !defined(__OpenBSD__)
+ case BUS_SBUS:
+ for (i = 0; i < nDevToConfig; i++)
+ if (DevToConfig[i].sVideo &&
+ DevToConfig[i].sVideo->fbNum == ((sbusDevicePtr) busData)->fbNum)
+ return NULL;
+ break;
+#endif
+ default:
+ return NULL;
+ }
+
+ /* Allocate new structure occurrence */
+ i = nDevToConfig++;
+ DevToConfig =
+ xnfrealloc(DevToConfig, nDevToConfig * sizeof(DevToConfigRec));
+#if 1 /* Doesn't work when a driver detects more than one adapter */
+ if ((i > 0) && isPrimary) {
+ memmove(DevToConfig + 1,DevToConfig,
+ (nDevToConfig - 1) * sizeof(DevToConfigRec));
+ i = 0;
+ }
+#endif
+ memset(DevToConfig + i, 0, sizeof(DevToConfigRec));
+
+# define NewDevice DevToConfig[i]
+
+ NewDevice.GDev.chipID = NewDevice.GDev.chipRev = NewDevice.GDev.irq = -1;
+
+ NewDevice.iDriver = CurrentDriver;
+
+ /* Fill in what we know, converting the driver name to lower case */
+ NewDevice.GDev.driver = xnfalloc(strlen(driver) + 1);
+ for (j = 0; (NewDevice.GDev.driver[j] = tolower(driver[j])); j++);
+
+ switch (bus) {
+ case BUS_PCI: {
+ const char *VendorName;
+ const char *CardName;
+ char busnum[8];
+
+ NewDevice.pVideo = pVideo;
+ xf86FindPciNamesByDevice(pVideo->vendor, pVideo->chipType,
+ NOVENDOR, NOSUBSYS,
+ &VendorName, &CardName, NULL, NULL);
+
+ if (!VendorName) {
+ VendorName = xnfalloc(15);
+ sprintf((char*)VendorName, "Unknown Vendor");
+ }
+
+ if (!CardName) {
+ CardName = xnfalloc(14);
+ sprintf((char*)CardName, "Unknown Board");
+ }
+
+ NewDevice.GDev.identifier =
+ xnfalloc(strlen(VendorName) + strlen(CardName) + 2);
+ sprintf(NewDevice.GDev.identifier, "%s %s", VendorName, CardName);
+
+ NewDevice.GDev.vendor = (char *)VendorName;
+ NewDevice.GDev.board = (char *)CardName;
+
+ NewDevice.GDev.busID = xnfalloc(16);
+ xf86FormatPciBusNumber(pVideo->bus, busnum);
+ sprintf(NewDevice.GDev.busID, "PCI:%s:%d:%d",
+ busnum, pVideo->device, pVideo->func);
+
+ NewDevice.GDev.chipID = pVideo->chipType;
+ NewDevice.GDev.chipRev = pVideo->chipRev;
+
+ if (chipset < 0)
+ chipset = (pVideo->vendor << 16) | pVideo->chipType;
+ }
+ break;
+ case BUS_ISA:
+ NewDevice.GDev.identifier = "ISA Adapter";
+ NewDevice.GDev.busID = "ISA";
+ break;
+#if defined(__sparc__) && !defined(__OpenBSD__)
+ case BUS_SBUS: {
+ char *promPath = NULL;
+ NewDevice.sVideo = (sbusDevicePtr) busData;
+ NewDevice.GDev.identifier = NewDevice.sVideo->descr;
+ if (sparcPromInit() >= 0) {
+ promPath = sparcPromNode2Pathname(&NewDevice.sVideo->node);
+ sparcPromClose();
+ }
+ if (promPath) {
+ NewDevice.GDev.busID = xnfalloc(strlen(promPath) + 6);
+ sprintf(NewDevice.GDev.busID, "SBUS:%s", promPath);
+ xfree(promPath);
+ } else {
+ NewDevice.GDev.busID = xnfalloc(12);
+ sprintf(NewDevice.GDev.busID, "SBUS:fb%d", NewDevice.sVideo->fbNum);
+ }
+ }
+ break;
+#endif
+ default:
+ break;
+ }
+
+ /* Get driver's available options */
+ if (xf86DriverList[CurrentDriver]->AvailableOptions)
+ NewDevice.GDev.options = (OptionInfoPtr)
+ (*xf86DriverList[CurrentDriver]->AvailableOptions)(chipset,
+ bus);
+
+ return &NewDevice.GDev;
+
+# undef NewDevice
+}
+
+/*
+ * Backwards compatibility
+ */
+GDevPtr
+xf86AddDeviceToConfigure(const char *driver, pciVideoPtr pVideo, int chipset)
+{
+ return xf86AddBusDeviceToConfigure(driver, pVideo ? BUS_PCI : BUS_ISA,
+ pVideo, chipset);
+}
+
+static XF86ConfInputPtr
+configureInputSection (void)
+{
+ XF86ConfInputPtr mouse = NULL;
+ parsePrologue (XF86ConfInputPtr, XF86ConfInputRec)
+
+ ptr->inp_identifier = "Keyboard0";
+#ifdef USE_DEPRECATED_KEYBOARD_DRIVER
+ ptr->inp_driver = "keyboard";
+#else
+ ptr->inp_driver = "kbd";
+#endif
+ ptr->list.next = NULL;
+
+ /* Crude mechanism to auto-detect mouse (os dependent) */
+ {
+ int fd;
+#if 0 && defined linux
+ /* Our autodetection code can do a better job */
+ int len;
+ char path[32];
+
+ if ((len = readlink(DFLT_MOUSE_DEV, path, sizeof(path) - 1)) > 0) {
+ path[len] = '\0';
+ if (strstr(path, "psaux") != NULL)
+ DFLT_MOUSE_PROTO = "PS/2";
+ }
+#endif
+#ifdef WSCONS_SUPPORT
+ fd = open("/dev/wsmouse", 0);
+ if (fd > 0) {
+ DFLT_MOUSE_DEV = "/dev/wsmouse";
+ DFLT_MOUSE_PROTO = "wsmouse";
+ close(fd);
+ } else {
+ ErrorF("cannot open /dev/wsmouse\n");
+ }
+#endif
+
+#ifndef __SCO__
+ fd = open(DFLT_MOUSE_DEV, 0);
+ if (fd != -1) {
+ foundMouse = TRUE;
+ close(fd);
+ }
+#else
+ foundMouse = TRUE;
+#endif
+ }
+
+ mouse = xf86confmalloc(sizeof(XF86ConfInputRec));
+ memset((XF86ConfInputPtr)mouse,0,sizeof(XF86ConfInputRec));
+ mouse->inp_identifier = "Mouse0";
+ mouse->inp_driver = "mouse";
+ mouse->inp_option_lst =
+ xf86addNewOption(mouse->inp_option_lst, "Protocol", DFLT_MOUSE_PROTO);
+#ifndef __SCO__
+ mouse->inp_option_lst =
+ xf86addNewOption(mouse->inp_option_lst, "Device", DFLT_MOUSE_DEV);
+#endif
+ mouse->inp_option_lst =
+ xf86addNewOption(mouse->inp_option_lst, "ZAxisMapping", "4 5 6 7");
+ ptr = (XF86ConfInputPtr)xf86addListItem((glp)ptr, (glp)mouse);
+ return ptr;
+}
+
+static XF86ConfDRIPtr
+configureDRISection (void)
+{
+#ifdef NOTYET
+ parsePrologue (XF86ConfDRIPtr, XF86ConfDRIRec)
+
+ return ptr;
+#else
+ return NULL;
+#endif
+}
+
+static XF86ConfVendorPtr
+configureVendorSection (void)
+{
+ parsePrologue (XF86ConfVendorPtr, XF86ConfVendorRec)
+
+ return NULL;
+#if 0
+ return ptr;
+#endif
+}
+
+static XF86ConfScreenPtr
+configureScreenSection (int screennum)
+{
+ int i;
+ int depths[] = { 1, 4, 8, 15, 16, 24/*, 32*/ };
+ parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec)
+
+ ptr->scrn_identifier = xf86confmalloc(18);
+ sprintf(ptr->scrn_identifier, "Screen%d", screennum);
+ ptr->scrn_monitor_str = xf86confmalloc(19);
+ sprintf(ptr->scrn_monitor_str, "Monitor%d", screennum);
+ ptr->scrn_device_str = xf86confmalloc(16);
+ sprintf(ptr->scrn_device_str, "Card%d", screennum);
+
+ for (i=0; i<sizeof(depths)/sizeof(depths[0]); i++)
+ {
+ XF86ConfDisplayPtr display;
+
+ display = xf86confmalloc(sizeof(XF86ConfDisplayRec));
+ memset((XF86ConfDisplayPtr)display,0,sizeof(XF86ConfDisplayRec));
+ display->disp_depth = depths[i];
+ display->disp_black.red = display->disp_white.red = -1;
+ display->disp_black.green = display->disp_white.green = -1;
+ display->disp_black.blue = display->disp_white.blue = -1;
+ ptr->scrn_display_lst = (XF86ConfDisplayPtr)xf86addListItem(
+ (glp)ptr->scrn_display_lst, (glp)display);
+ }
+
+ return ptr;
+}
+
+static const char*
+optionTypeToSting(OptionValueType type)
+{
+ switch (type) {
+ case OPTV_NONE:
+ return "";
+ case OPTV_INTEGER:
+ return "<i>";
+ case OPTV_STRING:
+ return "<str>";
+ case OPTV_ANYSTR:
+ return "[<str>]";
+ case OPTV_REAL:
+ return "<f>";
+ case OPTV_BOOLEAN:
+ return "[<bool>]";
+ case OPTV_FREQ:
+ return "<freq>";
+ default:
+ return "";
+ }
+}
+
+static XF86ConfDevicePtr
+configureDeviceSection (int screennum)
+{
+ char identifier[16];
+ OptionInfoPtr p;
+ int i = 0;
+#ifdef DO_FBDEV_PROBE
+ Bool foundFBDEV = FALSE;
+#endif
+ parsePrologue (XF86ConfDevicePtr, XF86ConfDeviceRec)
+
+ /* Move device info to parser structure */
+ sprintf(identifier, "Card%d", screennum);
+ ptr->dev_identifier = strdup(identifier);
+/* ptr->dev_identifier = DevToConfig[screennum].GDev.identifier;*/
+ ptr->dev_vendor = DevToConfig[screennum].GDev.vendor;
+ ptr->dev_board = DevToConfig[screennum].GDev.board;
+ ptr->dev_chipset = DevToConfig[screennum].GDev.chipset;
+ ptr->dev_busid = DevToConfig[screennum].GDev.busID;
+ ptr->dev_driver = DevToConfig[screennum].GDev.driver;
+ ptr->dev_ramdac = DevToConfig[screennum].GDev.ramdac;
+ for (i = 0; (i < MAXDACSPEEDS) && (i < CONF_MAXDACSPEEDS); i++)
+ ptr->dev_dacSpeeds[i] = DevToConfig[screennum].GDev.dacSpeeds[i];
+ ptr->dev_videoram = DevToConfig[screennum].GDev.videoRam;
+ ptr->dev_textclockfreq = DevToConfig[screennum].GDev.textClockFreq;
+ ptr->dev_bios_base = DevToConfig[screennum].GDev.BiosBase;
+ ptr->dev_mem_base = DevToConfig[screennum].GDev.MemBase;
+ ptr->dev_io_base = DevToConfig[screennum].GDev.IOBase;
+ ptr->dev_clockchip = DevToConfig[screennum].GDev.clockchip;
+ for (i = 0; (i < MAXCLOCKS) && (i < DevToConfig[screennum].GDev.numclocks); i++)
+ ptr->dev_clock[i] = DevToConfig[screennum].GDev.clock[i];
+ ptr->dev_clocks = i;
+ ptr->dev_chipid = DevToConfig[screennum].GDev.chipID;
+ ptr->dev_chiprev = DevToConfig[screennum].GDev.chipRev;
+ ptr->dev_irq = DevToConfig[screennum].GDev.irq;
+
+ /* Make sure older drivers don't segv */
+ if (DevToConfig[screennum].GDev.options) {
+ /* Fill in the available driver options for people to use */
+ const char *descrip =
+ " ### Available Driver options are:-\n"
+ " ### Values: <i>: integer, <f>: float, "
+ "<bool>: \"True\"/\"False\",\n"
+ " ### <string>: \"String\", <freq>: \"<f> Hz/kHz/MHz\"\n"
+ " ### [arg]: arg optional\n";
+ ptr->dev_comment = xstrdup(descrip);
+ if (ptr->dev_comment) {
+ for (p = DevToConfig[screennum].GDev.options;
+ p->name != NULL; p++) {
+ char *p_e;
+ const char *prefix = " #Option ";
+ const char *middle = " \t# ";
+ const char *suffix = "\n";
+ const char *opttype = optionTypeToSting(p->type);
+ char *optname;
+ int len = strlen(ptr->dev_comment) + strlen(prefix) +
+ strlen(middle) + strlen(suffix) + 1;
+
+ optname = xalloc(strlen(p->name) + 2 + 1);
+ if (!optname)
+ break;
+ sprintf(optname, "\"%s\"", p->name);
+
+ len += max(20, strlen(optname));
+ len += strlen(opttype);
+
+ ptr->dev_comment = xrealloc(ptr->dev_comment, len);
+ if (!ptr->dev_comment)
+ break;
+ p_e = ptr->dev_comment + strlen(ptr->dev_comment);
+ sprintf(p_e, "%s%-20s%s%s%s", prefix, optname, middle,
+ opttype, suffix);
+ xfree(optname);
+ }
+ }
+ }
+
+#ifdef DO_FBDEV_PROBE
+ /* Crude mechanism to auto-detect fbdev (os dependent) */
+ /* Skip it for now. Options list it anyway, and we can't
+ * determine which screen/driver this belongs too anyway. */
+ {
+ int fd;
+
+ fd = open("/dev/fb0", 0);
+ if (fd != -1) {
+ foundFBDEV = TRUE;
+ close(fd);
+ }
+ }
+
+ if (foundFBDEV) {
+ XF86OptionPtr fbdev;
+
+ fbdev = xf86confmalloc(sizeof(XF86OptionRec));
+ memset((XF86OptionPtr)fbdev,0,sizeof(XF86OptionRec));
+ fbdev->opt_name = "UseFBDev";
+ fbdev->opt_val = "ON";
+ ptr->dev_option_lst = (XF86OptionPtr)xf86addListItem(
+ (glp)ptr->dev_option_lst, (glp)fbdev);
+ }
+#endif
+
+ return ptr;
+}
+
+static XF86ConfLayoutPtr
+configureLayoutSection (void)
+{
+ int scrnum = 0;
+ parsePrologue (XF86ConfLayoutPtr, XF86ConfLayoutRec)
+
+ ptr->lay_identifier = "X.org Configured";
+
+ {
+ XF86ConfInputrefPtr iptr;
+
+ iptr = xf86confmalloc (sizeof (XF86ConfInputrefRec));
+ iptr->list.next = NULL;
+ iptr->iref_option_lst = NULL;
+ iptr->iref_inputdev_str = "Mouse0";
+ iptr->iref_option_lst =
+ xf86addNewOption (iptr->iref_option_lst, "CorePointer", NULL);
+ ptr->lay_input_lst = (XF86ConfInputrefPtr)
+ xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr);
+ }
+
+ {
+ XF86ConfInputrefPtr iptr;
+
+ iptr = xf86confmalloc (sizeof (XF86ConfInputrefRec));
+ iptr->list.next = NULL;
+ iptr->iref_option_lst = NULL;
+ iptr->iref_inputdev_str = "Keyboard0";
+ iptr->iref_option_lst =
+ xf86addNewOption (iptr->iref_option_lst, "CoreKeyboard", NULL);
+ ptr->lay_input_lst = (XF86ConfInputrefPtr)
+ xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr);
+ }
+
+ for (scrnum = 0; scrnum < nDevToConfig; scrnum++) {
+ XF86ConfAdjacencyPtr aptr;
+
+ aptr = xf86confmalloc (sizeof (XF86ConfAdjacencyRec));
+ aptr->list.next = NULL;
+ aptr->adj_x = 0;
+ aptr->adj_y = 0;
+ aptr->adj_scrnum = scrnum;
+ aptr->adj_screen_str = xnfalloc(18);
+ sprintf(aptr->adj_screen_str, "Screen%d", scrnum);
+ if (scrnum == 0) {
+ aptr->adj_where = CONF_ADJ_ABSOLUTE;
+ aptr->adj_refscreen = NULL;
+ }
+ else {
+ aptr->adj_where = CONF_ADJ_RIGHTOF;
+ aptr->adj_refscreen = xnfalloc(18);
+ sprintf(aptr->adj_refscreen, "Screen%d", scrnum - 1);
+ }
+ ptr->lay_adjacency_lst =
+ (XF86ConfAdjacencyPtr)xf86addListItem((glp)ptr->lay_adjacency_lst,
+ (glp)aptr);
+ }
+
+ return ptr;
+}
+
+static XF86ConfModesPtr
+configureModesSection (void)
+{
+#ifdef NOTYET
+ parsePrologue (XF86ConfModesPtr, XF86ConfModesRec)
+
+ return ptr;
+#else
+ return NULL;
+#endif
+}
+
+static XF86ConfVideoAdaptorPtr
+configureVideoAdaptorSection (void)
+{
+ parsePrologue (XF86ConfVideoAdaptorPtr, XF86ConfVideoAdaptorRec)
+
+ return NULL;
+#if 0
+ return ptr;
+#endif
+}
+
+static XF86ConfFlagsPtr
+configureFlagsSection (void)
+{
+ parsePrologue (XF86ConfFlagsPtr, XF86ConfFlagsRec)
+
+ return ptr;
+}
+
+static XF86ConfModulePtr
+configureModuleSection (void)
+{
+#ifdef XFree86LOADER
+ char **elist, **el;
+ /* Find the list of extension modules. */
+ const char *esubdirs[] = {
+ "extensions",
+ NULL
+ };
+ const char *fsubdirs[] = {
+ "fonts",
+ NULL
+ };
+#endif
+ parsePrologue (XF86ConfModulePtr, XF86ConfModuleRec)
+
+#ifdef XFree86LOADER
+ elist = LoaderListDirs(esubdirs, NULL);
+ if (elist) {
+ for (el = elist; *el; el++) {
+ XF86LoadPtr module;
+
+ module = xf86confmalloc(sizeof(XF86LoadRec));
+ memset((XF86LoadPtr)module,0,sizeof(XF86LoadRec));
+ module->load_name = *el;
+ /* HACK, remove GLcore, glx, loads it as a submodule */
+ if (strcmp(*el, "GLcore"))
+ ptr->mod_load_lst = (XF86LoadPtr)xf86addListItem(
+ (glp)ptr->mod_load_lst, (glp)module);
+ }
+ xfree(elist);
+ }
+
+ /* Process list of font backends separately to include only required ones */
+ elist = LoaderListDirs(fsubdirs, NULL);
+ if (elist) {
+ for (el = elist; *el; el++) {
+ XF86LoadPtr module;
+
+ module = xf86confmalloc(sizeof(XF86LoadRec));
+ memset((XF86LoadPtr)module,0,sizeof(XF86LoadRec));
+ module->load_name = *el;
+
+ /* Add only those font backends which are referenced by fontpath */
+ /* 'strstr(dFP,"/dir")' is meant as 'dFP =~ m(/dir\W)' */
+ if (defaultFontPath && (
+ (strcmp(*el, "freetype") == 0 &&
+ strstr(defaultFontPath, "/TTF")) ||
+ (strcmp(*el, "type1") == 0 &&
+ strstr(defaultFontPath, "/Type1")) ||
+ (strcmp(*el, "speedo") == 0 &&
+ strstr(defaultFontPath, "/Speedo"))))
+ ptr->mod_load_lst = (XF86LoadPtr)xf86addListItem(
+ (glp)ptr->mod_load_lst, (glp)module);
+ }
+ xfree(elist);
+ }
+#endif
+
+ return ptr;
+}
+
+static XF86ConfFilesPtr
+configureFilesSection (void)
+{
+ parsePrologue (XF86ConfFilesPtr, XF86ConfFilesRec)
+
+#ifdef XFree86LOADER
+ if (xf86ModulePath)
+ ptr->file_modulepath = strdup(xf86ModulePath);
+#endif
+ if (defaultFontPath)
+ ptr->file_fontpath = strdup(defaultFontPath);
+ if (rgbPath)
+ ptr->file_rgbpath = strdup(rgbPath);
+
+ return ptr;
+}
+
+static XF86ConfMonitorPtr
+configureMonitorSection (int screennum)
+{
+ parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec)
+
+ ptr->mon_identifier = xf86confmalloc(19);
+ sprintf(ptr->mon_identifier, "Monitor%d", screennum);
+ ptr->mon_vendor = strdup("Monitor Vendor");
+ ptr->mon_modelname = strdup("Monitor Model");
+
+ return ptr;
+}
+
+static XF86ConfMonitorPtr
+configureDDCMonitorSection (int screennum)
+{
+ int i = 0;
+ int len, mon_width, mon_height;
+#define displaySizeMaxLen 80
+ char displaySize_string[displaySizeMaxLen];
+ int displaySizeLen;
+
+ parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec)
+
+ ptr->mon_identifier = xf86confmalloc(19);
+ sprintf(ptr->mon_identifier, "Monitor%d", screennum);
+ ptr->mon_vendor = strdup(ConfiguredMonitor->vendor.name);
+ ptr->mon_modelname = xf86confmalloc(12);
+ sprintf(ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id);
+
+ /* features in centimetres, we want millimetres */
+ mon_width = 10 * ConfiguredMonitor->features.hsize ;
+ mon_height = 10 * ConfiguredMonitor->features.vsize ;
+
+#ifdef CONFIGURE_DISPLAYSIZE
+ ptr->mon_width = mon_width;
+ ptr->mon_height = mon_height;
+#else
+ if (mon_width && mon_height) {
+ /* when values available add DisplaySize option AS A COMMENT */
+
+ displaySizeLen = snprintf(displaySize_string, displaySizeMaxLen,
+ "\t#DisplaySize\t%5d %5d\t# mm\n",
+ mon_width, mon_height);
+
+ if (displaySizeLen>0 && displaySizeLen<displaySizeMaxLen) {
+ if (ptr->mon_comment) {
+ len = strlen(ptr->mon_comment);
+ } else {
+ len = 0;
+ }
+ if ((ptr->mon_comment =
+ xf86confrealloc(ptr->mon_comment,
+ len+strlen(displaySize_string)))) {
+ strcpy(ptr->mon_comment + len, displaySize_string);
+ }
+ }
+ }
+#endif /* def CONFIGURE_DISPLAYSIZE */
+
+ for (i=0;i<4;i++) {
+ switch (ConfiguredMonitor->det_mon[i].type) {
+ case DS_NAME:
+ ptr->mon_modelname = xf86confrealloc(ptr->mon_modelname,
+ strlen((char*)(ConfiguredMonitor->det_mon[i].section.name))
+ + 1);
+ strcpy(ptr->mon_modelname,
+ (char*)(ConfiguredMonitor->det_mon[i].section.name));
+ break;
+ case DS_RANGES:
+ ptr->mon_hsync[ptr->mon_n_hsync].lo =
+ ConfiguredMonitor->det_mon[i].section.ranges.min_h;
+ ptr->mon_hsync[ptr->mon_n_hsync].hi =
+ ConfiguredMonitor->det_mon[i].section.ranges.max_h;
+ ptr->mon_n_vrefresh = 1;
+ ptr->mon_vrefresh[ptr->mon_n_hsync].lo =
+ ConfiguredMonitor->det_mon[i].section.ranges.min_v;
+ ptr->mon_vrefresh[ptr->mon_n_hsync].hi =
+ ConfiguredMonitor->det_mon[i].section.ranges.max_v;
+ ptr->mon_n_hsync++;
+ default:
+ break;
+ }
+ }
+
+ if (ConfiguredMonitor->features.dpms) {
+ ptr->mon_option_lst = xf86addNewOption(ptr->mon_option_lst, "DPMS", NULL);
+ }
+
+ return ptr;
+}
+
+void
+DoConfigure()
+{
+ int i,j, screennum = -1;
+ char *home = NULL;
+ char *filename = NULL;
+ XF86ConfigPtr xf86config = NULL;
+ char **vlist, **vl;
+ int *dev2screen;
+
+ vlist = xf86DriverlistFromCompile();
+
+ if (!vlist) {
+ ErrorF("Missing output drivers. Configuration failed.\n");
+ goto bail;
+ }
+
+ ErrorF("List of video drivers:\n");
+ for (vl = vlist; *vl; vl++)
+ ErrorF("\t%s\n", *vl);
+
+#ifdef XFree86LOADER
+ /* Load all the drivers that were found. */
+ xf86LoadModules(vlist, NULL);
+#endif /* XFree86LOADER */
+
+ xfree(vlist);
+
+ for (i = 0; i < xf86NumDrivers; i++) {
+ xorgHWFlags flags;
+ if (!xf86DriverList[i]->driverFunc
+ || !xf86DriverList[i]->driverFunc(NULL,
+ GET_REQUIRED_HW_INTERFACES,
+ &flags)
+ || NEED_IO_ENABLED(flags)) {
+ xorgHWAccess = TRUE;
+ break;
+ }
+ }
+ /* Enable full I/O access */
+ if (xorgHWAccess) {
+ if(!xf86EnableIO())
+ /* oops, we have failed */
+ xorgHWAccess = FALSE;
+ }
+
+ /* Disable PCI devices */
+ xf86ResourceBrokerInit();
+ xf86AccessInit();
+ xf86FindPrimaryDevice();
+
+ /* Create XF86Config file structure */
+ xf86config = malloc(sizeof(XF86ConfigRec));
+ memset ((XF86ConfigPtr)xf86config, 0, sizeof(XF86ConfigRec));
+ xf86config->conf_device_lst = NULL;
+ xf86config->conf_screen_lst = NULL;
+ xf86config->conf_monitor_lst = NULL;
+
+ /* Call all of the probe functions, reporting the results. */
+ for (CurrentDriver = 0; CurrentDriver < xf86NumDrivers; CurrentDriver++) {
+ xorgHWFlags flags;
+
+ if (!xorgHWAccess) {
+ if (!xf86DriverList[CurrentDriver]->driverFunc
+ || !xf86DriverList[CurrentDriver]->driverFunc(NULL,
+ GET_REQUIRED_HW_INTERFACES,
+ &flags)
+ || NEED_IO_ENABLED(flags))
+ continue;
+ }
+
+ if (xf86DriverList[CurrentDriver]->Probe == NULL) continue;
+
+ if ((*xf86DriverList[CurrentDriver]->Probe)(
+ xf86DriverList[CurrentDriver], PROBE_DETECT) &&
+ xf86DriverList[CurrentDriver]->Identify)
+ (*xf86DriverList[CurrentDriver]->Identify)(0);
+ }
+
+ if (nDevToConfig <= 0) {
+ ErrorF("No devices to configure. Configuration failed.\n");
+ goto bail;
+ }
+
+ /* Add device, monitor and screen sections for detected devices */
+ for (screennum = 0; screennum < nDevToConfig; screennum++) {
+ XF86ConfDevicePtr DevicePtr;
+ XF86ConfMonitorPtr MonitorPtr;
+ XF86ConfScreenPtr ScreenPtr;
+
+ DevicePtr = configureDeviceSection(screennum);
+ xf86config->conf_device_lst = (XF86ConfDevicePtr)xf86addListItem(
+ (glp)xf86config->conf_device_lst, (glp)DevicePtr);
+ MonitorPtr = configureMonitorSection(screennum);
+ xf86config->conf_monitor_lst = (XF86ConfMonitorPtr)xf86addListItem(
+ (glp)xf86config->conf_monitor_lst, (glp)MonitorPtr);
+ ScreenPtr = configureScreenSection(screennum);
+ xf86config->conf_screen_lst = (XF86ConfScreenPtr)xf86addListItem(
+ (glp)xf86config->conf_screen_lst, (glp)ScreenPtr);
+ }
+
+ xf86config->conf_files = configureFilesSection();
+ xf86config->conf_modules = configureModuleSection();
+ xf86config->conf_flags = configureFlagsSection();
+ xf86config->conf_videoadaptor_lst = configureVideoAdaptorSection();
+ xf86config->conf_modes_lst = configureModesSection();
+ xf86config->conf_vendor_lst = configureVendorSection();
+ xf86config->conf_dri = configureDRISection();
+ xf86config->conf_input_lst = configureInputSection();
+ xf86config->conf_layout_lst = configureLayoutSection();
+
+ if (!(home = getenv("HOME")))
+ home = "/";
+ {
+#ifdef __UNIXOS2__
+#define PATH_MAX 2048
+#endif
+#if !defined(PATH_MAX)
+#define PATH_MAX 1024
+#endif
+ const char* configfile = XF86CONFIGFILE".new";
+ char homebuf[PATH_MAX];
+ /* getenv might return R/O memory, as with OS/2 */
+ strncpy(homebuf,home,PATH_MAX-1);
+ homebuf[PATH_MAX-1] = '\0';
+ home = homebuf;
+ if (!(filename =
+ (char *)ALLOCATE_LOCAL(strlen(home) +
+ strlen(configfile) + 3)))
+
+ if (home[0] == '/' && home[1] == '\0')
+ home[0] = '\0';
+#ifndef QNX4
+ sprintf(filename, "%s/%s", home,configfile);
+#else
+ sprintf(filename, "//%d%s/%s", getnid(),home,configfile);
+#endif
+
+ }
+
+ xf86writeConfigFile(filename, xf86config);
+
+ xf86DoConfigurePass1 = FALSE;
+ /* Try to get DDC information filled in */
+ xf86ConfigFile = filename;
+ if (xf86HandleConfigFile(FALSE) != CONFIG_OK) {
+ goto bail;
+ }
+
+ xf86DoConfigurePass1 = FALSE;
+
+ dev2screen = xnfcalloc(1,xf86NumDrivers*sizeof(int));
+
+ {
+ Bool *driverProbed = xnfcalloc(1,xf86NumDrivers*sizeof(Bool));
+ for (screennum = 0; screennum < nDevToConfig; screennum++) {
+ int k,l,n,oldNumScreens;
+
+ i = DevToConfig[screennum].iDriver;
+
+ if (driverProbed[i]) continue;
+ driverProbed[i] = TRUE;
+
+ oldNumScreens = xf86NumScreens;
+
+ (*xf86DriverList[i]->Probe)(xf86DriverList[i], 0);
+
+ /* reorder */
+ k = screennum > 0 ? screennum : 1;
+ for (l = oldNumScreens; l < xf86NumScreens; l++) {
+ /* is screen primary? */
+ Bool primary = FALSE;
+ for (n = 0; n<xf86Screens[l]->numEntities; n++) {
+ if (xf86IsEntityPrimary(xf86Screens[l]->entityList[n])) {
+ dev2screen[0] = l;
+ primary = TRUE;
+ break;
+ }
+ }
+ if (primary) continue;
+ /* not primary: assign it to next device of same driver */
+ /*
+ * NOTE: we assume that devices in DevToConfig
+ * and xf86Screens[] have the same order except
+ * for the primary device which always comes first.
+ */
+ for (; k < nDevToConfig; k++) {
+ if (DevToConfig[k].iDriver == i) {
+ dev2screen[k++] = l;
+ break;
+ }
+ }
+ }
+ xf86SetPciVideo(NULL,NONE);
+ }
+ xfree(driverProbed);
+ }
+
+
+ if (nDevToConfig != xf86NumScreens) {
+ ErrorF("Number of created screens does not match number of detected"
+ " devices.\n Configuration failed.\n");
+ goto bail;
+ }
+
+ xf86PostProbe();
+ xf86EntityInit();
+
+ for (j = 0; j < xf86NumScreens; j++) {
+ xf86Screens[j]->scrnIndex = j;
+ }
+
+ xf86freeMonitorList(xf86config->conf_monitor_lst);
+ xf86config->conf_monitor_lst = NULL;
+ xf86freeScreenList(xf86config->conf_screen_lst);
+ xf86config->conf_screen_lst = NULL;
+ for (j = 0; j < xf86NumScreens; j++) {
+ XF86ConfMonitorPtr MonitorPtr;
+ XF86ConfScreenPtr ScreenPtr;
+
+ ConfiguredMonitor = NULL;
+
+ xf86EnableAccess(xf86Screens[dev2screen[j]]);
+ if ((*xf86Screens[dev2screen[j]]->PreInit)(xf86Screens[dev2screen[j]],
+ PROBE_DETECT) &&
+ ConfiguredMonitor) {
+ MonitorPtr = configureDDCMonitorSection(j);
+ } else {
+ MonitorPtr = configureMonitorSection(j);
+ }
+ ScreenPtr = configureScreenSection(j);
+ xf86config->conf_monitor_lst = (XF86ConfMonitorPtr)xf86addListItem(
+ (glp)xf86config->conf_monitor_lst, (glp)MonitorPtr);
+ xf86config->conf_screen_lst = (XF86ConfScreenPtr)xf86addListItem(
+ (glp)xf86config->conf_screen_lst, (glp)ScreenPtr);
+ }
+
+ xf86writeConfigFile(filename, xf86config);
+
+ ErrorF("\n");
+
+#ifdef __SCO__
+ ErrorF("\n"__XSERVERNAME__
+ " is using the kernel event driver to access the mouse.\n"
+ "If you wish to use the internal "__XSERVERNAME__
+ " mouse drivers, please\n"
+ "edit the file and correct the Device.\n");
+#else /* !__SCO__ */
+ if (!foundMouse) {
+ ErrorF("\n"__XSERVERNAME__" is not able to detect your mouse.\n"
+ "Edit the file and correct the Device.\n");
+ } else {
+#ifndef __UNIXOS2__ /* OS/2 definitely has a mouse */
+ ErrorF("\n"__XSERVERNAME__" detected your mouse at device %s.\n"
+ "Please check your config if the mouse is still not\n"
+ "operational, as by default "__XSERVERNAME__
+ " tries to autodetect\n"
+ "the protocol.\n",DFLT_MOUSE_DEV);
+#endif
+ }
+#endif /* !__SCO__ */
+
+ if (xf86NumScreens > 1) {
+ ErrorF("\n"__XSERVERNAME__
+ " has configured a multihead system, please check your config.\n");
+ }
+
+ ErrorF("\nYour %s file is %s\n\n", XF86CONFIGFILE ,filename);
+ ErrorF("To test the server, run 'X -config %s'\n\n", filename);
+
+bail:
+ OsCleanup(TRUE);
+ AbortDDX();
+ fflush(stderr);
+ exit(0);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Cursor.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Cursor.c
new file mode 100644
index 000000000..0e2d77492
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Cursor.c
@@ -0,0 +1,788 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Cursor.c,v 3.37 2003/11/07 22:20:17 dawes Exp $ */
+/*
+ * Copyright (c) 1994-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).
+ */
+
+/* $XConsortium: xf86Cursor.c /main/10 1996/10/19 17:58:23 kaleb $ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "cursor.h"
+#include "mipointer.h"
+#include "scrnintstr.h"
+#include "globals.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSproc.h"
+
+#ifdef XINPUT
+#include <X11/extensions/XIproto.h>
+#include "xf86Xinput.h"
+#endif
+
+#ifdef XFreeXDGA
+#include "dgaproc.h"
+#endif
+
+typedef struct _xf86EdgeRec {
+ short screen;
+ short start;
+ short end;
+ DDXPointRec offset;
+ struct _xf86EdgeRec *next;
+} xf86EdgeRec, *xf86EdgePtr;
+
+typedef struct {
+ xf86EdgePtr left, right, up, down;
+} xf86ScreenLayoutRec, *xf86ScreenLayoutPtr;
+
+static Bool xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y);
+static void xf86CrossScreen(ScreenPtr pScreen, Bool entering);
+static void xf86WarpCursor(ScreenPtr pScreen, int x, int y);
+
+static void xf86PointerMoved(int scrnIndex, int x, int y);
+
+static miPointerScreenFuncRec xf86PointerScreenFuncs = {
+ xf86CursorOffScreen,
+ xf86CrossScreen,
+ xf86WarpCursor,
+#ifdef XINPUT
+ xf86eqEnqueue,
+ xf86eqSwitchScreen
+#else
+ /* let miPointerInitialize take care of these */
+ NULL,
+ NULL
+#endif
+};
+
+static xf86ScreenLayoutRec xf86ScreenLayout[MAXSCREENS];
+
+static Bool HardEdges;
+
+/*
+ * xf86InitViewport --
+ * Initialize paning & zooming parameters, so that a driver must only
+ * check what resolutions are possible and whether the virtual area
+ * is valid if specified.
+ */
+
+void
+xf86InitViewport(ScrnInfoPtr pScr)
+{
+
+ pScr->PointerMoved = xf86PointerMoved;
+
+ /*
+ * Compute the initial Viewport if necessary
+ */
+ if (pScr->display) {
+ if (pScr->display->frameX0 < 0) {
+ pScr->frameX0 = (pScr->virtualX - pScr->modes->HDisplay) / 2;
+ pScr->frameY0 = (pScr->virtualY - pScr->modes->VDisplay) / 2;
+ } else {
+ pScr->frameX0 = pScr->display->frameX0;
+ pScr->frameY0 = pScr->display->frameY0;
+ }
+ }
+
+ pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
+ pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
+
+ /*
+ * Now adjust the initial Viewport, so it lies within the virtual area
+ */
+ if (pScr->frameX1 >= pScr->virtualX)
+ {
+ pScr->frameX0 = pScr->virtualX - pScr->modes->HDisplay;
+ pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
+ }
+
+ if (pScr->frameY1 >= pScr->virtualY)
+ {
+ pScr->frameY0 = pScr->virtualY - pScr->modes->VDisplay;
+ pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
+ }
+}
+
+
+/*
+ * xf86SetViewport --
+ * Scroll the visual part of the screen so the pointer is visible.
+ */
+
+void
+xf86SetViewport(ScreenPtr pScreen, int x, int y)
+{
+ ScrnInfoPtr pScr = XF86SCRNINFO(pScreen);
+
+ (*pScr->PointerMoved)(pScreen->myNum, x, y);
+}
+
+
+static void
+xf86PointerMoved(int scrnIndex, int x, int y)
+{
+ Bool frameChanged = FALSE;
+ ScrnInfoPtr pScr = xf86Screens[scrnIndex];
+
+ /*
+ * check wether (x,y) belongs to the visual part of the screen
+ * if not, change the base of the displayed frame accoring
+ */
+ if ( pScr->frameX0 > x) {
+ pScr->frameX0 = x;
+ pScr->frameX1 = x + pScr->currentMode->HDisplay - 1;
+ frameChanged = TRUE ;
+ }
+
+ if ( pScr->frameX1 < x) {
+ pScr->frameX1 = x + 1;
+ pScr->frameX0 = x - pScr->currentMode->HDisplay + 1;
+ frameChanged = TRUE ;
+ }
+
+ if ( pScr->frameY0 > y) {
+ pScr->frameY0 = y;
+ pScr->frameY1 = y + pScr->currentMode->VDisplay - 1;
+ frameChanged = TRUE;
+ }
+
+ if ( pScr->frameY1 < y) {
+ pScr->frameY1 = y;
+ pScr->frameY0 = y - pScr->currentMode->VDisplay + 1;
+ frameChanged = TRUE;
+ }
+
+ if (frameChanged && pScr->AdjustFrame != NULL)
+ pScr->AdjustFrame(pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0);
+}
+
+/*
+ * xf86LockZoom --
+ * Enable/disable ZoomViewport
+ */
+
+void
+xf86LockZoom(ScreenPtr pScreen, Bool lock)
+{
+ XF86SCRNINFO(pScreen)->zoomLocked = lock;
+}
+
+/*
+ * xf86SwitchMode --
+ * This is called by both keyboard processing and the VidMode extension to
+ * set a new mode.
+ */
+
+Bool
+xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode)
+{
+ ScrnInfoPtr pScr = XF86SCRNINFO(pScreen);
+ ScreenPtr pCursorScreen;
+ Bool Switched;
+ int px, py;
+
+ if (!pScr->vtSema || !mode || !pScr->SwitchMode)
+ return FALSE;
+
+#ifdef XFreeXDGA
+ if (DGAActive(pScr->scrnIndex))
+ return FALSE;
+#endif
+
+ if (mode == pScr->currentMode)
+ return TRUE;
+
+ if (mode->HDisplay > pScr->virtualX || mode->VDisplay > pScr->virtualY)
+ return FALSE;
+
+ pCursorScreen = miPointerCurrentScreen();
+ if (pScreen == pCursorScreen)
+ miPointerPosition(&px, &py);
+
+ xf86EnterServerState(SETUP);
+ Switched = (*pScr->SwitchMode)(pScr->scrnIndex, mode, 0);
+ xf86EnterServerState(OPERATING);
+ if (Switched) {
+ pScr->currentMode = mode;
+
+ /*
+ * Adjust frame for new display size.
+ */
+ if (pScreen == pCursorScreen)
+ pScr->frameX0 = px - (mode->HDisplay / 2) + 1;
+ else
+ pScr->frameX0 = (pScr->frameX0 + pScr->frameX1 + 1 - mode->HDisplay) / 2;
+
+ if (pScr->frameX0 < 0)
+ pScr->frameX0 = 0;
+
+ pScr->frameX1 = pScr->frameX0 + mode->HDisplay - 1;
+ if (pScr->frameX1 >= pScr->virtualX) {
+ pScr->frameX0 = pScr->virtualX - mode->HDisplay;
+ pScr->frameX1 = pScr->virtualX - 1;
+ }
+
+ if (pScreen == pCursorScreen)
+ pScr->frameY0 = py - (mode->VDisplay / 2) + 1;
+ else
+ pScr->frameY0 = (pScr->frameY0 + pScr->frameY1 + 1 - mode->VDisplay) / 2;
+
+ if (pScr->frameY0 < 0)
+ pScr->frameY0 = 0;
+
+ pScr->frameY1 = pScr->frameY0 + mode->VDisplay - 1;
+ if (pScr->frameY1 >= pScr->virtualY) {
+ pScr->frameY0 = pScr->virtualY - mode->VDisplay;
+ pScr->frameY1 = pScr->virtualY - 1;
+ }
+ }
+
+ if (pScr->AdjustFrame)
+ (*pScr->AdjustFrame)(pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0);
+
+ if (pScreen == pCursorScreen)
+ xf86WarpCursor(pScreen, px, py);
+
+ return Switched;
+}
+
+/*
+ * xf86ZoomViewport --
+ * Reinitialize the visual part of the screen for another mode.
+ */
+
+void
+xf86ZoomViewport(ScreenPtr pScreen, int zoom)
+{
+ ScrnInfoPtr pScr = XF86SCRNINFO(pScreen);
+ DisplayModePtr mode;
+
+ if (pScr->zoomLocked || !(mode = pScr->currentMode))
+ return;
+
+ do {
+ if (zoom > 0)
+ mode = mode->next;
+ else
+ mode = mode->prev;
+ } while (mode != pScr->currentMode && !(mode->type & M_T_USERDEF));
+
+ (void)xf86SwitchMode(pScreen, mode);
+}
+
+
+static xf86EdgePtr
+FindEdge(xf86EdgePtr edge, int val)
+{
+ while(edge && (edge->end <= val))
+ edge = edge->next;
+
+ if(edge && (edge->start <= val))
+ return edge;
+
+ return NULL;
+}
+
+/*
+ * xf86CursorOffScreen --
+ * Check whether it is necessary to switch to another screen
+ */
+
+static Bool
+xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y)
+{
+ xf86EdgePtr edge;
+ int tmp;
+
+ if(screenInfo.numScreens == 1)
+ return FALSE;
+
+ if(*x < 0) {
+ tmp = *y;
+ if(tmp < 0) tmp = 0;
+ if(tmp >= (*pScreen)->height) tmp = (*pScreen)->height - 1;
+
+ if((edge = xf86ScreenLayout[(*pScreen)->myNum].left))
+ edge = FindEdge(edge, tmp);
+
+ if(!edge) *x = 0;
+ else {
+ *x += edge->offset.x;
+ *y += edge->offset.y;
+ *pScreen = xf86Screens[edge->screen]->pScreen;
+ }
+ }
+
+ if(*x >= (*pScreen)->width) {
+ tmp = *y;
+ if(tmp < 0) tmp = 0;
+ if(tmp >= (*pScreen)->height) tmp = (*pScreen)->height - 1;
+
+ if((edge = xf86ScreenLayout[(*pScreen)->myNum].right))
+ edge = FindEdge(edge, tmp);
+
+ if(!edge) *x = (*pScreen)->width - 1;
+ else {
+ *x += edge->offset.x;
+ *y += edge->offset.y;
+ *pScreen = xf86Screens[edge->screen]->pScreen;
+ }
+ }
+
+ if(*y < 0) {
+ tmp = *x;
+ if(tmp < 0) tmp = 0;
+ if(tmp >= (*pScreen)->width) tmp = (*pScreen)->width - 1;
+
+ if((edge = xf86ScreenLayout[(*pScreen)->myNum].up))
+ edge = FindEdge(edge, tmp);
+
+ if(!edge) *y = 0;
+ else {
+ *x += edge->offset.x;
+ *y += edge->offset.y;
+ *pScreen = xf86Screens[edge->screen]->pScreen;
+ }
+ }
+
+ if(*y >= (*pScreen)->height) {
+ tmp = *x;
+ if(tmp < 0) tmp = 0;
+ if(tmp >= (*pScreen)->width) tmp = (*pScreen)->width - 1;
+
+ if((edge = xf86ScreenLayout[(*pScreen)->myNum].down))
+ edge = FindEdge(edge, tmp);
+
+ if(!edge) *y = (*pScreen)->height - 1;
+ else {
+ *x += edge->offset.x;
+ *y += edge->offset.y;
+ (*pScreen) = xf86Screens[edge->screen]->pScreen;
+ }
+ }
+
+
+#if 0
+ /* This presents problems for overlapping screens when
+ HardEdges is used. Have to think about the logic more */
+ if((*x < 0) || (*x >= (*pScreen)->width) ||
+ (*y < 0) || (*y >= (*pScreen)->height)) {
+ /* We may have crossed more than one screen */
+ xf86CursorOffScreen(pScreen, x, y);
+ }
+#endif
+
+ return TRUE;
+}
+
+
+
+/*
+ * xf86CrossScreen --
+ * Switch to another screen
+ */
+
+/* NEED TO CHECK THIS */
+/* ARGSUSED */
+static void
+xf86CrossScreen (ScreenPtr pScreen, Bool entering)
+{
+#if 0
+ if (xf86Info.sharedMonitor)
+ (XF86SCRNINFO(pScreen)->EnterLeaveMonitor)(entering);
+ (XF86SCRNINFO(pScreen)->EnterLeaveCursor)(entering);
+#endif
+}
+
+
+/*
+ * xf86WarpCursor --
+ * Warp possible to another screen
+ */
+
+/* ARGSUSED */
+static void
+xf86WarpCursor (ScreenPtr pScreen, int x, int y)
+{
+ int sigstate;
+ sigstate = xf86BlockSIGIO ();
+ miPointerWarpCursor(pScreen,x,y);
+
+ xf86Info.currentScreen = pScreen;
+ xf86UnblockSIGIO (sigstate);
+}
+
+
+void *
+xf86GetPointerScreenFuncs(void)
+{
+ return (void *)&xf86PointerScreenFuncs;
+}
+
+
+static xf86EdgePtr
+AddEdge(
+ xf86EdgePtr edge,
+ short min,
+ short max,
+ short dx,
+ short dy,
+ short screen
+){
+ xf86EdgePtr pEdge = edge, pPrev = NULL, pNew;
+
+ while(1) {
+ while(pEdge && (min >= pEdge->end)) {
+ pPrev = pEdge;
+ pEdge = pEdge->next;
+ }
+
+ if(!pEdge) {
+ if(!(pNew = xalloc(sizeof(xf86EdgeRec))))
+ break;
+
+ pNew->screen = screen;
+ pNew->start = min;
+ pNew->end = max;
+ pNew->offset.x = dx;
+ pNew->offset.y = dy;
+ pNew->next = NULL;
+
+ if(pPrev)
+ pPrev->next = pNew;
+ else
+ edge = pNew;
+
+ break;
+ } else if (min < pEdge->start) {
+ if(!(pNew = xalloc(sizeof(xf86EdgeRec))))
+ break;
+
+ pNew->screen = screen;
+ pNew->start = min;
+ pNew->offset.x = dx;
+ pNew->offset.y = dy;
+ pNew->next = pEdge;
+
+ if(pPrev) pPrev->next = pNew;
+ else edge = pNew;
+
+ if(max <= pEdge->start) {
+ pNew->end = max;
+ break;
+ } else {
+ pNew->end = pEdge->start;
+ min = pEdge->end;
+ }
+ } else
+ min = pEdge->end;
+
+ pPrev = pEdge;
+ pEdge = pEdge->next;
+
+ if(max <= min) break;
+ }
+
+ return edge;
+}
+
+static void
+FillOutEdge(xf86EdgePtr pEdge, int limit)
+{
+ xf86EdgePtr pNext;
+ int diff;
+
+ if(pEdge->start > 0) pEdge->start = 0;
+
+ while((pNext = pEdge->next)) {
+ diff = pNext->start - pEdge->end;
+ if(diff > 0) {
+ pEdge->end += diff >> 1;
+ pNext->start -= diff - (diff >> 1);
+ }
+ pEdge = pNext;
+ }
+
+ if(pEdge->end < limit)
+ pEdge->end = limit;
+}
+
+/*
+ * xf86InitOrigins() can deal with a maximum of 32 screens
+ * on 32 bit architectures, 64 on 64 bit architectures.
+ */
+
+void
+xf86InitOrigins(void)
+{
+ unsigned long screensLeft, prevScreensLeft, mask;
+ screenLayoutPtr screen;
+ ScreenPtr pScreen;
+ int x1, x2, y1, y2, left, right, top, bottom;
+ int i, j, ref, minX, minY, min, max;
+ xf86ScreenLayoutPtr pLayout;
+ Bool OldStyleConfig = FALSE;
+
+ /* need to have this set up with a config file option */
+ HardEdges = FALSE;
+
+ bzero(xf86ScreenLayout, MAXSCREENS * sizeof(xf86ScreenLayoutRec));
+
+ screensLeft = prevScreensLeft = (1 << xf86NumScreens) - 1;
+
+ while(1) {
+ for(mask = screensLeft, i = 0; mask; mask >>= 1, i++) {
+ if(!(mask & 1L)) continue;
+
+ screen = &xf86ConfigLayout.screens[i];
+
+ switch(screen->where) {
+ case PosObsolete:
+ OldStyleConfig = TRUE;
+ pLayout = &xf86ScreenLayout[i];
+ /* force edge lists */
+ if(screen->left) {
+ ref = screen->left->screennum;
+ pLayout->left = AddEdge(pLayout->left,
+ 0, xf86Screens[i]->pScreen->height,
+ xf86Screens[ref]->pScreen->width, 0, ref);
+ }
+ if(screen->right) {
+ ref = screen->right->screennum;
+ pScreen = xf86Screens[i]->pScreen;
+ pLayout->right = AddEdge(pLayout->right,
+ 0, pScreen->height, -pScreen->width, 0, ref);
+ }
+ if(screen->top) {
+ ref = screen->top->screennum;
+ pLayout->up = AddEdge(pLayout->up,
+ 0, xf86Screens[i]->pScreen->width,
+ 0, xf86Screens[ref]->pScreen->height, ref);
+ }
+ if(screen->bottom) {
+ ref = screen->bottom->screennum;
+ pScreen = xf86Screens[i]->pScreen;
+ pLayout->down = AddEdge(pLayout->down,
+ 0, pScreen->width, 0, -pScreen->height, ref);
+ }
+ /* we could also try to place it based on those
+ relative locations if we wanted to */
+ screen->x = screen->y = 0;
+ /* FALLTHROUGH */
+ case PosAbsolute:
+ dixScreenOrigins[i].x = screen->x;
+ dixScreenOrigins[i].y = screen->y;
+ screensLeft &= ~(1 << i);
+ break;
+ case PosRelative:
+ ref = screen->refscreen->screennum;
+ if(screensLeft & (1 << ref)) break;
+ dixScreenOrigins[i].x = dixScreenOrigins[ref].x + screen->x;
+ dixScreenOrigins[i].y = dixScreenOrigins[ref].y + screen->y;
+ screensLeft &= ~(1 << i);
+ break;
+ case PosRightOf:
+ ref = screen->refscreen->screennum;
+ if(screensLeft & (1 << ref)) break;
+ pScreen = xf86Screens[ref]->pScreen;
+ dixScreenOrigins[i].x =
+ dixScreenOrigins[ref].x + pScreen->width;
+ dixScreenOrigins[i].y = dixScreenOrigins[ref].y;
+ screensLeft &= ~(1 << i);
+ break;
+ case PosLeftOf:
+ ref = screen->refscreen->screennum;
+ if(screensLeft & (1 << ref)) break;
+ pScreen = xf86Screens[i]->pScreen;
+ dixScreenOrigins[i].x =
+ dixScreenOrigins[ref].x - pScreen->width;
+ dixScreenOrigins[i].y = dixScreenOrigins[ref].y;
+ screensLeft &= ~(1 << i);
+ break;
+ case PosBelow:
+ ref = screen->refscreen->screennum;
+ if(screensLeft & (1 << ref)) break;
+ pScreen = xf86Screens[ref]->pScreen;
+ dixScreenOrigins[i].x = dixScreenOrigins[ref].x;
+ dixScreenOrigins[i].y =
+ dixScreenOrigins[ref].y + pScreen->height;
+ screensLeft &= ~(1 << i);
+ break;
+ case PosAbove:
+ ref = screen->refscreen->screennum;
+ if(screensLeft & (1 << ref)) break;
+ pScreen = xf86Screens[i]->pScreen;
+ dixScreenOrigins[i].x = dixScreenOrigins[ref].x;
+ dixScreenOrigins[i].y =
+ dixScreenOrigins[ref].y - pScreen->height;
+ screensLeft &= ~(1 << i);
+ break;
+ default:
+ ErrorF("Illegal placement keyword in Layout!\n");
+ break;
+ }
+
+ }
+
+ if(!screensLeft) break;
+
+ if(screensLeft == prevScreensLeft) {
+ /* All the remaining screens are referencing each other.
+ Assign a value to one of them and go through again */
+ i = 0;
+ while(!((1 << i) & screensLeft)){ i++; }
+
+ ref = xf86ConfigLayout.screens[i].refscreen->screennum;
+ dixScreenOrigins[ref].x = dixScreenOrigins[ref].y = 0;
+ screensLeft &= ~(1 << ref);
+ }
+
+ prevScreensLeft = screensLeft;
+ }
+
+ /* justify the topmost and leftmost to (0,0) */
+ minX = dixScreenOrigins[0].x;
+ minY = dixScreenOrigins[0].y;
+
+ for(i = 1; i < xf86NumScreens; i++) {
+ if(dixScreenOrigins[i].x < minX)
+ minX = dixScreenOrigins[i].x;
+ if(dixScreenOrigins[i].y < minY)
+ minY = dixScreenOrigins[i].y;
+ }
+
+ if (minX || minY) {
+ for(i = 0; i < xf86NumScreens; i++) {
+ dixScreenOrigins[i].x -= minX;
+ dixScreenOrigins[i].y -= minY;
+ }
+ }
+
+
+ /* Create the edge lists */
+
+ if(!OldStyleConfig) {
+ for(i = 0; i < xf86NumScreens; i++) {
+ pLayout = &xf86ScreenLayout[i];
+
+ pScreen = xf86Screens[i]->pScreen;
+
+ left = dixScreenOrigins[i].x;
+ right = left + pScreen->width;
+ top = dixScreenOrigins[i].y;
+ bottom = top + pScreen->height;
+
+ for(j = 0; j < xf86NumScreens; j++) {
+ if(i == j) continue;
+
+ x1 = dixScreenOrigins[j].x;
+ x2 = x1 + xf86Screens[j]->pScreen->width;
+ y1 = dixScreenOrigins[j].y;
+ y2 = y1 + xf86Screens[j]->pScreen->height;
+
+ if((bottom > y1) && (top < y2)) {
+ min = y1 - top;
+ if(min < 0) min = 0;
+ max = pScreen->height - (bottom - y2);
+ if(max > pScreen->height) max = pScreen->height;
+
+ if(((left - 1) >= x1) && ((left - 1) < x2))
+ pLayout->left = AddEdge(pLayout->left, min, max,
+ dixScreenOrigins[i].x - dixScreenOrigins[j].x,
+ dixScreenOrigins[i].y - dixScreenOrigins[j].y, j);
+
+ if((right >= x1) && (right < x2))
+ pLayout->right = AddEdge(pLayout->right, min, max,
+ dixScreenOrigins[i].x - dixScreenOrigins[j].x,
+ dixScreenOrigins[i].y - dixScreenOrigins[j].y, j);
+ }
+
+
+ if((left < x2) && (right > x1)) {
+ min = x1 - left;
+ if(min < 0) min = 0;
+ max = pScreen->width - (right - x2);
+ if(max > pScreen->width) max = pScreen->width;
+
+ if(((top - 1) >= y1) && ((top - 1) < y2))
+ pLayout->up = AddEdge(pLayout->up, min, max,
+ dixScreenOrigins[i].x - dixScreenOrigins[j].x,
+ dixScreenOrigins[i].y - dixScreenOrigins[j].y, j);
+
+ if((bottom >= y1) && (bottom < y2))
+ pLayout->down = AddEdge(pLayout->down, min, max,
+ dixScreenOrigins[i].x - dixScreenOrigins[j].x,
+ dixScreenOrigins[i].y - dixScreenOrigins[j].y, j);
+ }
+ }
+ }
+ }
+
+ if(!HardEdges && !OldStyleConfig) {
+ for(i = 0; i < xf86NumScreens; i++) {
+ pLayout = &xf86ScreenLayout[i];
+ pScreen = xf86Screens[i]->pScreen;
+ if(pLayout->left)
+ FillOutEdge(pLayout->left, pScreen->height);
+ if(pLayout->right)
+ FillOutEdge(pLayout->right, pScreen->height);
+ if(pLayout->up)
+ FillOutEdge(pLayout->up, pScreen->width);
+ if(pLayout->down)
+ FillOutEdge(pLayout->down, pScreen->width);
+ }
+ }
+}
+
+void
+xf86ReconfigureLayout(void)
+{
+ int i;
+
+ for (i = 0; i < MAXSCREENS; i++) {
+ xf86ScreenLayoutPtr sl = &xf86ScreenLayout[i];
+ /* we don't have to zero these, xf86InitOrigins() takes care of that */
+ if (sl->left) xfree(sl->left);
+ if (sl->right) xfree(sl->right);
+ if (sl->up) xfree(sl->up);
+ if (sl->down) xfree(sl->down);
+ }
+
+ xf86InitOrigins();
+}
+
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86DGA.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DGA.c
new file mode 100644
index 000000000..a213e39e2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DGA.c
@@ -0,0 +1,1267 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86DGA.c,v 1.7 2005/11/08 03:12:43 alanc Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86DGA.c,v 1.46 2002/12/03 18:17:40 tsi Exp $ */
+/*
+ * Copyright (c) 1998-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).
+ *
+ * Written by Mark Vojkovich
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86str.h"
+#include "xf86Priv.h"
+#include "dgaproc.h"
+#include <X11/extensions/xf86dgastr.h>
+#include "colormapst.h"
+#include "pixmapstr.h"
+#include "inputstr.h"
+#include "globals.h"
+#include "servermd.h"
+#include "micmap.h"
+#ifdef XKB
+#include <X11/extensions/XKBsrv.h>
+#endif
+#include "xf86Xinput.h"
+
+static unsigned long DGAGeneration = 0;
+static int DGAScreenIndex = -1;
+
+static Bool DGACloseScreen(int i, ScreenPtr pScreen);
+static void DGADestroyColormap(ColormapPtr pmap);
+static void DGAInstallColormap(ColormapPtr pmap);
+static void DGAUninstallColormap(ColormapPtr pmap);
+
+static void
+DGACopyModeInfo(
+ DGAModePtr mode,
+ XDGAModePtr xmode
+);
+
+#if defined(XFree86LOADER) || !defined(XFreeXDGA)
+int *XDGAEventBase = NULL;
+#else
+int *XDGAEventBase = &DGAEventBase;
+#endif
+
+#define DGA_GET_SCREEN_PRIV(pScreen) \
+ ((DGAScreenPtr)((pScreen)->devPrivates[DGAScreenIndex].ptr))
+
+
+typedef struct _FakedVisualList{
+ Bool free;
+ VisualPtr pVisual;
+ struct _FakedVisualList *next;
+} FakedVisualList;
+
+
+typedef struct {
+ ScrnInfoPtr pScrn;
+ int numModes;
+ DGAModePtr modes;
+ CloseScreenProcPtr CloseScreen;
+ DestroyColormapProcPtr DestroyColormap;
+ InstallColormapProcPtr InstallColormap;
+ UninstallColormapProcPtr UninstallColormap;
+ DGADevicePtr current;
+ DGAFunctionPtr funcs;
+ int input;
+ ClientPtr client;
+ int pixmapMode;
+ FakedVisualList *fakedVisuals;
+ ColormapPtr dgaColormap;
+ ColormapPtr savedColormap;
+ Bool grabMouse;
+ Bool grabKeyboard;
+} DGAScreenRec, *DGAScreenPtr;
+
+
+Bool
+DGAInit(
+ ScreenPtr pScreen,
+ DGAFunctionPtr funcs,
+ DGAModePtr modes,
+ int num
+){
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ DGAScreenPtr pScreenPriv;
+ int i;
+
+ if(!funcs || !funcs->SetMode || !funcs->OpenFramebuffer)
+ return FALSE;
+
+ if(!modes || num <= 0)
+ return FALSE;
+
+ if(DGAGeneration != serverGeneration) {
+ if((DGAScreenIndex = AllocateScreenPrivateIndex()) < 0)
+ return FALSE;
+ DGAGeneration = serverGeneration;
+ }
+
+ if(!(pScreenPriv = (DGAScreenPtr)xalloc(sizeof(DGAScreenRec))))
+ return FALSE;
+
+ pScreenPriv->pScrn = pScrn;
+ pScreenPriv->numModes = num;
+ pScreenPriv->modes = modes;
+ pScreenPriv->current = NULL;
+
+ pScreenPriv->funcs = funcs;
+ pScreenPriv->input = 0;
+ pScreenPriv->client = NULL;
+ pScreenPriv->fakedVisuals = NULL;
+ pScreenPriv->dgaColormap = NULL;
+ pScreenPriv->savedColormap = NULL;
+ pScreenPriv->grabMouse = FALSE;
+ pScreenPriv->grabKeyboard = FALSE;
+
+ for(i = 0; i < num; i++)
+ modes[i].num = i + 1;
+
+#ifdef PANORAMIX
+ if(!noPanoramiXExtension)
+ for(i = 0; i < num; i++)
+ modes[i].flags &= ~DGA_PIXMAP_AVAILABLE;
+#endif
+
+
+ pScreen->devPrivates[DGAScreenIndex].ptr = (pointer)pScreenPriv;
+ pScreenPriv->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = DGACloseScreen;
+ pScreenPriv->DestroyColormap = pScreen->DestroyColormap;
+ pScreen->DestroyColormap = DGADestroyColormap;
+ pScreenPriv->InstallColormap = pScreen->InstallColormap;
+ pScreen->InstallColormap = DGAInstallColormap;
+ pScreenPriv->UninstallColormap = pScreen->UninstallColormap;
+ pScreen->UninstallColormap = DGAUninstallColormap;
+
+ /*
+ * This is now set in InitOutput().
+ *
+ pScrn->SetDGAMode = xf86SetDGAMode;
+ */
+
+ return TRUE;
+}
+
+/* DGAReInitModes allows the driver to re-initialize
+ * the DGA mode list.
+ */
+
+Bool
+DGAReInitModes(
+ ScreenPtr pScreen,
+ DGAModePtr modes,
+ int num
+){
+ DGAScreenPtr pScreenPriv;
+ int i;
+
+ /* No DGA? Ignore call (but don't make it look like it failed) */
+ if(DGAScreenIndex < 0)
+ return TRUE;
+
+ pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+
+ /* Same as above */
+ if(!pScreenPriv)
+ return TRUE;
+
+ /* Can't do this while DGA is active */
+ if(pScreenPriv->current)
+ return FALSE;
+
+ /* Quick sanity check */
+ if(!num)
+ modes = NULL;
+ else if(!modes)
+ num = 0;
+
+ pScreenPriv->numModes = num;
+ pScreenPriv->modes = modes;
+
+ /* This practically disables DGA. So be it. */
+ if(!num)
+ return TRUE;
+
+ for(i = 0; i < num; i++)
+ modes[i].num = i + 1;
+
+#ifdef PANORAMIX
+ if(!noPanoramiXExtension)
+ for(i = 0; i < num; i++)
+ modes[i].flags &= ~DGA_PIXMAP_AVAILABLE;
+#endif
+
+ return TRUE;
+}
+
+static void
+FreeMarkedVisuals(ScreenPtr pScreen)
+{
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+ FakedVisualList *prev, *curr, *tmp;
+
+ if(!pScreenPriv->fakedVisuals)
+ return;
+
+ prev = NULL;
+ curr = pScreenPriv->fakedVisuals;
+
+ while(curr) {
+ if(curr->free) {
+ tmp = curr;
+ curr = curr->next;
+ if(prev)
+ prev->next = curr;
+ else
+ pScreenPriv->fakedVisuals = curr;
+ xfree(tmp->pVisual);
+ xfree(tmp);
+ } else {
+ prev = curr;
+ curr = curr->next;
+ }
+ }
+}
+
+
+static Bool
+DGACloseScreen(int i, ScreenPtr pScreen)
+{
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+
+ FreeMarkedVisuals(pScreen);
+
+ pScreen->CloseScreen = pScreenPriv->CloseScreen;
+ pScreen->DestroyColormap = pScreenPriv->DestroyColormap;
+ pScreen->InstallColormap = pScreenPriv->InstallColormap;
+ pScreen->UninstallColormap = pScreenPriv->UninstallColormap;
+
+ /* DGAShutdown() should have ensured that no DGA
+ screen were active by here */
+
+ xfree(pScreenPriv);
+
+ return((*pScreen->CloseScreen)(i, pScreen));
+}
+
+
+static void
+DGADestroyColormap(ColormapPtr pmap)
+{
+ ScreenPtr pScreen = pmap->pScreen;
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+ VisualPtr pVisual = pmap->pVisual;
+
+ if(pScreenPriv->fakedVisuals) {
+ FakedVisualList *curr = pScreenPriv->fakedVisuals;
+
+ while(curr) {
+ if(curr->pVisual == pVisual) {
+ /* We can't get rid of them yet since FreeColormap
+ still needs the pVisual during the cleanup */
+ curr->free = TRUE;
+ break;
+ }
+ curr = curr->next;
+ }
+ }
+
+ if(pScreenPriv->DestroyColormap) {
+ pScreen->DestroyColormap = pScreenPriv->DestroyColormap;
+ (*pScreen->DestroyColormap)(pmap);
+ pScreen->DestroyColormap = DGADestroyColormap;
+ }
+}
+
+
+static void
+DGAInstallColormap(ColormapPtr pmap)
+{
+ ScreenPtr pScreen = pmap->pScreen;
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+
+ if(pScreenPriv->current && pScreenPriv->dgaColormap) {
+ if (pmap != pScreenPriv->dgaColormap) {
+ pScreenPriv->savedColormap = pmap;
+ pmap = pScreenPriv->dgaColormap;
+ }
+ }
+
+ pScreen->InstallColormap = pScreenPriv->InstallColormap;
+ (*pScreen->InstallColormap)(pmap);
+ pScreen->InstallColormap = DGAInstallColormap;
+}
+
+static void
+DGAUninstallColormap(ColormapPtr pmap)
+{
+ ScreenPtr pScreen = pmap->pScreen;
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+
+ if(pScreenPriv->current && pScreenPriv->dgaColormap) {
+ if (pmap == pScreenPriv->dgaColormap) {
+ pScreenPriv->dgaColormap = NULL;
+ }
+ }
+
+ pScreen->UninstallColormap = pScreenPriv->UninstallColormap;
+ (*pScreen->UninstallColormap)(pmap);
+ pScreen->UninstallColormap = DGAUninstallColormap;
+}
+
+int
+xf86SetDGAMode(
+ int index,
+ int num,
+ DGADevicePtr devRet
+){
+ ScreenPtr pScreen = screenInfo.screens[index];
+ DGAScreenPtr pScreenPriv;
+ ScrnInfoPtr pScrn;
+ DGADevicePtr device;
+ PixmapPtr pPix = NULL;
+ DGAModePtr pMode = NULL;
+
+ /* First check if DGAInit was successful on this screen */
+ if (DGAScreenIndex < 0)
+ return BadValue;
+ pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+ if (!pScreenPriv)
+ return BadValue;
+ pScrn = pScreenPriv->pScrn;
+
+ if(!num) {
+ if(pScreenPriv->current) {
+ PixmapPtr oldPix = pScreenPriv->current->pPix;
+ if(oldPix) {
+ if(oldPix->drawable.id)
+ FreeResource(oldPix->drawable.id, RT_NONE);
+ else
+ (*pScreen->DestroyPixmap)(oldPix);
+ }
+ xfree(pScreenPriv->current);
+ pScreenPriv->current = NULL;
+ pScrn->vtSema = TRUE;
+ (*pScreenPriv->funcs->SetMode)(pScrn, NULL);
+ if(pScreenPriv->savedColormap) {
+ (*pScreen->InstallColormap)(pScreenPriv->savedColormap);
+ pScreenPriv->savedColormap = NULL;
+ }
+ pScreenPriv->dgaColormap = NULL;
+ (*pScrn->EnableDisableFBAccess)(index, TRUE);
+
+ FreeMarkedVisuals(pScreen);
+ }
+
+ pScreenPriv->grabMouse = FALSE;
+ pScreenPriv->grabKeyboard = FALSE;
+
+ return Success;
+ }
+
+ if(!pScrn->vtSema && !pScreenPriv->current) /* Really switched away */
+ return BadAlloc;
+
+ if((num > 0) && (num <= pScreenPriv->numModes))
+ pMode = &(pScreenPriv->modes[num - 1]);
+ else
+ return BadValue;
+
+ if(!(device = (DGADevicePtr)xalloc(sizeof(DGADeviceRec))))
+ return BadAlloc;
+
+ if(!pScreenPriv->current) {
+ Bool oldVTSema = pScrn->vtSema;
+
+ pScrn->vtSema = FALSE; /* kludge until we rewrite VT switching */
+ (*pScrn->EnableDisableFBAccess)(index, FALSE);
+ pScrn->vtSema = oldVTSema;
+ }
+
+ if(!(*pScreenPriv->funcs->SetMode)(pScrn, pMode)) {
+ xfree(device);
+ return BadAlloc;
+ }
+
+ pScrn->currentMode = pMode->mode;
+
+ if(!pScreenPriv->current && !pScreenPriv->input) {
+ /* if it's multihead we need to warp the cursor off of
+ our screen so it doesn't get trapped */
+ }
+
+ pScrn->vtSema = FALSE;
+
+ if(pScreenPriv->current) {
+ PixmapPtr oldPix = pScreenPriv->current->pPix;
+ if(oldPix) {
+ if(oldPix->drawable.id)
+ FreeResource(oldPix->drawable.id, RT_NONE);
+ else
+ (*pScreen->DestroyPixmap)(oldPix);
+ }
+ xfree(pScreenPriv->current);
+ pScreenPriv->current = NULL;
+ }
+
+ if(pMode->flags & DGA_PIXMAP_AVAILABLE) {
+ if((pPix = (*pScreen->CreatePixmap)(pScreen, 0, 0, pMode->depth))) {
+ (*pScreen->ModifyPixmapHeader)(pPix,
+ pMode->pixmapWidth, pMode->pixmapHeight,
+ pMode->depth, pMode->bitsPerPixel,
+ pMode->bytesPerScanline,
+ (pointer)(pMode->address));
+ }
+ }
+
+ devRet->mode = device->mode = pMode;
+ devRet->pPix = device->pPix = pPix;
+ pScreenPriv->current = device;
+ pScreenPriv->pixmapMode = FALSE;
+ pScreenPriv->grabMouse = TRUE;
+ pScreenPriv->grabKeyboard = TRUE;
+
+ return Success;
+}
+
+
+
+/*********** exported ones ***************/
+
+void
+DGASetInputMode(int index, Bool keyboard, Bool mouse)
+{
+ ScreenPtr pScreen = screenInfo.screens[index];
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+
+ if (pScreenPriv)
+ {
+ pScreenPriv->grabMouse = mouse;
+ pScreenPriv->grabKeyboard = keyboard;
+ }
+}
+
+Bool
+DGAChangePixmapMode(int index, int *x, int *y, int mode)
+{
+ DGAScreenPtr pScreenPriv;
+ DGADevicePtr pDev;
+ DGAModePtr pMode;
+ PixmapPtr pPix;
+
+ if(DGAScreenIndex < 0)
+ return FALSE;
+
+ pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ if(!pScreenPriv || !pScreenPriv->current || !pScreenPriv->current->pPix)
+ return FALSE;
+
+ pDev = pScreenPriv->current;
+ pPix = pDev->pPix;
+ pMode = pDev->mode;
+
+ if(mode) {
+ int shift = 2;
+
+ if(*x > (pMode->pixmapWidth - pMode->viewportWidth))
+ *x = pMode->pixmapWidth - pMode->viewportWidth;
+ if(*y > (pMode->pixmapHeight - pMode->viewportHeight))
+ *y = pMode->pixmapHeight - pMode->viewportHeight;
+
+ switch(xf86Screens[index]->bitsPerPixel) {
+ case 16: shift = 1; break;
+ case 32: shift = 0; break;
+ default: break;
+ }
+
+ if(BITMAP_SCANLINE_PAD == 64)
+ shift++;
+
+ *x = (*x >> shift) << shift;
+
+ pPix->drawable.x = *x;
+ pPix->drawable.y = *y;
+ pPix->drawable.width = pMode->viewportWidth;
+ pPix->drawable.height = pMode->viewportHeight;
+ } else {
+ pPix->drawable.x = 0;
+ pPix->drawable.y = 0;
+ pPix->drawable.width = pMode->pixmapWidth;
+ pPix->drawable.height = pMode->pixmapHeight;
+ }
+ pPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+ pScreenPriv->pixmapMode = mode;
+
+ return TRUE;
+}
+
+Bool
+DGAAvailable(int index)
+{
+ if(DGAScreenIndex < 0)
+ return FALSE;
+
+ if (!xf86NoSharedResources(((ScrnInfoPtr)screenInfo.screens[index]->
+ devPrivates[xf86ScreenIndex].ptr)->scrnIndex,MEM))
+ return FALSE;
+
+ if(DGA_GET_SCREEN_PRIV(screenInfo.screens[index]))
+ return TRUE;
+
+ return FALSE;
+}
+
+Bool
+DGAActive(int index)
+{
+ DGAScreenPtr pScreenPriv;
+
+ if(DGAScreenIndex < 0)
+ return FALSE;
+
+ pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ if(pScreenPriv && pScreenPriv->current)
+ return TRUE;
+
+ return FALSE;
+}
+
+
+
+/* Called by the event code in case the server is abruptly terminated */
+
+void
+DGAShutdown()
+{
+ ScrnInfoPtr pScrn;
+ int i;
+
+ if(DGAScreenIndex < 0)
+ return;
+
+ for(i = 0; i < screenInfo.numScreens; i++) {
+ pScrn = xf86Screens[i];
+
+ (void)(*pScrn->SetDGAMode)(pScrn->scrnIndex, 0, NULL);
+ }
+}
+
+/* Called by the extension to initialize a mode */
+
+int
+DGASetMode(
+ int index,
+ int num,
+ XDGAModePtr mode,
+ PixmapPtr *pPix
+){
+ ScrnInfoPtr pScrn = xf86Screens[index];
+ DGADeviceRec device;
+ int ret;
+
+ /* We rely on the extension to check that DGA is available */
+
+ ret = (*pScrn->SetDGAMode)(index, num, &device);
+ if((ret == Success) && num) {
+ DGACopyModeInfo(device.mode, mode);
+ *pPix = device.pPix;
+ }
+
+ return ret;
+}
+
+/* Called from the extension to let the DDX know which events are requested */
+
+void
+DGASelectInput(
+ int index,
+ ClientPtr client,
+ long mask
+){
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ /* We rely on the extension to check that DGA is available */
+ pScreenPriv->client = client;
+ pScreenPriv->input = mask;
+}
+
+int
+DGAGetViewportStatus(int index)
+{
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ /* We rely on the extension to check that DGA is active */
+
+ if (!pScreenPriv->funcs->GetViewport)
+ return 0;
+
+ return (*pScreenPriv->funcs->GetViewport)(pScreenPriv->pScrn);
+}
+
+int
+DGASetViewport(
+ int index,
+ int x, int y,
+ int mode
+){
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ if (pScreenPriv->funcs->SetViewport)
+ (*pScreenPriv->funcs->SetViewport)(pScreenPriv->pScrn, x, y, mode);
+ return Success;
+}
+
+
+static int
+BitsClear(CARD32 data)
+{
+ int bits = 0;
+ CARD32 mask;
+
+ for(mask = 1; mask; mask <<= 1) {
+ if(!(data & mask)) bits++;
+ else break;
+ }
+
+ return bits;
+}
+
+int
+DGACreateColormap(int index, ClientPtr client, int id, int mode, int alloc)
+{
+ ScreenPtr pScreen = screenInfo.screens[index];
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+ FakedVisualList *fvlp;
+ VisualPtr pVisual;
+ DGAModePtr pMode;
+ ColormapPtr pmap;
+
+ if(!mode || (mode > pScreenPriv->numModes))
+ return BadValue;
+
+ if((alloc != AllocNone) && (alloc != AllocAll))
+ return BadValue;
+
+ pMode = &(pScreenPriv->modes[mode - 1]);
+
+ if(!(pVisual = xalloc(sizeof(VisualRec))))
+ return BadAlloc;
+
+ pVisual->vid = FakeClientID(0);
+ pVisual->class = pMode->visualClass;
+ pVisual->nplanes = pMode->depth;
+ pVisual->ColormapEntries = 1 << pMode->depth;
+ pVisual->bitsPerRGBValue = (pMode->depth + 2) / 3;
+
+ switch (pVisual->class) {
+ case PseudoColor:
+ case GrayScale:
+ case StaticGray:
+ pVisual->bitsPerRGBValue = 8; /* not quite */
+ pVisual->redMask = 0;
+ pVisual->greenMask = 0;
+ pVisual->blueMask = 0;
+ pVisual->offsetRed = 0;
+ pVisual->offsetGreen = 0;
+ pVisual->offsetBlue = 0;
+ break;
+ case DirectColor:
+ case TrueColor:
+ pVisual->ColormapEntries = 1 << pVisual->bitsPerRGBValue;
+ /* fall through */
+ case StaticColor:
+ pVisual->redMask = pMode->red_mask;
+ pVisual->greenMask = pMode->green_mask;
+ pVisual->blueMask = pMode->blue_mask;
+ pVisual->offsetRed = BitsClear(pVisual->redMask);
+ pVisual->offsetGreen = BitsClear(pVisual->greenMask);
+ pVisual->offsetBlue = BitsClear(pVisual->blueMask);
+ }
+
+ if(!(fvlp = xalloc(sizeof(FakedVisualList)))) {
+ xfree(pVisual);
+ return BadAlloc;
+ }
+
+ fvlp->free = FALSE;
+ fvlp->pVisual = pVisual;
+ fvlp->next = pScreenPriv->fakedVisuals;
+ pScreenPriv->fakedVisuals = fvlp;
+
+ LEGAL_NEW_RESOURCE(id, client);
+
+ return CreateColormap(id, pScreen, pVisual, &pmap, alloc, client->index);
+}
+
+/* Called by the extension to install a colormap on DGA active screens */
+
+void
+DGAInstallCmap(ColormapPtr cmap)
+{
+ ScreenPtr pScreen = cmap->pScreen;
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+
+ /* We rely on the extension to check that DGA is active */
+
+ if(!pScreenPriv->dgaColormap)
+ pScreenPriv->savedColormap = miInstalledMaps[pScreen->myNum];
+
+ pScreenPriv->dgaColormap = cmap;
+
+ (*pScreen->InstallColormap)(cmap);
+}
+
+int
+DGASync(int index)
+{
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ /* We rely on the extension to check that DGA is active */
+
+ if (pScreenPriv->funcs->Sync)
+ (*pScreenPriv->funcs->Sync)(pScreenPriv->pScrn);
+
+ return Success;
+}
+
+int
+DGAFillRect(
+ int index,
+ int x, int y, int w, int h,
+ unsigned long color
+){
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ /* We rely on the extension to check that DGA is active */
+
+ if(pScreenPriv->funcs->FillRect &&
+ (pScreenPriv->current->mode->flags & DGA_FILL_RECT)) {
+
+ (*pScreenPriv->funcs->FillRect)(pScreenPriv->pScrn, x, y, w, h, color);
+ return Success;
+ }
+ return BadMatch;
+}
+
+int
+DGABlitRect(
+ int index,
+ int srcx, int srcy,
+ int w, int h,
+ int dstx, int dsty
+){
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ /* We rely on the extension to check that DGA is active */
+
+ if(pScreenPriv->funcs->BlitRect &&
+ (pScreenPriv->current->mode->flags & DGA_BLIT_RECT)) {
+
+ (*pScreenPriv->funcs->BlitRect)(pScreenPriv->pScrn,
+ srcx, srcy, w, h, dstx, dsty);
+ return Success;
+ }
+ return BadMatch;
+}
+
+int
+DGABlitTransRect(
+ int index,
+ int srcx, int srcy,
+ int w, int h,
+ int dstx, int dsty,
+ unsigned long color
+){
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ /* We rely on the extension to check that DGA is active */
+
+ if(pScreenPriv->funcs->BlitTransRect &&
+ (pScreenPriv->current->mode->flags & DGA_BLIT_RECT_TRANS)) {
+
+ (*pScreenPriv->funcs->BlitTransRect)(pScreenPriv->pScrn,
+ srcx, srcy, w, h, dstx, dsty, color);
+ return Success;
+ }
+ return BadMatch;
+}
+
+
+int
+DGAGetModes(int index)
+{
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+ /* We rely on the extension to check that DGA is available */
+
+ return pScreenPriv->numModes;
+}
+
+
+int
+DGAGetModeInfo(
+ int index,
+ XDGAModePtr mode,
+ int num
+){
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+ /* We rely on the extension to check that DGA is available */
+
+ if((num <= 0) || (num > pScreenPriv->numModes))
+ return BadValue;
+
+ DGACopyModeInfo(&(pScreenPriv->modes[num - 1]), mode);
+
+ return Success;
+}
+
+
+static void
+DGACopyModeInfo(
+ DGAModePtr mode,
+ XDGAModePtr xmode
+){
+ DisplayModePtr dmode = mode->mode;
+
+ xmode->num = mode->num;
+ xmode->name = dmode->name;
+ xmode->VSync_num = (int)(dmode->VRefresh * 1000.0);
+ xmode->VSync_den = 1000;
+ xmode->flags = mode->flags;
+ xmode->imageWidth = mode->imageWidth;
+ xmode->imageHeight = mode->imageHeight;
+ xmode->pixmapWidth = mode->pixmapWidth;
+ xmode->pixmapHeight = mode->pixmapHeight;
+ xmode->bytesPerScanline = mode->bytesPerScanline;
+ xmode->byteOrder = mode->byteOrder;
+ xmode->depth = mode->depth;
+ xmode->bitsPerPixel = mode->bitsPerPixel;
+ xmode->red_mask = mode->red_mask;
+ xmode->green_mask = mode->green_mask;
+ xmode->blue_mask = mode->blue_mask;
+ xmode->visualClass = mode->visualClass;
+ xmode->viewportWidth = mode->viewportWidth;
+ xmode->viewportHeight = mode->viewportHeight;
+ xmode->xViewportStep = mode->xViewportStep;
+ xmode->yViewportStep = mode->yViewportStep;
+ xmode->maxViewportX = mode->maxViewportX;
+ xmode->maxViewportY = mode->maxViewportY;
+ xmode->viewportFlags = mode->viewportFlags;
+ xmode->reserved1 = mode->reserved1;
+ xmode->reserved2 = mode->reserved2;
+ xmode->offset = mode->offset;
+
+ if(dmode->Flags & V_INTERLACE) xmode->flags |= DGA_INTERLACED;
+ if(dmode->Flags & V_DBLSCAN) xmode->flags |= DGA_DOUBLESCAN;
+}
+
+
+Bool
+DGAVTSwitch(void)
+{
+ ScreenPtr pScreen;
+ int i;
+
+ for(i = 0; i < screenInfo.numScreens; i++) {
+ pScreen = screenInfo.screens[i];
+
+ /* Alternatively, this could send events to DGA clients */
+
+ if(DGAScreenIndex >= 0) {
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+
+ if(pScreenPriv && pScreenPriv->current)
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+
+/* We have the power to steal or modify events that are about to get queued */
+
+Bool
+DGAStealKeyEvent(int index, xEvent *e)
+{
+ DGAScreenPtr pScreenPriv;
+ dgaEvent de;
+
+ if(DGAScreenIndex < 0) /* no DGA */
+ return FALSE;
+
+ pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ if(!pScreenPriv || !pScreenPriv->grabKeyboard) /* no direct mode */
+ return FALSE;
+
+ de.u.u.type = e->u.u.type + *XDGAEventBase;
+ de.u.u.detail = e->u.u.detail;
+ de.u.event.time = e->u.keyButtonPointer.time;
+ xf86eqEnqueue ((xEvent *) &de);
+ return TRUE;
+}
+
+static int DGAMouseX, DGAMouseY;
+
+Bool
+DGAStealMouseEvent(int index, xEvent *e, int dx, int dy)
+{
+ DGAScreenPtr pScreenPriv;
+ dgaEvent de;
+
+ if(DGAScreenIndex < 0) /* no DGA */
+ return FALSE;
+
+ pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ if(!pScreenPriv || !pScreenPriv->grabMouse) /* no direct mode */
+ return FALSE;
+
+ DGAMouseX += dx;
+ if (DGAMouseX < 0)
+ DGAMouseX = 0;
+ else if (DGAMouseX > screenInfo.screens[index]->width)
+ DGAMouseX = screenInfo.screens[index]->width;
+ DGAMouseY += dy;
+ if (DGAMouseY < 0)
+ DGAMouseY = 0;
+ else if (DGAMouseY > screenInfo.screens[index]->height)
+ DGAMouseY = screenInfo.screens[index]->height;
+ de.u.u.type = e->u.u.type + *XDGAEventBase;
+ de.u.u.detail = e->u.u.detail;
+ de.u.event.time = e->u.keyButtonPointer.time;
+ de.u.event.dx = dx;
+ de.u.event.dy = dy;
+ de.u.event.pad1 = DGAMouseX;
+ de.u.event.pad2 = DGAMouseY;
+ xf86eqEnqueue ((xEvent *) &de);
+ return TRUE;
+}
+
+Bool
+DGAIsDgaEvent (xEvent *e)
+{
+ int coreEquiv;
+ if (DGAScreenIndex < 0 || XDGAEventBase == 0)
+ return FALSE;
+ coreEquiv = e->u.u.type - *XDGAEventBase;
+ if (KeyPress <= coreEquiv && coreEquiv <= MotionNotify)
+ return TRUE;
+ return FALSE;
+}
+
+#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */
+static Mask filters[] =
+{
+ NoSuchEvent, /* 0 */
+ NoSuchEvent, /* 1 */
+ KeyPressMask, /* KeyPress */
+ KeyReleaseMask, /* KeyRelease */
+ ButtonPressMask, /* ButtonPress */
+ ButtonReleaseMask, /* ButtonRelease */
+ PointerMotionMask, /* MotionNotify (initial state) */
+};
+
+static void
+DGAProcessKeyboardEvent (ScreenPtr pScreen, dgaEvent *de, DeviceIntPtr keybd)
+{
+ int key, bit;
+ register BYTE *kptr;
+ register int i;
+ register CARD8 modifiers;
+ register CARD16 mask;
+ int coreEquiv;
+ xEvent core;
+ KeyClassPtr keyc = keybd->key;
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+
+ coreEquiv = de->u.u.type - *XDGAEventBase;
+
+ /*
+ * Fill in remaining event state
+ */
+ de->u.event.dx = 0;
+ de->u.event.dy = 0;
+ de->u.event.screen = pScreen->myNum;
+ de->u.event.state = keyc->state | (inputInfo.pointer)->button->state;
+
+ /*
+ * Keep the core state in sync by duplicating what
+ * CoreProcessKeyboardEvent does
+ */
+ key = de->u.u.detail;
+ kptr = &keyc->down[key >> 3];
+ bit = 1 << (key & 7);
+ modifiers = keyc->modifierMap[key];
+ switch (coreEquiv)
+ {
+ case KeyPress:
+ inputInfo.pointer->valuator->motionHintWindow = NullWindow;
+ *kptr |= bit;
+ keyc->prev_state = keyc->state;
+#ifdef XKB
+ if (noXkbExtension)
+#endif
+ {
+
+ for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
+ {
+ if (mask & modifiers)
+ {
+ /* This key affects modifier "i" */
+ keyc->modifierKeyCount[i]++;
+ keyc->state |= mask;
+ modifiers &= ~mask;
+ }
+ }
+ }
+ break;
+ case KeyRelease:
+ inputInfo.pointer->valuator->motionHintWindow = NullWindow;
+ *kptr &= ~bit;
+ keyc->prev_state = keyc->state;
+#ifdef XKB
+ if (noXkbExtension)
+#endif
+ {
+ for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
+ {
+ if (mask & modifiers) {
+ /* This key affects modifier "i" */
+ if (--keyc->modifierKeyCount[i] <= 0) {
+ keyc->state &= ~mask;
+ keyc->modifierKeyCount[i] = 0;
+ }
+ modifiers &= ~mask;
+ }
+ }
+ }
+ break;
+ }
+ /*
+ * Deliver the DGA event
+ */
+ if (pScreenPriv->client)
+ {
+ /* If the DGA client has selected input, then deliver based on the usual filter */
+ TryClientEvents (pScreenPriv->client, (xEvent *) de, 1,
+ filters[coreEquiv], pScreenPriv->input, 0);
+ }
+ else
+ {
+ /* If the keyboard is actively grabbed, deliver a grabbed core event */
+ if (keybd->grab && !keybd->fromPassiveGrab)
+ {
+ core.u.u.type = coreEquiv;
+ core.u.u.detail = de->u.u.detail;
+ core.u.keyButtonPointer.time = de->u.event.time;
+ core.u.keyButtonPointer.eventX = de->u.event.dx;
+ core.u.keyButtonPointer.eventY = de->u.event.dy;
+ core.u.keyButtonPointer.rootX = de->u.event.dx;
+ core.u.keyButtonPointer.rootY = de->u.event.dy;
+ core.u.keyButtonPointer.state = de->u.event.state;
+ DeliverGrabbedEvent (&core, keybd, FALSE, 1);
+ }
+ }
+}
+
+static void
+DGAProcessPointerEvent (ScreenPtr pScreen, dgaEvent *de, DeviceIntPtr mouse)
+{
+ ButtonClassPtr butc = mouse->button;
+ int coreEquiv;
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+ xEvent core;
+
+ coreEquiv = de->u.u.type - *XDGAEventBase;
+ /*
+ * Fill in remaining event state
+ */
+ de->u.event.screen = pScreen->myNum;
+ de->u.event.state = butc->state | inputInfo.keyboard->key->state;
+ /*
+ * Keep the core state in sync by duplicating what
+ * CoreProcessPointerEvent does
+ */
+ if (coreEquiv != MotionNotify)
+ {
+ register int key;
+ register BYTE *kptr;
+ int bit;
+
+ key = de->u.u.detail;
+ kptr = &butc->down[key >> 3];
+ bit = 1 << (key & 7);
+ switch (coreEquiv)
+ {
+ case ButtonPress:
+ mouse->valuator->motionHintWindow = NullWindow;
+ if (!(*kptr & bit))
+ butc->buttonsDown++;
+ butc->motionMask = ButtonMotionMask;
+ *kptr |= bit;
+ if (key <= 5)
+ butc->state |= (Button1Mask >> 1) << key;
+ break;
+ case ButtonRelease:
+ mouse->valuator->motionHintWindow = NullWindow;
+ if (*kptr & bit)
+ --butc->buttonsDown;
+ if (!butc->buttonsDown)
+ butc->motionMask = 0;
+ *kptr &= ~bit;
+ if (key == 0)
+ return;
+ if (key <= 5)
+ butc->state &= ~((Button1Mask >> 1) << key);
+ break;
+ }
+ }
+ /*
+ * Deliver the DGA event
+ */
+ if (pScreenPriv->client)
+ {
+ /* If the DGA client has selected input, then deliver based on the usual filter */
+ TryClientEvents (pScreenPriv->client, (xEvent *) de, 1,
+ filters[coreEquiv], pScreenPriv->input, 0);
+ }
+ else
+ {
+ /* If the pointer is actively grabbed, deliver a grabbed core event */
+ if (mouse->grab && !mouse->fromPassiveGrab)
+ {
+ core.u.u.type = coreEquiv;
+ core.u.u.detail = de->u.u.detail;
+ core.u.keyButtonPointer.time = de->u.event.time;
+ core.u.keyButtonPointer.eventX = de->u.event.dx;
+ core.u.keyButtonPointer.eventY = de->u.event.dy;
+ core.u.keyButtonPointer.rootX = de->u.event.dx;
+ core.u.keyButtonPointer.rootY = de->u.event.dy;
+ core.u.keyButtonPointer.state = de->u.event.state;
+ DeliverGrabbedEvent (&core, mouse, FALSE, 1);
+ }
+ }
+}
+
+Bool
+DGADeliverEvent (ScreenPtr pScreen, xEvent *e)
+{
+ dgaEvent *de = (dgaEvent *) e;
+ DGAScreenPtr pScreenPriv;
+ int coreEquiv;
+
+ /* no DGA */
+ if (DGAScreenIndex < 0 || XDGAEventBase == 0)
+ return FALSE;
+ pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+
+ /* DGA not initialized on this screen */
+ if (!pScreenPriv)
+ return FALSE;
+
+ coreEquiv = de->u.u.type - *XDGAEventBase;
+ /* Not a DGA event */
+ if (coreEquiv < KeyPress || coreEquiv > MotionNotify)
+ return FALSE;
+
+ switch (coreEquiv) {
+ case KeyPress:
+ case KeyRelease:
+ DGAProcessKeyboardEvent (pScreen, de, inputInfo.keyboard);
+ break;
+ default:
+ DGAProcessPointerEvent (pScreen, de, inputInfo.pointer);
+ break;
+ }
+ return TRUE;
+}
+
+Bool
+DGAOpenFramebuffer(
+ int index,
+ char **name,
+ unsigned char **mem,
+ int *size,
+ int *offset,
+ int *flags
+){
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ /* We rely on the extension to check that DGA is available */
+
+ return (*pScreenPriv->funcs->OpenFramebuffer)(pScreenPriv->pScrn,
+ name, mem, size, offset, flags);
+}
+
+void
+DGACloseFramebuffer(int index)
+{
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+ /* We rely on the extension to check that DGA is available */
+ if(pScreenPriv->funcs->CloseFramebuffer)
+ (*pScreenPriv->funcs->CloseFramebuffer)(pScreenPriv->pScrn);
+}
+
+/* For DGA 1.0 backwards compatibility only */
+
+int
+DGAGetOldDGAMode(int index)
+{
+ DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+ ScrnInfoPtr pScrn = pScreenPriv->pScrn;
+ DGAModePtr mode;
+ int i, w, h, p;
+
+ /* We rely on the extension to check that DGA is available */
+
+ w = pScrn->currentMode->HDisplay;
+ h = pScrn->currentMode->VDisplay;
+ p = ((pScrn->displayWidth * (pScrn->bitsPerPixel >> 3)) + 3) & ~3L;
+
+ for(i = 0; i < pScreenPriv->numModes; i++) {
+ mode = &(pScreenPriv->modes[i]);
+
+ if((mode->viewportWidth == w) && (mode->viewportHeight == h) &&
+ (mode->bytesPerScanline == p) &&
+ (mode->bitsPerPixel == pScrn->bitsPerPixel) &&
+ (mode->depth == pScrn->depth)) {
+
+ return mode->num;
+ }
+ }
+
+ return 0;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86DPMS.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DPMS.c
new file mode 100644
index 000000000..f02585a0f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DPMS.c
@@ -0,0 +1,222 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86DPMS.c,v 1.11 2003/11/11 21:02:28 dawes Exp $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86DPMS.c,v 1.8 2005/07/03 08:53:42 daniels Exp $ */
+
+/*
+ * 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 DPMS functions required by the extension.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "globals.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#ifdef DPMSExtension
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+#include "dpmsproc.h"
+#endif
+
+
+#ifdef DPMSExtension
+static int DPMSGeneration = 0;
+static int DPMSIndex = -1;
+static Bool DPMSClose(int i, ScreenPtr pScreen);
+static int DPMSCount = 0;
+#endif
+
+
+Bool
+xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
+{
+#ifdef DPMSExtension
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ DPMSPtr pDPMS;
+ pointer DPMSOpt;
+
+ if (serverGeneration != DPMSGeneration) {
+ if ((DPMSIndex = AllocateScreenPrivateIndex()) < 0)
+ return FALSE;
+ DPMSGeneration = serverGeneration;
+ }
+
+ if (DPMSDisabledSwitch)
+ DPMSEnabled = FALSE;
+ if (!(pScreen->devPrivates[DPMSIndex].ptr = xcalloc(sizeof(DPMSRec), 1)))
+ return FALSE;
+
+ pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
+ pScrn->DPMSSet = set;
+ pDPMS->Flags = flags;
+ DPMSOpt = xf86FindOption(pScrn->options, "dpms");
+ if (DPMSOpt) {
+ if ((pDPMS->Enabled
+ = xf86SetBoolOption(pScrn->options, "dpms", FALSE))
+ && !DPMSDisabledSwitch)
+ DPMSEnabled = TRUE;
+ xf86MarkOptionUsed(DPMSOpt);
+ xf86DrvMsg(pScreen->myNum, X_CONFIG, "DPMS enabled\n");
+ } else if (DPMSEnabledSwitch) {
+ if (!DPMSDisabledSwitch)
+ DPMSEnabled = TRUE;
+ pDPMS->Enabled = TRUE;
+ }
+ else {
+ pDPMS->Enabled = defaultDPMSEnabled;
+ }
+ pDPMS->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = DPMSClose;
+ DPMSCount++;
+ return TRUE;
+#else
+ return FALSE;
+#endif
+}
+
+
+#ifdef DPMSExtension
+
+static Bool
+DPMSClose(int i, ScreenPtr pScreen)
+{
+ DPMSPtr pDPMS;
+
+ /* This shouldn't happen */
+ if (DPMSIndex < 0)
+ return FALSE;
+
+ pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
+
+ /* This shouldn't happen */
+ if (!pDPMS)
+ return FALSE;
+
+ pScreen->CloseScreen = pDPMS->CloseScreen;
+
+ /*
+ * Turn on DPMS when shutting down. If this function can be used
+ * depends on the order the driver wraps things. If this is called
+ * after the driver has shut down everything the driver will have
+ * to deal with this internally.
+ */
+ if (xf86Screens[i]->vtSema && xf86Screens[i]->DPMSSet) {
+ xf86Screens[i]->DPMSSet(xf86Screens[i],DPMSModeOn,0);
+ }
+
+ xfree((pointer)pDPMS);
+ pScreen->devPrivates[DPMSIndex].ptr = NULL;
+ if (--DPMSCount == 0)
+ DPMSIndex = -1;
+ return pScreen->CloseScreen(i, pScreen);
+}
+
+
+/*
+ * DPMSSet --
+ * Device dependent DPMS mode setting hook. This is called whenever
+ * the DPMS mode is to be changed.
+ */
+void
+DPMSSet(int level)
+{
+ int i;
+ DPMSPtr pDPMS;
+ ScrnInfoPtr pScrn;
+
+ DPMSPowerLevel = level;
+
+ if (DPMSIndex < 0)
+ return;
+
+ if (level != DPMSModeOn)
+ SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverActive);
+
+ /* For each screen, set the DPMS level */
+ for (i = 0; i < xf86NumScreens; i++) {
+ pScrn = xf86Screens[i];
+ pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
+ if (pDPMS && pScrn->DPMSSet && pDPMS->Enabled && pScrn->vtSema) {
+ xf86EnableAccess(pScrn);
+ pScrn->DPMSSet(pScrn, level, 0);
+ }
+ }
+}
+
+
+/*
+ * DPMSSupported --
+ * Return TRUE if any screen supports DPMS.
+ */
+Bool
+DPMSSupported(void)
+{
+ int i;
+ DPMSPtr pDPMS;
+ ScrnInfoPtr pScrn;
+
+ if (DPMSIndex < 0) {
+ return FALSE;
+ }
+
+ /* For each screen, check if DPMS is supported */
+ for (i = 0; i < xf86NumScreens; i++) {
+ pScrn = xf86Screens[i];
+ pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
+ if (pDPMS && pScrn->DPMSSet)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+/*
+ * DPMSGet --
+ * Device dependent DPMS mode getting hook. This returns the current
+ * DPMS mode, or -1 if DPMS is not supported.
+ *
+ * This should hook in to the appropriate driver-level function, which
+ * will be added to the ScrnInfoRec.
+ *
+ * NOTES:
+ * 1. the calling interface should be changed to specify which
+ * screen to check.
+ * 2. It isn't clear that this function is ever used or what it should
+ * return.
+ */
+int
+DPMSGet(int *level)
+{
+ return DPMSPowerLevel;
+}
+
+#endif /* DPMSExtension */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Debug.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Debug.c
new file mode 100644
index 000000000..15c267232
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Debug.c
@@ -0,0 +1,197 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Debug.c,v 1.7 2003/09/24 02:43:17 dawes Exp $ */
+
+/*
+ * Copyright (c) 2000-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
+
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+
+#include <sys/time.h>
+#include <unistd.h>
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "compiler.h"
+
+void xf86Break1(void)
+{
+}
+
+void xf86Break2(void)
+{
+}
+
+void xf86Break3(void)
+{
+}
+
+char *xf86p8bit[] = { "00000000", "00000001", "00000010", "00000011",
+ "00000100", "00000101", "00000110", "00000111",
+ "00001000", "00001001", "00001010", "00001011",
+ "00001100", "00001101", "00001110", "00001111",
+ "00010000", "00010001", "00010010", "00010011",
+ "00010100", "00010101", "00010110", "00010111",
+ "00011000", "00011001", "00011010", "00011011",
+ "00011100", "00011101", "00011110", "00011111",
+ "00100000", "00100001", "00100010", "00100011",
+ "00100100", "00100101", "00100110", "00100111",
+ "00101000", "00101001", "00101010", "00101011",
+ "00101100", "00101101", "00101110", "00101111",
+ "00110000", "00110001", "00110010", "00110011",
+ "00110100", "00110101", "00110110", "00110111",
+ "00111000", "00111001", "00111010", "00111011",
+ "00111100", "00111101", "00111110", "00111111",
+ "01000000", "01000001", "01000010", "01000011",
+ "01000100", "01000101", "01000110", "01000111",
+ "01001000", "01001001", "01001010", "01001011",
+ "01001100", "01001101", "01001110", "01001111",
+ "01010000", "01010001", "01010010", "01010011",
+ "01010100", "01010101", "01010110", "01010111",
+ "01011000", "01011001", "01011010", "01011011",
+ "01011100", "01011101", "01011110", "01011111",
+ "01100000", "01100001", "01100010", "01100011",
+ "01100100", "01100101", "01100110", "01100111",
+ "01101000", "01101001", "01101010", "01101011",
+ "01101100", "01101101", "01101110", "01101111",
+ "01110000", "01110001", "01110010", "01110011",
+ "01110100", "01110101", "01110110", "01110111",
+ "01111000", "01111001", "01111010", "01111011",
+ "01111100", "01111101", "01111110", "01111111",
+ "10000000", "10000001", "10000010", "10000011",
+ "10000100", "10000101", "10000110", "10000111",
+ "10001000", "10001001", "10001010", "10001011",
+ "10001100", "10001101", "10001110", "10001111",
+ "10010000", "10010001", "10010010", "10010011",
+ "10010100", "10010101", "10010110", "10010111",
+ "10011000", "10011001", "10011010", "10011011",
+ "10011100", "10011101", "10011110", "10011111",
+ "10100000", "10100001", "10100010", "10100011",
+ "10100100", "10100101", "10100110", "10100111",
+ "10101000", "10101001", "10101010", "10101011",
+ "10101100", "10101101", "10101110", "10101111",
+ "10110000", "10110001", "10110010", "10110011",
+ "10110100", "10110101", "10110110", "10110111",
+ "10111000", "10111001", "10111010", "10111011",
+ "10111100", "10111101", "10111110", "10111111",
+ "11000000", "11000001", "11000010", "11000011",
+ "11000100", "11000101", "11000110", "11000111",
+ "11001000", "11001001", "11001010", "11001011",
+ "11001100", "11001101", "11001110", "11001111",
+ "11010000", "11010001", "11010010", "11010011",
+ "11010100", "11010101", "11010110", "11010111",
+ "11011000", "11011001", "11011010", "11011011",
+ "11011100", "11011101", "11011110", "11011111",
+ "11100000", "11100001", "11100010", "11100011",
+ "11100100", "11100101", "11100110", "11100111",
+ "11101000", "11101001", "11101010", "11101011",
+ "11101100", "11101101", "11101110", "11101111",
+ "11110000", "11110001", "11110010", "11110011",
+ "11110100", "11110101", "11110110", "11110111",
+ "11111000", "11111001", "11111010", "11111011",
+ "11111100", "11111101", "11111110", "11111111"
+};
+
+CARD32 xf86DummyVar1;
+CARD32 xf86DummyVar2;
+CARD32 xf86DummyVar3;
+
+CARD8 xf86PeekFb8(CARD8 *p) { return *p; }
+CARD16 xf86PeekFb16(CARD16 *p) { return *p; }
+CARD32 xf86PeekFb32(CARD32 *p) { return *p; }
+void xf86PokeFb8(CARD8 *p, CARD8 v) { *p = v; }
+void xf86PokeFb16(CARD16 *p, CARD16 v) { *p = v; }
+void xf86PokeFb32(CARD16 *p, CARD32 v) { *p = v; }
+
+CARD8 xf86PeekMmio8(pointer Base, unsigned long Offset)
+{
+ return MMIO_IN8(Base,Offset);
+}
+
+CARD16 xf86PeekMmio16(pointer Base, unsigned long Offset)
+{
+ return MMIO_IN16(Base,Offset);
+}
+
+CARD32 xf86PeekMmio32(pointer Base, unsigned long Offset)
+{
+ return MMIO_IN32(Base,Offset);
+}
+
+void xf86PokeMmio8(pointer Base, unsigned long Offset, CARD8 v)
+{
+ MMIO_OUT8(Base,Offset,v);
+}
+
+void xf86PokeMmio16(pointer Base, unsigned long Offset, CARD16 v)
+{
+ MMIO_OUT16(Base,Offset,v);
+}
+
+void xf86PokeMmio32(pointer Base, unsigned long Offset, CARD32 v)
+{
+ MMIO_OUT32(Base,Offset,v);
+}
+
+
+void
+xf86STimestamp(xf86TsPtr* timestamp)
+{
+ if (*timestamp) {
+ gettimeofday((struct timeval*)*timestamp,NULL);
+ } else {
+ *timestamp = xnfalloc(sizeof(xf86TsRec));
+ gettimeofday((struct timeval*)*timestamp,NULL);
+ }
+}
+
+void
+xf86SPTimestamp(xf86TsPtr* timestamp, char *str)
+{
+ if (*timestamp) {
+ long diff;
+ struct timeval ts;
+ ts = **(struct timeval**)timestamp;
+ gettimeofday((struct timeval*)*timestamp,NULL);
+ if (ts.tv_usec > (*timestamp)->usec)
+ diff = ((*timestamp)->sec - ts.tv_sec - 1) * 1000
+ + (ts.tv_usec - (*timestamp)->usec) / 1000;
+ else
+ diff = ((*timestamp)->sec - ts.tv_sec) * 1000
+ +(- ts.tv_usec + (*timestamp)->usec) / 1000;
+ ErrorF("%s Elapsed: %li\n",str,diff);
+ } else {
+ *timestamp = xnfalloc(sizeof(xf86TsRec));
+ gettimeofday((struct timeval*)*timestamp,NULL);
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86DefModes.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DefModes.c
new file mode 100644
index 000000000..a39d0a212
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DefModes.c
@@ -0,0 +1,160 @@
+/* $XFree86$ */
+
+/* THIS FILE IS AUTOMATICALLY GENERATED -- DO NOT EDIT -- LOOK at
+ * modeline2c.pl */
+
+/*
+ * Copyright 1999-2003 by The XFree86 Project, Inc.
+ *
+ * Author: Dirk Hohndel <hohndel@XFree86.Org>
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+#include "xf86.h"
+#include "xf86Config.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include "globals.h"
+
+#define MODEPREFIX(name) NULL, NULL, name, MODE_OK, M_T_DEFAULT
+#define MODESUFFIX 0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0
+
+DisplayModeRec xf86DefaultModes [] = {
+/* 640x350 @ 85Hz (VESA) hsync: 37.9kHz */
+ {MODEPREFIX("640x350"),31500, 640,672,736,832,0, 350,382,385,445,0, V_PHSYNC | V_NVSYNC, MODESUFFIX},
+ {MODEPREFIX("320x175"),15750, 320,336,368,416,0, 175,191,192,222,0, V_PHSYNC | V_NVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 640x400 @ 85Hz (VESA) hsync: 37.9kHz */
+ {MODEPREFIX("640x400"),31500, 640,672,736,832,0, 400,401,404,445,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("320x200"),15750, 320,336,368,416,0, 200,200,202,222,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 720x400 @ 85Hz (VESA) hsync: 37.9kHz */
+ {MODEPREFIX("720x400"),35500, 720,756,828,936,0, 400,401,404,446,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("360x200"),17750, 360,378,414,468,0, 200,200,202,223,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 640x480 @ 60Hz (Industry standard) hsync: 31.5kHz */
+ {MODEPREFIX("640x480"),25200, 640,656,752,800,0, 480,490,492,525,0, V_NHSYNC | V_NVSYNC, MODESUFFIX},
+ {MODEPREFIX("320x240"),12600, 320,328,376,400,0, 240,245,246,262,0, V_NHSYNC | V_NVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 640x480 @ 72Hz (VESA) hsync: 37.9kHz */
+ {MODEPREFIX("640x480"),31500, 640,664,704,832,0, 480,489,491,520,0, V_NHSYNC | V_NVSYNC, MODESUFFIX},
+ {MODEPREFIX("320x240"),15750, 320,332,352,416,0, 240,244,245,260,0, V_NHSYNC | V_NVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 640x480 @ 75Hz (VESA) hsync: 37.5kHz */
+ {MODEPREFIX("640x480"),31500, 640,656,720,840,0, 480,481,484,500,0, V_NHSYNC | V_NVSYNC, MODESUFFIX},
+ {MODEPREFIX("320x240"),15750, 320,328,360,420,0, 240,240,242,250,0, V_NHSYNC | V_NVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 640x480 @ 85Hz (VESA) hsync: 43.3kHz */
+ {MODEPREFIX("640x480"),36000, 640,696,752,832,0, 480,481,484,509,0, V_NHSYNC | V_NVSYNC, MODESUFFIX},
+ {MODEPREFIX("320x240"),18000, 320,348,376,416,0, 240,240,242,254,0, V_NHSYNC | V_NVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 800x600 @ 56Hz (VESA) hsync: 35.2kHz */
+ {MODEPREFIX("800x600"),36000, 800,824,896,1024,0, 600,601,603,625,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("400x300"),18000, 400,412,448,512,0, 300,300,301,312,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 800x600 @ 60Hz (VESA) hsync: 37.9kHz */
+ {MODEPREFIX("800x600"),40000, 800,840,968,1056,0, 600,601,605,628,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("400x300"),20000, 400,420,484,528,0, 300,300,302,314,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 800x600 @ 72Hz (VESA) hsync: 48.1kHz */
+ {MODEPREFIX("800x600"),50000, 800,856,976,1040,0, 600,637,643,666,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("400x300"),25000, 400,428,488,520,0, 300,318,321,333,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 800x600 @ 75Hz (VESA) hsync: 46.9kHz */
+ {MODEPREFIX("800x600"),49500, 800,816,896,1056,0, 600,601,604,625,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("400x300"),24750, 400,408,448,528,0, 300,300,302,312,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 800x600 @ 85Hz (VESA) hsync: 53.7kHz */
+ {MODEPREFIX("800x600"),56300, 800,832,896,1048,0, 600,601,604,631,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("400x300"),28150, 400,416,448,524,0, 300,300,302,315,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1024x768i @ 43Hz (industry standard) hsync: 35.5kHz */
+ {MODEPREFIX("1024x768"),44900, 1024,1032,1208,1264,0, 768,768,776,817,0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX},
+ {MODEPREFIX("512x384"),22450, 512,516,604,632,0, 384,384,388,408,0, V_PHSYNC | V_PVSYNC | V_INTERLACE | V_DBLSCAN, MODESUFFIX},
+/* 1024x768 @ 60Hz (VESA) hsync: 48.4kHz */
+ {MODEPREFIX("1024x768"),65000, 1024,1048,1184,1344,0, 768,771,777,806,0, V_NHSYNC | V_NVSYNC, MODESUFFIX},
+ {MODEPREFIX("512x384"),32500, 512,524,592,672,0, 384,385,388,403,0, V_NHSYNC | V_NVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1024x768 @ 70Hz (VESA) hsync: 56.5kHz */
+ {MODEPREFIX("1024x768"),75000, 1024,1048,1184,1328,0, 768,771,777,806,0, V_NHSYNC | V_NVSYNC, MODESUFFIX},
+ {MODEPREFIX("512x384"),37500, 512,524,592,664,0, 384,385,388,403,0, V_NHSYNC | V_NVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1024x768 @ 75Hz (VESA) hsync: 60.0kHz */
+ {MODEPREFIX("1024x768"),78800, 1024,1040,1136,1312,0, 768,769,772,800,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("512x384"),39400, 512,520,568,656,0, 384,384,386,400,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1024x768 @ 85Hz (VESA) hsync: 68.7kHz */
+ {MODEPREFIX("1024x768"),94500, 1024,1072,1168,1376,0, 768,769,772,808,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("512x384"),47250, 512,536,584,688,0, 384,384,386,404,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1152x864 @ 75Hz (VESA) hsync: 67.5kHz */
+ {MODEPREFIX("1152x864"),108000, 1152,1216,1344,1600,0, 864,865,868,900,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("576x432"),54000, 576,608,672,800,0, 432,432,434,450,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1280x960 @ 60Hz (VESA) hsync: 60.0kHz */
+ {MODEPREFIX("1280x960"),108000, 1280,1376,1488,1800,0, 960,961,964,1000,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("640x480"),54000, 640,688,744,900,0, 480,480,482,500,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1280x960 @ 85Hz (VESA) hsync: 85.9kHz */
+ {MODEPREFIX("1280x960"),148500, 1280,1344,1504,1728,0, 960,961,964,1011,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("640x480"),74250, 640,672,752,864,0, 480,480,482,505,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1280x1024 @ 60Hz (VESA) hsync: 64.0kHz */
+ {MODEPREFIX("1280x1024"),108000, 1280,1328,1440,1688,0, 1024,1025,1028,1066,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("640x512"),54000, 640,664,720,844,0, 512,512,514,533,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1280x1024 @ 75Hz (VESA) hsync: 80.0kHz */
+ {MODEPREFIX("1280x1024"),135000, 1280,1296,1440,1688,0, 1024,1025,1028,1066,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("640x512"),67500, 640,648,720,844,0, 512,512,514,533,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1280x1024 @ 85Hz (VESA) hsync: 91.1kHz */
+ {MODEPREFIX("1280x1024"),157500, 1280,1344,1504,1728,0, 1024,1025,1028,1072,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("640x512"),78750, 640,672,752,864,0, 512,512,514,536,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1600x1200 @ 60Hz (VESA) hsync: 75.0kHz */
+ {MODEPREFIX("1600x1200"),162000, 1600,1664,1856,2160,0, 1200,1201,1204,1250,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("800x600"),81000, 800,832,928,1080,0, 600,600,602,625,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1600x1200 @ 65Hz (VESA) hsync: 81.3kHz */
+ {MODEPREFIX("1600x1200"),175500, 1600,1664,1856,2160,0, 1200,1201,1204,1250,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("800x600"),87750, 800,832,928,1080,0, 600,600,602,625,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1600x1200 @ 70Hz (VESA) hsync: 87.5kHz */
+ {MODEPREFIX("1600x1200"),189000, 1600,1664,1856,2160,0, 1200,1201,1204,1250,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("800x600"),94500, 800,832,928,1080,0, 600,600,602,625,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1600x1200 @ 75Hz (VESA) hsync: 93.8kHz */
+ {MODEPREFIX("1600x1200"),202500, 1600,1664,1856,2160,0, 1200,1201,1204,1250,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("800x600"),101250, 800,832,928,1080,0, 600,600,602,625,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1600x1200 @ 85Hz (VESA) hsync: 106.3kHz */
+ {MODEPREFIX("1600x1200"),229500, 1600,1664,1856,2160,0, 1200,1201,1204,1250,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("800x600"),114750, 800,832,928,1080,0, 600,600,602,625,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1792x1344 @ 60Hz (VESA) hsync: 83.6kHz */
+ {MODEPREFIX("1792x1344"),204800, 1792,1920,2120,2448,0, 1344,1345,1348,1394,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("896x672"),102400, 896,960,1060,1224,0, 672,672,674,697,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1792x1344 @ 75Hz (VESA) hsync: 106.3kHz */
+ {MODEPREFIX("1792x1344"),261000, 1792,1888,2104,2456,0, 1344,1345,1348,1417,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("896x672"),130500, 896,944,1052,1228,0, 672,672,674,708,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1856x1392 @ 60Hz (VESA) hsync: 86.3kHz */
+ {MODEPREFIX("1856x1392"),218300, 1856,1952,2176,2528,0, 1392,1393,1396,1439,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("928x696"),109150, 928,976,1088,1264,0, 696,696,698,719,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1856x1392 @ 75Hz (VESA) hsync: 112.5kHz */
+ {MODEPREFIX("1856x1392"),288000, 1856,1984,2208,2560,0, 1392,1393,1396,1500,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("928x696"),144000, 928,992,1104,1280,0, 696,696,698,750,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1920x1440 @ 60Hz (VESA) hsync: 90.0kHz */
+ {MODEPREFIX("1920x1440"),234000, 1920,2048,2256,2600,0, 1440,1441,1444,1500,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("960x720"),117000, 960,1024,1128,1300,0, 720,720,722,750,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1920x1440 @ 75Hz (VESA) hsync: 112.5kHz */
+ {MODEPREFIX("1920x1440"),297000, 1920,2064,2288,2640,0, 1440,1441,1444,1500,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("960x720"),148500, 960,1032,1144,1320,0, 720,720,722,750,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 832x624 @ 75Hz (74.55Hz) (fix if the official/Apple spec is different) hsync: 49.725kHz */
+ {MODEPREFIX("832x624"),57284, 832,864,928,1152,0, 624,625,628,667,0, V_NHSYNC | V_NVSYNC, MODESUFFIX},
+ {MODEPREFIX("416x312"),28642, 416,432,464,576,0, 312,312,314,333,0, V_NHSYNC | V_NVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1152x768 @ 54.8Hz (Titanium PowerBook) hsync: 44.2kHz */
+ {MODEPREFIX("1152x768"),64995, 1152,1178,1314,1472,0, 768,771,777,806,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("576x384"),32497, 576,589,657,736,0, 384,385,388,403,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1400x1050 @ 60Hz (VESA GTF) hsync: 65.5kHz */
+ {MODEPREFIX("1400x1050"),122000, 1400,1488,1640,1880,0, 1050,1052,1064,1082,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("700x525"),61000, 700,744,820,940,0, 525,526,532,541,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1400x1050 @ 75Hz (VESA GTF) hsync: 82.2kHz */
+ {MODEPREFIX("1400x1050"),155800, 1400,1464,1784,1912,0, 1050,1052,1064,1090,0, V_PHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("700x525"),77900, 700,732,892,956,0, 525,526,532,545,0, V_PHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1600x1024 @ 60Hz (SGI 1600SW) hsync: 64.0kHz */
+ {MODEPREFIX("1600x1024"),106910, 1600,1620,1640,1670,0, 1024,1027,1030,1067,0, V_NHSYNC | V_NVSYNC, MODESUFFIX},
+ {MODEPREFIX("800x512"),53455, 800,810,820,835,0, 512,513,515,533,0, V_NHSYNC | V_NVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 1920x1440 @ 85Hz (VESA GTF) hsync: 128.5kHz */
+ {MODEPREFIX("1920x1440"),341350, 1920,2072,2288,2656,0, 1440,1441,1444,1512,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("960x720"),170675, 960,1036,1144,1328,0, 720,720,722,756,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 2048x1536 @ 60Hz (VESA GTF) hsync: 95.3kHz */
+ {MODEPREFIX("2048x1536"),266950, 2048,2200,2424,2800,0, 1536,1537,1540,1589,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("1024x768"),133475, 1024,1100,1212,1400,0, 768,768,770,794,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 2048x1536 @ 75Hz (VESA GTF) hsync: 120.2kHz */
+ {MODEPREFIX("2048x1536"),340480, 2048,2216,2440,2832,0, 1536,1537,1540,1603,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("1024x768"),170240, 1024,1108,1220,1416,0, 768,768,770,801,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+/* 2048x1536 @ 85Hz (VESA GTF) hsync: 137.0kHz */
+ {MODEPREFIX("2048x1536"),388040, 2048,2216,2440,2832,0, 1536,1537,1540,1612,0, V_NHSYNC | V_PVSYNC, MODESUFFIX},
+ {MODEPREFIX("1024x768"),194020, 1024,1108,1220,1416,0, 768,768,770,806,0, V_NHSYNC | V_PVSYNC | V_DBLSCAN, MODESUFFIX},
+ {MODEPREFIX(NULL),0,0,0,0,0,0,0,0,0,0,0,0,MODESUFFIX}
+};
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86DoProbe.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DoProbe.c
new file mode 100644
index 000000000..2f5b03eb1
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DoProbe.c
@@ -0,0 +1,129 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86DoProbe.c,v 1.14 2003/10/29 04:17:21 dawes Exp $ */
+/*
+ * Copyright (c) 1999-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).
+ */
+
+/*
+ * finish setting up the server
+ * Load the driver modules and call their probe functions.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "os.h"
+#ifdef XFree86LOADER
+#include "loaderProcs.h"
+#include "xf86Config.h"
+#endif /* XFree86LOADER */
+#include "xf86_OSlib.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+
+void
+DoProbeArgs(int argc, char **argv, int i)
+{
+}
+
+void
+DoProbe()
+{
+ int i;
+ Bool probeResult;
+ Bool ioEnableFailed = FALSE;
+
+#ifdef XFree86LOADER
+ /* Find the list of video driver modules. */
+ char **list = xf86DriverlistFromCompile();
+ char **l;
+
+ if (list) {
+ ErrorF("List of video driver modules:\n");
+ for (l = list; *l; l++)
+ ErrorF("\t%s\n", *l);
+ } else {
+ ErrorF("No video driver modules found\n");
+ }
+
+ /* Load all the drivers that were found. */
+ xf86LoadModules(list, NULL);
+#endif /* XFree86LOADER */
+
+ /* Disable PCI devices */
+ xf86AccessInit();
+
+ /* Call all of the probe functions, reporting the results. */
+ for (i = 0; i < xf86NumDrivers; i++) {
+
+ if (!xorgHWAccess) {
+ xorgHWFlags flags;
+ if (!xf86DriverList[i]->driverFunc
+ || !xf86DriverList[i]->driverFunc(NULL,
+ GET_REQUIRED_HW_INTERFACES,
+ &flags)
+ || NEED_IO_ENABLED(flags)) {
+ if (ioEnableFailed)
+ continue;
+ if (!xf86EnableIO()) {
+ ioEnableFailed = TRUE;
+ continue;
+ }
+ xorgHWAccess = TRUE;
+ }
+ }
+
+ if (xf86DriverList[i]->Probe == NULL) continue;
+
+ xf86MsgVerb(X_INFO, 3, "Probing in driver %s\n",
+ xf86DriverList[i]->driverName);
+ probeResult =
+ (*xf86DriverList[i]->Probe)(xf86DriverList[i], PROBE_DETECT);
+ if (!probeResult) {
+ xf86ErrorF("Probe in driver `%s' returns FALSE\n",
+ xf86DriverList[i]->driverName);
+ } else {
+ xf86ErrorF("Probe in driver `%s' returns TRUE\n",
+ xf86DriverList[i]->driverName);
+
+ /* If we have a result, then call driver's Identify function */
+ if (xf86DriverList[i]->Identify != NULL) {
+ int verbose = xf86SetVerbosity(1);
+ (*xf86DriverList[i]->Identify)(0);
+ xf86SetVerbosity(verbose);
+ }
+ }
+ }
+
+ OsCleanup(TRUE);
+ AbortDDX();
+ fflush(stderr);
+ exit(0);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86DoScanPci.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DoScanPci.c
new file mode 100644
index 000000000..9f8c15651
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86DoScanPci.c
@@ -0,0 +1,130 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86DoScanPci.c,v 1.15 2003/09/23 06:43:46 dawes Exp $ */
+/*
+ * Copyright (c) 1999-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).
+ */
+
+/*
+ * Finish setting up the server.
+ * Call the functions from the scanpci module.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "os.h"
+#ifdef XFree86LOADER
+#include "loaderProcs.h"
+#endif
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Pci.h"
+#include "xf86ScanPci.h"
+
+
+void DoScanPci(int argc, char **argv, int i)
+{
+ int j,skip,globalVerbose,scanpciVerbose;
+ ScanPciSetupProcPtr PciSetup;
+ ScanPciDisplayCardInfoProcPtr DisplayPCICardInfo;
+#ifdef XFree86LOADER
+ int errmaj, errmin;
+#endif
+
+ /*
+ * first we need to finish setup of the OS so that we can call other
+ * functions in the server
+ */
+ OsInit();
+
+ /*
+ * The old verbosity processing that was here isn't useful anymore, but
+ * for compatibility purposes, ignore verbosity changes after the -scanpci
+ * flag.
+ */
+ globalVerbose = xf86Verbose;
+
+ /*
+ * next we process the arguments that are remaining on the command line,
+ * so that things like the module path can be set there
+ */
+ for ( j = i+1; j < argc; j++ ) {
+ if ((skip = ddxProcessArgument(argc, argv, j)))
+ j += (skip - 1);
+ }
+
+ /*
+ * Was the verbosity level increased? If so, set it back.
+ */
+ if (xf86Verbose > globalVerbose)
+ xf86SetVerbosity(globalVerbose);
+
+ /*
+ * Setting scanpciVerbose to 0 will ensure that the output will go to
+ * stderr for all reasonable default stderr verbosity levels.
+ */
+ scanpciVerbose = 0;
+
+ /*
+ * now get the loader set up and load the scanpci module
+ */
+#ifdef XFree86LOADER
+ /* Initialise the loader */
+ LoaderInit();
+ /* Tell the loader the default module search path */
+ LoaderSetPath(xf86ModulePath);
+
+ if (!LoadModule("scanpci", NULL, NULL, NULL, NULL, NULL,
+ &errmaj, &errmin)) {
+ LoaderErrorMsg(NULL, "scanpci", errmaj, errmin);
+ exit(1);
+ }
+ if (LoaderCheckUnresolved(LD_RESOLV_IFDONE)) {
+ /* For now, just a warning */
+ xf86Msg(X_WARNING, "Some symbols could not be resolved!\n");
+ }
+ PciSetup = (ScanPciSetupProcPtr)LoaderSymbol("ScanPciSetupPciIds");
+ DisplayPCICardInfo =
+ (ScanPciDisplayCardInfoProcPtr)LoaderSymbol("ScanPciDisplayPCICardInfo");
+#else
+ PciSetup = ScanPciSetupPciIds;
+ DisplayPCICardInfo = ScanPciDisplayPCICardInfo;
+#endif
+
+ if (!(*PciSetup)())
+ FatalError("ScanPciSetupPciIds() failed\n");
+ (*DisplayPCICardInfo)(scanpciVerbose);
+
+ /*
+ * That's it; we really should clean things up, but a simple
+ * exit seems to be all we need.
+ */
+ exit(0);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Events.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Events.c
new file mode 100644
index 000000000..c1b478ee2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Events.c
@@ -0,0 +1,1865 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Events.c,v 3.159 2003/11/22 04:22:11 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
+ * Copyright (c) 1994-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).
+ */
+
+/* $XConsortium: xf86Events.c /main/46 1996/10/25 11:36:30 kaleb $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86Events.c,v 1.21 2005/11/08 06:33:28 jkj Exp $ */
+
+/* [JCH-96/01/21] Extended std reverse map to four buttons. */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+
+#include <X11/X.h>
+#include <X11/Xpoll.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+
+
+#ifdef XFreeXDGA
+#include "dgaproc.h"
+#endif
+
+#ifdef XINPUT
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#else
+#include "inputstr.h"
+#endif
+#include "xf86Xinput.h"
+
+#include "mi.h"
+#include "mipointer.h"
+
+#ifdef XF86BIGFONT
+#define _XF86BIGFONT_SERVER_
+#include <X11/extensions/xf86bigfont.h>
+#endif
+
+#ifdef XKB
+extern Bool noXkbExtension;
+#endif
+
+#ifdef DPMSExtension
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+#include "dpmsproc.h"
+#endif
+
+#define XE_POINTER 1
+#define XE_KEYBOARD 2
+
+#ifdef XINPUT
+#define __EqEnqueue(ev) xf86eqEnqueue(ev)
+#else
+#define __EqEnqueue(ev) mieqEnqueue(ev)
+#endif
+
+#define EqEnqueue(ev) { \
+ int __sigstate = xf86BlockSIGIO (); \
+ __EqEnqueue (ev); \
+ xf86UnblockSIGIO(__sigstate); \
+}
+
+#ifdef XTESTEXT1
+
+#define XTestSERVER_SIDE
+#include <X11/extensions/xtestext1.h>
+extern short xtest_mousex;
+extern short xtest_mousey;
+extern int on_steal_input;
+extern Bool XTestStealKeyData();
+extern void XTestStealMotionData();
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ if (!on_steal_input || \
+ XTestStealKeyData((ev)->u.u.detail, (ev)->u.u.type, dev_type, \
+ xtest_mousex, xtest_mousey)) \
+ EqEnqueue((ev))
+#else /* ! XTESTEXT1 */
+
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ EqEnqueue((ev))
+
+#endif
+
+/*
+ * The first of many hacks to get VT switching to work under
+ * Solaris 2.1 for x86. The basic problem is that Solaris is supposed
+ * to be SVR4. It is for the most part, except where the video interface
+ * is concerned. These hacks work around those problems.
+ * See the comments for Linux, and SCO.
+ *
+ * This is a toggling variable:
+ * FALSE = No VT switching keys have been pressed last time around
+ * TRUE = Possible VT switch Pending
+ * (DWH - 12/2/93)
+ *
+ * This has been generalised to work with Linux and *BSD+syscons (DHD)
+ */
+
+#ifdef USE_VT_SYSREQ
+Bool VTSysreqToggle = FALSE;
+#endif /* !USE_VT_SYSREQ */
+Bool VTSwitchEnabled = TRUE; /* Allows run-time disabling for
+ *BSD and for avoiding VT
+ switches when using the DRI
+ automatic full screen mode.*/
+
+extern fd_set EnabledDevices;
+
+#if defined(XQUEUE)
+extern void xf86XqueRequest(void);
+#endif
+#ifdef XF86PM
+extern void (*xf86OSPMClose)(void);
+#endif
+
+static void xf86VTSwitch(void);
+
+/*
+ * Allow arbitrary drivers or other XFree86 code to register with our main
+ * Wakeup handler.
+ */
+typedef struct x_IHRec {
+ int fd;
+ InputHandlerProc ihproc;
+ pointer data;
+ Bool enabled;
+ struct x_IHRec * next;
+} IHRec, *IHPtr;
+
+static IHPtr InputHandlers = NULL;
+
+
+/*
+ * TimeSinceLastInputEvent --
+ * Function used for screensaver purposes by the os module. Returns the
+ * time in milliseconds since there last was any input.
+ */
+
+int
+TimeSinceLastInputEvent()
+{
+ if (xf86Info.lastEventTime == 0) {
+ xf86Info.lastEventTime = GetTimeInMillis();
+ }
+ return GetTimeInMillis() - xf86Info.lastEventTime;
+}
+
+
+
+/*
+ * SetTimeSinceLastInputEvent --
+ * Set the lastEventTime to now.
+ */
+
+void
+SetTimeSinceLastInputEvent()
+{
+ xf86Info.lastEventTime = GetTimeInMillis();
+}
+
+
+
+/*
+ * ProcessInputEvents --
+ * Retrieve all waiting input events and pass them to DIX in their
+ * correct chronological order. Only reads from the system pointer
+ * and keyboard.
+ */
+
+void
+ProcessInputEvents ()
+{
+ int x, y;
+#ifdef INHERIT_LOCK_STATE
+ static int generation = 0;
+#endif
+
+ /*
+ * With INHERIT_LOCK_STATE defined, the initial state of CapsLock, NumLock
+ * and ScrollLock will be set to match that of the VT the server is
+ * running on.
+ */
+#ifdef INHERIT_LOCK_STATE
+ if (generation != serverGeneration) {
+ xEvent kevent;
+ DevicePtr pKeyboard = xf86Info.pKeyboard;
+ extern unsigned int xf86InitialCaps, xf86InitialNum, xf86InitialScroll;
+
+ generation = serverGeneration;
+ kevent.u.keyButtonPointer.time = GetTimeInMillis();
+ kevent.u.keyButtonPointer.rootX = 0;
+ kevent.u.keyButtonPointer.rootY = 0;
+ kevent.u.u.type = KeyPress;
+
+
+ if (xf86InitialCaps) {
+ kevent.u.u.detail = xf86InitialCaps;
+ (* pKeyboard->processInputProc)(&kevent, (DeviceIntPtr)pKeyboard, 1);
+ xf86InitialCaps = 0;
+ }
+ if (xf86InitialNum) {
+ kevent.u.u.detail = xf86InitialNum;
+ (* pKeyboard->processInputProc)(&kevent, (DeviceIntPtr)pKeyboard, 1);
+ xf86InitialNum = 0;
+ }
+ if (xf86InitialScroll) {
+ kevent.u.u.detail = xf86InitialScroll;
+ (* pKeyboard->processInputProc)(&kevent, (DeviceIntPtr)pKeyboard, 1);
+ xf86InitialScroll = 0;
+ }
+ }
+#endif
+
+ xf86Info.inputPending = FALSE;
+
+#ifdef XINPUT
+ xf86eqProcessInputEvents();
+#else
+ mieqProcessInputEvents();
+#endif
+ miPointerUpdate();
+
+ miPointerPosition(&x, &y);
+ xf86SetViewport(xf86Info.currentScreen, x, y);
+}
+
+void
+xf86GrabServerCallback(CallbackListPtr *callbacks, pointer data, pointer args)
+{
+ ServerGrabInfoRec *grab = (ServerGrabInfoRec*)args;
+
+ xf86Info.grabInfo.server.client = grab->client;
+ xf86Info.grabInfo.server.grabstate = grab->grabstate;
+}
+
+/*
+ * Handle keyboard events that cause some kind of "action"
+ * (i.e., server termination, video mode changes, VT switches, etc.)
+ */
+void
+xf86ProcessActionEvent(ActionEvent action, void *arg)
+{
+#ifdef DEBUG
+ ErrorF("ProcessActionEvent(%d,%x)\n", (int) action, arg);
+#endif
+ switch (action) {
+ case ACTION_TERMINATE:
+ if (!xf86Info.dontZap) {
+#ifdef XFreeXDGA
+ DGAShutdown();
+#endif
+ GiveUp(0);
+ }
+ break;
+ case ACTION_NEXT_MODE:
+ if (!xf86Info.dontZoom)
+ xf86ZoomViewport(xf86Info.currentScreen, 1);
+ break;
+ case ACTION_PREV_MODE:
+ if (!xf86Info.dontZoom)
+ xf86ZoomViewport(xf86Info.currentScreen, -1);
+ break;
+ case ACTION_DISABLEGRAB:
+ if (!xf86Info.grabInfo.disabled && xf86Info.grabInfo.allowDeactivate) {
+ if (inputInfo.pointer && inputInfo.pointer->grab != NULL &&
+ inputInfo.pointer->DeactivateGrab)
+ inputInfo.pointer->DeactivateGrab(inputInfo.pointer);
+ if (inputInfo.keyboard && inputInfo.keyboard->grab != NULL &&
+ inputInfo.keyboard->DeactivateGrab)
+ inputInfo.keyboard->DeactivateGrab(inputInfo.keyboard);
+ }
+ break;
+ case ACTION_CLOSECLIENT:
+ if (!xf86Info.grabInfo.disabled && xf86Info.grabInfo.allowClosedown) {
+ ClientPtr pointer, keyboard, server;
+
+ pointer = keyboard = server = NULL;
+ if (inputInfo.pointer && inputInfo.pointer->grab != NULL)
+ pointer = clients[CLIENT_ID(inputInfo.pointer->grab->resource)];
+ if (inputInfo.keyboard && inputInfo.keyboard->grab != NULL) {
+ keyboard = clients[CLIENT_ID(inputInfo.keyboard->grab->resource)];
+ if (keyboard == pointer)
+ keyboard = NULL;
+ }
+ if ((xf86Info.grabInfo.server.grabstate == SERVER_GRABBED) &&
+ (((server = xf86Info.grabInfo.server.client) == pointer) ||
+ (server == keyboard)))
+ server = NULL;
+
+ if (pointer)
+ CloseDownClient(pointer);
+ if (keyboard)
+ CloseDownClient(keyboard);
+ if (server)
+ CloseDownClient(server);
+ }
+ break;
+#if !defined(__SOL8__) && !defined(__UNIXOS2__) && !defined(sgi) && \
+ (!defined(sun) || defined(i386)) && defined(VT_ACTIVATE)
+ case ACTION_SWITCHSCREEN:
+ if (VTSwitchEnabled && !xf86Info.dontVTSwitch && arg) {
+ int vtno = *((int *) arg);
+#if defined(__SCO__) || defined(__UNIXWARE__)
+ vtno--;
+#endif
+#if defined(QNX4)
+ xf86Info.vtRequestsPending = vtno;
+#else
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vtno) < 0)
+ ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
+#endif
+ }
+ break;
+ case ACTION_SWITCHSCREEN_NEXT:
+ if (VTSwitchEnabled && !xf86Info.dontVTSwitch) {
+/* Shouldn't this be true for (sun) && (i386) && (SVR4) ? */
+#if defined(__SCO__) || defined(__UNIXWARE__)
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
+#else
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno + 1) < 0)
+#endif
+#if defined (__SCO__) || (defined(sun) && defined (i386) && defined (SVR4)) || defined(__UNIXWARE__)
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 0) < 0)
+#else
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) < 0)
+#endif
+ ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
+ }
+ break;
+ case ACTION_SWITCHSCREEN_PREV:
+ if (VTSwitchEnabled && !xf86Info.dontVTSwitch && xf86Info.vtno > 0) {
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno - 1) < 0)
+ ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
+ }
+ break;
+#endif
+ case ACTION_MESSAGE:
+ {
+ char *retstr, *message = (char *) arg;
+ ScrnInfoPtr pScr = XF86SCRNINFO(xf86Info.currentScreen);
+
+#ifdef DEBUG
+ ErrorF("ActionMessage: '%s'\n", message);
+#endif
+ /* Okay the message made it to the ddx. The common layer */
+ /* can check for relevant messages here and react to any */
+ /* that have a global effect. For example: */
+ /* */
+ /* if (!strcmp(message, "foo") { */
+ /* do_foo(); break */
+ /* } */
+ /* */
+ /* otherwise fallback to sending a key event message to */
+ /* the current screen's driver: */
+ if (*pScr->HandleMessage != NULL) {
+ (void) (*pScr->HandleMessage)(pScr->scrnIndex,
+ "KeyEventMessage", message, &retstr);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+/*
+ * xf86PostKbdEvent --
+ * Translate the raw hardware KbdEvent into an XEvent, and tell DIX
+ * about it. Scancode preprocessing and so on is done ...
+ *
+ * OS/2 specific xf86PostKbdEvent(key) has been moved to os-support/os2/os2_kbd.c
+ * as some things differ, and I did not want to scatter this routine with
+ * ifdefs further (hv).
+ */
+
+#ifdef __linux__
+extern u_char SpecialServerMap[];
+#endif
+
+#if !defined(__UNIXOS2__)
+void
+xf86PostKbdEvent(unsigned key)
+{
+ int scanCode = (key & 0x7f);
+ int specialkey = 0;
+ Bool down = (key & 0x80 ? FALSE : TRUE);
+ KeyClassRec *keyc = ((DeviceIntPtr)xf86Info.pKeyboard)->key;
+ Bool updateLeds = FALSE;
+ Bool UsePrefix = FALSE;
+ Bool Direction = FALSE;
+ xEvent kevent;
+ KeySym *keysym;
+ int keycode;
+ static int lockkeys = 0;
+#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
+ static Bool first_time = TRUE;
+#endif
+#if defined(__sparc__) && defined(__linux__)
+ static int kbdSun = -1;
+#endif
+ /* Disable any keyboard processing while in suspend */
+ if (xf86inSuspend)
+ return;
+
+#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
+ if (first_time)
+ {
+ first_time = FALSE;
+ VTSwitchEnabled = (xf86Info.consType == SYSCONS)
+ || (xf86Info.consType == PCVT);
+ }
+#endif
+
+#if defined (__sparc__) && defined(__linux__)
+ if (kbdSun == -1) {
+ if ((xf86Info.xkbmodel && !strcmp(xf86Info.xkbmodel, "sun"))
+ || (xf86Info.xkbrules && !strcmp(xf86Info.xkbrules, "sun")))
+ kbdSun = 1;
+ else
+ kbdSun = 0;
+ }
+ if (kbdSun)
+ goto special;
+#endif /* __sparc__ && __linux__ */
+
+#ifdef __linux__
+ if (xf86Info.kbdCustomKeycodes) {
+ specialkey = SpecialServerMap[scanCode];
+ goto customkeycodes;
+ }
+#endif
+
+ /*
+ * First do some special scancode remapping ...
+ */
+ if (xf86Info.scanPrefix == 0) {
+
+ switch (scanCode) {
+ case KEY_Prefix0:
+ case KEY_Prefix1:
+#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
+ if (xf86Info.consType == PCCONS || xf86Info.consType == SYSCONS
+ || xf86Info.consType == PCVT
+#ifdef WSCONS_SUPPORT
+ || (xf86Info.consType == WSCONS && xf86Info.kbdEvents != xf86WSKbdEvents)
+#endif
+ ) {
+#endif
+ xf86Info.scanPrefix = scanCode; /* special prefixes */
+ return;
+#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
+ }
+ break;
+#endif
+ }
+#if defined (i386) && defined (SVR4)
+ /*
+ * PANIX returns DICOP standards based keycodes in using 106jp
+ * keyboard. We need to remap some keys.
+ */
+ if(xf86Info.panix106 == TRUE){
+ switch (scanCode) {
+ case 0x56: scanCode = KEY_BSlash2; break; /* Backslash */
+ case 0x5A: scanCode = KEY_NFER; break; /* No Kanji Transfer*/
+ case 0x5B: scanCode = KEY_XFER; break; /* Kanji Tranfer */
+ case 0x5C: scanCode = KEY_Yen; break; /* Yen curs pgup */
+ case 0x6B: scanCode = KEY_Left; break; /* Cur Left */
+ case 0x6F: scanCode = KEY_PgUp; break; /* Cur PageUp */
+ case 0x72: scanCode = KEY_AltLang; break; /* AltLang(right) */
+ case 0x73: scanCode = KEY_RCtrl; break; /* not needed */
+ }
+ } else
+#endif /* i386 && SVR4 */
+ {
+ switch (scanCode) {
+ case 0x59: scanCode = KEY_0x59; break;
+ case 0x5a: scanCode = KEY_0x5A; break;
+ case 0x5b: scanCode = KEY_0x5B; break;
+ case 0x5c: scanCode = KEY_KP_Equal; break; /* Keypad Equal */
+ case 0x5d: scanCode = KEY_0x5D; break;
+ case 0x5e: scanCode = KEY_0x5E; break;
+ case 0x5f: scanCode = KEY_0x5F; break;
+ case 0x62: scanCode = KEY_0x62; break;
+ case 0x63: scanCode = KEY_0x63; break;
+ case 0x64: scanCode = KEY_0x64; break;
+ case 0x65: scanCode = KEY_0x65; break;
+ case 0x66: scanCode = KEY_0x66; break;
+ case 0x67: scanCode = KEY_0x67; break;
+ case 0x68: scanCode = KEY_0x68; break;
+ case 0x69: scanCode = KEY_0x69; break;
+ case 0x6a: scanCode = KEY_0x6A; break;
+ case 0x6b: scanCode = KEY_0x6B; break;
+ case 0x6c: scanCode = KEY_0x6C; break;
+ case 0x6d: scanCode = KEY_0x6D; break;
+ case 0x6e: scanCode = KEY_0x6E; break;
+ case 0x6f: scanCode = KEY_0x6F; break;
+ case 0x70: scanCode = KEY_0x70; break;
+ case 0x71: scanCode = KEY_0x71; break;
+ case 0x72: scanCode = KEY_0x72; break;
+ case 0x73: scanCode = KEY_0x73; break;
+ case 0x74: scanCode = KEY_0x74; break;
+ case 0x75: scanCode = KEY_0x75; break;
+ case 0x76: scanCode = KEY_0x76; break;
+ }
+ }
+ }
+
+ else if (
+#ifdef CSRG_BASED
+ (xf86Info.consType == PCCONS || xf86Info.consType == SYSCONS
+ || xf86Info.consType == PCVT
+#ifdef WSCONS_SUPPORT
+ || (xf86Info.consType == WSCONS && xf86Info.kbdEvents !=
+ xf86WSKbdEvents)
+#endif
+ ) &&
+#endif
+ (xf86Info.scanPrefix == KEY_Prefix0)) {
+ xf86Info.scanPrefix = 0;
+
+ switch (scanCode) {
+ case KEY_KP_7: scanCode = KEY_Home; break; /* curs home */
+ case KEY_KP_8: scanCode = KEY_Up; break; /* curs up */
+ case KEY_KP_9: scanCode = KEY_PgUp; break; /* curs pgup */
+ case KEY_KP_4: scanCode = KEY_Left; break; /* curs left */
+ case KEY_KP_5: scanCode = KEY_Begin; break; /* curs begin */
+ case KEY_KP_6: scanCode = KEY_Right; break; /* curs right */
+ case KEY_KP_1: scanCode = KEY_End; break; /* curs end */
+ case KEY_KP_2: scanCode = KEY_Down; break; /* curs down */
+ case KEY_KP_3: scanCode = KEY_PgDown; break; /* curs pgdown */
+ case KEY_KP_0: scanCode = KEY_Insert; break; /* curs insert */
+ case KEY_KP_Decimal: scanCode = KEY_Delete; break; /* curs delete */
+ case KEY_Enter: scanCode = KEY_KP_Enter; break; /* keypad enter */
+ case KEY_LCtrl: scanCode = KEY_RCtrl; break; /* right ctrl */
+ case KEY_KP_Multiply: scanCode = KEY_Print; break; /* print */
+ case KEY_Slash: scanCode = KEY_KP_Divide; break; /* keyp divide */
+ case KEY_Alt: scanCode = KEY_AltLang; break; /* right alt */
+ case KEY_ScrollLock: scanCode = KEY_Break; break; /* curs break */
+ case 0x5b: scanCode = KEY_LMeta; break;
+ case 0x5c: scanCode = KEY_RMeta; break;
+ case 0x5d: scanCode = KEY_Menu; break;
+ case KEY_F3: scanCode = KEY_F13; break;
+ case KEY_F4: scanCode = KEY_F14; break;
+ case KEY_F5: scanCode = KEY_F15; break;
+ case KEY_F6: scanCode = KEY_F16; break;
+ case KEY_F7: scanCode = KEY_F17; break;
+ case KEY_KP_Plus: scanCode = KEY_KP_DEC; break;
+ /*
+ * Ignore virtual shifts (E0 2A, E0 AA, E0 36, E0 B6)
+ */
+ case 0x2A:
+ case 0x36:
+ return;
+ default:
+ xf86MsgVerb(X_INFO, 4, "Unreported Prefix0 scancode: 0x%02x\n",
+ scanCode);
+ /*
+ * "Internet" keyboards are generating lots of new codes. Let them
+ * pass. There is little consistency between them, so don't bother
+ * with symbolic names at this level.
+ */
+ scanCode += 0x78;
+ }
+ }
+
+ else if (xf86Info.scanPrefix == KEY_Prefix1)
+ {
+ xf86Info.scanPrefix = (scanCode == KEY_LCtrl) ? KEY_LCtrl : 0;
+ return;
+ }
+
+ else if (xf86Info.scanPrefix == KEY_LCtrl)
+ {
+ xf86Info.scanPrefix = 0;
+ if (scanCode != KEY_NumLock) return;
+ scanCode = KEY_Pause; /* pause */
+ }
+
+#ifndef __sparc64__
+ /*
+ * PC keyboards generate separate key codes for
+ * Alt+Print and Control+Pause but in the X keyboard model
+ * they need to get the same key code as the base key on the same
+ * physical keyboard key.
+ */
+ if (scanCode == KEY_SysReqest)
+ scanCode = KEY_Print;
+ else if (scanCode == KEY_Break)
+ scanCode = KEY_Pause;
+#endif
+
+ /*
+ * and now get some special keysequences
+ */
+
+ specialkey = scanCode;
+
+#ifdef __linux__
+customkeycodes:
+#endif
+#if defined(i386) || defined(__i386__)
+ if (xf86IsPc98()) {
+ switch (scanCode) {
+ case 0x0e: specialkey = 0x0e; break; /* KEY_BackSpace */
+ case 0x40: specialkey = 0x4a; break; /* KEY_KP_Minus */
+ case 0x49: specialkey = 0x4e; break; /* KEY_KP_Plus */
+
+ /* XXX needs cases for KEY_KP_Divide and KEY_KP_Multiply */
+
+ case 0x62: specialkey = 0x3b; break; /* KEY_F1 */
+ case 0x63: specialkey = 0x3c; break; /* KEY_F2 */
+ case 0x64: specialkey = 0x3d; break; /* KEY_F3 */
+ case 0x65: specialkey = 0x3e; break; /* KEY_F4 */
+ case 0x66: specialkey = 0x3f; break; /* KEY_F5 */
+ case 0x67: specialkey = 0x40; break; /* KEY_F6 */
+ case 0x68: specialkey = 0x41; break; /* KEY_F7 */
+ case 0x69: specialkey = 0x42; break; /* KEY_F8 */
+ case 0x6a: specialkey = 0x43; break; /* KEY_F9 */
+ case 0x6b: specialkey = 0x44; break; /* KEY_F10 */
+ /* case 0x73: specialkey = 0x38; break; KEY_Alt */
+ /* case 0x74: specialkey = 0x1d; break; KEY_LCtrl */
+ default: specialkey = 0x00; break;
+ }
+ }
+#endif
+#if defined (__sparc__) && defined(__linux__)
+special:
+ if (kbdSun) {
+ switch (scanCode) {
+ case 0x2b: specialkey = KEY_BackSpace; break;
+ case 0x47: specialkey = KEY_KP_Minus; break;
+ case 0x7d: specialkey = KEY_KP_Plus; break;
+
+ /* XXX needs cases for KEY_KP_Divide and KEY_KP_Multiply */
+
+ case 0x05: specialkey = KEY_F1; break;
+ case 0x06: specialkey = KEY_F2; break;
+ case 0x08: specialkey = KEY_F3; break;
+ case 0x0a: specialkey = KEY_F4; break;
+ case 0x0c: specialkey = KEY_F5; break;
+ case 0x0e: specialkey = KEY_F6; break;
+ case 0x10: specialkey = KEY_F7; break;
+ case 0x11: specialkey = KEY_F8; break;
+ case 0x12: specialkey = KEY_F9; break;
+ case 0x07: specialkey = KEY_F10; break;
+ case 0x09: specialkey = KEY_F11; break;
+ case 0x0b: specialkey = KEY_F12; break;
+ default: specialkey = 0; break;
+ }
+ /*
+ * XXX XXX XXX:
+ *
+ * I really don't know what's wrong here, but passing the real
+ * scanCode offsets by one from XKB's point of view.
+ *
+ * (ecd@skynet.be, 980405)
+ */
+ scanCode--;
+ }
+#endif /* defined (__sparc__) && defined(__linux__) */
+
+#ifdef XKB
+ if ((xf86Info.ddxSpecialKeys == SKWhenNeeded &&
+ !xf86Info.ActionKeyBindingsSet) ||
+ noXkbExtension || xf86Info.ddxSpecialKeys == SKAlways) {
+#endif
+ if (!(ModifierDown(ShiftMask)) &&
+ ((ModifierDown(ControlMask | AltMask)) ||
+ (ModifierDown(ControlMask | AltLangMask))))
+ {
+ switch (specialkey) {
+
+ case KEY_BackSpace:
+ xf86ProcessActionEvent(ACTION_TERMINATE, NULL);
+ break;
+
+ /*
+ * Check grabs
+ */
+ case KEY_KP_Divide:
+ xf86ProcessActionEvent(ACTION_DISABLEGRAB, NULL);
+ break;
+ case KEY_KP_Multiply:
+ xf86ProcessActionEvent(ACTION_CLOSECLIENT, NULL);
+ break;
+
+ /*
+ * Video mode switches
+ */
+ case KEY_KP_Minus: /* Keypad - */
+ if (down) xf86ProcessActionEvent(ACTION_PREV_MODE, NULL);
+ if (!xf86Info.dontZoom) return;
+ break;
+
+ case KEY_KP_Plus: /* Keypad + */
+ if (down) xf86ProcessActionEvent(ACTION_NEXT_MODE, NULL);
+ if (!xf86Info.dontZoom) return;
+ break;
+
+ /* Under QNX4, we set the vtPending flag for VT switching and
+ * let the VT switch function do the rest...
+ * This is a little different from the other OS'es.
+ */
+#if defined(QNX4)
+ case KEY_1:
+ case KEY_2:
+ case KEY_3:
+ case KEY_4:
+ case KEY_5:
+ case KEY_6:
+ case KEY_7:
+ case KEY_8:
+ case KEY_9:
+ if (VTSwitchEnabled && !xf86Info.dontVTSwitch) {
+ if (down) {
+ int vtno = specialkey - KEY_1 + 1;
+ xf86ProcessActionEvent(ACTION_SWITCHSCREEN, (void *) &vtno);
+ }
+ return;
+ }
+ break;
+#endif
+
+#if defined(linux) || (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT))) || defined(__SCO__) || defined(__UNIXWARE__)
+ /*
+ * Under Linux, the raw keycodes are consumed before the kernel
+ * does any processing on them, so we must emulate the vt switching
+ * we want ourselves.
+ */
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ case KEY_F11:
+ case KEY_F12:
+ if ((VTSwitchEnabled && !xf86Info.vtSysreq && !xf86Info.dontVTSwitch)
+#if (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)))
+ && (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT)
+#endif
+ ) {
+ int vtno = specialkey - KEY_F1 + 1;
+ if (specialkey == KEY_F11 || specialkey == KEY_F12)
+ vtno = specialkey - KEY_F11 + 11;
+ if (down)
+ xf86ProcessActionEvent(ACTION_SWITCHSCREEN, (void *) &vtno);
+ return;
+ }
+ break;
+#endif /* linux || BSD with VTs */
+
+ /* just worth mentioning here: any 386bsd keyboard driver
+ * (pccons.c or co_kbd.c) catches CTRL-ALT-DEL and CTRL-ALT-ESC
+ * before any application (e.g. XF86) will see it
+ * OBS: syscons does not, nor does pcvt !
+ */
+ }
+ }
+
+ /*
+ * Start of actual Solaris VT switching code.
+ * This should pretty much emulate standard SVR4 switching keys.
+ *
+ * DWH 12/2/93
+ */
+
+#ifdef USE_VT_SYSREQ
+ if (VTSwitchEnabled && xf86Info.vtSysreq && !xf86Info.dontVTSwitch)
+ {
+ switch (specialkey)
+ {
+ /*
+ * syscons on *BSD doesn't have a VT #0 -- don't think Linux does
+ * either
+ */
+#if defined (sun) && defined (i386) && defined (SVR4)
+ case KEY_H:
+ if (VTSysreqToggle && down)
+ {
+ xf86ProcessActionEvent(ACTION_SWITCHSCREEN, NULL);
+ VTSysreqToggle = 0;
+ return;
+ }
+ break;
+
+ /*
+ * Yah, I know the N, and P keys seem backwards, however that's
+ * how they work under Solaris
+ * XXXX N means go to next active VT not necessarily vtno+1 (or vtno-1)
+ */
+
+ case KEY_N:
+ if (VTSysreqToggle && down)
+ {
+ xf86ProcessActionEvent(ACTION_SWITCHSCREEN_NEXT, NULL);
+ VTSysreqToggle = FALSE;
+ return;
+ }
+ break;
+
+ case KEY_P:
+ if (VTSysreqToggle && down)
+ {
+ xf86ProcessActionEvent(ACTION_SWITCHSCREEN_NEXT, NULL);
+ VTSysreqToggle = FALSE;
+ return;
+ }
+ break;
+#endif
+
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ case KEY_F11:
+ case KEY_F12:
+ if (VTSysreqToggle && down)
+ { int vtno = specialkey - KEY_F1 + 1;
+ if (specialkey == KEY_F11 || specialkey == KEY_F12)
+ vtno = specialkey - KEY_F11 + 11;
+ xf86ProcessActionEvent(ACTION_SWITCHSCREEN, (void *) &vtno);
+ VTSysreqToggle = FALSE;
+ return;
+ }
+ break;
+
+ /* Ignore these keys -- ie don't let them cancel an alt-sysreq */
+ case KEY_Alt:
+ case KEY_AltLang:
+ break;
+
+ case KEY_SysReqest:
+ if (down && (ModifierDown(AltMask) || ModifierDown(AltLangMask)))
+ VTSysreqToggle = TRUE;
+ break;
+
+ default:
+ if (VTSysreqToggle)
+ {
+ /*
+ * We only land here when Alt-SysReq is followed by a
+ * non-switching key.
+ */
+ VTSysreqToggle = FALSE;
+
+ }
+ }
+ }
+
+#endif /* USE_VT_SYSREQ */
+
+#ifdef __SCO__
+ /*
+ * With the console in raw mode, SCO will not switch consoles,
+ * you get around this by activating the next console along, if
+ * this fails then go back to console 0, if there is only one
+ * then it doesn't matter, switching to yourself is a nop as far
+ * as the console driver is concerned.
+ * We could do something similar to linux here but SCO ODT uses
+ * Ctrl-PrintScrn, so why change?
+ */
+ if (specialkey == KEY_Print && ModifierDown(ControlMask)) {
+ if (down)
+ xf86ProcessActionEvent(ACTION_SWITCHSCREEN_NEXT, NULL);
+ return;
+ }
+#endif /* __SCO__ */
+#ifdef XKB
+ }
+#endif
+
+ /*
+ * Now map the scancodes to real X-keycodes ...
+ */
+ keycode = scanCode + MIN_KEYCODE;
+ keysym = (keyc->curKeySyms.map +
+ keyc->curKeySyms.mapWidth *
+ (keycode - keyc->curKeySyms.minKeyCode));
+#ifdef XKB
+ if (noXkbExtension) {
+#endif
+ /*
+ * Filter autorepeated caps/num/scroll lock keycodes.
+ */
+#define CAPSFLAG 0x01
+#define NUMFLAG 0x02
+#define SCROLLFLAG 0x04
+#define MODEFLAG 0x08
+ if( down ) {
+ switch( keysym[0] ) {
+ case XK_Caps_Lock :
+ if (lockkeys & CAPSFLAG)
+ return;
+ else
+ lockkeys |= CAPSFLAG;
+ break;
+
+ case XK_Num_Lock :
+ if (lockkeys & NUMFLAG)
+ return;
+ else
+ lockkeys |= NUMFLAG;
+ break;
+
+ case XK_Scroll_Lock :
+ if (lockkeys & SCROLLFLAG)
+ return;
+ else
+ lockkeys |= SCROLLFLAG;
+ break;
+ }
+ if (keysym[1] == XF86XK_ModeLock)
+ {
+ if (lockkeys & MODEFLAG)
+ return;
+ else
+ lockkeys |= MODEFLAG;
+ }
+
+ }
+ else {
+ switch( keysym[0] ) {
+ case XK_Caps_Lock :
+ lockkeys &= ~CAPSFLAG;
+ break;
+
+ case XK_Num_Lock :
+ lockkeys &= ~NUMFLAG;
+ break;
+
+ case XK_Scroll_Lock :
+ lockkeys &= ~SCROLLFLAG;
+ break;
+ }
+ if (keysym[1] == XF86XK_ModeLock)
+ lockkeys &= ~MODEFLAG;
+ }
+
+ /*
+ * LockKey special handling:
+ * ignore releases, toggle on & off on presses.
+ * Don't deal with the Caps_Lock keysym directly, but check the lock modifier
+ */
+ if (keyc->modifierMap[keycode] & LockMask ||
+ keysym[0] == XK_Scroll_Lock ||
+ keysym[1] == XF86XK_ModeLock ||
+ keysym[0] == XK_Num_Lock)
+ {
+ Bool flag;
+
+ if (!down) return;
+ if (KeyPressed(keycode)) {
+ down = !down;
+ flag = FALSE;
+ }
+ else
+ flag = TRUE;
+
+ if (keyc->modifierMap[keycode] & LockMask) xf86Info.capsLock = flag;
+ if (keysym[0] == XK_Num_Lock) xf86Info.numLock = flag;
+ if (keysym[0] == XK_Scroll_Lock) xf86Info.scrollLock = flag;
+ if (keysym[1] == XF86XK_ModeLock) xf86Info.modeSwitchLock = flag;
+ updateLeds = TRUE;
+ }
+
+ if (!xf86Info.kbdCustomKeycodes) {
+ /*
+ * normal, non-keypad keys
+ */
+ if (scanCode < KEY_KP_7 || scanCode > KEY_KP_Decimal) {
+#if !defined(CSRG_BASED) && \
+ !defined(__GNU__) && \
+ defined(KB_84)
+ /*
+ * magic ALT_L key on AT84 keyboards for multilingual support
+ */
+ if (xf86Info.kbdType == KB_84 &&
+ ModifierDown(AltMask) &&
+ keysym[2] != NoSymbol)
+ {
+ UsePrefix = TRUE;
+ Direction = TRUE;
+ }
+#endif /* !CSRG_BASED && ... */
+ }
+ }
+ if (updateLeds) xf86UpdateKbdLeds();
+#ifdef XKB
+ }
+#endif
+
+ /*
+ * check for an autorepeat-event
+ */
+ if (down && KeyPressed(keycode)) {
+ KbdFeedbackClassRec *kbdfeed = ((DeviceIntPtr)xf86Info.pKeyboard)->kbdfeed;
+ if ((xf86Info.autoRepeat != AutoRepeatModeOn) ||
+ keyc->modifierMap[keycode] ||
+ (kbdfeed && !(kbdfeed->ctrl.autoRepeats[keycode>>3] & ( 1<<(keycode&7) ))))
+ return;
+ }
+
+
+ xf86Info.lastEventTime = kevent.u.keyButtonPointer.time = GetTimeInMillis();
+ /*
+ * And now send these prefixes ...
+ * NOTE: There cannot be multiple Mode_Switch keys !!!!
+ */
+ if (UsePrefix)
+ {
+ ENQUEUE(&kevent,
+ keyc->modifierKeyMap[keyc->maxKeysPerModifier*7],
+ (Direction ? KeyPress : KeyRelease),
+ XE_KEYBOARD);
+ ENQUEUE(&kevent, keycode, (down ? KeyPress : KeyRelease), XE_KEYBOARD);
+ ENQUEUE(&kevent,
+ keyc->modifierKeyMap[keyc->maxKeysPerModifier*7],
+ (Direction ? KeyRelease : KeyPress),
+ XE_KEYBOARD);
+ }
+ else
+ {
+ ENQUEUE(&kevent, keycode, (down ? KeyPress : KeyRelease), XE_KEYBOARD);
+ }
+}
+#endif /* !__UNIXOS2__ */
+
+#define ModifierIsSet(k) ((modifiers & (k)) == (k))
+
+Bool
+xf86CommonSpecialKey(int key, Bool down, int modifiers)
+{
+ if ((!ModifierIsSet(ShiftMask)) &&
+ (((ModifierIsSet(ControlMask | AltMask)) ||
+ (ModifierIsSet(ControlMask | AltLangMask))))) {
+ switch (key) {
+
+ case KEY_BackSpace:
+ xf86ProcessActionEvent(ACTION_TERMINATE, NULL);
+ break;
+
+ /*
+ * Check grabs
+ */
+ case KEY_KP_Divide:
+ xf86ProcessActionEvent(ACTION_DISABLEGRAB, NULL);
+ break;
+ case KEY_KP_Multiply:
+ xf86ProcessActionEvent(ACTION_CLOSECLIENT, NULL);
+ break;
+
+ /*
+ * The idea here is to pass the scancode down to a list of
+ * registered routines. There should be some standard conventions
+ * for processing certain keys.
+ */
+ case KEY_KP_Minus: /* Keypad - */
+ if (down) xf86ProcessActionEvent(ACTION_PREV_MODE, NULL);
+ if (!xf86Info.dontZoom) return TRUE;
+ break;
+
+ case KEY_KP_Plus: /* Keypad + */
+ if (down) xf86ProcessActionEvent(ACTION_NEXT_MODE, NULL);
+ if (!xf86Info.dontZoom) return TRUE;
+ break;
+ }
+ }
+ return FALSE;
+}
+
+/*
+ * xf86Wakeup --
+ * Os wakeup handler.
+ */
+
+/* ARGSUSED */
+void
+xf86Wakeup(pointer blockData, int err, pointer pReadmask)
+{
+#if !defined(__UNIXOS2__) && !defined(__QNX__)
+ fd_set* LastSelectMask = (fd_set*)pReadmask;
+ fd_set devicesWithInput;
+ InputInfoPtr pInfo;
+
+ if (err >= 0) {
+
+ XFD_ANDSET(&devicesWithInput, LastSelectMask, &EnabledDevices);
+ if (XFD_ANYSET(&devicesWithInput)) {
+ if (xf86Info.kbdEvents)
+ (xf86Info.kbdEvents)();
+ pInfo = xf86InputDevs;
+ while (pInfo) {
+ if (pInfo->read_input && pInfo->fd >= 0 &&
+ (FD_ISSET(pInfo->fd, &devicesWithInput) != 0)) {
+ int sigstate = xf86BlockSIGIO();
+
+ pInfo->read_input(pInfo);
+ xf86UnblockSIGIO(sigstate);
+ /*
+ * Remove the descriptior from the set because more than one
+ * device may share the same file descriptor.
+ */
+ FD_CLR(pInfo->fd, &devicesWithInput);
+ }
+ pInfo = pInfo->next;
+ }
+ }
+ }
+#else /* __UNIXOS2__ and __QNX__ */
+
+ InputInfoPtr pInfo;
+
+ (xf86Info.kbdEvents)(); /* Under OS/2 and QNX, always call */
+
+ pInfo = xf86InputDevs;
+ while (pInfo) {
+ if (pInfo->read_input && pInfo->fd >= 0) {
+ int sigstate = xf86BlockSIGIO();
+
+ pInfo->read_input(pInfo);
+ xf86UnblockSIGIO(sigstate);
+ /*
+ * Must break here because more than one device may share
+ * the same file descriptor.
+ */
+ break;
+ }
+ pInfo = pInfo->next;
+ }
+
+#endif /* __UNIXOS2__ and __QNX__ */
+
+ if (err >= 0) { /* we don't want the handlers called if select() */
+ IHPtr ih; /* returned with an error condition, do we? */
+
+ for (ih = InputHandlers; ih; ih = ih->next) {
+ if (ih->enabled && ih->fd >= 0 && ih->ihproc &&
+ (FD_ISSET(ih->fd, ((fd_set *)pReadmask)) != 0)) {
+ ih->ihproc(ih->fd, ih->data);
+ }
+ }
+ }
+
+ if (xf86VTSwitchPending()) xf86VTSwitch();
+
+ if (xf86Info.inputPending) ProcessInputEvents();
+}
+
+
+/*
+ * xf86SigioReadInput --
+ * signal handler for the SIGIO signal.
+ */
+static void
+xf86SigioReadInput(int fd,
+ void *closure)
+{
+ int sigstate = xf86BlockSIGIO();
+ InputInfoPtr pInfo = (InputInfoPtr) closure;
+
+ pInfo->read_input(pInfo);
+
+ xf86UnblockSIGIO(sigstate);
+}
+
+/*
+ * xf86AddEnabledDevice --
+ *
+ */
+void
+xf86AddEnabledDevice(InputInfoPtr pInfo)
+{
+ if (!xf86InstallSIGIOHandler (pInfo->fd, xf86SigioReadInput, pInfo)) {
+ AddEnabledDevice(pInfo->fd);
+ }
+}
+
+/*
+ * xf86RemoveEnabledDevice --
+ *
+ */
+void
+xf86RemoveEnabledDevice(InputInfoPtr pInfo)
+{
+ if (!xf86RemoveSIGIOHandler (pInfo->fd)) {
+ RemoveEnabledDevice(pInfo->fd);
+ }
+}
+
+static int *xf86SignalIntercept = NULL;
+
+void
+xf86InterceptSignals(int *signo)
+{
+ if ((xf86SignalIntercept = signo))
+ *signo = -1;
+}
+
+static void (*xf86SigIllHandler)(void) = NULL;
+
+void
+xf86InterceptSigIll(void (*sigillhandler)(void))
+{
+ xf86SigIllHandler = sigillhandler;
+}
+
+#ifdef HAVE_EXECINFO_H
+#define HAVE_BACKTRACE
+#include <execinfo.h>
+#endif
+
+#ifdef HAVE_BACKTRACE
+
+static __inline__ void xorg_backtrace(void)
+{
+ void *array[32]; /* deeper nesting than this means something's wrong */
+ size_t size, i;
+ char **strings;
+ ErrorF("\nBacktrace:\n");
+ size = backtrace(array, 32);
+ strings = backtrace_symbols(array, size);
+ for (i = 0; i < size; i++)
+ ErrorF("%d: %s\n", i, strings[i]);
+ free(strings);
+}
+
+#else /* not glibc or glibc < 2.1 */
+
+# if defined(sun) && defined(__SVR4)
+# define HAVE_PSTACK
+# endif
+
+# if defined(HAVE_WALKCONTEXT) /* Solaris 9 & later */
+
+# include <ucontext.h>
+# include <signal.h>
+# include <dlfcn.h>
+# include <sys/elf.h>
+
+#ifdef _LP64
+# define ElfSym Elf64_Sym
+#else
+# define ElfSym Elf32_Sym
+#endif
+
+/* Called for each frame on the stack to print it's contents */
+static int xorg_backtrace_frame(uintptr_t pc, int signo, void *arg)
+{
+ Dl_info dlinfo;
+ ElfSym *dlsym;
+ char header[32];
+ int depth = *((int *) arg);
+
+ if (signo) {
+ char signame[SIG2STR_MAX];
+
+ if (sig2str(signo, signame) != 0) {
+ strcpy(signame, "unknown");
+ }
+
+ ErrorF("** Signal %d (%s)\n", signo, signame);
+ }
+
+ snprintf(header, sizeof(header), "%d: 0x%lx", depth, pc);
+ *((int *) arg) = depth + 1;
+
+ /* Ask system dynamic loader for info on the address */
+ if (dladdr1((void *) pc, &dlinfo, (void **) &dlsym, RTLD_DL_SYMENT)) {
+ unsigned long offset = pc - (uintptr_t) dlinfo.dli_saddr;
+ const char *symname;
+
+ if (offset < dlsym->st_size) { /* inside a function */
+ symname = dlinfo.dli_sname;
+ } else { /* found which file it was in, but not which function */
+ symname = "<section start>";
+ offset = pc - (uintptr_t)dlinfo.dli_fbase;
+ }
+ ErrorF("%s: %s:%s+0x%lx\n", header, dlinfo.dli_fname,
+ symname, offset);
+
+ } else {
+ /* Couldn't find symbol info from system dynamic loader, should
+ * probably poke elfloader here, but haven't written that code yet,
+ * so we just print the pc.
+ */
+ ErrorF("%s\n", header);
+ }
+
+ return 0;
+}
+# endif /* HAVE_WALKCONTEXT */
+
+# ifdef HAVE_PSTACK
+static int xorg_backtrace_pstack(void) {
+ pid_t kidpid;
+ int pipefd[2];
+
+ if (pipe(pipefd) != 0) {
+ return -1;
+ }
+
+ kidpid = fork1();
+
+ if (kidpid == -1) {
+ /* ERROR */
+ return -1;
+ } else if (kidpid == 0) {
+ /* CHILD */
+ char parent[16];
+
+ seteuid(0);
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ dup2(pipefd[1],STDOUT_FILENO);
+ closefrom(STDERR_FILENO);
+
+ snprintf(parent, sizeof(parent), "%d", getppid());
+ execle("/usr/bin/pstack", "pstack", parent, NULL);
+ exit(1);
+ } else {
+ /* PARENT */
+ char btline[256];
+ int kidstat;
+ int bytesread;
+ int done = 0;
+
+ close(pipefd[1]);
+
+ while (!done) {
+ bytesread = read(pipefd[0], btline, sizeof(btline) - 1);
+
+ if (bytesread > 0) {
+ btline[bytesread] = 0;
+ ErrorF("%s", btline);
+ }
+ else if ((bytesread < 0) ||
+ ((errno != EINTR) && (errno != EAGAIN)))
+ done = 1;
+ }
+ close(pipefd[0]);
+ waitpid(kidpid, &kidstat, 0);
+ if (kidstat != 0)
+ return -1;
+ }
+ return 0;
+}
+# endif /* HAVE_PSTACK */
+
+
+# if defined(HAVE_PSTACK) || defined(HAVE_WALKCONTEXT)
+
+static __inline__ void xorg_backtrace(void) {
+
+ ErrorF("\nBacktrace:\n");
+
+# ifdef HAVE_PSTACK
+/* First try fork/exec of pstack - otherwise fall back to walkcontext
+ pstack is preferred since it can print names of non-exported functions */
+
+ if (xorg_backtrace_pstack() < 0)
+# endif
+ {
+# ifdef HAVE_WALKCONTEXT
+ ucontext_t u;
+ int depth = 1;
+
+ if (getcontext(&u) == 0)
+ walkcontext(&u, xorg_backtrace_frame, &depth);
+ else
+# endif
+ Error("Failed to get backtrace info");
+ }
+ ErrorF("\n");
+}
+
+# else
+
+/* Default fallback if we can't find any way to get a backtrace */
+static __inline__ void xorg_backtrace(void) { return; }
+
+# endif
+#endif
+
+/*
+ * xf86SigHandler --
+ * Catch unexpected signals and exit or continue cleanly.
+ */
+void
+xf86SigHandler(int signo)
+{
+ if ((signo == SIGILL) && xf86SigIllHandler) {
+ (*xf86SigIllHandler)();
+ /* Re-arm handler just in case we unexpectedly return here */
+ (void) signal(signo, xf86SigHandler);
+ return;
+ }
+
+ if (xf86SignalIntercept && (*xf86SignalIntercept < 0)) {
+ *xf86SignalIntercept = signo;
+ /* Re-arm handler just in case */
+ (void) signal(signo, xf86SigHandler);
+ return;
+ }
+
+ signal(signo,SIG_IGN);
+ xf86Info.caughtSignal = TRUE;
+#ifdef XF86BIGFONT
+ XF86BigfontCleanup();
+#endif
+#if defined(XFree86LOADER)
+ if (xf86Initialising)
+ LoaderCheckUnresolved(LD_RESOLV_IFDONE);
+ ErrorF("\n"
+ " *** If unresolved symbols were reported above, they might not\n"
+ " *** be the reason for the server aborting.\n");
+#endif
+
+ xorg_backtrace();
+
+ FatalError("Caught signal %d. Server aborting\n", signo);
+}
+
+#ifdef MEMDEBUG
+void
+xf86SigMemDebug(int signo)
+{
+ CheckMemory();
+ (void) signal(signo, xf86SigMemDebug);
+ return;
+}
+#endif
+
+/*
+ * xf86VTSwitch --
+ * Handle requests for switching the vt.
+ */
+static void
+xf86VTSwitch()
+{
+ int i, prevSIGIO;
+ InputInfoPtr pInfo;
+ IHPtr ih;
+
+#ifdef DEBUG
+ ErrorF("xf86VTSwitch()\n");
+#endif
+
+#ifdef XFreeXDGA
+ if(!DGAVTSwitch())
+ return;
+#endif
+
+ /*
+ * Since all screens are currently all in the same state it is sufficient
+ * check the first. This might change in future.
+ */
+ if (xf86Screens[0]->vtSema) {
+
+#ifdef DEBUG
+ ErrorF("xf86VTSwitch: Leaving, xf86Exiting is %s\n",
+ BOOLTOSTRING((dispatchException & DE_TERMINATE) ? TRUE : FALSE));
+#endif
+#ifdef DPMSExtension
+ if (DPMSPowerLevel != DPMSModeOn)
+ DPMSSet(DPMSModeOn);
+#endif
+ for (i = 0; i < xf86NumScreens; i++) {
+ if (!(dispatchException & DE_TERMINATE))
+ if (xf86Screens[i]->EnableDisableFBAccess)
+ (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE);
+ }
+#if !defined(__UNIXOS2__)
+
+ /*
+ * Keep the order: Disable Device > LeaveVT
+ * EnterVT > EnableDevice
+ */
+ DisableDevice((DeviceIntPtr)xf86Info.pKeyboard);
+ pInfo = xf86InputDevs;
+ while (pInfo) {
+ DisableDevice(pInfo->dev);
+ pInfo = pInfo->next;
+ }
+#endif /* !__UNIXOS2__ */
+ xf86EnterServerState(SETUP);
+ for (i = 0; i < xf86NumScreens; i++)
+ xf86Screens[i]->LeaveVT(i, 0);
+
+ for (ih = InputHandlers; ih; ih = ih->next)
+ xf86DisableInputHandler(ih);
+ xf86AccessLeave(); /* We need this here, otherwise */
+ xf86AccessLeaveState(); /* console won't be restored */
+
+ if (!xf86VTSwitchAway()) {
+ /*
+ * switch failed
+ */
+
+#ifdef DEBUG
+ ErrorF("xf86VTSwitch: Leave failed\n");
+#endif
+ prevSIGIO = xf86BlockSIGIO();
+ xf86AccessEnter();
+ xf86EnterServerState(SETUP);
+ for (i = 0; i < xf86NumScreens; i++) {
+ if (!xf86Screens[i]->EnterVT(i, 0))
+ FatalError("EnterVT failed for screen %d\n", i);
+ }
+ xf86EnterServerState(OPERATING);
+ if (!(dispatchException & DE_TERMINATE)) {
+ for (i = 0; i < xf86NumScreens; i++) {
+ if (xf86Screens[i]->EnableDisableFBAccess)
+ (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE);
+ }
+ }
+ SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
+
+#if !defined(__UNIXOS2__)
+ EnableDevice((DeviceIntPtr)xf86Info.pKeyboard);
+ pInfo = xf86InputDevs;
+ while (pInfo) {
+ EnableDevice(pInfo->dev);
+ pInfo = pInfo->next;
+ }
+#endif /* !__UNIXOS2__ */
+ for (ih = InputHandlers; ih; ih = ih->next)
+ xf86EnableInputHandler(ih);
+
+ xf86UnblockSIGIO(prevSIGIO);
+
+ } else {
+#ifdef XF86PM
+ if (xf86OSPMClose)
+ xf86OSPMClose();
+ xf86OSPMClose = NULL;
+#endif
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ /*
+ * zero all access functions to
+ * trap calls when switched away.
+ */
+ xf86Screens[i]->vtSema = FALSE;
+ xf86Screens[i]->access = NULL;
+ xf86Screens[i]->busAccess = NULL;
+ }
+ if (xorgHWAccess)
+ xf86DisableIO();
+ }
+ } else {
+
+#ifdef DEBUG
+ ErrorF("xf86VTSwitch: Entering\n");
+#endif
+ if (!xf86VTSwitchTo()) return;
+
+ prevSIGIO = xf86BlockSIGIO();
+#ifdef XF86PM
+ xf86OSPMClose = xf86OSPMOpen();
+#endif
+
+ if (xorgHWAccess)
+ xf86EnableIO();
+ xf86AccessEnter();
+ xf86EnterServerState(SETUP);
+ for (i = 0; i < xf86NumScreens; i++) {
+ xf86Screens[i]->vtSema = TRUE;
+ if (!xf86Screens[i]->EnterVT(i, 0))
+ FatalError("EnterVT failed for screen %d\n", i);
+ }
+ xf86EnterServerState(OPERATING);
+ for (i = 0; i < xf86NumScreens; i++) {
+ if (xf86Screens[i]->EnableDisableFBAccess)
+ (*xf86Screens[i]->EnableDisableFBAccess)(i, TRUE);
+ }
+
+ /* Turn screen saver off when switching back */
+ SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset);
+
+#if !defined(__UNIXOS2__)
+ EnableDevice((DeviceIntPtr)xf86Info.pKeyboard);
+ pInfo = xf86InputDevs;
+ while (pInfo) {
+ EnableDevice(pInfo->dev);
+ pInfo = pInfo->next;
+ }
+#endif /* !__UNIXOS2__ */
+
+ for (ih = InputHandlers; ih; ih = ih->next)
+ xf86EnableInputHandler(ih);
+
+ xf86UnblockSIGIO(prevSIGIO);
+ }
+}
+
+
+/* Input handler registration */
+
+pointer
+xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data)
+{
+ IHPtr ih;
+
+ if (fd < 0 || !proc)
+ return NULL;
+
+ ih = xcalloc(sizeof(*ih), 1);
+ if (!ih)
+ return NULL;
+
+ ih->fd = fd;
+ ih->ihproc = proc;
+ ih->data = data;
+ ih->enabled = TRUE;
+
+ ih->next = InputHandlers;
+ InputHandlers = ih;
+
+ AddEnabledDevice(fd);
+
+ return ih;
+}
+
+int
+xf86RemoveInputHandler(pointer handler)
+{
+ IHPtr ih, p;
+ int fd;
+
+ if (!handler)
+ return -1;
+
+ ih = handler;
+ fd = ih->fd;
+
+ if (ih->fd >= 0)
+ RemoveEnabledDevice(ih->fd);
+
+ if (ih == InputHandlers)
+ InputHandlers = ih->next;
+ else {
+ p = InputHandlers;
+ while (p && p->next != ih)
+ p = p->next;
+ if (ih)
+ p->next = ih->next;
+ }
+ xfree(ih);
+ return fd;
+}
+
+void
+xf86DisableInputHandler(pointer handler)
+{
+ IHPtr ih;
+
+ if (!handler)
+ return;
+
+ ih = handler;
+ ih->enabled = FALSE;
+ if (ih->fd >= 0)
+ RemoveEnabledDevice(ih->fd);
+}
+
+void
+xf86EnableInputHandler(pointer handler)
+{
+ IHPtr ih;
+
+ if (!handler)
+ return;
+
+ ih = handler;
+ ih->enabled = TRUE;
+ if (ih->fd >= 0)
+ AddEnabledDevice(ih->fd);
+}
+
+/*
+ * As used currently by the DRI, the return value is ignored.
+ */
+Bool
+xf86EnableVTSwitch(Bool new)
+{
+ static Bool def = TRUE;
+ Bool old;
+
+ old = VTSwitchEnabled;
+ if (!new) {
+ /* Disable VT switching */
+ def = VTSwitchEnabled;
+ VTSwitchEnabled = FALSE;
+ } else {
+ /* Restore VT switching to default */
+ VTSwitchEnabled = def;
+ }
+ return old;
+}
+
+#ifdef XTESTEXT1
+
+void
+XTestGetPointerPos(short *fmousex, short *fmousey)
+{
+ int x,y;
+
+ miPointerPosition(&x, &y);
+ *fmousex = x;
+ *fmousey = y;
+}
+
+
+
+void
+XTestJumpPointer(int jx, int jy, int dev_type)
+{
+ miPointerAbsoluteCursor(jx, jy, GetTimeInMillis() );
+}
+
+void
+XTestGenerateEvent(int dev_type, int keycode, int keystate, int mousex,
+ int mousey)
+{
+ xEvent tevent;
+
+ tevent.u.u.type = (dev_type == XE_POINTER) ?
+ (keystate == XTestKEY_UP) ? ButtonRelease : ButtonPress :
+ (keystate == XTestKEY_UP) ? KeyRelease : KeyPress;
+ tevent.u.u.detail = keycode;
+ tevent.u.keyButtonPointer.rootX = mousex;
+ tevent.u.keyButtonPointer.rootY = mousey;
+ tevent.u.keyButtonPointer.time = xf86Info.lastEventTime = GetTimeInMillis();
+#ifdef XINPUT
+ xf86eqEnqueue(&tevent);
+#else
+ mieqEnqueue(&tevent);
+#endif
+ xf86Info.inputPending = TRUE; /* virtual event */
+}
+
+#endif /* XTESTEXT1 */
+
+void
+xf86ReloadInputDevs(int sig)
+{
+ InputInfoPtr pInfo;
+
+ signal(sig, (void(*)(int))xf86ReloadInputDevs);
+
+ DisableDevice((DeviceIntPtr)xf86Info.pKeyboard);
+ EnableDevice((DeviceIntPtr)xf86Info.pKeyboard);
+
+ pInfo = xf86InputDevs;
+ while (pInfo) {
+ DisableDevice(pInfo->dev);
+ EnableDevice(pInfo->dev);
+ pInfo = pInfo->next;
+ }
+
+ return;
+}
+
+#ifdef WSCONS_SUPPORT
+
+/* XXX Currently XKB is mandatory. */
+
+extern int WSKbdToKeycode(int);
+
+void
+xf86PostWSKbdEvent(struct wscons_event *event)
+{
+ int type = event->type;
+ int value = event->value;
+ unsigned int keycode;
+ int blocked;
+
+ if (type == WSCONS_EVENT_KEY_UP || type == WSCONS_EVENT_KEY_DOWN) {
+ Bool down = (type == WSCONS_EVENT_KEY_DOWN ? TRUE : FALSE);
+
+ /* map the scancodes to standard XFree86 scancode */
+ keycode = WSKbdToKeycode(value);
+ if (!down) keycode |= 0x80;
+ /* It seems better to block SIGIO there */
+ blocked = xf86BlockSIGIO();
+ xf86PostKbdEvent(keycode);
+ xf86UnblockSIGIO(blocked);
+ }
+}
+#endif /* WSCONS_SUPPORT */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Globals.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Globals.c
new file mode 100644
index 000000000..30fe10554
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Globals.c
@@ -0,0 +1,254 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Globals.c,v 1.42 2004/01/27 01:31:44 dawes Exp $ */
+
+/*
+ * 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 all the XFree86 global variables.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "windowstr.h"
+#include "propertyst.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Parser.h"
+#include "xf86Xinput.h"
+#include "xf86InPriv.h"
+
+/* Globals that video drivers may access */
+
+int xf86ScreenIndex = -1; /* Index of ScrnInfo in pScreen.devPrivates */
+int xf86CreateRootWindowIndex = -1; /* Index into pScreen.devPrivates */
+ScrnInfoPtr *xf86Screens = NULL; /* List of ScrnInfos */
+int xf86PixmapIndex = 0;
+const unsigned char byte_reversed[256] =
+{
+ 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
+ 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
+ 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
+ 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
+ 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
+ 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
+ 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
+ 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
+ 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
+ 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
+ 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
+ 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
+ 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
+ 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
+ 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
+ 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
+ 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
+ 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
+ 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
+ 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
+ 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
+ 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
+ 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
+ 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
+ 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
+ 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
+ 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
+ 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
+ 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
+ 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
+ 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
+ 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
+};
+
+/* Globals that input drivers may access */
+InputInfoPtr xf86InputDevs = NULL;
+
+
+/* Globals that video drivers may not access */
+
+xf86InfoRec xf86Info = {
+ NULL, /* pKeyboard */
+ NULL, /* kbdProc */
+ NULL, /* kbdEvents */
+ -1, /* consoleFd */
+ -1, /* kbdFd */
+ -1, /* vtno */
+ -1, /* kbdType */
+ -1, /* kbdRate */
+ -1, /* kbdDelay */
+ -1, /* bell_pitch */
+ -1, /* bell_duration */
+ TRUE, /* autoRepeat */
+ 0, /* leds */
+ 0, /* xleds */
+ NULL, /* vtinit */
+ 0, /* scanPrefix */
+ FALSE, /* capsLock */
+ FALSE, /* numLock */
+ FALSE, /* scrollLock */
+ FALSE, /* modeSwitchLock */
+ FALSE, /* composeLock */
+ FALSE, /* vtSysreq */
+ SKWhenNeeded, /* ddxSpecialKeys */
+ FALSE, /* ActionKeyBindingsSet */
+#if defined(SVR4) && defined(i386)
+ FALSE, /* panix106 */
+#endif
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+ 0, /* wskbdType */
+#endif
+ NULL, /* pMouse */
+#ifdef XINPUT
+ NULL, /* mouseLocal */
+#endif
+ -1, /* lastEventTime */
+ FALSE, /* vtRequestsPending */
+ FALSE, /* inputPending */
+ FALSE, /* dontVTSwitch */
+ FALSE, /* dontZap */
+ FALSE, /* dontZoom */
+ FALSE, /* notrapSignals */
+ FALSE, /* caughtSignal */
+ FALSE, /* sharedMonitor */
+ NULL, /* currentScreen */
+#ifdef CSRG_BASED
+ -1, /* screenFd */
+ -1, /* consType */
+#endif
+#ifdef XKB
+ NULL, /* xkbkeymap */
+ NULL, /* xkbkeycodes */
+ NULL, /* xkbtypes */
+ NULL, /* xkbcompat */
+ NULL, /* xkbsymbols */
+ NULL, /* xkbgeometry */
+ FALSE, /* xkbcomponents_specified */
+ NULL, /* xkbrules */
+ NULL, /* xkbmodel */
+ NULL, /* xkblayout */
+ NULL, /* xkbvariant */
+ NULL, /* xkboptions */
+#endif
+ FALSE, /* allowMouseOpenFail */
+ TRUE, /* vidModeEnabled */
+ FALSE, /* vidModeAllowNonLocal */
+ TRUE, /* miscModInDevEnabled */
+ FALSE, /* miscModInDevAllowNonLocal */
+ PCIOsConfig, /* pciFlags */
+ Pix24DontCare, /* pixmap24 */
+ X_DEFAULT, /* pix24From */
+#if defined(i386) || defined(__i386__)
+ FALSE, /* pc98 */
+#endif
+ TRUE, /* pmFlag */
+ LogNone, /* syncLog */
+ 0, /* estimateSizesAggressively */
+ FALSE, /* kbdCustomKeycodes */
+ FALSE, /* disableRandR */
+ X_DEFAULT /* randRFrom */
+};
+const char *xf86ConfigFile = NULL;
+const char *xf86InputDeviceList = NULL;
+const char *xf86ModulePath = DEFAULT_MODULE_PATH;
+MessageType xf86ModPathFrom = X_DEFAULT;
+const char *xf86LogFile = DEFAULT_LOGPREFIX;
+MessageType xf86LogFileFrom = X_DEFAULT;
+Bool xf86LogFileWasOpened = FALSE;
+serverLayoutRec xf86ConfigLayout = {NULL, };
+confDRIRec xf86ConfigDRI = {0, };
+XF86ConfigPtr xf86configptr = NULL;
+Bool xf86Resetting = FALSE;
+Bool xf86Initialising = FALSE;
+Bool xf86ProbeFailed = FALSE;
+Bool xf86DoProbe = FALSE;
+Bool xf86DoConfigure = FALSE;
+#ifdef XFree86LOADER
+DriverPtr *xf86DriverList = NULL;
+int xf86NumDrivers = 0;
+InputDriverPtr *xf86InputDriverList = NULL;
+int xf86NumInputDrivers = 0;
+ModuleInfoPtr *xf86ModuleInfoList = NULL;
+int xf86NumModuleInfos = 0;
+#endif
+int xf86NumScreens = 0;
+
+const char *xf86VisualNames[] = {
+ "StaticGray",
+ "GrayScale",
+ "StaticColor",
+ "PseudoColor",
+ "TrueColor",
+ "DirectColor"
+};
+
+/* Parameters set only from the command line */
+char *xf86ServerName = "no-name";
+Bool xf86fpFlag = FALSE;
+Bool xf86coFlag = FALSE;
+Bool xf86sFlag = FALSE;
+Bool xf86bsEnableFlag = FALSE;
+Bool xf86bsDisableFlag = FALSE;
+Bool xf86silkenMouseDisableFlag = FALSE;
+Bool xf86acpiDisableFlag = FALSE;
+char *xf86LayoutName = NULL;
+char *xf86ScreenName = NULL;
+char *xf86PointerName = NULL;
+char *xf86KeyboardName = NULL;
+Bool xf86ProbeOnly = FALSE;
+int xf86Verbose = DEFAULT_VERBOSE;
+int xf86LogVerbose = DEFAULT_LOG_VERBOSE;
+int xf86FbBpp = -1;
+Pix24Flags xf86Pix24 = Pix24DontCare;
+int xf86Depth = -1;
+rgb xf86Weight = {0, 0, 0};
+Bool xf86FlipPixels = FALSE;
+Gamma xf86Gamma = {0.0, 0.0, 0.0};
+Bool xf86ShowUnresolved = DEFAULT_UNRESOLVED;
+Bool xf86BestRefresh = DEFAULT_BEST_REFRESH;
+Bool xf86AllowMouseOpenFail = FALSE;
+#ifdef XF86VIDMODE
+Bool xf86VidModeDisabled = FALSE;
+Bool xf86VidModeAllowNonLocal = FALSE;
+#endif
+#ifdef XF86MISC
+Bool xf86MiscModInDevDisabled = FALSE;
+Bool xf86MiscModInDevAllowNonLocal = FALSE;
+#endif
+RootWinPropPtr *xf86RegisteredPropertiesTable = NULL;
+Bool xf86inSuspend = FALSE;
+Bool xorgHWAccess = FALSE;
+PciBusId xf86IsolateDevice;
+
+#ifdef DLOPEN_HACK
+/*
+ * This stuff is a hack to allow dlopen() modules to work. It is intended
+ * only to be used when using dlopen() modules for debugging purposes.
+ */
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Helper.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Helper.c
new file mode 100644
index 000000000..a6c7d5c89
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Helper.c
@@ -0,0 +1,2983 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Helper.c,v 1.136 2004/01/27 01:31:45 dawes Exp $ */
+
+/*
+ * 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).
+ */
+
+/*
+ * Authors: Dirk Hohndel <hohndel@XFree86.Org>
+ * David Dawes <dawes@XFree86.Org>
+ * ... and others
+ *
+ * This file includes the helper functions that the server provides for
+ * different drivers.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "servermd.h"
+#include "pixmapstr.h"
+#include "windowstr.h"
+#include "propertyst.h"
+#include "gcstruct.h"
+#include "loaderProcs.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "micmap.h"
+#include "xf86PciInfo.h"
+#include "xf86DDC.h"
+#include "xf86Xinput.h"
+#include "xf86InPriv.h"
+#include "mivalidate.h"
+#include "xf86RAC.h"
+#include "xf86Bus.h"
+#include "xf86Version.h"
+
+/* For xf86GetClocks */
+#if defined(CSRG_BASED) || defined(__GNU__)
+#define HAS_SETPRIORITY
+#include <sys/resource.h>
+#endif
+
+static int xf86ScrnInfoPrivateCount = 0;
+
+
+#ifdef XFree86LOADER
+/* Add a pointer to a new DriverRec to xf86DriverList */
+
+void
+xf86AddDriver(DriverPtr driver, pointer module, int flags)
+{
+ /* Don't add null entries */
+ if (!driver)
+ return;
+
+ if (xf86DriverList == NULL)
+ xf86NumDrivers = 0;
+
+ xf86NumDrivers++;
+ xf86DriverList = xnfrealloc(xf86DriverList,
+ xf86NumDrivers * sizeof(DriverPtr));
+ xf86DriverList[xf86NumDrivers - 1] = xnfalloc(sizeof(DriverRec));
+ if (flags & HaveDriverFuncs)
+ *xf86DriverList[xf86NumDrivers - 1] = *driver;
+ else {
+ memcpy(xf86DriverList[xf86NumDrivers - 1], driver, sizeof(DriverRec1));
+ xf86DriverList[xf86NumDrivers - 1]->driverFunc = NULL;
+ }
+ xf86DriverList[xf86NumDrivers - 1]->module = module;
+ xf86DriverList[xf86NumDrivers - 1]->refCount = 0;
+}
+
+void
+xf86DeleteDriver(int drvIndex)
+{
+ if (xf86DriverList[drvIndex]
+ && (!xf86DriverHasEntities(xf86DriverList[drvIndex]))) {
+ if (xf86DriverList[drvIndex]->module)
+ UnloadModule(xf86DriverList[drvIndex]->module);
+ xfree(xf86DriverList[drvIndex]);
+ xf86DriverList[drvIndex] = NULL;
+ }
+}
+
+/* Add a pointer to a new InputDriverRec to xf86InputDriverList */
+
+void
+xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags)
+{
+ /* Don't add null entries */
+ if (!driver)
+ return;
+
+ if (xf86InputDriverList == NULL)
+ xf86NumInputDrivers = 0;
+
+ xf86NumInputDrivers++;
+ xf86InputDriverList = xnfrealloc(xf86InputDriverList,
+ xf86NumInputDrivers * sizeof(InputDriverPtr));
+ xf86InputDriverList[xf86NumInputDrivers - 1] =
+ xnfalloc(sizeof(InputDriverRec));
+ *xf86InputDriverList[xf86NumInputDrivers - 1] = *driver;
+ xf86InputDriverList[xf86NumInputDrivers - 1]->module = module;
+ xf86InputDriverList[xf86NumInputDrivers - 1]->refCount = 0;
+}
+
+void
+xf86DeleteInputDriver(int drvIndex)
+{
+ if (xf86InputDriverList[drvIndex] && xf86InputDriverList[drvIndex]->module)
+ UnloadModule(xf86InputDriverList[drvIndex]->module);
+ xfree(xf86InputDriverList[drvIndex]);
+ xf86InputDriverList[drvIndex] = NULL;
+}
+
+void
+xf86AddModuleInfo(ModuleInfoPtr info, pointer module)
+{
+ /* Don't add null entries */
+ if (!module)
+ return;
+
+ if (xf86ModuleInfoList == NULL)
+ xf86NumModuleInfos = 0;
+
+ xf86NumModuleInfos++;
+ xf86ModuleInfoList = xnfrealloc(xf86ModuleInfoList,
+ xf86NumModuleInfos * sizeof(ModuleInfoPtr));
+ xf86ModuleInfoList[xf86NumModuleInfos - 1] = xnfalloc(sizeof(ModuleInfoRec));
+ *xf86ModuleInfoList[xf86NumModuleInfos - 1] = *info;
+ xf86ModuleInfoList[xf86NumModuleInfos - 1]->module = module;
+ xf86ModuleInfoList[xf86NumModuleInfos - 1]->refCount = 0;
+}
+
+void
+xf86DeleteModuleInfo(int idx)
+{
+ if (xf86ModuleInfoList[idx]) {
+ if (xf86ModuleInfoList[idx]->module)
+ UnloadModule(xf86ModuleInfoList[idx]->module);
+ xfree(xf86ModuleInfoList[idx]);
+ xf86ModuleInfoList[idx] = NULL;
+ }
+}
+#endif
+
+
+/* Allocate a new ScrnInfoRec in xf86Screens */
+
+ScrnInfoPtr
+xf86AllocateScreen(DriverPtr drv, int flags)
+{
+ int i;
+
+ if (xf86Screens == NULL)
+ xf86NumScreens = 0;
+
+ i = xf86NumScreens++;
+ xf86Screens = xnfrealloc(xf86Screens, xf86NumScreens * sizeof(ScrnInfoPtr));
+ xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1);
+ xf86Screens[i]->scrnIndex = i; /* Changes when a screen is removed */
+ xf86Screens[i]->origIndex = i; /* This never changes */
+ xf86Screens[i]->privates = xnfcalloc(sizeof(DevUnion),
+ xf86ScrnInfoPrivateCount);
+ /*
+ * EnableDisableFBAccess now gets initialized in InitOutput()
+ * xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess;
+ */
+
+ xf86Screens[i]->drv = drv;
+ drv->refCount++;
+#ifdef XFree86LOADER
+ xf86Screens[i]->module = DuplicateModule(drv->module, NULL);
+#else
+ xf86Screens[i]->module = NULL;
+#endif
+ /*
+ * set the initial access state. This will be modified after PreInit.
+ * XXX Or should we do it some other place?
+ */
+ xf86Screens[i]->CurrentAccess = &xf86CurrentAccess;
+ xf86Screens[i]->resourceType = MEM_IO;
+
+#ifdef DEBUG
+ /* OOps -- What's this ? */
+ ErrorF("xf86AllocateScreen - xf86Screens[%d]->pScreen = %p\n",
+ i, xf86Screens[i]->pScreen );
+ if ( NULL != xf86Screens[i]->pScreen ) {
+ ErrorF("xf86Screens[%d]->pScreen->CreateWindow = %p\n",
+ i, xf86Screens[i]->pScreen->CreateWindow );
+ }
+#endif
+
+ xf86Screens[i]->DriverFunc = drv->driverFunc;
+
+ return xf86Screens[i];
+}
+
+
+/*
+ * Remove an entry from xf86Screens. Ideally it should free all allocated
+ * data. To do this properly may require a driver hook.
+ */
+
+void
+xf86DeleteScreen(int scrnIndex, int flags)
+{
+ ScrnInfoPtr pScrn;
+ int i;
+
+ /* First check if the screen is valid */
+ if (xf86NumScreens == 0 || xf86Screens == NULL)
+ return;
+
+ if (scrnIndex > xf86NumScreens - 1)
+ return;
+
+ if (!(pScrn = xf86Screens[scrnIndex]))
+ return;
+
+ /* If a FreeScreen function is defined, call it here */
+ if (pScrn->FreeScreen != NULL)
+ pScrn->FreeScreen(scrnIndex, 0);
+
+ while (pScrn->modes)
+ xf86DeleteMode(&pScrn->modes, pScrn->modes);
+
+ while (pScrn->modePool)
+ xf86DeleteMode(&pScrn->modePool, pScrn->modePool);
+
+ xf86OptionListFree(pScrn->options);
+
+#ifdef XFree86LOADER
+ if (pScrn->module)
+ UnloadModule(pScrn->module);
+#endif
+
+ if (pScrn->drv)
+ pScrn->drv->refCount--;
+
+ if (pScrn->privates)
+ xfree(pScrn->privates);
+
+ xf86ClearEntityListForScreen(scrnIndex);
+
+ xfree(pScrn);
+
+ /* Move the other entries down, updating their scrnIndex fields */
+
+ xf86NumScreens--;
+
+ for (i = scrnIndex; i < xf86NumScreens; i++) {
+ xf86Screens[i] = xf86Screens[i + 1];
+ xf86Screens[i]->scrnIndex = i;
+ /* Also need to take care of the screen layout settings */
+ }
+}
+
+/*
+ * Allocate a private in ScrnInfoRec.
+ */
+
+int
+xf86AllocateScrnInfoPrivateIndex(void)
+{
+ int idx, i;
+ ScrnInfoPtr pScr;
+ DevUnion *nprivs;
+
+ idx = xf86ScrnInfoPrivateCount++;
+ for (i = 0; i < xf86NumScreens; i++) {
+ pScr = xf86Screens[i];
+ nprivs = xnfrealloc(pScr->privates,
+ xf86ScrnInfoPrivateCount * sizeof(DevUnion));
+ /* Zero the new private */
+ bzero(&nprivs[idx], sizeof(DevUnion));
+ pScr->privates = nprivs;
+ }
+ return idx;
+}
+
+/* Allocate a new InputInfoRec and add it to the head xf86InputDevs. */
+
+InputInfoPtr
+xf86AllocateInput(InputDriverPtr drv, int flags)
+{
+ InputInfoPtr new;
+
+ if (!(new = xcalloc(sizeof(InputInfoRec), 1)))
+ return NULL;
+
+ new->drv = drv;
+ drv->refCount++;
+#ifdef XFree86LOADER
+ new->module = DuplicateModule(drv->module, NULL);
+#else
+ new->module = NULL;
+#endif
+ new->next = xf86InputDevs;
+ xf86InputDevs = new;
+ return new;
+}
+
+
+/*
+ * Remove an entry from xf86InputDevs. Ideally it should free all allocated
+ * data. To do this properly may require a driver hook.
+ */
+
+void
+xf86DeleteInput(InputInfoPtr pInp, int flags)
+{
+ InputInfoPtr p;
+
+ /* First check if the inputdev is valid. */
+ if (pInp == NULL)
+ return;
+
+#if 0
+ /* If a free function is defined, call it here. */
+ if (pInp->free)
+ pInp->free(pInp, 0);
+#endif
+
+#ifdef XFree86LOADER
+ if (pInp->module)
+ UnloadModule(pInp->module);
+#endif
+
+ if (pInp->drv)
+ pInp->drv->refCount--;
+
+ if (pInp->private)
+ xfree(pInp->private);
+
+ /* Remove the entry from the list. */
+ if (pInp == xf86InputDevs)
+ xf86InputDevs = pInp->next;
+ else {
+ p = xf86InputDevs;
+ while (p && p->next != pInp)
+ p = p->next;
+ if (p)
+ p->next = pInp->next;
+ /* Else the entry wasn't in the xf86InputDevs list (ignore this). */
+ }
+ xfree(pInp);
+}
+
+Bool
+xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad)
+{
+ int i;
+
+ if (pScrn->numFormats >= MAXFORMATS)
+ return FALSE;
+
+ if (bpp <= 0) {
+ if (depth == 1)
+ bpp = 1;
+ else if (depth <= 8)
+ bpp = 8;
+ else if (depth <= 16)
+ bpp = 16;
+ else if (depth <= 32)
+ bpp = 32;
+ else
+ return FALSE;
+ }
+ if (pad <= 0)
+ pad = BITMAP_SCANLINE_PAD;
+
+ i = pScrn->numFormats++;
+ pScrn->formats[i].depth = depth;
+ pScrn->formats[i].bitsPerPixel = bpp;
+ pScrn->formats[i].scanlinePad = pad;
+ return TRUE;
+}
+
+/*
+ * Set the depth we are using based on (in the following order of preference):
+ * - values given on the command line
+ * - values given in the config file
+ * - values provided by the driver
+ * - an overall default when nothing else is given
+ *
+ * Also find a Display subsection matching the depth/bpp found.
+ *
+ * Sets the following ScrnInfoRec fields:
+ * bitsPerPixel, pixmap24, depth, display, imageByteOrder,
+ * bitmapScanlinePad, bitmapScanlineUnit, bitmapBitOrder, numFormats,
+ * formats, fbFormat.
+ */
+
+/* Can the screen handle 24 bpp pixmaps */
+#define DO_PIX24(f) ((f & Support24bppFb) || \
+ ((f & Support32bppFb) && (f & SupportConvert24to32)))
+
+/* Can the screen handle 32 bpp pixmaps */
+#define DO_PIX32(f) ((f & Support32bppFb) || \
+ ((f & Support24bppFb) && (f & SupportConvert32to24)))
+
+/* Does the screen prefer 32bpp fb for 24bpp pixmaps */
+#define CHOOSE32FOR24(f) ((f & Support32bppFb) && (f & SupportConvert24to32) \
+ && (f & PreferConvert24to32))
+
+/* Does the screen prefer 24bpp fb for 32bpp pixmaps */
+#define CHOOSE24FOR32(f) ((f & Support24bppFb) && (f & SupportConvert32to24) \
+ && (f & PreferConvert32to24))
+
+/* Can the screen handle 32bpp pixmaps for 24bpp fb */
+#define DO_PIX32FOR24(f) ((f & Support24bppFb) && (f & SupportConvert32to24))
+
+/* Can the screen handle 24bpp pixmaps for 32bpp fb */
+#define DO_PIX24FOR32(f) ((f & Support32bppFb) && (f & SupportConvert24to32))
+
+#ifndef GLOBAL_DEFAULT_DEPTH
+#define GLOBAL_DEFAULT_DEPTH 16
+#endif
+
+#ifndef GLOBAL_DEFAULT_FBBPP
+#define GLOBAL_DEFAULT_FBBPP 16
+#endif
+
+Bool
+xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp,
+ int depth24flags)
+{
+ int i;
+ DispPtr disp;
+ Pix24Flags pix24 = xf86Info.pixmap24;
+ Bool nomatch = FALSE;
+
+ scrp->bitsPerPixel = -1;
+ scrp->depth = -1;
+ scrp->pixmap24 = Pix24DontCare;
+ scrp->bitsPerPixelFrom = X_DEFAULT;
+ scrp->depthFrom = X_DEFAULT;
+
+#if BITMAP_SCANLINE_UNIT == 64
+ /*
+ * For platforms with 64-bit scanlines, modify the driver's depth24flags
+ * to remove preferences for packed 24bpp modes, which are not currently
+ * supported on these platforms.
+ */
+ depth24flags &= ~(SupportConvert32to24 | SupportConvert32to24 |
+ PreferConvert24to32 | PreferConvert32to24);
+#endif
+
+ if (xf86FbBpp > 0) {
+ scrp->bitsPerPixel = xf86FbBpp;
+ scrp->bitsPerPixelFrom = X_CMDLINE;
+ }
+
+ if (xf86Depth > 0) {
+ scrp->depth = xf86Depth;
+ scrp->depthFrom = X_CMDLINE;
+ }
+
+ if (xf86FbBpp < 0 && xf86Depth < 0) {
+ if (scrp->confScreen->defaultfbbpp > 0) {
+ scrp->bitsPerPixel = scrp->confScreen->defaultfbbpp;
+ scrp->bitsPerPixelFrom = X_CONFIG;
+ }
+ if (scrp->confScreen->defaultdepth > 0) {
+ scrp->depth = scrp->confScreen->defaultdepth;
+ scrp->depthFrom = X_CONFIG;
+ }
+
+ if (scrp->confScreen->defaultfbbpp <= 0 &&
+ scrp->confScreen->defaultdepth <= 0) {
+ /*
+ * Check for DefaultDepth and DefaultFbBpp options in the
+ * Device sections.
+ */
+ int i;
+ GDevPtr device;
+ Bool found = FALSE;
+
+ for (i = 0; i < scrp->numEntities; i++) {
+ device = xf86GetDevFromEntity(scrp->entityList[i],
+ scrp->entityInstanceList[i]);
+ if (device && device->options) {
+ if (xf86FindOption(device->options, "DefaultDepth")) {
+ scrp->depth = xf86SetIntOption(device->options,
+ "DefaultDepth", -1);
+ scrp->depthFrom = X_CONFIG;
+ found = TRUE;
+ }
+ if (xf86FindOption(device->options, "DefaultFbBpp")) {
+ scrp->bitsPerPixel = xf86SetIntOption(device->options,
+ "DefaultFbBpp",
+ -1);
+ scrp->bitsPerPixelFrom = X_CONFIG;
+ found = TRUE;
+ }
+ }
+ if (found)
+ break;
+ }
+ }
+ }
+
+ /* If none of these is set, pick a default */
+ if (scrp->bitsPerPixel < 0 && scrp->depth < 0) {
+ if (fbbpp > 0 || depth > 0) {
+ if (fbbpp > 0)
+ scrp->bitsPerPixel = fbbpp;
+ if (depth > 0)
+ scrp->depth = depth;
+ } else {
+ scrp->bitsPerPixel = GLOBAL_DEFAULT_FBBPP;
+ scrp->depth = GLOBAL_DEFAULT_DEPTH;
+ }
+ }
+
+ /* If any are not given, determine a default for the others */
+
+ if (scrp->bitsPerPixel < 0) {
+ /* The depth must be set */
+ if (scrp->depth > -1) {
+ if (scrp->depth == 1)
+ scrp->bitsPerPixel = 1;
+ else if (scrp->depth <= 4)
+ scrp->bitsPerPixel = 4;
+ else if (scrp->depth <= 8)
+ scrp->bitsPerPixel = 8;
+ else if (scrp->depth <= 16)
+ scrp->bitsPerPixel = 16;
+ else if (scrp->depth <= 24) {
+ /*
+ * Figure out if a choice is possible based on the depth24
+ * and pix24 flags.
+ */
+ /* Check pix24 first */
+ if (pix24 != Pix24DontCare) {
+ if (pix24 == Pix24Use32) {
+ if (DO_PIX32(depth24flags)) {
+ if (CHOOSE24FOR32(depth24flags))
+ scrp->bitsPerPixel = 24;
+ else
+ scrp->bitsPerPixel = 32;
+ } else {
+ nomatch = TRUE;
+ }
+ } else if (pix24 == Pix24Use24) {
+ if (DO_PIX24(depth24flags)) {
+ if (CHOOSE32FOR24(depth24flags))
+ scrp->bitsPerPixel = 32;
+ else
+ scrp->bitsPerPixel = 24;
+ } else {
+ nomatch = TRUE;
+ }
+ }
+ } else {
+ if (DO_PIX32(depth24flags)) {
+ if (CHOOSE24FOR32(depth24flags))
+ scrp->bitsPerPixel = 24;
+ else
+ scrp->bitsPerPixel = 32;
+ } else if (DO_PIX24(depth24flags)) {
+ if (CHOOSE32FOR24(depth24flags))
+ scrp->bitsPerPixel = 32;
+ else
+ scrp->bitsPerPixel = 24;
+ }
+ }
+ } else if (scrp->depth <= 32)
+ scrp->bitsPerPixel = 32;
+ else {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Specified depth (%d) is greater than 32\n",
+ scrp->depth);
+ return FALSE;
+ }
+ } else {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "xf86SetDepthBpp: internal error: depth and fbbpp"
+ " are both not set\n");
+ return FALSE;
+ }
+ if (scrp->bitsPerPixel < 0) {
+ if (nomatch)
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Driver can't support depth 24 pixmap format (%d)\n",
+ PIX24TOBPP(pix24));
+ else if ((depth24flags & (Support24bppFb | Support32bppFb)) ==
+ NoDepth24Support)
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Driver can't support depth 24\n");
+ else
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Can't find fbbpp for depth 24\n");
+ return FALSE;
+ }
+ scrp->bitsPerPixelFrom = X_PROBED;
+ }
+
+ if (scrp->depth <= 0) {
+ /* bitsPerPixel is already set */
+ switch (scrp->bitsPerPixel) {
+ case 32:
+ scrp->depth = 24;
+ break;
+ default:
+ /* 1, 4, 8, 16 and 24 */
+ scrp->depth = scrp->bitsPerPixel;
+ break;
+ }
+ scrp->depthFrom = X_PROBED;
+ }
+
+ /* Sanity checks */
+ if (scrp->depth < 1 || scrp->depth > 32) {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Specified depth (%d) is not in the range 1-32\n",
+ scrp->depth);
+ return FALSE;
+ }
+ switch (scrp->bitsPerPixel) {
+ case 1:
+ case 4:
+ case 8:
+ case 16:
+ case 24:
+ case 32:
+ break;
+ default:
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Specified fbbpp (%d) is not a permitted value\n",
+ scrp->bitsPerPixel);
+ return FALSE;
+ }
+ if (scrp->depth > scrp->bitsPerPixel) {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Specified depth (%d) is greater than the fbbpp (%d)\n",
+ scrp->depth, scrp->bitsPerPixel);
+ return FALSE;
+ }
+
+ /* set scrp->pixmap24 if the driver isn't flexible */
+ if (scrp->bitsPerPixel == 24 && !DO_PIX32FOR24(depth24flags)) {
+ scrp->pixmap24 = Pix24Use24;
+ }
+ if (scrp->bitsPerPixel == 32 && !DO_PIX24FOR32(depth24flags)) {
+ scrp->pixmap24 = Pix24Use32;
+ }
+
+ /*
+ * Find the Display subsection matching the depth/fbbpp and initialise
+ * scrp->display with it.
+ */
+ for (i = 0, disp = scrp->confScreen->displays;
+ i < scrp->confScreen->numdisplays; i++, disp++) {
+ if ((disp->depth == scrp->depth && disp->fbbpp == scrp->bitsPerPixel)
+ || (disp->depth == scrp->depth && disp->fbbpp <= 0)
+ || (disp->fbbpp == scrp->bitsPerPixel && disp->depth <= 0)) {
+ scrp->display = disp;
+ break;
+ }
+ }
+
+ /*
+ * If an exact match can't be found, see if there is one with no
+ * depth or fbbpp specified.
+ */
+ if (i == scrp->confScreen->numdisplays) {
+ for (i = 0, disp = scrp->confScreen->displays;
+ i < scrp->confScreen->numdisplays; i++, disp++) {
+ if (disp->depth <= 0 && disp->fbbpp <= 0) {
+ scrp->display = disp;
+ break;
+ }
+ }
+ }
+
+ /*
+ * If all else fails, create a default one.
+ */
+ if (i == scrp->confScreen->numdisplays) {
+ scrp->confScreen->numdisplays++;
+ scrp->confScreen->displays =
+ xnfrealloc(scrp->confScreen->displays,
+ scrp->confScreen->numdisplays * sizeof(DispRec));
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Creating default Display subsection in Screen section\n"
+ "\t\"%s\" for depth/fbbpp %d/%d\n",
+ scrp->confScreen->id, scrp->depth, scrp->bitsPerPixel);
+ memset(&scrp->confScreen->displays[i], 0, sizeof(DispRec));
+ scrp->confScreen->displays[i].blackColour.red = -1;
+ scrp->confScreen->displays[i].blackColour.green = -1;
+ scrp->confScreen->displays[i].blackColour.blue = -1;
+ scrp->confScreen->displays[i].whiteColour.red = -1;
+ scrp->confScreen->displays[i].whiteColour.green = -1;
+ scrp->confScreen->displays[i].whiteColour.blue = -1;
+ scrp->confScreen->displays[i].defaultVisual = -1;
+ scrp->confScreen->displays[i].modes = xnfalloc(sizeof(char *));
+ scrp->confScreen->displays[i].modes[0] = NULL;
+ scrp->confScreen->displays[i].depth = depth;
+ scrp->confScreen->displays[i].fbbpp = fbbpp;
+ scrp->display = &scrp->confScreen->displays[i];
+ }
+
+ /*
+ * Setup defaults for the display-wide attributes the framebuffer will
+ * need. These defaults should eventually be set globally, and not
+ * dependent on the screens.
+ */
+ scrp->imageByteOrder = IMAGE_BYTE_ORDER;
+ scrp->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+ if (scrp->depth < 8) {
+ /* Planar modes need these settings */
+ scrp->bitmapScanlineUnit = 8;
+ scrp->bitmapBitOrder = MSBFirst;
+ } else {
+ scrp->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+ scrp->bitmapBitOrder = BITMAP_BIT_ORDER;
+ }
+
+ /*
+ * If an unusual depth is required, add it to scrp->formats. The formats
+ * for the common depths are handled globally in InitOutput
+ */
+ switch (scrp->depth) {
+ case 1:
+ case 4:
+ case 8:
+ case 15:
+ case 16:
+ case 24:
+ /* Common depths. Nothing to do for them */
+ break;
+ default:
+ if (!xf86AddPixFormat(scrp, scrp->depth, 0, 0)) {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Can't add pixmap format for depth %d\n", scrp->depth);
+ return FALSE;
+ }
+ }
+
+ /* Initialise the framebuffer format for this screen */
+ scrp->fbFormat.depth = scrp->depth;
+ scrp->fbFormat.bitsPerPixel = scrp->bitsPerPixel;
+ scrp->fbFormat.scanlinePad = BITMAP_SCANLINE_PAD;
+
+ return TRUE;
+}
+
+/*
+ * Print out the selected depth and bpp.
+ */
+void
+xf86PrintDepthBpp(ScrnInfoPtr scrp)
+{
+ xf86DrvMsg(scrp->scrnIndex, scrp->depthFrom, "Depth %d, ", scrp->depth);
+ xf86Msg(scrp->bitsPerPixelFrom, "framebuffer bpp %d\n", scrp->bitsPerPixel);
+}
+
+/*
+ * xf86SetWeight sets scrp->weight, scrp->mask, scrp->offset, and for depths
+ * greater than MAX_PSEUDO_DEPTH also scrp->rgbBits.
+ */
+Bool
+xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask)
+{
+ MessageType weightFrom = X_DEFAULT;
+
+ scrp->weight.red = 0;
+ scrp->weight.green = 0;
+ scrp->weight.blue = 0;
+
+ if (xf86Weight.red > 0 && xf86Weight.green > 0 && xf86Weight.blue > 0) {
+ scrp->weight = xf86Weight;
+ weightFrom = X_CMDLINE;
+ } else if (scrp->display->weight.red > 0 && scrp->display->weight.green > 0
+ && scrp->display->weight.blue > 0) {
+ scrp->weight = scrp->display->weight;
+ weightFrom = X_CONFIG;
+ } else if (weight.red > 0 && weight.green > 0 && weight.blue > 0) {
+ scrp->weight = weight;
+ } else {
+ switch (scrp->depth) {
+ case 1:
+ case 4:
+ case 8:
+ scrp->weight.red = scrp->weight.green =
+ scrp->weight.blue = scrp->rgbBits;
+ break;
+ case 15:
+ scrp->weight.red = scrp->weight.green = scrp->weight.blue = 5;
+ break;
+ case 16:
+ scrp->weight.red = scrp->weight.blue = 5;
+ scrp->weight.green = 6;
+ break;
+ case 24:
+ scrp->weight.red = scrp->weight.green = scrp->weight.blue = 8;
+ break;
+ case 30:
+ scrp->weight.red = scrp->weight.green = scrp->weight.blue = 10;
+ break;
+ }
+ }
+
+ if (scrp->weight.red)
+ xf86DrvMsg(scrp->scrnIndex, weightFrom, "RGB weight %d%d%d\n",
+ (int)scrp->weight.red, (int)scrp->weight.green,
+ (int)scrp->weight.blue);
+
+ if (scrp->depth > MAX_PSEUDO_DEPTH &&
+ (scrp->depth != scrp->weight.red + scrp->weight.green +
+ scrp->weight.blue)) {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Weight given (%d%d%d) is inconsistent with the "
+ "depth (%d)\n",
+ (int)scrp->weight.red, (int)scrp->weight.green,
+ (int)scrp->weight.blue, scrp->depth);
+ return FALSE;
+ }
+ if (scrp->depth > MAX_PSEUDO_DEPTH && scrp->weight.red) {
+ /*
+ * XXX Does this even mean anything for TrueColor visuals?
+ * If not, we shouldn't even be setting it here. However, this
+ * matches the behaviour of 3.x versions of XFree86.
+ */
+ scrp->rgbBits = scrp->weight.red;
+ if (scrp->weight.green > scrp->rgbBits)
+ scrp->rgbBits = scrp->weight.green;
+ if (scrp->weight.blue > scrp->rgbBits)
+ scrp->rgbBits = scrp->weight.blue;
+ }
+
+ /* Set the mask and offsets */
+ if (mask.red == 0 || mask.green == 0 || mask.blue == 0) {
+ /* Default to a setting common to PC hardware */
+ scrp->offset.red = scrp->weight.green + scrp->weight.blue;
+ scrp->offset.green = scrp->weight.blue;
+ scrp->offset.blue = 0;
+ scrp->mask.red = ((1 << scrp->weight.red) - 1) << scrp->offset.red;
+ scrp->mask.green = ((1 << scrp->weight.green) - 1)
+ << scrp->offset.green;
+ scrp->mask.blue = (1 << scrp->weight.blue) - 1;
+ } else {
+ /* Initialise to the values passed */
+ scrp->mask.red = mask.red;
+ scrp->mask.green = mask.green;
+ scrp->mask.blue = mask.blue;
+ scrp->offset.red = ffs(mask.red);
+ scrp->offset.green = ffs(mask.green);
+ scrp->offset.blue = ffs(mask.blue);
+ }
+ return TRUE;
+}
+
+Bool
+xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual)
+{
+ MessageType visualFrom = X_DEFAULT;
+
+ if (defaultColorVisualClass >= 0) {
+ scrp->defaultVisual = defaultColorVisualClass;
+ visualFrom = X_CMDLINE;
+ } else if (scrp->display->defaultVisual >= 0) {
+ scrp->defaultVisual = scrp->display->defaultVisual;
+ visualFrom = X_CONFIG;
+ } else if (visual >= 0) {
+ scrp->defaultVisual = visual;
+ } else {
+ if (scrp->depth == 1)
+ scrp->defaultVisual = StaticGray;
+ else if (scrp->depth == 4)
+ scrp->defaultVisual = StaticColor;
+ else if (scrp->depth <= MAX_PSEUDO_DEPTH)
+ scrp->defaultVisual = PseudoColor;
+ else
+ scrp->defaultVisual = TrueColor;
+ }
+ switch (scrp->defaultVisual) {
+ case StaticGray:
+ case GrayScale:
+ case StaticColor:
+ case PseudoColor:
+ case TrueColor:
+ case DirectColor:
+ xf86DrvMsg(scrp->scrnIndex, visualFrom, "Default visual is %s\n",
+ xf86VisualNames[scrp->defaultVisual]);
+ return TRUE;
+ default:
+
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Invalid default visual class (%d)\n", scrp->defaultVisual);
+ return FALSE;
+ }
+}
+
+#define TEST_GAMMA(g) \
+ (g).red > GAMMA_ZERO || (g).green > GAMMA_ZERO || (g).blue > GAMMA_ZERO
+
+#define SET_GAMMA(g) \
+ (g) > GAMMA_ZERO ? (g) : 1.0
+
+Bool
+xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma)
+{
+ MessageType from = X_DEFAULT;
+#if 0
+ xf86MonPtr DDC = (xf86MonPtr)(scrp->monitor->DDC);
+#endif
+ if (TEST_GAMMA(xf86Gamma)) {
+ from = X_CMDLINE;
+ scrp->gamma.red = SET_GAMMA(xf86Gamma.red);
+ scrp->gamma.green = SET_GAMMA(xf86Gamma.green);
+ scrp->gamma.blue = SET_GAMMA(xf86Gamma.blue);
+ } else if (TEST_GAMMA(scrp->monitor->gamma)) {
+ from = X_CONFIG;
+ scrp->gamma.red = SET_GAMMA(scrp->monitor->gamma.red);
+ scrp->gamma.green = SET_GAMMA(scrp->monitor->gamma.green);
+ scrp->gamma.blue = SET_GAMMA(scrp->monitor->gamma.blue);
+#if 0
+ } else if ( DDC && DDC->features.gamma > GAMMA_ZERO ) {
+ from = X_PROBED;
+ scrp->gamma.red = SET_GAMMA(DDC->features.gamma);
+ scrp->gamma.green = SET_GAMMA(DDC->features.gamma);
+ scrp->gamma.blue = SET_GAMMA(DDC->features.gamma);
+ /* EDID structure version 2 gives optional seperate red, green & blue gamma values
+ * in bytes 0x57-0x59 */
+#endif
+ } else if (TEST_GAMMA(gamma)) {
+ scrp->gamma.red = SET_GAMMA(gamma.red);
+ scrp->gamma.green = SET_GAMMA(gamma.green);
+ scrp->gamma.blue = SET_GAMMA(gamma.blue);
+ } else {
+ scrp->gamma.red = 1.0;
+ scrp->gamma.green = 1.0;
+ scrp->gamma.blue = 1.0;
+ }
+ xf86DrvMsg(scrp->scrnIndex, from,
+ "Using gamma correction (%.1f, %.1f, %.1f)\n",
+ scrp->gamma.red, scrp->gamma.green, scrp->gamma.blue);
+
+ return TRUE;
+}
+
+#undef TEST_GAMMA
+#undef SET_GAMMA
+
+
+/*
+ * Set the DPI from the command line option. XXX should allow it to be
+ * calculated from the widthmm/heightmm values.
+ */
+
+#undef MMPERINCH
+#define MMPERINCH 25.4
+
+void
+xf86SetDpi(ScrnInfoPtr pScrn, int x, int y)
+{
+ MessageType from = X_DEFAULT;
+ xf86MonPtr DDC = (xf86MonPtr)(pScrn->monitor->DDC);
+ int ddcWidthmm, ddcHeightmm;
+ int widthErr, heightErr;
+
+ /* XXX Maybe there is no need for widthmm/heightmm in ScrnInfoRec */
+ pScrn->widthmm = pScrn->monitor->widthmm;
+ pScrn->heightmm = pScrn->monitor->heightmm;
+
+ if (DDC && (DDC->features.hsize > 0 && DDC->features.vsize > 0) ) {
+ /* DDC gives display size in mm for individual modes,
+ * but cm for monitor
+ */
+ ddcWidthmm = DDC->features.hsize * 10; /* 10mm in 1cm */
+ ddcHeightmm = DDC->features.vsize * 10; /* 10mm in 1cm */
+ } else {
+ ddcWidthmm = ddcHeightmm = 0;
+ }
+
+ if (monitorResolution > 0) {
+ pScrn->xDpi = monitorResolution;
+ pScrn->yDpi = monitorResolution;
+ from = X_CMDLINE;
+ } else if (pScrn->widthmm > 0 || pScrn->heightmm > 0) {
+ from = X_CONFIG;
+ if (pScrn->widthmm > 0) {
+ pScrn->xDpi =
+ (int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm);
+ }
+ if (pScrn->heightmm > 0) {
+ pScrn->yDpi =
+ (int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm);
+ }
+ if (pScrn->xDpi > 0 && pScrn->yDpi <= 0)
+ pScrn->yDpi = pScrn->xDpi;
+ if (pScrn->yDpi > 0 && pScrn->xDpi <= 0)
+ pScrn->xDpi = pScrn->yDpi;
+ xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n",
+ pScrn->widthmm, pScrn->heightmm);
+
+ /* Warn if config and probe disagree about display size */
+ if ( ddcWidthmm && ddcHeightmm ) {
+ if (pScrn->widthmm > 0) {
+ widthErr = abs(ddcWidthmm - pScrn->widthmm);
+ } else {
+ widthErr = 0;
+ }
+ if (pScrn->heightmm > 0) {
+ heightErr = abs(ddcHeightmm - pScrn->heightmm);
+ } else {
+ heightErr = 0;
+ }
+ if (widthErr>10 || heightErr>10) {
+ /* Should include config file name for monitor here */
+ xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+ "Probed monitor is %dx%d mm, using Displaysize %dx%d mm\n",
+ ddcWidthmm,ddcHeightmm, pScrn->widthmm,pScrn->heightmm);
+ }
+ }
+ } else if ( ddcWidthmm && ddcHeightmm ) {
+ from = X_PROBED;
+ xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n",
+ ddcWidthmm, ddcHeightmm );
+ pScrn->widthmm = ddcWidthmm;
+ pScrn->heightmm = ddcHeightmm;
+ if (pScrn->widthmm > 0) {
+ pScrn->xDpi =
+ (int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm);
+ }
+ if (pScrn->heightmm > 0) {
+ pScrn->yDpi =
+ (int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm);
+ }
+ if (pScrn->xDpi > 0 && pScrn->yDpi <= 0)
+ pScrn->yDpi = pScrn->xDpi;
+ if (pScrn->yDpi > 0 && pScrn->xDpi <= 0)
+ pScrn->xDpi = pScrn->yDpi;
+ } else {
+ if (x > 0)
+ pScrn->xDpi = x;
+ else
+ pScrn->xDpi = DEFAULT_DPI;
+ if (y > 0)
+ pScrn->yDpi = y;
+ else
+ pScrn->yDpi = DEFAULT_DPI;
+ }
+ xf86DrvMsg(pScrn->scrnIndex, from, "DPI set to (%d, %d)\n",
+ pScrn->xDpi, pScrn->yDpi);
+}
+
+#undef MMPERINCH
+
+
+void
+xf86SetBlackWhitePixels(ScreenPtr pScreen)
+{
+ if (xf86FlipPixels) {
+ pScreen->whitePixel = 0;
+ pScreen->blackPixel = 1;
+ } else {
+ pScreen->whitePixel = 1;
+ pScreen->blackPixel = 0;
+ }
+}
+
+/*
+ * xf86SetRootClip --
+ * Enable or disable rendering to the screen by
+ * setting the root clip list and revalidating
+ * all of the windows
+ */
+
+static void
+xf86SetRootClip (ScreenPtr pScreen, Bool enable)
+{
+ WindowPtr pWin = WindowTable[pScreen->myNum];
+ WindowPtr pChild;
+ Bool WasViewable = (Bool)(pWin->viewable);
+ Bool anyMarked = FALSE;
+ RegionPtr pOldClip = NULL, bsExposed;
+#ifdef DO_SAVE_UNDERS
+ Bool dosave = FALSE;
+#endif
+ WindowPtr pLayerWin;
+ BoxRec box;
+
+ if (WasViewable)
+ {
+ for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
+ {
+ (void) (*pScreen->MarkOverlappedWindows)(pChild,
+ pChild,
+ &pLayerWin);
+ }
+ (*pScreen->MarkWindow) (pWin);
+ anyMarked = TRUE;
+ if (pWin->valdata)
+ {
+ if (HasBorder (pWin))
+ {
+ RegionPtr borderVisible;
+
+ borderVisible = REGION_CREATE(pScreen, NullBox, 1);
+ REGION_SUBTRACT(pScreen, borderVisible,
+ &pWin->borderClip, &pWin->winSize);
+ pWin->valdata->before.borderVisible = borderVisible;
+ }
+ pWin->valdata->before.resized = TRUE;
+ }
+ }
+
+ /*
+ * Use REGION_BREAK to avoid optimizations in ValidateTree
+ * that assume the root borderClip can't change well, normally
+ * it doesn't...)
+ */
+ if (enable)
+ {
+ box.x1 = 0;
+ box.y1 = 0;
+ box.x2 = pScreen->width;
+ box.y2 = pScreen->height;
+ REGION_INIT (pScreen, &pWin->winSize, &box, 1);
+ REGION_INIT (pScreen, &pWin->borderSize, &box, 1);
+ if (WasViewable)
+ REGION_RESET(pScreen, &pWin->borderClip, &box);
+ pWin->drawable.width = pScreen->width;
+ pWin->drawable.height = pScreen->height;
+ REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+ }
+ else
+ {
+ REGION_EMPTY(pScreen, &pWin->borderClip);
+ REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+ }
+
+ ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
+
+ if (WasViewable)
+ {
+ if (pWin->backStorage)
+ {
+ pOldClip = REGION_CREATE(pScreen, NullBox, 1);
+ REGION_COPY(pScreen, pOldClip, &pWin->clipList);
+ }
+
+ if (pWin->firstChild)
+ {
+ anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin->firstChild,
+ pWin->firstChild,
+ (WindowPtr *)NULL);
+ }
+ else
+ {
+ (*pScreen->MarkWindow) (pWin);
+ anyMarked = TRUE;
+ }
+
+#ifdef DO_SAVE_UNDERS
+ if (DO_SAVE_UNDERS(pWin))
+ {
+ dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin);
+ }
+#endif /* DO_SAVE_UNDERS */
+
+ if (anyMarked)
+ (*pScreen->ValidateTree)(pWin, NullWindow, VTOther);
+ }
+
+ if (pWin->backStorage &&
+ ((pWin->backingStore == Always) || WasViewable))
+ {
+ if (!WasViewable)
+ pOldClip = &pWin->clipList; /* a convenient empty region */
+ bsExposed = (*pScreen->TranslateBackingStore)
+ (pWin, 0, 0, pOldClip,
+ pWin->drawable.x, pWin->drawable.y);
+ if (WasViewable)
+ REGION_DESTROY(pScreen, pOldClip);
+ if (bsExposed)
+ {
+ RegionPtr valExposed = NullRegion;
+
+ if (pWin->valdata)
+ valExposed = &pWin->valdata->after.exposed;
+ (*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
+ if (valExposed)
+ REGION_EMPTY(pScreen, valExposed);
+ REGION_DESTROY(pScreen, bsExposed);
+ }
+ }
+ if (WasViewable)
+ {
+ if (anyMarked)
+ (*pScreen->HandleExposures)(pWin);
+#ifdef DO_SAVE_UNDERS
+ if (dosave)
+ (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin);
+#endif /* DO_SAVE_UNDERS */
+ if (anyMarked && pScreen->PostValidateTree)
+ (*pScreen->PostValidateTree)(pWin, NullWindow, VTOther);
+ }
+ if (pWin->realized)
+ WindowsRestructured ();
+ FlushAllOutput ();
+}
+
+/*
+ * Function to enable/disable access to the frame buffer
+ *
+ * This is used when VT switching and when entering/leaving DGA direct mode.
+ *
+ * This has been rewritten again to eliminate the saved pixmap. The
+ * devPrivate field in the screen pixmap is set to NULL to catch code
+ * accidentally referencing the frame buffer while the X server is not
+ * supposed to touch it.
+ *
+ * Here, we exchange the pixmap private data, rather than the pixmaps
+ * themselves to avoid having to find and change any references to the screen
+ * pixmap such as GC's, window privates etc. This also means that this code
+ * does not need to know exactly how the pixmap pixels are accessed. Further,
+ * this exchange is >not< done through the screen's ModifyPixmapHeader()
+ * vector. This means the called frame buffer code layers can determine
+ * whether they are switched in or out by keeping track of the root pixmap's
+ * private data, and therefore don't need to access pScrnInfo->vtSema.
+ */
+void
+xf86EnableDisableFBAccess(int scrnIndex, Bool enable)
+{
+ ScrnInfoPtr pScrnInfo = xf86Screens[scrnIndex];
+ ScreenPtr pScreen = pScrnInfo->pScreen;
+ PixmapPtr pspix;
+
+ pspix = (*pScreen->GetScreenPixmap) (pScreen);
+ if (enable)
+ {
+ /*
+ * Restore the screen pixmap devPrivate field
+ */
+ pspix->devPrivate = pScrnInfo->pixmapPrivate;
+ /*
+ * Restore all of the clip lists on the screen
+ */
+ if (!xf86Resetting)
+ xf86SetRootClip (pScreen, TRUE);
+
+ }
+ else
+ {
+ /*
+ * Empty all of the clip lists on the screen
+ */
+ xf86SetRootClip (pScreen, FALSE);
+ /*
+ * save the screen pixmap devPrivate field and
+ * replace it with NULL so accidental references
+ * to the frame buffer are caught
+ */
+ pScrnInfo->pixmapPrivate = pspix->devPrivate;
+ pspix->devPrivate.ptr = NULL;
+ }
+}
+
+/* Print driver messages in the standard format */
+
+#undef PREFIX_SIZE
+#define PREFIX_SIZE 14
+
+void
+xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
+ va_list args)
+{
+ char *tmpFormat;
+
+ /* Prefix the scrnIndex name to the format string. */
+ if (scrnIndex >= 0 && scrnIndex < xf86NumScreens &&
+ xf86Screens[scrnIndex]->name) {
+ tmpFormat = xalloc(strlen(format) +
+ strlen(xf86Screens[scrnIndex]->name) +
+ PREFIX_SIZE + 1);
+ if (!tmpFormat)
+ return;
+
+ snprintf(tmpFormat, PREFIX_SIZE + 1, "%s(%d): ",
+ xf86Screens[scrnIndex]->name, scrnIndex);
+
+ strcat(tmpFormat, format);
+ LogVMessageVerb(type, verb, tmpFormat, args);
+ xfree(tmpFormat);
+ } else
+ LogVMessageVerb(type, verb, format, args);
+}
+#undef PREFIX_SIZE
+
+/* Print driver messages, with verbose level specified directly */
+void
+xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
+ ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ xf86VDrvMsgVerb(scrnIndex, type, verb, format, ap);
+ va_end(ap);
+}
+
+/* Print driver messages, with verbose level of 1 (default) */
+void
+xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ xf86VDrvMsgVerb(scrnIndex, type, 1, format, ap);
+ va_end(ap);
+}
+
+/* Print non-driver messages with verbose level specified directly */
+void
+xf86MsgVerb(MessageType type, int verb, const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ xf86VDrvMsgVerb(-1, type, verb, format, ap);
+ va_end(ap);
+}
+
+/* Print non-driver messages with verbose level of 1 (default) */
+void
+xf86Msg(MessageType type, const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ xf86VDrvMsgVerb(-1, type, 1, format, ap);
+ va_end(ap);
+}
+
+/* Just like ErrorF, but with the verbose level checked */
+void
+xf86ErrorFVerb(int verb, const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ if (xf86Verbose >= verb || xf86LogVerbose >= verb)
+ LogVWrite(verb, format, ap);
+ va_end(ap);
+}
+
+/* Like xf86ErrorFVerb, but with an implied verbose level of 1 */
+void
+xf86ErrorF(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ if (xf86Verbose >= 1 || xf86LogVerbose >= 1)
+ LogVWrite(1, format, ap);
+ va_end(ap);
+}
+
+
+void
+xf86LogInit()
+{
+ char *lf;
+
+#define LOGSUFFIX ".log"
+#define LOGOLDSUFFIX ".old"
+
+ /* Get the log file name */
+ if (xf86LogFileFrom == X_DEFAULT) {
+ /* Append the display number and ".log" */
+ lf = malloc(strlen(xf86LogFile) + strlen("%s") +
+ strlen(LOGSUFFIX) + 1);
+ if (!lf)
+ FatalError("Cannot allocate space for the log file name\n");
+ sprintf(lf, "%s%%s" LOGSUFFIX, xf86LogFile);
+ xf86LogFile = lf;
+ }
+
+ xf86LogFile = LogInit(xf86LogFile, LOGOLDSUFFIX);
+ xf86LogFileWasOpened = TRUE;
+
+ xf86SetVerbosity(xf86Verbose);
+ xf86SetLogVerbosity(xf86LogVerbose);
+
+#undef LOGSUFFIX
+#undef LOGOLDSUFFIX
+}
+
+void
+xf86CloseLog()
+{
+ LogClose();
+}
+
+
+/*
+ * Drivers can use these for using their own SymTabRecs.
+ */
+
+const char *
+xf86TokenToString(SymTabPtr table, int token)
+{
+ int i;
+
+ for (i = 0; table[i].token >= 0 && table[i].token != token; i++)
+ ;
+
+ if (table[i].token < 0)
+ return NULL;
+ else
+ return(table[i].name);
+}
+
+int
+xf86StringToToken(SymTabPtr table, const char *string)
+{
+ int i;
+
+ if (string == NULL)
+ return -1;
+
+ for (i = 0; table[i].token >= 0 && xf86NameCmp(string, table[i].name); i++)
+ ;
+
+ return(table[i].token);
+}
+
+/*
+ * helper to display the clocks found on a card
+ */
+void
+xf86ShowClocks(ScrnInfoPtr scrp, MessageType from)
+{
+ int j;
+
+ xf86DrvMsg(scrp->scrnIndex, from, "Pixel clocks available:");
+ for (j=0; j < scrp->numClocks; j++) {
+ if ((j % 4) == 0) {
+ xf86ErrorF("\n");
+ xf86DrvMsg(scrp->scrnIndex, from, "pixel clocks:");
+ }
+ xf86ErrorF(" %7.3f", (double)scrp->clock[j] / 1000.0);
+ }
+ xf86ErrorF("\n");
+}
+
+
+/*
+ * This prints out the driver identify message, including the names of
+ * the supported chipsets.
+ *
+ * XXX This makes assumptions about the line width, etc. Maybe we could
+ * use a more general "pretty print" function for messages.
+ */
+void
+xf86PrintChipsets(const char *drvname, const char *drvmsg, SymTabPtr chips)
+{
+ int len, i;
+
+ len = 6 + strlen(drvname) + 2 + strlen(drvmsg) + 2;
+ xf86Msg(X_INFO, "%s: %s:", drvname, drvmsg);
+ for (i = 0; chips[i].name != NULL; i++) {
+ if (i != 0) {
+ xf86ErrorF(",");
+ len++;
+ }
+ if (len + 2 + strlen(chips[i].name) < 78) {
+ xf86ErrorF(" ");
+ len++;
+ } else {
+ xf86ErrorF("\n\t");
+ len = 8;
+ }
+ xf86ErrorF("%s", chips[i].name);
+ len += strlen(chips[i].name);
+ }
+ xf86ErrorF("\n");
+}
+
+
+#define MAXDRIVERS 64 /* A >hack<, to be sure ... */
+
+
+int
+xf86MatchDevice(const char *drivername, GDevPtr **sectlist)
+{
+ GDevPtr gdp, *pgdp = NULL;
+ confScreenPtr screensecptr;
+ int i,j;
+
+ if (sectlist)
+ *sectlist = NULL;
+
+ if (xf86DoProbe) return 1;
+
+ if (xf86DoConfigure && xf86DoConfigurePass1) return 1;
+
+ /*
+ * This is a very important function that matches the device sections
+ * as they show up in the config file with the drivers that the server
+ * loads at run time.
+ *
+ * ChipProbe can call
+ * int xf86MatchDevice(char * drivername, GDevPtr ** sectlist)
+ * with its driver name. The function allocates an array of GDevPtr and
+ * returns this via sectlist and returns the number of elements in
+ * this list as return value. 0 means none found, -1 means fatal error.
+ *
+ * It can figure out which of the Device sections to use for which card
+ * (using things like the Card statement, etc). For single headed servers
+ * there will of course be just one such Device section.
+ */
+ i = 0;
+
+ /*
+ * first we need to loop over all the Screens sections to get to all
+ * 'active' device sections
+ */
+ for (j=0; xf86ConfigLayout.screens[j].screen != NULL; j++) {
+ screensecptr = xf86ConfigLayout.screens[j].screen;
+ if ((screensecptr->device->driver != NULL)
+ && (xf86NameCmp( screensecptr->device->driver,drivername) == 0)
+ && (! screensecptr->device->claimed)) {
+ /*
+ * we have a matching driver that wasn't claimed, yet
+ */
+ pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr));
+ pgdp[i++] = screensecptr->device;
+ }
+ }
+
+ /* Then handle the inactive devices */
+ j = 0;
+ while (xf86ConfigLayout.inactives[j].identifier) {
+ gdp = &xf86ConfigLayout.inactives[j];
+ if (gdp->driver && !gdp->claimed &&
+ !xf86NameCmp(gdp->driver,drivername)) {
+ /* we have a matching driver that wasn't claimed yet */
+ pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr));
+ pgdp[i++] = gdp;
+ }
+ j++;
+ }
+
+ /*
+ * make the array NULL terminated and return its address
+ */
+ if (i)
+ pgdp[i] = NULL;
+
+ if (sectlist)
+ *sectlist = pgdp;
+ else
+ xfree(pgdp);
+ return i;
+}
+
+struct Inst {
+ pciVideoPtr pci;
+ GDevPtr dev;
+ Bool foundHW; /* PCIid in list of supported chipsets */
+ Bool claimed; /* BusID matches with a device section */
+ int chip;
+ int screen;
+};
+
+int
+xf86MatchPciInstances(const char *driverName, int vendorID,
+ SymTabPtr chipsets, PciChipsets *PCIchipsets,
+ GDevPtr *devList, int numDevs, DriverPtr drvp,
+ int **foundEntities)
+{
+ int i,j;
+ MessageType from;
+ pciVideoPtr pPci, *ppPci;
+ struct Inst {
+ pciVideoPtr pci;
+ GDevPtr dev;
+ Bool foundHW; /* PCIid in list of supported chipsets */
+ Bool claimed; /* BusID matches with a device section */
+ int chip;
+ int screen;
+ } *instances = NULL;
+ int numClaimedInstances = 0;
+ int allocatedInstances = 0;
+ int numFound = 0;
+ SymTabRec *c;
+ PciChipsets *id;
+ GDevPtr devBus = NULL;
+ GDevPtr dev = NULL;
+ int *retEntities = NULL;
+
+ *foundEntities = NULL;
+
+ if (vendorID == 0) {
+ for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
+ Bool foundVendor = FALSE;
+ for (id = PCIchipsets; id->PCIid != -1; id++) {
+ if ( (((id->PCIid & 0xFFFF0000) >> 16) == (*ppPci)->vendor)) {
+ if (!foundVendor) {
+ ++allocatedInstances;
+ instances = xnfrealloc(instances,
+ allocatedInstances * sizeof(struct Inst));
+ instances[allocatedInstances - 1].pci = *ppPci;
+ instances[allocatedInstances - 1].dev = NULL;
+ instances[allocatedInstances - 1].claimed = FALSE;
+ instances[allocatedInstances - 1].foundHW = FALSE;
+ instances[allocatedInstances - 1].screen = 0;
+ foundVendor = TRUE;
+ }
+ if ((id->PCIid & 0x0000FFFF) == (*ppPci)->chipType) {
+ instances[allocatedInstances - 1].foundHW = TRUE;
+ instances[allocatedInstances - 1].chip = id->numChipset;
+ numFound++;
+ }
+ }
+ }
+ }
+ } else if (vendorID == PCI_VENDOR_GENERIC) {
+ for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
+ for (id = PCIchipsets; id->PCIid != -1; id++) {
+ if (id->PCIid == xf86CheckPciGAType(*ppPci)) {
+ ++allocatedInstances;
+ instances = xnfrealloc(instances,
+ allocatedInstances * sizeof(struct Inst));
+ instances[allocatedInstances - 1].pci = *ppPci;
+ instances[allocatedInstances - 1].dev = NULL;
+ instances[allocatedInstances - 1].claimed = FALSE;
+ instances[allocatedInstances - 1].foundHW = TRUE;
+ instances[allocatedInstances - 1].chip = id->numChipset;
+ instances[allocatedInstances - 1].screen = 0;
+ numFound++;
+ }
+ }
+ }
+ } else {
+ /* Find PCI devices that match the given vendor ID */
+ for (ppPci = xf86PciVideoInfo; (ppPci != NULL)
+ && (*ppPci != NULL); ppPci++) {
+ if ((*ppPci)->vendor == vendorID) {
+ ++allocatedInstances;
+ instances = xnfrealloc(instances,
+ allocatedInstances * sizeof(struct Inst));
+ instances[allocatedInstances - 1].pci = *ppPci;
+ instances[allocatedInstances - 1].dev = NULL;
+ instances[allocatedInstances - 1].claimed = FALSE;
+ instances[allocatedInstances - 1].foundHW = FALSE;
+ instances[allocatedInstances - 1].screen = 0;
+
+ /* Check if the chip type is listed in the chipsets table */
+ for (id = PCIchipsets; id->PCIid != -1; id++) {
+ if (id->PCIid == (*ppPci)->chipType) {
+ instances[allocatedInstances - 1].chip
+ = id->numChipset;
+ instances[allocatedInstances - 1].foundHW = TRUE;
+ numFound++;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * This may be debatable, but if no PCI devices with a matching vendor
+ * type is found, return zero now. It is probably not desirable to
+ * allow the config file to override this.
+ */
+ if (allocatedInstances <= 0) {
+ xfree(instances);
+ return 0;
+ }
+
+ if (xf86DoProbe) {
+ xfree(instances);
+ return numFound;
+ }
+
+ if (xf86DoConfigure && xf86DoConfigurePass1) {
+ GDevPtr pGDev;
+ int actualcards = 0;
+ for (i = 0; i < allocatedInstances; i++) {
+ pPci = instances[i].pci;
+ if (instances[i].foundHW) {
+ if (!xf86CheckPciSlot(pPci->bus, pPci->device, pPci->func))
+ continue;
+ actualcards++;
+ pGDev = xf86AddDeviceToConfigure(drvp->driverName,
+ instances[i].pci, -1);
+ if (pGDev) {
+ /*
+ * XF86Match???Instances() treat chipID and chipRev as
+ * overrides, so clobber them here.
+ */
+ pGDev->chipID = pGDev->chipRev = -1;
+ }
+ }
+ }
+ xfree(instances);
+ return actualcards;
+ }
+
+#ifdef DEBUG
+ ErrorF("%s instances found: %d\n", driverName, allocatedInstances);
+#endif
+
+ /*
+ * Check for devices that need duplicated instances. This is required
+ * when there is more than one screen per entity.
+ *
+ * XXX This currently doesn't work for cases where the BusID isn't
+ * specified explicitly in the config file.
+ */
+
+ for (j = 0; j < numDevs; j++) {
+ if (devList[j]->screen > 0 && devList[j]->busID
+ && *devList[j]->busID) {
+ for (i = 0; i < allocatedInstances; i++) {
+ pPci = instances[i].pci;
+ if (xf86ComparePciBusString(devList[j]->busID, pPci->bus,
+ pPci->device,
+ pPci->func)) {
+ allocatedInstances++;
+ instances = xnfrealloc(instances,
+ allocatedInstances *
+ sizeof(struct Inst));
+ instances[allocatedInstances - 1] = instances[i];
+ instances[allocatedInstances - 1].screen =
+ devList[j]->screen;
+ numFound++;
+ break;
+ }
+ }
+ }
+ }
+
+ for (i = 0; i < allocatedInstances; i++) {
+ pPci = instances[i].pci;
+ devBus = NULL;
+ dev = NULL;
+ for (j = 0; j < numDevs; j++) {
+ if (devList[j]->busID && *devList[j]->busID) {
+ if (xf86ComparePciBusString(devList[j]->busID, pPci->bus,
+ pPci->device,
+ pPci->func) &&
+ devList[j]->screen == instances[i].screen) {
+
+ if (devBus)
+ xf86MsgVerb(X_WARNING,0,
+ "%s: More than one matching Device section for "
+ "instances\n\t(BusID: %s) found: %s\n",
+ driverName, devList[j]->busID,
+ devList[j]->identifier);
+ else
+ devBus = devList[j];
+ }
+ } else {
+ /*
+ * if device section without BusID is found
+ * only assign to it to the primary device.
+ */
+ if (xf86IsPrimaryPci(pPci)) {
+ xf86Msg(X_PROBED, "Assigning device section with no busID"
+ " to primary device\n");
+ if (dev || devBus)
+ xf86MsgVerb(X_WARNING, 0,
+ "%s: More than one matching Device section "
+ "found: %s\n", driverName, devList[j]->identifier);
+ else
+ dev = devList[j];
+ }
+ }
+ }
+ if (devBus) dev = devBus; /* busID preferred */
+ if (!dev) {
+ if (xf86CheckPciSlot(pPci->bus, pPci->device, pPci->func)) {
+ xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section "
+ "for instance (BusID PCI:%i:%i:%i) found\n",
+ driverName, pPci->bus, pPci->device, pPci->func);
+ }
+ } else {
+ numClaimedInstances++;
+ instances[i].claimed = TRUE;
+ instances[i].dev = dev;
+ }
+ }
+#ifdef DEBUG
+ ErrorF("%s instances found: %d\n", driverName, numClaimedInstances);
+#endif
+ /*
+ * Now check that a chipset or chipID override in the device section
+ * is valid. Chipset has precedence over chipID.
+ * If chipset is not valid ignore BusSlot completely.
+ */
+ for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) {
+ if (!instances[i].claimed) {
+ continue;
+ }
+ from = X_PROBED;
+ if (instances[i].dev->chipset) {
+ for (c = chipsets; c->token >= 0; c++) {
+ if (xf86NameCmp(c->name, instances[i].dev->chipset) == 0)
+ break;
+ }
+ if (c->token == -1) {
+ instances[i].claimed = FALSE;
+ numClaimedInstances--;
+ xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device "
+ "section \"%s\" isn't valid for this driver\n",
+ driverName, instances[i].dev->chipset,
+ instances[i].dev->identifier);
+ } else {
+ instances[i].chip = c->token;
+
+ for (id = PCIchipsets; id->numChipset >= 0; id++) {
+ if (id->numChipset == instances[i].chip)
+ break;
+ }
+ if(id->numChipset >=0){
+ xf86Msg(X_CONFIG,"Chipset override: %s\n",
+ instances[i].dev->chipset);
+ from = X_CONFIG;
+ } else {
+ instances[i].claimed = FALSE;
+ numClaimedInstances--;
+ xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device "
+ "section \"%s\" isn't a valid PCI chipset\n",
+ driverName, instances[i].dev->chipset,
+ instances[i].dev->identifier);
+ }
+ }
+ } else if (instances[i].dev->chipID > 0) {
+ for (id = PCIchipsets; id->numChipset >= 0; id++) {
+ if (id->PCIid == instances[i].dev->chipID)
+ break;
+ }
+ if (id->numChipset == -1) {
+ instances[i].claimed = FALSE;
+ numClaimedInstances--;
+ xf86MsgVerb(X_WARNING, 0, "%s: ChipID 0x%04X in Device "
+ "section \"%s\" isn't valid for this driver\n",
+ driverName, instances[i].dev->chipID,
+ instances[i].dev->identifier);
+ } else {
+ instances[i].chip = id->numChipset;
+
+ xf86Msg( X_CONFIG,"ChipID override: 0x%04X\n",
+ instances[i].dev->chipID);
+ from = X_CONFIG;
+ }
+ } else if (!instances[i].foundHW) {
+ /*
+ * This means that there was no override and the PCI chipType
+ * doesn't match one that is supported
+ */
+ instances[i].claimed = FALSE;
+ numClaimedInstances--;
+ }
+ if (instances[i].claimed == TRUE){
+ for (c = chipsets; c->token >= 0; c++) {
+ if (c->token == instances[i].chip)
+ break;
+ }
+ xf86Msg(from,"Chipset %s found\n",
+ c->name);
+ }
+ }
+
+ /*
+ * Of the claimed instances, check that another driver hasn't already
+ * claimed its slot.
+ */
+ numFound = 0;
+ for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) {
+
+ if (!instances[i].claimed)
+ continue;
+ pPci = instances[i].pci;
+
+
+ /*
+ * Allow the same entity to be used more than once for devices with
+ * multiple screens per entity. This assumes implicitly that there
+ * will be a screen == 0 instance.
+ *
+ * XXX Need to make sure that two different drivers don't claim
+ * the same screen > 0 instance.
+ */
+ if (instances[i].screen == 0 &&
+ !xf86CheckPciSlot(pPci->bus, pPci->device, pPci->func))
+ continue;
+
+#ifdef DEBUG
+ ErrorF("%s: card at %d:%d:%d is claimed by a Device section\n",
+ driverName, pPci->bus, pPci->device, pPci->func);
+#endif
+
+ /* Allocate an entry in the lists to be returned */
+ numFound++;
+ retEntities = xnfrealloc(retEntities, numFound * sizeof(int));
+ retEntities[numFound - 1]
+ = xf86ClaimPciSlot(pPci->bus, pPci->device,
+ pPci->func,drvp, instances[i].chip,
+ instances[i].dev,instances[i].dev->active ?
+ TRUE : FALSE);
+ if (retEntities[numFound - 1] == -1 && instances[i].screen > 0) {
+ for (j = 0; j < xf86NumEntities; j++) {
+ EntityPtr pEnt = xf86Entities[j];
+ if (pEnt->busType != BUS_PCI)
+ continue;
+ if (pEnt->pciBusId.bus == pPci->bus &&
+ pEnt->pciBusId.device == pPci->device &&
+ pEnt->pciBusId.func == pPci->func) {
+ retEntities[numFound - 1] = j;
+ xf86AddDevToEntity(j, instances[i].dev);
+ break;
+ }
+ }
+ }
+ }
+ xfree(instances);
+ if (numFound > 0) {
+ *foundEntities = retEntities;
+ }
+
+ return numFound;
+}
+
+int
+xf86MatchIsaInstances(const char *driverName, SymTabPtr chipsets,
+ IsaChipsets *ISAchipsets, DriverPtr drvp,
+ FindIsaDevProc FindIsaDevice, GDevPtr *devList,
+ int numDevs, int **foundEntities)
+{
+ SymTabRec *c;
+ IsaChipsets *Chips;
+ int i;
+ int numFound = 0;
+ int foundChip = -1;
+ int *retEntities = NULL;
+
+ *foundEntities = NULL;
+
+#if defined(__sparc__) || defined(__powerpc__)
+ FindIsaDevice = NULL; /* Temporary */
+#endif
+
+ if (xf86DoProbe || (xf86DoConfigure && xf86DoConfigurePass1)) {
+ if (FindIsaDevice &&
+ ((foundChip = (*FindIsaDevice)(NULL)) != -1)) {
+ xf86AddDeviceToConfigure(drvp->driverName, NULL, foundChip);
+ return 1;
+ }
+ return 0;
+ }
+
+ for (i = 0; i < numDevs; i++) {
+ MessageType from = X_CONFIG;
+ GDevPtr dev = NULL;
+ GDevPtr devBus = NULL;
+
+ if (devList[i]->busID && *devList[i]->busID) {
+ if (xf86ParseIsaBusString(devList[i]->busID)) {
+ if (devBus) xf86MsgVerb(X_WARNING,0,
+ "%s: More than one matching Device "
+ "section for ISA-Bus found: %s\n",
+ driverName,devList[i]->identifier);
+ else devBus = devList[i];
+ }
+ } else {
+ if (xf86IsPrimaryIsa()) {
+ if (dev) xf86MsgVerb(X_WARNING,0,
+ "%s: More than one matching "
+ "Device section found: %s\n",
+ driverName,devList[i]->identifier);
+ else dev = devList[i];
+ }
+ }
+ if (devBus) dev = devBus;
+ if (dev) {
+ if (dev->chipset) {
+ for (c = chipsets; c->token >= 0; c++) {
+ if (xf86NameCmp(c->name, dev->chipset) == 0)
+ break;
+ }
+ if (c->token == -1) {
+ xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device "
+ "section \"%s\" isn't valid for this driver\n",
+ driverName, dev->chipset,
+ dev->identifier);
+ } else
+ foundChip = c->token;
+ } else {
+ if (FindIsaDevice) foundChip = (*FindIsaDevice)(dev);
+ /* Probe it */
+ from = X_PROBED;
+ }
+ }
+
+ /* Check if the chip type is listed in the chipset table - for sanity*/
+
+ if (foundChip >= 0){
+ for (Chips = ISAchipsets; Chips->numChipset >= 0; Chips++) {
+ if (Chips->numChipset == foundChip)
+ break;
+ }
+ if (Chips->numChipset == -1){
+ foundChip = -1;
+ xf86MsgVerb(X_WARNING,0,
+ "%s: Driver detected unknown ISA-Bus Chipset\n",
+ driverName);
+ }
+ }
+ if (foundChip != -1) {
+ numFound++;
+ retEntities = xnfrealloc(retEntities,numFound * sizeof(int));
+ retEntities[numFound - 1] =
+ xf86ClaimIsaSlot(drvp,foundChip,dev, dev->active ? TRUE : FALSE);
+ for (c = chipsets; c->token >= 0; c++) {
+ if (c->token == foundChip)
+ break;
+ }
+ xf86Msg(from, "Chipset %s found\n", c->name);
+ }
+ }
+ *foundEntities = retEntities;
+
+ return numFound;
+}
+
+/*
+ * xf86GetClocks -- get the dot-clocks via a BIG BAD hack ...
+ */
+void
+xf86GetClocks(ScrnInfoPtr pScrn, int num, Bool (*ClockFunc)(ScrnInfoPtr, int),
+ void (*ProtectRegs)(ScrnInfoPtr, Bool),
+ void (*BlankScreen)(ScrnInfoPtr, Bool), IOADDRESS vertsyncreg,
+ int maskval, int knownclkindex, int knownclkvalue)
+{
+ register int status = vertsyncreg;
+ unsigned long i, cnt, rcnt, sync;
+
+ /* First save registers that get written on */
+ (*ClockFunc)(pScrn, CLK_REG_SAVE);
+
+ xf86SetPriority(TRUE);
+
+ if (num > MAXCLOCKS)
+ num = MAXCLOCKS;
+
+ for (i = 0; i < num; i++)
+ {
+ if (ProtectRegs)
+ (*ProtectRegs)(pScrn, TRUE);
+ if (!(*ClockFunc)(pScrn, i))
+ {
+ pScrn->clock[i] = -1;
+ continue;
+ }
+ if (ProtectRegs)
+ (*ProtectRegs)(pScrn, FALSE);
+ if (BlankScreen)
+ (*BlankScreen)(pScrn, FALSE);
+
+ usleep(50000); /* let VCO stabilise */
+
+ cnt = 0;
+ sync = 200000;
+
+ /* XXX How critical is this? */
+ if (!xf86DisableInterrupts())
+ {
+ (*ClockFunc)(pScrn, CLK_REG_RESTORE);
+ ErrorF("Failed to disable interrupts during clock probe. If\n");
+ ErrorF("your OS does not support disabling interrupts, then you\n");
+ FatalError("must specify a Clocks line in the XF86Config file.\n");
+ }
+ while ((inb(status) & maskval) == 0x00)
+ if (sync-- == 0) goto finish;
+ /* Something appears to be happening, so reset sync count */
+ sync = 200000;
+ while ((inb(status) & maskval) == maskval)
+ if (sync-- == 0) goto finish;
+ /* Something appears to be happening, so reset sync count */
+ sync = 200000;
+ while ((inb(status) & maskval) == 0x00)
+ if (sync-- == 0) goto finish;
+
+ for (rcnt = 0; rcnt < 5; rcnt++)
+ {
+ while (!(inb(status) & maskval))
+ cnt++;
+ while ((inb(status) & maskval))
+ cnt++;
+ }
+
+finish:
+ xf86EnableInterrupts();
+
+ pScrn->clock[i] = cnt ? cnt : -1;
+ if (BlankScreen)
+ (*BlankScreen)(pScrn, TRUE);
+ }
+
+ xf86SetPriority(FALSE);
+
+ for (i = 0; i < num; i++)
+ {
+ if (i != knownclkindex)
+ {
+ if (pScrn->clock[i] == -1)
+ {
+ pScrn->clock[i] = 0;
+ }
+ else
+ {
+ pScrn->clock[i] = (int)(0.5 +
+ (((float)knownclkvalue) * pScrn->clock[knownclkindex]) /
+ (pScrn->clock[i]));
+ /* Round to nearest 10KHz */
+ pScrn->clock[i] += 5;
+ pScrn->clock[i] /= 10;
+ pScrn->clock[i] *= 10;
+ }
+ }
+ }
+
+ pScrn->clock[knownclkindex] = knownclkvalue;
+ pScrn->numClocks = num;
+
+ /* Restore registers that were written on */
+ (*ClockFunc)(pScrn, CLK_REG_RESTORE);
+}
+
+void
+xf86SetPriority(Bool up)
+{
+ static int saved_nice;
+
+ if (up) {
+#ifdef HAS_SETPRIORITY
+ saved_nice = getpriority(PRIO_PROCESS, 0);
+ setpriority(PRIO_PROCESS, 0, -20);
+#endif
+#if defined(SYSV) || defined(SVR4) || defined(linux)
+ saved_nice = nice(0);
+ nice(-20 - saved_nice);
+#endif
+ } else {
+#ifdef HAS_SETPRIORITY
+ setpriority(PRIO_PROCESS, 0, saved_nice);
+#endif
+#if defined(SYSV) || defined(SVR4) || defined(linux)
+ nice(20 + saved_nice);
+#endif
+ }
+}
+
+const char *
+xf86GetVisualName(int visual)
+{
+ if (visual < 0 || visual > DirectColor)
+ return NULL;
+
+ return xf86VisualNames[visual];
+}
+
+
+int
+xf86GetVerbosity()
+{
+ return max(xf86Verbose, xf86LogVerbose);
+}
+
+Pix24Flags
+xf86GetPix24()
+{
+ return xf86Info.pixmap24;
+}
+
+
+int
+xf86GetDepth()
+{
+ return xf86Depth;
+}
+
+
+rgb
+xf86GetWeight()
+{
+ return xf86Weight;
+}
+
+
+Gamma
+xf86GetGamma()
+{
+ return xf86Gamma;
+}
+
+
+Bool
+xf86GetFlipPixels()
+{
+ return xf86FlipPixels;
+}
+
+
+const char *
+xf86GetServerName()
+{
+ return xf86ServerName;
+}
+
+
+Bool
+xf86ServerIsExiting()
+{
+ return (dispatchException & DE_TERMINATE) == DE_TERMINATE;
+}
+
+
+Bool
+xf86ServerIsResetting()
+{
+ return xf86Resetting;
+}
+
+
+Bool
+xf86ServerIsInitialising()
+{
+ return xf86Initialising;
+}
+
+
+Bool
+xf86ServerIsOnlyDetecting(void)
+{
+ return xf86DoProbe || xf86DoConfigure;
+}
+
+
+Bool
+xf86ServerIsOnlyProbing(void)
+{
+ return xf86ProbeOnly;
+}
+
+
+Bool
+xf86CaughtSignal()
+{
+ return xf86Info.caughtSignal;
+}
+
+
+Bool
+xf86GetVidModeAllowNonLocal()
+{
+ return xf86Info.vidModeAllowNonLocal;
+}
+
+
+Bool
+xf86GetVidModeEnabled()
+{
+ return xf86Info.vidModeEnabled;
+}
+
+Bool
+xf86GetModInDevAllowNonLocal()
+{
+ return xf86Info.miscModInDevAllowNonLocal;
+}
+
+
+Bool
+xf86GetModInDevEnabled()
+{
+ return xf86Info.miscModInDevEnabled;
+}
+
+
+Bool
+xf86GetAllowMouseOpenFail()
+{
+ return xf86Info.allowMouseOpenFail;
+}
+
+
+Bool
+xf86IsPc98()
+{
+#if defined(i386) || defined(__i386__)
+ return xf86Info.pc98;
+#else
+ return FALSE;
+#endif
+}
+
+void
+xf86DisableRandR()
+{
+ xf86Info.disableRandR = TRUE;
+ xf86Info.randRFrom = X_PROBED;
+}
+
+CARD32
+xf86GetVersion()
+{
+ return XF86_VERSION_CURRENT;
+}
+
+CARD32
+xf86GetModuleVersion(pointer module)
+{
+#ifdef XFree86LOADER
+ return (CARD32)LoaderGetModuleVersion(module);
+#else
+ return 0;
+#endif
+}
+
+pointer
+xf86LoadDrvSubModule(DriverPtr drv, const char *name)
+{
+#ifdef XFree86LOADER
+ pointer ret;
+ int errmaj = 0, errmin = 0;
+
+ ret = LoadSubModule(drv->module, name, NULL, NULL, NULL, NULL,
+ &errmaj, &errmin);
+ if (!ret)
+ LoaderErrorMsg(NULL, name, errmaj, errmin);
+ return ret;
+#else
+ return (pointer)1;
+#endif
+}
+
+pointer
+xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name)
+{
+#ifdef XFree86LOADER
+ pointer ret;
+ int errmaj = 0, errmin = 0;
+
+ ret = LoadSubModule(pScrn->module, name, NULL, NULL, NULL, NULL,
+ &errmaj, &errmin);
+ if (!ret)
+ LoaderErrorMsg(pScrn->name, name, errmaj, errmin);
+ return ret;
+#else
+ return (pointer)1;
+#endif
+}
+
+/*
+ * xf86LoadOneModule loads a single module.
+ */
+pointer
+xf86LoadOneModule(char *name, pointer opt)
+{
+#ifdef XFree86LOADER
+ int errmaj, errmin;
+#endif
+ char *Name;
+ pointer mod;
+
+ if (!name)
+ return NULL;
+
+#ifndef NORMALISE_MODULE_NAME
+ Name = xstrdup(name);
+#else
+ /* Normalise the module name */
+ Name = xf86NormalizeName(name);
+#endif
+
+ /* Skip empty names */
+ if (Name == NULL)
+ return NULL;
+ if (*Name == '\0') {
+ xfree(Name);
+ return NULL;
+ }
+
+#ifdef XFree86LOADER
+ mod = LoadModule(Name, NULL, NULL, NULL, opt, NULL, &errmaj, &errmin);
+ if (!mod)
+ LoaderErrorMsg(NULL, Name, errmaj, errmin);
+#else
+ mod = (pointer)1;
+#endif
+ xfree(Name);
+ return mod;
+}
+
+void
+xf86UnloadSubModule(pointer mod)
+{
+ /*
+ * This is disabled for now. The loader isn't smart enough yet to undo
+ * relocations.
+ */
+#if defined(XFree86LOADER) && 0
+ UnloadSubModule(mod);
+#endif
+}
+
+Bool
+xf86LoaderCheckSymbol(const char *name)
+{
+#ifdef XFree86LOADER
+ return LoaderSymbol(name) != NULL;
+#else
+ return TRUE;
+#endif
+}
+
+void
+xf86LoaderReqSymLists(const char **list0, ...)
+{
+#ifdef XFree86LOADER
+ va_list ap;
+
+ va_start(ap, list0);
+ LoaderVReqSymLists(list0, ap);
+ va_end(ap);
+#endif
+}
+
+void
+xf86LoaderReqSymbols(const char *sym0, ...)
+{
+#ifdef XFree86LOADER
+ va_list ap;
+
+ va_start(ap, sym0);
+ LoaderVReqSymbols(sym0, ap);
+ va_end(ap);
+#endif
+}
+
+void
+xf86LoaderRefSymLists(const char **list0, ...)
+{
+#ifdef XFree86LOADER
+ va_list ap;
+
+ va_start(ap, list0);
+ LoaderVRefSymLists(list0, ap);
+ va_end(ap);
+#endif
+}
+
+void
+xf86LoaderRefSymbols(const char *sym0, ...)
+{
+#ifdef XFree86LOADER
+ va_list ap;
+
+ va_start(ap, sym0);
+ LoaderVRefSymbols(sym0, ap);
+ va_end(ap);
+#endif
+}
+
+
+typedef enum {
+ OPTION_BACKING_STORE
+} BSOpts;
+
+static const OptionInfoRec BSOptions[] = {
+ { OPTION_BACKING_STORE, "BackingStore", OPTV_BOOLEAN, {0}, FALSE },
+ { -1, NULL, OPTV_NONE, {0}, FALSE }
+};
+
+void
+xf86SetBackingStore(ScreenPtr pScreen)
+{
+ Bool useBS = FALSE;
+ MessageType from = X_DEFAULT;
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ OptionInfoPtr options;
+
+ options = xnfalloc(sizeof(BSOptions));
+ (void)memcpy(options, BSOptions, sizeof(BSOptions));
+ xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
+
+ /* check for commandline option here */
+ if (xf86bsEnableFlag) {
+ from = X_CMDLINE;
+ useBS = TRUE;
+ } else if (xf86bsDisableFlag) {
+ from = X_CMDLINE;
+ useBS = FALSE;
+ } else {
+ if (xf86GetOptValBool(options, OPTION_BACKING_STORE, &useBS))
+ from = X_CONFIG;
+ }
+ xfree(options);
+ pScreen->backingStoreSupport = useBS ? Always : NotUseful;
+ if (serverGeneration == 1)
+ xf86DrvMsg(pScreen->myNum, from, "Backing store %s\n",
+ useBS ? "enabled" : "disabled");
+}
+
+
+typedef enum {
+ OPTION_SILKEN_MOUSE
+} SMOpts;
+
+static const OptionInfoRec SMOptions[] = {
+ { OPTION_SILKEN_MOUSE, "SilkenMouse", OPTV_BOOLEAN, {0}, FALSE },
+ { -1, NULL, OPTV_NONE, {0}, FALSE }
+};
+
+void
+xf86SetSilkenMouse (ScreenPtr pScreen)
+{
+ Bool useSM = TRUE;
+ MessageType from = X_DEFAULT;
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ OptionInfoPtr options;
+
+ options = xnfalloc(sizeof(SMOptions));
+ (void)memcpy(options, SMOptions, sizeof(SMOptions));
+ xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
+
+ /* check for commandline option here */
+ /* disable if screen shares resources */
+ if (((pScrn->racMemFlags & RAC_CURSOR) &&
+ !xf86NoSharedResources(pScrn->scrnIndex,MEM)) ||
+ ((pScrn->racIoFlags & RAC_CURSOR) &&
+ !xf86NoSharedResources(pScrn->scrnIndex,IO))) {
+ useSM = FALSE;
+ from = X_PROBED;
+ } else if (xf86silkenMouseDisableFlag) {
+ from = X_CMDLINE;
+ useSM = FALSE;
+ } else {
+ if (xf86GetOptValBool(options, OPTION_SILKEN_MOUSE, &useSM))
+ from = X_CONFIG;
+ }
+ xfree(options);
+ /*
+ * XXX quick hack to report correctly for OSs that can't do SilkenMouse
+ * yet. Should handle this differently so that alternate async methods
+ * like Xqueue work correctly with this too.
+ */
+ pScrn->silkenMouse = useSM && xf86SIGIOSupported();
+ if (serverGeneration == 1)
+ xf86DrvMsg(pScreen->myNum, from, "Silken mouse %s\n",
+ pScrn->silkenMouse ? "enabled" : "disabled");
+}
+
+/* Wrote this function for the PM2 Xv driver, preliminary. */
+
+pointer
+xf86FindXvOptions(int scrnIndex, int adaptor_index, char *port_name,
+ char **adaptor_name, pointer *adaptor_options)
+{
+ ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+ confXvAdaptorPtr adaptor;
+ int i;
+
+ if (adaptor_index >= pScrn->confScreen->numxvadaptors) {
+ if (adaptor_name) *adaptor_name = NULL;
+ if (adaptor_options) *adaptor_options = NULL;
+ return NULL;
+ }
+
+ adaptor = &pScrn->confScreen->xvadaptors[adaptor_index];
+ if (adaptor_name) *adaptor_name = adaptor->identifier;
+ if (adaptor_options) *adaptor_options = adaptor->options;
+
+ for (i = 0; i < adaptor->numports; i++)
+ if (!xf86NameCmp(adaptor->ports[i].identifier, port_name))
+ return adaptor->ports[i].options;
+
+ return NULL;
+}
+
+/* Rather than duplicate loader's get OS function, just include it directly */
+#define LoaderGetOS xf86GetOS
+#include "loader/os.c"
+
+/* new RAC */
+/*
+ * xf86ConfigIsa/PciEntity() -- These helper functions assign an
+ * active entity to a screen, registers its fixed resources, assign
+ * special enter/leave functions and their private scratch area to
+ * this entity, take the dog for a walk...
+ */
+ScrnInfoPtr
+xf86ConfigIsaEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex,
+ IsaChipsets *i_chip, resList res, EntityProc init,
+ EntityProc enter, EntityProc leave, pointer private)
+{
+ IsaChipsets *i_id;
+ EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
+ if (!pEnt) return pScrn;
+
+ if (!(pEnt->location.type == BUS_ISA)) {
+ xfree(pEnt);
+ return pScrn;
+ }
+
+ if (!pEnt->active) {
+ xf86ConfigIsaEntityInactive(pEnt, i_chip, res, init, enter,
+ leave, private);
+ return pScrn;
+ }
+
+ if (!pScrn)
+ pScrn = xf86AllocateScreen(pEnt->driver,scrnFlag);
+ xf86AddEntityToScreen(pScrn,entityIndex);
+
+ if (i_chip) {
+ for (i_id = i_chip; i_id->numChipset != -1; i_id++) {
+ if (pEnt->chipset == i_id->numChipset) break;
+ }
+ xf86ClaimFixedResources(i_id->resList,entityIndex);
+ }
+ xfree(pEnt);
+ xf86ClaimFixedResources(res,entityIndex);
+ xf86SetEntityFuncs(entityIndex,init,enter,leave,private);
+
+ return pScrn;
+}
+
+ScrnInfoPtr
+xf86ConfigPciEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex,
+ PciChipsets *p_chip, resList res, EntityProc init,
+ EntityProc enter, EntityProc leave, pointer private)
+{
+ PciChipsets *p_id;
+ EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
+ if (!pEnt) return pScrn;
+
+ if (!(pEnt->location.type == BUS_PCI)
+ || !xf86GetPciInfoForEntity(entityIndex)) {
+ xfree(pEnt);
+ return pScrn;
+ }
+ if (!pEnt->active) {
+ xf86ConfigPciEntityInactive(pEnt, p_chip, res, init, enter,
+ leave, private);
+ return pScrn;
+ }
+
+ if (!pScrn)
+ pScrn = xf86AllocateScreen(pEnt->driver,scrnFlag);
+ if (xf86IsEntitySharable(entityIndex)) {
+ xf86SetEntityShared(entityIndex);
+ }
+ xf86AddEntityToScreen(pScrn,entityIndex);
+ if (xf86IsEntityShared(entityIndex)) {
+ return pScrn;
+ }
+ if (p_chip) {
+ for (p_id = p_chip; p_id->numChipset != -1; p_id++) {
+ if (pEnt->chipset == p_id->numChipset) break;
+ }
+ xf86ClaimFixedResources(p_id->resList,entityIndex);
+ }
+ xfree(pEnt);
+
+ xf86ClaimFixedResources(res,entityIndex);
+ xf86SetEntityFuncs(entityIndex,init,enter,leave,private);
+
+ return pScrn;
+}
+
+ScrnInfoPtr
+xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex,
+ EntityProc init, EntityProc enter, EntityProc leave,
+ pointer private)
+{
+ EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
+ if (!pEnt) return pScrn;
+
+ if (!(pEnt->location.type == BUS_NONE)) {
+ xfree(pEnt);
+ return pScrn;
+ }
+
+ if (!pEnt->active) {
+ xf86ConfigFbEntityInactive(pEnt, init, enter, leave, private);
+ return pScrn;
+ }
+
+ if (!pScrn)
+ pScrn = xf86AllocateScreen(pEnt->driver,scrnFlag);
+ xf86AddEntityToScreen(pScrn,entityIndex);
+
+ xf86SetEntityFuncs(entityIndex,init,enter,leave,private);
+
+ return pScrn;
+}
+
+/*
+ *
+ * OBSOLETE ! xf86ConfigActiveIsaEntity() and xf86ConfigActivePciEntity()
+ * are obsolete functions. They the are likely to be removed
+ * Don't use!
+ */
+Bool
+xf86ConfigActiveIsaEntity(ScrnInfoPtr pScrn, int entityIndex,
+ IsaChipsets *i_chip, resList res, EntityProc init,
+ EntityProc enter, EntityProc leave, pointer private)
+{
+ IsaChipsets *i_id;
+ EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
+ if (!pEnt) return FALSE;
+
+ if (!pEnt->active || !(pEnt->location.type == BUS_ISA)) {
+ xfree(pEnt);
+ return FALSE;
+ }
+
+ xf86AddEntityToScreen(pScrn,entityIndex);
+
+ if (i_chip) {
+ for (i_id = i_chip; i_id->numChipset != -1; i_id++) {
+ if (pEnt->chipset == i_id->numChipset) break;
+ }
+ xf86ClaimFixedResources(i_id->resList,entityIndex);
+ }
+ xfree(pEnt);
+ xf86ClaimFixedResources(res,entityIndex);
+ if (!xf86SetEntityFuncs(entityIndex,init,enter,leave,private))
+ return FALSE;
+
+ return TRUE;
+}
+
+Bool
+xf86ConfigActivePciEntity(ScrnInfoPtr pScrn, int entityIndex,
+ PciChipsets *p_chip, resList res, EntityProc init,
+ EntityProc enter, EntityProc leave, pointer private)
+{
+ PciChipsets *p_id;
+ EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
+ if (!pEnt) return FALSE;
+
+ if (!pEnt->active || !(pEnt->location.type == BUS_PCI)) {
+ xfree(pEnt);
+ return FALSE;
+ }
+ xf86AddEntityToScreen(pScrn,entityIndex);
+
+ if (p_chip) {
+ for (p_id = p_chip; p_id->numChipset != -1; p_id++) {
+ if (pEnt->chipset == p_id->numChipset) break;
+ }
+ xf86ClaimFixedResources(p_id->resList,entityIndex);
+ }
+ xfree(pEnt);
+
+ xf86ClaimFixedResources(res,entityIndex);
+ if (!xf86SetEntityFuncs(entityIndex,init,enter,leave,private))
+ return FALSE;
+
+ return TRUE;
+}
+
+/*
+ * xf86ConfigPci/IsaEntityInactive() -- These functions can be used
+ * to configure an inactive entity as well as to reconfigure an
+ * previously active entity inactive. If the entity has been
+ * assigned to a screen before it will be removed. If p_pci(p_isa) is
+ * non-NULL all static resources listed there will be registered.
+ */
+void
+xf86ConfigPciEntityInactive(EntityInfoPtr pEnt, PciChipsets *p_chip,
+ resList res, EntityProc init, EntityProc enter,
+ EntityProc leave, pointer private)
+{
+ PciChipsets *p_id;
+ ScrnInfoPtr pScrn;
+
+ if ((pScrn = xf86FindScreenForEntity(pEnt->index)))
+ xf86RemoveEntityFromScreen(pScrn,pEnt->index);
+ else if (p_chip) {
+ for (p_id = p_chip; p_id->numChipset != -1; p_id++) {
+ if (pEnt->chipset == p_id->numChipset) break;
+ }
+ xf86ClaimFixedResources(p_id->resList,pEnt->index);
+ }
+ xf86ClaimFixedResources(res,pEnt->index);
+ /* shared resources are only needed when entity is active: remove */
+ xf86DeallocateResourcesForEntity(pEnt->index, ResShared);
+ xf86SetEntityFuncs(pEnt->index,init,enter,leave,private);
+}
+
+void
+xf86ConfigIsaEntityInactive(EntityInfoPtr pEnt, IsaChipsets *i_chip,
+ resList res, EntityProc init, EntityProc enter,
+ EntityProc leave, pointer private)
+{
+ IsaChipsets *i_id;
+ ScrnInfoPtr pScrn;
+
+ if ((pScrn = xf86FindScreenForEntity(pEnt->index)))
+ xf86RemoveEntityFromScreen(pScrn,pEnt->index);
+ else if (i_chip) {
+ for (i_id = i_chip; i_id->numChipset != -1; i_id++) {
+ if (pEnt->chipset == i_id->numChipset) break;
+ }
+ xf86ClaimFixedResources(i_id->resList,pEnt->index);
+ }
+ xf86ClaimFixedResources(res,pEnt->index);
+ /* shared resources are only needed when entity is active: remove */
+ xf86DeallocateResourcesForEntity(pEnt->index, ResShared);
+ xf86SetEntityFuncs(pEnt->index,init,enter,leave,private);
+}
+
+void
+xf86ConfigFbEntityInactive(EntityInfoPtr pEnt, EntityProc init,
+ EntityProc enter, EntityProc leave, pointer private)
+{
+ ScrnInfoPtr pScrn;
+
+ if ((pScrn = xf86FindScreenForEntity(pEnt->index)))
+ xf86RemoveEntityFromScreen(pScrn,pEnt->index);
+ xf86SetEntityFuncs(pEnt->index,init,enter,leave,private);
+}
+
+Bool
+xf86IsScreenPrimary(int scrnIndex)
+{
+ ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+ int i;
+
+ for (i=0 ; i < pScrn->numEntities; i++) {
+ if (xf86IsEntityPrimary(i))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+int
+xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type,
+ int format, unsigned long len, pointer value )
+{
+ RootWinPropPtr pNewProp = NULL, pRegProp;
+ int i;
+ Bool existing = FALSE;
+
+#ifdef DEBUG
+ ErrorF("xf86RegisterRootWindowProperty(%d, %ld, %ld, %d, %ld, %p)\n",
+ ScrnIndex, property, type, format, len, value);
+#endif
+
+ if (ScrnIndex<0 || ScrnIndex>=xf86NumScreens) {
+ return(BadMatch);
+ }
+
+ if (xf86RegisteredPropertiesTable &&
+ xf86RegisteredPropertiesTable[ScrnIndex]) {
+ for (pNewProp = xf86RegisteredPropertiesTable[ScrnIndex];
+ pNewProp; pNewProp = pNewProp->next) {
+ if (strcmp(pNewProp->name, NameForAtom(property)) == 0)
+ break;
+ }
+ }
+
+ if (!pNewProp) {
+ if ((pNewProp = (RootWinPropPtr)xalloc(sizeof(RootWinProp))) == NULL) {
+ return(BadAlloc);
+ }
+ /*
+ * We will put this property at the end of the list so that
+ * the changes are made in the order they were requested.
+ */
+ pNewProp->next = NULL;
+ } else {
+ if (pNewProp->name)
+ xfree(pNewProp->name);
+ existing = TRUE;
+ }
+
+ pNewProp->name = xnfstrdup(NameForAtom(property));
+ pNewProp->type = type;
+ pNewProp->format = format;
+ pNewProp->size = len;
+ pNewProp->data = value;
+
+#ifdef DEBUG
+ ErrorF("new property filled\n");
+#endif
+
+ if (NULL==xf86RegisteredPropertiesTable) {
+#ifdef DEBUG
+ ErrorF("creating xf86RegisteredPropertiesTable[] size %d\n",
+ xf86NumScreens);
+#endif
+ if ( NULL==(xf86RegisteredPropertiesTable=(RootWinPropPtr*)xnfcalloc(sizeof(RootWinProp),xf86NumScreens) )) {
+ return(BadAlloc);
+ }
+ for (i=0; i<xf86NumScreens; i++) {
+ xf86RegisteredPropertiesTable[i] = NULL;
+ }
+ }
+
+#ifdef DEBUG
+ ErrorF("xf86RegisteredPropertiesTable %p\n",
+ (void *)xf86RegisteredPropertiesTable);
+ ErrorF("xf86RegisteredPropertiesTable[%d] %p\n",
+ ScrnIndex, (void *)xf86RegisteredPropertiesTable[ScrnIndex]);
+#endif
+
+ if (!existing) {
+ if ( xf86RegisteredPropertiesTable[ScrnIndex] == NULL) {
+ xf86RegisteredPropertiesTable[ScrnIndex] = pNewProp;
+ } else {
+ pRegProp = xf86RegisteredPropertiesTable[ScrnIndex];
+ while (pRegProp->next != NULL) {
+#ifdef DEBUG
+ ErrorF("- next %p\n", (void *)pRegProp);
+#endif
+ pRegProp = pRegProp->next;
+ }
+ pRegProp->next = pNewProp;
+ }
+ }
+#ifdef DEBUG
+ ErrorF("xf86RegisterRootWindowProperty succeeded\n");
+#endif
+ return(Success);
+}
+
+Bool
+xf86IsUnblank(int mode)
+{
+ switch(mode) {
+ case SCREEN_SAVER_OFF:
+ case SCREEN_SAVER_FORCER:
+ return TRUE;
+ case SCREEN_SAVER_ON:
+ case SCREEN_SAVER_CYCLE:
+ return FALSE;
+ default:
+ xf86MsgVerb(X_WARNING, 0, "Unexpected save screen mode: %d\n", mode);
+ return TRUE;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86InPriv.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86InPriv.h
new file mode 100644
index 000000000..4a02606d3
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86InPriv.h
@@ -0,0 +1,48 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86InPriv.h,v 1.5 2003/08/24 17:36:52 dawes Exp $ */
+
+/*
+ * Copyright (c) 1999 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 _xf86InPriv_h
+#define _xf86InPriv_h
+
+/* xf86Globals.c */
+#ifdef XFree86LOADER
+extern InputDriverPtr *xf86InputDriverList;
+#else
+extern InputDriverPtr xf86InputDriverList[];
+#endif
+extern int xf86NumInputDrivers;
+
+/* xf86Xinput.c */
+void xf86ActivateDevice(InputInfoPtr pInfo);
+
+#endif /* _xf86InPriv_h */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Init.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Init.c
new file mode 100644
index 000000000..e504c300a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Init.c
@@ -0,0 +1,2035 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Init.c,v 3.212 2004/01/27 01:31:45 dawes Exp $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86Init.c,v 1.29 2005/12/14 20:12:00 ajax Exp $ */
+
+/*
+ * Loosely based on code bearing the following copyright:
+ *
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ */
+/*
+ * Copyright (c) 1992-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
+
+#include <stdlib.h>
+
+#undef HAS_UTSNAME
+#if !defined(WIN32) && !defined(__UNIXOS2__)
+#define HAS_UTSNAME 1
+#include <sys/utsname.h>
+#endif
+
+#define NEED_EVENTS
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include <X11/Xproto.h>
+#include <X11/Xatom.h>
+#include "input.h"
+#include "servermd.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "site.h"
+#include "mi.h"
+
+#include "compiler.h"
+
+#ifdef XFree86LOADER
+#include "loaderProcs.h"
+#endif
+#ifdef XFreeXDGA
+#include "dgaproc.h"
+#endif
+
+#define XF86_OS_PRIVS
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Config.h"
+#include "xf86_OSlib.h"
+#include "xorgVersion.h"
+#include "xf86Date.h"
+#include "xf86Build.h"
+#include "mipointer.h"
+#ifdef XINPUT
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#else
+#include "inputstr.h"
+#endif
+#include "xf86DDC.h"
+#include "xf86Xinput.h"
+#include "xf86InPriv.h"
+#ifdef RENDER
+#include "picturestr.h"
+#endif
+
+#include "globals.h"
+
+#ifdef XTESTEXT1
+#include "atKeynames.h"
+extern int xtest_command_key;
+#endif /* XTESTEXT1 */
+
+#ifdef DPMSExtension
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+#include "dpmsproc.h"
+#endif
+
+
+/* forward declarations */
+
+static void xf86PrintBanner(void);
+static void xf86PrintMarkers(void);
+static void xf86RunVtInit(void);
+
+#ifdef __UNIXOS2__
+extern void os2ServerVideoAccess();
+#endif
+
+#ifdef XF86PM
+void (*xf86OSPMClose)(void) = NULL;
+#endif
+
+#ifdef XFree86LOADER
+static char *baseModules[] = {
+ "bitmap",
+ "pcidata",
+ NULL
+};
+#endif
+
+/* Common pixmap formats */
+
+static PixmapFormatRec formats[MAXFORMATS] = {
+ { 1, 1, BITMAP_SCANLINE_PAD },
+ { 4, 8, BITMAP_SCANLINE_PAD },
+ { 8, 8, BITMAP_SCANLINE_PAD },
+ { 15, 16, BITMAP_SCANLINE_PAD },
+ { 16, 16, BITMAP_SCANLINE_PAD },
+ { 24, 32, BITMAP_SCANLINE_PAD },
+#ifdef RENDER
+ { 32, 32, BITMAP_SCANLINE_PAD },
+#endif
+};
+#ifdef RENDER
+static int numFormats = 7;
+#else
+static int numFormats = 6;
+#endif
+static Bool formatsDone = FALSE;
+
+InputDriverRec XF86KEYBOARD = {
+ 1,
+ "keyboard",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0
+};
+
+static Bool
+xf86CreateRootWindow(WindowPtr pWin)
+{
+ int ret = TRUE;
+ int err = Success;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ RootWinPropPtr pProp;
+ CreateWindowProcPtr CreateWindow =
+ (CreateWindowProcPtr)(pScreen->devPrivates[xf86CreateRootWindowIndex].ptr);
+
+#ifdef DEBUG
+ ErrorF("xf86CreateRootWindow(%p)\n", pWin);
+#endif
+
+ if ( pScreen->CreateWindow != xf86CreateRootWindow ) {
+ /* Can't find hook we are hung on */
+ xf86DrvMsg(pScreen->myNum, X_WARNING /* X_ERROR */,
+ "xf86CreateRootWindow %p called when not in pScreen->CreateWindow %p n",
+ (void *)xf86CreateRootWindow,
+ (void *)pScreen->CreateWindow );
+ }
+
+ /* Unhook this function ... */
+ pScreen->CreateWindow = CreateWindow;
+ pScreen->devPrivates[xf86CreateRootWindowIndex].ptr = NULL;
+
+ /* ... and call the previous CreateWindow fuction, if any */
+ if (NULL!=pScreen->CreateWindow) {
+ ret = (*pScreen->CreateWindow)(pWin);
+ }
+
+ /* Now do our stuff */
+ if (xf86RegisteredPropertiesTable != NULL) {
+ if (pWin->parent == NULL && xf86RegisteredPropertiesTable != NULL) {
+ for (pProp = xf86RegisteredPropertiesTable[pScreen->myNum];
+ pProp != NULL && err==Success;
+ pProp = pProp->next )
+ {
+ Atom prop;
+
+ prop = MakeAtom(pProp->name, strlen(pProp->name), TRUE);
+ err = ChangeWindowProperty(pWin,
+ prop, pProp->type,
+ pProp->format, PropModeReplace,
+ pProp->size, pProp->data,
+ FALSE
+ );
+ }
+
+ /* Look at err */
+ ret &= (err==Success);
+
+ } else {
+ xf86Msg(X_ERROR, "xf86CreateRootWindow unexpectedly called with "
+ "non-root window %p (parent %p)\n",
+ (void *)pWin, (void *)pWin->parent);
+ ret = FALSE;
+ }
+ }
+
+#ifdef DEBUG
+ ErrorF("xf86CreateRootWindow() returns %d\n", ret);
+#endif
+ return (ret);
+}
+
+
+/*
+ * InitOutput --
+ * Initialize screenInfo for all actually accessible framebuffers.
+ * That includes vt-manager setup, querying all possible devices and
+ * collecting the pixmap formats.
+ */
+
+static void
+PostConfigInit(void)
+{
+ /*
+ * Install signal handler for unexpected signals
+ */
+ xf86Info.caughtSignal=FALSE;
+ if (!xf86Info.notrapSignals) {
+ signal(SIGSEGV,xf86SigHandler);
+ signal(SIGILL,xf86SigHandler);
+#ifdef SIGEMT
+ signal(SIGEMT,xf86SigHandler);
+#endif
+ signal(SIGFPE,xf86SigHandler);
+#ifdef SIGBUS
+ signal(SIGBUS,xf86SigHandler);
+#endif
+#ifdef SIGSYS
+ signal(SIGSYS,xf86SigHandler);
+#endif
+#ifdef SIGXCPU
+ signal(SIGXCPU,xf86SigHandler);
+#endif
+#ifdef SIGXFSZ
+ signal(SIGXFSZ,xf86SigHandler);
+#endif
+#ifdef MEMDEBUG
+ signal(SIGUSR2,xf86SigMemDebug);
+#endif
+ }
+
+#ifdef XF86PM
+ xf86OSPMClose = xf86OSPMOpen();
+#endif
+
+ /* Run an external VT Init program if specified in the config file */
+ xf86RunVtInit();
+
+ /* Do this after XF86Config is read (it's normally in OsInit()) */
+ OsInitColors();
+}
+
+void
+InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
+{
+ int i, j, k, scr_index;
+ static unsigned long generation = 0;
+#ifdef XFree86LOADER
+ char **modulelist;
+ pointer *optionlist;
+#endif
+ screenLayoutPtr layout;
+ Pix24Flags screenpix24, pix24;
+ MessageType pix24From = X_DEFAULT;
+ Bool pix24Fail = FALSE;
+ Bool autoconfig = FALSE;
+
+#ifdef __UNIXOS2__
+ os2ServerVideoAccess(); /* See if we have access to the screen before doing anything */
+#endif
+
+ xf86Initialising = TRUE;
+
+ /* Do this early? */
+ if (generation != serverGeneration) {
+ xf86ScreenIndex = AllocateScreenPrivateIndex();
+ xf86CreateRootWindowIndex = AllocateScreenPrivateIndex();
+ xf86PixmapIndex = AllocatePixmapPrivateIndex();
+ generation = serverGeneration;
+ }
+
+ if (serverGeneration == 1) {
+
+ pScreenInfo->numScreens = 0;
+
+ if ((xf86ServerName = strrchr(argv[0], '/')) != 0)
+ xf86ServerName++;
+ else
+ xf86ServerName = argv[0];
+
+ xf86PrintBanner();
+ xf86PrintMarkers();
+ if (xf86LogFile) {
+ time_t t;
+ const char *ct;
+ t = time(NULL);
+ ct = ctime(&t);
+ xf86MsgVerb(xf86LogFileFrom, 0, "Log file: \"%s\", Time: %s",
+ xf86LogFile, ct);
+ }
+
+ /* Read and parse the config file */
+ if (!xf86DoProbe && !xf86DoConfigure) {
+ switch (xf86HandleConfigFile(FALSE)) {
+ case CONFIG_OK:
+ break;
+ case CONFIG_PARSE_ERROR:
+ xf86Msg(X_ERROR, "Error parsing the config file\n");
+ return;
+ case CONFIG_NOFILE:
+ autoconfig = TRUE;
+ break;
+ }
+ }
+
+ if (!autoconfig)
+ PostConfigInit();
+
+#ifdef XFree86LOADER
+ /* Initialise the loader */
+ LoaderInit();
+
+ /* Tell the loader the default module search path */
+ LoaderSetPath(xf86ModulePath);
+
+#ifdef TESTING
+ {
+ char **list, **l;
+ const char *subdirs[] = {
+ "drivers",
+ NULL
+ };
+ const char *patlist[] = {
+ "(.*)_drv\\.so",
+ "(.*)_drv\\.o",
+ NULL
+ };
+ ErrorF("Getting module listing...\n");
+ list = LoaderListDirs(NULL, NULL);
+ if (list)
+ for (l = list; *l; l++)
+ ErrorF("module: %s\n", *l);
+ LoaderFreeDirList(list);
+ ErrorF("Getting video driver listing...\n");
+ list = LoaderListDirs(subdirs, NULL);
+ if (list)
+ for (l = list; *l; l++)
+ ErrorF("video driver: %s\n", *l);
+ LoaderFreeDirList(list);
+ ErrorF("Getting driver listing...\n");
+ list = LoaderListDirs(NULL, patlist);
+ if (list)
+ for (l = list; *l; l++)
+ ErrorF("video driver: %s\n", *l);
+ LoaderFreeDirList(list);
+ }
+#endif
+
+ /* Force load mandatory base modules */
+ if (!xf86LoadModules(baseModules, NULL))
+ FatalError("Unable to load required base modules, Exiting...\n");
+
+#endif
+
+ xf86OpenConsole();
+
+ /* Do a general bus probe. This will be a PCI probe for x86 platforms */
+ xf86BusProbe();
+
+ if (xf86DoProbe)
+ DoProbe();
+
+ if (xf86DoConfigure)
+ DoConfigure();
+
+ if (autoconfig) {
+ if (!xf86AutoConfig()) {
+ xf86Msg(X_ERROR, "Auto configuration failed\n");
+ return;
+ }
+ PostConfigInit();
+ }
+
+ /* Initialise the resource broker */
+ xf86ResourceBrokerInit();
+
+#ifdef XFree86LOADER
+ /* Load all modules specified explicitly in the config file */
+ if ((modulelist = xf86ModulelistFromConfig(&optionlist))) {
+ xf86LoadModules(modulelist, optionlist);
+ xfree(modulelist);
+ xfree(optionlist);
+ }
+
+ /* Load all driver modules specified in the config file */
+ if ((modulelist = xf86DriverlistFromConfig())) {
+ xf86LoadModules(modulelist, NULL);
+ xfree(modulelist);
+ }
+
+#ifdef USE_DEPRECATED_KEYBOARD_DRIVER
+ /* Setup the builtin input drivers */
+ xf86AddInputDriver(&XF86KEYBOARD, NULL, 0);
+#endif
+ /* Load all input driver modules specified in the config file. */
+ if ((modulelist = xf86InputDriverlistFromConfig())) {
+ xf86LoadModules(modulelist, NULL);
+ xfree(modulelist);
+ }
+
+ /*
+ * It is expected that xf86AddDriver()/xf86AddInputDriver will be
+ * called for each driver as it is loaded. Those functions save the
+ * module pointers for drivers.
+ * XXX Nothing keeps track of them for other modules.
+ */
+ /* XXX What do we do if not all of these could be loaded? */
+#endif
+
+ /*
+ * At this point, xf86DriverList[] is all filled in with entries for
+ * each of the drivers to try and xf86NumDrivers has the number of
+ * drivers. If there are none, return now.
+ */
+
+ if (xf86NumDrivers == 0) {
+ xf86Msg(X_ERROR, "No drivers available.\n");
+ return;
+ }
+
+ /*
+ * Call each of the Identify functions and call the driverFunc to check
+ * if HW access is required. The Identify functions print out some
+ * identifying information, and anything else that might be
+ * needed at this early stage.
+ */
+
+ for (i = 0; i < xf86NumDrivers; i++) {
+ xorgHWFlags flags;
+ /* The Identify function is mandatory, but if it isn't there continue */
+ if (xf86DriverList[i]->Identify != NULL)
+ xf86DriverList[i]->Identify(0);
+ else {
+ xf86Msg(X_WARNING, "Driver `%s' has no Identify function\n",
+ xf86DriverList[i]->driverName ? xf86DriverList[i]->driverName
+ : "noname");
+ }
+ if (!xorgHWAccess
+ && (!xf86DriverList[i]->driverFunc
+ || !xf86DriverList[i]->driverFunc(NULL,
+ GET_REQUIRED_HW_INTERFACES,
+ &flags)
+ || NEED_IO_ENABLED(flags)))
+ xorgHWAccess = TRUE;
+ }
+
+ /* Enable full I/O access */
+ if (xorgHWAccess) {
+ if(!xf86EnableIO())
+ /* oops, we have failed */
+ xorgHWAccess = FALSE;
+ }
+
+ /*
+ * Locate bus slot that had register IO enabled at server startup
+ */
+
+ xf86AccessInit();
+ xf86FindPrimaryDevice();
+
+ /*
+ * Now call each of the Probe functions. Each successful probe will
+ * result in an extra entry added to the xf86Screens[] list for each
+ * instance of the hardware found.
+ */
+
+ for (i = 0; i < xf86NumDrivers; i++) {
+ xorgHWFlags flags;
+ if (!xorgHWAccess) {
+ if (!xf86DriverList[i]->driverFunc
+ || !xf86DriverList[i]->driverFunc(NULL,
+ GET_REQUIRED_HW_INTERFACES,
+ &flags)
+ || NEED_IO_ENABLED(flags))
+ continue;
+ }
+
+ if (xf86DriverList[i]->Probe != NULL)
+ xf86DriverList[i]->Probe(xf86DriverList[i], PROBE_DEFAULT);
+ else {
+ xf86MsgVerb(X_WARNING, 0,
+ "Driver `%s' has no Probe function (ignoring)\n",
+ xf86DriverList[i]->driverName
+ ? xf86DriverList[i]->driverName : "noname");
+ }
+ xf86SetPciVideo(NULL,NONE);
+ }
+
+ /*
+ * If nothing was detected, return now.
+ */
+
+ if (xf86NumScreens == 0) {
+ xf86Msg(X_ERROR, "No devices detected.\n");
+ return;
+ }
+
+ /*
+ * Match up the screens found by the probes against those specified
+ * in the config file. Remove the ones that won't be used. Sort
+ * them in the order specified.
+ */
+
+ /*
+ * What is the best way to do this?
+ *
+ * For now, go through the screens allocated by the probes, and
+ * look for screen config entry which refers to the same device
+ * section as picked out by the probe.
+ *
+ */
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ for (layout = xf86ConfigLayout.screens; layout->screen != NULL;
+ layout++) {
+ Bool found = FALSE;
+ for (j = 0; j < xf86Screens[i]->numEntities; j++) {
+
+ GDevPtr dev =
+ xf86GetDevFromEntity(xf86Screens[i]->entityList[j],
+ xf86Screens[i]->entityInstanceList[j]);
+
+ if (dev == layout->screen->device) {
+ /* A match has been found */
+ xf86Screens[i]->confScreen = layout->screen;
+ found = TRUE;
+ break;
+ }
+ }
+ if (found) break;
+ }
+ if (layout->screen == NULL) {
+ /* No match found */
+ xf86Msg(X_ERROR,
+ "Screen %d deleted because of no matching config section.\n", i);
+ xf86DeleteScreen(i--, 0);
+ }
+ }
+
+ /*
+ * If no screens left, return now.
+ */
+
+ if (xf86NumScreens == 0) {
+ xf86Msg(X_ERROR,
+ "Device(s) detected, but none match those in the config file.\n");
+ return;
+ }
+
+ xf86PostProbe();
+ xf86EntityInit();
+
+ /*
+ * Sort the drivers to match the requested ording. Using a slow
+ * bubble sort.
+ */
+ for (j = 0; j < xf86NumScreens - 1; j++) {
+ for (i = 0; i < xf86NumScreens - j - 1; i++) {
+ if (xf86Screens[i + 1]->confScreen->screennum <
+ xf86Screens[i]->confScreen->screennum) {
+ ScrnInfoPtr tmpScrn = xf86Screens[i + 1];
+ xf86Screens[i + 1] = xf86Screens[i];
+ xf86Screens[i] = tmpScrn;
+ }
+ }
+ }
+ /* Fix up the indexes */
+ for (i = 0; i < xf86NumScreens; i++) {
+ xf86Screens[i]->scrnIndex = i;
+ }
+
+ /*
+ * Call the driver's PreInit()'s to complete initialisation for the first
+ * generation.
+ */
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ xf86EnableAccess(xf86Screens[i]);
+ if (xf86Screens[i]->PreInit &&
+ xf86Screens[i]->PreInit(xf86Screens[i], 0))
+ xf86Screens[i]->configured = TRUE;
+ }
+ for (i = 0; i < xf86NumScreens; i++)
+ if (!xf86Screens[i]->configured)
+ xf86DeleteScreen(i--, 0);
+
+ /*
+ * If no screens left, return now.
+ */
+
+ if (xf86NumScreens == 0) {
+ xf86Msg(X_ERROR,
+ "Screen(s) found, but none have a usable configuration.\n");
+ return;
+ }
+
+ /* This could be moved into a separate function */
+
+ /*
+ * Check that all screens have initialised the mandatory function
+ * entry points. Delete those which have not.
+ */
+
+#define WARN_SCREEN(func) \
+ xf86Msg(X_ERROR, "Driver `%s' has no %s function, deleting.\n", \
+ xf86Screens[i]->name, (warned++, func))
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ int warned = 0;
+ if (xf86Screens[i]->name == NULL) {
+ xf86Screens[i]->name = xnfalloc(strlen("screen") + 1 + 1);
+ if (i < 10)
+ sprintf(xf86Screens[i]->name, "screen%c", i + '0');
+ else
+ sprintf(xf86Screens[i]->name, "screen%c", i - 10 + 'A');
+ xf86MsgVerb(X_WARNING, 0,
+ "Screen driver %d has no name set, using `%s'.\n",
+ i, xf86Screens[i]->name);
+ }
+ if (xf86Screens[i]->ScreenInit == NULL)
+ WARN_SCREEN("ScreenInit");
+ if (xf86Screens[i]->EnterVT == NULL)
+ WARN_SCREEN("EnterVT");
+ if (xf86Screens[i]->LeaveVT == NULL)
+ WARN_SCREEN("LeaveVT");
+ if (warned)
+ xf86DeleteScreen(i--, 0);
+ }
+
+ /*
+ * If no screens left, return now.
+ */
+
+ if (xf86NumScreens == 0) {
+ xf86Msg(X_ERROR, "Screen(s) found, but drivers were unusable.\n");
+ return;
+ }
+
+ /* XXX Should this be before or after loading dependent modules? */
+ if (xf86ProbeOnly)
+ {
+ OsCleanup(TRUE);
+ AbortDDX();
+ fflush(stderr);
+ exit(0);
+ }
+
+#ifdef XFree86LOADER
+ /* Remove (unload) drivers that are not required */
+ for (i = 0; i < xf86NumDrivers; i++)
+ if (xf86DriverList[i] && xf86DriverList[i]->refCount <= 0)
+ xf86DeleteDriver(i);
+#endif
+
+ /*
+ * At this stage we know how many screens there are.
+ */
+
+ for (i = 0; i < xf86NumScreens; i++)
+ xf86InitViewport(xf86Screens[i]);
+
+ /*
+ * Collect all pixmap formats and check for conflicts at the display
+ * level. Should we die here? Or just delete the offending screens?
+ * Also, should this be done for -probeonly?
+ */
+ screenpix24 = Pix24DontCare;
+ for (i = 0; i < xf86NumScreens; i++) {
+ if (xf86Screens[i]->imageByteOrder !=
+ xf86Screens[0]->imageByteOrder)
+ FatalError("Inconsistent display bitmapBitOrder. Exiting\n");
+ if (xf86Screens[i]->bitmapScanlinePad !=
+ xf86Screens[0]->bitmapScanlinePad)
+ FatalError("Inconsistent display bitmapScanlinePad. Exiting\n");
+ if (xf86Screens[i]->bitmapScanlineUnit !=
+ xf86Screens[0]->bitmapScanlineUnit)
+ FatalError("Inconsistent display bitmapScanlineUnit. Exiting\n");
+ if (xf86Screens[i]->bitmapBitOrder !=
+ xf86Screens[0]->bitmapBitOrder)
+ FatalError("Inconsistent display bitmapBitOrder. Exiting\n");
+
+ /* Determine the depth 24 pixmap format the screens would like */
+ if (xf86Screens[i]->pixmap24 != Pix24DontCare) {
+ if (screenpix24 == Pix24DontCare)
+ screenpix24 = xf86Screens[i]->pixmap24;
+ else if (screenpix24 != xf86Screens[i]->pixmap24)
+ FatalError("Inconsistent depth 24 pixmap format. Exiting\n");
+ }
+ }
+ /* check if screenpix24 is consistent with the config/cmdline */
+ if (xf86Info.pixmap24 != Pix24DontCare) {
+ pix24 = xf86Info.pixmap24;
+ pix24From = xf86Info.pix24From;
+ if (screenpix24 != Pix24DontCare && screenpix24 != xf86Info.pixmap24)
+ pix24Fail = TRUE;
+ } else if (screenpix24 != Pix24DontCare) {
+ pix24 = screenpix24;
+ pix24From = X_PROBED;
+ } else
+ pix24 = Pix24Use32;
+
+ if (pix24Fail)
+ FatalError("Screen(s) can't use the required depth 24 pixmap format"
+ " (%d). Exiting\n", PIX24TOBPP(pix24));
+
+ /* Initialise the depth 24 format */
+ for (j = 0; j < numFormats && formats[j].depth != 24; j++)
+ ;
+ formats[j].bitsPerPixel = PIX24TOBPP(pix24);
+
+ /* Collect additional formats */
+ for (i = 0; i < xf86NumScreens; i++) {
+ for (j = 0; j < xf86Screens[i]->numFormats; j++) {
+ for (k = 0; ; k++) {
+ if (k >= numFormats) {
+ if (k >= MAXFORMATS)
+ FatalError("Too many pixmap formats! Exiting\n");
+ formats[k] = xf86Screens[i]->formats[j];
+ numFormats++;
+ break;
+ }
+ if (formats[k].depth == xf86Screens[i]->formats[j].depth) {
+ if ((formats[k].bitsPerPixel ==
+ xf86Screens[i]->formats[j].bitsPerPixel) &&
+ (formats[k].scanlinePad ==
+ xf86Screens[i]->formats[j].scanlinePad))
+ break;
+ FatalError("Inconsistent pixmap format for depth %d."
+ " Exiting\n", formats[k].depth);
+ }
+ }
+ }
+ }
+ formatsDone = TRUE;
+
+ if (xf86Info.vtno >= 0 ) {
+#define VT_ATOM_NAME "XFree86_VT"
+ Atom VTAtom=-1;
+ CARD32 *VT = NULL;
+ int ret;
+
+ /* This memory needs to stay available until the screen has been
+ initialized, and we can create the property for real.
+ */
+ if ( (VT = xalloc(sizeof(CARD32)))==NULL ) {
+ FatalError("Unable to make VT property - out of memory. Exiting...\n");
+ }
+ *VT = xf86Info.vtno;
+
+ VTAtom = MakeAtom(VT_ATOM_NAME, sizeof(VT_ATOM_NAME), TRUE);
+
+ for (i = 0, ret = Success; i < xf86NumScreens && ret == Success; i++) {
+ ret = xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex,
+ VTAtom, XA_INTEGER, 32,
+ 1, VT );
+ if (ret != Success)
+ xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING,
+ "Failed to register VT property\n");
+ }
+ }
+
+ /* If a screen uses depth 24, show what the pixmap format is */
+ for (i = 0; i < xf86NumScreens; i++) {
+ if (xf86Screens[i]->depth == 24) {
+ xf86Msg(pix24From, "Depth 24 pixmap format is %d bpp\n",
+ PIX24TOBPP(pix24));
+ break;
+ }
+ }
+
+#if BITMAP_SCANLINE_UNIT == 64
+ /*
+ * cfb24 doesn't currently work on architectures with a 64 bit
+ * BITMAP_SCANLINE_UNIT, so check for 24 bit pixel size for pixmaps
+ * or framebuffers.
+ */
+ {
+ Bool usesCfb24 = FALSE;
+
+ if (PIX24TOBPP(pix24) == 24)
+ usesCfb24 = TRUE;
+ for (i = 0; i < xf86NumScreens; i++)
+ if (xf86Screens[i]->bitsPerPixel == 24)
+ usesCfb24 = TRUE;
+ if (usesCfb24) {
+ FatalError("24-bit pixel size is not supported on systems with"
+ " 64-bit scanlines.\n");
+ }
+ }
+#endif
+
+#ifdef XKB
+ xf86InitXkb();
+#endif
+ /* set up the proper access funcs */
+ xf86PostPreInit();
+
+ AddCallback(&ServerGrabCallback, xf86GrabServerCallback, NULL);
+
+ } else {
+ /*
+ * serverGeneration != 1; some OSs have to do things here, too.
+ */
+ xf86OpenConsole();
+
+#ifdef XF86PM
+ /*
+ should we reopen it here? We need to deal with an already opened
+ device. We could leave this to the OS layer. For now we simply
+ close it here
+ */
+ if (xf86OSPMClose)
+ xf86OSPMClose();
+ if ((xf86OSPMClose = xf86OSPMOpen()) != NULL)
+ xf86MsgVerb(X_INFO, 3, "APM registered successfully\n");
+#endif
+
+ /* Make sure full I/O access is enabled */
+ if (xorgHWAccess)
+ xf86EnableIO();
+ }
+
+#if 0
+ /*
+ * Install signal handler for unexpected signals
+ */
+ xf86Info.caughtSignal=FALSE;
+ if (!xf86Info.notrapSignals)
+ {
+ signal(SIGSEGV,xf86SigHandler);
+ signal(SIGILL,xf86SigHandler);
+#ifdef SIGEMT
+ signal(SIGEMT,xf86SigHandler);
+#endif
+ signal(SIGFPE,xf86SigHandler);
+#ifdef SIGBUS
+ signal(SIGBUS,xf86SigHandler);
+#endif
+#ifdef SIGSYS
+ signal(SIGSYS,xf86SigHandler);
+#endif
+#ifdef SIGXCPU
+ signal(SIGXCPU,xf86SigHandler);
+#endif
+#ifdef SIGXFSZ
+ signal(SIGXFSZ,xf86SigHandler);
+#endif
+ }
+#endif
+
+ /*
+ * Use the previously collected parts to setup pScreenInfo
+ */
+
+ pScreenInfo->imageByteOrder = xf86Screens[0]->imageByteOrder;
+ pScreenInfo->bitmapScanlinePad = xf86Screens[0]->bitmapScanlinePad;
+ pScreenInfo->bitmapScanlineUnit = xf86Screens[0]->bitmapScanlineUnit;
+ pScreenInfo->bitmapBitOrder = xf86Screens[0]->bitmapBitOrder;
+ pScreenInfo->numPixmapFormats = numFormats;
+ for (i = 0; i < numFormats; i++)
+ pScreenInfo->formats[i] = formats[i];
+
+ /* Make sure the server's VT is active */
+
+ if (serverGeneration != 1) {
+ xf86Resetting = TRUE;
+ /* All screens are in the same state, so just check the first */
+ if (!xf86Screens[0]->vtSema) {
+#ifdef HAS_USL_VTS
+ ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ);
+#endif
+ xf86AccessEnter();
+ xf86EnterServerState(SETUP);
+ }
+ }
+#ifdef SCO325
+ else {
+ /*
+ * Under SCO we must ack that we got the console at startup,
+ * I think this is the safest way to assure it.
+ */
+ static int once = 1;
+ if (once) {
+ once = 0;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
+ xf86Msg(X_WARNING, "VT_ACKACQ failed");
+ }
+ }
+#endif /* SCO325 */
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ xf86EnableAccess(xf86Screens[i]);
+ /*
+ * Almost everything uses these defaults, and many of those that
+ * don't, will wrap them.
+ */
+ xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess;
+ xf86Screens[i]->SetDGAMode = xf86SetDGAMode;
+ xf86Screens[i]->DPMSSet = NULL;
+ xf86Screens[i]->LoadPalette = NULL;
+ xf86Screens[i]->SetOverscan = NULL;
+ xf86Screens[i]->DriverFunc = NULL;
+ xf86Screens[i]->pScreen = NULL;
+ scr_index = AddScreen(xf86Screens[i]->ScreenInit, argc, argv);
+ if (scr_index == i) {
+ /*
+ * Hook in our ScrnInfoRec, and initialise some other pScreen
+ * fields.
+ */
+ screenInfo.screens[scr_index]->devPrivates[xf86ScreenIndex].ptr
+ = (pointer)xf86Screens[i];
+ xf86Screens[i]->pScreen = screenInfo.screens[scr_index];
+ /* The driver should set this, but make sure it is set anyway */
+ xf86Screens[i]->vtSema = TRUE;
+ } else {
+ /* This shouldn't normally happen */
+ FatalError("AddScreen/ScreenInit failed for driver %d\n", i);
+ }
+
+#ifdef DEBUG
+ ErrorF("InitOutput - xf86Screens[%d]->pScreen = %p\n",
+ i, xf86Screens[i]->pScreen );
+ ErrorF("xf86Screens[%d]->pScreen->CreateWindow = %p\n",
+ i, xf86Screens[i]->pScreen->CreateWindow );
+#endif
+
+ screenInfo.screens[scr_index]->devPrivates[xf86CreateRootWindowIndex].ptr
+ = (void*)(xf86Screens[i]->pScreen->CreateWindow);
+ xf86Screens[i]->pScreen->CreateWindow = xf86CreateRootWindow;
+
+#ifdef RENDER
+ if (PictureGetSubpixelOrder (xf86Screens[i]->pScreen) == SubPixelUnknown)
+ {
+ xf86MonPtr DDC = (xf86MonPtr)(xf86Screens[i]->monitor->DDC);
+ PictureSetSubpixelOrder (xf86Screens[i]->pScreen,
+ DDC ?
+ (DDC->features.input_type ?
+ SubPixelHorizontalRGB : SubPixelNone) :
+ SubPixelUnknown);
+ }
+#endif
+#ifdef RANDR
+ if (!xf86Info.disableRandR)
+ xf86RandRInit (screenInfo.screens[scr_index]);
+ xf86Msg(xf86Info.randRFrom, "RandR %s\n",
+ xf86Info.disableRandR ? "disabled" : "enabled");
+#endif
+#ifdef NOT_USED
+ /*
+ * Here we have to let the driver getting access of the VT. Note that
+ * this doesn't mean that the graphics board may access automatically
+ * the monitor. If the monitor is shared this is done in xf86CrossScreen!
+ */
+ if (!xf86Info.sharedMonitor) (xf86Screens[i]->EnterLeaveMonitor)(ENTER);
+#endif
+ }
+
+#ifdef XFree86LOADER
+ if ((serverGeneration == 1) && LoaderCheckUnresolved(LD_RESOLV_IFDONE)) {
+ /* For now, just a warning */
+ xf86Msg(X_WARNING, "Some symbols could not be resolved!\n");
+ }
+#endif
+
+ xf86PostScreenInit();
+
+ xf86InitOrigins();
+
+ xf86Resetting = FALSE;
+ xf86Initialising = FALSE;
+
+ RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA, xf86Wakeup,
+ NULL);
+}
+
+
+static InputDriverPtr
+MatchInput(IDevPtr pDev)
+{
+ int i;
+
+ for (i = 0; i < xf86NumInputDrivers; i++) {
+ if (xf86InputDriverList[i] && xf86InputDriverList[i]->driverName &&
+ xf86NameCmp(pDev->driver, xf86InputDriverList[i]->driverName) == 0)
+ return xf86InputDriverList[i];
+ }
+ return NULL;
+}
+
+
+/*
+ * InitInput --
+ * Initialize all supported input devices.
+ */
+
+void
+InitInput(argc, argv)
+ int argc;
+ char **argv;
+{
+ IDevPtr pDev;
+ InputDriverPtr pDrv;
+ InputInfoPtr pInfo;
+ static InputInfoPtr coreKeyboard = NULL, corePointer = NULL;
+
+ xf86Info.vtRequestsPending = FALSE;
+ xf86Info.inputPending = FALSE;
+#ifdef XTESTEXT1
+ xtest_command_key = KEY_Begin + MIN_KEYCODE;
+#endif /* XTESTEXT1 */
+
+ if (serverGeneration == 1) {
+ /* Call the PreInit function for each input device instance. */
+ for (pDev = xf86ConfigLayout.inputs; pDev && pDev->identifier; pDev++) {
+#ifdef USE_DEPRECATED_KEYBOARD_DRIVER
+ /* XXX The keyboard driver is a special case for now. */
+ if (!xf86NameCmp(pDev->driver, "keyboard")) {
+ xf86MsgVerb(X_WARNING, 0, "*** WARNING the legacy keyboard driver \"keyboard\" is deprecated\n");
+ xf86MsgVerb(X_WARNING, 0, "*** and will be removed in the next release of the Xorg server.\n");
+ xf86MsgVerb(X_WARNING, 0, "*** Please consider using the the new \"kbd\" driver for \"%s\".\n",
+ pDev->identifier);
+
+ continue;
+ }
+#endif
+
+ if ((pDrv = MatchInput(pDev)) == NULL) {
+ xf86Msg(X_ERROR, "No Input driver matching `%s'\n", pDev->driver);
+ /* XXX For now, just continue. */
+ continue;
+ }
+ if (!pDrv->PreInit) {
+ xf86MsgVerb(X_WARNING, 0,
+ "Input driver `%s' has no PreInit function (ignoring)\n",
+ pDrv->driverName);
+ continue;
+ }
+ pInfo = pDrv->PreInit(pDrv, pDev, 0);
+ if (!pInfo) {
+ xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n",
+ pDev->identifier);
+ continue;
+ } else if (!(pInfo->flags & XI86_CONFIGURED)) {
+ xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n",
+ pDev->identifier);
+ xf86DeleteInput(pInfo, 0);
+ continue;
+ }
+ if (pInfo->flags & XI86_CORE_KEYBOARD) {
+ if (coreKeyboard) {
+ xf86Msg(X_ERROR,
+ "Attempt to register more than one core keyboard (%s)\n",
+ pInfo->name);
+ pInfo->flags &= ~XI86_CORE_KEYBOARD;
+ } else {
+ if (!(pInfo->flags & XI86_KEYBOARD_CAPABLE)) {
+ /* XXX just a warning for now */
+ xf86Msg(X_WARNING,
+ "%s: does not have core keyboard capabilities\n",
+ pInfo->name);
+ }
+ coreKeyboard = pInfo;
+ }
+ }
+ if (pInfo->flags & XI86_CORE_POINTER) {
+ if (corePointer) {
+ xf86Msg(X_ERROR,
+ "Attempt to register more than one core pointer (%s)\n",
+ pInfo->name);
+ pInfo->flags &= ~XI86_CORE_POINTER;
+ } else {
+ if (!(pInfo->flags & XI86_POINTER_CAPABLE)) {
+ /* XXX just a warning for now */
+ xf86Msg(X_WARNING,
+ "%s: does not have core pointer capabilities\n",
+ pInfo->name);
+ }
+ corePointer = pInfo;
+ }
+ }
+ }
+ if (!corePointer) {
+ xf86Msg(X_WARNING, "No core pointer registered\n");
+ /* XXX register a dummy core pointer */
+ }
+#ifdef NEW_KBD
+ if (!coreKeyboard) {
+ xf86Msg(X_WARNING, "No core keyboard registered\n");
+ /* XXX register a dummy core keyboard */
+ }
+#endif
+ }
+
+ /* Initialise all input devices. */
+ pInfo = xf86InputDevs;
+ while (pInfo) {
+ xf86ActivateDevice(pInfo);
+ pInfo = pInfo->next;
+ }
+
+ if (coreKeyboard) {
+ xf86Info.pKeyboard = coreKeyboard->dev;
+ xf86Info.kbdEvents = NULL; /* to prevent the internal keybord driver usage*/
+ }
+ else {
+#ifdef USE_DEPRECATED_KEYBOARD_DRIVER
+ /* Only set this if we're allowing the old driver. */
+ if (xf86Info.kbdProc != NULL)
+ xf86Info.pKeyboard = AddInputDevice(xf86Info.kbdProc, TRUE);
+#endif
+ }
+ if (corePointer)
+ xf86Info.pMouse = corePointer->dev;
+ if (xf86Info.pKeyboard)
+ RegisterKeyboardDevice(xf86Info.pKeyboard);
+
+ miRegisterPointerDevice(screenInfo.screens[0], xf86Info.pMouse);
+#ifdef XINPUT
+ xf86eqInit ((DevicePtr)xf86Info.pKeyboard, (DevicePtr)xf86Info.pMouse);
+#else
+ mieqInit ((DevicePtr)xf86Info.pKeyboard, (DevicePtr)xf86Info.pMouse);
+#endif
+}
+
+#ifndef SET_STDERR_NONBLOCKING
+#define SET_STDERR_NONBLOCKING 1
+#endif
+
+/*
+ * OsVendorInit --
+ * OS/Vendor-specific initialisations. Called from OsInit(), which
+ * is called by dix before establishing the well known sockets.
+ */
+
+void
+OsVendorInit()
+{
+ static Bool beenHere = FALSE;
+
+ /* xf86WrapperInit() is called directly from OsInit() */
+#ifdef SIGCHLD
+ signal(SIGCHLD, SIG_DFL); /* Need to wait for child processes */
+#endif
+ OsDelayInitColors = TRUE;
+#ifdef XFree86LOADER
+ loadableFonts = TRUE;
+#endif
+
+ if (!beenHere)
+ xf86LogInit();
+
+#if SET_STDERR_NONBLOCKING
+ /* Set stderr to non-blocking. */
+#ifndef O_NONBLOCK
+#if defined(FNDELAY)
+#define O_NONBLOCK FNDELAY
+#elif defined(O_NDELAY)
+#define O_NONBLOCK O_NDELAY
+#endif
+#endif
+
+#ifdef O_NONBLOCK
+ if (!beenHere) {
+#if !defined(__EMX__)
+ if (geteuid() == 0 && getuid() != geteuid())
+#endif
+ {
+ int status;
+
+ status = fcntl(fileno(stderr), F_GETFL, 0);
+ if (status != -1) {
+ fcntl(fileno(stderr), F_SETFL, status | O_NONBLOCK);
+ }
+ }
+ }
+#endif
+#endif
+
+ beenHere = TRUE;
+}
+
+/*
+ * ddxGiveUp --
+ * Device dependent cleanup. Called by by dix before normal server death.
+ * For SYSV386 we must switch the terminal back to normal mode. No error-
+ * checking here, since there should be restored as much as possible.
+ */
+
+void
+ddxGiveUp()
+{
+ int i;
+
+#ifdef XF86PM
+ if (xf86OSPMClose)
+ xf86OSPMClose();
+ xf86OSPMClose = NULL;
+#endif
+
+ xf86AccessLeaveState();
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ /*
+ * zero all access functions to
+ * trap calls when switched away.
+ */
+ xf86Screens[i]->vtSema = FALSE;
+ xf86Screens[i]->access = NULL;
+ xf86Screens[i]->busAccess = NULL;
+ }
+
+#ifdef USE_XF86_SERVERLOCK
+ xf86UnlockServer();
+#endif
+#ifdef XFreeXDGA
+ DGAShutdown();
+#endif
+
+ xf86CloseConsole();
+
+ xf86CloseLog();
+
+ /* If an unexpected signal was caught, dump a core for debugging */
+ if (xf86Info.caughtSignal)
+ abort();
+}
+
+
+
+/*
+ * AbortDDX --
+ * DDX - specific abort routine. Called by AbortServer(). The attempt is
+ * made to restore all original setting of the displays. Also all devices
+ * are closed.
+ */
+
+void
+AbortDDX()
+{
+ int i;
+
+ /*
+ * try to deinitialize all input devices
+ */
+ if (xf86Info.kbdProc && xf86Info.pKeyboard)
+ (xf86Info.kbdProc)(xf86Info.pKeyboard, DEVICE_CLOSE);
+
+ /*
+ * try to restore the original video state
+ */
+#ifdef HAS_USL_VTS
+ /* Need the sleep when starting X from within another X session */
+ sleep(1);
+#endif
+#ifdef DPMSExtension /* Turn screens back on */
+ if (DPMSPowerLevel != DPMSModeOn)
+ DPMSSet(DPMSModeOn);
+#endif
+ if (xf86Screens) {
+ if (xf86Screens[0]->vtSema)
+ xf86EnterServerState(SETUP);
+ for (i = 0; i < xf86NumScreens; i++)
+ if (xf86Screens[i]->vtSema) {
+ /*
+ * if we are aborting before ScreenInit() has finished
+ * we might not have been wrapped yet. Therefore enable
+ * screen explicitely.
+ */
+ xf86EnableAccess(xf86Screens[i]);
+ (xf86Screens[i]->LeaveVT)(i, 0);
+ }
+ }
+
+ xf86AccessLeave();
+
+ /*
+ * This is needed for an abnormal server exit, since the normal exit stuff
+ * MUST also be performed (i.e. the vt must be left in a defined state)
+ */
+ ddxGiveUp();
+}
+
+void
+OsVendorFatalError()
+{
+#ifdef VENDORSUPPORT
+ ErrorF("\nPlease refer to your Operating System Vendor support pages\n"
+ "at %s for support on this crash.\n",VENDORSUPPORT);
+#else
+ ErrorF("\nPlease consult the "XVENDORNAME" support \n"
+ "\t at "__VENDORDWEBSUPPORT__"\n for help. \n");
+#endif
+ if (xf86LogFile && xf86LogFileWasOpened)
+ ErrorF("Please also check the log file at \"%s\" for additional "
+ "information.\n", xf86LogFile);
+ ErrorF("\n");
+}
+
+int
+xf86SetVerbosity(int verb)
+{
+ int save = xf86Verbose;
+
+ xf86Verbose = verb;
+ LogSetParameter(XLOG_VERBOSITY, verb);
+ return save;
+}
+
+int
+xf86SetLogVerbosity(int verb)
+{
+ int save = xf86LogVerbose;
+
+ xf86LogVerbose = verb;
+ LogSetParameter(XLOG_FILE_VERBOSITY, verb);
+ return save;
+}
+
+/*
+ * ddxProcessArgument --
+ * Process device-dependent command line args. Returns 0 if argument is
+ * not device dependent, otherwise Count of number of elements of argv
+ * that are part of a device dependent commandline option.
+ *
+ */
+
+
+
+/* ARGSUSED */
+int
+ddxProcessArgument(int argc, char **argv, int i)
+{
+ /*
+ * Note: can't use xalloc/xfree here because OsInit() hasn't been called
+ * yet. Use malloc/free instead.
+ */
+
+#define CHECK_FOR_REQUIRED_ARGUMENT() \
+ if (((i + 1) >= argc) || (!argv[i + 1])) { \
+ ErrorF("Required argument to %s not specified\n", argv[i]); \
+ UseMsg(); \
+ FatalError("Required argument to %s not specified\n", argv[i]); \
+ }
+
+ /* First the options that are only allowed for root */
+ if (getuid() == 0 || geteuid() != 0)
+ {
+ if (!strcmp(argv[i], "-modulepath"))
+ {
+ char *mp;
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ mp = malloc(strlen(argv[i + 1]) + 1);
+ if (!mp)
+ FatalError("Can't allocate memory for ModulePath\n");
+ strcpy(mp, argv[i + 1]);
+ xf86ModulePath = mp;
+ xf86ModPathFrom = X_CMDLINE;
+ return 2;
+ }
+ else if (!strcmp(argv[i], "-logfile"))
+ {
+ char *lf;
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ lf = malloc(strlen(argv[i + 1]) + 1);
+ if (!lf)
+ FatalError("Can't allocate memory for LogFile\n");
+ strcpy(lf, argv[i + 1]);
+ xf86LogFile = lf;
+ xf86LogFileFrom = X_CMDLINE;
+ return 2;
+ }
+ } else if (!strcmp(argv[i], "-modulepath") || !strcmp(argv[i], "-logfile")) {
+ FatalError("The '%s' option can only be used by root.\n", argv[i]);
+ }
+ if (!strcmp(argv[i], "-config") || !strcmp(argv[i], "-xf86config"))
+ {
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ if (getuid() != 0 && !xf86PathIsSafe(argv[i + 1])) {
+ FatalError("\nInvalid argument for %s\n"
+ "\tFor non-root users, the file specified with %s must be\n"
+ "\ta relative path and must not contain any \"..\" elements.\n"
+ "\tUsing default "__XCONFIGFILE__" search path.\n\n",
+ argv[i], argv[i]);
+ }
+ xf86ConfigFile = argv[i + 1];
+ return 2;
+ }
+ if (!strcmp(argv[i],"-showunresolved"))
+ {
+ xf86ShowUnresolved = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-probeonly"))
+ {
+ xf86ProbeOnly = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-flipPixels"))
+ {
+ xf86FlipPixels = TRUE;
+ return 1;
+ }
+#ifdef XF86VIDMODE
+ if (!strcmp(argv[i],"-disableVidMode"))
+ {
+ xf86VidModeDisabled = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-allowNonLocalXvidtune"))
+ {
+ xf86VidModeAllowNonLocal = TRUE;
+ return 1;
+ }
+#endif
+#ifdef XF86MISC
+ if (!strcmp(argv[i],"-disableModInDev"))
+ {
+ xf86MiscModInDevDisabled = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-allowNonLocalModInDev"))
+ {
+ xf86MiscModInDevAllowNonLocal = TRUE;
+ return 1;
+ }
+#endif
+ if (!strcmp(argv[i],"-allowMouseOpenFail"))
+ {
+ xf86AllowMouseOpenFail = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-bestRefresh"))
+ {
+ xf86BestRefresh = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-ignoreABI"))
+ {
+#ifdef XFree86LOADER
+ LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL);
+#endif
+ return 1;
+ }
+ if (!strcmp(argv[i],"-verbose"))
+ {
+ if (++i < argc && argv[i])
+ {
+ char *end;
+ long val;
+ val = strtol(argv[i], &end, 0);
+ if (*end == '\0')
+ {
+ xf86SetVerbosity(val);
+ return 2;
+ }
+ }
+ xf86SetVerbosity(++xf86Verbose);
+ return 1;
+ }
+ if (!strcmp(argv[i],"-logverbose"))
+ {
+ if (++i < argc && argv[i])
+ {
+ char *end;
+ long val;
+ val = strtol(argv[i], &end, 0);
+ if (*end == '\0')
+ {
+ xf86SetLogVerbosity(val);
+ return 2;
+ }
+ }
+ xf86SetLogVerbosity(++xf86LogVerbose);
+ return 1;
+ }
+ if (!strcmp(argv[i],"-quiet"))
+ {
+ xf86SetVerbosity(0);
+ return 1;
+ }
+ if (!strcmp(argv[i],"-showconfig") || !strcmp(argv[i],"-version"))
+ {
+ xf86PrintBanner();
+ exit(0);
+ }
+ /* Notice the -fp flag, but allow it to pass to the dix layer */
+ if (!strcmp(argv[i], "-fp"))
+ {
+ xf86fpFlag = TRUE;
+ return 0;
+ }
+ /* Notice the -co flag, but allow it to pass to the dix layer */
+ if (!strcmp(argv[i], "-co"))
+ {
+ xf86coFlag = TRUE;
+ return 0;
+ }
+ /* Notice the -bs flag, but allow it to pass to the dix layer */
+ if (!strcmp(argv[i], "-bs"))
+ {
+ xf86bsDisableFlag = TRUE;
+ return 0;
+ }
+ /* Notice the +bs flag, but allow it to pass to the dix layer */
+ if (!strcmp(argv[i], "+bs"))
+ {
+ xf86bsEnableFlag = TRUE;
+ return 0;
+ }
+ /* Notice the -s flag, but allow it to pass to the dix layer */
+ if (!strcmp(argv[i], "-s"))
+ {
+ xf86sFlag = TRUE;
+ return 0;
+ }
+ if (!strcmp(argv[i], "-bpp"))
+ {
+ ErrorF("The -bpp option is no longer supported.\n"
+ "\tUse -depth to set the color depth, and use -fbbpp if you really\n"
+ "\tneed to force a non-default framebuffer (hardware) pixel format.\n");
+ if (++i >= argc)
+ return 1;
+ return 2;
+ }
+ if (!strcmp(argv[i], "-pixmap24"))
+ {
+ xf86Pix24 = Pix24Use24;
+ return 1;
+ }
+ if (!strcmp(argv[i], "-pixmap32"))
+ {
+ xf86Pix24 = Pix24Use32;
+ return 1;
+ }
+ if (!strcmp(argv[i], "-fbbpp"))
+ {
+ int bpp;
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ if (sscanf(argv[++i], "%d", &bpp) == 1)
+ {
+ xf86FbBpp = bpp;
+ return 2;
+ }
+ else
+ {
+ ErrorF("Invalid fbbpp\n");
+ return 0;
+ }
+ }
+ if (!strcmp(argv[i], "-depth"))
+ {
+ int depth;
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ if (sscanf(argv[++i], "%d", &depth) == 1)
+ {
+ xf86Depth = depth;
+ return 2;
+ }
+ else
+ {
+ ErrorF("Invalid depth\n");
+ return 0;
+ }
+ }
+ if (!strcmp(argv[i], "-weight"))
+ {
+ int red, green, blue;
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ if (sscanf(argv[++i], "%1d%1d%1d", &red, &green, &blue) == 3)
+ {
+ xf86Weight.red = red;
+ xf86Weight.green = green;
+ xf86Weight.blue = blue;
+ return 2;
+ }
+ else
+ {
+ ErrorF("Invalid weighting\n");
+ return 0;
+ }
+ }
+ if (!strcmp(argv[i], "-gamma") || !strcmp(argv[i], "-rgamma") ||
+ !strcmp(argv[i], "-ggamma") || !strcmp(argv[i], "-bgamma"))
+ {
+ double gamma;
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ if (sscanf(argv[++i], "%lf", &gamma) == 1) {
+ if (gamma < GAMMA_MIN || gamma > GAMMA_MAX) {
+ ErrorF("gamma out of range, only %.2f <= gamma_value <= %.1f"
+ " is valid\n", GAMMA_MIN, GAMMA_MAX);
+ return 0;
+ }
+ if (!strcmp(argv[i-1], "-gamma"))
+ xf86Gamma.red = xf86Gamma.green = xf86Gamma.blue = gamma;
+ else if (!strcmp(argv[i-1], "-rgamma")) xf86Gamma.red = gamma;
+ else if (!strcmp(argv[i-1], "-ggamma")) xf86Gamma.green = gamma;
+ else if (!strcmp(argv[i-1], "-bgamma")) xf86Gamma.blue = gamma;
+ return 2;
+ }
+ }
+ if (!strcmp(argv[i], "-layout"))
+ {
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ xf86LayoutName = argv[++i];
+ return 2;
+ }
+ if (!strcmp(argv[i], "-screen"))
+ {
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ xf86ScreenName = argv[++i];
+ return 2;
+ }
+ if (!strcmp(argv[i], "-pointer"))
+ {
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ xf86PointerName = argv[++i];
+ return 2;
+ }
+ if (!strcmp(argv[i], "-keyboard"))
+ {
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ xf86KeyboardName = argv[++i];
+ return 2;
+ }
+ if (!strcmp(argv[i], "-nosilk"))
+ {
+ xf86silkenMouseDisableFlag = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i], "-noacpi"))
+ {
+ xf86acpiDisableFlag = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i], "-scanpci"))
+ {
+ DoScanPci(argc, argv, i);
+ }
+ if (!strcmp(argv[i], "-probe"))
+ {
+ xf86DoProbe = TRUE;
+#if 0
+ DoProbe(argc, argv, i);
+#endif
+ return 1;
+ }
+ if (!strcmp(argv[i], "-configure"))
+ {
+ if (getuid() != 0 && geteuid() == 0) {
+ ErrorF("The '-configure' option can only be used by root.\n");
+ exit(1);
+ }
+ xf86DoConfigure = TRUE;
+ xf86AllowMouseOpenFail = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i], "-isolateDevice"))
+ {
+ int bus, device, func;
+ CHECK_FOR_REQUIRED_ARGUMENT();
+ if (strncmp(argv[++i], "PCI:", 4)) {
+ FatalError("Bus types other than PCI not yet isolable\n");
+ }
+ if (sscanf(argv[i], "PCI:%d:%d:%d", &bus, &device, &func) == 3) {
+ xf86IsolateDevice.bus = bus;
+ xf86IsolateDevice.device = device;
+ xf86IsolateDevice.func = func;
+ return 2;
+ } else {
+ FatalError("Invalid isolated device specification\n");
+ }
+ }
+ /* OS-specific processing */
+ return xf86ProcessArgument(argc, argv, i);
+}
+
+/* ddxInitGlobals - called by |InitGlobals| from os/util.c */
+void ddxInitGlobals(void)
+{
+}
+
+/*
+ * ddxUseMsg --
+ * Print out correct use of device dependent commandline options.
+ * Maybe the user now knows what really to do ...
+ */
+
+void
+ddxUseMsg()
+{
+ ErrorF("\n");
+ ErrorF("\n");
+ ErrorF("Device Dependent Usage\n");
+ if (getuid() == 0 || geteuid() != 0)
+ {
+ ErrorF("-modulepath paths specify the module search path\n");
+ ErrorF("-logfile file specify a log file name\n");
+ ErrorF("-configure probe for devices and write an "__XCONFIGFILE__"\n");
+ }
+ ErrorF("-config file specify a configuration file, relative to the\n");
+ ErrorF(" "__XCONFIGFILE__" search path, only root can use absolute\n");
+ ErrorF("-probeonly probe for devices, then exit\n");
+ ErrorF("-scanpci execute the scanpci module and exit\n");
+ ErrorF("-verbose [n] verbose startup messages\n");
+ ErrorF("-logverbose [n] verbose log messages\n");
+ ErrorF("-quiet minimal startup messages\n");
+ ErrorF("-pixmap24 use 24bpp pixmaps for depth 24\n");
+ ErrorF("-pixmap32 use 32bpp pixmaps for depth 24\n");
+ ErrorF("-fbbpp n set bpp for the framebuffer. Default: 8\n");
+ ErrorF("-depth n set colour depth. Default: 8\n");
+ ErrorF("-gamma f set gamma value (0.1 < f < 10.0) Default: 1.0\n");
+ ErrorF("-rgamma f set gamma value for red phase\n");
+ ErrorF("-ggamma f set gamma value for green phase\n");
+ ErrorF("-bgamma f set gamma value for blue phase\n");
+ ErrorF("-weight nnn set RGB weighting at 16 bpp. Default: 565\n");
+ ErrorF("-layout name specify the ServerLayout section name\n");
+ ErrorF("-screen name specify the Screen section name\n");
+ ErrorF("-keyboard name specify the core keyboard InputDevice name\n");
+ ErrorF("-pointer name specify the core pointer InputDevice name\n");
+ ErrorF("-nosilk disable Silken Mouse\n");
+ ErrorF("-flipPixels swap default black/white Pixel values\n");
+#ifdef XF86VIDMODE
+ ErrorF("-disableVidMode disable mode adjustments with xvidtune\n");
+ ErrorF("-allowNonLocalXvidtune allow xvidtune to be run as a non-local client\n");
+#endif
+#ifdef XF86MISC
+ ErrorF("-disableModInDev disable dynamic modification of input device settings\n");
+ ErrorF("-allowNonLocalModInDev allow changes to keyboard and mouse settings\n");
+ ErrorF(" from non-local clients\n");
+ ErrorF("-allowMouseOpenFail start server even if the mouse can't be initialized\n");
+#endif
+ ErrorF("-bestRefresh choose modes with the best refresh rate\n");
+ ErrorF("-ignoreABI make module ABI mismatches non-fatal\n");
+ ErrorF("-isolateDevice bus_id restrict device resets to bus_id (PCI only)\n");
+ ErrorF("-version show the server version\n");
+ /* OS-specific usage */
+ xf86UseMsg();
+ ErrorF("\n");
+}
+
+
+#ifndef OSNAME
+#define OSNAME " unknown"
+#endif
+#ifndef OSVENDOR
+#define OSVENDOR ""
+#endif
+#ifndef PRE_RELEASE
+#define PRE_RELEASE XORG_VERSION_SNAP
+#endif
+
+static void
+xf86PrintBanner()
+{
+#if PRE_RELEASE
+ ErrorF("\n"
+ "This is a pre-release version of the X server from " XVENDORNAME ".\n"
+ "It is not supported in any way.\n"
+ "Bugs may be filed in the bugzilla at http://bugs.freedesktop.org/.\n"
+ "Select the \"xorg\" product for bugs you find in this release.\n"
+ "Before reporting bugs in pre-release versions please check the\n"
+ "latest version in the X.Org Foundation CVS repository.\n"
+ "See http://wiki.x.org/wiki/CvsPage for CVS access instructions.\n");
+#endif
+ ErrorF("\nX Window System Version %d.%d.%d",
+ XORG_VERSION_MAJOR,
+ XORG_VERSION_MINOR,
+ XORG_VERSION_PATCH);
+#if XORG_VERSION_SNAP > 0
+ ErrorF(".%d", XORG_VERSION_SNAP);
+#endif
+
+#if XORG_VERSION_SNAP >= 900
+ /* When the minor number is 99, that signifies that the we are making
+ * a release candidate for a major version. (X.0.0)
+ * When the patch number is 99, that signifies that the we are making
+ * a release candidate for a minor version. (X.Y.0)
+ * When the patch number is < 99, then we are making a release
+ * candidate for the next point release. (X.Y.Z)
+ */
+#if XORG_VERSION_MINOR >= 99
+ ErrorF(" (%d.0.0 RC %d)", XORG_VERSION_MAJOR+1, XORG_VERSION_SNAP - 900);
+#elif XORG_VERSION_PATCH == 99
+ ErrorF(" (%d.%d.0 RC %d)", XORG_VERSION_MAJOR, XORG_VERSION_MINOR + 1,
+ XORG_VERSION_SNAP - 900);
+#else
+ ErrorF(" (%d.%d.%d RC %d)", XORG_VERSION_MAJOR, XORG_VERSION_MINOR,
+ XORG_VERSION_PATCH + 1, XORG_VERSION_SNAP - 900);
+#endif
+#endif
+
+#ifdef XORG_CUSTOM_VERSION
+ ErrorF(" (%s)", XORG_CUSTOM_VERSION);
+#endif
+#ifndef XORG_DATE
+#define XORG_DATE XF86_DATE
+#endif
+ ErrorF("\nRelease Date: %s\n", XORG_DATE);
+ ErrorF("X Protocol Version %d, Revision %d, %s\n",
+ X_PROTOCOL, X_PROTOCOL_REVISION, XORG_RELEASE );
+ ErrorF("Build Operating System:%s%s\n", OSNAME, OSVENDOR);
+#ifdef HAS_UTSNAME
+ {
+ struct utsname name;
+
+ /* Linux & BSD state that 0 is success, SysV (including Solaris, HP-UX,
+ and Irix) and Single Unix Spec 3 just say that non-negative is success.
+ All agree that failure is represented by a negative number.
+ */
+ if (uname(&name) >= 0) {
+ ErrorF("Current Operating System: %s %s %s %s %s\n",
+ name.sysname, name.nodename, name.release, name.version, name.machine);
+ }
+ }
+#endif
+#if defined(BUILD_DATE) && (BUILD_DATE > 19000000)
+ {
+ struct tm t;
+ char buf[100];
+
+ bzero(&t, sizeof(t));
+ bzero(buf, sizeof(buf));
+ t.tm_mday = BUILD_DATE % 100;
+ t.tm_mon = (BUILD_DATE / 100) % 100 - 1;
+ t.tm_year = BUILD_DATE / 10000 - 1900;
+ if (strftime(buf, sizeof(buf), "%d %B %Y", &t))
+ ErrorF("Build Date: %s\n", buf);
+ }
+#endif
+#if defined(CLOG_DATE) && (CLOG_DATE > 19000000)
+ {
+ struct tm t;
+ char buf[100];
+
+ bzero(&t, sizeof(t));
+ bzero(buf, sizeof(buf));
+ t.tm_mday = CLOG_DATE % 100;
+ t.tm_mon = (CLOG_DATE / 100) % 100 - 1;
+ t.tm_year = CLOG_DATE / 10000 - 1900;
+ if (strftime(buf, sizeof(buf), "%d %B %Y", &t))
+ ErrorF("Changelog Date: %s\n", buf);
+ }
+#endif
+#if defined(BUILDERSTRING)
+ ErrorF("%s \n",BUILDERSTRING);
+#endif
+ ErrorF("\tBefore reporting problems, check "__VENDORDWEBSUPPORT__"\n"
+ "\tto make sure that you have the latest version.\n");
+#ifdef XFree86LOADER
+ ErrorF("Module Loader present\n");
+#endif
+}
+
+static void
+xf86PrintMarkers()
+{
+ LogPrintMarkers();
+}
+
+static void
+xf86RunVtInit(void)
+{
+ int i;
+
+ /*
+ * If VTInit was set, run that program with consoleFd as stdin and stdout
+ */
+
+ if (xf86Info.vtinit) {
+ switch(fork()) {
+ case -1:
+ FatalError("xf86RunVtInit: fork failed (%s)\n", strerror(errno));
+ break;
+ case 0: /* child */
+ if (setuid(getuid()) == -1) {
+ xf86Msg(X_ERROR, "xf86RunVtInit: setuid failed (%s)\n",
+ strerror(errno));
+ exit(255);
+ }
+ /* set stdin, stdout to the consoleFd */
+ for (i = 0; i < 2; i++) {
+ if (xf86Info.consoleFd != i) {
+ close(i);
+ dup(xf86Info.consoleFd);
+ }
+ }
+ execl("/bin/sh", "sh", "-c", xf86Info.vtinit, (void *)NULL);
+ xf86Msg(X_WARNING, "exec of /bin/sh failed for VTInit (%s)\n",
+ strerror(errno));
+ exit(255);
+ break;
+ default: /* parent */
+ wait(NULL);
+ }
+ }
+}
+
+#ifdef XFree86LOADER
+/*
+ * xf86LoadModules iterates over a list that is being passed in.
+ */
+Bool
+xf86LoadModules(char **list, pointer *optlist)
+{
+ int errmaj, errmin;
+ pointer opt;
+ int i;
+ char *name;
+ Bool failed = FALSE;
+
+ if (!list)
+ return TRUE;
+
+ for (i = 0; list[i] != NULL; i++) {
+
+#ifndef NORMALISE_MODULE_NAME
+ name = xstrdup(list[i]);
+#else
+ /* Normalise the module name */
+ name = xf86NormalizeName(list[i]);
+#endif
+
+ /* Skip empty names */
+ if (name == NULL || *name == '\0')
+ continue;
+
+ if (optlist)
+ opt = optlist[i];
+ else
+ opt = NULL;
+
+ if (!LoadModule(name, NULL, NULL, NULL, opt, NULL, &errmaj, &errmin)) {
+ LoaderErrorMsg(NULL, name, errmaj, errmin);
+ failed = TRUE;
+ }
+ xfree(name);
+ }
+ return !failed;
+}
+
+#endif
+
+/* Pixmap format stuff */
+
+PixmapFormatPtr
+xf86GetPixFormat(ScrnInfoPtr pScrn, int depth)
+{
+ int i;
+ static PixmapFormatRec format; /* XXX not reentrant */
+
+ /*
+ * When the formats[] list initialisation isn't complete, check the
+ * depth 24 pixmap config/cmdline options and screen-specified formats.
+ */
+
+ if (!formatsDone) {
+ if (depth == 24) {
+ Pix24Flags pix24 = Pix24DontCare;
+
+ format.depth = 24;
+ format.scanlinePad = BITMAP_SCANLINE_PAD;
+ if (xf86Info.pixmap24 != Pix24DontCare)
+ pix24 = xf86Info.pixmap24;
+ else if (pScrn->pixmap24 != Pix24DontCare)
+ pix24 = pScrn->pixmap24;
+ if (pix24 == Pix24Use24)
+ format.bitsPerPixel = 24;
+ else
+ format.bitsPerPixel = 32;
+ return &format;
+ }
+ }
+
+ for (i = 0; i < numFormats; i++)
+ if (formats[i].depth == depth)
+ break;
+ if (i != numFormats)
+ return &formats[i];
+ else if (!formatsDone) {
+ /* Check for screen-specified formats */
+ for (i = 0; i < pScrn->numFormats; i++)
+ if (pScrn->formats[i].depth == depth)
+ break;
+ if (i != pScrn->numFormats)
+ return &pScrn->formats[i];
+ }
+ return NULL;
+}
+
+int
+xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth)
+{
+ PixmapFormatPtr format;
+
+
+ format = xf86GetPixFormat(pScrn, depth);
+ if (format)
+ return format->bitsPerPixel;
+ else
+ return 0;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Io.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Io.c
new file mode 100644
index 000000000..ef0fddf99
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Io.c
@@ -0,0 +1,507 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Io.c,v 3.56 2003/11/03 05:11:02 tsi Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
+ * Copyright (c) 1992-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).
+ */
+
+/* $XConsortium: xf86Io.c /main/27 1996/10/19 17:58:55 kaleb $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86Io.c,v 1.5 2005/07/03 07:01:24 daniels Exp $ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSlib.h"
+#include "mipointer.h"
+
+#ifdef XINPUT
+#include "xf86Xinput.h"
+#include <X11/extensions/XIproto.h>
+#include "exevents.h"
+#endif
+
+#ifdef XKB
+#include <X11/extensions/XKB.h>
+#include <X11/extensions/XKBstr.h>
+#include <X11/extensions/XKBsrv.h>
+#endif
+
+unsigned int xf86InitialCaps = 0;
+unsigned int xf86InitialNum = 0;
+unsigned int xf86InitialScroll = 0;
+
+#include "atKeynames.h"
+
+/*
+ * xf86KbdBell --
+ * Ring the terminal/keyboard bell for an amount of time proportional to
+ * "loudness".
+ */
+
+void
+xf86KbdBell(percent, pKeyboard, ctrl, unused)
+ int percent; /* Percentage of full volume */
+ DeviceIntPtr pKeyboard; /* Keyboard to ring */
+ pointer ctrl;
+ int unused;
+{
+ xf86SoundKbdBell(percent, xf86Info.bell_pitch, xf86Info.bell_duration);
+}
+
+void
+xf86UpdateKbdLeds()
+{
+ int leds = 0;
+ if (xf86Info.capsLock) leds |= XLED1;
+ if (xf86Info.numLock) leds |= XLED2;
+ if (xf86Info.scrollLock || xf86Info.modeSwitchLock) leds |= XLED3;
+ if (xf86Info.composeLock) leds |= XLED4;
+ xf86Info.leds = (xf86Info.leds & xf86Info.xleds) | (leds & ~xf86Info.xleds);
+ xf86KbdLeds();
+}
+
+void
+xf86KbdLeds ()
+{
+ int leds, real_leds = 0;
+
+#if defined (__sparc__) && defined(__linux__)
+ static int kbdSun = -1;
+ if (kbdSun == -1) {
+ if ((xf86Info.xkbmodel && !strcmp(xf86Info.xkbmodel, "sun")) ||
+ (xf86Info.xkbrules && !strcmp(xf86Info.xkbrules, "sun")))
+ kbdSun = 1;
+ else
+ kbdSun = 0;
+ }
+ if (kbdSun) {
+ if (xf86Info.leds & 0x08) real_leds |= XLED1;
+ if (xf86Info.leds & 0x04) real_leds |= XLED3;
+ if (xf86Info.leds & 0x02) real_leds |= XLED4;
+ if (xf86Info.leds & 0x01) real_leds |= XLED2;
+ leds = real_leds;
+ real_leds = 0;
+ } else {
+ leds = xf86Info.leds;
+ }
+#else
+ leds = xf86Info.leds;
+#endif /* defined (__sparc__) */
+
+#ifdef LED_CAP
+ if (leds & XLED1) real_leds |= LED_CAP;
+ if (leds & XLED2) real_leds |= LED_NUM;
+ if (leds & XLED3) real_leds |= LED_SCR;
+#ifdef LED_COMP
+ if (leds & XLED4) real_leds |= LED_COMP;
+#else
+ if (leds & XLED4) real_leds |= LED_SCR;
+#endif
+#endif
+#ifdef sun
+ /* Pass through any additional LEDs, such as Kana LED on Sun Japanese kbd */
+ real_leds |= (leds & 0xFFFFFFF0);
+#endif
+ xf86SetKbdLeds(real_leds);
+ (void)leds;
+}
+
+/*
+ * xf86KbdCtrl --
+ * Alter some of the keyboard control parameters. All special protocol
+ * values are handled by dix (ProgChangeKeyboardControl)
+ */
+
+void
+xf86KbdCtrl (pKeyboard, ctrl)
+ DevicePtr pKeyboard; /* Keyboard to alter */
+ KeybdCtrl *ctrl;
+{
+ int leds;
+ xf86Info.bell_pitch = ctrl->bell_pitch;
+ xf86Info.bell_duration = ctrl->bell_duration;
+ xf86Info.autoRepeat = ctrl->autoRepeat;
+
+ xf86Info.composeLock = (ctrl->leds & XCOMP) ? TRUE : FALSE;
+
+ leds = (ctrl->leds & ~(XCAPS | XNUM | XSCR));
+#ifdef XKB
+ if (noXkbExtension) {
+#endif
+ xf86Info.leds = (leds & xf86Info.xleds)|(xf86Info.leds & ~xf86Info.xleds);
+#ifdef XKB
+ } else {
+ xf86Info.leds = leds;
+ }
+#endif
+
+ xf86KbdLeds();
+}
+
+/*
+ * xf86InitKBD --
+ * Reinitialize the keyboard. Only set Lockkeys according to ours leds.
+ * Depress all other keys.
+ */
+
+void
+xf86InitKBD(init)
+Bool init;
+{
+ char leds = 0, rad;
+ unsigned int i;
+ xEvent kevent;
+ DeviceIntPtr pKeyboard = xf86Info.pKeyboard;
+ KeyClassRec *keyc = xf86Info.pKeyboard->key;
+ KeySym *map = keyc->curKeySyms.map;
+
+ kevent.u.keyButtonPointer.time = GetTimeInMillis();
+ kevent.u.keyButtonPointer.rootX = 0;
+ kevent.u.keyButtonPointer.rootY = 0;
+
+ /*
+ * Hmm... here is the biggest hack of every time !
+ * It may be possible that a switch-vt procedure has finished BEFORE
+ * you released all keys neccessary to do this. That peculiar behavior
+ * can fool the X-server pretty much, cause it assumes that some keys
+ * were not released. TWM may stuck alsmost completly....
+ * OK, what we are doing here is after returning from the vt-switch
+ * exeplicitely unrelease all keyboard keys before the input-devices
+ * are reenabled.
+ */
+ for (i = keyc->curKeySyms.minKeyCode, map = keyc->curKeySyms.map;
+ i < keyc->curKeySyms.maxKeyCode;
+ i++, map += keyc->curKeySyms.mapWidth)
+ if (KeyPressed(i))
+ {
+ switch (*map) {
+ /* Don't release the lock keys */
+ case XK_Caps_Lock:
+ case XK_Shift_Lock:
+ case XK_Num_Lock:
+ case XK_Scroll_Lock:
+ case XK_Kana_Lock:
+ break;
+ default:
+ kevent.u.u.detail = i;
+ kevent.u.u.type = KeyRelease;
+ (* pKeyboard->public.processInputProc)(&kevent, pKeyboard, 1);
+ }
+ }
+
+ xf86Info.scanPrefix = 0;
+
+ if (init)
+ {
+ /*
+ * we must deal here with the fact, that on some cases the numlock or
+ * capslock key are enabled BEFORE the server is started up. So look
+ * here at the state on the according LEDS to determine whether a
+ * lock-key is already set.
+ */
+
+ xf86Info.capsLock = FALSE;
+ xf86Info.numLock = FALSE;
+ xf86Info.scrollLock = FALSE;
+ xf86Info.modeSwitchLock = FALSE;
+ xf86Info.composeLock = FALSE;
+
+#ifdef LED_CAP
+#ifdef INHERIT_LOCK_STATE
+ leds = xf86Info.leds;
+
+ for (i = keyc->curKeySyms.minKeyCode, map = keyc->curKeySyms.map;
+ i < keyc->curKeySyms.maxKeyCode;
+ i++, map += keyc->curKeySyms.mapWidth)
+
+ switch(*map) {
+
+ case XK_Caps_Lock:
+ case XK_Shift_Lock:
+ if (leds & LED_CAP)
+ {
+ xf86InitialCaps = i;
+ xf86Info.capsLock = TRUE;
+ }
+ break;
+
+ case XK_Num_Lock:
+ if (leds & LED_NUM)
+ {
+ xf86InitialNum = i;
+ xf86Info.numLock = TRUE;
+ }
+ break;
+
+ case XK_Scroll_Lock:
+ case XK_Kana_Lock:
+ if (leds & LED_SCR)
+ {
+ xf86InitialScroll = i;
+ xf86Info.scrollLock = TRUE;
+ }
+ break;
+ }
+#endif /* INHERIT_LOCK_STATE */
+ xf86SetKbdLeds(leds);
+#endif /* LED_CAP */
+ (void)leds;
+
+ if (xf86Info.kbdDelay <= 375) rad = 0x00;
+ else if (xf86Info.kbdDelay <= 625) rad = 0x20;
+ else if (xf86Info.kbdDelay <= 875) rad = 0x40;
+ else rad = 0x60;
+
+ if (xf86Info.kbdRate <= 2) rad |= 0x1F;
+ else if (xf86Info.kbdRate >= 30) rad |= 0x00;
+ else rad |= ((58 / xf86Info.kbdRate) - 2);
+
+ xf86SetKbdRepeat(rad);
+ }
+}
+
+/*
+ * xf86KbdProc --
+ * Handle the initialization, etc. of a keyboard.
+ */
+
+int
+xf86KbdProc (pKeyboard, what)
+ DeviceIntPtr pKeyboard; /* Keyboard to manipulate */
+ int what; /* What to do to it */
+{
+ KeySymsRec keySyms;
+ CARD8 modMap[MAP_LENGTH];
+ int kbdFd;
+
+ switch (what) {
+
+ case DEVICE_INIT:
+ /*
+ * First open and find the current state of the keyboard.
+ */
+
+ xf86KbdInit();
+
+ xf86KbdGetMapping(&keySyms, modMap);
+
+
+#ifndef XKB
+ defaultKeyboardControl.leds = xf86GetKbdLeds();
+#else
+ defaultKeyboardControl.leds = 0;
+#endif
+
+ /*
+ * Perform final initialization of the system private keyboard
+ * structure and fill in various slots in the device record
+ * itself which couldn't be filled in before.
+ */
+
+ pKeyboard->public.on = FALSE;
+
+#ifdef XKB
+ if (noXkbExtension) {
+#endif
+ InitKeyboardDeviceStruct((DevicePtr)xf86Info.pKeyboard,
+ &keySyms,
+ modMap,
+ xf86KbdBell,
+ (KbdCtrlProcPtr)xf86KbdCtrl);
+#ifdef XKB
+ } else {
+ XkbComponentNamesRec names;
+ XkbDescPtr desc;
+ Bool foundTerminate = FALSE;
+ int keyc;
+ if (XkbInitialMap) {
+ if ((xf86Info.xkbkeymap = strchr(XkbInitialMap, '/')) != NULL)
+ xf86Info.xkbkeymap++;
+ else
+ xf86Info.xkbkeymap = XkbInitialMap;
+ }
+ if (xf86Info.xkbkeymap) {
+ names.keymap = xf86Info.xkbkeymap;
+ names.keycodes = NULL;
+ names.types = NULL;
+ names.compat = NULL;
+ names.symbols = NULL;
+ names.geometry = NULL;
+ } else {
+ names.keymap = NULL;
+ names.keycodes = xf86Info.xkbkeycodes;
+ names.types = xf86Info.xkbtypes;
+ names.compat = xf86Info.xkbcompat;
+ names.symbols = xf86Info.xkbsymbols;
+ names.geometry = xf86Info.xkbgeometry;
+ }
+ if ((xf86Info.xkbkeymap || xf86Info.xkbcomponents_specified)
+ && (xf86Info.xkbmodel == NULL || xf86Info.xkblayout == NULL)) {
+ xf86Info.xkbrules = NULL;
+ }
+ XkbSetRulesDflts(xf86Info.xkbrules, xf86Info.xkbmodel,
+ xf86Info.xkblayout, xf86Info.xkbvariant,
+ xf86Info.xkboptions);
+
+ XkbInitKeyboardDeviceStruct(pKeyboard,
+ &names,
+ &keySyms,
+ modMap,
+ xf86KbdBell,
+ (KbdCtrlProcPtr)xf86KbdCtrl);
+
+ /* Search keymap for Terminate action */
+ desc = pKeyboard->key->xkbInfo->desc;
+ for (keyc = desc->min_key_code; keyc <= desc->max_key_code; keyc++) {
+ int i;
+ for (i = 1; i <= XkbKeyNumActions(desc, keyc); i++) {
+ if (XkbKeyAction(desc, keyc, i)
+ && XkbKeyAction(desc, keyc, i)->type == XkbSA_Terminate) {
+ foundTerminate = TRUE;
+ goto searchdone;
+ }
+ }
+ }
+searchdone:
+ xf86Info.ActionKeyBindingsSet = foundTerminate;
+ if (!foundTerminate)
+ xf86Msg(X_INFO, "Server_Terminate keybinding not found\n");
+ }
+#endif
+
+ xf86InitKBD(TRUE);
+ break;
+
+ case DEVICE_ON:
+ /*
+ * Set the keyboard into "direct" mode and turn on
+ * event translation.
+ */
+
+ kbdFd = xf86KbdOn();
+ /*
+ * Discard any pending input after a VT switch to prevent the server
+ * passing on parts of the VT switch sequence.
+ */
+ sleep(1);
+#if defined(WSCONS_SUPPORT)
+ if (xf86Info.consType != WSCONS) {
+#endif
+ if (kbdFd != -1) {
+ char buf[16];
+ read(kbdFd, buf, 16);
+ }
+#if defined(WSCONS_SUPPORT)
+ }
+#endif
+
+#if !defined(__UNIXOS2__) /* Under EMX, keyboard cannot be select()'ed */
+ if (kbdFd != -1)
+ AddEnabledDevice(kbdFd);
+#endif /* __UNIXOS2__ */
+
+ pKeyboard->public.on = TRUE;
+ xf86InitKBD(FALSE);
+ break;
+
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ /*
+ * Restore original keyboard directness and translation.
+ */
+
+ kbdFd = xf86KbdOff();
+
+ if (kbdFd != -1)
+ RemoveEnabledDevice(kbdFd);
+
+ pKeyboard->public.on = FALSE;
+ break;
+
+ }
+ return (Success);
+}
+
+#if defined(DDXTIME) && !defined(QNX4)
+/*
+ * These are getting tossed in here until I can think of where
+ * they really belong
+ */
+#define HALFMONTH ((unsigned long) 1<<31)
+CARD32
+GetTimeInMillis()
+{
+ struct timeval tp;
+ register CARD32 val;
+ register INT32 diff;
+ static CARD32 oldval = 0;
+ static CARD32 time = 0;
+
+ gettimeofday(&tp, 0);
+ val = (tp.tv_sec * 1000) + (tp.tv_usec / 1000);
+ if (oldval) {
+ diff = val - oldval;
+ if (diff > 0)
+ time += diff;
+ }
+ oldval = val;
+
+ return time;
+}
+#endif /* DDXTIME && !QNX4 */
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Kbd.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Kbd.c
new file mode 100644
index 000000000..85f9e3406
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Kbd.c
@@ -0,0 +1,395 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Kbd.c,v 3.26 2003/08/24 17:36:53 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
+ * Copyright (c) 1992-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).
+ */
+
+/* $XConsortium: xf86Kbd.c /main/10 1996/02/21 17:38:32 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+#include "xf86Config.h"
+
+#include "xf86Keymap.h"
+
+#if defined(KDGKBTYPE) && \
+ !defined(Lynx) && \
+ !defined(__UNIXOS2__) && !defined(__mips__) && \
+ !defined(__arm32__) && !defined(__GNU__) && !defined(__QNX__)
+#define HAS_GETKBTYPE
+#endif
+#if defined(GIO_KEYMAP) && \
+ !defined(Lynx) && \
+ !defined(__UNIXOS2__) && !defined(__mips__) && \
+ !defined(__arm32__) && !defined(__GNU__) && !defined(DGUX) && \
+ !defined(__QNX__)
+#define HAS_GETKEYMAP
+
+#define KD_GET_ENTRY(i,n) \
+ eascii_to_x[((keymap.key[i].spcl << (n+1)) & 0x100) + keymap.key[i].map[n]]
+
+/*
+ * NOTE: Not all possible remappable symbols are remapped. There are two main
+ * reasons:
+ * a) The mapping between scancode and SYSV/386 - symboltable
+ * is inconsistent between different versions and has some
+ * BIG mistakes.
+ * b) In X-Windows there is a difference between numpad-keys
+ * and normal keys. SYSV/386 uses for both kinds of keys
+ * the same symbol.
+ *
+ * Thus only the alpha keypad and the function keys are translated.
+ * Also CapsLock, NumLock, ScrollLock, Shift, Control & Alt.
+ */
+
+static unsigned char remap[128] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0x69, 0x65, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+
+static KeySym eascii_to_x[512] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex,
+ XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla,
+ XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis,
+ XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring,
+ XK_Eacute, XK_ae, XK_AE, XK_ocircumflex,
+ XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave,
+ XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent,
+ XK_sterling, XK_yen, XK_paragraph, XK_section,
+ XK_aacute, XK_iacute, XK_oacute, XK_uacute,
+ XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine,
+ XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf,
+ XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi,
+ XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau,
+ XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta,
+ XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection,
+ XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal,
+ XK_topintegral, XK_botintegral, XK_division, XK_similarequal,
+ XK_degree, NoSymbol, NoSymbol, XK_radical,
+ XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol,
+
+ /*
+ * special marked entries (256 + x)
+ */
+
+ NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R,
+ XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L,
+ NoSymbol, XK_Control_L, XK_Alt_L, XK_Alt_R,
+ XK_Control_L, XK_Control_R, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_F1,
+ XK_F2, XK_F3, XK_F4, XK_F5,
+ XK_F6, XK_F7, XK_F8, XK_F9,
+ XK_F10, XK_F11, XK_F12, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ };
+
+#endif /* HAS_GETKEYMAP */
+
+/*
+ * LegalModifier --
+ * determine whether a key is a legal modifier key, i.e send a
+ * press/release sequence.
+ */
+
+/*ARGSUSED*/
+Bool
+LegalModifier(key, pDev)
+ unsigned int key;
+ DevicePtr pDev;
+{
+ return (TRUE);
+}
+
+
+
+/*
+ * xf86KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+void
+xf86KbdGetMapping (pKeySyms, pModMap)
+ KeySymsPtr pKeySyms;
+ CARD8 *pModMap;
+{
+ KeySym *k;
+#ifdef HAS_GETKEYMAP
+ keymap_t keymap;
+#endif
+ int i;
+ KeySym *pMap;
+
+#ifdef HAS_GETKBTYPE
+ char type;
+
+ xf86Info.kbdType =
+ ioctl(xf86Info.consoleFd, KDGKBTYPE, &type) != -1 ? type : KB_101;
+ if (xf86Info.kbdType == KB_84)
+ pMap = map84;
+ else
+ pMap = map;
+#else
+/* OS/2 sets the keyboard type during xf86OpenKbd */
+#ifndef __UNIXOS2__
+ xf86Info.kbdType = 0;
+#endif
+ pMap = map;
+#endif
+
+#ifdef HAS_GETKEYMAP
+ /*
+ * use the keymap, which can be gotten from our oringinal vt??.
+ * ( ttymap(1) !!!! )
+ */
+ if (ioctl(xf86Info.consoleFd, GIO_KEYMAP, &keymap) != -1) {
+ for (i = 0; i < keymap.n_keys && i < NUM_KEYCODES; i++)
+
+ if (remap[i]) {
+
+ k = pMap + (remap[i] << 2);
+
+ k[0] = KD_GET_ENTRY(i,0); /* non-shifed */
+ k[1] = KD_GET_ENTRY(i,1); /* shifted */
+ k[2] = KD_GET_ENTRY(i,4); /* alt */
+ k[3] = KD_GET_ENTRY(i,5); /* alt - shifted */
+
+ if (k[3] == k[2]) k[3] = NoSymbol;
+ if (k[2] == k[1]) k[2] = NoSymbol;
+ if (k[1] == k[0]) k[1] = NoSymbol;
+ if (k[0] == k[2] && k[1] == k[3]) k[2] = k[3] = NoSymbol;
+ }
+ }
+#endif
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = pMap, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+ pKeySyms->map = pMap;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdBSD.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdBSD.c
new file mode 100644
index 000000000..c1f6156e3
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdBSD.c
@@ -0,0 +1,1266 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdBSD.c,v 3.22 2003/10/07 22:00:52 herrb Exp $ */
+/*
+ * Derived from xf86Kbd.c by S_ren Schmidt (sos@login.dkuug.dk)
+ * which is Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ * and from xf86KbdCODrv.c by Holger Veit
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * Copyright (c) 1994-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).
+ */
+
+/* $XConsortium: xf86KbdBSD.c /main/6 1996/10/23 13:12:27 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+#include "xf86Keymap.h"
+
+#if (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)) && defined(GIO_KEYMAP)
+#define KD_GET_ENTRY(i,n) \
+ eascii_to_x[((keymap.key[i].spcl << (n+1)) & 0x100) + keymap.key[i].map[n]]
+
+static unsigned char remap[NUM_KEYCODES] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0x69, 0x65, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+
+/* This table assumes the ibm code page 437 coding for characters
+ * > 0x80. They are returned in this form by PCVT */
+static KeySym eascii_to_x[512] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex,
+ XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla,
+ XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis,
+ XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring,
+ XK_Eacute, XK_ae, XK_AE, XK_ocircumflex,
+ XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave,
+ XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent,
+ XK_sterling, XK_yen, XK_paragraph, XK_section,
+ XK_aacute, XK_iacute, XK_oacute, XK_uacute,
+ XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine,
+ XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf,
+ XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi,
+ XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau,
+ XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta,
+ XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection,
+ XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal,
+ XK_topintegral, XK_botintegral, XK_division, XK_similarequal,
+ XK_degree, NoSymbol, NoSymbol, XK_radical,
+ XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol,
+
+ /*
+ * special marked entries (256 + x)
+ */
+
+#if 1
+ /* This has been checked against what syscons actually does */
+ NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R,
+ XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L,
+ XK_ISO_Left_Tab,XK_Control_L, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_F1,
+ XK_F2, XK_F3, XK_F4, XK_F5,
+ XK_F6, XK_F7, XK_F8, XK_F9,
+ XK_F10, XK_F11, XK_F12, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Control_R, XK_Alt_R, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol
+#else
+ /* The old table, supposedly for pcvt. */
+ NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R,
+ XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L,
+ NoSymbol, XK_Control_L, XK_Alt_L, XK_Alt_R,
+ XK_Control_L, XK_Control_R, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_F1,
+ XK_F2, XK_F3, XK_F4, XK_F5,
+ XK_F6, XK_F7, XK_F8, XK_F9,
+ XK_F10, XK_F11, XK_F12, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol
+#endif
+ };
+
+#ifdef __OpenBSD__
+/* don't mark AltR and CtrlR for remapping, since they
+ * cannot be remapped by pccons */
+static unsigned char pccons_remap[128] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+
+/* This table assumes an iso8859_1 encoding for the characters
+ * > 80, as returned by pccons */
+static KeySym latin1_to_x[256] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_nobreakspace,XK_exclamdown, XK_cent, XK_sterling,
+ XK_currency, XK_yen, XK_brokenbar, XK_section,
+ XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft,
+ XK_notsign, XK_hyphen, XK_registered, XK_macron,
+ XK_degree, XK_plusminus, XK_twosuperior, XK_threesuperior,
+ XK_acute, XK_mu, XK_paragraph, XK_periodcentered,
+ XK_cedilla, XK_onesuperior, XK_masculine, XK_guillemotright,
+ XK_onequarter, XK_onehalf, XK_threequarters,XK_questiondown,
+ XK_Agrave, XK_Aacute, XK_Acircumflex, XK_Atilde,
+ XK_Adiaeresis, XK_Aring, XK_AE, XK_Ccedilla,
+ XK_Egrave, XK_Eacute, XK_Ecircumflex, XK_Ediaeresis,
+ XK_Igrave, XK_Iacute, XK_Icircumflex, XK_Idiaeresis,
+ XK_ETH, XK_Ntilde, XK_Ograve, XK_Oacute,
+ XK_Ocircumflex, XK_Otilde, XK_Odiaeresis, XK_multiply,
+ XK_Ooblique, XK_Ugrave, XK_Uacute, XK_Ucircumflex,
+ XK_Udiaeresis, XK_Yacute, XK_THORN, XK_ssharp,
+ XK_agrave, XK_aacute, XK_acircumflex, XK_atilde,
+ XK_adiaeresis, XK_aring, XK_ae, XK_ccedilla,
+ XK_egrave, XK_eacute, XK_ecircumflex, XK_ediaeresis,
+ XK_igrave, XK_iacute, XK_icircumflex, XK_idiaeresis,
+ XK_eth, XK_ntilde, XK_ograve, XK_oacute,
+ XK_ocircumflex, XK_otilde, XK_odiaeresis, XK_division,
+ XK_oslash, XK_ugrave, XK_uacute, XK_ucircumflex,
+ XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis
+ };
+#endif
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+/*
+ * LegalModifier --
+ * determine whether a key is a legal modifier key, i.e send a
+ * press/release sequence.
+ */
+
+/*ARGSUSED*/
+Bool
+LegalModifier(key, pDev)
+ unsigned int key;
+ DevicePtr pDev;
+{
+ return (TRUE);
+}
+
+/*
+ * xf86KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+void
+xf86KbdGetMapping (pKeySyms, pModMap)
+ KeySymsPtr pKeySyms;
+ CARD8 *pModMap;
+{
+ KeySym *k;
+ int i;
+
+#ifndef __bsdi__
+ switch (xf86Info.consType) {
+
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+#if defined(__OpenBSD__)
+ /*
+ * on OpenBSD, the pccons keymap is programmable, too
+ */
+ {
+ pccons_keymap_t keymap[KB_NUM_KEYS];
+ if (ioctl(xf86Info.consoleFd, CONSOLE_GET_KEYMAP, &keymap) != -1) {
+ for (i = 0; i < KB_NUM_KEYS; i++)
+ if (pccons_remap[i]) {
+ k = map + (pccons_remap[i] << 2);
+ switch (keymap[i].type) {
+ case KB_ASCII:
+ /* For ASCII keys, there is only one char in the keymap */
+ k[0] = latin1_to_x[(unsigned char)keymap[i].unshift[0]];
+ k[1] = latin1_to_x[(unsigned char)keymap[i].shift[0]];
+ k[2] = latin1_to_x[(unsigned char)keymap[i].altgr[0]];
+ k[3] = latin1_to_x[(unsigned char)keymap[i].shift_altgr[0]];
+ break;
+ case KB_SCROLL:
+ k[0] = XK_Scroll_Lock;
+ goto special;
+ case KB_NUM:
+ k[0] = XK_Num_Lock;
+ goto special;
+ case KB_CAPS:
+ k[0] = XK_Caps_Lock;
+ goto special;
+ case KB_SHIFT:
+ switch (keymap[i].unshift[0]) {
+ case 1:
+ /* left shift */
+ k[0] = XK_Shift_L;
+ break;
+ case 2:
+ /* right shift */
+ k[0] = XK_Shift_R;
+ break;
+ default:
+ k[0] = NoSymbol;
+ }
+ goto special;
+ case KB_CTL:
+ k[0] = XK_Control_L;
+ goto special;
+ case KB_ALT:
+ k[0] = XK_Alt_L;
+ goto special;
+ case KB_FUNC:
+ switch (keymap[i].unshift[2]) {
+ case 'M':
+ k[0] = XK_F1;
+ break;
+ case 'N':
+ k[0] = XK_F2;
+ break;
+ case 'O':
+ k[0] = XK_F3;
+ break;
+ case 'P':
+ k[0] = XK_F4;
+ break;
+ case 'Q':
+ k[0] = XK_F5;
+ break;
+ case 'R':
+ k[0] = XK_F6;
+ break;
+ case 'S':
+ k[0] = XK_F7;
+ break;
+ case 'T':
+ k[0] = XK_F8;
+ break;
+ case 'U':
+ k[0] = XK_F9;
+ break;
+ case 'V':
+ k[0] = XK_F10;
+ break;
+ case 'W':
+ k[0] = XK_F11;
+ break;
+ case 'X':
+ k[0] = XK_F12;
+ break;
+ default:
+ k[0] = NoSymbol;
+ break;
+ }
+ goto special;
+ default:
+ k[0] = NoSymbol;
+ special:
+ k[1] = k[2] = k[3] = NoSymbol;
+ }
+ }
+ } else {
+ ErrorF("Can't read pccons keymap\n");
+ }
+ }
+#endif /* __OpenBSD__ */
+ break;
+#endif
+
+/*
+ * XXX wscons has no GIO_KEYMAP
+ */
+#if (defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)) && defined(GIO_KEYMAP)
+ case SYSCONS:
+ case PCVT:
+ {
+ keymap_t keymap;
+
+ if (ioctl(xf86Info.consoleFd, GIO_KEYMAP, &keymap) != -1) {
+ for (i = 0; i < keymap.n_keys && i < NUM_KEYCODES; i++)
+ if (remap[i]) {
+ k = map + (remap[i] << 2);
+ k[0] = KD_GET_ENTRY(i,0); /* non-shifed */
+ k[1] = KD_GET_ENTRY(i,1); /* shifted */
+ k[2] = KD_GET_ENTRY(i,4); /* alt */
+ k[3] = KD_GET_ENTRY(i,5); /* alt - shifted */
+ if (k[3] == k[2]) k[3] = NoSymbol;
+ if (k[2] == k[1]) k[2] = NoSymbol;
+ if (k[1] == k[0]) k[1] = NoSymbol;
+ if (k[0] == k[2] && k[1] == k[3])
+ k[2] = k[3] = NoSymbol;
+ }
+ }
+ }
+ break;
+#endif /* SYSCONS || PCVT */
+
+ }
+#endif /* !bsdi */
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+ xf86Info.kbdType = 0;
+
+ pKeySyms->map = map;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+
+}
+
+#ifdef WSCONS_SUPPORT
+#include "atKeynames.h"
+
+static CARD8 wsUsbMap[] = {
+ /* 0 */ KEY_NOTUSED,
+ /* 1 */ KEY_NOTUSED,
+ /* 2 */ KEY_NOTUSED,
+ /* 3 */ KEY_NOTUSED,
+ /* 4 */ KEY_A,
+ /* 5 */ KEY_B,
+ /* 6 */ KEY_C,
+ /* 7 */ KEY_D,
+ /* 8 */ KEY_E,
+ /* 9 */ KEY_F,
+ /* 10 */ KEY_G,
+ /* 11 */ KEY_H,
+ /* 12 */ KEY_I,
+ /* 13 */ KEY_J,
+ /* 14 */ KEY_K,
+ /* 15 */ KEY_L,
+ /* 16 */ KEY_M,
+ /* 17 */ KEY_N,
+ /* 18 */ KEY_O,
+ /* 19 */ KEY_P,
+ /* 20 */ KEY_Q,
+ /* 21 */ KEY_R,
+ /* 22 */ KEY_S,
+ /* 23 */ KEY_T,
+ /* 24 */ KEY_U,
+ /* 25 */ KEY_V,
+ /* 26 */ KEY_W,
+ /* 27 */ KEY_X,
+ /* 28 */ KEY_Y,
+ /* 29 */ KEY_Z,
+ /* 30 */ KEY_1, /* 1 !*/
+ /* 31 */ KEY_2, /* 2 @ */
+ /* 32 */ KEY_3, /* 3 # */
+ /* 33 */ KEY_4, /* 4 $ */
+ /* 34 */ KEY_5, /* 5 % */
+ /* 35 */ KEY_6, /* 6 ^ */
+ /* 36 */ KEY_7, /* 7 & */
+ /* 37 */ KEY_8, /* 8 * */
+ /* 38 */ KEY_9, /* 9 ( */
+ /* 39 */ KEY_0, /* 0 ) */
+ /* 40 */ KEY_Enter, /* Return */
+ /* 41 */ KEY_Escape, /* Escape */
+ /* 42 */ KEY_BackSpace, /* Backspace Delete */
+ /* 43 */ KEY_Tab, /* Tab */
+ /* 44 */ KEY_Space, /* Space */
+ /* 45 */ KEY_Minus, /* - _ */
+ /* 46 */ KEY_Equal, /* = + */
+ /* 47 */ KEY_LBrace, /* [ { */
+ /* 48 */ KEY_RBrace, /* ] } */
+ /* 49 */ KEY_BSlash, /* \ | */
+ /* 50 */ KEY_BSlash2, /* \ _ # ~ on some keyboards */
+ /* 51 */ KEY_SemiColon, /* ; : */
+ /* 52 */ KEY_Quote, /* ' " */
+ /* 53 */ KEY_Tilde, /* ` ~ */
+ /* 54 */ KEY_Comma, /* , < */
+ /* 55 */ KEY_Period, /* . > */
+ /* 56 */ KEY_Slash, /* / ? */
+ /* 57 */ KEY_CapsLock, /* Caps Lock */
+ /* 58 */ KEY_F1, /* F1 */
+ /* 59 */ KEY_F2, /* F2 */
+ /* 60 */ KEY_F3, /* F3 */
+ /* 61 */ KEY_F4, /* F4 */
+ /* 62 */ KEY_F5, /* F5 */
+ /* 63 */ KEY_F6, /* F6 */
+ /* 64 */ KEY_F7, /* F7 */
+ /* 65 */ KEY_F8, /* F8 */
+ /* 66 */ KEY_F9, /* F9 */
+ /* 67 */ KEY_F10, /* F10 */
+ /* 68 */ KEY_F11, /* F11 */
+ /* 69 */ KEY_F12, /* F12 */
+ /* 70 */ KEY_Print, /* PrintScrn SysReq */
+ /* 71 */ KEY_ScrollLock, /* Scroll Lock */
+ /* 72 */ KEY_Pause, /* Pause Break */
+ /* 73 */ KEY_Insert, /* Insert XXX Help on some Mac Keyboards */
+ /* 74 */ KEY_Home, /* Home */
+ /* 75 */ KEY_PgUp, /* Page Up */
+ /* 76 */ KEY_Delete, /* Delete */
+ /* 77 */ KEY_End, /* End */
+ /* 78 */ KEY_PgDown, /* Page Down */
+ /* 79 */ KEY_Right, /* Right Arrow */
+ /* 80 */ KEY_Left, /* Left Arrow */
+ /* 81 */ KEY_Down, /* Down Arrow */
+ /* 82 */ KEY_Up, /* Up Arrow */
+ /* 83 */ KEY_NumLock, /* Num Lock */
+ /* 84 */ KEY_KP_Divide, /* Keypad / */
+ /* 85 */ KEY_KP_Multiply, /* Keypad * */
+ /* 86 */ KEY_KP_Minus, /* Keypad - */
+ /* 87 */ KEY_KP_Plus, /* Keypad + */
+ /* 88 */ KEY_KP_Enter, /* Keypad Enter */
+ /* 89 */ KEY_KP_1, /* Keypad 1 End */
+ /* 90 */ KEY_KP_2, /* Keypad 2 Down */
+ /* 91 */ KEY_KP_3, /* Keypad 3 Pg Down */
+ /* 92 */ KEY_KP_4, /* Keypad 4 Left */
+ /* 93 */ KEY_KP_5, /* Keypad 5 */
+ /* 94 */ KEY_KP_6, /* Keypad 6 */
+ /* 95 */ KEY_KP_7, /* Keypad 7 Home */
+ /* 96 */ KEY_KP_8, /* Keypad 8 Up */
+ /* 97 */ KEY_KP_9, /* KEypad 9 Pg Up */
+ /* 98 */ KEY_KP_0, /* Keypad 0 Ins */
+ /* 99 */ KEY_KP_Decimal, /* Keypad . Del */
+ /* 100 */ KEY_Less, /* < > on some keyboards */
+ /* 101 */ KEY_Menu, /* Menu */
+ /* 102 */ KEY_NOTUSED,
+ /* 103 */ KEY_KP_Equal, /* Keypad = on Mac keyboards */
+ /* 104 */ KEY_NOTUSED,
+ /* 105 */ KEY_NOTUSED,
+ /* 106 */ KEY_NOTUSED,
+ /* 107 */ KEY_NOTUSED,
+ /* 108 */ KEY_NOTUSED,
+ /* 109 */ KEY_NOTUSED,
+ /* 110 */ KEY_NOTUSED,
+ /* 111 */ KEY_NOTUSED,
+ /* 112 */ KEY_NOTUSED,
+ /* 113 */ KEY_NOTUSED,
+ /* 114 */ KEY_NOTUSED,
+ /* 115 */ KEY_NOTUSED,
+ /* 116 */ KEY_NOTUSED,
+ /* 117 */ KEY_NOTUSED,
+ /* 118 */ KEY_NOTUSED,
+ /* 119 */ KEY_NOTUSED,
+ /* 120 */ KEY_NOTUSED,
+ /* 121 */ KEY_NOTUSED,
+ /* 122 */ KEY_NOTUSED,
+ /* 123 */ KEY_NOTUSED,
+ /* 124 */ KEY_NOTUSED,
+ /* 125 */ KEY_NOTUSED,
+ /* 126 */ KEY_NOTUSED,
+ /* 127 */ KEY_NOTUSED,
+ /* 128 */ KEY_NOTUSED,
+ /* 129 */ KEY_NOTUSED,
+ /* 130 */ KEY_NOTUSED,
+ /* 131 */ KEY_NOTUSED,
+ /* 132 */ KEY_NOTUSED,
+ /* 133 */ KEY_NOTUSED,
+ /* 134 */ KEY_NOTUSED,
+ /* 135 */ KEY_NOTUSED,
+ /* 136 */ KEY_NOTUSED,
+ /* 137 */ KEY_NOTUSED,
+ /* 138 */ KEY_NOTUSED,
+ /* 139 */ KEY_NOTUSED,
+ /* 140 */ KEY_NOTUSED,
+ /* 141 */ KEY_NOTUSED,
+ /* 142 */ KEY_NOTUSED,
+ /* 143 */ KEY_NOTUSED,
+ /* 144 */ KEY_NOTUSED,
+ /* 145 */ KEY_NOTUSED,
+ /* 146 */ KEY_NOTUSED,
+ /* 147 */ KEY_NOTUSED,
+ /* 148 */ KEY_NOTUSED,
+ /* 149 */ KEY_NOTUSED,
+ /* 150 */ KEY_NOTUSED,
+ /* 151 */ KEY_NOTUSED,
+ /* 152 */ KEY_NOTUSED,
+ /* 153 */ KEY_NOTUSED,
+ /* 154 */ KEY_NOTUSED,
+ /* 155 */ KEY_NOTUSED,
+ /* 156 */ KEY_NOTUSED,
+ /* 157 */ KEY_NOTUSED,
+ /* 158 */ KEY_NOTUSED,
+ /* 159 */ KEY_NOTUSED,
+ /* 160 */ KEY_NOTUSED,
+ /* 161 */ KEY_NOTUSED,
+ /* 162 */ KEY_NOTUSED,
+ /* 163 */ KEY_NOTUSED,
+ /* 164 */ KEY_NOTUSED,
+ /* 165 */ KEY_NOTUSED,
+ /* 166 */ KEY_NOTUSED,
+ /* 167 */ KEY_NOTUSED,
+ /* 168 */ KEY_NOTUSED,
+ /* 169 */ KEY_NOTUSED,
+ /* 170 */ KEY_NOTUSED,
+ /* 171 */ KEY_NOTUSED,
+ /* 172 */ KEY_NOTUSED,
+ /* 173 */ KEY_NOTUSED,
+ /* 174 */ KEY_NOTUSED,
+ /* 175 */ KEY_NOTUSED,
+ /* 176 */ KEY_NOTUSED,
+ /* 177 */ KEY_NOTUSED,
+ /* 178 */ KEY_NOTUSED,
+ /* 179 */ KEY_NOTUSED,
+ /* 180 */ KEY_NOTUSED,
+ /* 181 */ KEY_NOTUSED,
+ /* 182 */ KEY_NOTUSED,
+ /* 183 */ KEY_NOTUSED,
+ /* 184 */ KEY_NOTUSED,
+ /* 185 */ KEY_NOTUSED,
+ /* 186 */ KEY_NOTUSED,
+ /* 187 */ KEY_NOTUSED,
+ /* 188 */ KEY_NOTUSED,
+ /* 189 */ KEY_NOTUSED,
+ /* 190 */ KEY_NOTUSED,
+ /* 191 */ KEY_NOTUSED,
+ /* 192 */ KEY_NOTUSED,
+ /* 193 */ KEY_NOTUSED,
+ /* 194 */ KEY_NOTUSED,
+ /* 195 */ KEY_NOTUSED,
+ /* 196 */ KEY_NOTUSED,
+ /* 197 */ KEY_NOTUSED,
+ /* 198 */ KEY_NOTUSED,
+ /* 199 */ KEY_NOTUSED,
+ /* 200 */ KEY_NOTUSED,
+ /* 201 */ KEY_NOTUSED,
+ /* 202 */ KEY_NOTUSED,
+ /* 203 */ KEY_NOTUSED,
+ /* 204 */ KEY_NOTUSED,
+ /* 205 */ KEY_NOTUSED,
+ /* 206 */ KEY_NOTUSED,
+ /* 207 */ KEY_NOTUSED,
+ /* 208 */ KEY_NOTUSED,
+ /* 209 */ KEY_NOTUSED,
+ /* 210 */ KEY_NOTUSED,
+ /* 211 */ KEY_NOTUSED,
+ /* 212 */ KEY_NOTUSED,
+ /* 213 */ KEY_NOTUSED,
+ /* 214 */ KEY_NOTUSED,
+ /* 215 */ KEY_NOTUSED,
+ /* 216 */ KEY_NOTUSED,
+ /* 217 */ KEY_NOTUSED,
+ /* 218 */ KEY_NOTUSED,
+ /* 219 */ KEY_NOTUSED,
+ /* 220 */ KEY_NOTUSED,
+ /* 221 */ KEY_NOTUSED,
+ /* 222 */ KEY_NOTUSED,
+ /* 223 */ KEY_NOTUSED,
+ /* 224 */ KEY_LCtrl, /* Left Control */
+ /* 225 */ KEY_ShiftL, /* Left Shift */
+ /* 226 */ KEY_Alt, /* Left Alt */
+ /* 227 */ KEY_LMeta, /* Left Meta */
+ /* 228 */ KEY_RCtrl, /* Right Control */
+ /* 229 */ KEY_ShiftR, /* Right Shift */
+ /* 230 */ KEY_AltLang, /* Right Alt, AKA AltGr */
+ /* 231 */ KEY_LMeta, /* Right Meta XXX */
+};
+
+#define WS_USB_MAP_SIZE (sizeof(wsUsbMap)/sizeof(unsigned char))
+
+/* Map for adb keyboards */
+static CARD8 wsAdbMap[] = {
+ /* 0 */ KEY_A,
+ /* 1 */ KEY_S,
+ /* 2 */ KEY_D,
+ /* 3 */ KEY_F,
+ /* 4 */ KEY_H,
+ /* 5 */ KEY_G,
+ /* 6 */ KEY_Z,
+ /* 7 */ KEY_X,
+ /* 8 */ KEY_C,
+ /* 9 */ KEY_V,
+ /* 10 */ KEY_UNKNOWN, /* @ # on french keyboards */
+ /* 11 */ KEY_B,
+ /* 12 */ KEY_Q,
+ /* 13 */ KEY_W,
+ /* 14 */ KEY_E,
+ /* 15 */ KEY_R,
+ /* 16 */ KEY_Y,
+ /* 17 */ KEY_T,
+ /* 18 */ KEY_1,
+ /* 19 */ KEY_2,
+ /* 20 */ KEY_3,
+ /* 21 */ KEY_4,
+ /* 22 */ KEY_6,
+ /* 23 */ KEY_5,
+ /* 24 */ KEY_Equal,
+ /* 25 */ KEY_9,
+ /* 26 */ KEY_7,
+ /* 27 */ KEY_Minus,
+ /* 28 */ KEY_8,
+ /* 29 */ KEY_0,
+ /* 30 */ KEY_RBrace,
+ /* 31 */ KEY_O,
+ /* 32 */ KEY_U,
+ /* 33 */ KEY_LBrace,
+ /* 34 */ KEY_I,
+ /* 35 */ KEY_P,
+ /* 36 */ KEY_Enter,
+ /* 37 */ KEY_L,
+ /* 38 */ KEY_J,
+ /* 39 */ KEY_Quote,
+ /* 40 */ KEY_K,
+ /* 41 */ KEY_SemiColon,
+ /* 42 */ KEY_BSlash,
+ /* 43 */ KEY_Comma,
+ /* 44 */ KEY_Slash,
+ /* 45 */ KEY_N,
+ /* 46 */ KEY_M,
+ /* 47 */ KEY_Period,
+ /* 48 */ KEY_Tab,
+ /* 49 */ KEY_Space,
+ /* 50 */ KEY_Tilde,
+ /* 51 */ KEY_Delete,
+ /* 52 */ KEY_AltLang,
+ /* 53 */ KEY_Escape,
+ /* 54 */ KEY_LCtrl,
+ /* 55 */ KEY_Alt,
+ /* 56 */ KEY_ShiftL,
+ /* 57 */ KEY_CapsLock,
+ /* 58 */ KEY_LMeta,
+ /* 59 */ KEY_Left,
+ /* 60 */ KEY_Right,
+ /* 61 */ KEY_Down,
+ /* 62 */ KEY_Up,
+ /* 63 */ KEY_UNKNOWN, /* Fn */
+ /* 64 */ KEY_NOTUSED,
+ /* 65 */ KEY_KP_Decimal,
+ /* 66 */ KEY_NOTUSED,
+ /* 67 */ KEY_KP_Multiply,
+ /* 68 */ KEY_NOTUSED,
+ /* 69 */ KEY_KP_Plus,
+ /* 70 */ KEY_NOTUSED,
+ /* 71 */ KEY_UNKNOWN, /* Clear */
+ /* 72 */ KEY_NOTUSED,
+ /* 73 */ KEY_NOTUSED,
+ /* 74 */ KEY_NOTUSED,
+ /* 75 */ KEY_KP_Divide,
+ /* 76 */ KEY_KP_Enter,
+ /* 77 */ KEY_NOTUSED,
+ /* 78 */ KEY_KP_Minus,
+ /* 79 */ KEY_NOTUSED,
+ /* 80 */ KEY_NOTUSED,
+ /* 81 */ KEY_KP_Equal, /* Keypad = */
+ /* 82 */ KEY_KP_0,
+ /* 83 */ KEY_KP_1,
+ /* 84 */ KEY_KP_2,
+ /* 85 */ KEY_KP_3,
+ /* 86 */ KEY_KP_4,
+ /* 87 */ KEY_KP_5,
+ /* 88 */ KEY_KP_6,
+ /* 89 */ KEY_KP_7,
+ /* 90 */ KEY_NOTUSED,
+ /* 91 */ KEY_KP_8,
+ /* 92 */ KEY_KP_9,
+ /* 93 */ KEY_NOTUSED,
+ /* 94 */ KEY_NOTUSED,
+ /* 95 */ KEY_UNKNOWN, /* Keypad , */
+ /* 96 */ KEY_F5,
+ /* 97 */ KEY_F6,
+ /* 98 */ KEY_F7,
+ /* 99 */ KEY_F3,
+ /* 100 */ KEY_F8,
+ /* 101 */ KEY_F9,
+ /* 102 */ KEY_NOTUSED,
+ /* 103 */ KEY_F11,
+ /* 104 */ KEY_NOTUSED,
+ /* 105 */ KEY_NOTUSED,
+ /* 106 */ KEY_KP_Enter,
+ /* 107 */ KEY_NOTUSED,
+ /* 108 */ KEY_NOTUSED,
+ /* 109 */ KEY_F10,
+ /* 110 */ KEY_NOTUSED,
+ /* 111 */ KEY_F12,
+ /* 112 */ KEY_NOTUSED,
+ /* 113 */ KEY_NOTUSED,
+ /* 114 */ KEY_NOTUSED,
+ /* 115 */ KEY_Home,
+ /* 116 */ KEY_PgUp,
+ /* 117 */ KEY_NOTUSED,
+ /* 118 */ KEY_F4,
+ /* 119 */ KEY_End,
+ /* 120 */ KEY_F2,
+ /* 121 */ KEY_PgDown,
+ /* 122 */ KEY_F1,
+ /* 123 */ KEY_NOTUSED,
+ /* 124 */ KEY_NOTUSED,
+ /* 125 */ KEY_NOTUSED,
+ /* 126 */ KEY_NOTUSED,
+ /* 127 */ KEY_NOTUSED,
+ /* 128 */ KEY_NOTUSED,
+ /* 129 */ KEY_NOTUSED,
+ /* 130 */ KEY_NOTUSED,
+ /* 131 */ KEY_NOTUSED,
+ /* 132 */ KEY_NOTUSED,
+ /* 133 */ KEY_NOTUSED,
+ /* 134 */ KEY_NOTUSED,
+ /* 135 */ KEY_NOTUSED,
+ /* 136 */ KEY_NOTUSED,
+ /* 137 */ KEY_NOTUSED,
+ /* 138 */ KEY_NOTUSED,
+ /* 139 */ KEY_NOTUSED,
+ /* 140 */ KEY_NOTUSED,
+ /* 141 */ KEY_NOTUSED,
+ /* 142 */ KEY_NOTUSED,
+ /* 143 */ KEY_NOTUSED,
+ /* 144 */ KEY_NOTUSED,
+ /* 145 */ KEY_NOTUSED,
+ /* 146 */ KEY_NOTUSED,
+ /* 147 */ KEY_NOTUSED,
+ /* 148 */ KEY_NOTUSED,
+ /* 149 */ KEY_NOTUSED,
+ /* 150 */ KEY_NOTUSED,
+ /* 151 */ KEY_NOTUSED,
+ /* 152 */ KEY_NOTUSED,
+ /* 153 */ KEY_NOTUSED,
+ /* 154 */ KEY_NOTUSED,
+ /* 155 */ KEY_NOTUSED,
+ /* 156 */ KEY_NOTUSED,
+ /* 157 */ KEY_NOTUSED,
+ /* 158 */ KEY_NOTUSED,
+ /* 159 */ KEY_NOTUSED,
+ /* 160 */ KEY_NOTUSED,
+ /* 161 */ KEY_NOTUSED,
+ /* 162 */ KEY_NOTUSED,
+ /* 163 */ KEY_NOTUSED,
+ /* 164 */ KEY_NOTUSED,
+ /* 165 */ KEY_NOTUSED,
+ /* 166 */ KEY_NOTUSED,
+ /* 167 */ KEY_NOTUSED,
+ /* 168 */ KEY_NOTUSED,
+ /* 169 */ KEY_NOTUSED,
+ /* 170 */ KEY_NOTUSED,
+ /* 171 */ KEY_NOTUSED,
+ /* 172 */ KEY_NOTUSED,
+ /* 173 */ KEY_NOTUSED,
+ /* 174 */ KEY_NOTUSED,
+ /* 175 */ KEY_NOTUSED,
+ /* 176 */ KEY_NOTUSED,
+ /* 177 */ KEY_NOTUSED,
+ /* 178 */ KEY_NOTUSED,
+ /* 179 */ KEY_NOTUSED,
+ /* 180 */ KEY_NOTUSED,
+ /* 181 */ KEY_NOTUSED,
+ /* 182 */ KEY_NOTUSED,
+ /* 183 */ KEY_NOTUSED,
+ /* 184 */ KEY_NOTUSED,
+ /* 185 */ KEY_NOTUSED,
+ /* 186 */ KEY_NOTUSED,
+ /* 187 */ KEY_NOTUSED,
+ /* 188 */ KEY_NOTUSED,
+ /* 189 */ KEY_NOTUSED,
+ /* 190 */ KEY_NOTUSED,
+ /* 191 */ KEY_NOTUSED,
+ /* 192 */ KEY_NOTUSED,
+ /* 193 */ KEY_NOTUSED,
+ /* 194 */ KEY_NOTUSED,
+ /* 195 */ KEY_NOTUSED,
+ /* 196 */ KEY_NOTUSED,
+ /* 197 */ KEY_NOTUSED,
+ /* 198 */ KEY_NOTUSED,
+ /* 199 */ KEY_NOTUSED,
+ /* 200 */ KEY_NOTUSED,
+ /* 201 */ KEY_NOTUSED,
+ /* 202 */ KEY_NOTUSED,
+ /* 203 */ KEY_NOTUSED,
+ /* 204 */ KEY_NOTUSED,
+ /* 205 */ KEY_NOTUSED,
+ /* 206 */ KEY_NOTUSED,
+ /* 207 */ KEY_NOTUSED,
+ /* 208 */ KEY_NOTUSED,
+ /* 209 */ KEY_NOTUSED,
+ /* 210 */ KEY_NOTUSED,
+ /* 211 */ KEY_NOTUSED,
+ /* 212 */ KEY_NOTUSED,
+ /* 213 */ KEY_NOTUSED,
+ /* 214 */ KEY_NOTUSED,
+ /* 215 */ KEY_NOTUSED,
+ /* 216 */ KEY_NOTUSED,
+ /* 217 */ KEY_NOTUSED,
+ /* 218 */ KEY_NOTUSED,
+ /* 219 */ KEY_NOTUSED,
+ /* 220 */ KEY_NOTUSED,
+ /* 221 */ KEY_NOTUSED,
+ /* 222 */ KEY_NOTUSED,
+ /* 223 */ KEY_NOTUSED,
+};
+
+#define WS_ADB_MAP_SIZE (sizeof(wsAdbMap)/sizeof(unsigned char))
+
+static CARD8 wsSunMap[] = {
+ /* 0x00 */ KEY_NOTUSED,
+ /* 0x01 */ KEY_NOTUSED, /* stop */
+ /* 0x02 */ KEY_NOTUSED, /* BrightnessDown / S-VolumeDown */
+ /* 0x03 */ KEY_NOTUSED, /* again */
+ /* 0x04 */ KEY_NOTUSED, /* BridgtnessUp / S-VolumeUp */
+ /* 0x05 */ KEY_F1,
+ /* 0x06 */ KEY_F2,
+ /* 0x07 */ KEY_F10,
+ /* 0x08 */ KEY_F3,
+ /* 0x09 */ KEY_F11,
+ /* 0x0a */ KEY_F4,
+ /* 0x0b */ KEY_F12,
+ /* 0x0c */ KEY_F5,
+ /* 0x0d */ KEY_AltLang,
+ /* 0x0e */ KEY_F6,
+ /* 0x0f */ KEY_NOTUSED,
+ /* 0x10 */ KEY_F7,
+ /* 0x11 */ KEY_F8,
+ /* 0x12 */ KEY_F9,
+ /* 0x13 */ KEY_Alt,
+ /* 0x14 */ KEY_Up,
+ /* 0x15 */ KEY_Pause,
+ /* 0x16 */ KEY_Print,
+ /* 0x17 */ KEY_NOTUSED, /* props */
+ /* 0x18 */ KEY_Left,
+ /* 0x19 */ KEY_ScrollLock,
+ /* 0x1a */ KEY_NOTUSED, /* undo */
+ /* 0x1b */ KEY_Down,
+ /* 0x1c */ KEY_Right,
+ /* 0x1d */ KEY_Escape,
+ /* 0x1e */ KEY_1,
+ /* 0x1f */ KEY_2,
+ /* 0x20 */ KEY_3,
+ /* 0x21 */ KEY_4,
+ /* 0x22 */ KEY_5,
+ /* 0x23 */ KEY_6,
+ /* 0x24 */ KEY_7,
+ /* 0x25 */ KEY_8,
+ /* 0x26 */ KEY_9,
+ /* 0x27 */ KEY_0,
+ /* 0x28 */ KEY_Minus,
+ /* 0x29 */ KEY_Equal,
+ /* 0x2a */ KEY_Tilde,
+ /* 0x2b */ KEY_BackSpace,
+ /* 0x2c */ KEY_Insert,
+ /* 0x2d */ KEY_KP_Equal,
+ /* 0x2e */ KEY_KP_Divide,
+ /* 0x2f */ KEY_KP_Multiply,
+ /* 0x30 */ KEY_NOTUSED,
+ /* 0x31 */ KEY_NOTUSED, /* front */
+ /* 0x32 */ KEY_KP_Decimal,
+ /* 0x33 */ KEY_NOTUSED, /* copy */
+ /* 0x34 */ KEY_Home,
+ /* 0x35 */ KEY_Tab,
+ /* 0x36 */ KEY_Q,
+ /* 0x37 */ KEY_W,
+ /* 0x38 */ KEY_E,
+ /* 0x39 */ KEY_R,
+ /* 0x3a */ KEY_T,
+ /* 0x3b */ KEY_Y,
+ /* 0x3c */ KEY_U,
+ /* 0x3d */ KEY_I,
+ /* 0x3e */ KEY_O,
+ /* 0x3f */ KEY_P,
+ /* 0x40 */ KEY_LBrace,
+ /* 0x41 */ KEY_RBrace,
+ /* 0x42 */ KEY_Delete,
+ /* 0x43 */ KEY_NOTUSED, /* compose */
+ /* 0x44 */ KEY_KP_7,
+ /* 0x45 */ KEY_KP_8,
+ /* 0x46 */ KEY_KP_9,
+ /* 0x47 */ KEY_KP_Minus,
+ /* 0x48 */ KEY_NOTUSED, /* open */
+ /* 0x49 */ KEY_NOTUSED, /* paste */
+ /* 0x4a */ KEY_End,
+ /* 0x4b */ KEY_NOTUSED,
+ /* 0x4c */ KEY_LCtrl,
+ /* 0x4d */ KEY_A,
+ /* 0x4e */ KEY_S,
+ /* 0x4f */ KEY_D,
+ /* 0x50 */ KEY_F,
+ /* 0x51 */ KEY_G,
+ /* 0x52 */ KEY_H,
+ /* 0x53 */ KEY_J,
+ /* 0x54 */ KEY_K,
+ /* 0x55 */ KEY_L,
+ /* 0x56 */ KEY_SemiColon,
+ /* 0x57 */ KEY_Quote,
+ /* 0x58 */ KEY_BSlash,
+ /* 0x59 */ KEY_Enter,
+ /* 0x5a */ KEY_KP_Enter,
+ /* 0x5b */ KEY_KP_4,
+ /* 0x5c */ KEY_KP_5,
+ /* 0x5d */ KEY_KP_6,
+ /* 0x5e */ KEY_KP_0,
+ /* 0x5f */ KEY_NOTUSED, /* find */
+ /* 0x60 */ KEY_PgUp,
+ /* 0x61 */ KEY_NOTUSED, /* cut */
+ /* 0x62 */ KEY_NumLock,
+ /* 0x63 */ KEY_ShiftL,
+ /* 0x64 */ KEY_Z,
+ /* 0x65 */ KEY_X,
+ /* 0x66 */ KEY_C,
+ /* 0x67 */ KEY_V,
+ /* 0x68 */ KEY_B,
+ /* 0x69 */ KEY_N,
+ /* 0x6a */ KEY_M,
+ /* 0x6b */ KEY_Comma,
+ /* 0x6c */ KEY_Period,
+ /* 0x6d */ KEY_Slash,
+ /* 0x6e */ KEY_ShiftR,
+ /* 0x6f */ KEY_NOTUSED, /* linefeed */
+ /* 0x70 */ KEY_KP_1,
+ /* 0x71 */ KEY_KP_2,
+ /* 0x72 */ KEY_KP_3,
+ /* 0x73 */ KEY_NOTUSED,
+ /* 0x74 */ KEY_NOTUSED,
+ /* 0x75 */ KEY_NOTUSED,
+ /* 0x76 */ KEY_NOTUSED, /* help */
+ /* 0x77 */ KEY_CapsLock,
+ /* 0x78 */ KEY_LMeta,
+ /* 0x79 */ KEY_Space,
+ /* 0x7a */ KEY_RMeta,
+ /* 0x7b */ KEY_PgDown,
+ /* 0x7c */ KEY_NOTUSED,
+ /* 0x7d */ KEY_KP_Plus,
+ /* 0x7e */ KEY_NOTUSED,
+ /* 0x7f */ KEY_NOTUSED
+};
+
+#define WS_SUN_MAP_SIZE (sizeof(wsSunMap)/sizeof(unsigned char))
+
+/*
+ * Translate raw wskbd keyboard event values to XFree86 standard keycodes
+ * (based on the AT keyboard scan codes using the tables above
+ */
+int
+WSKbdToKeycode(int keycode)
+{
+ switch (xf86Info.wsKbdType) {
+ case WSKBD_TYPE_PC_XT:
+ case WSKBD_TYPE_PC_AT:
+ /* No translation needed */
+ return keycode;
+ case WSKBD_TYPE_USB:
+ if (keycode < 0 || keycode >= WS_USB_MAP_SIZE)
+ return KEY_UNKNOWN;
+ else
+ return wsUsbMap[keycode];
+#ifdef WSKBD_TYPE_ADB
+ case WSKBD_TYPE_ADB:
+ if (keycode < 0 || keycode >= WS_ADB_MAP_SIZE)
+ return KEY_UNKNOWN;
+ else
+ return wsAdbMap[keycode];
+#endif
+#ifdef WSKBD_TYPE_SUN
+ case WSKBD_TYPE_SUN:
+#ifdef WSKBD_TYPE_SUN5
+ case WSKBD_TYPE_SUN5:
+#endif
+ if (keycode < 0 || keycode >= WS_SUN_MAP_SIZE)
+ return KEY_UNKNOWN;
+ else
+ return wsSunMap[keycode];
+#endif
+ default:
+ ErrorF("Unknown wskbd type %d\n", xf86Info.wsKbdType);
+ return KEY_UNKNOWN;
+ }
+}
+
+#endif /* WSCONS_SUPPORT */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdLnx.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdLnx.c
new file mode 100644
index 000000000..c5361f5d9
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdLnx.c
@@ -0,0 +1,651 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdLnx.c,v 3.17 2003/08/24 17:36:53 dawes Exp $ */
+/*
+ * Linux version of keymapping setup. The kernel (since 0.99.14) has support
+ * for fully remapping the keyboard, but there are some differences between
+ * the Linux map and the SVR4 map (esp. in the extended keycodes). We also
+ * remove the restriction on what keycodes can be remapped.
+ * Orest Zborowski.
+ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
+ * Copyright (c) 1994-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).
+ */
+
+/* $XConsortium: xf86KbdLnx.c /main/7 1996/10/19 17:59:00 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+
+#include "xf86Keymap.h"
+
+/*
+ * LegalModifier --
+ * determine whether a key is a legal modifier key, i.e send a
+ * press/release sequence.
+ */
+
+/*ARGSUSED*/
+Bool
+LegalModifier(unsigned int key, DevicePtr pDev)
+{
+ return (TRUE);
+}
+
+/*
+ * xf86KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+static void readKernelMapping(KeySymsPtr pKeySyms, CARD8 *pModMap);
+
+void
+xf86KbdGetMapping (KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ KeySym *k;
+ char type;
+ int i;
+
+ readKernelMapping(pKeySyms, pModMap);
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+ xf86Info.kbdType =
+ ioctl(xf86Info.consoleFd, KDGKBTYPE, &type) != -1 ? type : KB_101;
+
+ pKeySyms->map = map;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+}
+
+#include <linux/keyboard.h>
+
+static KeySym linux_to_x[256] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_BackSpace,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_nobreakspace,XK_exclamdown, XK_cent, XK_sterling,
+ XK_currency, XK_yen, XK_brokenbar, XK_section,
+ XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft,
+ XK_notsign, XK_hyphen, XK_registered, XK_macron,
+ XK_degree, XK_plusminus, XK_twosuperior, XK_threesuperior,
+ XK_acute, XK_mu, XK_paragraph, XK_periodcentered,
+ XK_cedilla, XK_onesuperior, XK_masculine, XK_guillemotright,
+ XK_onequarter, XK_onehalf, XK_threequarters,XK_questiondown,
+ XK_Agrave, XK_Aacute, XK_Acircumflex, XK_Atilde,
+ XK_Adiaeresis, XK_Aring, XK_AE, XK_Ccedilla,
+ XK_Egrave, XK_Eacute, XK_Ecircumflex, XK_Ediaeresis,
+ XK_Igrave, XK_Iacute, XK_Icircumflex, XK_Idiaeresis,
+ XK_ETH, XK_Ntilde, XK_Ograve, XK_Oacute,
+ XK_Ocircumflex, XK_Otilde, XK_Odiaeresis, XK_multiply,
+ XK_Ooblique, XK_Ugrave, XK_Uacute, XK_Ucircumflex,
+ XK_Udiaeresis, XK_Yacute, XK_THORN, XK_ssharp,
+ XK_agrave, XK_aacute, XK_acircumflex, XK_atilde,
+ XK_adiaeresis, XK_aring, XK_ae, XK_ccedilla,
+ XK_egrave, XK_eacute, XK_ecircumflex, XK_ediaeresis,
+ XK_igrave, XK_iacute, XK_icircumflex, XK_idiaeresis,
+ XK_eth, XK_ntilde, XK_ograve, XK_oacute,
+ XK_ocircumflex, XK_otilde, XK_odiaeresis, XK_division,
+ XK_oslash, XK_ugrave, XK_uacute, XK_ucircumflex,
+ XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis
+};
+
+/*
+ * Maps the AT keycodes to Linux keycodes
+ */
+static unsigned char at2lnx[NUM_KEYCODES] =
+{
+ 0x01, /* KEY_Escape */ 0x02, /* KEY_1 */
+ 0x03, /* KEY_2 */ 0x04, /* KEY_3 */
+ 0x05, /* KEY_4 */ 0x06, /* KEY_5 */
+ 0x07, /* KEY_6 */ 0x08, /* KEY_7 */
+ 0x09, /* KEY_8 */ 0x0a, /* KEY_9 */
+ 0x0b, /* KEY_0 */ 0x0c, /* KEY_Minus */
+ 0x0d, /* KEY_Equal */ 0x0e, /* KEY_BackSpace */
+ 0x0f, /* KEY_Tab */ 0x10, /* KEY_Q */
+ 0x11, /* KEY_W */ 0x12, /* KEY_E */
+ 0x13, /* KEY_R */ 0x14, /* KEY_T */
+ 0x15, /* KEY_Y */ 0x16, /* KEY_U */
+ 0x17, /* KEY_I */ 0x18, /* KEY_O */
+ 0x19, /* KEY_P */ 0x1a, /* KEY_LBrace */
+ 0x1b, /* KEY_RBrace */ 0x1c, /* KEY_Enter */
+ 0x1d, /* KEY_LCtrl */ 0x1e, /* KEY_A */
+ 0x1f, /* KEY_S */ 0x20, /* KEY_D */
+ 0x21, /* KEY_F */ 0x22, /* KEY_G */
+ 0x23, /* KEY_H */ 0x24, /* KEY_J */
+ 0x25, /* KEY_K */ 0x26, /* KEY_L */
+ 0x27, /* KEY_SemiColon */ 0x28, /* KEY_Quote */
+ 0x29, /* KEY_Tilde */ 0x2a, /* KEY_ShiftL */
+ 0x2b, /* KEY_BSlash */ 0x2c, /* KEY_Z */
+ 0x2d, /* KEY_X */ 0x2e, /* KEY_C */
+ 0x2f, /* KEY_V */ 0x30, /* KEY_B */
+ 0x31, /* KEY_N */ 0x32, /* KEY_M */
+ 0x33, /* KEY_Comma */ 0x34, /* KEY_Period */
+ 0x35, /* KEY_Slash */ 0x36, /* KEY_ShiftR */
+ 0x37, /* KEY_KP_Multiply */ 0x38, /* KEY_Alt */
+ 0x39, /* KEY_Space */ 0x3a, /* KEY_CapsLock */
+ 0x3b, /* KEY_F1 */ 0x3c, /* KEY_F2 */
+ 0x3d, /* KEY_F3 */ 0x3e, /* KEY_F4 */
+ 0x3f, /* KEY_F5 */ 0x40, /* KEY_F6 */
+ 0x41, /* KEY_F7 */ 0x42, /* KEY_F8 */
+ 0x43, /* KEY_F9 */ 0x44, /* KEY_F10 */
+ 0x45, /* KEY_NumLock */ 0x46, /* KEY_ScrollLock */
+ 0x47, /* KEY_KP_7 */ 0x48, /* KEY_KP_8 */
+ 0x49, /* KEY_KP_9 */ 0x4a, /* KEY_KP_Minus */
+ 0x4b, /* KEY_KP_4 */ 0x4c, /* KEY_KP_5 */
+ 0x4d, /* KEY_KP_6 */ 0x4e, /* KEY_KP_Plus */
+ 0x4f, /* KEY_KP_1 */ 0x50, /* KEY_KP_2 */
+ 0x51, /* KEY_KP_3 */ 0x52, /* KEY_KP_0 */
+ 0x53, /* KEY_KP_Decimal */ 0x54, /* KEY_SysReqest */
+ 0x00, /* 0x55 */ 0x56, /* KEY_Less */
+ 0x57, /* KEY_F11 */ 0x58, /* KEY_F12 */
+ 0x66, /* KEY_Home */ 0x67, /* KEY_Up */
+ 0x68, /* KEY_PgUp */ 0x69, /* KEY_Left */
+ 0x5d, /* KEY_Begin */ 0x6a, /* KEY_Right */
+ 0x6b, /* KEY_End */ 0x6c, /* KEY_Down */
+ 0x6d, /* KEY_PgDown */ 0x6e, /* KEY_Insert */
+ 0x6f, /* KEY_Delete */ 0x60, /* KEY_KP_Enter */
+ 0x61, /* KEY_RCtrl */ 0x77, /* KEY_Pause */
+ 0x63, /* KEY_Print */ 0x62, /* KEY_KP_Divide */
+ 0x64, /* KEY_AltLang */ 0x65, /* KEY_Break */
+ 0x00, /* KEY_LMeta */ 0x00, /* KEY_RMeta */
+ 0x7A, /* KEY_Menu/FOCUS_PF11*/0x00, /* 0x6e */
+ 0x7B, /* FOCUS_PF12 */ 0x00, /* 0x70 */
+ 0x00, /* 0x71 */ 0x00, /* 0x72 */
+ 0x59, /* FOCUS_PF2 */ 0x78, /* FOCUS_PF9 */
+ 0x00, /* 0x75 */ 0x00, /* 0x76 */
+ 0x5A, /* FOCUS_PF3 */ 0x5B, /* FOCUS_PF4 */
+ 0x5C, /* FOCUS_PF5 */ 0x5D, /* FOCUS_PF6 */
+ 0x5E, /* FOCUS_PF7 */ 0x5F, /* FOCUS_PF8 */
+ 0x7C, /* JAP_86 */ 0x79, /* FOCUS_PF10 */
+ 0x00, /* 0x7f */
+};
+#define NUM_AT2LNX (sizeof(at2lnx) / sizeof(at2lnx[0]))
+
+#define NUM_CUSTOMKEYS NR_KEYS
+
+u_char SpecialServerMap[NUM_CUSTOMKEYS];
+
+static void
+readKernelMapping(KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ KeySym *k;
+ int i;
+ int maxkey;
+ static unsigned char tbl[GLYPHS_PER_KEY] =
+ {
+ 0, /* unshifted */
+ 1, /* shifted */
+ 0, /* modeswitch unshifted */
+ 0 /* modeswitch shifted */
+ };
+
+ /*
+ * Read the mapping from the kernel.
+ * Since we're still using the XFree86 scancode->AT keycode mapping
+ * routines, we need to convert the AT keycodes to Linux keycodes,
+ * then translate the Linux keysyms into X keysyms.
+ *
+ * First, figure out which tables to use for the modeswitch columns
+ * above, from the XF86Config fields.
+ */
+ tbl[2] = 8; /* alt */
+ tbl[3] = tbl[2] | 1;
+
+ if (xf86Info.kbdCustomKeycodes) {
+ k = map;
+ maxkey = NUM_CUSTOMKEYS;
+ }
+ else {
+ k = map+GLYPHS_PER_KEY;
+ maxkey = NUM_AT2LNX;
+ }
+
+ for (i = 0; i < maxkey; ++i)
+ {
+ struct kbentry kbe;
+ int j;
+
+ if (xf86Info.kbdCustomKeycodes)
+ kbe.kb_index = i;
+ else
+ kbe.kb_index = at2lnx[i];
+
+ for (j = 0; j < GLYPHS_PER_KEY; ++j, ++k)
+ {
+ unsigned short kval;
+
+ *k = NoSymbol;
+
+ kbe.kb_table = tbl[j];
+ if (
+ (!xf86Info.kbdCustomKeycodes && kbe.kb_index == 0) ||
+ ioctl(xf86Info.consoleFd, KDGKBENT, &kbe))
+ continue;
+
+ kval = KVAL(kbe.kb_value);
+ switch (KTYP(kbe.kb_value))
+ {
+ case KT_LATIN:
+ case KT_LETTER:
+ *k = linux_to_x[kval];
+ break;
+
+ case KT_FN:
+ if (kval <= 19)
+ *k = XK_F1 + kval;
+ else switch (kbe.kb_value)
+ {
+ case K_FIND:
+ *k = XK_Home; /* or XK_Find */
+ break;
+ case K_INSERT:
+ *k = XK_Insert;
+ break;
+ case K_REMOVE:
+ *k = XK_Delete;
+ break;
+ case K_SELECT:
+ *k = XK_End; /* or XK_Select */
+ break;
+ case K_PGUP:
+ *k = XK_Prior;
+ break;
+ case K_PGDN:
+ *k = XK_Next;
+ break;
+ case K_HELP:
+ *k = XK_Help;
+ break;
+ case K_DO:
+ *k = XK_Execute;
+ break;
+ case K_PAUSE:
+ *k = XK_Pause;
+ break;
+ case K_MACRO:
+ *k = XK_Menu;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case KT_SPEC:
+ switch (kbe.kb_value)
+ {
+ case K_ENTER:
+ *k = XK_Return;
+ break;
+ case K_BREAK:
+ *k = XK_Break;
+ break;
+ case K_CAPS:
+ *k = XK_Caps_Lock;
+ break;
+ case K_NUM:
+ *k = XK_Num_Lock;
+ break;
+ case K_HOLD:
+ *k = XK_Scroll_Lock;
+ break;
+ case K_COMPOSE:
+ *k = XK_Multi_key;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case KT_PAD:
+ switch (kbe.kb_value)
+ {
+ case K_PPLUS:
+ *k = XK_KP_Add;
+ break;
+ case K_PMINUS:
+ *k = XK_KP_Subtract;
+ break;
+ case K_PSTAR:
+ *k = XK_KP_Multiply;
+ break;
+ case K_PSLASH:
+ *k = XK_KP_Divide;
+ break;
+ case K_PENTER:
+ *k = XK_KP_Enter;
+ break;
+ case K_PCOMMA:
+ *k = XK_KP_Separator;
+ break;
+ case K_PDOT:
+ *k = XK_KP_Decimal;
+ break;
+ case K_PPLUSMINUS:
+ *k = XK_KP_Subtract;
+ break;
+ default:
+ if (kval <= 9)
+ *k = XK_KP_0 + kval;
+ break;
+ }
+ break;
+
+ /*
+ * KT_DEAD keys are for accelerated diacritical creation.
+ */
+ case KT_DEAD:
+ switch (kbe.kb_value)
+ {
+ case K_DGRAVE:
+ *k = XK_dead_grave;
+ break;
+ case K_DACUTE:
+ *k = XK_dead_acute;
+ break;
+ case K_DCIRCM:
+ *k = XK_dead_circumflex;
+ break;
+ case K_DTILDE:
+ *k = XK_dead_tilde;
+ break;
+ case K_DDIERE:
+ *k = XK_dead_diaeresis;
+ break;
+ }
+ break;
+
+ case KT_CUR:
+ switch (kbe.kb_value)
+ {
+ case K_DOWN:
+ *k = XK_Down;
+ break;
+ case K_LEFT:
+ *k = XK_Left;
+ break;
+ case K_RIGHT:
+ *k = XK_Right;
+ break;
+ case K_UP:
+ *k = XK_Up;
+ break;
+ }
+ break;
+
+ case KT_SHIFT:
+ switch (kbe.kb_value)
+ {
+ case K_ALTGR:
+ *k = XK_Alt_R;
+ break;
+ case K_ALT:
+ *k = (kbe.kb_index == 0x64 ?
+ XK_Alt_R : XK_Alt_L);
+ break;
+ case K_CTRL:
+ *k = (kbe.kb_index == 0x61 ?
+ XK_Control_R : XK_Control_L);
+ break;
+ case K_CTRLL:
+ *k = XK_Control_L;
+ break;
+ case K_CTRLR:
+ *k = XK_Control_R;
+ break;
+ case K_SHIFT:
+ *k = (kbe.kb_index == 0x36 ?
+ XK_Shift_R : XK_Shift_L);
+ break;
+ case K_SHIFTL:
+ *k = XK_Shift_L;
+ break;
+ case K_SHIFTR:
+ *k = XK_Shift_R;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ /*
+ * KT_ASCII keys accumulate a 3 digit decimal number that gets
+ * emitted when the shift state changes. We can't emulate that.
+ */
+ case KT_ASCII:
+ break;
+
+ case KT_LOCK:
+ if (kbe.kb_value == K_SHIFTLOCK)
+ *k = XK_Shift_Lock;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (k[-1] == k[-2]) k[-1] = NoSymbol;
+ if (k[-2] == k[-3]) k[-2] = NoSymbol;
+ if (k[-3] == k[-4]) k[-3] = NoSymbol;
+ if (k[-4] == k[-2] && k[-3] == k[-1]) k[-2] = k[-1] = NoSymbol;
+ if (k[-1] == k[-4] && k[-2] == k[-3] && k[-2] == NoSymbol) k[-1] =NoSymbol;
+ }
+
+ if (!xf86Info.kbdCustomKeycodes)
+ return;
+
+ /*
+ * Find the Mapping for the special server functions
+ */
+ for (i = 0; i < NUM_CUSTOMKEYS; ++i) {
+ struct kbentry kbe;
+ int special = 0;
+
+ kbe.kb_index = i;
+ kbe.kb_table = 0; /* Plain map */
+ if (!ioctl(xf86Info.consoleFd, KDGKBENT, &kbe))
+ switch (kbe.kb_value) {
+ case K(KT_LATIN,0x7f): /* This catches DEL too... But who cares? */
+ special = KEY_BackSpace;
+ break;
+ case K_PMINUS:
+ special = KEY_KP_Minus;
+ break;
+ case K_PPLUS:
+ special = KEY_KP_Plus;
+ break;
+ case K_F1:
+ special = KEY_F1;
+ break;
+ case K_F2:
+ special = KEY_F2;
+ break;
+ case K_F3:
+ special = KEY_F3;
+ break;
+ case K_F4:
+ special = KEY_F4;
+ break;
+ case K_F5:
+ special = KEY_F5;
+ break;
+ case K_F6:
+ special = KEY_F6;
+ break;
+ case K_F7:
+ special = KEY_F7;
+ break;
+ case K_F8:
+ special = KEY_F8;
+ break;
+ case K_F9:
+ special = KEY_F9;
+ break;
+ case K_F10:
+ special = KEY_F10;
+ break;
+ case K_F11:
+ special = KEY_F11;
+ break;
+ case K_F12:
+ special = KEY_F12;
+ break;
+ case K_ALT:
+ special = KEY_Alt;
+ break;
+ case K_ALTGR:
+ special = KEY_AltLang;
+ break;
+ case K_CONS:
+ special = KEY_SysReqest;
+ break;
+ }
+ SpecialServerMap[i] = special;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdMach.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdMach.c
new file mode 100644
index 000000000..89c23c24a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86KbdMach.c
@@ -0,0 +1,317 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdMach.c,v 3.7.4.2 1998/06/04 17:35:20 dawes Exp $ */
+/*
+ *****************************************************************************
+ * HISTORY
+ * Log: xf86KbdMach.c,v
+ * Revision 2.1.2.1 92/06/25 10:32:08 moore
+ * Incorporate the Elliot Dresselhaus's, Ernest Hua's and local changes
+ * to run Thomas Roell's I386 color X11R5. Original code only worked
+ * with SCO Unix. New code works with 2.5 and 3.0 Mach
+ * [92/06/24 rvb]
+ *
+ * EndLog
+ *
+ *****************************************************************************
+ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: xf86KbdMach.c /main/9 1996/02/21 17:38:43 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+#include "xf86Config.h"
+
+#include "xf86Keymap.h"
+
+static KeySym ascii_to_x[256] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex,
+ XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla,
+ XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis,
+ XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring,
+ XK_Eacute, XK_ae, XK_AE, XK_ocircumflex,
+ XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave,
+ XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent,
+ XK_sterling, XK_yen, XK_paragraph, XK_section,
+ XK_aacute, XK_iacute, XK_oacute, XK_uacute,
+ XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine,
+ XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf,
+ XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi,
+ XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau,
+ XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta,
+ XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection,
+ XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal,
+ XK_topintegral, XK_botintegral, XK_division, XK_similarequal,
+ XK_degree, NoSymbol, NoSymbol, XK_radical,
+ XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol,
+ };
+
+/*
+ * LegalModifier --
+ * determine whether a key is a legal modifier key, i.e send a
+ * press/release sequence.
+ */
+
+/*ARGSUSED*/
+Bool
+LegalModifier(key, pDev)
+ unsigned int key;
+ DevicePtr pDev;
+{
+ return (TRUE);
+}
+
+
+
+/*
+ * xf86KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+void
+xf86KbdGetMapping (pKeySyms, pModMap)
+ KeySymsPtr pKeySyms;
+ CARD8 *pModMap;
+{
+ KeySym *k;
+ struct kbentry kbe;
+ char type;
+ int i, j;
+
+ for (i = 0; i < NUMKEYS; i++)
+ {
+ static int states[] = { NORM_STATE, SHIFT_STATE, ALT_STATE, SHIFT_ALT };
+ int j;
+
+ k = &map[i*4];
+ kbe.kb_index = i;
+
+ for (j = 0; j < 4; j++)
+ {
+ kbe.kb_state = states[j];
+
+ if (ioctl (xf86Info.consoleFd, KDGKBENT, &kbe) != -1)
+ continue;
+
+ if (kbe.kb_value [0] == K_SCAN)
+ {
+ int keycode = -1;
+ switch (kbe.kb_value [1])
+ {
+ case K_CTLSC: keycode = XK_Control_L; break;
+ case K_LSHSC: keycode = XK_Shift_L; break;
+ case K_RSHSC: keycode = XK_Shift_R; break;
+ case K_ALTSC: keycode = XK_Alt_L; break;
+ case K_CLCKSC: keycode = XK_Caps_Lock; break;
+ case K_NLCKSC: keycode = XK_Num_Lock; break;
+ default: break;
+ }
+ if (keycode > 0)
+ k[j] = keycode;
+ }
+ else if (kbe.kb_value[1] != NC)
+ {
+ /* How to handle multiple characters?
+ Ignore them for now. */
+ }
+ else
+ {
+ k[j] = ascii_to_x[kbe.kb_value[0]];
+ }
+ }
+ }
+
+ /*
+ * Apply the special key mapping specified in XF86Config
+ */
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4) {
+ switch (k[0]) {
+ case XK_Alt_L:
+ j = K_INDEX_LEFTALT;
+ break;
+ case XK_Alt_R:
+ j = K_INDEX_RIGHTALT;
+ break;
+ case XK_Scroll_Lock:
+ j = K_INDEX_SCROLLLOCK;
+ break;
+ case XK_Control_R:
+ j = K_INDEX_RIGHTCTL;
+ break;
+ default:
+ j = -1;
+ }
+ if (j >= 0)
+ switch (xf86Info.specialKeyMap[j]) {
+ case KM_META:
+ if (k[0] == XK_Alt_R)
+ k[1] = XK_Meta_R;
+ else {
+ k[0] = XK_Alt_L;
+ k[1] = XK_Meta_L;
+ }
+ break;
+ case KM_COMPOSE:
+ k[0] = XK_Multi_key;
+ break;
+ case KM_MODESHIFT:
+ k[0] = XK_Mode_switch;
+ k[1] = NoSymbol;
+ break;
+ case KM_MODELOCK:
+ k[0] = XK_Mode_switch;
+ k[1] = XF86XK_ModeLock;
+ break;
+ case KM_SCROLLLOCK:
+ k[0] = XK_Scroll_Lock;
+ break;
+ case KM_CONTROL:
+ k[0] = XK_Control_R;
+ break;
+ }
+ }
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ if (!xf86Info.serverNumLock) pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+ xf86Info.kbdType =
+ ioctl(xf86Info.kbdFd, KDGKBDTYPE, &type) != -1 ? type : KB_VANILLAKB;
+
+ pKeySyms->map = map;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ if (xf86Info.serverNumLock)
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+ else
+ pKeySyms->maxKeyCode = MAX_STD_KEYCODE;
+
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Keymap.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Keymap.h
new file mode 100644
index 000000000..f0998ba9b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Keymap.h
@@ -0,0 +1,455 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Keymap.h,v 3.20 2003/08/24 17:36:53 dawes Exp $ */
+
+/*
+ * Copyright (c) 1994-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).
+ */
+
+/*
+ *
+ * For Scancodes see notes in atKeynames.h !!!!
+ *
+ */
+/* $XConsortium: xf86Keymap.h /main/14 1996/02/21 17:38:47 kaleb $ */
+
+static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = {
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#if !defined(__SOL8__) && (!defined(sun) || defined(i386))
+
+ /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x01 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol,
+ /* 0x03 */ XK_2, XK_at, NoSymbol, NoSymbol,
+ /* 0x04 */ XK_3, XK_numbersign, NoSymbol, NoSymbol,
+ /* 0x05 */ XK_4, XK_dollar, NoSymbol, NoSymbol,
+ /* 0x06 */ XK_5, XK_percent, NoSymbol, NoSymbol,
+ /* 0x07 */ XK_6, XK_asciicircum, NoSymbol, NoSymbol,
+ /* 0x08 */ XK_7, XK_ampersand, NoSymbol, NoSymbol,
+ /* 0x09 */ XK_8, XK_asterisk, NoSymbol, NoSymbol,
+ /* 0x0a */ XK_9, XK_parenleft, NoSymbol, NoSymbol,
+ /* 0x0b */ XK_0, XK_parenright, NoSymbol, NoSymbol,
+ /* 0x0c */ XK_minus, XK_underscore, NoSymbol, NoSymbol,
+ /* 0x0d */ XK_equal, XK_plus, NoSymbol, NoSymbol,
+ /* 0x0e */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x0f */ XK_Tab, XK_ISO_Left_Tab,NoSymbol, NoSymbol,
+ /* 0x10 */ XK_Q, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x11 */ XK_W, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x12 */ XK_E, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x13 */ XK_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x14 */ XK_T, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x15 */ XK_Y, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x16 */ XK_U, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x17 */ XK_I, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x18 */ XK_O, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x19 */ XK_P, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1a */ XK_bracketleft, XK_braceleft, NoSymbol, NoSymbol,
+ /* 0x1b */ XK_bracketright,XK_braceright, NoSymbol, NoSymbol,
+ /* 0x1c */ XK_Return, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1d */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1e */ XK_A, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1f */ XK_S, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x20 */ XK_D, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x21 */ XK_F, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x22 */ XK_G, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x23 */ XK_H, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x24 */ XK_J, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x25 */ XK_K, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x26 */ XK_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x27 */ XK_semicolon, XK_colon, NoSymbol, NoSymbol,
+ /* 0x28 */ XK_quoteright, XK_quotedbl, NoSymbol, NoSymbol,
+ /* 0x29 */ XK_quoteleft, XK_asciitilde, NoSymbol, NoSymbol,
+ /* 0x2a */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2b */ XK_backslash, XK_bar, NoSymbol, NoSymbol,
+ /* 0x2c */ XK_Z, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2d */ XK_X, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2e */ XK_C, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2f */ XK_V, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x30 */ XK_B, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x31 */ XK_N, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x32 */ XK_M, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x33 */ XK_comma, XK_less, NoSymbol, NoSymbol,
+ /* 0x34 */ XK_period, XK_greater, NoSymbol, NoSymbol,
+ /* 0x35 */ XK_slash, XK_question, NoSymbol, NoSymbol,
+ /* 0x36 */ XK_Shift_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x37 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x38 */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol,
+ /* 0x39 */ XK_space, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3a */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3b */ XK_F1, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3c */ XK_F2, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3d */ XK_F3, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3e */ XK_F4, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3f */ XK_F5, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x40 */ XK_F6, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x41 */ XK_F7, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x42 */ XK_F8, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x43 */ XK_F9, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x44 */ XK_F10, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x45 */ XK_Num_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x46 */ XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x47 */ XK_KP_Home, XK_KP_7, NoSymbol, NoSymbol,
+ /* 0x48 */ XK_KP_Up, XK_KP_8, NoSymbol, NoSymbol,
+ /* 0x49 */ XK_KP_Prior, XK_KP_9, NoSymbol, NoSymbol,
+ /* 0x4a */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4b */ XK_KP_Left, XK_KP_4, NoSymbol, NoSymbol,
+ /* 0x4c */ XK_KP_Begin, XK_KP_5, NoSymbol, NoSymbol,
+ /* 0x4d */ XK_KP_Right, XK_KP_6, NoSymbol, NoSymbol,
+ /* 0x4e */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4f */ XK_KP_End, XK_KP_1, NoSymbol, NoSymbol,
+ /* 0x50 */ XK_KP_Down, XK_KP_2, NoSymbol, NoSymbol,
+ /* 0x51 */ XK_KP_Next, XK_KP_3, NoSymbol, NoSymbol,
+ /* 0x52 */ XK_KP_Insert, XK_KP_0, NoSymbol, NoSymbol,
+ /* 0x53 */ XK_KP_Delete, XK_KP_Decimal, NoSymbol, NoSymbol,
+ /* 0x54 */ XK_Sys_Req, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x55 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x56 */ XK_less, XK_greater, NoSymbol, NoSymbol,
+ /* 0x57 */ XK_F11, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x58 */ XK_F12, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x59 */ XK_Home, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5a */ XK_Up, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5b */ XK_Prior, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5c */ XK_Left, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5d */ XK_Begin, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5e */ XK_Right, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5f */ XK_End, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x60 */ XK_Down, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x61 */ XK_Next, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x62 */ XK_Insert, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x63 */ XK_Delete, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x64 */ XK_KP_Enter, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x65 */ XK_Control_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x66 */ XK_Pause, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x67 */ XK_Print, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x68 */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x69 */ XK_Alt_R, XK_Meta_R, NoSymbol, NoSymbol,
+ /* 0x6a */ XK_Break, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6b */ XK_Meta_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6c */ XK_Meta_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6d */ XK_Menu, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6e */ XK_F13, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6f */ XK_F14, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x70 */ XK_F15, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x71 */ XK_F16, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x72 */ XK_F17, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x73 */ XK_backslash, XK_underscore, NoSymbol, NoSymbol,
+ /* 0x74 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x75 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x76 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x77 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x78 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x79 */ XK_Henkan, XK_Mode_switch, NoSymbol, NoSymbol,
+ /* 0x7a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7b */ XK_Muhenkan, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7d */ XK_backslash, XK_bar, NoSymbol, NoSymbol,
+ /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+
+#else /* SunOS */
+
+/* Assumes a US English keyboard as default - sorry 'bout that
+ *
+ * Hopefully it'll be enough someone can have a sorta working
+ * keyboard, if they're not using XKB
+ *
+ * DWH 9/12/99
+ */
+
+ /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x01 */ XK_quoteleft, XK_asciitilde, NoSymbol, NoSymbol,
+ /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol,
+ /* 0x03 */ XK_2, XK_at, NoSymbol, NoSymbol,
+ /* 0x04 */ XK_3, XK_numbersign, NoSymbol, NoSymbol,
+ /* 0x05 */ XK_4, XK_dollar, NoSymbol, NoSymbol,
+ /* 0x06 */ XK_5, XK_percent, NoSymbol, NoSymbol,
+ /* 0x07 */ XK_6, XK_asciicircum, NoSymbol, NoSymbol,
+ /* 0x08 */ XK_7, XK_ampersand, NoSymbol, NoSymbol,
+ /* 0x09 */ XK_8, XK_asterisk, NoSymbol, NoSymbol,
+ /* 0x0a */ XK_9, XK_parenleft, NoSymbol, NoSymbol,
+ /* 0x0b */ XK_0, XK_parenright, NoSymbol, NoSymbol,
+ /* 0x0c */ XK_minus, XK_underscore, NoSymbol, NoSymbol,
+ /* 0x0d */ XK_equal, XK_plus, NoSymbol, NoSymbol,
+ /* 0x0e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x0f */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x10 */ XK_Tab, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x11 */ XK_Q, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x12 */ XK_W, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x13 */ XK_E, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x14 */ XK_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x15 */ XK_T, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x16 */ XK_Y, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x17 */ XK_U, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x18 */ XK_I, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x19 */ XK_O, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1a */ XK_P, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1b */ XK_bracketleft, XK_braceleft, NoSymbol, NoSymbol,
+ /* 0x1c */ XK_bracketright,XK_braceright, NoSymbol, NoSymbol,
+ /* 0x1d */ XK_backslash, XK_bar, NoSymbol, NoSymbol,
+ /* 0x1e */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1f */ XK_A, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x20 */ XK_S, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x21 */ XK_D, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x22 */ XK_F, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x23 */ XK_G, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x24 */ XK_H, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x25 */ XK_J, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x26 */ XK_K, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x27 */ XK_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x28 */ XK_semicolon, XK_colon, NoSymbol, NoSymbol,
+ /* 0x29 */ XK_quoteright, XK_quotedbl, NoSymbol, NoSymbol,
+ /* 0x2a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2b */ XK_Return, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2c */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2e */ XK_Z, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2f */ XK_X, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x30 */ XK_C, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x31 */ XK_V, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x32 */ XK_B, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x33 */ XK_N, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x34 */ XK_M, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x35 */ XK_comma, XK_less, NoSymbol, NoSymbol,
+ /* 0x36 */ XK_period, XK_greater, NoSymbol, NoSymbol,
+ /* 0x37 */ XK_slash, XK_question, NoSymbol, NoSymbol,
+ /* 0x38 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x39 */ XK_Shift_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3a */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3c */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol,
+ /* 0x3d */ XK_space, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3e */ XK_Alt_R, XK_Meta_R, NoSymbol, NoSymbol,
+ /* 0x3f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x40 */ XK_Control_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x41 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x42 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x43 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x44 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x45 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x46 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x47 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x48 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x49 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4b */ XK_Insert, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4c */ XK_Delete, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4f */ XK_Left, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x50 */ XK_Home, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x51 */ XK_End, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x52 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x53 */ XK_Up, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x54 */ XK_Down, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x55 */ XK_Prior, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x56 */ XK_Next, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x57 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x58 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x59 */ XK_Right, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5a */ XK_Num_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5b */ XK_KP_Home, XK_KP_7, NoSymbol, NoSymbol,
+ /* 0x5c */ XK_KP_Left, XK_KP_4, NoSymbol, NoSymbol,
+ /* 0x5d */ XK_KP_End, XK_KP_1, NoSymbol, NoSymbol,
+ /* 0x5e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5f */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x60 */ XK_KP_Up, XK_KP_8, NoSymbol, NoSymbol,
+ /* 0x61 */ NoSymbol, XK_KP_5, NoSymbol, NoSymbol,
+ /* 0x62 */ XK_KP_Down, XK_KP_2, NoSymbol, NoSymbol,
+ /* 0x63 */ XK_KP_Insert, XK_KP_0, NoSymbol, NoSymbol,
+ /* 0x64 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x65 */ XK_KP_Prior, XK_KP_9, NoSymbol, NoSymbol,
+ /* 0x66 */ XK_KP_Right, XK_KP_6, NoSymbol, NoSymbol,
+ /* 0x67 */ XK_KP_Next, XK_KP_3, NoSymbol, NoSymbol,
+ /* 0x68 */ XK_KP_Delete, XK_KP_Decimal, NoSymbol, NoSymbol,
+ /* 0x69 */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6a */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6c */ XK_KP_Enter, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6e */ XK_Escape, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x70 */ XK_F1, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x71 */ XK_F2, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x72 */ XK_F3, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x73 */ XK_F4, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x74 */ XK_F5, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x75 */ XK_F6, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x76 */ XK_F7, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x77 */ XK_F8, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x78 */ XK_F9, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x79 */ XK_F10, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7a */ XK_F11, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7b */ XK_F12, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7c */ XK_Print, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7d */ XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7e */ XK_Pause, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+
+#endif /* SunOS */
+
+};
+
+#if !defined(Lynx) && \
+ !defined(__UNIXOS2__) && \
+ !defined(__mips__) && \
+ !defined(linux) && \
+ !defined(CSRG_BASED) && \
+ !defined(__CYGWIN__) && \
+ !defined(__SOL8__) && \
+ (!defined(sun) || defined(i386))
+
+static KeySym map84[NUM_KEYCODES * GLYPHS_PER_KEY] = {
+ /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x01 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol,
+ /* 0x03 */ XK_2, XK_at, NoSymbol, NoSymbol,
+ /* 0x04 */ XK_3, XK_numbersign, NoSymbol, NoSymbol,
+ /* 0x05 */ XK_4, XK_dollar, NoSymbol, NoSymbol,
+ /* 0x06 */ XK_5, XK_percent, NoSymbol, NoSymbol,
+ /* 0x07 */ XK_6, XK_asciicircum, NoSymbol, NoSymbol,
+ /* 0x08 */ XK_7, XK_ampersand, NoSymbol, NoSymbol,
+ /* 0x09 */ XK_8, XK_asterisk, NoSymbol, NoSymbol,
+ /* 0x0a */ XK_9, XK_parenleft, NoSymbol, NoSymbol,
+ /* 0x0b */ XK_0, XK_parenright, NoSymbol, NoSymbol,
+ /* 0x0c */ XK_minus, XK_underscore, NoSymbol, NoSymbol,
+ /* 0x0d */ XK_equal, XK_plus, NoSymbol, NoSymbol,
+ /* 0x0e */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x0f */ XK_Tab, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x10 */ XK_Q, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x11 */ XK_W, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x12 */ XK_E, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x13 */ XK_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x14 */ XK_T, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x15 */ XK_Y, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x16 */ XK_U, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x17 */ XK_I, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x18 */ XK_O, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x19 */ XK_P, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1a */ XK_bracketleft, XK_braceleft, NoSymbol, NoSymbol,
+ /* 0x1b */ XK_bracketright,XK_braceright, NoSymbol, NoSymbol,
+ /* 0x1c */ XK_Return, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1d */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1e */ XK_A, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1f */ XK_S, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x20 */ XK_D, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x21 */ XK_F, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x22 */ XK_G, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x23 */ XK_H, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x24 */ XK_J, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x25 */ XK_K, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x26 */ XK_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x27 */ XK_semicolon, XK_colon, NoSymbol, NoSymbol,
+ /* 0x28 */ XK_quoteright, XK_quotedbl, NoSymbol, NoSymbol,
+ /* 0x29 */ XK_quoteleft, XK_asciitilde, NoSymbol, NoSymbol,
+ /* 0x2a */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2b */ XK_backslash, XK_bar, NoSymbol, NoSymbol,
+ /* 0x2c */ XK_Z, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2d */ XK_X, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2e */ XK_C, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2f */ XK_V, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x30 */ XK_B, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x31 */ XK_N, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x32 */ XK_M, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x33 */ XK_comma, XK_less, NoSymbol, NoSymbol,
+ /* 0x34 */ XK_period, XK_greater, NoSymbol, NoSymbol,
+ /* 0x35 */ XK_slash, XK_question, NoSymbol, NoSymbol,
+ /* 0x36 */ XK_Shift_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x37 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x38 */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol,
+ /* 0x39 */ XK_space, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3a */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3b */ XK_F1, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3c */ XK_F2, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3d */ XK_F3, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3e */ XK_F4, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3f */ XK_F5, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x40 */ XK_F6, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x41 */ XK_F7, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x42 */ XK_F8, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x43 */ XK_F9, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x44 */ XK_F10, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x45 */ XK_Num_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x46 */ XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x47 */ XK_KP_Home, XK_KP_7, NoSymbol, NoSymbol,
+ /* 0x48 */ XK_KP_Up, XK_KP_8, NoSymbol, NoSymbol,
+ /* 0x49 */ XK_KP_Prior, XK_KP_9, NoSymbol, NoSymbol,
+ /* 0x4a */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4b */ XK_KP_Left, XK_KP_4, NoSymbol, NoSymbol,
+ /* 0x4c */ NoSymbol, XK_KP_5, NoSymbol, NoSymbol,
+ /* 0x4d */ XK_KP_Right, XK_KP_6, NoSymbol, NoSymbol,
+ /* 0x4e */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4f */ XK_KP_End, XK_KP_1, NoSymbol, NoSymbol,
+ /* 0x50 */ XK_KP_Down, XK_KP_2, NoSymbol, NoSymbol,
+ /* 0x51 */ XK_KP_Next, XK_KP_3, NoSymbol, NoSymbol,
+ /* 0x52 */ XK_KP_Insert, XK_KP_0, NoSymbol, NoSymbol,
+ /* 0x53 */ XK_KP_Delete, XK_KP_Decimal, NoSymbol, NoSymbol,
+ /* 0x54 */ XK_Sys_Req, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x55 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x56 */ XK_less, XK_greater, NoSymbol, NoSymbol,
+ /* 0x57 */ XK_F11, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x58 */ XK_F12, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x59 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x60 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x61 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x62 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x63 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x64 */ XK_KP_Enter, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x65 */ XK_Control_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x66 */ XK_Pause, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x67 */ XK_Print, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x68 */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x69 */ XK_Alt_R, XK_Meta_R, NoSymbol, NoSymbol,
+ /* 0x6a */ XK_Break, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6b */ XK_Meta_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6c */ XK_Meta_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6d */ XK_Menu, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x70 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x71 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x72 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x73 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x74 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x75 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x76 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x77 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x78 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x79 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+};
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86MiscExt.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86MiscExt.c
new file mode 100644
index 000000000..54c0cd510
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86MiscExt.c
@@ -0,0 +1,656 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86MiscExt.c,v 1.16 2003/11/03 05:11:02 tsi Exp $ */
+/*
+ * Copyright (c) 1999-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 Pointer/Keyboard functions needed by the
+ * XFree86-Misc extension.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+
+#ifdef XF86MISC
+#define _XF86MISC_SERVER_
+#include <X11/extensions/xf86misc.h>
+#include "xf86miscproc.h"
+#endif
+
+#define XF86_OS_PRIVS
+#include "xf86_OSlib.h"
+
+#ifdef XINPUT
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#include "xf86Xinput.h"
+#else
+#include "inputstr.h"
+#endif
+
+#include "xf86OSmouse.h"
+
+#ifdef DEBUG
+# define DEBUG_P(x) ErrorF(x"\n");
+#else
+# define DEBUG_P(x) /**/
+#endif
+
+#ifdef XF86MISC
+
+typedef struct {
+ int type;
+ int baudrate;
+ int samplerate;
+ int resolution;
+ int buttons;
+ Bool em3buttons;
+ int em3timeout;
+ Bool chordmiddle;
+ int flags;
+ char* device;
+ pointer private;
+} mseParamsRec, *mseParamsPtr;
+
+typedef struct {
+ int type;
+ int rate;
+ int delay;
+ int serverNumLock; /* obsolete */
+} kbdParamsRec, *kbdParamsPtr;
+
+/*
+ Sigh...
+
+ The extension should probably be changed to use protocol
+ names instead of ID numbers
+*/
+static struct mouse_map {
+ int mtype;
+ MouseProtocolID proto;
+} m_map[] =
+{
+ { MTYPE_MICROSOFT, PROT_MS },
+ { MTYPE_MOUSESYS, PROT_MSC },
+ { MTYPE_MMSERIES, PROT_MM },
+ { MTYPE_LOGITECH, PROT_LOGI },
+ { MTYPE_LOGIMAN, PROT_LOGIMAN },
+ { MTYPE_MMHIT, PROT_MMHIT },
+ { MTYPE_GLIDEPOINT, PROT_GLIDE },
+ { MTYPE_IMSERIAL, PROT_IMSERIAL },
+ { MTYPE_THINKING, PROT_THINKING },
+ { MTYPE_ACECAD, PROT_ACECAD },
+ { MTYPE_PS_2, PROT_PS2 },
+ { MTYPE_IMPS2, PROT_IMPS2 },
+ { MTYPE_EXPPS2, PROT_EXPPS2 },
+ { MTYPE_THINKINGPS2, PROT_THINKPS2 },
+ { MTYPE_MMANPLUSPS2, PROT_MMPS2 },
+ { MTYPE_GLIDEPOINTPS2, PROT_GLIDEPS2 },
+ { MTYPE_NETPS2, PROT_NETPS2 },
+ { MTYPE_NETSCROLLPS2, PROT_NETSCPS2 },
+ { MTYPE_BUSMOUSE, PROT_BM },
+ { MTYPE_AUTOMOUSE, PROT_AUTO },
+ { MTYPE_SYSMOUSE, PROT_SYSMOUSE },
+ { MTYPE_UNKNOWN, PROT_UNKNOWN }
+};
+
+static int
+MapMseProtoToMisc(MouseProtocolID proto)
+{
+ int i;
+
+ for (i = 0; m_map[i].proto != PROT_UNKNOWN; i++)
+ if (proto == m_map[i].proto)
+ return m_map[i].mtype;
+
+ return MTYPE_UNKNOWN;
+}
+
+static MouseProtocolID
+MapMseMiscToProto(int proto)
+{
+ int i;
+
+ for (i = 0; m_map[i].mtype != MTYPE_UNKNOWN; i++)
+ if (proto == m_map[i].mtype)
+ return m_map[i].proto;
+
+ return PROT_UNKNOWN;
+}
+
+Bool
+MiscExtGetMouseSettings(pointer *mouse, char **devname)
+{
+ mseParamsPtr mseptr;
+
+ DEBUG_P("MiscExtGetMouseSettings");
+
+ mseptr = MiscExtCreateStruct(MISC_POINTER);
+ if (!mseptr)
+ return FALSE;
+
+ {
+ InputInfoPtr pInfo = mseptr->private;
+ MouseDevPtr pMse;
+
+ *devname = xf86FindOptionValue(pInfo->options, "Device");
+ pMse = pInfo->private;
+
+ mseptr->type = MapMseProtoToMisc(pMse->protocolID);
+ mseptr->baudrate = pMse->baudRate;
+ mseptr->samplerate = pMse->sampleRate;
+ mseptr->resolution = pMse->resolution;
+ mseptr->buttons = pMse->buttons;
+ mseptr->em3buttons = pMse->emulate3Buttons;
+ mseptr->em3timeout = pMse->emulate3Timeout;
+ mseptr->chordmiddle = pMse->chordMiddle;
+ mseptr->flags = pMse->mouseFlags;
+ }
+ *mouse = mseptr;
+ return TRUE;
+}
+
+int
+MiscExtGetMouseValue(pointer mouse, MiscExtMseValType valtype)
+{
+ mseParamsPtr mse = mouse;
+
+ DEBUG_P("MiscExtGetMouseValue");
+
+ switch (valtype) {
+ case MISC_MSE_PROTO: return mse->type;
+ case MISC_MSE_BAUDRATE: return mse->baudrate;
+ case MISC_MSE_SAMPLERATE: return mse->samplerate;
+ case MISC_MSE_RESOLUTION: return mse->resolution;
+ case MISC_MSE_BUTTONS: return mse->buttons;
+ case MISC_MSE_EM3BUTTONS: return mse->em3buttons;
+ case MISC_MSE_EM3TIMEOUT: return mse->em3timeout;
+ case MISC_MSE_CHORDMIDDLE: return mse->chordmiddle;
+ case MISC_MSE_FLAGS: return mse->flags;
+ }
+ return 0;
+}
+
+Bool
+MiscExtSetMouseValue(pointer mouse, MiscExtMseValType valtype, int value)
+{
+ mseParamsPtr mse = mouse;
+
+ DEBUG_P("MiscExtSetMouseValue");
+
+ switch (valtype) {
+ case MISC_MSE_PROTO:
+ mse->type = value;
+ return TRUE;
+ case MISC_MSE_BAUDRATE:
+ mse->baudrate = value;
+ return TRUE;
+ case MISC_MSE_SAMPLERATE:
+ mse->samplerate = value;
+ return TRUE;
+ case MISC_MSE_RESOLUTION:
+ mse->resolution = value;
+ return TRUE;
+ case MISC_MSE_BUTTONS:
+ mse->buttons = value;
+ return TRUE;
+ case MISC_MSE_EM3BUTTONS:
+ mse->em3buttons = value;
+ return TRUE;
+ case MISC_MSE_EM3TIMEOUT:
+ mse->em3timeout = value;
+ return TRUE;
+ case MISC_MSE_CHORDMIDDLE:
+ mse->chordmiddle = value;
+ return TRUE;
+ case MISC_MSE_FLAGS:
+ mse->flags = value;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+Bool
+MiscExtSetMouseDevice(pointer mouse, char* device)
+{
+ mseParamsPtr mse = mouse;
+
+ mse->device = device;
+
+ return TRUE;
+}
+
+Bool
+MiscExtGetKbdSettings(pointer *kbd)
+{
+ kbdParamsPtr kbdptr;
+
+ DEBUG_P("MiscExtGetKbdSettings");
+
+ kbdptr = MiscExtCreateStruct(MISC_KEYBOARD);
+ if (!kbdptr)
+ return FALSE;
+ kbdptr->type = xf86Info.kbdType;
+ kbdptr->rate = xf86Info.kbdRate;
+ kbdptr->delay = xf86Info.kbdDelay;
+ *kbd = kbdptr;
+ return TRUE;
+}
+
+int
+MiscExtGetKbdValue(pointer keyboard, MiscExtKbdValType valtype)
+{
+ kbdParamsPtr kbd = keyboard;
+
+ DEBUG_P("MiscExtGetKbdValue");
+ switch (valtype) {
+ case MISC_KBD_TYPE: return kbd->type;
+ case MISC_KBD_RATE: return kbd->rate;
+ case MISC_KBD_DELAY: return kbd->delay;
+ case MISC_KBD_SERVNUMLOCK: return 0;
+ }
+ return 0;
+}
+
+Bool
+MiscExtSetKbdValue(pointer keyboard, MiscExtKbdValType valtype, int value)
+{
+ kbdParamsPtr kbd = keyboard;
+
+ DEBUG_P("MiscExtSetKbdValue");
+ switch (valtype) {
+ case MISC_KBD_TYPE:
+ kbd->type = value;
+ return TRUE;
+ case MISC_KBD_RATE:
+ kbd->rate = value;
+ return TRUE;
+ case MISC_KBD_DELAY:
+ kbd->delay = value;
+ return TRUE;
+ case MISC_KBD_SERVNUMLOCK:
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void
+MiscExtClientStateCallback(CallbackListPtr *callbacks,
+ pointer data, pointer args)
+{
+ NewClientInfoRec *clientinfo = (NewClientInfoRec*)args;
+
+ if (clientinfo->client == xf86Info.grabInfo.override &&
+ clientinfo->client->clientState == ClientStateGone) {
+ xf86Info.grabInfo.override = NULL;
+ xf86Info.grabInfo.disabled = 0;
+ DeleteCallback(&ClientStateCallback, MiscExtClientStateCallback, NULL);
+ }
+}
+
+#define MiscExtGrabStateSuccess 0 /* No errors */
+#define MiscExtGrabStateLocked 1 /* A client already requested that
+ * grabs cannot be removed/killed */
+#define MiscExtGrabStateAlready 2 /* Request for enabling/disabling
+ * grab removeal/kill already done */
+int
+MiscExtSetGrabKeysState(ClientPtr client, int state)
+{
+ DEBUG_P("MiscExtSetGrabKeysState");
+
+ if (xf86Info.grabInfo.override == NULL ||
+ xf86Info.grabInfo.override == client) {
+ if (state == 0 && xf86Info.grabInfo.disabled == 0) {
+ xf86Info.grabInfo.disabled = 1;
+ AddCallback(&ClientStateCallback,
+ MiscExtClientStateCallback, NULL);
+ xf86Info.grabInfo.override = client;
+ }
+ else if (state == 1 && xf86Info.grabInfo.disabled == 1) {
+ xf86Info.grabInfo.disabled = 0;
+ DeleteCallback(&ClientStateCallback,
+ MiscExtClientStateCallback, NULL);
+ xf86Info.grabInfo.override = NULL;
+ }
+ else
+ return MiscExtGrabStateAlready;
+
+ return MiscExtGrabStateSuccess;
+ }
+
+ return MiscExtGrabStateLocked;
+}
+
+pointer
+MiscExtCreateStruct(MiscExtStructType mse_or_kbd)
+{
+ DEBUG_P("MiscExtCreateStruct");
+
+ switch (mse_or_kbd) {
+ case MISC_POINTER:
+ {
+ mseParamsPtr mseptr;
+ InputInfoPtr pInfo = xf86InputDevs;
+
+ while (pInfo) {
+ if (xf86IsCorePointer(pInfo->dev))
+ break;
+ pInfo = pInfo->next;
+ }
+ if (!pInfo)
+ return NULL;
+
+ mseptr = xcalloc(sizeof(mseParamsRec),1);
+ if (mseptr)
+ mseptr->private = pInfo;
+ return mseptr;
+ }
+ case MISC_KEYBOARD:
+ return xcalloc(sizeof(kbdParamsRec),1);
+ }
+ return 0;
+}
+
+void
+MiscExtDestroyStruct(pointer structure, MiscExtStructType mse_or_kbd)
+{
+ DEBUG_P("MiscExtDestroyStruct");
+
+ switch (mse_or_kbd) {
+ case MISC_POINTER:
+ case MISC_KEYBOARD:
+ xfree(structure);
+ }
+}
+
+static Bool
+MiscExtAuthorizeDevice(InputInfoPtr pInfo, char *device)
+{
+ Bool authorized = FALSE;
+ char *elem;
+ struct stat dev, dev_list;
+ const char *olddev = xf86FindOptionValue(pInfo->options, "Device");
+
+ if (stat(device,&dev))
+ return FALSE;
+
+ if (!S_ISCHR(dev.st_mode))
+ return FALSE;
+
+ if (!stat(olddev,&dev_list)) {
+ if (dev_list.st_dev == dev.st_dev
+ && dev_list.st_ino == dev.st_ino) {
+ authorized = TRUE;
+ }
+ }
+
+ if (!authorized) {
+ char *path;
+
+ if (!xf86InputDeviceList
+ || (path = strdup(xf86InputDeviceList)) == NULL)
+ return FALSE;
+
+ elem = strtok(path,",");
+
+ while (elem) {
+
+ if (!stat(elem,&dev_list)) {
+ if (dev_list.st_dev == dev.st_dev
+ && dev_list.st_ino == dev.st_ino) {
+ authorized = TRUE;
+ break;
+
+ }
+ }
+ elem = strtok(NULL,",");
+ }
+ xfree(path);
+ }
+#if 0
+ ErrorF("AUTHORIZED: %s\n",authorized?"Yes":"No");
+#endif
+ return (authorized);
+}
+
+MiscExtReturn
+MiscExtApply(pointer structure, MiscExtStructType mse_or_kbd)
+{
+ DEBUG_P("MiscExtApply");
+
+ if (mse_or_kbd == MISC_POINTER) {
+ Bool protoChanged = FALSE;
+ int oldflags;
+ Bool reopen = FALSE;
+ MouseProtocolID newProtocol;
+ mseParamsPtr mse = structure;
+ InputInfoPtr pInfo;
+ MouseDevPtr pMse;
+#ifdef XFree86LOADER
+ pointer xf86MouseProtocolIDToName
+ = LoaderSymbol("xf86MouseProtocolIDToName");
+ if (!xf86MouseProtocolIDToName)
+ return MISC_RET_NOMODULE;
+#endif
+ if (mse->type < MTYPE_MICROSOFT
+ || ( mse->type > MTYPE_EXPPS2
+ && (mse->type!=MTYPE_OSMOUSE && mse->type!=MTYPE_XQUEUE)))
+ return MISC_RET_BADMSEPROTO;
+#ifdef OSMOUSE_ONLY
+ if (mse->type != MTYPE_OSMOUSE)
+ return MISC_RET_BADMSEPROTO;
+#else
+ if (mse->type == MTYPE_XQUEUE)
+ return MISC_RET_BADMSEPROTO;
+ if (mse->type == MTYPE_OSMOUSE)
+ return MISC_RET_BADMSEPROTO;
+#endif /* OSMOUSE_ONLY */
+
+ if (mse->em3timeout < 0)
+ return MISC_RET_BADVAL;
+
+ if (mse->type == MTYPE_LOGIMAN
+ && !(mse->baudrate == 0
+ || mse->baudrate == 1200
+ || mse->baudrate == 9600))
+ return MISC_RET_BADBAUDRATE;
+ if (mse->type == MTYPE_LOGIMAN && mse->samplerate)
+ return MISC_RET_BADCOMBO;
+
+ if (mse->flags & MF_REOPEN) {
+ reopen = TRUE;
+ mse->flags &= ~MF_REOPEN;
+ }
+ if (mse->type != MTYPE_OSMOUSE
+ && mse->type != MTYPE_XQUEUE
+ && mse->type != MTYPE_PS_2
+ && mse->type != MTYPE_BUSMOUSE
+ && mse->type != MTYPE_IMPS2
+ && mse->type != MTYPE_THINKINGPS2
+ && mse->type != MTYPE_MMANPLUSPS2
+ && mse->type != MTYPE_GLIDEPOINTPS2
+ && mse->type != MTYPE_NETPS2
+ && mse->type != MTYPE_NETSCROLLPS2
+ && mse->type != MTYPE_SYSMOUSE)
+ {
+ if (mse->baudrate % 1200 != 0
+ || (mse->baudrate != 0 && mse->baudrate < 1200)
+ || mse->baudrate > 9600)
+ return MISC_RET_BADBAUDRATE;
+ }
+ if ((mse->flags & (MF_CLEAR_DTR|MF_CLEAR_RTS))
+ && (mse->type != MTYPE_MOUSESYS))
+ return MISC_RET_BADFLAGS;
+
+ if (mse->type != MTYPE_OSMOUSE
+ && mse->type != MTYPE_XQUEUE
+ && mse->type != MTYPE_BUSMOUSE)
+ {
+ if (mse->samplerate < 0)
+ return MISC_RET_BADVAL;
+ }
+
+ if (mse->resolution < 0)
+ return MISC_RET_BADVAL;
+ if (mse->chordmiddle)
+ {
+ if (mse->em3buttons || !(mse->type == MTYPE_MICROSOFT
+ || mse->type == MTYPE_LOGIMAN) )
+ return MISC_RET_BADCOMBO;
+ }
+
+ /* XXX - This still needs work */
+
+ pInfo = mse->private;
+ pMse = pInfo->private;
+ oldflags = pMse->mouseFlags;
+
+ newProtocol = MapMseMiscToProto(mse->type);
+ protoChanged = pMse->protocolID != newProtocol;
+ if (protoChanged
+ || pMse->baudRate != mse->baudrate
+ || pMse->sampleRate != mse->samplerate
+ || pMse->resolution != mse->resolution
+ || pMse->mouseFlags != mse->flags)
+ reopen = TRUE;
+
+ if (mse->device)
+ reopen = TRUE;
+
+ if (reopen)
+ (pMse->device->deviceProc)(pMse->device, DEVICE_CLOSE);
+
+ pMse->protocolID = newProtocol;
+ pMse->baudRate = mse->baudrate;
+ pMse->sampleRate = mse->samplerate;
+ pMse->resolution = mse->resolution;
+ pMse->buttons = mse->buttons;
+ pMse->emulate3Buttons = mse->em3buttons;
+ pMse->emulate3Timeout = mse->em3timeout;
+ pMse->chordMiddle = mse->chordmiddle;
+ pMse->mouseFlags = mse->flags;
+
+#ifdef XFree86LOADER
+ pMse->protocol = ((const char *(*)(MouseProtocolID))
+ xf86MouseProtocolIDToName)(pMse->protocolID);
+#else
+ pMse->protocol = xf86MouseProtocolIDToName(pMse->protocolID);
+#endif
+
+ if (mse->device) {
+ if (MiscExtAuthorizeDevice(pInfo, mse->device)) {
+ xf86ReplaceStrOption(pInfo->options, "Device", mse->device);
+ } else {
+ return MISC_RET_BADVAL;
+ }
+ }
+
+ if (reopen) {
+ /* Only if protocol is changed explicitely disable auto detect */
+ if (protoChanged)
+ pMse->autoProbe = FALSE;
+ (pMse->device->deviceProc)(pMse->device, DEVICE_ON);
+ }
+ /* Set pInfo->options too */
+
+ if ((oldflags & MF_CLEAR_DTR) != (pMse->mouseFlags & MF_CLEAR_DTR))
+ xf86ReplaceBoolOption(pInfo->options, "ClearDTR",
+ pMse->mouseFlags | MF_CLEAR_DTR);
+ if ((oldflags & MF_CLEAR_RTS) != (pMse->mouseFlags & MF_CLEAR_RTS))
+ xf86ReplaceBoolOption(pInfo->options, "ClearRTS",
+ pMse->mouseFlags | MF_CLEAR_RTS);
+ }
+ if (mse_or_kbd == MISC_KEYBOARD) {
+ kbdParamsPtr kbd = structure;
+
+ if (kbd->rate < 0)
+ return MISC_RET_BADVAL;
+ if (kbd->delay < 0)
+ return MISC_RET_BADVAL;
+ if (kbd->type < KTYPE_UNKNOWN || kbd->type > KTYPE_XQUEUE)
+ return MISC_RET_BADKBDTYPE;
+
+ if (xf86Info.kbdRate!=kbd->rate || xf86Info.kbdDelay!=kbd->delay) {
+ char rad;
+
+ xf86Info.kbdRate = kbd->rate;
+ xf86Info.kbdDelay = kbd->delay;
+ if (xf86Info.kbdDelay <= 375) rad = 0x00;
+ else if (xf86Info.kbdDelay <= 625) rad = 0x20;
+ else if (xf86Info.kbdDelay <= 875) rad = 0x40;
+ else rad = 0x60;
+
+ if (xf86Info.kbdRate <= 2) rad |= 0x1F;
+ else if (xf86Info.kbdRate >= 30) rad |= 0x00;
+ else rad |= ((58/xf86Info.kbdRate)-2);
+
+ xf86SetKbdRepeat(rad);
+ }
+#if 0 /* Not done yet */
+ xf86Info.kbdType = kbd->kbdtype;
+#endif
+ }
+ return MISC_RET_SUCCESS;
+}
+
+Bool
+MiscExtGetFilePaths(const char **configfile, const char **modulepath,
+ const char **logfile)
+{
+ DEBUG_P("MiscExtGetFilePaths");
+
+ *configfile = xf86ConfigFile;
+ *modulepath = xf86ModulePath;
+ *logfile = xf86LogFile;
+
+ return TRUE;
+}
+
+int
+MiscExtPassMessage(int scrnIndex, const char *msgtype, const char *msgval,
+ char **retstr)
+{
+ ScrnInfoPtr pScr = xf86Screens[scrnIndex];
+
+ DEBUG_P("MiscExtPassMessage");
+
+ if (*pScr->HandleMessage == NULL)
+ return BadImplementation;
+ return (*pScr->HandleMessage)(scrnIndex, msgtype, msgval, retstr);
+}
+
+#endif /* XF86MISC */
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Mode.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Mode.c
new file mode 100644
index 000000000..2abbd2213
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Mode.c
@@ -0,0 +1,2185 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86Mode.c,v 1.7 2005/07/03 08:53:42 daniels Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Mode.c,v 1.69 2003/10/08 14:58:28 dawes Exp $ */
+/*
+ * 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).
+ */
+
+/*
+ * Authors: Dirk Hohndel <hohndel@XFree86.Org>
+ * David Dawes <dawes@XFree86.Org>
+ * Marc La France <tsi@XFree86.Org>
+ * ... and others
+ *
+ * This file includes helper functions for mode related things.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "servermd.h"
+#include "mibank.h"
+#include "globals.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86DDC.h"
+
+/*
+ * xf86GetNearestClock --
+ * Find closest clock to given frequency (in kHz). This assumes the
+ * number of clocks is greater than zero.
+ */
+int
+xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
+ int DivFactor, int MulFactor, int *divider)
+{
+ int nearestClock = 0, nearestDiv = 1;
+ int minimumGap = abs(freq - scrp->clock[0]);
+ int i, j, k, gap;
+
+ if (allowDiv2)
+ k = 2;
+ else
+ k = 1;
+
+ /* Must set this here in case the best match is scrp->clock[0] */
+ if (divider != NULL)
+ *divider = 0;
+
+ for (i = 0; i < scrp->numClocks; i++) {
+ for (j = 1; j <= k; j++) {
+ gap = abs((freq * j) - ((scrp->clock[i] * DivFactor) / MulFactor));
+ if ((gap < minimumGap) ||
+ ((gap == minimumGap) && (j < nearestDiv))) {
+ minimumGap = gap;
+ nearestClock = i;
+ nearestDiv = j;
+ if (divider != NULL)
+ *divider = (j - 1) * V_CLKDIV2;
+ }
+ }
+ }
+ return nearestClock;
+}
+
+/*
+ * xf86ModeStatusToString
+ *
+ * Convert a ModeStatus value to a printable message
+ */
+
+const char *
+xf86ModeStatusToString(ModeStatus status)
+{
+ switch (status) {
+ case MODE_OK:
+ return "Mode OK";
+ case MODE_HSYNC:
+ return "hsync out of range";
+ case MODE_VSYNC:
+ return "vrefresh out of range";
+ case MODE_H_ILLEGAL:
+ return "illegal horizontal timings";
+ case MODE_V_ILLEGAL:
+ return "illegal vertical timings";
+ case MODE_BAD_WIDTH:
+ return "width requires unsupported line pitch";
+ case MODE_NOMODE:
+ return "no mode of this name";
+ case MODE_NO_INTERLACE:
+ return "interlace mode not supported";
+ case MODE_NO_DBLESCAN:
+ return "doublescan mode not supported";
+ case MODE_NO_VSCAN:
+ return "multiscan mode not supported";
+ case MODE_MEM:
+ return "insufficient memory for mode";
+ case MODE_VIRTUAL_X:
+ return "width too large for virtual size";
+ case MODE_VIRTUAL_Y:
+ return "height too large for virtual size";
+ case MODE_MEM_VIRT:
+ return "insufficient memory given virtual size";
+ case MODE_NOCLOCK:
+ return "no clock available for mode";
+ case MODE_CLOCK_HIGH:
+ return "mode clock too high";
+ case MODE_CLOCK_LOW:
+ return "mode clock too low";
+ case MODE_CLOCK_RANGE:
+ return "bad mode clock/interlace/doublescan";
+ case MODE_BAD_HVALUE:
+ return "horizontal timing out of range";
+ case MODE_BAD_VVALUE:
+ return "vertical timing out of range";
+ case MODE_BAD_VSCAN:
+ return "VScan value out of range";
+ case MODE_HSYNC_NARROW:
+ return "horizontal sync too narrow";
+ case MODE_HSYNC_WIDE:
+ return "horizontal sync too wide";
+ case MODE_HBLANK_NARROW:
+ return "horizontal blanking too narrow";
+ case MODE_HBLANK_WIDE:
+ return "horizontal blanking too wide";
+ case MODE_VSYNC_NARROW:
+ return "vertical sync too narrow";
+ case MODE_VSYNC_WIDE:
+ return "vertical sync too wide";
+ case MODE_VBLANK_NARROW:
+ return "vertical blanking too narrow";
+ case MODE_VBLANK_WIDE:
+ return "vertical blanking too wide";
+ case MODE_PANEL:
+ return "exceeds panel dimensions";
+ case MODE_INTERLACE_WIDTH:
+ return "width too large for interlaced mode";
+ case MODE_ONE_WIDTH:
+ return "all modes must have the same width";
+ case MODE_ONE_HEIGHT:
+ return "all modes must have the same height";
+ case MODE_ONE_SIZE:
+ return "all modes must have the same resolution";
+ case MODE_BAD:
+ return "unknown reason";
+ case MODE_ERROR:
+ return "internal error";
+ default:
+ return "unknown";
+ }
+}
+
+/*
+ * xf86ShowClockRanges() -- Print the clock ranges allowed
+ * and the clock values scaled by ClockMulFactor and ClockDivFactor
+ */
+void
+xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges)
+{
+ ClockRangePtr cp;
+ int MulFactor = 1;
+ int DivFactor = 1;
+ int i, j;
+ int scaledClock;
+
+ for (cp = clockRanges; cp != NULL; cp = cp->next) {
+ DivFactor = max(1, cp->ClockDivFactor);
+ MulFactor = max(1, cp->ClockMulFactor);
+ if (scrp->progClock) {
+ if (cp->minClock) {
+ if (cp->maxClock) {
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Clock range: %6.2f to %6.2f MHz\n",
+ (double)cp->minClock / 1000.0,
+ (double)cp->maxClock / 1000.0);
+ } else {
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Minimum clock: %6.2f MHz\n",
+ (double)cp->minClock / 1000.0);
+ }
+ } else {
+ if (cp->maxClock) {
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Maximum clock: %6.2f MHz\n",
+ (double)cp->maxClock / 1000.0);
+ }
+ }
+ } else if (DivFactor > 1 || MulFactor > 1) {
+ j = 0;
+ for (i = 0; i < scrp->numClocks; i++) {
+ scaledClock = (scrp->clock[i] * DivFactor) / MulFactor;
+ if (scaledClock >= cp->minClock && scaledClock <= cp->maxClock) {
+ if ((j % 8) == 0) {
+ if (j > 0)
+ xf86ErrorF("\n");
+ xf86DrvMsg(scrp->scrnIndex, X_INFO, "scaled clocks:");
+ }
+ xf86ErrorF(" %6.2f", (double)scaledClock / 1000.0);
+ j++;
+ }
+ }
+ xf86ErrorF("\n");
+ }
+ }
+}
+
+
+/*
+ * xf86FindClockRangeForMode() [... like the name says ...]
+ */
+static ClockRangePtr
+xf86FindClockRangeForMode(ClockRangePtr clockRanges, DisplayModePtr p)
+{
+ ClockRangePtr cp;
+
+ for (cp = clockRanges; ; cp = cp->next)
+ if (!cp ||
+ ((p->Clock >= cp->minClock) &&
+ (p->Clock <= cp->maxClock) &&
+ (cp->interlaceAllowed || !(p->Flags & V_INTERLACE)) &&
+ (cp->doubleScanAllowed ||
+ ((p->VScan <= 1) && !(p->Flags & V_DBLSCAN)))))
+ return cp;
+}
+
+
+/*
+ * xf86HandleBuiltinMode() - handles built-in modes
+ */
+static ModeStatus
+xf86HandleBuiltinMode(ScrnInfoPtr scrp,
+ DisplayModePtr p,
+ DisplayModePtr modep,
+ ClockRangePtr clockRanges,
+ Bool allowDiv2)
+{
+ ClockRangePtr cp;
+ int extraFlags = 0;
+ int MulFactor = 1;
+ int DivFactor = 1;
+ int clockIndex;
+
+ /* Reject previously rejected modes */
+ if (p->status != MODE_OK)
+ return p->status;
+
+ /* Reject previously considered modes */
+ if (p->prev)
+ return MODE_NOMODE;
+
+ if ((p->type & M_T_CLOCK_C) == M_T_CLOCK_C) {
+ /* Check clock is in range */
+ cp = xf86FindClockRangeForMode(clockRanges, p);
+ if (cp == NULL){
+ modep->type = p->type;
+ p->status = MODE_CLOCK_RANGE;
+ return MODE_CLOCK_RANGE;
+ }
+ DivFactor = cp->ClockDivFactor;
+ MulFactor = cp->ClockMulFactor;
+ if (!scrp->progClock) {
+ clockIndex = xf86GetNearestClock(scrp, p->Clock, allowDiv2,
+ cp->ClockDivFactor,
+ cp->ClockMulFactor, &extraFlags);
+ modep->Clock = (scrp->clock[clockIndex] * DivFactor)
+ / MulFactor;
+ modep->ClockIndex = clockIndex;
+ modep->SynthClock = scrp->clock[clockIndex];
+ if (extraFlags & V_CLKDIV2) {
+ modep->Clock /= 2;
+ modep->SynthClock /= 2;
+ }
+ } else {
+ modep->Clock = p->Clock;
+ modep->ClockIndex = -1;
+ modep->SynthClock = (modep->Clock * MulFactor)
+ / DivFactor;
+ }
+ modep->PrivFlags = cp->PrivFlags;
+ } else {
+ if(!scrp->progClock) {
+ modep->Clock = p->Clock;
+ modep->ClockIndex = p->ClockIndex;
+ modep->SynthClock = p->SynthClock;
+ } else {
+ modep->Clock = p->Clock;
+ modep->ClockIndex = -1;
+ modep->SynthClock = p->SynthClock;
+ }
+ modep->PrivFlags = p->PrivFlags;
+ }
+ modep->type = p->type;
+ modep->HDisplay = p->HDisplay;
+ modep->HSyncStart = p->HSyncStart;
+ modep->HSyncEnd = p->HSyncEnd;
+ modep->HTotal = p->HTotal;
+ modep->HSkew = p->HSkew;
+ modep->VDisplay = p->VDisplay;
+ modep->VSyncStart = p->VSyncStart;
+ modep->VSyncEnd = p->VSyncEnd;
+ modep->VTotal = p->VTotal;
+ modep->VScan = p->VScan;
+ modep->Flags = p->Flags | extraFlags;
+ modep->CrtcHDisplay = p->CrtcHDisplay;
+ modep->CrtcHBlankStart = p->CrtcHBlankStart;
+ modep->CrtcHSyncStart = p->CrtcHSyncStart;
+ modep->CrtcHSyncEnd = p->CrtcHSyncEnd;
+ modep->CrtcHBlankEnd = p->CrtcHBlankEnd;
+ modep->CrtcHTotal = p->CrtcHTotal;
+ modep->CrtcHSkew = p->CrtcHSkew;
+ modep->CrtcVDisplay = p->CrtcVDisplay;
+ modep->CrtcVBlankStart = p->CrtcVBlankStart;
+ modep->CrtcVSyncStart = p->CrtcVSyncStart;
+ modep->CrtcVSyncEnd = p->CrtcVSyncEnd;
+ modep->CrtcVBlankEnd = p->CrtcVBlankEnd;
+ modep->CrtcVTotal = p->CrtcVTotal;
+ modep->CrtcHAdjusted = p->CrtcHAdjusted;
+ modep->CrtcVAdjusted = p->CrtcVAdjusted;
+ modep->HSync = p->HSync;
+ modep->VRefresh = p->VRefresh;
+ modep->Private = p->Private;
+ modep->PrivSize = p->PrivSize;
+
+ p->prev = modep;
+
+ return MODE_OK;
+}
+
+static double
+ModeHSync(DisplayModePtr mode)
+{
+ double hsync = 0.0;
+
+ if (mode->HSync > 0.0)
+ hsync = mode->HSync;
+ else if (mode->HTotal > 0)
+ hsync = (float)mode->Clock / (float)mode->HTotal;
+
+ return hsync;
+}
+
+static double
+ModeVRefresh(DisplayModePtr mode)
+{
+ double refresh = 0.0;
+
+ if (mode->VRefresh > 0.0)
+ refresh = mode->VRefresh;
+ else if (mode->HTotal > 0 && mode->VTotal > 0) {
+ refresh = mode->Clock * 1000.0 / mode->HTotal / mode->VTotal;
+ if (mode->Flags & V_INTERLACE)
+ refresh *= 2.0;
+ if (mode->Flags & V_DBLSCAN)
+ refresh /= 2.0;
+ if (mode->VScan > 1)
+ refresh /= (float)(mode->VScan);
+ }
+ return refresh;
+}
+
+/*
+ * xf86LookupMode
+ *
+ * This function returns a mode from the given list which matches the
+ * given name. When multiple modes with the same name are available,
+ * the method of picking the matching mode is determined by the
+ * strategy selected.
+ *
+ * This function takes the following parameters:
+ * scrp ScrnInfoPtr
+ * modep pointer to the returned mode, which must have the name
+ * field filled in.
+ * clockRanges a list of clock ranges. This is optional when all the
+ * modes are built-in modes.
+ * strategy how to decide which mode to use from multiple modes with
+ * the same name
+ *
+ * In addition, the following fields from the ScrnInfoRec are used:
+ * modePool the list of monitor modes compatible with the driver
+ * clocks a list of discrete clocks
+ * numClocks number of discrete clocks
+ * progClock clock is programmable
+ *
+ * If a mode was found, its values are filled in to the area pointed to
+ * by modep, If a mode was not found the return value indicates the
+ * reason.
+ */
+
+ModeStatus
+xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
+ ClockRangePtr clockRanges, LookupModeFlags strategy)
+{
+ DisplayModePtr p, bestMode = NULL;
+ ClockRangePtr cp;
+ int i, k, gap, minimumGap = CLOCK_TOLERANCE + 1;
+ double refresh, bestRefresh = 0.0;
+ Bool found = FALSE;
+ int extraFlags = 0;
+ int clockIndex = -1;
+ int MulFactor = 1;
+ int DivFactor = 1;
+ int ModePrivFlags = 0;
+ ModeStatus status = MODE_NOMODE;
+ Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0;
+ Bool haveBuiltin;
+
+ strategy &= ~(LOOKUP_CLKDIV2 | LOOKUP_OPTIONAL_TOLERANCES);
+
+ /* Some sanity checking */
+ if (scrp == NULL || scrp->modePool == NULL ||
+ (!scrp->progClock && scrp->numClocks == 0)) {
+ ErrorF("xf86LookupMode: called with invalid scrnInfoRec\n");
+ return MODE_ERROR;
+ }
+ if (modep == NULL || modep->name == NULL) {
+ ErrorF("xf86LookupMode: called with invalid modep\n");
+ return MODE_ERROR;
+ }
+ for (cp = clockRanges; cp != NULL; cp = cp->next) {
+ /* DivFactor and MulFactor must be > 0 */
+ cp->ClockDivFactor = max(1, cp->ClockDivFactor);
+ cp->ClockMulFactor = max(1, cp->ClockMulFactor);
+ }
+
+ haveBuiltin = FALSE;
+ /* Scan the mode pool for matching names */
+ for (p = scrp->modePool; p != NULL; p = p->next) {
+ if (strcmp(p->name, modep->name) == 0) {
+ /*
+ * Requested mode is a built-in mode. Don't let the user
+ * override it.
+ * Since built-in modes always come before user specified
+ * modes it will always be found first.
+ */
+ if (p->type & M_T_BUILTIN) {
+ haveBuiltin = TRUE;
+ }
+
+ if (haveBuiltin && !(p->type & M_T_BUILTIN))
+ continue;
+
+ /* Skip over previously rejected modes */
+ if (p->status != MODE_OK) {
+ if (!found)
+ status = p->status;
+ continue;
+ }
+
+ /* Skip over previously considered modes */
+ if (p->prev)
+ continue;
+
+ if (p->type & M_T_BUILTIN) {
+ return xf86HandleBuiltinMode(scrp, p,modep, clockRanges,
+ allowDiv2);
+ }
+
+ /* Check clock is in range */
+ cp = xf86FindClockRangeForMode(clockRanges, p);
+ if (cp == NULL) {
+ /*
+ * XXX Could do more here to provide a more detailed
+ * reason for not finding a mode.
+ */
+ p->status = MODE_CLOCK_RANGE;
+ if (!found)
+ status = MODE_CLOCK_RANGE;
+ continue;
+ }
+
+ /*
+ * If programmable clock and strategy is not LOOKUP_BEST_REFRESH,
+ * the required mode has been found, otherwise record the refresh
+ * and continue looking.
+ */
+ if (scrp->progClock) {
+ found = TRUE;
+ if (strategy != LOOKUP_BEST_REFRESH) {
+ bestMode = p;
+ DivFactor = cp->ClockDivFactor;
+ MulFactor = cp->ClockMulFactor;
+ ModePrivFlags = cp->PrivFlags;
+ break;
+ }
+ refresh = ModeVRefresh(p);
+ if (p->Flags & V_INTERLACE)
+ refresh /= INTERLACE_REFRESH_WEIGHT;
+ if (refresh > bestRefresh) {
+ bestMode = p;
+ DivFactor = cp->ClockDivFactor;
+ MulFactor = cp->ClockMulFactor;
+ ModePrivFlags = cp->PrivFlags;
+ bestRefresh = refresh;
+ }
+ continue;
+ }
+
+ /*
+ * Clock is in range, so if it is not a programmable clock, find
+ * a matching clock.
+ */
+
+ i = xf86GetNearestClock(scrp, p->Clock, allowDiv2,
+ cp->ClockDivFactor, cp->ClockMulFactor, &k);
+ /*
+ * If the clock is too far from the requested clock, this
+ * mode is no good.
+ */
+ if (k & V_CLKDIV2)
+ gap = abs((p->Clock * 2) -
+ ((scrp->clock[i] * cp->ClockDivFactor) / cp->ClockMulFactor));
+ else
+ gap = abs(p->Clock -
+ ((scrp->clock[i] * cp->ClockDivFactor) / cp->ClockMulFactor));
+ if (gap > minimumGap) {
+ p->status = MODE_NOCLOCK;
+ if (!found)
+ status = MODE_NOCLOCK;
+ continue;
+ }
+ found = TRUE;
+
+ if (strategy == LOOKUP_BEST_REFRESH) {
+ refresh = ModeVRefresh(p);
+ if (p->Flags & V_INTERLACE)
+ refresh /= INTERLACE_REFRESH_WEIGHT;
+ if (refresh > bestRefresh) {
+ bestMode = p;
+ DivFactor = cp->ClockDivFactor;
+ MulFactor = cp->ClockMulFactor;
+ ModePrivFlags = cp->PrivFlags;
+ extraFlags = k;
+ clockIndex = i;
+ bestRefresh = refresh;
+ }
+ continue;
+ }
+ if (strategy == LOOKUP_CLOSEST_CLOCK) {
+ if (gap < minimumGap) {
+ bestMode = p;
+ DivFactor = cp->ClockDivFactor;
+ MulFactor = cp->ClockMulFactor;
+ ModePrivFlags = cp->PrivFlags;
+ extraFlags = k;
+ clockIndex = i;
+ minimumGap = gap;
+ }
+ continue;
+ }
+ /*
+ * If strategy is neither LOOKUP_BEST_REFRESH or
+ * LOOKUP_CLOSEST_CLOCK the required mode has been found.
+ */
+ bestMode = p;
+ DivFactor = cp->ClockDivFactor;
+ MulFactor = cp->ClockMulFactor;
+ ModePrivFlags = cp->PrivFlags;
+ extraFlags = k;
+ clockIndex = i;
+ break;
+ }
+ }
+ if (!found || bestMode == NULL)
+ return status;
+
+ /* Fill in the mode parameters */
+ if (scrp->progClock) {
+ modep->Clock = bestMode->Clock;
+ modep->ClockIndex = -1;
+ modep->SynthClock = (modep->Clock * MulFactor) / DivFactor;
+ } else {
+ modep->Clock = (scrp->clock[clockIndex] * DivFactor) / MulFactor;
+ modep->ClockIndex = clockIndex;
+ modep->SynthClock = scrp->clock[clockIndex];
+ if (extraFlags & V_CLKDIV2) {
+ modep->Clock /= 2;
+ modep->SynthClock /= 2;
+ }
+ }
+ modep->type = bestMode->type;
+ modep->PrivFlags = ModePrivFlags;
+ modep->HDisplay = bestMode->HDisplay;
+ modep->HSyncStart = bestMode->HSyncStart;
+ modep->HSyncEnd = bestMode->HSyncEnd;
+ modep->HTotal = bestMode->HTotal;
+ modep->HSkew = bestMode->HSkew;
+ modep->VDisplay = bestMode->VDisplay;
+ modep->VSyncStart = bestMode->VSyncStart;
+ modep->VSyncEnd = bestMode->VSyncEnd;
+ modep->VTotal = bestMode->VTotal;
+ modep->VScan = bestMode->VScan;
+ modep->Flags = bestMode->Flags | extraFlags;
+ modep->CrtcHDisplay = bestMode->CrtcHDisplay;
+ modep->CrtcHBlankStart = bestMode->CrtcHBlankStart;
+ modep->CrtcHSyncStart = bestMode->CrtcHSyncStart;
+ modep->CrtcHSyncEnd = bestMode->CrtcHSyncEnd;
+ modep->CrtcHBlankEnd = bestMode->CrtcHBlankEnd;
+ modep->CrtcHTotal = bestMode->CrtcHTotal;
+ modep->CrtcHSkew = bestMode->CrtcHSkew;
+ modep->CrtcVDisplay = bestMode->CrtcVDisplay;
+ modep->CrtcVBlankStart = bestMode->CrtcVBlankStart;
+ modep->CrtcVSyncStart = bestMode->CrtcVSyncStart;
+ modep->CrtcVSyncEnd = bestMode->CrtcVSyncEnd;
+ modep->CrtcVBlankEnd = bestMode->CrtcVBlankEnd;
+ modep->CrtcVTotal = bestMode->CrtcVTotal;
+ modep->CrtcHAdjusted = bestMode->CrtcHAdjusted;
+ modep->CrtcVAdjusted = bestMode->CrtcVAdjusted;
+ modep->HSync = bestMode->HSync;
+ modep->VRefresh = bestMode->VRefresh;
+ modep->Private = bestMode->Private;
+ modep->PrivSize = bestMode->PrivSize;
+
+ bestMode->prev = modep;
+
+ return MODE_OK;
+}
+
+
+/*
+ * xf86SetModeCrtc
+ *
+ * Initialises the Crtc parameters for a mode. The initialisation includes
+ * adjustments for interlaced and double scan modes.
+ */
+static void
+xf86SetModeCrtc(DisplayModePtr p, int adjustFlags)
+{
+ if ((p == NULL) || ((p->type & M_T_CRTC_C) == M_T_BUILTIN))
+ return;
+
+ p->CrtcHDisplay = p->HDisplay;
+ p->CrtcHSyncStart = p->HSyncStart;
+ p->CrtcHSyncEnd = p->HSyncEnd;
+ p->CrtcHTotal = p->HTotal;
+ p->CrtcHSkew = p->HSkew;
+ p->CrtcVDisplay = p->VDisplay;
+ p->CrtcVSyncStart = p->VSyncStart;
+ p->CrtcVSyncEnd = p->VSyncEnd;
+ p->CrtcVTotal = p->VTotal;
+ if (p->Flags & V_INTERLACE) {
+ if (adjustFlags & INTERLACE_HALVE_V) {
+ p->CrtcVDisplay /= 2;
+ p->CrtcVSyncStart /= 2;
+ p->CrtcVSyncEnd /= 2;
+ p->CrtcVTotal /= 2;
+ }
+ /* Force interlaced modes to have an odd VTotal */
+ /* maybe we should only do this when INTERLACE_HALVE_V is set? */
+ p->CrtcVTotal |= 1;
+ }
+
+ if (p->Flags & V_DBLSCAN) {
+ p->CrtcVDisplay *= 2;
+ p->CrtcVSyncStart *= 2;
+ p->CrtcVSyncEnd *= 2;
+ p->CrtcVTotal *= 2;
+ }
+ if (p->VScan > 1) {
+ p->CrtcVDisplay *= p->VScan;
+ p->CrtcVSyncStart *= p->VScan;
+ p->CrtcVSyncEnd *= p->VScan;
+ p->CrtcVTotal *= p->VScan;
+ }
+ p->CrtcHAdjusted = FALSE;
+ p->CrtcVAdjusted = FALSE;
+
+ /*
+ * XXX
+ *
+ * The following is taken from VGA, but applies to other cores as well.
+ */
+ p->CrtcVBlankStart = min(p->CrtcVSyncStart, p->CrtcVDisplay);
+ p->CrtcVBlankEnd = max(p->CrtcVSyncEnd, p->CrtcVTotal);
+ if ((p->CrtcVBlankEnd - p->CrtcVBlankStart) >= 127) {
+ /*
+ * V Blanking size must be < 127.
+ * Moving blank start forward is safer than moving blank end
+ * back, since monitors clamp just AFTER the sync pulse (or in
+ * the sync pulse), but never before.
+ */
+ p->CrtcVBlankStart = p->CrtcVBlankEnd - 127;
+ /*
+ * If VBlankStart is now > VSyncStart move VBlankStart
+ * to VSyncStart using the maximum width that fits into
+ * VTotal.
+ */
+ if (p->CrtcVBlankStart > p->CrtcVSyncStart) {
+ p->CrtcVBlankStart = p->CrtcVSyncStart;
+ p->CrtcVBlankEnd = min(p->CrtcHBlankStart + 127, p->CrtcVTotal);
+ }
+ }
+ p->CrtcHBlankStart = min(p->CrtcHSyncStart, p->CrtcHDisplay);
+ p->CrtcHBlankEnd = max(p->CrtcHSyncEnd, p->CrtcHTotal);
+
+ if ((p->CrtcHBlankEnd - p->CrtcHBlankStart) >= 63 * 8) {
+ /*
+ * H Blanking size must be < 63*8. Same remark as above.
+ */
+ p->CrtcHBlankStart = p->CrtcHBlankEnd - 63 * 8;
+ if (p->CrtcHBlankStart > p->CrtcHSyncStart) {
+ p->CrtcHBlankStart = p->CrtcHSyncStart;
+ p->CrtcHBlankEnd = min(p->CrtcHBlankStart + 63 * 8, p->CrtcHTotal);
+ }
+ }
+}
+
+/*
+ * xf86CheckModeForMonitor
+ *
+ * This function takes a mode and monitor description, and determines
+ * if the mode is valid for the monitor.
+ */
+ModeStatus
+xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor)
+{
+ int i;
+
+ /* Sanity checks */
+ if (mode == NULL || monitor == NULL) {
+ ErrorF("xf86CheckModeForMonitor: called with invalid parameters\n");
+ return MODE_ERROR;
+ }
+
+#ifdef DEBUG
+ ErrorF("xf86CheckModeForMonitor(%p %s, %p %s)\n",
+ mode, mode->name, monitor, monitor->id);
+#endif
+
+ if (monitor->DDC) {
+ xf86MonPtr DDC = (xf86MonPtr)(monitor->DDC);
+ struct detailed_monitor_section* detMon;
+ struct monitor_ranges *mon_range;
+ int i;
+
+ mon_range = NULL;
+ for (i = 0; i < 4; i++) {
+ detMon = &DDC->det_mon[i];
+ if(detMon->type == DS_RANGES) {
+ mon_range = &detMon->section.ranges;
+ }
+ }
+ if (mon_range) {
+ /* mode->Clock in kHz, DDC in MHz */
+ if (mon_range->max_clock < 2550 &&
+ mode->Clock / 1000.0 > mon_range->max_clock) {
+ xf86Msg(X_WARNING,
+ "(%s,%s) mode clock %gMHz exceeds DDC maximum %dMHz\n",
+ mode->name, monitor->id,
+ mode->Clock/1000.0, mon_range->max_clock);
+ }
+ }
+ }
+
+ /* Some basic mode validity checks */
+ if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart ||
+ mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal)
+ return MODE_H_ILLEGAL;
+
+ if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart ||
+ mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal)
+ return MODE_V_ILLEGAL;
+
+ if (monitor->nHsync > 0) {
+ /* Check hsync against the allowed ranges */
+ float hsync = ModeHSync(mode);
+ for (i = 0; i < monitor->nHsync; i++)
+ if ((hsync > monitor->hsync[i].lo * (1.0 - SYNC_TOLERANCE)) &&
+ (hsync < monitor->hsync[i].hi * (1.0 + SYNC_TOLERANCE)))
+ break;
+
+ /* Now see whether we ran out of sync ranges without finding a match */
+ if (i == monitor->nHsync)
+ return MODE_HSYNC;
+ }
+
+ if (monitor->nVrefresh > 0) {
+ /* Check vrefresh against the allowed ranges */
+ float vrefrsh = ModeVRefresh(mode);
+ for (i = 0; i < monitor->nVrefresh; i++)
+ if ((vrefrsh > monitor->vrefresh[i].lo * (1.0 - SYNC_TOLERANCE)) &&
+ (vrefrsh < monitor->vrefresh[i].hi * (1.0 + SYNC_TOLERANCE)))
+ break;
+
+ /* Now see whether we ran out of refresh ranges without finding a match */
+ if (i == monitor->nVrefresh)
+ return MODE_VSYNC;
+ }
+
+ /* Force interlaced modes to have an odd VTotal */
+ if (mode->Flags & V_INTERLACE)
+ mode->CrtcVTotal = mode->VTotal |= 1;
+
+ return MODE_OK;
+}
+
+/*
+ * xf86CheckModeSize
+ *
+ * An internal routine to check if a mode fits in video memory. This tries to
+ * avoid overflows that would otherwise occur when video memory size is greater
+ * than 256MB.
+ */
+static Bool
+xf86CheckModeSize(ScrnInfoPtr scrp, int w, int x, int y)
+{
+ int bpp = scrp->fbFormat.bitsPerPixel,
+ pad = scrp->fbFormat.scanlinePad;
+ int lineWidth, lastWidth;
+
+ if (scrp->depth == 4)
+ pad *= 4; /* 4 planes */
+
+ /* Sanity check */
+ if ((w < 0) || (x < 0) || (y <= 0))
+ return FALSE;
+
+ lineWidth = (((w * bpp) + pad - 1) / pad) * pad;
+ lastWidth = x * bpp;
+
+ /*
+ * At this point, we need to compare
+ *
+ * (lineWidth * (y - 1)) + lastWidth
+ *
+ * against
+ *
+ * scrp->videoRam * (1024 * 8)
+ *
+ * These are bit quantities. To avoid overflows, do the comparison in
+ * terms of BITMAP_SCANLINE_PAD units. This assumes BITMAP_SCANLINE_PAD
+ * is a power of 2. We currently use 32, which limits us to a video
+ * memory size of 8GB.
+ */
+
+ lineWidth = (lineWidth + (BITMAP_SCANLINE_PAD - 1)) / BITMAP_SCANLINE_PAD;
+ lastWidth = (lastWidth + (BITMAP_SCANLINE_PAD - 1)) / BITMAP_SCANLINE_PAD;
+
+ if ((lineWidth * (y - 1) + lastWidth) >
+ (scrp->videoRam * ((1024 * 8) / BITMAP_SCANLINE_PAD)))
+ return FALSE;
+
+ return TRUE;
+}
+
+/*
+ * xf86InitialCheckModeForDriver
+ *
+ * This function checks if a mode satisfies a driver's initial requirements:
+ * - mode size fits within the available pixel area (memory)
+ * - width lies within the range of supported line pitches
+ * - mode size fits within virtual size (if fixed)
+ * - horizontal timings are in range
+ *
+ * This function takes the following parameters:
+ * scrp ScrnInfoPtr
+ * mode mode to check
+ * maxPitch (optional) maximum line pitch
+ * virtualX (optional) virtual width requested
+ * virtualY (optional) virtual height requested
+ *
+ * In addition, the following fields from the ScrnInfoRec are used:
+ * monitor pointer to structure for monitor section
+ * fbFormat pixel format for the framebuffer
+ * videoRam video memory size (in kB)
+ * maxHValue maximum horizontal timing value
+ * maxVValue maximum vertical timing value
+ */
+
+ModeStatus
+xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode,
+ ClockRangePtr clockRanges,
+ LookupModeFlags strategy,
+ int maxPitch, int virtualX, int virtualY)
+{
+ ClockRangePtr cp;
+ ModeStatus status;
+ Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0;
+ int i, needDiv2;
+
+ /* Sanity checks */
+ if (!scrp || !mode || !clockRanges) {
+ ErrorF("xf86InitialCheckModeForDriver: "
+ "called with invalid parameters\n");
+ return MODE_ERROR;
+ }
+
+#ifdef DEBUG
+ ErrorF("xf86InitialCheckModeForDriver(%p, %p %s, %p, 0x%x, %d, %d, %d)\n",
+ scrp, mode, mode->name , clockRanges, strategy, maxPitch, virtualX, virtualY);
+#endif
+
+ /* Some basic mode validity checks */
+ if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart ||
+ mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal)
+ return MODE_H_ILLEGAL;
+
+ if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart ||
+ mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal)
+ return MODE_V_ILLEGAL;
+
+ if (!xf86CheckModeSize(scrp, mode->HDisplay, mode->HDisplay,
+ mode->VDisplay))
+ return MODE_MEM;
+
+ if (maxPitch > 0 && mode->HDisplay > maxPitch)
+ return MODE_BAD_WIDTH;
+
+ if (virtualX > 0 && mode->HDisplay > virtualX)
+ return MODE_VIRTUAL_X;
+
+ if (virtualY > 0 && mode->VDisplay > virtualY)
+ return MODE_VIRTUAL_Y;
+
+ if (scrp->maxHValue > 0 && mode->HTotal > scrp->maxHValue)
+ return MODE_BAD_HVALUE;
+
+ if (scrp->maxVValue > 0 && mode->VTotal > scrp->maxVValue)
+ return MODE_BAD_VVALUE;
+
+ /*
+ * The use of the DisplayModeRec's Crtc* and SynthClock elements below is
+ * provisional, in that they are later reused by the driver at mode-set
+ * time. Here, they are temporarily enlisted to contain the mode timings
+ * as seen by the CRT or panel (rather than the CRTC). The driver's
+ * ValidMode() is allowed to modify these so it can deal with such things
+ * as mode stretching and/or centering. The driver should >NOT< modify the
+ * user-supplied values as these are reported back when mode validation is
+ * said and done.
+ */
+ /*
+ * NOTE: We (ab)use the mode->Crtc* values here to store timing
+ * information for the calculation of Hsync and Vrefresh. Before
+ * these values are calculated the driver is given the opportunity
+ * to either set these HSync and VRefresh itself or modify the timing
+ * values.
+ * The difference to the final calculation is small but imortand:
+ * here we pass the flag INTERLACE_HALVE_V regardless if the driver
+ * sets it or not. This way our calculation of VRefresh has the same
+ * effect as if we do if (flags & V_INTERLACE) refresh *= 2.0
+ * This dual use of the mode->Crtc* values will certainly create
+ * confusion and is bad software design. However since it's part of
+ * the driver API it's hard to change.
+ */
+
+ if (scrp->ValidMode) {
+
+ xf86SetModeCrtc(mode, INTERLACE_HALVE_V);
+
+ cp = xf86FindClockRangeForMode(clockRanges, mode);
+ if (!cp)
+ return MODE_CLOCK_RANGE;
+
+ if (cp->ClockMulFactor < 1)
+ cp->ClockMulFactor = 1;
+ if (cp->ClockDivFactor < 1)
+ cp->ClockDivFactor = 1;
+
+ /*
+ * XXX The effect of clock dividers and multipliers on the monitor's
+ * pixel clock needs to be verified.
+ */
+ if (scrp->progClock) {
+ mode->SynthClock = mode->Clock;
+ } else {
+ i = xf86GetNearestClock(scrp, mode->Clock, allowDiv2,
+ cp->ClockDivFactor, cp->ClockMulFactor,
+ &needDiv2);
+ mode->SynthClock = (scrp->clock[i] * cp->ClockDivFactor) /
+ cp->ClockMulFactor;
+ if (needDiv2 & V_CLKDIV2)
+ mode->SynthClock /= 2;
+ }
+
+ status = (*scrp->ValidMode)(scrp->scrnIndex, mode, FALSE,
+ MODECHECK_INITIAL);
+ if (status != MODE_OK)
+ return status;
+
+ if (mode->HSync <= 0.0)
+ mode->HSync = (float)mode->SynthClock / (float)mode->CrtcHTotal;
+ if (mode->VRefresh <= 0.0)
+ mode->VRefresh = (mode->SynthClock * 1000.0)
+ / (mode->CrtcHTotal * mode->CrtcVTotal);
+ }
+
+ mode->HSync = ModeHSync(mode);
+ mode->VRefresh = ModeVRefresh(mode);
+
+ /* Assume it is OK */
+ return MODE_OK;
+}
+
+/*
+ * xf86CheckModeForDriver
+ *
+ * This function is for checking modes while the server is running (for
+ * use mainly by the VidMode extension).
+ *
+ * This function checks if a mode satisfies a driver's requirements:
+ * - width lies within the line pitch
+ * - mode size fits within virtual size
+ * - horizontal/vertical timings are in range
+ *
+ * This function takes the following parameters:
+ * scrp ScrnInfoPtr
+ * mode mode to check
+ * flags not (currently) used
+ *
+ * In addition, the following fields from the ScrnInfoRec are used:
+ * maxHValue maximum horizontal timing value
+ * maxVValue maximum vertical timing value
+ * virtualX virtual width
+ * virtualY virtual height
+ * clockRanges allowable clock ranges
+ */
+
+ModeStatus
+xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags)
+{
+ ClockRangesPtr cp;
+ int i, k, gap, minimumGap = CLOCK_TOLERANCE + 1;
+ int extraFlags = 0;
+ int clockIndex = -1;
+ int MulFactor = 1;
+ int DivFactor = 1;
+ int ModePrivFlags = 0;
+ Bool allowDiv2;
+ ModeStatus status = MODE_NOMODE;
+
+ /* Some sanity checking */
+ if (scrp == NULL || (!scrp->progClock && scrp->numClocks == 0)) {
+ ErrorF("xf86CheckModeForDriver: called with invalid scrnInfoRec\n");
+ return MODE_ERROR;
+ }
+ if (mode == NULL) {
+ ErrorF("xf86CheckModeForDriver: called with invalid modep\n");
+ return MODE_ERROR;
+ }
+
+ /* Check the mode size */
+ if (mode->HDisplay > scrp->virtualX)
+ return MODE_VIRTUAL_X;
+
+ if (mode->VDisplay > scrp->virtualY)
+ return MODE_VIRTUAL_Y;
+
+ if (scrp->maxHValue > 0 && mode->HTotal > scrp->maxHValue)
+ return MODE_BAD_HVALUE;
+
+ if (scrp->maxVValue > 0 && mode->VTotal > scrp->maxVValue)
+ return MODE_BAD_VVALUE;
+
+ for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) {
+ /* DivFactor and MulFactor must be > 0 */
+ cp->ClockDivFactor = max(1, cp->ClockDivFactor);
+ cp->ClockMulFactor = max(1, cp->ClockMulFactor);
+ }
+
+ if (scrp->progClock) {
+ /* Check clock is in range */
+ for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) {
+ if ((cp->minClock <= mode->Clock) &&
+ (cp->maxClock >= mode->Clock) &&
+ (cp->interlaceAllowed || !(mode->Flags & V_INTERLACE)) &&
+ (cp->doubleScanAllowed ||
+ ((!(mode->Flags & V_DBLSCAN)) && (mode->VScan <= 1))))
+ break;
+ }
+ if (cp == NULL) {
+ return MODE_CLOCK_RANGE;
+ }
+ /*
+ * If programmable clock the required mode has been found
+ */
+ DivFactor = cp->ClockDivFactor;
+ MulFactor = cp->ClockMulFactor;
+ ModePrivFlags = cp->PrivFlags;
+ } else {
+ status = MODE_CLOCK_RANGE;
+ /* Check clock is in range */
+ for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) {
+ if ((cp->minClock <= mode->Clock) &&
+ (cp->maxClock >= mode->Clock) &&
+ (cp->interlaceAllowed || !(mode->Flags & V_INTERLACE)) &&
+ (cp->doubleScanAllowed ||
+ ((!(mode->Flags & V_DBLSCAN)) && (mode->VScan <= 1)))) {
+
+ /*
+ * Clock is in range, so if it is not a programmable clock,
+ * find a matching clock.
+ */
+
+ allowDiv2 = (cp->strategy & LOOKUP_CLKDIV2) != 0;
+ i = xf86GetNearestClock(scrp, mode->Clock, allowDiv2,
+ cp->ClockDivFactor, cp->ClockMulFactor, &k);
+ /*
+ * If the clock is too far from the requested clock, this
+ * mode is no good.
+ */
+ if (k & V_CLKDIV2)
+ gap = abs((mode->Clock * 2) -
+ ((scrp->clock[i] * cp->ClockDivFactor) /
+ cp->ClockMulFactor));
+ else
+ gap = abs(mode->Clock -
+ ((scrp->clock[i] * cp->ClockDivFactor) /
+ cp->ClockMulFactor));
+ if (gap > minimumGap) {
+ status = MODE_NOCLOCK;
+ continue;
+ }
+
+ DivFactor = cp->ClockDivFactor;
+ MulFactor = cp->ClockMulFactor;
+ ModePrivFlags = cp->PrivFlags;
+ extraFlags = k;
+ clockIndex = i;
+ break;
+ }
+ }
+ if (cp == NULL)
+ return status;
+ }
+
+ /* Fill in the mode parameters */
+ if (scrp->progClock) {
+ mode->ClockIndex = -1;
+ mode->SynthClock = (mode->Clock * MulFactor) / DivFactor;
+ } else {
+ mode->Clock = (scrp->clock[clockIndex] * DivFactor) / MulFactor;
+ mode->ClockIndex = clockIndex;
+ mode->SynthClock = scrp->clock[clockIndex];
+ if (extraFlags & V_CLKDIV2) {
+ mode->Clock /= 2;
+ mode->SynthClock /= 2;
+ }
+ }
+ mode->PrivFlags = ModePrivFlags;
+
+ return MODE_OK;
+}
+
+/*
+ * xf86ValidateModes
+ *
+ * This function takes a set of mode names, modes and limiting conditions,
+ * and selects a set of modes and parameters based on those conditions.
+ *
+ * This function takes the following parameters:
+ * scrp ScrnInfoPtr
+ * availModes the list of modes available for the monitor
+ * modeNames (optional) list of mode names that the screen is requesting
+ * clockRanges a list of clock ranges
+ * linePitches (optional) a list of line pitches
+ * minPitch (optional) minimum line pitch (in pixels)
+ * maxPitch (optional) maximum line pitch (in pixels)
+ * pitchInc (mandatory) pitch increment (in bits)
+ * minHeight (optional) minimum virtual height (in pixels)
+ * maxHeight (optional) maximum virtual height (in pixels)
+ * virtualX (optional) virtual width requested (in pixels)
+ * virtualY (optional) virtual height requested (in pixels)
+ * apertureSize size of video aperture (in bytes)
+ * strategy how to decide which mode to use from multiple modes with
+ * the same name
+ *
+ * In addition, the following fields from the ScrnInfoRec are used:
+ * clocks a list of discrete clocks
+ * numClocks number of discrete clocks
+ * progClock clock is programmable
+ * monitor pointer to structure for monitor section
+ * fbFormat format of the framebuffer
+ * videoRam video memory size
+ * maxHValue maximum horizontal timing value
+ * maxVValue maximum vertical timing value
+ * xInc horizontal timing increment (defaults to 8 pixels)
+ *
+ * The function fills in the following ScrnInfoRec fields:
+ * modePool A subset of the modes available to the monitor which
+ * are compatible with the driver.
+ * modes one mode entry for each of the requested modes, with the
+ * status field filled in to indicate if the mode has been
+ * accepted or not.
+ * virtualX the resulting virtual width
+ * virtualY the resulting virtual height
+ * displayWidth the resulting line pitch
+ *
+ * The function's return value is the number of matching modes found, or -1
+ * if an unrecoverable error was encountered.
+ */
+
+int
+xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
+ char **modeNames, ClockRangePtr clockRanges,
+ int *linePitches, int minPitch, int maxPitch, int pitchInc,
+ int minHeight, int maxHeight, int virtualX, int virtualY,
+ int apertureSize, LookupModeFlags strategy)
+{
+ DisplayModePtr p, q, r, new, last, *endp;
+ int i, numModes = 0;
+ ModeStatus status;
+ int linePitch = -1, virtX = 0, virtY = 0;
+ int newLinePitch, newVirtX, newVirtY;
+ int modeSize; /* in pixels */
+ Bool validateAllDefaultModes = FALSE;
+ Bool userModes = FALSE;
+ int saveType;
+ PixmapFormatRec *BankFormat;
+ ClockRangePtr cp;
+ ClockRangesPtr storeClockRanges;
+ struct monitor_ranges *mon_range = NULL;
+ double targetRefresh = 0.0;
+ int numTimings = 0;
+ range hsync[MAX_HSYNC];
+ range vrefresh[MAX_VREFRESH];
+
+#ifdef DEBUG
+ ErrorF("xf86ValidateModes(%p, %p, %p, %p,\n\t\t %p, %d, %d, %d, %d, %d, %d, %d, %d, 0x%x)\n",
+ scrp, availModes, modeNames, clockRanges,
+ linePitches, minPitch, maxPitch, pitchInc,
+ minHeight, maxHeight, virtualX, virtualY,
+ apertureSize, strategy
+ );
+#endif
+
+ /* Some sanity checking */
+ if (scrp == NULL || scrp->name == NULL || !scrp->monitor ||
+ (!scrp->progClock && scrp->numClocks == 0)) {
+ ErrorF("xf86ValidateModes: called with invalid scrnInfoRec\n");
+ return -1;
+ }
+ if (linePitches != NULL && linePitches[0] <= 0) {
+ ErrorF("xf86ValidateModes: called with invalid linePitches\n");
+ return -1;
+ }
+ if (pitchInc <= 0) {
+ ErrorF("xf86ValidateModes: called with invalid pitchInc\n");
+ return -1;
+ }
+ if ((virtualX > 0) != (virtualY > 0)) {
+ ErrorF("xf86ValidateModes: called with invalid virtual resolution\n");
+ return -1;
+ }
+
+ /*
+ * Probe monitor so that we can enforce/warn about its limits.
+ * If one or more DS_RANGES descriptions are present, use the parameters
+ * that they provide. Otherwise, deduce limits based on the modes that
+ * are shown as supported via standard and detailed timings.
+ *
+ * XXX The full potential of the DDC/EDID data still isn't being tapped.
+ */
+ if (scrp->monitor->DDC) {
+ MonPtr monitor = scrp->monitor;
+ xf86MonPtr DDC = (xf86MonPtr)(scrp->monitor->DDC);
+ int i, j;
+ float hmin = 1e6, hmax = 0.0, vmin = 1e6, vmax = 0.0;
+ float h;
+ struct std_timings *t;
+ struct detailed_timings *dt;
+
+ numTimings = 0;
+ for (i = 0; i < DET_TIMINGS; i++) {
+ switch (DDC->det_mon[i].type) {
+ case DS_RANGES:
+ mon_range = &DDC->det_mon[i].section.ranges;
+ hsync[numTimings].lo = mon_range->min_h;
+ hsync[numTimings].hi = mon_range->max_h;
+ vrefresh[numTimings].lo = mon_range->min_v;
+ vrefresh[numTimings].hi = mon_range->max_v;
+ numTimings++;
+ break;
+
+ case DS_STD_TIMINGS:
+ t = DDC->det_mon[i].section.std_t;
+ for (j = 0; j < 5; j++) {
+ if (t[j].hsize > 256) { /* sanity check */
+ if (t[j].refresh < vmin)
+ vmin = t[i].refresh;
+ if (t[j].refresh > vmax)
+ vmax = t[i].refresh;
+ /*
+ * For typical modes this is a reasonable estimate
+ * of the horizontal sync rate.
+ */
+ h = t[j].refresh * 1.07 * t[j].vsize / 1000.0;
+ if (h < hmin)
+ hmin = h;
+ if (h > hmax)
+ hmax = h;
+ }
+ }
+ break;
+
+ case DT:
+ dt = &DDC->det_mon[i].section.d_timings;
+ if (dt->clock > 15000000) { /* sanity check */
+ float v;
+ h = (float)dt->clock / (dt->h_active + dt->h_blanking);
+ v = h / (dt->v_active + dt->v_blanking);
+ h /= 1000.0;
+ if (dt->interlaced)
+ v /= 2.0;
+
+ if (v < vmin)
+ vmin = v;
+ if (v > vmax)
+ vmax = v;
+ if (h < hmin)
+ hmin = h;
+ if (h > hmax)
+ hmax = h;
+ }
+ break;
+ }
+
+ if (numTimings > MAX_HSYNC)
+ break;
+ }
+
+ if (numTimings == 0) {
+ t = DDC->timings2;
+ for (i = 0; i < STD_TIMINGS; i++) {
+ if (t[i].hsize > 256) { /* sanity check */
+ if (t[i].refresh < vmin)
+ vmin = t[i].refresh;
+ if (t[i].refresh > vmax)
+ vmax = t[i].refresh;
+ /*
+ * For typical modes this is a reasonable estimate
+ * of the horizontal sync rate.
+ */
+ h = t[i].refresh * 1.07 * t[i].vsize / 1000.0;
+ if (h < hmin)
+ hmin = h;
+ if (h > hmax)
+ hmax = h;
+ }
+ }
+
+ if (hmax > 0.0) {
+ hsync[numTimings].lo = hmin;
+ hsync[numTimings].hi = hmax;
+ vrefresh[numTimings].lo = vmin;
+ vrefresh[numTimings].hi = vmax;
+ numTimings++;
+ }
+ }
+
+ if (numTimings > 0) {
+
+#ifdef DEBUG
+ for (i = 0; i < numTimings; i++) {
+ ErrorF("DDC - Hsync %.1f-%.1f kHz - Vrefresh %.1f-%.1f Hz\n",
+ hsync[i].lo, hsync[i].hi,
+ vrefresh[i].lo, vrefresh[i].hi);
+ }
+#endif
+
+#define DDC_SYNC_TOLERANCE SYNC_TOLERANCE
+ if (monitor->nHsync > 0) {
+ for (i = 0; i < monitor->nHsync; i++) {
+ Bool good = FALSE;
+ for (j = 0; j < numTimings; j++) {
+ if ((1.0 - DDC_SYNC_TOLERANCE) * hsync[j].lo <=
+ monitor->hsync[i].lo &&
+ (1.0 + DDC_SYNC_TOLERANCE) * hsync[j].hi >=
+ monitor->hsync[i].hi) {
+ good = TRUE;
+ break;
+ }
+ }
+ if (!good) {
+ xf86DrvMsg(scrp->scrnIndex, X_WARNING,
+ "config file hsync range %g-%gkHz not within DDC "
+ "hsync ranges.\n",
+ monitor->hsync[i].lo, monitor->hsync[i].hi);
+ }
+ }
+ }
+
+ if (monitor->nVrefresh > 0) {
+ for (i = 0; i < monitor->nVrefresh; i++) {
+ Bool good = FALSE;
+ for (j = 0; j < numTimings; j++) {
+ if ((1.0 - DDC_SYNC_TOLERANCE) * vrefresh[j].lo <=
+ monitor->vrefresh[0].lo &&
+ (1.0 + DDC_SYNC_TOLERANCE) * vrefresh[j].hi >=
+ monitor->vrefresh[0].hi) {
+ good = TRUE;
+ break;
+ }
+ }
+ if (!good) {
+ xf86DrvMsg(scrp->scrnIndex, X_WARNING,
+ "config file vrefresh range %g-%gHz not within DDC "
+ "vrefresh ranges.\n",
+ monitor->vrefresh[i].lo, monitor->vrefresh[i].hi);
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * If requested by the driver, allow missing hsync and/or vrefresh ranges
+ * in the monitor section.
+ */
+ if (strategy & LOOKUP_OPTIONAL_TOLERANCES) {
+ strategy &= ~LOOKUP_OPTIONAL_TOLERANCES;
+ } else {
+ const char *type = "";
+
+ if (scrp->monitor->nHsync <= 0) {
+ if (numTimings > 0) {
+ scrp->monitor->nHsync = numTimings;
+ for (i = 0; i < numTimings; i++) {
+ scrp->monitor->hsync[i].lo = hsync[i].lo;
+ scrp->monitor->hsync[i].hi = hsync[i].hi;
+ }
+ } else {
+ scrp->monitor->hsync[0].lo = 28;
+ scrp->monitor->hsync[0].hi = 33;
+ scrp->monitor->nHsync = 1;
+ }
+ type = "default ";
+ }
+ for (i = 0; i < scrp->monitor->nHsync; i++) {
+ if (scrp->monitor->hsync[i].lo == scrp->monitor->hsync[i].hi)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "%s: Using %shsync value of %.2f kHz\n",
+ scrp->monitor->id, type,
+ scrp->monitor->hsync[i].lo);
+ else
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "%s: Using %shsync range of %.2f-%.2f kHz\n",
+ scrp->monitor->id, type,
+ scrp->monitor->hsync[i].lo,
+ scrp->monitor->hsync[i].hi);
+ }
+
+ type = "";
+ if (scrp->monitor->nVrefresh <= 0) {
+ if (numTimings > 0) {
+ scrp->monitor->nVrefresh = numTimings;
+ for (i = 0; i < numTimings; i++) {
+ scrp->monitor->vrefresh[i].lo = vrefresh[i].lo;
+ scrp->monitor->vrefresh[i].hi = vrefresh[i].hi;
+ }
+ } else {
+ scrp->monitor->vrefresh[0].lo = 43;
+ scrp->monitor->vrefresh[0].hi = 72;
+ scrp->monitor->nVrefresh = 1;
+ }
+ type = "default ";
+ }
+ for (i = 0; i < scrp->monitor->nVrefresh; i++) {
+ if (scrp->monitor->vrefresh[i].lo == scrp->monitor->vrefresh[i].hi)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "%s: Using %svrefresh value of %.2f Hz\n",
+ scrp->monitor->id, type,
+ scrp->monitor->vrefresh[i].lo);
+ else
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "%s: Using %svrefresh range of %.2f-%.2f Hz\n",
+ scrp->monitor->id, type,
+ scrp->monitor->vrefresh[i].lo,
+ scrp->monitor->vrefresh[i].hi);
+ }
+ }
+
+ /*
+ * Store the clockRanges for later use by the VidMode extension. Must
+ * also store the strategy, since ClockDiv2 flag is stored there.
+ */
+ storeClockRanges = scrp->clockRanges;
+ while (storeClockRanges != NULL) {
+ storeClockRanges = storeClockRanges->next;
+ }
+ for (cp = clockRanges; cp != NULL; cp = cp->next,
+ storeClockRanges = storeClockRanges->next) {
+ storeClockRanges = xnfalloc(sizeof(ClockRanges));
+ if (scrp->clockRanges == NULL)
+ scrp->clockRanges = storeClockRanges;
+ memcpy(storeClockRanges, cp, sizeof(ClockRange));
+ storeClockRanges->strategy = strategy;
+ }
+
+ /* Determine which pixmap format to pass to miScanLineWidth() */
+ if (scrp->depth > 4)
+ BankFormat = &scrp->fbFormat;
+ else
+ BankFormat = xf86GetPixFormat(scrp, 1); /* >not< scrp->depth! */
+
+ if (scrp->xInc <= 0)
+ scrp->xInc = 8; /* Suitable for VGA and others */
+
+#define _VIRTUALX(x) ((((x) + scrp->xInc - 1) / scrp->xInc) * scrp->xInc)
+
+ /*
+ * Determine maxPitch if it wasn't given explicitly. Note linePitches
+ * always takes precedence if is non-NULL. In that case the minPitch and
+ * maxPitch values passed are ignored.
+ */
+ if (linePitches) {
+ minPitch = maxPitch = linePitches[0];
+ for (i = 1; linePitches[i] > 0; i++) {
+ if (linePitches[i] > maxPitch)
+ maxPitch = linePitches[i];
+ if (linePitches[i] < minPitch)
+ minPitch = linePitches[i];
+ }
+ }
+
+ /* Initial check of virtual size against other constraints */
+ scrp->virtualFrom = X_PROBED;
+ /*
+ * Initialise virtX and virtY if the values are fixed.
+ */
+ if (virtualY > 0) {
+ if (maxHeight > 0 && virtualY > maxHeight) {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Virtual height (%d) is too large for the hardware "
+ "(max %d)\n", virtualY, maxHeight);
+ return -1;
+ }
+
+ if (minHeight > 0 && virtualY < minHeight) {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Virtual height (%d) is too small for the hardware "
+ "(min %d)\n", virtualY, minHeight);
+ return -1;
+ }
+
+ virtualX = _VIRTUALX(virtualX);
+ if (linePitches != NULL) {
+ for (i = 0; linePitches[i] != 0; i++) {
+ if ((linePitches[i] >= virtualX) &&
+ (linePitches[i] ==
+ miScanLineWidth(virtualX, virtualY, linePitches[i],
+ apertureSize, BankFormat, pitchInc))) {
+ linePitch = linePitches[i];
+ break;
+ }
+ }
+ } else {
+ linePitch = miScanLineWidth(virtualX, virtualY, minPitch,
+ apertureSize, BankFormat, pitchInc);
+ }
+
+ if ((linePitch < minPitch) || (linePitch > maxPitch)) {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Virtual width (%d) is too large for the hardware "
+ "(max %d)\n", virtualX, maxPitch);
+ return -1;
+ }
+
+ if (!xf86CheckModeSize(scrp, linePitch, virtualX, virtualY)) {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Virtual size (%dx%d) (pitch %d) exceeds video memory\n",
+ virtualX, virtualY, linePitch);
+ return -1;
+ }
+
+ virtX = virtualX;
+ virtY = virtualY;
+ scrp->virtualFrom = X_CONFIG;
+ }
+
+ /* Print clock ranges and scaled clocks */
+ xf86ShowClockRanges(scrp, clockRanges);
+
+ /*
+ * If scrp->modePool hasn't been setup yet, set it up now. This allows the
+ * modes that the driver definitely can't use to be weeded out early. Note
+ * that a modePool mode's prev field is used to hold a pointer to the
+ * member of the scrp->modes list for which a match was considered.
+ */
+ if (scrp->modePool == NULL) {
+ q = NULL;
+ for (p = availModes; p != NULL; p = p->next) {
+ status = xf86InitialCheckModeForDriver(scrp, p, clockRanges,
+ strategy, maxPitch,
+ virtualX, virtualY);
+
+ if (status == MODE_OK) {
+ status = xf86CheckModeForMonitor(p, scrp->monitor);
+ }
+
+ if (status == MODE_OK) {
+ new = xnfalloc(sizeof(DisplayModeRec));
+ *new = *p;
+ new->next = NULL;
+ if (!q) {
+ scrp->modePool = new;
+ } else {
+ q->next = new;
+ }
+ new->prev = NULL;
+ q = new;
+ q->name = xnfstrdup(p->name);
+ q->status = MODE_OK;
+ } else {
+ if (p->type & M_T_BUILTIN)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using built-in mode \"%s\" (%s)\n",
+ p->name, xf86ModeStatusToString(status));
+ else if (p->type & M_T_DEFAULT)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using default mode \"%s\" (%s)\n", p->name,
+ xf86ModeStatusToString(status));
+ else
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using mode \"%s\" (%s)\n", p->name,
+ xf86ModeStatusToString(status));
+ }
+ }
+
+ if (scrp->modePool == NULL) {
+ xf86DrvMsg(scrp->scrnIndex, X_WARNING, "Mode pool is empty\n");
+ return 0;
+ }
+ } else {
+ for (p = scrp->modePool; p != NULL; p = p->next) {
+ p->prev = NULL;
+ p->status = MODE_OK;
+ }
+ }
+
+ /*
+ * Go through the mode pool and see if any modes match the target
+ * refresh rate, (if specified). If no modes match, abandon the target.
+ */
+ targetRefresh = xf86SetRealOption(scrp->options,
+ "TargetRefresh", 0.0);
+ if (targetRefresh > 0.0) {
+ for (p = scrp->modePool; p != NULL; p = p->next) {
+ if (ModeVRefresh(p) > targetRefresh * (1.0 - SYNC_TOLERANCE))
+ break;
+ }
+ if (!p)
+ targetRefresh = 0.0;
+ }
+
+ if (targetRefresh > 0.0) {
+ xf86DrvMsg(scrp->scrnIndex, X_CONFIG,
+ "Target refresh rate is %.1f Hz\n", targetRefresh);
+ }
+
+ /*
+ * Allocate one entry in scrp->modes for each named mode.
+ */
+ while (scrp->modes)
+ xf86DeleteMode(&scrp->modes, scrp->modes);
+ endp = &scrp->modes;
+ last = NULL;
+ if (modeNames != NULL) {
+ for (i = 0; modeNames[i] != NULL; i++) {
+ userModes = TRUE;
+ new = xnfcalloc(1, sizeof(DisplayModeRec));
+ new->prev = last;
+ new->type = M_T_USERDEF;
+ new->name = xnfalloc(strlen(modeNames[i]) + 1);
+ strcpy(new->name, modeNames[i]);
+ if (new->prev)
+ new->prev->next = new;
+ *endp = last = new;
+ endp = &new->next;
+ }
+ }
+
+ /* Lookup each mode */
+#ifdef RANDR
+ if (!xf86Info.disableRandR
+#ifdef PANORAMIX
+ && noPanoramiXExtension
+#endif
+ )
+ validateAllDefaultModes = TRUE;
+#endif
+
+ for (p = scrp->modes; ; p = p->next) {
+ Bool repeat;
+
+ /*
+ * If the supplied mode names don't produce a valid mode, scan through
+ * unconsidered modePool members until one survives validation. This
+ * is done in decreasing order by mode pixel area.
+ */
+
+ if (p == NULL) {
+ if ((numModes > 0) && !validateAllDefaultModes)
+ break;
+
+ validateAllDefaultModes = TRUE;
+ r = NULL;
+ modeSize = 0;
+ for (q = scrp->modePool; q != NULL; q = q->next) {
+ if ((q->prev == NULL) && (q->status == MODE_OK)) {
+ /*
+ * Deal with the case where this mode wasn't considered
+ * because of a builtin mode of the same name.
+ */
+ for (p = scrp->modes; p != NULL; p = p->next) {
+ if ((p->status != MODE_OK) &&
+ !strcmp(p->name, q->name))
+ break;
+ }
+
+ if (p != NULL)
+ q->prev = p;
+ else {
+ /*
+ * A quick check to not allow default modes with
+ * horizontal timing parameters that CRTs may have
+ * problems with.
+ */
+ if ((q->type & M_T_DEFAULT) &&
+ ((double)q->HTotal / (double)q->HDisplay) < 1.15)
+ continue;
+
+ /*
+ * If there is a target refresh rate, skip modes that
+ * don't match up.
+ */
+ if (ModeVRefresh(q) <
+ (1.0 - SYNC_TOLERANCE) * targetRefresh)
+ continue;
+
+ if (modeSize < (q->HDisplay * q->VDisplay)) {
+ r = q;
+ modeSize = q->HDisplay * q->VDisplay;
+ }
+ }
+ }
+ }
+
+ if (r == NULL)
+ break;
+
+ p = xnfcalloc(1, sizeof(DisplayModeRec));
+ p->prev = last;
+ p->name = xnfalloc(strlen(r->name) + 1);
+ if (!userModes)
+ p->type = M_T_USERDEF;
+ strcpy(p->name, r->name);
+ if (p->prev)
+ p->prev->next = p;
+ *endp = last = p;
+ endp = &p->next;
+ }
+
+ repeat = FALSE;
+ lookupNext:
+ if (repeat && ((status = p->status) != MODE_OK)) {
+ if (p->type & M_T_BUILTIN)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using built-in mode \"%s\" (%s)\n",
+ p->name, xf86ModeStatusToString(status));
+ else if (p->type & M_T_DEFAULT)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using default mode \"%s\" (%s)\n", p->name,
+ xf86ModeStatusToString(status));
+ else
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using mode \"%s\" (%s)\n", p->name,
+ xf86ModeStatusToString(status));
+ }
+ saveType = p->type;
+ status = xf86LookupMode(scrp, p, clockRanges, strategy);
+ if (repeat && status == MODE_NOMODE) {
+ continue;
+ }
+ if (status != MODE_OK) {
+ if (p->type & M_T_BUILTIN)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using built-in mode \"%s\" (%s)\n",
+ p->name, xf86ModeStatusToString(status));
+ else if (p->type & M_T_DEFAULT)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using default mode \"%s\" (%s)\n", p->name,
+ xf86ModeStatusToString(status));
+ else
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using mode \"%s\" (%s)\n", p->name,
+ xf86ModeStatusToString(status));
+ }
+ if (status == MODE_ERROR) {
+ ErrorF("xf86ValidateModes: "
+ "unexpected result from xf86LookupMode()\n");
+ return -1;
+ }
+ if (status != MODE_OK) {
+ if (p->status == MODE_OK)
+ p->status = status;
+ continue;
+ }
+ p->type |= saveType;
+ repeat = TRUE;
+
+ newLinePitch = linePitch;
+ newVirtX = virtX;
+ newVirtY = virtY;
+
+ /*
+ * Don't let non-user defined modes increase the virtual size
+ */
+ if (!(p->type & M_T_USERDEF) && (numModes > 0)) {
+ if (p->HDisplay > virtX) {
+ p->status = MODE_VIRTUAL_X;
+ goto lookupNext;
+ }
+ if (p->VDisplay > virtY) {
+ p->status = MODE_VIRTUAL_Y;
+ goto lookupNext;
+ }
+ }
+ /*
+ * Adjust virtual width and height if the mode is too large for the
+ * current values and if they are not fixed.
+ */
+ if (virtualX <= 0 && p->HDisplay > newVirtX)
+ newVirtX = _VIRTUALX(p->HDisplay);
+ if (virtualY <= 0 && p->VDisplay > newVirtY) {
+ if (maxHeight > 0 && p->VDisplay > maxHeight) {
+ p->status = MODE_VIRTUAL_Y; /* ? */
+ goto lookupNext;
+ }
+ newVirtY = p->VDisplay;
+ }
+
+ /*
+ * If virtual resolution is to be increased, revalidate it.
+ */
+ if ((virtX != newVirtX) || (virtY != newVirtY)) {
+ if (linePitches != NULL) {
+ newLinePitch = -1;
+ for (i = 0; linePitches[i] != 0; i++) {
+ if ((linePitches[i] >= newVirtX) &&
+ (linePitches[i] >= linePitch) &&
+ (linePitches[i] ==
+ miScanLineWidth(newVirtX, newVirtY, linePitches[i],
+ apertureSize, BankFormat, pitchInc))) {
+ newLinePitch = linePitches[i];
+ break;
+ }
+ }
+ } else {
+ if (linePitch < minPitch)
+ linePitch = minPitch;
+ newLinePitch = miScanLineWidth(newVirtX, newVirtY, linePitch,
+ apertureSize, BankFormat,
+ pitchInc);
+ }
+ if ((newLinePitch < minPitch) || (newLinePitch > maxPitch)) {
+ p->status = MODE_BAD_WIDTH;
+ goto lookupNext;
+ }
+
+ /*
+ * Check that the pixel area required by the new virtual height
+ * and line pitch isn't too large.
+ */
+ if (!xf86CheckModeSize(scrp, newLinePitch, newVirtX, newVirtY)) {
+ p->status = MODE_MEM_VIRT;
+ goto lookupNext;
+ }
+ }
+
+ if (scrp->ValidMode) {
+ /*
+ * Give the driver a final say, passing it the proposed virtual
+ * geometry.
+ */
+ scrp->virtualX = newVirtX;
+ scrp->virtualY = newVirtY;
+ scrp->displayWidth = newLinePitch;
+ p->status = (scrp->ValidMode)(scrp->scrnIndex, p, FALSE,
+ MODECHECK_FINAL);
+
+ if (p->status != MODE_OK) {
+ goto lookupNext;
+ }
+ }
+
+ /* Mode has passed all the tests */
+ virtX = newVirtX;
+ virtY = newVirtY;
+ linePitch = newLinePitch;
+ p->status = MODE_OK;
+ numModes++;
+ }
+
+#undef _VIRTUALX
+
+ /* Update the ScrnInfoRec parameters */
+
+ scrp->virtualX = virtX;
+ scrp->virtualY = virtY;
+ scrp->displayWidth = linePitch;
+
+ if (numModes <= 0)
+ return 0;
+
+ /* Make the mode list into a circular list by joining up the ends */
+ p = scrp->modes;
+ while (p->next != NULL)
+ p = p->next;
+ /* p is now the last mode on the list */
+ p->next = scrp->modes;
+ scrp->modes->prev = p;
+
+ if (minHeight > 0 && virtY < minHeight) {
+ xf86DrvMsg(scrp->scrnIndex, X_ERROR,
+ "Virtual height (%d) is too small for the hardware "
+ "(min %d)\n", virtY, minHeight);
+ return -1;
+ }
+
+ return numModes;
+}
+
+/*
+ * xf86DeleteMode
+ *
+ * This function removes a mode from a list of modes.
+ *
+ * There are different types of mode lists:
+ *
+ * - singly linked linear lists, ending in NULL
+ * - doubly linked linear lists, starting and ending in NULL
+ * - doubly linked circular lists
+ *
+ */
+
+void
+xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode)
+{
+ /* Catch the easy/insane cases */
+ if (modeList == NULL || *modeList == NULL || mode == NULL)
+ return;
+
+ /* If the mode is at the start of the list, move the start of the list */
+ if (*modeList == mode)
+ *modeList = mode->next;
+
+ /* If mode is the only one on the list, set the list to NULL */
+ if ((mode == mode->prev) && (mode == mode->next)) {
+ *modeList = NULL;
+ } else {
+ if ((mode->prev != NULL) && (mode->prev->next == mode))
+ mode->prev->next = mode->next;
+ if ((mode->next != NULL) && (mode->next->prev == mode))
+ mode->next->prev = mode->prev;
+ }
+
+ xfree(mode->name);
+ xfree(mode);
+}
+
+/*
+ * xf86PruneDriverModes
+ *
+ * Remove modes from the driver's mode list which have been marked as
+ * invalid.
+ */
+
+void
+xf86PruneDriverModes(ScrnInfoPtr scrp)
+{
+ DisplayModePtr first, p, n;
+
+ p = scrp->modes;
+ if (p == NULL)
+ return;
+
+ do {
+ if (!(first = scrp->modes))
+ return;
+ n = p->next;
+ if (p->status != MODE_OK) {
+#if 0
+ if (p->type & M_T_BUILTIN)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using built-in mode \"%s\" (%s)\n", p->name,
+ xf86ModeStatusToString(p->status));
+ else if (p->type & M_T_DEFAULT)
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using default mode \"%s\" (%s)\n", p->name,
+ xf86ModeStatusToString(p->status));
+ else
+ xf86DrvMsg(scrp->scrnIndex, X_INFO,
+ "Not using mode \"%s\" (%s)\n", p->name,
+ xf86ModeStatusToString(p->status));
+#endif
+ xf86DeleteMode(&(scrp->modes), p);
+ }
+ p = n;
+ } while (p != NULL && p != first);
+
+ /* modePool is no longer needed, turf it */
+ while (scrp->modePool) {
+ /*
+ * A modePool mode's prev field is used to hold a pointer to the
+ * member of the scrp->modes list for which a match was considered.
+ * Clear that pointer first, otherwise xf86DeleteMode might get
+ * confused
+ */
+ scrp->modePool->prev = NULL;
+ xf86DeleteMode(&scrp->modePool, scrp->modePool);
+ }
+}
+
+
+/*
+ * xf86SetCrtcForModes
+ *
+ * Goes through the screen's mode list, and initialises the Crtc
+ * parameters for each mode. The initialisation includes adjustments
+ * for interlaced and double scan modes.
+ */
+void
+xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags)
+{
+ DisplayModePtr p;
+
+ /*
+ * Store adjustFlags for use with the VidMode extension. There is an
+ * implicit assumption here that SetCrtcForModes is called once.
+ */
+ scrp->adjustFlags = adjustFlags;
+
+ p = scrp->modes;
+ if (p == NULL)
+ return;
+
+ do {
+ xf86SetModeCrtc(p, adjustFlags);
+#ifdef DEBUG
+ ErrorF("%sMode %s: %d (%d) %d %d (%d) %d %d (%d) %d %d (%d) %d\n",
+ (p->type & M_T_DEFAULT) ? "Default " : "",
+ p->name, p->CrtcHDisplay, p->CrtcHBlankStart,
+ p->CrtcHSyncStart, p->CrtcHSyncEnd, p->CrtcHBlankEnd,
+ p->CrtcHTotal, p->CrtcVDisplay, p->CrtcVBlankStart,
+ p->CrtcVSyncStart, p->CrtcVSyncEnd, p->CrtcVBlankEnd,
+ p->CrtcVTotal);
+#endif
+ p = p->next;
+ } while (p != NULL && p != scrp->modes);
+}
+
+
+static void
+add(char **p, char *new)
+{
+ *p = xnfrealloc(*p, strlen(*p) + strlen(new) + 2);
+ strcat(*p, " ");
+ strcat(*p, new);
+}
+
+static void
+PrintModeline(int scrnIndex,DisplayModePtr mode)
+{
+ char tmp[256];
+ char *flags = xnfcalloc(1, 1);
+
+ if (mode->HSkew) {
+ snprintf(tmp, 256, "hskew %i", mode->HSkew);
+ add(&flags, tmp);
+ }
+ if (mode->VScan) {
+ snprintf(tmp, 256, "vscan %i", mode->VScan);
+ add(&flags, tmp);
+ }
+ if (mode->Flags & V_INTERLACE) add(&flags, "interlace");
+ if (mode->Flags & V_CSYNC) add(&flags, "composite");
+ if (mode->Flags & V_DBLSCAN) add(&flags, "doublescan");
+ if (mode->Flags & V_BCAST) add(&flags, "bcast");
+ if (mode->Flags & V_PHSYNC) add(&flags, "+hsync");
+ if (mode->Flags & V_NHSYNC) add(&flags, "-hsync");
+ if (mode->Flags & V_PVSYNC) add(&flags, "+vsync");
+ if (mode->Flags & V_NVSYNC) add(&flags, "-vsync");
+ if (mode->Flags & V_PCSYNC) add(&flags, "+csync");
+ if (mode->Flags & V_NCSYNC) add(&flags, "-csync");
+#if 0
+ if (mode->Flags & V_CLKDIV2) add(&flags, "vclk/2");
+#endif
+ xf86DrvMsgVerb(scrnIndex, X_INFO, 3,
+ "Modeline \"%s\" %6.2f %i %i %i %i %i %i %i %i%s\n",
+ mode->name, mode->Clock/1000., mode->HDisplay,
+ mode->HSyncStart, mode->HSyncEnd, mode->HTotal,
+ mode->VDisplay, mode->VSyncStart, mode->VSyncEnd,
+ mode->VTotal, flags);
+ xfree(flags);
+}
+
+void
+xf86PrintModes(ScrnInfoPtr scrp)
+{
+ DisplayModePtr p;
+ float hsync, refresh = 0;
+ char *desc, *desc2, *prefix, *uprefix;
+
+ if (scrp == NULL)
+ return;
+
+ xf86DrvMsg(scrp->scrnIndex, scrp->virtualFrom, "Virtual size is %dx%d "
+ "(pitch %d)\n", scrp->virtualX, scrp->virtualY,
+ scrp->displayWidth);
+
+ p = scrp->modes;
+ if (p == NULL)
+ return;
+
+ do {
+ desc = desc2 = "";
+ hsync = ModeHSync(p);
+ refresh = ModeVRefresh(p);
+ if (p->Flags & V_INTERLACE) {
+ desc = " (I)";
+ }
+ if (p->Flags & V_DBLSCAN) {
+ desc = " (D)";
+ }
+ if (p->VScan > 1) {
+ desc2 = " (VScan)";
+ }
+ if (p->type & M_T_BUILTIN)
+ prefix = "Built-in mode";
+ else if (p->type & M_T_DEFAULT)
+ prefix = "Default mode";
+ else
+ prefix = "Mode";
+ if (p->type & M_T_USERDEF)
+ uprefix = "*";
+ else
+ uprefix = " ";
+ if (hsync == 0 || refresh == 0) {
+ if (p->name)
+ xf86DrvMsg(scrp->scrnIndex, X_CONFIG,
+ "%s%s \"%s\"\n", uprefix, prefix, p->name);
+ else
+ xf86DrvMsg(scrp->scrnIndex, X_PROBED,
+ "%s%s %dx%d (unnamed)\n",
+ uprefix, prefix, p->HDisplay, p->VDisplay);
+ } else if (p->Clock == p->SynthClock) {
+ xf86DrvMsg(scrp->scrnIndex, X_CONFIG,
+ "%s%s \"%s\": %.1f MHz, %.1f kHz, %.1f Hz%s%s\n",
+ uprefix, prefix, p->name, p->Clock / 1000.0,
+ hsync, refresh, desc, desc2);
+ } else {
+ xf86DrvMsg(scrp->scrnIndex, X_CONFIG,
+ "%s%s \"%s\": %.1f MHz (scaled from %.1f MHz), "
+ "%.1f kHz, %.1f Hz%s%s\n",
+ uprefix, prefix, p->name, p->Clock / 1000.0,
+ p->SynthClock / 1000.0, hsync, refresh, desc, desc2);
+ }
+ if (hsync != 0 && refresh != 0)
+ PrintModeline(scrp->scrnIndex,p);
+ p = p->next;
+ } while (p != NULL && p != scrp->modes);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Module.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Module.h
new file mode 100644
index 000000000..84c3e32c3
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Module.h
@@ -0,0 +1,226 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Module.h,v 1.37 2003/08/24 17:36:54 dawes Exp $ */
+
+/*
+ * 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 parts of the loader interface that are visible
+ * to modules. This is the only loader-related header that modules should
+ * include.
+ *
+ * It should include a bare minimum of other headers.
+ *
+ * Longer term, the module/loader code should probably live directly under
+ * Xserver/.
+ *
+ * XXX This file arguably belongs in xfree86/loader/.
+ */
+
+#ifndef _XF86MODULE_H
+#define _XF86MODULE_H
+
+#include "misc.h"
+#include "xf86Version.h"
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+typedef enum {
+ LD_RESOLV_IFDONE = 0, /* only check if no more
+ delays pending */
+ LD_RESOLV_NOW = 1, /* finish one delay step */
+ LD_RESOLV_FORCE = 2 /* force checking... */
+} LoaderResolveOptions;
+
+#define DEFAULT_LIST ((char *)-1)
+
+/* This indicates a special module that doesn't have the usual entry point */
+#define EXTERN_MODULE ((pointer)-1)
+
+/* Built-in ABI classes. These definitions must not be changed. */
+#define ABI_CLASS_NONE NULL
+#define ABI_CLASS_ANSIC "X.Org ANSI C Emulation"
+#define ABI_CLASS_VIDEODRV "X.Org Video Driver"
+#define ABI_CLASS_XINPUT "X.Org XInput driver"
+#define ABI_CLASS_EXTENSION "X.Org Server Extension"
+#define ABI_CLASS_FONT "X.Org Font Renderer"
+
+#define ABI_MINOR_MASK 0x0000FFFF
+#define ABI_MAJOR_MASK 0xFFFF0000
+#define GET_ABI_MINOR(v) ((v) & ABI_MINOR_MASK)
+#define GET_ABI_MAJOR(v) (((v) & ABI_MAJOR_MASK) >> 16)
+#define SET_ABI_VERSION(maj, min) \
+ ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK))
+
+/*
+ * ABI versions. Each version has a major and minor revision. Modules
+ * using lower minor revisions must work with servers of a higher minor
+ * revision. There is no compatibility between different major revisions.
+ * Whenever the ABI_ANSIC_VERSION is changed, the others must also be
+ * changed. The minor revision mask is 0x0000FFFF and the major revision
+ * mask is 0xFFFF0000.
+ */
+#define ABI_ANSIC_VERSION SET_ABI_VERSION(0, 2)
+#define ABI_VIDEODRV_VERSION SET_ABI_VERSION(0, 8)
+#define ABI_XINPUT_VERSION SET_ABI_VERSION(0, 5)
+#define ABI_EXTENSION_VERSION SET_ABI_VERSION(0, 2)
+#define ABI_FONT_VERSION SET_ABI_VERSION(0, 4)
+
+#define MODINFOSTRING1 0xef23fdc5
+#define MODINFOSTRING2 0x10dc023a
+
+#ifndef MODULEVENDORSTRING
+#ifndef __OS2ELF__
+#define MODULEVENDORSTRING "X.Org Foundation"
+#else
+#define MODULEVENDORSTRING "X.Org Foundation - OS2"
+#endif
+#endif
+
+/* Error return codes for errmaj. New codes must only be added at the end. */
+typedef enum {
+ LDR_NOERROR = 0,
+ LDR_NOMEM, /* memory allocation failed */
+ LDR_NOENT, /* Module file does not exist */
+ LDR_NOSUBENT, /* pre-requsite file to be sub-loaded does not exist */
+ LDR_NOSPACE, /* internal module array full */
+ LDR_NOMODOPEN, /* module file could not be opened (check errmin) */
+ LDR_UNKTYPE, /* file is not a recognized module type */
+ LDR_NOLOAD, /* type specific loader failed */
+ LDR_ONCEONLY, /* Module should only be loaded once (not an error) */
+ LDR_NOPORTOPEN, /* could not open port (check errmin) */
+ LDR_NOHARDWARE, /* could not query/initialize the hardware device */
+ LDR_MISMATCH, /* the module didn't match the spec'd requirments */
+ LDR_BADUSAGE, /* LoadModule is called with bad arguments */
+ LDR_INVALID, /* The module doesn't have a valid ModuleData object */
+ LDR_BADOS, /* The module doesn't support the OS */
+ LDR_MODSPECIFIC /* A module-specific error in the SetupProc */
+} LoaderErrorCode;
+
+/*
+ * Some common module classes. The moduleclass can be used to identify
+ * that modules loaded are of the correct type. This is a finer
+ * classification than the ABI classes even though the default set of
+ * classes have the same names. For example, not all modules that require
+ * the video driver ABI are themselves video drivers.
+ */
+#define MOD_CLASS_NONE NULL
+#define MOD_CLASS_VIDEODRV "X.Org Video Driver"
+#define MOD_CLASS_XINPUT "X.Org XInput Driver"
+#define MOD_CLASS_FONT "X.Org Font Renderer"
+#define MOD_CLASS_EXTENSION "X.Org Server Extension"
+
+/* This structure is expected to be returned by the initfunc */
+typedef struct {
+ const char * modname; /* name of module, e.g. "foo" */
+ const char * vendor; /* vendor specific string */
+ CARD32 _modinfo1_; /* constant MODINFOSTRING1/2 to find */
+ CARD32 _modinfo2_; /* infoarea with a binary editor or sign tool */
+ CARD32 xf86version; /* contains XF86_VERSION_CURRENT */
+ CARD8 majorversion; /* module-specific major version */
+ CARD8 minorversion; /* module-specific minor version */
+ CARD16 patchlevel; /* module-specific patch level */
+ const char * abiclass; /* ABI class that the module uses */
+ CARD32 abiversion; /* ABI version */
+ const char * moduleclass; /* module class description */
+ CARD32 checksum[4]; /* contains a digital signature of the */
+ /* version info structure */
+} XF86ModuleVersionInfo;
+
+/*
+ * This structure can be used to callers of LoadModule and LoadSubModule to
+ * specify version and/or ABI requirements.
+ */
+typedef struct {
+ CARD8 majorversion; /* module-specific major version */
+ CARD8 minorversion; /* moudle-specific minor version */
+ CARD16 patchlevel; /* module-specific patch level */
+ const char * abiclass; /* ABI class that the module uses */
+ CARD32 abiversion; /* ABI version */
+ const char * moduleclass; /* module class */
+} XF86ModReqInfo;
+
+/* values to indicate unspecified fields in XF86ModReqInfo. */
+#define MAJOR_UNSPEC 0xFF
+#define MINOR_UNSPEC 0xFF
+#define PATCH_UNSPEC 0xFFFF
+#define ABI_VERS_UNSPEC 0xFFFFFFFF
+
+#define MODULE_VERSION_NUMERIC(maj, min, patch) \
+ ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF))
+#define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF)
+#define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF)
+#define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF)
+
+#define INITARGS void
+
+typedef void (*InitExtension)(INITARGS);
+
+typedef struct {
+ InitExtension initFunc;
+ const char * name;
+ Bool *disablePtr;
+ InitExtension setupFunc;
+ const char ** initDependencies;
+} ExtensionModule;
+
+extern ExtensionModule *ExtensionModuleList;
+
+/* Prototypes for Loader functions that are exported to modules */
+#ifndef IN_LOADER
+/* Prototypes with opaque pointers for use by modules */
+pointer LoadSubModule(pointer, const char *, const char **,
+ const char **, pointer, const XF86ModReqInfo *,
+ int *, int *);
+void UnloadSubModule(pointer);
+void LoadFont(pointer);
+void UnloadModule (pointer);
+#endif
+pointer LoaderSymbol(const char *);
+char **LoaderListDirs(const char **, const char **);
+void LoaderFreeDirList(char **);
+void LoaderErrorMsg(const char *, const char *, int, int);
+void LoadExtension(ExtensionModule *, Bool);
+void LoaderRefSymLists(const char **, ...);
+void LoaderRefSymbols(const char *, ...);
+void LoaderReqSymLists(const char **, ...);
+void LoaderReqSymbols(const char *, ...);
+int LoaderCheckUnresolved(int);
+void LoaderGetOS(const char **name, int *major, int *minor, int *teeny);
+
+typedef pointer (*ModuleSetupProc)(pointer, pointer, int *, int *);
+typedef void (*ModuleTearDownProc)(pointer);
+#define MODULESETUPPROTO(func) pointer func(pointer, pointer, int*, int*)
+#define MODULETEARDOWNPROTO(func) void func(pointer)
+
+typedef struct {
+ XF86ModuleVersionInfo * vers;
+ ModuleSetupProc setup;
+ ModuleTearDownProc teardown;
+} XF86ModuleData;
+
+#endif /* _XF86STR_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Opt.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Opt.h
new file mode 100644
index 000000000..718732353
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Opt.h
@@ -0,0 +1,114 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Opt.h,v 1.15 2003/10/08 14:30:38 dawes Exp $ */
+
+/*
+ * Copyright (c) 1998-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).
+ */
+
+/* Option handling things that ModuleSetup procs can use */
+
+#ifndef _XF86_OPT_H_
+#define _XF86_OPT_H_
+
+typedef struct {
+ double freq;
+ int units;
+} OptFrequency;
+
+typedef union {
+ unsigned long num;
+ char * str;
+ double realnum;
+ Bool bool;
+ OptFrequency freq;
+} ValueUnion;
+
+typedef enum {
+ OPTV_NONE = 0,
+ OPTV_INTEGER,
+ OPTV_STRING, /* a non-empty string */
+ OPTV_ANYSTR, /* Any string, including an empty one */
+ OPTV_REAL,
+ OPTV_BOOLEAN,
+ OPTV_FREQ
+} OptionValueType;
+
+typedef enum {
+ OPTUNITS_HZ = 1,
+ OPTUNITS_KHZ,
+ OPTUNITS_MHZ
+} OptFreqUnits;
+
+typedef struct {
+ int token;
+ const char* name;
+ OptionValueType type;
+ ValueUnion value;
+ Bool found;
+} OptionInfoRec, *OptionInfoPtr;
+
+int xf86SetIntOption(pointer optlist, const char *name, int deflt);
+double xf86SetRealOption(pointer optlist, const char *name, double deflt);
+char *xf86SetStrOption(pointer optlist, const char *name, char *deflt);
+int xf86SetBoolOption(pointer list, const char *name, int deflt );
+int xf86CheckIntOption(pointer optlist, const char *name, int deflt);
+double xf86CheckRealOption(pointer optlist, const char *name, double deflt);
+char *xf86CheckStrOption(pointer optlist, const char *name, char *deflt);
+int xf86CheckBoolOption(pointer list, const char *name, int deflt );
+pointer xf86AddNewOption(pointer head, const char *name, const char *val );
+pointer xf86NewOption(char *name, char *value );
+pointer xf86NextOption(pointer list );
+pointer xf86OptionListCreate(const char **options, int count, int used);
+pointer xf86OptionListMerge(pointer head, pointer tail);
+void xf86OptionListFree(pointer opt);
+char *xf86OptionName(pointer opt);
+char *xf86OptionValue(pointer opt);
+void xf86OptionListReport(pointer parm);
+pointer xf86FindOption(pointer options, const char *name);
+char *xf86FindOptionValue(pointer options, const char *name);
+void xf86MarkOptionUsed(pointer option);
+void xf86MarkOptionUsedByName(pointer options, const char *name);
+Bool xf86CheckIfOptionUsed(pointer option);
+Bool xf86CheckIfOptionUsedByName(pointer options, const char *name);
+void xf86ShowUnusedOptions(int scrnIndex, pointer options);
+void xf86ProcessOptions(int scrnIndex, pointer options, OptionInfoPtr optinfo);
+OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table, int token);
+const char *xf86TokenToOptName(const OptionInfoRec *table, int token);
+Bool xf86IsOptionSet(const OptionInfoRec *table, int token);
+char *xf86GetOptValString(const OptionInfoRec *table, int token);
+Bool xf86GetOptValInteger(const OptionInfoRec *table, int token, int *value);
+Bool xf86GetOptValULong(const OptionInfoRec *table, int token, unsigned long *value);
+Bool xf86GetOptValReal(const OptionInfoRec *table, int token, double *value);
+Bool xf86GetOptValFreq(const OptionInfoRec *table, int token,
+ OptFreqUnits expectedUnits, double *value);
+Bool xf86GetOptValBool(const OptionInfoRec *table, int token, Bool *value);
+Bool xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def);
+int xf86NameCmp(const char *s1, const char *s2);
+char *xf86NormalizeName(const char *s);
+pointer xf86ReplaceIntOption(pointer optlist, const char *name, const int val);
+pointer xf86ReplaceRealOption(pointer optlist, const char *name, const double val);
+pointer xf86ReplaceBoolOption(pointer optlist, const char *name, const Bool val);
+pointer xf86ReplaceStrOption(pointer optlist, const char *name, const char* val);
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Option.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Option.c
new file mode 100644
index 000000000..9bffdee70
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Option.c
@@ -0,0 +1,884 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Option.c,v 1.29 2003/10/18 12:34:19 dawes Exp $ */
+/*
+ * Copyright (c) 1998-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).
+ */
+
+/*
+ * Author: David Dawes <dawes@xfree86.org>
+ *
+ * This file includes public option handling functions.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86Optrec.h"
+
+static Bool ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
+ Bool markUsed);
+
+/*
+ * xf86CollectOptions collects the options from each of the config file
+ * sections used by the screen and puts the combined list in pScrn->options.
+ * This function requires that the following have been initialised:
+ *
+ * pScrn->confScreen
+ * pScrn->Entities[i]->device
+ * pScrn->display
+ * pScrn->monitor
+ *
+ * The extraOpts parameter may optionally contain a list of additional options
+ * to include.
+ *
+ * The order of precedence for options is:
+ *
+ * extraOpts, display, confScreen, monitor, device
+ */
+
+void
+xf86CollectOptions(ScrnInfoPtr pScrn, pointer extraOpts)
+{
+ XF86OptionPtr tmp;
+ XF86OptionPtr extras = (XF86OptionPtr)extraOpts;
+ GDevPtr device;
+
+ int i;
+
+ pScrn->options = NULL;
+
+ for (i=pScrn->numEntities - 1; i >= 0; i--) {
+ device = xf86GetDevFromEntity(pScrn->entityList[i],
+ pScrn->entityInstanceList[i]);
+ if (device && device->options) {
+ tmp = xf86optionListDup(device->options);
+ if (pScrn->options)
+ xf86optionListMerge(pScrn->options,tmp);
+ else
+ pScrn->options = tmp;
+ }
+ }
+ if (pScrn->monitor->options) {
+ tmp = xf86optionListDup(pScrn->monitor->options);
+ if (pScrn->options)
+ pScrn->options = xf86optionListMerge(pScrn->options, tmp);
+ else
+ pScrn->options = tmp;
+ }
+ if (pScrn->confScreen->options) {
+ tmp = xf86optionListDup(pScrn->confScreen->options);
+ if (pScrn->options)
+ pScrn->options = xf86optionListMerge(pScrn->options, tmp);
+ else
+ pScrn->options = tmp;
+ }
+ if (pScrn->display->options) {
+ tmp = xf86optionListDup(pScrn->display->options);
+ if (pScrn->options)
+ pScrn->options = xf86optionListMerge(pScrn->options, tmp);
+ else
+ pScrn->options = tmp;
+ }
+ if (extras) {
+ tmp = xf86optionListDup(extras);
+ if (pScrn->options)
+ pScrn->options = xf86optionListMerge(pScrn->options, tmp);
+ else
+ pScrn->options = tmp;
+ }
+}
+
+/*
+ * xf86CollectInputOptions collects the options for an InputDevice.
+ * This function requires that the following has been initialised:
+ *
+ * pInfo->conf_idev
+ *
+ * The extraOpts parameter may optionally contain a list of additional options
+ * to include.
+ *
+ * The order of precedence for options is:
+ *
+ * extraOpts, pInfo->conf_idev->extraOptions,
+ * pInfo->conf_idev->commonOptions, defaultOpts
+ */
+
+void
+xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts,
+ pointer extraOpts)
+{
+ XF86OptionPtr tmp;
+ XF86OptionPtr extras = (XF86OptionPtr)extraOpts;
+
+ pInfo->options = NULL;
+ if (defaultOpts) {
+ pInfo->options = xf86OptionListCreate(defaultOpts, -1, 0);
+ }
+ if (pInfo->conf_idev->commonOptions) {
+ tmp = xf86optionListDup(pInfo->conf_idev->commonOptions);
+ if (pInfo->options)
+ pInfo->options = xf86optionListMerge(pInfo->options, tmp);
+ else
+ pInfo->options = tmp;
+ }
+ if (pInfo->conf_idev->extraOptions) {
+ tmp = xf86optionListDup(pInfo->conf_idev->extraOptions);
+ if (pInfo->options)
+ pInfo->options = xf86optionListMerge(pInfo->options, tmp);
+ else
+ pInfo->options = tmp;
+ }
+ if (extras) {
+ tmp = xf86optionListDup(extras);
+ if (pInfo->options)
+ pInfo->options = xf86optionListMerge(pInfo->options, tmp);
+ else
+ pInfo->options = tmp;
+ }
+}
+
+/* Created for new XInput stuff -- essentially extensions to the parser */
+
+static int
+LookupIntOption(pointer optlist, const char *name, int deflt, Bool markUsed)
+{
+ OptionInfoRec o;
+
+ o.name = name;
+ o.type = OPTV_INTEGER;
+ if (ParseOptionValue(-1, optlist, &o, markUsed))
+ deflt = o.value.num;
+ return deflt;
+}
+
+
+static double
+LookupRealOption(pointer optlist, const char *name, double deflt,
+ Bool markUsed)
+{
+ OptionInfoRec o;
+
+ o.name = name;
+ o.type = OPTV_REAL;
+ if (ParseOptionValue(-1, optlist, &o, markUsed))
+ deflt = o.value.realnum;
+ return deflt;
+}
+
+
+static char *
+LookupStrOption(pointer optlist, const char *name, char *deflt, Bool markUsed)
+{
+ OptionInfoRec o;
+
+ o.name = name;
+ o.type = OPTV_STRING;
+ if (ParseOptionValue(-1, optlist, &o, markUsed))
+ deflt = o.value.str;
+ if (deflt)
+ return xstrdup(deflt);
+ else
+ return NULL;
+}
+
+
+static int
+LookupBoolOption(pointer optlist, const char *name, int deflt, Bool markUsed)
+{
+ OptionInfoRec o;
+
+ o.name = name;
+ o.type = OPTV_BOOLEAN;
+ if (ParseOptionValue(-1, optlist, &o, markUsed))
+ deflt = o.value.bool;
+ return deflt;
+}
+
+/* These xf86Set* functions are intended for use by non-screen specific code */
+
+int
+xf86SetIntOption(pointer optlist, const char *name, int deflt)
+{
+ return LookupIntOption(optlist, name, deflt, TRUE);
+}
+
+
+double
+xf86SetRealOption(pointer optlist, const char *name, double deflt)
+{
+ return LookupRealOption(optlist, name, deflt, TRUE);
+}
+
+
+char *
+xf86SetStrOption(pointer optlist, const char *name, char *deflt)
+{
+ return LookupStrOption(optlist, name, deflt, TRUE);
+}
+
+
+int
+xf86SetBoolOption(pointer optlist, const char *name, int deflt)
+{
+ return LookupBoolOption(optlist, name, deflt, TRUE);
+}
+
+/*
+ * These are like the Set*Option functions, but they don't mark the options
+ * as used.
+ */
+int
+xf86CheckIntOption(pointer optlist, const char *name, int deflt)
+{
+ return LookupIntOption(optlist, name, deflt, FALSE);
+}
+
+
+double
+xf86CheckRealOption(pointer optlist, const char *name, double deflt)
+{
+ return LookupRealOption(optlist, name, deflt, FALSE);
+}
+
+
+char *
+xf86CheckStrOption(pointer optlist, const char *name, char *deflt)
+{
+ return LookupStrOption(optlist, name, deflt, FALSE);
+}
+
+
+int
+xf86CheckBoolOption(pointer optlist, const char *name, int deflt)
+{
+ return LookupBoolOption(optlist, name, deflt, FALSE);
+}
+
+/*
+ * addNewOption() has the required property of replacing the option value
+ * if the option is already present.
+ */
+pointer
+xf86ReplaceIntOption(pointer optlist, const char *name, const int val)
+{
+ char *tmp = xnfalloc(16);
+ sprintf(tmp,"%i",val);
+ return xf86AddNewOption(optlist,name,tmp);
+}
+
+pointer
+xf86ReplaceRealOption(pointer optlist, const char *name, const double val)
+{
+ char *tmp = xnfalloc(32);
+ snprintf(tmp,32,"%f",val);
+ return xf86AddNewOption(optlist,name,tmp);
+}
+
+pointer
+xf86ReplaceBoolOption(pointer optlist, const char *name, const Bool val)
+{
+ return xf86AddNewOption(optlist,name,val?"True":"False");
+}
+
+pointer
+xf86ReplaceStrOption(pointer optlist, const char *name, const char* val)
+{
+ return xf86AddNewOption(optlist,name,val);
+}
+
+pointer
+xf86AddNewOption(pointer head, const char *name, const char *val)
+{
+ /* XXX These should actually be allocated in the parser library. */
+ char *tmp = strdup(val);
+ char *tmp_name = strdup(name);
+
+ return xf86addNewOption(head, tmp_name, tmp);
+}
+
+
+pointer
+xf86NewOption(char *name, char *value)
+{
+ return xf86newOption(name, value);
+}
+
+
+pointer
+xf86NextOption(pointer list)
+{
+ return xf86nextOption(list);
+}
+
+pointer
+xf86OptionListCreate(const char **options, int count, int used)
+{
+ return xf86optionListCreate(options, count, used);
+}
+
+pointer
+xf86OptionListMerge(pointer head, pointer tail)
+{
+ return xf86optionListMerge(head, tail);
+}
+
+void
+xf86OptionListFree(pointer opt)
+{
+ xf86optionListFree(opt);
+}
+
+char *
+xf86OptionName(pointer opt)
+{
+ return xf86optionName(opt);
+}
+
+char *
+xf86OptionValue(pointer opt)
+{
+ return xf86optionValue(opt);
+}
+
+void
+xf86OptionListReport(pointer parm)
+{
+ XF86OptionPtr opts = parm;
+
+ while(opts) {
+ if (xf86optionValue(opts))
+ xf86ErrorFVerb(5, "\tOption \"%s\" \"%s\"\n",
+ xf86optionName(opts), xf86optionValue(opts));
+ else
+ xf86ErrorFVerb( 5, "\tOption \"%s\"\n", xf86optionName(opts));
+ opts = xf86nextOption(opts);
+ }
+}
+
+/* End of XInput-caused section */
+
+pointer
+xf86FindOption(pointer options, const char *name)
+{
+ return xf86findOption(options, name);
+}
+
+
+char *
+xf86FindOptionValue(pointer options, const char *name)
+{
+ return xf86findOptionValue(options, name);
+}
+
+
+void
+xf86MarkOptionUsed(pointer option)
+{
+ if (option != NULL)
+ ((XF86OptionPtr)option)->opt_used = TRUE;
+}
+
+
+void
+xf86MarkOptionUsedByName(pointer options, const char *name)
+{
+ XF86OptionPtr opt;
+
+ opt = xf86findOption(options, name);
+ if (opt != NULL)
+ opt->opt_used = TRUE;
+}
+
+Bool
+xf86CheckIfOptionUsed(pointer option)
+{
+ if (option != NULL)
+ return ((XF86OptionPtr)option)->opt_used;
+ else
+ return FALSE;
+}
+
+Bool
+xf86CheckIfOptionUsedByName(pointer options, const char *name)
+{
+ XF86OptionPtr opt;
+
+ opt = xf86findOption(options, name);
+ if (opt != NULL)
+ return opt->opt_used;
+ else
+ return FALSE;
+}
+
+void
+xf86ShowUnusedOptions(int scrnIndex, pointer options)
+{
+ XF86OptionPtr opt = options;
+
+ while (opt) {
+ if (opt->opt_name && !opt->opt_used) {
+ xf86DrvMsg(scrnIndex, X_WARNING, "Option \"%s\" is not used\n",
+ opt->opt_name);
+ }
+ opt = opt->list.next;
+ }
+}
+
+
+static Bool
+GetBoolValue(OptionInfoPtr p, const char *s)
+{
+ if (*s == '\0') {
+ p->value.bool = TRUE;
+ } else {
+ if (xf86NameCmp(s, "1") == 0)
+ p->value.bool = TRUE;
+ else if (xf86NameCmp(s, "on") == 0)
+ p->value.bool = TRUE;
+ else if (xf86NameCmp(s, "true") == 0)
+ p->value.bool = TRUE;
+ else if (xf86NameCmp(s, "yes") == 0)
+ p->value.bool = TRUE;
+ else if (xf86NameCmp(s, "0") == 0)
+ p->value.bool = FALSE;
+ else if (xf86NameCmp(s, "off") == 0)
+ p->value.bool = FALSE;
+ else if (xf86NameCmp(s, "false") == 0)
+ p->value.bool = FALSE;
+ else if (xf86NameCmp(s, "no") == 0)
+ p->value.bool = FALSE;
+ else
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static Bool
+ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
+ Bool markUsed)
+{
+ char *s, *end;
+ Bool wasUsed = FALSE;
+
+ if ((s = xf86findOptionValue(options, p->name)) != NULL) {
+ if (markUsed) {
+ wasUsed = xf86CheckIfOptionUsedByName(options, p->name);
+ xf86MarkOptionUsedByName(options, p->name);
+ }
+ switch (p->type) {
+ case OPTV_INTEGER:
+ if (*s == '\0') {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires an integer value\n",
+ p->name);
+ p->found = FALSE;
+ } else {
+ p->value.num = strtoul(s, &end, 0);
+ if (*end == '\0') {
+ p->found = TRUE;
+ } else {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires an integer value\n",
+ p->name);
+ p->found = FALSE;
+ }
+ }
+ break;
+ case OPTV_STRING:
+ if (*s == '\0') {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires an string value\n",
+ p->name);
+ p->found = FALSE;
+ } else {
+ p->value.str = s;
+ p->found = TRUE;
+ }
+ break;
+ case OPTV_ANYSTR:
+ p->value.str = s;
+ p->found = TRUE;
+ break;
+ case OPTV_REAL:
+ if (*s == '\0') {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires a floating point value\n",
+ p->name);
+ p->found = FALSE;
+ } else {
+ p->value.realnum = strtod(s, &end);
+ if (*end == '\0') {
+ p->found = TRUE;
+ } else {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires a floating point value\n",
+ p->name);
+ p->found = FALSE;
+ }
+ }
+ break;
+ case OPTV_BOOLEAN:
+ if (GetBoolValue(p, s)) {
+ p->found = TRUE;
+ } else {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires a boolean value\n", p->name);
+ p->found = FALSE;
+ }
+ break;
+ case OPTV_FREQ:
+ if (*s == '\0') {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires a frequency value\n",
+ p->name);
+ p->found = FALSE;
+ } else {
+ double freq = strtod(s, &end);
+ int units = 0;
+
+ if (end != s) {
+ p->found = TRUE;
+ if (!xf86NameCmp(end, "Hz"))
+ units = 1;
+ else if (!xf86NameCmp(end, "kHz") ||
+ !xf86NameCmp(end, "k"))
+ units = 1000;
+ else if (!xf86NameCmp(end, "MHz") ||
+ !xf86NameCmp(end, "M"))
+ units = 1000000;
+ else {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires a frequency value\n",
+ p->name);
+ p->found = FALSE;
+ }
+ if (p->found)
+ freq *= (double)units;
+ } else {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires a frequency value\n",
+ p->name);
+ p->found = FALSE;
+ }
+ if (p->found) {
+ p->value.freq.freq = freq;
+ p->value.freq.units = units;
+ }
+ }
+ break;
+ case OPTV_NONE:
+ /* Should never get here */
+ p->found = FALSE;
+ break;
+ }
+ if (p->found && markUsed) {
+ int verb = 2;
+ if (wasUsed)
+ verb = 4;
+ xf86DrvMsgVerb(scrnIndex, X_CONFIG, verb, "Option \"%s\"", p->name);
+ if (!(p->type == OPTV_BOOLEAN && *s == 0)) {
+ xf86ErrorFVerb(verb, " \"%s\"", s);
+ }
+ xf86ErrorFVerb(verb, "\n");
+ }
+ } else if (p->type == OPTV_BOOLEAN) {
+ /* Look for matches with options with or without a "No" prefix. */
+ char *n, *newn;
+ OptionInfoRec opt;
+
+ n = xf86NormalizeName(p->name);
+ if (!n) {
+ p->found = FALSE;
+ return FALSE;
+ }
+ if (strncmp(n, "no", 2) == 0) {
+ newn = n + 2;
+ } else {
+ xfree(n);
+ n = xalloc(strlen(p->name) + 2 + 1);
+ if (!n) {
+ p->found = FALSE;
+ return FALSE;
+ }
+ strcpy(n, "No");
+ strcat(n, p->name);
+ newn = n;
+ }
+ if ((s = xf86findOptionValue(options, newn)) != NULL) {
+ if (markUsed)
+ xf86MarkOptionUsedByName(options, newn);
+ if (GetBoolValue(&opt, s)) {
+ p->value.bool = !opt.value.bool;
+ p->found = TRUE;
+ } else {
+ xf86DrvMsg(scrnIndex, X_WARNING,
+ "Option \"%s\" requires a boolean value\n", newn);
+ p->found = FALSE;
+ }
+ } else {
+ p->found = FALSE;
+ }
+ if (p->found && markUsed) {
+ xf86DrvMsgVerb(scrnIndex, X_CONFIG, 2, "Option \"%s\"", newn);
+ if (*s != 0) {
+ xf86ErrorFVerb(2, " \"%s\"", s);
+ }
+ xf86ErrorFVerb(2, "\n");
+ }
+ xfree(n);
+ } else {
+ p->found = FALSE;
+ }
+ return p->found;
+}
+
+
+void
+xf86ProcessOptions(int scrnIndex, pointer options, OptionInfoPtr optinfo)
+{
+ OptionInfoPtr p;
+
+ for (p = optinfo; p->name != NULL; p++) {
+ ParseOptionValue(scrnIndex, options, p, TRUE);
+ }
+}
+
+
+OptionInfoPtr
+xf86TokenToOptinfo(const OptionInfoRec *table, int token)
+{
+ const OptionInfoRec *p, *match = NULL, *set = NULL;
+
+ if (!table) {
+ ErrorF("xf86TokenToOptinfo: table is NULL\n");
+ return NULL;
+ }
+
+ for (p = table; p->token >= 0; p++) {
+ if (p->token == token) {
+ match = p;
+ if (p->found)
+ set = p;
+ }
+ }
+
+ if (set)
+ return (OptionInfoPtr)set;
+ else if (match)
+ return (OptionInfoPtr)match;
+ else
+ return NULL;
+}
+
+
+const char *
+xf86TokenToOptName(const OptionInfoRec *table, int token)
+{
+ const OptionInfoRec *p;
+
+ p = xf86TokenToOptinfo(table, token);
+ return p->name;
+}
+
+
+Bool
+xf86IsOptionSet(const OptionInfoRec *table, int token)
+{
+ OptionInfoPtr p;
+
+ p = xf86TokenToOptinfo(table, token);
+ return (p && p->found);
+}
+
+
+char *
+xf86GetOptValString(const OptionInfoRec *table, int token)
+{
+ OptionInfoPtr p;
+
+ p = xf86TokenToOptinfo(table, token);
+ if (p && p->found)
+ return p->value.str;
+ else
+ return NULL;
+}
+
+
+Bool
+xf86GetOptValInteger(const OptionInfoRec *table, int token, int *value)
+{
+ OptionInfoPtr p;
+
+ p = xf86TokenToOptinfo(table, token);
+ if (p && p->found) {
+ *value = p->value.num;
+ return TRUE;
+ } else
+ return FALSE;
+}
+
+
+Bool
+xf86GetOptValULong(const OptionInfoRec *table, int token, unsigned long *value)
+{
+ OptionInfoPtr p;
+
+ p = xf86TokenToOptinfo(table, token);
+ if (p && p->found) {
+ *value = p->value.num;
+ return TRUE;
+ } else
+ return FALSE;
+}
+
+
+Bool
+xf86GetOptValReal(const OptionInfoRec *table, int token, double *value)
+{
+ OptionInfoPtr p;
+
+ p = xf86TokenToOptinfo(table, token);
+ if (p && p->found) {
+ *value = p->value.realnum;
+ return TRUE;
+ } else
+ return FALSE;
+}
+
+
+Bool
+xf86GetOptValFreq(const OptionInfoRec *table, int token,
+ OptFreqUnits expectedUnits, double *value)
+{
+ OptionInfoPtr p;
+
+ p = xf86TokenToOptinfo(table, token);
+ if (p && p->found) {
+ if (p->value.freq.units > 0) {
+ /* Units give, so the scaling is known. */
+ switch (expectedUnits) {
+ case OPTUNITS_HZ:
+ *value = p->value.freq.freq;
+ break;
+ case OPTUNITS_KHZ:
+ *value = p->value.freq.freq / 1000.0;
+ break;
+ case OPTUNITS_MHZ:
+ *value = p->value.freq.freq / 1000000.0;
+ break;
+ }
+ } else {
+ /* No units given, so try to guess the scaling. */
+ switch (expectedUnits) {
+ case OPTUNITS_HZ:
+ *value = p->value.freq.freq;
+ break;
+ case OPTUNITS_KHZ:
+ if (p->value.freq.freq > 1000.0)
+ *value = p->value.freq.freq / 1000.0;
+ else
+ *value = p->value.freq.freq;
+ break;
+ case OPTUNITS_MHZ:
+ if (p->value.freq.freq > 1000000.0)
+ *value = p->value.freq.freq / 1000000.0;
+ else if (p->value.freq.freq > 1000.0)
+ *value = p->value.freq.freq / 1000.0;
+ else
+ *value = p->value.freq.freq;
+ }
+ }
+ return TRUE;
+ } else
+ return FALSE;
+}
+
+
+Bool
+xf86GetOptValBool(const OptionInfoRec *table, int token, Bool *value)
+{
+ OptionInfoPtr p;
+
+ p = xf86TokenToOptinfo(table, token);
+ if (p && p->found) {
+ *value = p->value.bool;
+ return TRUE;
+ } else
+ return FALSE;
+}
+
+
+Bool
+xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def)
+{
+ OptionInfoPtr p;
+
+ p = xf86TokenToOptinfo(table, token);
+ if (p && p->found) {
+ return p->value.bool;
+ } else
+ return def;
+}
+
+
+int
+xf86NameCmp(const char *s1, const char *s2)
+{
+ return xf86nameCompare(s1, s2);
+}
+
+char *
+xf86NormalizeName(const char *s)
+{
+ char *ret, *q;
+ const char *p;
+
+ if (s == NULL)
+ return NULL;
+
+ ret = xalloc(strlen(s) + 1);
+ for (p = s, q = ret; *p != 0; p++) {
+ switch (*p) {
+ case '_':
+ case ' ':
+ case '\t':
+ continue;
+ default:
+ if (isupper(*p))
+ *q++ = tolower(*p);
+ else
+ *q++ = *p;
+ }
+ }
+ *q = '\0';
+ return ret;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86PM.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86PM.c
new file mode 100644
index 000000000..0262be3df
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86PM.c
@@ -0,0 +1,225 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86PM.c,v 3.9 2003/08/24 17:36:54 dawes Exp $ */
+/*
+ * Copyright (c) 2000-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).
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Xinput.h"
+
+int (*xf86PMGetEventFromOs)(int fd,pmEvent *events,int num) = NULL;
+pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event) = NULL;
+
+static Bool suspended = FALSE;
+
+static int
+eventName(pmEvent event, char **str)
+{
+ switch(event) {
+ case XF86_APM_SYS_STANDBY: *str="System Standby Request"; return 0;
+ case XF86_APM_SYS_SUSPEND: *str="System Suspend Request"; return 0;
+ case XF86_APM_CRITICAL_SUSPEND: *str="Critical Suspend"; return 0;
+ case XF86_APM_USER_STANDBY: *str="User System Standby Request"; return 0;
+ case XF86_APM_USER_SUSPEND: *str="User System Suspend Request"; return 0;
+ case XF86_APM_STANDBY_RESUME: *str="System Standby Resume"; return 0;
+ case XF86_APM_NORMAL_RESUME: *str="Normal Resume System"; return 0;
+ case XF86_APM_CRITICAL_RESUME: *str="Critical Resume System"; return 0;
+ case XF86_APM_LOW_BATTERY: *str="Battery Low"; return 3;
+ case XF86_APM_POWER_STATUS_CHANGE: *str="Power Status Change";return 3;
+ case XF86_APM_UPDATE_TIME: *str="Update Time";return 3;
+ case XF86_APM_CAPABILITY_CHANGED: *str="Capability Changed"; return 3;
+ case XF86_APM_STANDBY_FAILED: *str="Standby Request Failed"; return 0;
+ case XF86_APM_SUSPEND_FAILED: *str="Suspend Request Failed"; return 0;
+ default: *str="Unknown Event"; return 0;
+ }
+}
+
+static void
+suspend (pmEvent event, Bool undo)
+{
+ int i;
+ InputInfoPtr pInfo;
+
+ xf86inSuspend = TRUE;
+
+ for (i = 0; i < xf86NumScreens; i++) {
+ xf86EnableAccess(xf86Screens[i]);
+ if (xf86Screens[i]->EnableDisableFBAccess)
+ (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE);
+ }
+#if !defined(__EMX__)
+ pInfo = xf86InputDevs;
+ while (pInfo) {
+ DisableDevice(pInfo->dev);
+ pInfo = pInfo->next;
+ }
+#endif
+ xf86EnterServerState(SETUP);
+ for (i = 0; i < xf86NumScreens; i++) {
+ xf86EnableAccess(xf86Screens[i]);
+ if (xf86Screens[i]->PMEvent)
+ xf86Screens[i]->PMEvent(i,event,undo);
+ else {
+ xf86Screens[i]->LeaveVT(i, 0);
+ xf86Screens[i]->vtSema = FALSE;
+ }
+ }
+ xf86AccessLeave();
+ xf86AccessLeaveState();
+}
+
+static void
+resume(pmEvent event, Bool undo)
+{
+ int i;
+ InputInfoPtr pInfo;
+
+ xf86AccessEnter();
+ xf86EnterServerState(SETUP);
+ for (i = 0; i < xf86NumScreens; i++) {
+ xf86EnableAccess(xf86Screens[i]);
+ if (xf86Screens[i]->PMEvent)
+ xf86Screens[i]->PMEvent(i,event,undo);
+ else {
+ xf86Screens[i]->vtSema = TRUE;
+ xf86Screens[i]->EnterVT(i, 0);
+ }
+ }
+ xf86EnterServerState(OPERATING);
+ for (i = 0; i < xf86NumScreens; i++) {
+ xf86EnableAccess(xf86Screens[i]);
+ if (xf86Screens[i]->EnableDisableFBAccess)
+ (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE);
+ }
+ SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
+#if !defined(__EMX__)
+ pInfo = xf86InputDevs;
+ while (pInfo) {
+ EnableDevice(pInfo->dev);
+ pInfo = pInfo->next;
+ }
+#endif
+ xf86inSuspend = FALSE;
+}
+
+static void
+DoApmEvent(pmEvent event, Bool undo)
+{
+ /*
+ * we leave that as a global function for now. I don't know if
+ * this might cause problems in the future. It is a global server
+ * variable therefore it needs to be in a server info structure
+ */
+ int i, setup = 0;
+
+ switch(event) {
+#if 0
+ case XF86_APM_SYS_STANDBY:
+ case XF86_APM_USER_STANDBY:
+#endif
+ case XF86_APM_SYS_SUSPEND:
+ case XF86_APM_CRITICAL_SUSPEND: /*do we want to delay a critical suspend?*/
+ case XF86_APM_USER_SUSPEND:
+ /* should we do this ? */
+ if (!undo && !suspended) {
+ suspend(event,undo);
+ suspended = TRUE;
+ } else if (undo && suspended) {
+ resume(event,undo);
+ suspended = FALSE;
+ }
+ break;
+#if 0
+ case XF86_APM_STANDBY_RESUME:
+#endif
+ case XF86_APM_NORMAL_RESUME:
+ case XF86_APM_CRITICAL_RESUME:
+ if (suspended) {
+ resume(event,undo);
+ suspended = FALSE;
+ }
+ break;
+ default:
+ for (i = 0; i < xf86NumScreens; i++) {
+ if (xf86Screens[i]->PMEvent) {
+ if (!setup) xf86EnterServerState(SETUP);
+ setup = 1;
+ xf86EnableAccess(xf86Screens[i]);
+ xf86Screens[i]->PMEvent(i,event,undo);
+ }
+ }
+ if (setup) xf86EnterServerState(OPERATING);
+ break;
+ }
+}
+
+#define MAX_NO_EVENTS 8
+
+void
+xf86HandlePMEvents(int fd, pointer data)
+{
+ pmEvent events[MAX_NO_EVENTS];
+ int i,n;
+ Bool wait = FALSE;
+
+ if (!xf86PMGetEventFromOs)
+ return;
+
+ if ((n = xf86PMGetEventFromOs(fd,events,MAX_NO_EVENTS))) {
+ do {
+ for (i = 0; i < n; i++) {
+ char *str = NULL;
+ int verb = eventName(events[i],&str);
+
+ xf86MsgVerb(X_INFO,verb,"PM Event received: %s\n",str);
+ DoApmEvent(events[i],FALSE);
+ switch (xf86PMConfirmEventToOs(fd,events[i])) {
+ case PM_WAIT:
+ wait = TRUE;
+ break;
+ case PM_CONTINUE:
+ wait = FALSE;
+ break;
+ case PM_FAILED:
+ DoApmEvent(events[i],TRUE);
+ wait = FALSE;
+ break;
+ default:
+ break;
+ }
+ }
+ if (wait)
+ n = xf86PMGetEventFromOs(fd,events,MAX_NO_EVENTS);
+ else
+ break;
+ } while (1);
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86PciInfo.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86PciInfo.h
new file mode 100644
index 000000000..183797e24
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86PciInfo.h
@@ -0,0 +1,726 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86PciInfo.h,v 1.156 2003/10/30 15:26:33 tsi Exp $ */
+
+/*
+ * Copyright (c) 1995-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 macros for the PCI Vendor and Device IDs for video
+ * cards plus a few other things that are needed in drivers or elsewhere.
+ * This information is used in several ways:
+ * 1. It is used by drivers and/or other code.
+ * 2. It is used by the pciid2c.pl script to determine what vendor data to
+ * include in the pcidata module that the X server loads.
+ * 3. A side-effect of 2. affects how config-generation works for
+ * otherwise "unknown" cards.
+ *
+ * Don't add entries here for vendors that don't make video cards,
+ * or for non-video devices unless they're needed by a driver or elsewhere.
+ * A comprehensive set of PCI vendor, device and subsystem data is
+ * auto-generated from the ../etc/pci.ids file using the pciids2c.pl script,
+ * and is used in both the scanpci module and the scanpci utility. Don't
+ * modify the pci.ids file. If new/corrected entries are required, add them
+ * to ../etc/extrapci.ids.
+ */
+
+#ifndef _XF86_PCIINFO_H
+#define _XF86_PCIINFO_H
+
+/* PCI Pseudo Vendor */
+#define PCI_VENDOR_GENERIC 0x00FF
+
+#define PCI_VENDOR_REAL3D 0x003D
+#define PCI_VENDOR_COMPAQ 0x0E11
+#define PCI_VENDOR_ATI 0x1002
+#define PCI_VENDOR_AVANCE 0x1005
+#define PCI_VENDOR_TSENG 0x100C
+#define PCI_VENDOR_NS 0x100B
+#define PCI_VENDOR_WEITEK 0x100E
+#define PCI_VENDOR_VIDEOLOGIC 0x1010
+#define PCI_VENDOR_DIGITAL 0x1011
+#define PCI_VENDOR_CIRRUS 0x1013
+#define PCI_VENDOR_AMD 0x1022
+#define PCI_VENDOR_TRIDENT 0x1023
+#define PCI_VENDOR_ALI 0x1025
+#define PCI_VENDOR_DELL 0x1028
+#define PCI_VENDOR_MATROX 0x102B
+#define PCI_VENDOR_CHIPSTECH 0x102C
+#define PCI_VENDOR_MIRO 0x1031
+#define PCI_VENDOR_NEC 0x1033
+#define PCI_VENDOR_SIS 0x1039
+#define PCI_VENDOR_HP 0x103C
+#define PCI_VENDOR_SGS 0x104A
+#define PCI_VENDOR_TI 0x104C
+#define PCI_VENDOR_SONY 0x104D
+#define PCI_VENDOR_OAK 0x104E
+#define PCI_VENDOR_MOTOROLA 0x1057
+#define PCI_VENDOR_NUMNINE 0x105D
+#define PCI_VENDOR_CYRIX 0x1078
+#define PCI_VENDOR_SUN 0x108E
+#define PCI_VENDOR_DIAMOND 0x1092
+#define PCI_VENDOR_BROOKTREE 0x109E
+#define PCI_VENDOR_NEOMAGIC 0x10C8
+#define PCI_VENDOR_NVIDIA 0x10DE
+#define PCI_VENDOR_IMS 0x10E0
+#define PCI_VENDOR_INTEGRAPHICS 0x10EA
+#define PCI_VENDOR_ALLIANCE 0x1142
+#define PCI_VENDOR_RENDITION 0x1163
+#define PCI_VENDOR_3DFX 0x121A
+#define PCI_VENDOR_SMI 0x126F
+#define PCI_VENDOR_TRITECH 0x1292
+#define PCI_VENDOR_NVIDIA_SGS 0x12D2
+#define PCI_VENDOR_VMWARE 0x15AD
+#define PCI_VENDOR_3DLABS 0x3D3D
+#define PCI_VENDOR_AVANCE_2 0x4005
+#define PCI_VENDOR_HERCULES 0x4843
+#define PCI_VENDOR_S3 0x5333
+#define PCI_VENDOR_INTEL 0x8086
+#define PCI_VENDOR_ARK 0xEDD8
+
+
+/* Generic */
+#define PCI_CHIP_VGA 0x0000
+#define PCI_CHIP_8514 0x0001
+
+/* Real 3D */
+#define PCI_CHIP_I740_PCI 0x00D1
+
+/* Compaq */
+#define PCI_CHIP_QV1280 0x3033
+
+/* ATI */
+#define PCI_CHIP_RV380_3150 0x3150
+#define PCI_CHIP_RV380_3151 0x3151
+#define PCI_CHIP_RV380_3152 0x3152
+#define PCI_CHIP_RV380_3153 0x3153
+#define PCI_CHIP_RV380_3154 0x3154
+#define PCI_CHIP_RV380_3156 0x3156
+#define PCI_CHIP_RV380_3E50 0x3E50
+#define PCI_CHIP_RV380_3E51 0x3E51
+#define PCI_CHIP_RV380_3E52 0x3E52
+#define PCI_CHIP_RV380_3E53 0x3E53
+#define PCI_CHIP_RV380_3E54 0x3E54
+#define PCI_CHIP_RV380_3E56 0x3E56
+#define PCI_CHIP_RS100_4136 0x4136
+#define PCI_CHIP_RS200_4137 0x4137
+#define PCI_CHIP_R300_AD 0x4144
+#define PCI_CHIP_R300_AE 0x4145
+#define PCI_CHIP_R300_AF 0x4146
+#define PCI_CHIP_R300_AG 0x4147
+#define PCI_CHIP_R350_AH 0x4148
+#define PCI_CHIP_R350_AI 0x4149
+#define PCI_CHIP_R350_AJ 0x414A
+#define PCI_CHIP_R350_AK 0x414B
+#define PCI_CHIP_RV350_AP 0x4150
+#define PCI_CHIP_RV350_AQ 0x4151
+#define PCI_CHIP_RV360_AR 0x4152
+#define PCI_CHIP_RV350_AS 0x4153
+#define PCI_CHIP_RV350_AT 0x4154
+#define PCI_CHIP_RV350_4155 0x4155
+#define PCI_CHIP_RV350_AV 0x4156
+#define PCI_CHIP_MACH32 0x4158
+#define PCI_CHIP_RS250_4237 0x4237
+#define PCI_CHIP_R200_BB 0x4242
+#define PCI_CHIP_R200_BC 0x4243
+#define PCI_CHIP_RS100_4336 0x4336
+#define PCI_CHIP_RS200_4337 0x4337
+#define PCI_CHIP_MACH64CT 0x4354
+#define PCI_CHIP_MACH64CX 0x4358
+#define PCI_CHIP_RS250_4437 0x4437
+#define PCI_CHIP_MACH64ET 0x4554
+#define PCI_CHIP_MACH64GB 0x4742
+#define PCI_CHIP_MACH64GD 0x4744
+#define PCI_CHIP_MACH64GI 0x4749
+#define PCI_CHIP_MACH64GL 0x474C
+#define PCI_CHIP_MACH64GM 0x474D
+#define PCI_CHIP_MACH64GN 0x474E
+#define PCI_CHIP_MACH64GO 0x474F
+#define PCI_CHIP_MACH64GP 0x4750
+#define PCI_CHIP_MACH64GQ 0x4751
+#define PCI_CHIP_MACH64GR 0x4752
+#define PCI_CHIP_MACH64GS 0x4753
+#define PCI_CHIP_MACH64GT 0x4754
+#define PCI_CHIP_MACH64GU 0x4755
+#define PCI_CHIP_MACH64GV 0x4756
+#define PCI_CHIP_MACH64GW 0x4757
+#define PCI_CHIP_MACH64GX 0x4758
+#define PCI_CHIP_MACH64GY 0x4759
+#define PCI_CHIP_MACH64GZ 0x475A
+#define PCI_CHIP_RV250_Id 0x4964
+#define PCI_CHIP_RV250_Ie 0x4965
+#define PCI_CHIP_RV250_If 0x4966
+#define PCI_CHIP_RV250_Ig 0x4967
+#define PCI_CHIP_R420_JH 0x4A48
+#define PCI_CHIP_R420_JI 0x4A49
+#define PCI_CHIP_R420_JJ 0x4A4A
+#define PCI_CHIP_R420_JK 0x4A4B
+#define PCI_CHIP_R420_JL 0x4A4C
+#define PCI_CHIP_R420_JM 0x4A4D
+#define PCI_CHIP_R420_JN 0x4A4E
+#define PCI_CHIP_R420_4A4F 0x4A4F
+#define PCI_CHIP_R420_JP 0x4A50
+#define PCI_CHIP_R481_4B49 0x4B49
+#define PCI_CHIP_R481_4B4A 0x4B4A
+#define PCI_CHIP_R481_4B4B 0x4B4B
+#define PCI_CHIP_R481_4B4C 0x4B4C
+#define PCI_CHIP_MACH64LB 0x4C42
+#define PCI_CHIP_MACH64LD 0x4C44
+#define PCI_CHIP_RAGE128LE 0x4C45
+#define PCI_CHIP_RAGE128LF 0x4C46
+#define PCI_CHIP_MACH64LG 0x4C47
+#define PCI_CHIP_MACH64LI 0x4C49
+#define PCI_CHIP_MACH64LM 0x4C4D
+#define PCI_CHIP_MACH64LN 0x4C4E
+#define PCI_CHIP_MACH64LP 0x4C50
+#define PCI_CHIP_MACH64LQ 0x4C51
+#define PCI_CHIP_MACH64LR 0x4C52
+#define PCI_CHIP_MACH64LS 0x4C53
+#define PCI_CHIP_RADEON_LW 0x4C57
+#define PCI_CHIP_RADEON_LX 0x4C58
+#define PCI_CHIP_RADEON_LY 0x4C59
+#define PCI_CHIP_RADEON_LZ 0x4C5A
+#define PCI_CHIP_RV250_Ld 0x4C64
+#define PCI_CHIP_RV250_Le 0x4C65
+#define PCI_CHIP_RV250_Lf 0x4C66
+#define PCI_CHIP_RV250_Lg 0x4C67
+#define PCI_CHIP_RV250_Ln 0x4C6E
+#define PCI_CHIP_RAGE128MF 0x4D46
+#define PCI_CHIP_RAGE128ML 0x4D4C
+#define PCI_CHIP_R300_ND 0x4E44
+#define PCI_CHIP_R300_NE 0x4E45
+#define PCI_CHIP_R300_NF 0x4E46
+#define PCI_CHIP_R300_NG 0x4E47
+#define PCI_CHIP_R350_NH 0x4E48
+#define PCI_CHIP_R350_NI 0x4E49
+#define PCI_CHIP_R360_NJ 0x4E4A
+#define PCI_CHIP_R350_NK 0x4E4B
+#define PCI_CHIP_RV350_NP 0x4E50
+#define PCI_CHIP_RV350_NQ 0x4E51
+#define PCI_CHIP_RV350_NR 0x4E52
+#define PCI_CHIP_RV350_NS 0x4E53
+#define PCI_CHIP_RV350_NT 0x4E54
+#define PCI_CHIP_RV350_NV 0x4E56
+#define PCI_CHIP_RAGE128PA 0x5041
+#define PCI_CHIP_RAGE128PB 0x5042
+#define PCI_CHIP_RAGE128PC 0x5043
+#define PCI_CHIP_RAGE128PD 0x5044
+#define PCI_CHIP_RAGE128PE 0x5045
+#define PCI_CHIP_RAGE128PF 0x5046
+#define PCI_CHIP_RAGE128PG 0x5047
+#define PCI_CHIP_RAGE128PH 0x5048
+#define PCI_CHIP_RAGE128PI 0x5049
+#define PCI_CHIP_RAGE128PJ 0x504A
+#define PCI_CHIP_RAGE128PK 0x504B
+#define PCI_CHIP_RAGE128PL 0x504C
+#define PCI_CHIP_RAGE128PM 0x504D
+#define PCI_CHIP_RAGE128PN 0x504E
+#define PCI_CHIP_RAGE128PO 0x504F
+#define PCI_CHIP_RAGE128PP 0x5050
+#define PCI_CHIP_RAGE128PQ 0x5051
+#define PCI_CHIP_RAGE128PR 0x5052
+#define PCI_CHIP_RAGE128PS 0x5053
+#define PCI_CHIP_RAGE128PT 0x5054
+#define PCI_CHIP_RAGE128PU 0x5055
+#define PCI_CHIP_RAGE128PV 0x5056
+#define PCI_CHIP_RAGE128PW 0x5057
+#define PCI_CHIP_RAGE128PX 0x5058
+#define PCI_CHIP_RADEON_QD 0x5144
+#define PCI_CHIP_RADEON_QE 0x5145
+#define PCI_CHIP_RADEON_QF 0x5146
+#define PCI_CHIP_RADEON_QG 0x5147
+#define PCI_CHIP_R200_QH 0x5148
+#define PCI_CHIP_R200_QI 0x5149
+#define PCI_CHIP_R200_QJ 0x514A
+#define PCI_CHIP_R200_QK 0x514B
+#define PCI_CHIP_R200_QL 0x514C
+#define PCI_CHIP_R200_QM 0x514D
+#define PCI_CHIP_R200_QN 0x514E
+#define PCI_CHIP_R200_QO 0x514F
+#define PCI_CHIP_RV200_QW 0x5157
+#define PCI_CHIP_RV200_QX 0x5158
+#define PCI_CHIP_RV100_QY 0x5159
+#define PCI_CHIP_RV100_QZ 0x515A
+#define PCI_CHIP_RN50_515E 0x515E
+#define PCI_CHIP_RAGE128RE 0x5245
+#define PCI_CHIP_RAGE128RF 0x5246
+#define PCI_CHIP_RAGE128RG 0x5247
+#define PCI_CHIP_RAGE128RK 0x524B
+#define PCI_CHIP_RAGE128RL 0x524C
+#define PCI_CHIP_RAGE128SE 0x5345
+#define PCI_CHIP_RAGE128SF 0x5346
+#define PCI_CHIP_RAGE128SG 0x5347
+#define PCI_CHIP_RAGE128SH 0x5348
+#define PCI_CHIP_RAGE128SK 0x534B
+#define PCI_CHIP_RAGE128SL 0x534C
+#define PCI_CHIP_RAGE128SM 0x534D
+#define PCI_CHIP_RAGE128SN 0x534E
+#define PCI_CHIP_RAGE128TF 0x5446
+#define PCI_CHIP_RAGE128TL 0x544C
+#define PCI_CHIP_RAGE128TR 0x5452
+#define PCI_CHIP_RAGE128TS 0x5453
+#define PCI_CHIP_RAGE128TT 0x5454
+#define PCI_CHIP_RAGE128TU 0x5455
+#define PCI_CHIP_RV370_5460 0x5460
+#define PCI_CHIP_RV370_5461 0x5461
+#define PCI_CHIP_RV370_5462 0x5462
+#define PCI_CHIP_RV370_5463 0x5463
+#define PCI_CHIP_RV370_5464 0x5464
+#define PCI_CHIP_RV370_5465 0x5465
+#define PCI_CHIP_RV370_5466 0x5466
+#define PCI_CHIP_RV370_5467 0x5467
+#define PCI_CHIP_R423_UH 0x5548
+#define PCI_CHIP_R423_UI 0x5549
+#define PCI_CHIP_R423_UJ 0x554A
+#define PCI_CHIP_R423_UK 0x554B
+#define PCI_CHIP_R430_554C 0x554C
+#define PCI_CHIP_R430_554D 0x554D
+#define PCI_CHIP_R430_554E 0x554E
+#define PCI_CHIP_R430_554F 0x554F
+#define PCI_CHIP_R423_5550 0x5550
+#define PCI_CHIP_R423_UQ 0x5551
+#define PCI_CHIP_R423_UR 0x5552
+#define PCI_CHIP_R423_UT 0x5554
+#define PCI_CHIP_RV410_564A 0x564A
+#define PCI_CHIP_RV410_564B 0x564B
+#define PCI_CHIP_RV410_5652 0x5652
+#define PCI_CHIP_RV410_5653 0x5653
+#define PCI_CHIP_MACH64VT 0x5654
+#define PCI_CHIP_MACH64VU 0x5655
+#define PCI_CHIP_MACH64VV 0x5656
+#define PCI_CHIP_RS300_5834 0x5834
+#define PCI_CHIP_RS300_5835 0x5835
+#define PCI_CHIP_RS300_5836 0x5836
+#define PCI_CHIP_RS300_5837 0x5837
+#define PCI_CHIP_RS480_5954 0x5954
+#define PCI_CHIP_RS480_5955 0x5955
+#define PCI_CHIP_RV280_5960 0x5960
+#define PCI_CHIP_RV280_5961 0x5961
+#define PCI_CHIP_RV280_5962 0x5962
+#define PCI_CHIP_RV280_5964 0x5964
+#define PCI_CHIP_RV280_5965 0x5965
+#define PCI_CHIP_RN50_5969 0x5969
+#define PCI_CHIP_RS482_5974 0x5974
+#define PCI_CHIP_RS482_5975 0x5975
+#define PCI_CHIP_RS400_5A41 0x5A41
+#define PCI_CHIP_RS400_5A42 0x5A42
+#define PCI_CHIP_RC410_5A61 0x5A61
+#define PCI_CHIP_RC410_5A62 0x5A62
+#define PCI_CHIP_RV370_5B60 0x5B60
+#define PCI_CHIP_RV370_5B61 0x5B61
+#define PCI_CHIP_RV370_5B62 0x5B62
+#define PCI_CHIP_RV370_5B63 0x5B63
+#define PCI_CHIP_RV370_5B64 0x5B64
+#define PCI_CHIP_RV370_5B65 0x5B65
+#define PCI_CHIP_RV370_5B66 0x5B66
+#define PCI_CHIP_RV370_5B67 0x5B67
+#define PCI_CHIP_RV280_5C61 0x5C61
+#define PCI_CHIP_RV280_5C63 0x5C63
+#define PCI_CHIP_R430_5D48 0x5D48
+#define PCI_CHIP_R430_5D49 0x5D49
+#define PCI_CHIP_R430_5D4A 0x5D4A
+#define PCI_CHIP_R480_5D4C 0x5D4C
+#define PCI_CHIP_R480_5D4D 0x5D4D
+#define PCI_CHIP_R480_5D4E 0x5D4E
+#define PCI_CHIP_R480_5D4F 0x5D4F
+#define PCI_CHIP_R480_5D50 0x5D50
+#define PCI_CHIP_R480_5D52 0x5D52
+#define PCI_CHIP_R423_5D57 0x5D57
+#define PCI_CHIP_RV410_5E48 0x5E48
+#define PCI_CHIP_RV410_5E4A 0x5E4A
+#define PCI_CHIP_RV410_5E4B 0x5E4B
+#define PCI_CHIP_RV410_5E4C 0x5E4C
+#define PCI_CHIP_RV410_5E4D 0x5E4D
+#define PCI_CHIP_RV410_5E4F 0x5E4F
+#define PCI_CHIP_RS350_7834 0x7834
+#define PCI_CHIP_RS350_7835 0x7835
+
+/* Avance Logic */
+#define PCI_CHIP_ALG2064 0x2064
+#define PCI_CHIP_ALG2301 0x2301
+#define PCI_CHIP_ALG2501 0x2501
+
+/* Tseng */
+#define PCI_CHIP_ET4000_W32P_A 0x3202
+#define PCI_CHIP_ET4000_W32P_B 0x3205
+#define PCI_CHIP_ET4000_W32P_D 0x3206
+#define PCI_CHIP_ET4000_W32P_C 0x3207
+#define PCI_CHIP_ET6000 0x3208
+#define PCI_CHIP_ET6300 0x4702
+
+/* Weitek */
+#define PCI_CHIP_P9000 0x9001
+#define PCI_CHIP_P9100 0x9100
+
+/* Digital */
+#define PCI_CHIP_DC21050 0x0001
+#define PCI_CHIP_DEC21030 0x0004
+#define PCI_CHIP_TGA2 0x000D
+
+/* Cirrus Logic */
+#define PCI_CHIP_GD7548 0x0038
+#define PCI_CHIP_GD7555 0x0040
+#define PCI_CHIP_GD5430 0x00A0
+#define PCI_CHIP_GD5434_4 0x00A4
+#define PCI_CHIP_GD5434_8 0x00A8
+#define PCI_CHIP_GD5436 0x00AC
+#define PCI_CHIP_GD5446 0x00B8
+#define PCI_CHIP_GD5480 0x00BC
+#define PCI_CHIP_GD5462 0x00D0
+#define PCI_CHIP_GD5464 0x00D4
+#define PCI_CHIP_GD5464BD 0x00D5
+#define PCI_CHIP_GD5465 0x00D6
+#define PCI_CHIP_6729 0x1100
+#define PCI_CHIP_6832 0x1110
+#define PCI_CHIP_GD7542 0x1200
+#define PCI_CHIP_GD7543 0x1202
+#define PCI_CHIP_GD7541 0x1204
+
+/* AMD */
+#define PCI_CHIP_AMD761 0x700E
+
+/* Trident */
+#define PCI_CHIP_2100 0x2100
+#define PCI_CHIP_8400 0x8400
+#define PCI_CHIP_8420 0x8420
+#define PCI_CHIP_8500 0x8500
+#define PCI_CHIP_8520 0x8520
+#define PCI_CHIP_8600 0x8600
+#define PCI_CHIP_8620 0x8620
+#define PCI_CHIP_8820 0x8820
+#define PCI_CHIP_9320 0x9320
+#define PCI_CHIP_9388 0x9388
+#define PCI_CHIP_9397 0x9397
+#define PCI_CHIP_939A 0x939A
+#define PCI_CHIP_9420 0x9420
+#define PCI_CHIP_9440 0x9440
+#define PCI_CHIP_9520 0x9520
+#define PCI_CHIP_9525 0x9525
+#define PCI_CHIP_9540 0x9540
+#define PCI_CHIP_9660 0x9660
+#define PCI_CHIP_9750 0x9750
+#define PCI_CHIP_9850 0x9850
+#define PCI_CHIP_9880 0x9880
+#define PCI_CHIP_9910 0x9910
+
+/* ALI */
+#define PCI_CHIP_M1435 0x1435
+
+/* Matrox */
+#define PCI_CHIP_MGA2085 0x0518
+#define PCI_CHIP_MGA2064 0x0519
+#define PCI_CHIP_MGA1064 0x051A
+#define PCI_CHIP_MGA2164 0x051B
+#define PCI_CHIP_MGA2164_AGP 0x051F
+#define PCI_CHIP_MGAG200_PCI 0x0520
+#define PCI_CHIP_MGAG200 0x0521
+#define PCI_CHIP_MGAG400 0x0525
+#define PCI_CHIP_MGAG550 0x2527
+#define PCI_CHIP_IMPRESSION 0x0D10
+#define PCI_CHIP_MGAG100_PCI 0x1000
+#define PCI_CHIP_MGAG100 0x1001
+
+#define PCI_CARD_G400_TH 0x2179
+#define PCI_CARD_MILL_G200_SD 0xFF00
+#define PCI_CARD_PROD_G100_SD 0xFF01
+#define PCI_CARD_MYST_G200_SD 0xFF02
+#define PCI_CARD_MILL_G200_SG 0xFF03
+#define PCI_CARD_MARV_G200_SD 0xFF04
+
+/* Chips & Tech */
+#define PCI_CHIP_65545 0x00D8
+#define PCI_CHIP_65548 0x00DC
+#define PCI_CHIP_65550 0x00E0
+#define PCI_CHIP_65554 0x00E4
+#define PCI_CHIP_65555 0x00E5
+#define PCI_CHIP_68554 0x00F4
+#define PCI_CHIP_69000 0x00C0
+#define PCI_CHIP_69030 0x0C30
+
+/* Miro */
+#define PCI_CHIP_ZR36050 0x5601
+
+/* NEC */
+#define PCI_CHIP_POWER_VR 0x0046
+
+/* SiS */
+#define PCI_CHIP_SG86C201 0x0001
+#define PCI_CHIP_SG86C202 0x0002
+#define PCI_CHIP_SG85C503 0x0008
+#define PCI_CHIP_SIS5597 0x0200
+/* Agregado por Carlos Duclos & Manuel Jander */
+#define PCI_CHIP_SIS82C204 0x0204
+#define PCI_CHIP_SG86C205 0x0205
+#define PCI_CHIP_SG86C215 0x0215
+#define PCI_CHIP_SG86C225 0x0225
+#define PCI_CHIP_85C501 0x0406
+#define PCI_CHIP_85C496 0x0496
+#define PCI_CHIP_85C601 0x0601
+#define PCI_CHIP_85C5107 0x5107
+#define PCI_CHIP_85C5511 0x5511
+#define PCI_CHIP_85C5513 0x5513
+#define PCI_CHIP_SIS5571 0x5571
+#define PCI_CHIP_SIS5597_2 0x5597
+#define PCI_CHIP_SIS530 0x6306
+#define PCI_CHIP_SIS6326 0x6326
+#define PCI_CHIP_SIS7001 0x7001
+#define PCI_CHIP_SIS300 0x0300
+#define PCI_CHIP_SIS315H 0x0310
+#define PCI_CHIP_SIS315PRO 0x0325
+#define PCI_CHIP_SIS330 0x0330
+#define PCI_CHIP_SIS630 0x6300
+#define PCI_CHIP_SIS540 0x5300
+#define PCI_CHIP_SIS550 0x5315
+#define PCI_CHIP_SIS650 0x6325
+#define PCI_CHIP_SIS730 0x7300
+
+/* Hewlett-Packard */
+#define PCI_CHIP_ELROY 0x1054
+#define PCI_CHIP_ZX1_SBA 0x1229
+#define PCI_CHIP_ZX1_IOC 0x122A
+#define PCI_CHIP_ZX1_LBA 0x122E /* a.k.a. Mercury */
+#define PCI_CHIP_ZX1_AGP8 0x12B4 /* a.k.a. QuickSilver */
+#define PCI_CHIP_ZX2_LBA 0x12EE
+#define PCI_CHIP_ZX2_SBA 0x4030
+#define PCI_CHIP_ZX2_IOC 0x4031
+
+/* SGS */
+#define PCI_CHIP_STG2000 0x0008
+#define PCI_CHIP_STG1764 0x0009
+#define PCI_CHIP_KYROII 0x0010
+
+/* Texas Instruments */
+#define PCI_CHIP_TI_PERMEDIA 0x3D04
+#define PCI_CHIP_TI_PERMEDIA2 0x3D07
+
+/* Oak */
+#define PCI_CHIP_OTI107 0x0107
+
+/* Number Nine */
+#define PCI_CHIP_I128 0x2309
+#define PCI_CHIP_I128_2 0x2339
+#define PCI_CHIP_I128_T2R 0x493D
+#define PCI_CHIP_I128_T2R4 0x5348
+
+/* Sun */
+#define PCI_CHIP_EBUS 0x1000
+#define PCI_CHIP_HAPPY_MEAL 0x1001
+#define PCI_CHIP_SIMBA 0x5000
+#define PCI_CHIP_PSYCHO 0x8000
+#define PCI_CHIP_SCHIZO 0x8001
+#define PCI_CHIP_SABRE 0xA000
+#define PCI_CHIP_HUMMINGBIRD 0xA001
+
+/* BrookTree */
+#define PCI_CHIP_BT848 0x0350
+#define PCI_CHIP_BT849 0x0351
+
+/* NVIDIA */
+#define PCI_CHIP_NV1 0x0008
+#define PCI_CHIP_DAC64 0x0009
+#define PCI_CHIP_TNT 0x0020
+#define PCI_CHIP_TNT2 0x0028
+#define PCI_CHIP_UTNT2 0x0029
+#define PCI_CHIP_VTNT2 0x002C
+#define PCI_CHIP_UVTNT2 0x002D
+#define PCI_CHIP_ITNT2 0x00A0
+#define PCI_CHIP_GEFORCE_256 0x0100
+#define PCI_CHIP_GEFORCE_DDR 0x0101
+#define PCI_CHIP_QUADRO 0x0103
+#define PCI_CHIP_GEFORCE2_MX 0x0110
+#define PCI_CHIP_GEFORCE2_MX_100 0x0111
+#define PCI_CHIP_GEFORCE2_GO 0x0112
+#define PCI_CHIP_QUADRO2_MXR 0x0113
+#define PCI_CHIP_GEFORCE2_GTS 0x0150
+#define PCI_CHIP_GEFORCE2_TI 0x0151
+#define PCI_CHIP_GEFORCE2_ULTRA 0x0152
+#define PCI_CHIP_QUADRO2_PRO 0x0153
+#define PCI_CHIP_GEFORCE4_MX_460 0x0170
+#define PCI_CHIP_GEFORCE4_MX_440 0x0171
+#define PCI_CHIP_GEFORCE4_MX_420 0x0172
+#define PCI_CHIP_GEFORCE4_440_GO 0x0174
+#define PCI_CHIP_GEFORCE4_420_GO 0x0175
+#define PCI_CHIP_GEFORCE4_420_GO_M32 0x0176
+#define PCI_CHIP_QUADRO4_500XGL 0x0178
+#define PCI_CHIP_GEFORCE4_440_GO_M64 0x0179
+#define PCI_CHIP_QUADRO4_200 0x017A
+#define PCI_CHIP_QUADRO4_550XGL 0x017B
+#define PCI_CHIP_QUADRO4_500_GOGL 0x017C
+#define PCI_CHIP_IGEFORCE2 0x01A0
+#define PCI_CHIP_GEFORCE3 0x0200
+#define PCI_CHIP_GEFORCE3_TI_200 0x0201
+#define PCI_CHIP_GEFORCE3_TI_500 0x0202
+#define PCI_CHIP_QUADRO_DCC 0x0203
+#define PCI_CHIP_GEFORCE4_TI_4600 0x0250
+#define PCI_CHIP_GEFORCE4_TI_4400 0x0251
+#define PCI_CHIP_GEFORCE4_TI_4200 0x0253
+#define PCI_CHIP_QUADRO4_900XGL 0x0258
+#define PCI_CHIP_QUADRO4_750XGL 0x0259
+#define PCI_CHIP_QUADRO4_700XGL 0x025B
+
+/* NVIDIA & SGS */
+#define PCI_CHIP_RIVA128 0x0018
+
+/* IMS */
+#define PCI_CHIP_IMSTT128 0x9128
+#define PCI_CHIP_IMSTT3D 0x9135
+
+/* Alliance Semiconductor */
+#define PCI_CHIP_AP6410 0x3210
+#define PCI_CHIP_AP6422 0x6422
+#define PCI_CHIP_AT24 0x6424
+#define PCI_CHIP_AT3D 0x643D
+
+/* 3dfx Interactive */
+#define PCI_CHIP_VOODOO_GRAPHICS 0x0001
+#define PCI_CHIP_VOODOO2 0x0002
+#define PCI_CHIP_BANSHEE 0x0003
+#define PCI_CHIP_VOODOO3 0x0005
+#define PCI_CHIP_VOODOO5 0x0009
+
+#define PCI_CARD_VOODOO3_2000 0x0036
+#define PCI_CARD_VOODOO3_3000 0x003A
+
+/* Rendition */
+#define PCI_CHIP_V1000 0x0001
+#define PCI_CHIP_V2x00 0x2000
+
+/* 3Dlabs */
+#define PCI_CHIP_300SX 0x0001
+#define PCI_CHIP_500TX 0x0002
+#define PCI_CHIP_DELTA 0x0003
+#define PCI_CHIP_PERMEDIA 0x0004
+#define PCI_CHIP_MX 0x0006
+#define PCI_CHIP_PERMEDIA2 0x0007
+#define PCI_CHIP_GAMMA 0x0008
+#define PCI_CHIP_PERMEDIA2V 0x0009
+#define PCI_CHIP_PERMEDIA3 0x000A
+#define PCI_CHIP_PERMEDIA4 0x000C
+#define PCI_CHIP_R4 0x000D
+#define PCI_CHIP_GAMMA2 0x000E
+#define PCI_CHIP_R4ALT 0x0011
+
+/* S3 */
+#define PCI_CHIP_PLATO 0x0551
+#define PCI_CHIP_VIRGE 0x5631
+#define PCI_CHIP_TRIO 0x8811
+#define PCI_CHIP_AURORA64VP 0x8812
+#define PCI_CHIP_TRIO64UVP 0x8814
+#define PCI_CHIP_VIRGE_VX 0x883D
+#define PCI_CHIP_868 0x8880
+#define PCI_CHIP_928 0x88B0
+#define PCI_CHIP_864_0 0x88C0
+#define PCI_CHIP_864_1 0x88C1
+#define PCI_CHIP_964_0 0x88D0
+#define PCI_CHIP_964_1 0x88D1
+#define PCI_CHIP_968 0x88F0
+#define PCI_CHIP_TRIO64V2_DXGX 0x8901
+#define PCI_CHIP_PLATO_PX 0x8902
+#define PCI_CHIP_Trio3D 0x8904
+#define PCI_CHIP_VIRGE_DXGX 0x8A01
+#define PCI_CHIP_VIRGE_GX2 0x8A10
+#define PCI_CHIP_Trio3D_2X 0x8A13
+#define PCI_CHIP_SAVAGE3D 0x8A20
+#define PCI_CHIP_SAVAGE3D_MV 0x8A21
+#define PCI_CHIP_SAVAGE4 0x8A22
+#define PCI_CHIP_PROSAVAGE_PM 0x8A25
+#define PCI_CHIP_PROSAVAGE_KM 0x8A26
+#define PCI_CHIP_VIRGE_MX 0x8C01
+#define PCI_CHIP_VIRGE_MXPLUS 0x8C02
+#define PCI_CHIP_VIRGE_MXP 0x8C03
+#define PCI_CHIP_SAVAGE_MX_MV 0x8C10
+#define PCI_CHIP_SAVAGE_MX 0x8C11
+#define PCI_CHIP_SAVAGE_IX_MV 0x8C12
+#define PCI_CHIP_SAVAGE_IX 0x8C13
+#define PCI_CHIP_SUPSAV_MX128 0x8C22
+#define PCI_CHIP_SUPSAV_MX64 0x8C24
+#define PCI_CHIP_SUPSAV_MX64C 0x8C26
+#define PCI_CHIP_SUPSAV_IX128SDR 0x8C2A
+#define PCI_CHIP_SUPSAV_IX128DDR 0x8C2B
+#define PCI_CHIP_SUPSAV_IX64SDR 0x8C2C
+#define PCI_CHIP_SUPSAV_IX64DDR 0x8C2D
+#define PCI_CHIP_SUPSAV_IXCSDR 0x8C2E
+#define PCI_CHIP_SUPSAV_IXCDDR 0x8C2F
+#define PCI_CHIP_S3TWISTER_P 0x8D01
+#define PCI_CHIP_S3TWISTER_K 0x8D02
+#define PCI_CHIP_PROSAVAGE_DDR 0x8D03
+#define PCI_CHIP_PROSAVAGE_DDRK 0x8D04
+#define PCI_CHIP_SAVAGE2000 0x9102
+
+/* ARK Logic */
+#define PCI_CHIP_1000PV 0xA091
+#define PCI_CHIP_2000PV 0xA099
+#define PCI_CHIP_2000MT 0xA0A1
+#define PCI_CHIP_2000MI 0xA0A9
+
+/* Tritech Microelectronics */
+#define PCI_CHIP_TR25202 0xFC02
+
+/* Neomagic */
+#define PCI_CHIP_NM2070 0x0001
+#define PCI_CHIP_NM2090 0x0002
+#define PCI_CHIP_NM2093 0x0003
+#define PCI_CHIP_NM2097 0x0083
+#define PCI_CHIP_NM2160 0x0004
+#define PCI_CHIP_NM2200 0x0005
+#define PCI_CHIP_NM2230 0x0025
+#define PCI_CHIP_NM2360 0x0006
+#define PCI_CHIP_NM2380 0x0016
+
+/* Intel */
+#define PCI_CHIP_I815_BRIDGE 0x1130
+#define PCI_CHIP_I815 0x1132
+#define PCI_CHIP_82801_P2P 0x244E
+#define PCI_CHIP_845_G_BRIDGE 0x2560
+#define PCI_CHIP_845_G 0x2562
+#define PCI_CHIP_I830_M_BRIDGE 0x3575
+#define PCI_CHIP_I830_M 0x3577
+#define PCI_CHIP_I810_BRIDGE 0x7120
+#define PCI_CHIP_I810 0x7121
+#define PCI_CHIP_I810_DC100_BRIDGE 0x7122
+#define PCI_CHIP_I810_DC100 0x7123
+#define PCI_CHIP_I810_E_BRIDGE 0x7124
+#define PCI_CHIP_I810_E 0x7125
+#define PCI_CHIP_I740_AGP 0x7800
+#define PCI_CHIP_460GX_PXB 0x84CB
+#define PCI_CHIP_460GX_SAC 0x84E0
+#define PCI_CHIP_460GX_GXB_2 0x84E2 /* PCI function 2 */
+#define PCI_CHIP_460GX_WXB 0x84E6
+#define PCI_CHIP_460GX_GXB_1 0x84EA /* PCI function 1 */
+
+/* Silicon Motion Inc. */
+#define PCI_CHIP_SMI910 0x0910
+#define PCI_CHIP_SMI810 0x0810
+#define PCI_CHIP_SMI820 0x0820
+#define PCI_CHIP_SMI710 0x0710
+#define PCI_CHIP_SMI712 0x0712
+#define PCI_CHIP_SMI720 0x0720
+#define PCI_CHIP_SMI731 0x0730
+
+/* VMware */
+#define PCI_CHIP_VMWARE0405 0x0405
+#define PCI_CHIP_VMWARE0710 0x0710
+
+#endif /* _XF86_PCIINFO_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Priv.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Priv.h
new file mode 100644
index 000000000..f32fa768d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Priv.h
@@ -0,0 +1,228 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Priv.h,v 3.83 2004/01/27 01:31:45 dawes Exp $ */
+
+/*
+ * 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).
+ */
+
+/*
+ * This file contains declarations for private XFree86 functions and variables,
+ * and definitions of private macros.
+ *
+ * "private" means not available to video drivers.
+ */
+
+#ifndef _XF86PRIV_H
+#define _XF86PRIV_H
+
+#include "xf86Privstr.h"
+#include "propertyst.h"
+
+/*
+ * Parameters set ONLY from the command line options
+ * The global state of these things is held in xf86InfoRec (when appropriate).
+ */
+extern const char *xf86ConfigFile;
+extern Bool xf86AllowMouseOpenFail;
+#ifdef XF86VIDMODE
+extern Bool xf86VidModeDisabled;
+extern Bool xf86VidModeAllowNonLocal;
+#endif
+#ifdef XF86MISC
+extern Bool xf86MiscModInDevDisabled;
+extern Bool xf86MiscModInDevAllowNonLocal;
+#endif
+extern Bool xf86fpFlag;
+extern Bool xf86coFlag;
+extern Bool xf86sFlag;
+extern Bool xf86bsEnableFlag;
+extern Bool xf86bsDisableFlag;
+extern Bool xf86silkenMouseDisableFlag;
+extern Bool xf86acpiDisableFlag;
+extern char *xf86LayoutName;
+extern char *xf86ScreenName;
+extern char *xf86PointerName;
+extern char *xf86KeyboardName;
+#ifdef KEEPBPP
+extern int xf86Bpp;
+#endif
+extern int xf86FbBpp;
+extern int xf86Depth;
+extern Pix24Flags xf86Pix24;
+extern rgb xf86Weight;
+extern Bool xf86FlipPixels;
+extern Bool xf86BestRefresh;
+extern Gamma xf86Gamma;
+extern char *xf86ServerName;
+extern Bool xf86ShowUnresolved;
+extern PciBusId xf86IsolateDevice;
+
+/* Other parameters */
+
+extern xf86InfoRec xf86Info;
+extern const char *xf86InputDeviceList;
+extern const char *xf86ModulePath;
+extern MessageType xf86ModPathFrom;
+extern const char *xf86LogFile;
+extern MessageType xf86LogFileFrom;
+extern Bool xf86LogFileWasOpened;
+extern serverLayoutRec xf86ConfigLayout;
+extern Pix24Flags xf86ConfigPix24;
+
+extern unsigned short xf86MouseCflags[];
+extern Bool xf86SupportedMouseTypes[];
+extern int xf86NumMouseTypes;
+
+#ifdef XFree86LOADER
+extern DriverPtr *xf86DriverList;
+extern ModuleInfoPtr *xf86ModuleInfoList;
+extern int xf86NumModuleInfos;
+#else
+extern DriverPtr xf86DriverList[];
+#endif
+extern int xf86NumDrivers;
+extern Bool xf86Resetting;
+extern Bool xf86Initialising;
+extern Bool xf86ProbeFailed;
+extern int xf86NumScreens;
+extern pciVideoPtr *xf86PciVideoInfo;
+extern xf86CurrentAccessRec xf86CurrentAccess;
+extern const char *xf86VisualNames[];
+extern int xf86Verbose; /* verbosity level */
+extern int xf86LogVerbose; /* log file verbosity level */
+extern Bool xf86ProbeOnly;
+extern Bool xf86DoProbe;
+extern Bool xorgHWAccess;
+
+extern RootWinPropPtr *xf86RegisteredPropertiesTable;
+
+#ifndef DEFAULT_VERBOSE
+#define DEFAULT_VERBOSE 0
+#endif
+#ifndef DEFAULT_LOG_VERBOSE
+#define DEFAULT_LOG_VERBOSE 3
+#endif
+#ifndef DEFAULT_DPI
+#define DEFAULT_DPI 75
+#endif
+
+#define DEFAULT_UNRESOLVED TRUE
+#define DEFAULT_BEST_REFRESH FALSE
+
+/* Function Prototypes */
+#ifndef _NO_XF86_PROTOTYPES
+
+/* xf86Bus.c */
+
+void xf86BusProbe(void);
+void xf86ChangeBusIndex(int oldIndex, int newIndex);
+void xf86AccessInit(void);
+void xf86AccessEnter(void);
+void xf86AccessLeave(void);
+void xf86EntityInit(void);
+void xf86EntityEnter(void);
+void xf86EntityLeave(void);
+void xf86AccessLeaveState(void);
+
+void xf86FindPrimaryDevice(void);
+/* new RAC */
+void xf86ResourceBrokerInit(void);
+void xf86PostProbe(void);
+void xf86ClearEntityListForScreen(int scrnIndex);
+void xf86AddDevToEntity(int entityIndex, GDevPtr dev);
+extern void xf86PostPreInit(void);
+extern void xf86PostScreenInit(void);
+extern memType getValidBIOSBase(PCITAG tag, int num);
+extern int pciTestMultiDeviceCard(int bus, int dev, int func, PCITAG** pTag);
+
+/* xf86Config.c */
+
+Bool xf86PathIsAbsolute(const char *path);
+Bool xf86PathIsSafe(const char *path);
+
+/* xf86DefaultModes */
+
+extern DisplayModeRec xf86DefaultModes [];
+
+/* xf86DoScanPci.c */
+
+void DoScanPci(int argc, char **argv, int i);
+
+/* xf86DoProbe.c */
+void DoProbeArgs(int argc, char **argv, int i);
+void DoProbe(void);
+void DoConfigure(void);
+
+/* xf86Events.c */
+
+void xf86PostKbdEvent(unsigned key);
+void xf86PostMseEvent(DeviceIntPtr device, int buttons, int dx, int dy);
+void xf86Wakeup(pointer blockData, int err, pointer pReadmask);
+void xf86SigHandler(int signo);
+#ifdef MEMDEBUG
+void xf86SigMemDebug(int signo);
+#endif
+void xf86HandlePMEvents(int fd, pointer data);
+extern int (*xf86PMGetEventFromOs)(int fd,pmEvent *events,int num);
+extern pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event);
+void xf86GrabServerCallback(CallbackListPtr *, pointer, pointer);
+
+/* xf86Helper.c */
+void xf86LogInit(void);
+void xf86CloseLog(void);
+
+/* xf86Init.c */
+Bool xf86LoadModules(char **list, pointer *optlist);
+int xf86SetVerbosity(int verb);
+int xf86SetLogVerbosity(int verb);
+
+/* xf86Io.c */
+
+void xf86KbdBell(int percent, DeviceIntPtr pKeyboard, pointer ctrl,
+ int unused);
+void xf86KbdLeds(void);
+void xf86UpdateKbdLeds(void);
+void xf86KbdCtrl(DevicePtr pKeyboard, KeybdCtrl *ctrl);
+void xf86InitKBD(Bool init);
+int xf86KbdProc(DeviceIntPtr pKeyboard, int what);
+
+/* xf86Kbd.c */
+
+void xf86KbdGetMapping(KeySymsPtr pKeySyms, CARD8 *pModMap);
+
+/* xf86Lock.c */
+
+#ifdef USE_XF86_SERVERLOCK
+void xf86UnlockServer(void);
+#endif
+
+/* xf86XKB.c */
+
+void xf86InitXkb(void);
+
+#endif /* _NO_XF86_PROTOTYPES */
+
+
+#endif /* _XF86PRIV_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Privstr.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Privstr.h
new file mode 100644
index 000000000..2f15e14cb
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Privstr.h
@@ -0,0 +1,234 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Privstr.h,v 1.41 2004/01/27 01:31:45 dawes Exp $ */
+
+/*
+ * 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 definitions of the private XFree86 data structures/types.
+ * None of the data structures here should be used by video drivers.
+ */
+
+#ifndef _XF86PRIVSTR_H
+#define _XF86PRIVSTR_H
+
+#include "xf86Pci.h"
+#include "xf86str.h"
+
+/* PCI probe flags */
+
+typedef enum {
+ PCIProbe1 = 0,
+ PCIProbe2,
+ PCIForceConfig1,
+ PCIForceConfig2,
+ PCIForceNone,
+ PCIOsConfig
+} PciProbeType;
+
+typedef enum {
+ LogNone,
+ LogFlush,
+ LogSync
+} Log;
+
+typedef enum {
+ SKNever,
+ SKWhenNeeded,
+ SKAlways
+} SpecialKeysInDDX;
+
+/*
+ * xf86InfoRec contains global parameters which the video drivers never
+ * need to access. Global parameters which the video drivers do need
+ * should be individual globals.
+ */
+
+typedef struct {
+
+ /* keyboard part */
+ DeviceIntPtr pKeyboard;
+ DeviceProc kbdProc; /* procedure for initializing */
+ void (* kbdEvents)(void); /* proc for processing events */
+ int consoleFd;
+ int kbdFd;
+ int vtno;
+ int kbdType; /* AT84 / AT101 */
+ int kbdRate;
+ int kbdDelay;
+ int bell_pitch;
+ int bell_duration;
+ Bool autoRepeat;
+ unsigned long leds;
+ unsigned long xleds;
+ char * vtinit;
+ int scanPrefix; /* scancode-state */
+ Bool capsLock;
+ Bool numLock;
+ Bool scrollLock;
+ Bool modeSwitchLock;
+ Bool composeLock;
+ Bool vtSysreq;
+ SpecialKeysInDDX ddxSpecialKeys;
+ Bool ActionKeyBindingsSet;
+#if defined(SVR4) && defined(i386)
+ Bool panix106;
+#endif /* SVR4 && i386 */
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+ int wsKbdType;
+#endif
+
+ /* mouse part */
+ DeviceIntPtr pMouse;
+#ifdef XINPUT
+ pointer mouseLocal;
+#endif
+
+ /* event handler part */
+ int lastEventTime;
+ Bool vtRequestsPending;
+ Bool inputPending;
+ Bool dontVTSwitch;
+ Bool dontZap;
+ Bool dontZoom;
+ Bool notrapSignals; /* don't exit cleanly - die at fault */
+ Bool caughtSignal;
+
+ /* graphics part */
+ Bool sharedMonitor;
+ ScreenPtr currentScreen;
+#if defined(CSRG_BASED) || defined(__FreeBSD_kernel__)
+ int screenFd; /* fd for memory mapped access to
+ * vga card */
+ int consType; /* Which console driver? */
+#endif
+
+#ifdef XKB
+ /*
+ * would like to use an XkbComponentNamesRec here but can't without
+ * pulling in a bunch of header files. :-(
+ */
+ char * xkbkeymap;
+ char * xkbkeycodes;
+ char * xkbtypes;
+ char * xkbcompat;
+ char * xkbsymbols;
+ char * xkbgeometry;
+ Bool xkbcomponents_specified;
+ char * xkbrules;
+ char * xkbmodel;
+ char * xkblayout;
+ char * xkbvariant;
+ char * xkboptions;
+#endif
+
+ /* Other things */
+ Bool allowMouseOpenFail;
+ Bool vidModeEnabled; /* VidMode extension enabled */
+ Bool vidModeAllowNonLocal; /* allow non-local VidMode
+ * connections */
+ Bool miscModInDevEnabled; /* Allow input devices to be
+ * changed */
+ Bool miscModInDevAllowNonLocal;
+ PciProbeType pciFlags;
+ Pix24Flags pixmap24;
+ MessageType pix24From;
+#if defined(i386) || defined(__i386__)
+ Bool pc98;
+#endif
+ Bool pmFlag;
+ Log log;
+ int estimateSizesAggressively;
+ Bool kbdCustomKeycodes;
+ Bool disableRandR;
+ MessageType randRFrom;
+ struct {
+ Bool disabled; /* enable/disable deactivating
+ * grabs or closing the
+ * connection to the grabbing
+ * client */
+ ClientPtr override; /* client that disabled
+ * grab deactivation.
+ */
+ Bool allowDeactivate;
+ Bool allowClosedown;
+ ServerGrabInfoRec server;
+ } grabInfo;
+} xf86InfoRec, *xf86InfoPtr;
+
+#ifdef DPMSExtension
+/* Private info for DPMS */
+typedef struct {
+ CloseScreenProcPtr CloseScreen;
+ Bool Enabled;
+ int Flags;
+} DPMSRec, *DPMSPtr;
+#endif
+
+#ifdef XF86VIDMODE
+/* Private info for Video Mode Extentsion */
+typedef struct {
+ DisplayModePtr First;
+ DisplayModePtr Next;
+ int Flags;
+ CloseScreenProcPtr CloseScreen;
+} VidModeRec, *VidModePtr;
+#endif
+
+/* Information for root window properties. */
+typedef struct _RootWinProp {
+ struct _RootWinProp * next;
+ char * name;
+ Atom type;
+ short format;
+ long size;
+ pointer data;
+} RootWinProp, *RootWinPropPtr;
+
+/* private resource types */
+#define ResNoAvoid ResBios
+
+/* ISC's cc can't handle ~ of UL constants, so explicitly type cast them. */
+#define XLED1 ((unsigned long) 0x00000001)
+#define XLED2 ((unsigned long) 0x00000002)
+#define XLED3 ((unsigned long) 0x00000004)
+#define XLED4 ((unsigned long) 0x00000008)
+#define XCAPS ((unsigned long) 0x20000000)
+#define XNUM ((unsigned long) 0x40000000)
+#define XSCR ((unsigned long) 0x80000000)
+#define XCOMP ((unsigned long) 0x00008000)
+
+/* BSD console driver types (consType) */
+#if defined(CSRG_BASED) || defined(__FreeBSD_kernel__)
+#define PCCONS 0
+#define CODRV011 1
+#define CODRV01X 2
+#define SYSCONS 8
+#define PCVT 16
+#define WSCONS 32
+#endif
+
+#endif /* _XF86PRIVSTR_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86RandR.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86RandR.c
new file mode 100644
index 000000000..4fb844a0f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86RandR.c
@@ -0,0 +1,438 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v 1.25 2005/10/30 17:38:49 twini Exp $ */
+/*
+ * $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v 1.7tsi Exp $
+ *
+ * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Keith Packard makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "mibank.h"
+#include "globals.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86DDC.h"
+#include "mipointer.h"
+#include <randrstr.h>
+
+typedef struct _xf86RandRInfo {
+ CreateScreenResourcesProcPtr CreateScreenResources;
+ CloseScreenProcPtr CloseScreen;
+ int virtualX;
+ int virtualY;
+ int mmWidth;
+ int mmHeight;
+ Rotation rotation;
+} XF86RandRInfoRec, *XF86RandRInfoPtr;
+
+static int xf86RandRIndex = -1;
+static int xf86RandRGeneration;
+
+#define XF86RANDRINFO(p) ((XF86RandRInfoPtr) (p)->devPrivates[xf86RandRIndex].ptr)
+
+static int
+xf86RandRModeRefresh (DisplayModePtr mode)
+{
+ if (mode->VRefresh)
+ return (int) (mode->VRefresh + 0.5);
+ else
+ return (int) (mode->Clock * 1000.0 / mode->HTotal / mode->VTotal + 0.5);
+}
+
+static Bool
+xf86RandRGetInfo (ScreenPtr pScreen, Rotation *rotations)
+{
+ RRScreenSizePtr pSize;
+ ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
+ XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
+ DisplayModePtr mode;
+ int refresh0 = 60;
+ xorgRRModeMM RRModeMM;
+
+ *rotations = RR_Rotate_0;
+
+ for (mode = scrp->modes; ; mode = mode->next)
+ {
+ int refresh = xf86RandRModeRefresh (mode);
+
+ if (mode == scrp->modes)
+ refresh0 = refresh;
+
+ RRModeMM.mode = mode;
+ RRModeMM.virtX = randrp->virtualX;
+ RRModeMM.virtY = randrp->virtualY;
+ RRModeMM.mmWidth = randrp->mmWidth;
+ RRModeMM.mmHeight = randrp->mmHeight;
+
+ if(scrp->DriverFunc) {
+ (*scrp->DriverFunc)(scrp, RR_GET_MODE_MM, &RRModeMM);
+ }
+
+ pSize = RRRegisterSize (pScreen,
+ mode->HDisplay, mode->VDisplay,
+ RRModeMM.mmWidth, RRModeMM.mmHeight);
+ if (!pSize)
+ return FALSE;
+ RRRegisterRate (pScreen, pSize, refresh);
+ if (mode == scrp->currentMode &&
+ mode->HDisplay == scrp->virtualX && mode->VDisplay == scrp->virtualY)
+ RRSetCurrentConfig (pScreen, randrp->rotation, refresh, pSize);
+ if (mode->next == scrp->modes)
+ break;
+ }
+ if (scrp->currentMode->HDisplay != randrp->virtualX ||
+ scrp->currentMode->VDisplay != randrp->virtualY)
+ {
+ mode = scrp->modes;
+
+ RRModeMM.mode = NULL;
+ RRModeMM.virtX = randrp->virtualX;
+ RRModeMM.virtY = randrp->virtualY;
+ RRModeMM.mmWidth = randrp->mmWidth;
+ RRModeMM.mmHeight = randrp->mmHeight;
+
+ if(scrp->DriverFunc) {
+ (*scrp->DriverFunc)(scrp, RR_GET_MODE_MM, &RRModeMM);
+ }
+
+ pSize = RRRegisterSize (pScreen,
+ randrp->virtualX, randrp->virtualY,
+ RRModeMM.mmWidth, RRModeMM.mmHeight);
+ if (!pSize)
+ return FALSE;
+ RRRegisterRate (pScreen, pSize, refresh0);
+ if (scrp->virtualX == randrp->virtualX &&
+ scrp->virtualY == randrp->virtualY)
+ {
+ RRSetCurrentConfig (pScreen, randrp->rotation, refresh0, pSize);
+ }
+ }
+
+ /* If there is driver support for randr, let it set our supported rotations */
+ if(scrp->DriverFunc) {
+ xorgRRRotation RRRotation;
+
+ RRRotation.RRRotations = *rotations;
+ if (!(*scrp->DriverFunc)(scrp, RR_GET_INFO, &RRRotation))
+ return TRUE;
+ *rotations = RRRotation.RRRotations;
+ }
+
+ return TRUE;
+}
+
+static Bool
+xf86RandRSetMode (ScreenPtr pScreen,
+ DisplayModePtr mode,
+ Bool useVirtual,
+ int mmWidth,
+ int mmHeight)
+{
+ ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
+ XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
+ int oldWidth = pScreen->width;
+ int oldHeight = pScreen->height;
+ int oldmmWidth = pScreen->mmWidth;
+ int oldmmHeight = pScreen->mmHeight;
+ WindowPtr pRoot = WindowTable[pScreen->myNum];
+ Bool ret = TRUE;
+
+ if (pRoot)
+ (*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE);
+ if (useVirtual)
+ {
+ scrp->virtualX = randrp->virtualX;
+ scrp->virtualY = randrp->virtualY;
+ }
+ else
+ {
+ scrp->virtualX = mode->HDisplay;
+ scrp->virtualY = mode->VDisplay;
+ }
+ if(randrp->rotation & (RR_Rotate_90 | RR_Rotate_270))
+ {
+ /* If the screen is rotated 90 or 270 degrees, swap the sizes. */
+ pScreen->width = scrp->virtualY;
+ pScreen->height = scrp->virtualX;
+ pScreen->mmWidth = mmHeight;
+ pScreen->mmHeight = mmWidth;
+ }
+ else
+ {
+ pScreen->width = scrp->virtualX;
+ pScreen->height = scrp->virtualY;
+ pScreen->mmWidth = mmWidth;
+ pScreen->mmHeight = mmHeight;
+ }
+ if (!xf86SwitchMode (pScreen, mode))
+ {
+ scrp->virtualX = pScreen->width = oldWidth;
+ scrp->virtualY = pScreen->height = oldHeight;
+ pScreen->mmWidth = oldmmWidth;
+ pScreen->mmHeight = oldmmHeight;
+ ret = FALSE;
+ }
+ /*
+ * Make sure the layout is correct
+ */
+ xf86ReconfigureLayout();
+
+ /*
+ * Make sure the whole screen is visible
+ */
+ xf86SetViewport (pScreen, pScreen->width, pScreen->height);
+ xf86SetViewport (pScreen, 0, 0);
+ if (pRoot)
+ (*scrp->EnableDisableFBAccess) (pScreen->myNum, TRUE);
+ return ret;
+}
+
+static Bool
+xf86RandRSetConfig (ScreenPtr pScreen,
+ Rotation rotation,
+ int rate,
+ RRScreenSizePtr pSize)
+{
+ ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
+ XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
+ DisplayModePtr mode;
+ int px, py;
+ Bool useVirtual = FALSE;
+ Rotation oldRotation = randrp->rotation;
+
+ miPointerPosition (&px, &py);
+ for (mode = scrp->modes; ; mode = mode->next)
+ {
+ if (mode->HDisplay == pSize->width &&
+ mode->VDisplay == pSize->height &&
+ (rate == 0 || xf86RandRModeRefresh (mode) == rate))
+ break;
+ if (mode->next == scrp->modes)
+ {
+ if (pSize->width == randrp->virtualX &&
+ pSize->height == randrp->virtualY)
+ {
+ mode = scrp->modes;
+ useVirtual = TRUE;
+ break;
+ }
+ return FALSE;
+ }
+ }
+
+ if (randrp->rotation != rotation) {
+
+ /* Have the driver do its thing. */
+ if (scrp->DriverFunc) {
+ xorgRRRotation RRRotation;
+ RRRotation.RRConfig.rotation = rotation;
+ RRRotation.RRConfig.rate = rate;
+ RRRotation.RRConfig.width = pSize->width;
+ RRRotation.RRConfig.height = pSize->height;
+
+ /*
+ * Currently we need to rely on HW support for rotation.
+ */
+ if (!(*scrp->DriverFunc)(scrp, RR_SET_CONFIG, &RRRotation))
+ return FALSE;
+ } else
+ return FALSE;
+
+ randrp->rotation = rotation;
+ }
+
+ if (!xf86RandRSetMode (pScreen, mode, useVirtual, pSize->mmWidth, pSize->mmHeight)) {
+ if(randrp->rotation != oldRotation) {
+ /* Have the driver undo its thing. */
+ if (scrp->DriverFunc) {
+ xorgRRRotation RRRotation;
+ RRRotation.RRConfig.rotation = oldRotation;
+ RRRotation.RRConfig.rate = xf86RandRModeRefresh (scrp->currentMode);
+ RRRotation.RRConfig.width = pScreen->width;
+ RRRotation.RRConfig.height = pScreen->height;
+ (*scrp->DriverFunc)(scrp, RR_SET_CONFIG, &RRRotation);
+ }
+
+ randrp->rotation = oldRotation;
+ }
+ return FALSE;
+ }
+ /*
+ * Move the cursor back where it belongs; SwitchMode repositions it
+ */
+ if (pScreen == miPointerCurrentScreen ())
+ {
+ px = (px >= pScreen->width ? (pScreen->width - 1) : px);
+ py = (py >= pScreen->height ? (pScreen->height - 1) : py);
+
+ xf86SetViewport(pScreen, px, py);
+
+ (*pScreen->SetCursorPosition) (pScreen, px, py, FALSE);
+ }
+
+ return TRUE;
+}
+
+/*
+ * Wait until the screen is initialized before whacking the
+ * sizes around; otherwise the screen pixmap will be allocated
+ * at the current mode size rather than the maximum size
+ */
+static Bool
+xf86RandRCreateScreenResources (ScreenPtr pScreen)
+{
+ XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
+#if 0
+ ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
+ DisplayModePtr mode;
+#endif
+
+ pScreen->CreateScreenResources = randrp->CreateScreenResources;
+ if (!(*pScreen->CreateScreenResources) (pScreen))
+ return FALSE;
+
+#if 0
+ mode = scrp->currentMode;
+ if (mode)
+ xf86RandRSetMode (pScreen, mode, TRUE);
+#endif
+
+ return TRUE;
+}
+
+/*
+ * Reset size back to original
+ */
+static Bool
+xf86RandRCloseScreen (int index, ScreenPtr pScreen)
+{
+ ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
+ XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
+
+ scrp->virtualX = pScreen->width = randrp->virtualX;
+ scrp->virtualY = pScreen->height = randrp->virtualY;
+ scrp->currentMode = scrp->modes;
+ pScreen->CloseScreen = randrp->CloseScreen;
+ xfree (randrp);
+ pScreen->devPrivates[xf86RandRIndex].ptr = 0;
+ return (*pScreen->CloseScreen) (index, pScreen);
+}
+
+Rotation
+xf86GetRotation(ScreenPtr pScreen)
+{
+ if (xf86RandRIndex == -1)
+ return RR_Rotate_0;
+
+ return XF86RANDRINFO(pScreen)->rotation;
+}
+
+/* Function to change RandR's idea of the virtual screen size */
+Bool
+xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen,
+ int newvirtX, int newvirtY, int newmmWidth, int newmmHeight,
+ Bool resetMode)
+{
+ XF86RandRInfoPtr randrp;
+
+ if (xf86RandRIndex == -1)
+ return FALSE;
+
+ randrp = XF86RANDRINFO(pScreen);
+ if (randrp == NULL)
+ return FALSE;
+
+ if (newvirtX > 0)
+ randrp->virtualX = newvirtX;
+
+ if (newvirtY > 0)
+ randrp->virtualY = newvirtY;
+
+ if (newmmWidth > 0)
+ randrp->mmWidth = newmmWidth;
+
+ if (newmmHeight > 0)
+ randrp->mmHeight = newmmHeight;
+
+ /* This is only for during server start */
+ if (resetMode) {
+ return (xf86RandRSetMode(pScreen,
+ XF86SCRNINFO(pScreen)->currentMode,
+ TRUE,
+ pScreen->mmWidth, pScreen->mmHeight));
+ }
+
+ return TRUE;
+}
+
+Bool
+xf86RandRInit (ScreenPtr pScreen)
+{
+ rrScrPrivPtr rp;
+ XF86RandRInfoPtr randrp;
+ ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
+
+#ifdef PANORAMIX
+ /* XXX disable RandR when using Xinerama */
+ if (!noPanoramiXExtension)
+ return TRUE;
+#endif
+ if (xf86RandRGeneration != serverGeneration)
+ {
+ xf86RandRIndex = AllocateScreenPrivateIndex();
+ xf86RandRGeneration = serverGeneration;
+ }
+
+ randrp = xalloc (sizeof (XF86RandRInfoRec));
+ if (!randrp)
+ return FALSE;
+
+ if (!RRScreenInit (pScreen))
+ {
+ xfree (randrp);
+ return FALSE;
+ }
+ rp = rrGetScrPriv(pScreen);
+ rp->rrGetInfo = xf86RandRGetInfo;
+ rp->rrSetConfig = xf86RandRSetConfig;
+
+ randrp->virtualX = scrp->virtualX;
+ randrp->virtualY = scrp->virtualY;
+ randrp->mmWidth = pScreen->mmWidth;
+ randrp->mmHeight = pScreen->mmHeight;
+
+ randrp->CreateScreenResources = pScreen->CreateScreenResources;
+ pScreen->CreateScreenResources = xf86RandRCreateScreenResources;
+
+ randrp->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = xf86RandRCloseScreen;
+
+ randrp->rotation = RR_Rotate_0;
+
+ pScreen->devPrivates[xf86RandRIndex].ptr = randrp;
+ return TRUE;
+}
+
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Resources.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Resources.h
new file mode 100644
index 000000000..ce2c62bb3
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Resources.h
@@ -0,0 +1,140 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Resources.h,v 1.15 2003/08/24 17:36:55 dawes Exp $ */
+
+/*
+ * Copyright (c) 1999-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).
+ */
+
+#ifndef _XF86_RESOURCES_H
+
+#define _XF86_RESOURCES_H
+
+#include "xf86str.h"
+
+#define _END {ResEnd,0,0}
+
+#define _VGA_EXCLUSIVE \
+ {ResExcMemBlock | ResBios | ResBus, 0x000A0000, 0x000AFFFF},\
+ {ResExcMemBlock | ResBios | ResBus, 0x000B0000, 0x000B7FFF},\
+ {ResExcMemBlock | ResBios | ResBus, 0x000B8000, 0x000BFFFF},\
+ {ResExcIoBlock | ResBios | ResBus, 0x03B0, 0x03BB},\
+ {ResExcIoBlock | ResBios | ResBus, 0x03C0, 0x03DF}
+
+#define _VGA_SHARED \
+ {ResShrMemBlock | ResBios | ResBus, 0x000A0000, 0x000AFFFF},\
+ {ResShrMemBlock | ResBios | ResBus, 0x000B0000, 0x000B7FFF},\
+ {ResShrMemBlock | ResBios | ResBus, 0x000B8000, 0x000BFFFF},\
+ {ResShrIoBlock | ResBios | ResBus, 0x03B0, 0x03BB},\
+ {ResShrIoBlock | ResBios | ResBus, 0x03C0, 0x03DF}
+
+#define _VGA_SHARED_MEM \
+ {ResShrMemBlock | ResBios | ResBus, 0x000A0000, 0x000AFFFF},\
+ {ResShrMemBlock | ResBios | ResBus, 0x000B0000, 0x000B7FFF},\
+ {ResShrMemBlock | ResBios | ResBus, 0x000B8000, 0x000BFFFF}
+
+#define _VGA_SHARED_IO \
+ {ResShrIoBlock | ResBios | ResBus, 0x03B0, 0x03BB},\
+ {ResShrIoBlock | ResBios | ResBus, 0x03C0, 0x03DF}
+
+/*
+ * Exclusive unused VGA: resources unneeded but cannot be disabled.
+ * Like old Millennium.
+ */
+#define _VGA_EXCLUSIVE_UNUSED \
+ {ResExcUusdMemBlock | ResBios | ResBus, 0x000A0000, 0x000AFFFF},\
+ {ResExcUusdMemBlock | ResBios | ResBus, 0x000B0000, 0x000B7FFF},\
+ {ResExcUusdMemBlock | ResBios | ResBus, 0x000B8000, 0x000BFFFF},\
+ {ResExcUusdIoBlock | ResBios | ResBus, 0x03B0, 0x03BB},\
+ {ResExcUusdIoBlock | ResBios | ResBus, 0x03C0, 0x03DF}
+
+/*
+ * Shared unused VGA: resources unneeded but cannot be disabled
+ * independently. This is used to determine if a device needs RAC.
+ */
+#define _VGA_SHARED_UNUSED \
+ {ResShrUusdMemBlock | ResBios | ResBus, 0x000A0000, 0x000AFFFF},\
+ {ResShrUusdMemBlock | ResBios | ResBus, 0x000B0000, 0x000B7FFF},\
+ {ResShrUusdMemBlock | ResBios | ResBus, 0x000B8000, 0x000BFFFF},\
+ {ResShrUusdIoBlock | ResBios | ResBus, 0x03B0, 0x03BB},\
+ {ResShrUusdIoBlock | ResBios | ResBus, 0x03C0, 0x03DF}
+
+/*
+ * Sparse versions of the above for those adapters that respond to all ISA
+ * aliases of VGA ports.
+ */
+#define _VGA_EXCLUSIVE_SPARSE \
+ {ResExcMemBlock | ResBios | ResBus, 0x000A0000, 0x000AFFFF},\
+ {ResExcMemBlock | ResBios | ResBus, 0x000B0000, 0x000B7FFF},\
+ {ResExcMemBlock | ResBios | ResBus, 0x000B8000, 0x000BFFFF},\
+ {ResExcIoSparse | ResBios | ResBus, 0x03B0, 0x03F8},\
+ {ResExcIoSparse | ResBios | ResBus, 0x03B8, 0x03FC},\
+ {ResExcIoSparse | ResBios | ResBus, 0x03C0, 0x03E0}
+
+#define _VGA_SHARED_SPARSE \
+ {ResShrMemBlock | ResBios | ResBus, 0x000A0000, 0x000AFFFF},\
+ {ResShrMemBlock | ResBios | ResBus, 0x000B0000, 0x000B7FFF},\
+ {ResShrMemBlock | ResBios | ResBus, 0x000B8000, 0x000BFFFF},\
+ {ResShrIoSparse | ResBios | ResBus, 0x03B0, 0x03F8},\
+ {ResShrIoSparse | ResBios | ResBus, 0x03B8, 0x03FC},\
+ {ResShrIoSparse | ResBios | ResBus, 0x03C0, 0x03E0}
+
+#define _8514_EXCLUSIVE \
+ {ResExcIoSparse | ResBios | ResBus, 0x02E8, 0x03F8}
+
+#define _8514_SHARED \
+ {ResShrIoSparse | ResBios | ResBus, 0x02E8, 0x03F8}
+
+/* Predefined resources */
+extern resRange resVgaExclusive[];
+extern resRange resVgaShared[];
+extern resRange resVgaIoShared[];
+extern resRange resVgaMemShared[];
+extern resRange resVgaUnusedExclusive[];
+extern resRange resVgaUnusedShared[];
+extern resRange resVgaSparseExclusive[];
+extern resRange resVgaSparseShared[];
+extern resRange res8514Exclusive[];
+extern resRange res8514Shared[];
+
+/* Less misleading aliases for xf86SetOperatingState() */
+#define resVgaMem resVgaMemShared
+#define resVgaIo resVgaIoShared
+#define resVga resVgaShared
+
+/* Old style names */
+#define RES_EXCLUSIVE_VGA resVgaExclusive
+#define RES_SHARED_VGA resVgaShared
+#define RES_EXCLUSIVE_8514 res8514Exclusive
+#define RES_SHARED_8514 res8514Shared
+
+#define _PCI_AVOID_PC_STYLE \
+ {ResExcIoSparse | ResBus, 0x0100, 0x0300},\
+ {ResExcIoSparse | ResBus, 0x0200, 0x0200},\
+ {ResExcMemBlock | ResBus, 0xA0000,0xFFFFF}
+
+extern resRange PciAvoid[];
+
+#define RES_UNDEFINED NULL
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Versions.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Versions.c
new file mode 100644
index 000000000..6de7d53c2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Versions.c
@@ -0,0 +1,81 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Versions.c,v 1.2 2003/08/24 20:01:19 dawes Exp $ */
+/*
+ * Copyright (c) 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
+
+#include "xf86.h"
+#include "xf86OSmouse.h"
+#include "xf86OSKbd.h"
+
+static CARD32 registeredVersions[NUM_BUILTIN_IFS];
+
+CARD32
+xf86GetBuiltinInterfaceVersion(BuiltinInterface iface, int flags)
+{
+ if (iface < 0 || iface >= NUM_BUILTIN_IFS) {
+ xf86Msg(X_ERROR, "xf86GetBuiltinInterfaceVersion: Unexpected interface"
+ "query: %d\n", iface);
+ return 0;
+ }
+
+ if (registeredVersions[iface])
+ return registeredVersions[iface];
+
+ /* Most built-in interfaces are handled this way. */
+ switch (iface) {
+ case BUILTIN_IF_OSMOUSE:
+ return OS_MOUSE_VERSION_CURRENT;
+ case BUILTIN_IF_OSKBD:
+ return OS_KBD_VERSION_CURRENT;
+ default:
+ xf86Msg(X_ERROR, "xf86GetBuiltinInterfaceVersion: internal error: "
+ "interface %d not handled\n", iface);
+ return 0;
+ }
+}
+
+Bool
+xf86RegisterBuiltinInterfaceVersion(BuiltinInterface iface, CARD32 version,
+ int flags)
+{
+ if (iface < 0 || iface >= NUM_BUILTIN_IFS) {
+ xf86Msg(X_ERROR, "xf86RegisterBuiltinInterfaceVersion: "
+ "unexpected interface number: %d\n", iface);
+ return FALSE;
+ }
+ if (version == 0) {
+ xf86Msg(X_ERROR, "xf86RegisterBuiltinInterfaceVersion: "
+ "versions must be greater than zero\n");
+ return FALSE;
+ }
+ registeredVersions[iface] = version;
+ return TRUE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86VidMode.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86VidMode.c
new file mode 100644
index 000000000..81e4b969e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86VidMode.c
@@ -0,0 +1,722 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86VidMode.c,v 1.17 2003/08/24 17:36:55 dawes Exp $ */
+/*
+ * Copyright (c) 1999-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 VidMode functions required by the extension.
+ * These have been added to avoid the need for the higher level extension
+ * code to access the private XFree86 data structures directly. Wherever
+ * possible this code uses the functions in xf86Mode.c to do the work,
+ * so that two version of code that do similar things don't have to be
+ * maintained.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+
+#ifdef XF86VIDMODE
+#include "vidmodeproc.h"
+#include "xf86cmap.h"
+
+static int VidModeGeneration = 0;
+static int VidModeIndex = -1;
+static int VidModeCount = 0;
+static Bool VidModeClose(int i, ScreenPtr pScreen);
+
+#define VMPTR(p) ((VidModePtr)(p)->devPrivates[VidModeIndex].ptr)
+
+#endif
+
+#ifdef DEBUG
+# define DEBUG_P(x) ErrorF(x"\n");
+#else
+# define DEBUG_P(x) /**/
+#endif
+
+Bool
+VidModeExtensionInit(ScreenPtr pScreen)
+{
+#ifdef XF86VIDMODE
+ VidModePtr pVidMode;
+
+ DEBUG_P("VidModeExtensionInit");
+
+ if (!xf86GetVidModeEnabled()) {
+ DEBUG_P("!xf86GetVidModeEnabled()");
+ return FALSE;
+ }
+
+ if (serverGeneration != VidModeGeneration) {
+ if ((VidModeIndex = AllocateScreenPrivateIndex()) < 0) {
+ DEBUG_P("AllocateScreenPrivateIndex() failed");
+ return FALSE;
+ }
+ VidModeGeneration = serverGeneration;
+ }
+
+ if (!(pScreen->devPrivates[VidModeIndex].ptr = xcalloc(sizeof(VidModeRec), 1))) {
+ DEBUG_P("xcalloc failed");
+ return FALSE;
+ }
+
+ pVidMode = VMPTR(pScreen);
+ pVidMode->Flags = 0;
+ pVidMode->Next = NULL;
+ pVidMode->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = VidModeClose;
+ VidModeCount++;
+ return TRUE;
+#else
+ DEBUG_P("no vidmode extension");
+ return FALSE;
+#endif
+}
+
+
+#ifdef XF86VIDMODE
+
+static Bool
+VidModeClose(int i, ScreenPtr pScreen)
+{
+ VidModePtr pVidMode = VMPTR(pScreen);
+
+ DEBUG_P("VidModeClose");
+
+ /* This shouldn't happen */
+ if (!pVidMode)
+ return FALSE;
+
+ pScreen->CloseScreen = pVidMode->CloseScreen;
+
+ if (--VidModeCount == 0) {
+ if (pScreen->devPrivates[VidModeIndex].ptr)
+ xfree(pScreen->devPrivates[VidModeIndex].ptr);
+ pScreen->devPrivates[VidModeIndex].ptr = NULL;
+ VidModeIndex = -1;
+ }
+ return pScreen->CloseScreen(i, pScreen);
+}
+
+Bool
+VidModeAvailable(int scrnIndex)
+{
+ ScrnInfoPtr pScrn;
+ VidModePtr pVidMode;
+
+ DEBUG_P("VidModeAvailable");
+
+ if (VidModeIndex < 0) {
+ DEBUG_P("VidModeIndex < 0");
+ return FALSE;
+ }
+
+ pScrn = xf86Screens[scrnIndex];
+ if (pScrn == NULL) {
+ DEBUG_P("pScrn == NULL");
+ return FALSE;
+ }
+
+ pVidMode = VMPTR(pScrn->pScreen);
+ if (pVidMode)
+ return TRUE;
+ else {
+ DEBUG_P("pVidMode == NULL");
+ return FALSE;
+ }
+}
+
+Bool
+VidModeGetCurrentModeline(int scrnIndex, pointer *mode, int *dotClock)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeGetCurrentModeline");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ *mode = (pointer)(pScrn->currentMode);
+ *dotClock = pScrn->currentMode->Clock;
+
+ return TRUE;
+}
+
+int
+VidModeGetDotClock(int scrnIndex, int Clock)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeGetDotClock");
+
+ if (!VidModeAvailable(scrnIndex))
+ return 0;
+
+ pScrn = xf86Screens[scrnIndex];
+ if ((pScrn->progClock) || (Clock > MAXCLOCKS))
+ return Clock;
+ else
+ return pScrn->clock[Clock];
+}
+
+int
+VidModeGetNumOfClocks(int scrnIndex, Bool *progClock)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeGetNumOfClocks");
+
+ if (!VidModeAvailable(scrnIndex))
+ return 0;
+
+ pScrn = xf86Screens[scrnIndex];
+ if (pScrn->progClock){
+ *progClock = TRUE;
+ return 0;
+ } else {
+ *progClock = FALSE;
+ return pScrn->numClocks;
+ }
+}
+
+Bool
+VidModeGetClocks(int scrnIndex, int *Clocks)
+{
+ ScrnInfoPtr pScrn;
+ int i;
+
+ DEBUG_P("VidModeGetClocks");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+
+ if (pScrn->progClock)
+ return FALSE;
+
+ for (i = 0; i < pScrn->numClocks; i++)
+ *Clocks++ = pScrn->clock[i];
+
+ return TRUE;
+}
+
+
+Bool
+VidModeGetFirstModeline(int scrnIndex, pointer *mode, int *dotClock)
+{
+ ScrnInfoPtr pScrn;
+ VidModePtr pVidMode;
+
+ DEBUG_P("VidModeGetFirstModeline");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ pVidMode = VMPTR(pScrn->pScreen);
+ pVidMode->First = pScrn->modes;
+ pVidMode->Next = pVidMode->First->next;
+
+ if (pVidMode->First->status == MODE_OK) {
+ *mode = (pointer)(pVidMode->First);
+ *dotClock = VidModeGetDotClock(scrnIndex, pVidMode->First->Clock);
+ return TRUE;
+ }
+
+ return VidModeGetNextModeline(scrnIndex, mode, dotClock);
+}
+
+Bool
+VidModeGetNextModeline(int scrnIndex, pointer *mode, int *dotClock)
+{
+ ScrnInfoPtr pScrn;
+ VidModePtr pVidMode;
+ DisplayModePtr p;
+
+ DEBUG_P("VidModeGetNextModeline");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ pVidMode = VMPTR(pScrn->pScreen);
+
+ for (p = pVidMode->Next; p != NULL && p != pVidMode->First; p = p->next) {
+ if (p->status == MODE_OK) {
+ pVidMode->Next = p->next;
+ *mode = (pointer)p;
+ *dotClock = VidModeGetDotClock(scrnIndex, p->Clock);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+Bool
+VidModeDeleteModeline(int scrnIndex, pointer mode)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeDeleteModeline");
+
+ if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ xf86DeleteMode(&(pScrn->modes), (DisplayModePtr)mode);
+ return TRUE;
+}
+
+Bool
+VidModeZoomViewport(int scrnIndex, int zoom)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeZoomViewPort");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ xf86ZoomViewport(pScrn->pScreen, zoom);
+ return TRUE;
+}
+
+Bool
+VidModeSetViewPort(int scrnIndex, int x, int y)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeSetViewPort");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ pScrn->frameX0 = min( max(x, 0),
+ pScrn->virtualX - pScrn->currentMode->HDisplay );
+ pScrn->frameX1 = pScrn->frameX0 + pScrn->currentMode->HDisplay - 1;
+ pScrn->frameY0 = min( max(y, 0),
+ pScrn->virtualY - pScrn->currentMode->VDisplay );
+ pScrn->frameY1 = pScrn->frameY0 + pScrn->currentMode->VDisplay - 1;
+ if (pScrn->AdjustFrame != NULL)
+ (pScrn->AdjustFrame)(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+
+ return TRUE;
+}
+
+Bool
+VidModeGetViewPort(int scrnIndex, int *x, int *y)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeGetViewPort");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ *x = pScrn->frameX0;
+ *y = pScrn->frameY0;
+ return TRUE;
+}
+
+Bool
+VidModeSwitchMode(int scrnIndex, pointer mode)
+{
+ ScrnInfoPtr pScrn;
+ DisplayModePtr pTmpMode;
+ Bool retval;
+
+ DEBUG_P("VidModeSwitchMode");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ /* save in case we fail */
+ pTmpMode = pScrn->currentMode;
+ /* Force a mode switch */
+ pScrn->currentMode = NULL;
+ retval = xf86SwitchMode(pScrn->pScreen, mode);
+ /* we failed: restore it */
+ if (retval == FALSE)
+ pScrn->currentMode = pTmpMode;
+ return retval;
+}
+
+Bool
+VidModeLockZoom(int scrnIndex, Bool lock)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeLockZoom");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+
+ if (xf86Info.dontZoom)
+ return FALSE;
+
+ xf86LockZoom(pScrn->pScreen, lock);
+ return TRUE;
+}
+
+Bool
+VidModeGetMonitor(int scrnIndex, pointer *monitor)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeGetMonitor");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ *monitor = (pointer)(pScrn->monitor);
+
+ return TRUE;
+}
+
+ModeStatus
+VidModeCheckModeForMonitor(int scrnIndex, pointer mode)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeCheckModeForMonitor");
+
+ if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
+ return MODE_ERROR;
+
+ pScrn = xf86Screens[scrnIndex];
+
+ return xf86CheckModeForMonitor((DisplayModePtr)mode, pScrn->monitor);
+}
+
+ModeStatus
+VidModeCheckModeForDriver(int scrnIndex, pointer mode)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeCheckModeForDriver");
+
+ if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
+ return MODE_ERROR;
+
+ pScrn = xf86Screens[scrnIndex];
+
+ return xf86CheckModeForDriver(pScrn, (DisplayModePtr)mode, 0);
+}
+
+void
+VidModeSetCrtcForMode(int scrnIndex, pointer mode)
+{
+ ScrnInfoPtr pScrn;
+ DisplayModePtr ScreenModes;
+
+ DEBUG_P("VidModeSetCrtcForMode");
+
+ if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
+ return;
+
+ /* Ugly hack so that the xf86Mode.c function can be used without change */
+ pScrn = xf86Screens[scrnIndex];
+ ScreenModes = pScrn->modes;
+ pScrn->modes = (DisplayModePtr)mode;
+
+ xf86SetCrtcForModes(pScrn, pScrn->adjustFlags);
+ pScrn->modes = ScreenModes;
+ return;
+}
+
+Bool
+VidModeAddModeline(int scrnIndex, pointer mode)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeAddModeline");
+
+ if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+
+ ((DisplayModePtr)mode)->name = strdup(""); /* freed by deletemode */
+ ((DisplayModePtr)mode)->status = MODE_OK;
+ ((DisplayModePtr)mode)->next = pScrn->modes->next;
+ ((DisplayModePtr)mode)->prev = pScrn->modes;
+ pScrn->modes->next = (DisplayModePtr)mode;
+ if( ((DisplayModePtr)mode)->next != NULL )
+ ((DisplayModePtr)mode)->next->prev = (DisplayModePtr)mode;
+
+ return TRUE;
+}
+
+int
+VidModeGetNumOfModes(int scrnIndex)
+{
+ pointer mode = NULL;
+ int dotClock= 0, nummodes = 0;
+
+ DEBUG_P("VidModeGetNumOfModes");
+
+ if (!VidModeGetFirstModeline(scrnIndex, &mode, &dotClock))
+ return nummodes;
+
+ do {
+ nummodes++;
+ if (!VidModeGetNextModeline(scrnIndex, &mode, &dotClock))
+ return nummodes;
+ } while (TRUE);
+}
+
+Bool
+VidModeSetGamma(int scrnIndex, float red, float green, float blue)
+{
+ ScrnInfoPtr pScrn;
+ Gamma gamma;
+
+ DEBUG_P("VidModeSetGamma");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ gamma.red = red;
+ gamma.green = green;
+ gamma.blue = blue;
+ if (xf86ChangeGamma(pScrn->pScreen, gamma) != Success)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+Bool
+VidModeGetGamma(int scrnIndex, float *red, float *green, float *blue)
+{
+ ScrnInfoPtr pScrn;
+
+ DEBUG_P("VidModeGetGamma");
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ *red = pScrn->gamma.red;
+ *green = pScrn->gamma.green;
+ *blue = pScrn->gamma.blue;
+ return TRUE;
+}
+
+Bool
+VidModeSetGammaRamp(int scrnIndex, int size, CARD16 *r, CARD16 *g, CARD16 *b)
+{
+ ScrnInfoPtr pScrn;
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ xf86ChangeGammaRamp(pScrn->pScreen, size, r, g, b);
+ return TRUE;
+}
+
+Bool
+VidModeGetGammaRamp(int scrnIndex, int size, CARD16 *r, CARD16 *g, CARD16 *b)
+{
+ ScrnInfoPtr pScrn;
+
+ if (!VidModeAvailable(scrnIndex))
+ return FALSE;
+
+ pScrn = xf86Screens[scrnIndex];
+ xf86GetGammaRamp(pScrn->pScreen, size, r, g, b);
+ return TRUE;
+}
+
+int
+VidModeGetGammaRampSize(int scrnIndex)
+{
+ if (!VidModeAvailable(scrnIndex))
+ return 0;
+
+ return xf86GetGammaRampSize(xf86Screens[scrnIndex]->pScreen);
+}
+
+pointer
+VidModeCreateMode(void)
+{
+ DisplayModePtr mode;
+
+ mode = xalloc(sizeof(DisplayModeRec));
+ if (mode != NULL) {
+ mode->name = "";
+ mode->VScan = 1; /* divides refresh rate. default = 1 */
+ mode->Private = NULL;
+ mode->next = mode;
+ mode->prev = mode;
+ }
+ return mode;
+}
+
+void
+VidModeCopyMode(pointer modefrom, pointer modeto)
+{
+ memcpy(modeto, modefrom, sizeof(DisplayModeRec));
+}
+
+
+int
+VidModeGetModeValue(pointer mode, int valtyp)
+{
+ int ret = 0;
+
+ switch (valtyp) {
+ case VIDMODE_H_DISPLAY:
+ ret = ((DisplayModePtr) mode)->HDisplay;
+ break;
+ case VIDMODE_H_SYNCSTART:
+ ret = ((DisplayModePtr)mode)->HSyncStart;
+ break;
+ case VIDMODE_H_SYNCEND:
+ ret = ((DisplayModePtr)mode)->HSyncEnd;
+ break;
+ case VIDMODE_H_TOTAL:
+ ret = ((DisplayModePtr)mode)->HTotal;
+ break;
+ case VIDMODE_H_SKEW:
+ ret = ((DisplayModePtr)mode)->HSkew;
+ break;
+ case VIDMODE_V_DISPLAY:
+ ret = ((DisplayModePtr)mode)->VDisplay;
+ break;
+ case VIDMODE_V_SYNCSTART:
+ ret = ((DisplayModePtr)mode)->VSyncStart;
+ break;
+ case VIDMODE_V_SYNCEND:
+ ret = ((DisplayModePtr)mode)->VSyncEnd;
+ break;
+ case VIDMODE_V_TOTAL:
+ ret = ((DisplayModePtr)mode)->VTotal;
+ break;
+ case VIDMODE_FLAGS:
+ ret = ((DisplayModePtr)mode)->Flags;
+ break;
+ case VIDMODE_CLOCK:
+ ret = ((DisplayModePtr)mode)->Clock;
+ break;
+ }
+ return ret;
+}
+
+void
+VidModeSetModeValue(pointer mode, int valtyp, int val)
+{
+ switch (valtyp) {
+ case VIDMODE_H_DISPLAY:
+ ((DisplayModePtr)mode)->HDisplay = val;
+ break;
+ case VIDMODE_H_SYNCSTART:
+ ((DisplayModePtr)mode)->HSyncStart = val;
+ break;
+ case VIDMODE_H_SYNCEND:
+ ((DisplayModePtr)mode)->HSyncEnd = val;
+ break;
+ case VIDMODE_H_TOTAL:
+ ((DisplayModePtr)mode)->HTotal = val;
+ break;
+ case VIDMODE_H_SKEW:
+ ((DisplayModePtr)mode)->HSkew = val;
+ break;
+ case VIDMODE_V_DISPLAY:
+ ((DisplayModePtr)mode)->VDisplay = val;
+ break;
+ case VIDMODE_V_SYNCSTART:
+ ((DisplayModePtr)mode)->VSyncStart = val;
+ break;
+ case VIDMODE_V_SYNCEND:
+ ((DisplayModePtr)mode)->VSyncEnd = val;
+ break;
+ case VIDMODE_V_TOTAL:
+ ((DisplayModePtr)mode)->VTotal = val;
+ break;
+ case VIDMODE_FLAGS:
+ ((DisplayModePtr)mode)->Flags = val;
+ break;
+ case VIDMODE_CLOCK:
+ ((DisplayModePtr)mode)->Clock = val;
+ break;
+ }
+ return;
+}
+
+vidMonitorValue
+VidModeGetMonitorValue(pointer monitor, int valtyp, int indx)
+{
+ vidMonitorValue ret;
+
+ switch (valtyp) {
+ case VIDMODE_MON_VENDOR:
+ ret.ptr = (((MonPtr)monitor)->vendor);
+ break;
+ case VIDMODE_MON_MODEL:
+ ret.ptr = (((MonPtr)monitor)->model);
+ break;
+ case VIDMODE_MON_NHSYNC:
+ ret.i = ((MonPtr)monitor)->nHsync;
+ break;
+ case VIDMODE_MON_NVREFRESH:
+ ret.i = ((MonPtr)monitor)->nVrefresh;
+ break;
+ case VIDMODE_MON_HSYNC_LO:
+ ret.f = (100.0 * ((MonPtr)monitor)->hsync[indx].lo);
+ break;
+ case VIDMODE_MON_HSYNC_HI:
+ ret.f = (100.0 * ((MonPtr)monitor)->hsync[indx].hi);
+ break;
+ case VIDMODE_MON_VREFRESH_LO:
+ ret.f = (100.0 * ((MonPtr)monitor)->vrefresh[indx].lo);
+ break;
+ case VIDMODE_MON_VREFRESH_HI:
+ ret.f = (100.0 * ((MonPtr)monitor)->vrefresh[indx].hi);
+ break;
+ }
+ return ret;
+}
+
+
+#endif /* XF86VIDMODE */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86XKB.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86XKB.c
new file mode 100644
index 000000000..68be17c3a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86XKB.c
@@ -0,0 +1,82 @@
+/* $XConsortium: xf86XKB.c /main/4 1996/02/04 09:28:04 kaleb $ */
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+/*
+ * Copyright (c) 1994-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).
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86XKB.c,v 3.12 2003/08/24 17:36:55 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#define NEED_EVENTS 1
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/keysym.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include <X11/extensions/XI.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSlib.h"
+
+#include <X11/extensions/XKBsrv.h>
+
+void
+xf86InitXkb(void)
+{
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Xinput.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Xinput.c
new file mode 100644
index 000000000..cc9e76361
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Xinput.c
@@ -0,0 +1,1513 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Xinput.c,v 3.70 2003/11/03 05:11:02 tsi Exp $ */
+/*
+ * Copyright 1995-1999 by Frederic Lepied, France. <Lepied@XFree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Frederic Lepied not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Frederic Lepied makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
+ * Copyright (c) 2000-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).
+ */
+/* $XConsortium: xf86Xinput.c /main/14 1996/10/27 11:05:25 kaleb $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86Xinput.c,v 1.7 2005/10/21 19:06:13 ajax Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/Xfuncproto.h>
+#include <X11/Xmd.h>
+#ifdef XINPUT
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#endif
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Xinput.h"
+#ifdef XINPUT
+#include "XIstubs.h"
+#endif
+#include "mipointer.h"
+#include "xf86InPriv.h"
+
+#ifdef DPMSExtension
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+#include "dpmsproc.h"
+#endif
+
+#ifdef XFreeXDGA
+#include "dgaproc.h"
+#endif
+
+#include "exevents.h" /* AddInputDevice */
+#include "exglobals.h"
+
+#define EXTENSION_PROC_ARGS void *
+#include "extnsionst.h"
+#include "extinit.h" /* LookupDeviceIntRec */
+
+#include "windowstr.h" /* screenIsSaved */
+
+#include <stdarg.h>
+
+#include "osdep.h" /* EnabledDevices */
+#include <X11/Xpoll.h>
+#include "xf86_OSproc.h" /* sigio stuff */
+
+/******************************************************************************
+ * debugging macro
+ *****************************************************************************/
+#ifdef DBG
+#undef DBG
+#endif
+#ifdef DEBUG
+#undef DEBUG
+#endif
+
+#define DEBUG 0
+
+#if DEBUG
+static int debug_level = 0;
+
+#define DBG(lvl, f) {if ((lvl) <= debug_level) f;}
+#else
+#define DBG(lvl, f)
+#endif
+
+/******************************************************************************
+ * macros
+ *****************************************************************************/
+#define ENQUEUE(e) xf86eqEnqueue((e))
+
+/***********************************************************************
+ *
+ * xf86AlwaysCoreControl --
+ *
+ * Control proc for the integer feedback that controls the always
+ * core feature.
+ *
+ ***********************************************************************
+ */
+static void
+xf86AlwaysCoreControl(DeviceIntPtr device,
+ IntegerCtrl *control)
+{
+}
+
+/***********************************************************************
+ *
+ * Core devices functions --
+ *
+ * Test if device is the core device by checking the
+ * value of always core feedback and the inputInfo struct.
+ *
+ ***********************************************************************
+ */
+int
+xf86IsCorePointer(DeviceIntPtr device)
+{
+ return(device == inputInfo.pointer);
+}
+
+static int
+xf86ShareCorePointer(DeviceIntPtr device)
+{
+ LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate;
+
+ return((local->always_core_feedback &&
+ local->always_core_feedback->ctrl.integer_displayed));
+}
+
+static Bool
+xf86SendDragEvents(DeviceIntPtr device)
+{
+ LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate;
+
+ if (inputInfo.pointer->button->buttonsDown > 0)
+ return (local->flags & XI86_SEND_DRAG_EVENTS);
+ else
+ return (TRUE);
+}
+
+int
+xf86IsCoreKeyboard(DeviceIntPtr device)
+{
+ LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate;
+
+ return((local->flags & XI86_ALWAYS_CORE) ||
+ (device == inputInfo.keyboard));
+}
+
+void
+xf86XInputSetSendCoreEvents(LocalDevicePtr local, Bool always)
+{
+ if (always) {
+ local->flags |= XI86_ALWAYS_CORE;
+ } else {
+ local->flags &= ~XI86_ALWAYS_CORE;
+ }
+}
+
+static int xf86CoreButtonState;
+
+/***********************************************************************
+ *
+ * xf86CheckButton --
+ *
+ * Test if the core pointer button state is coherent with
+ * the button event to send.
+ *
+ ***********************************************************************
+ */
+Bool
+xf86CheckButton(int button,
+ int down)
+{
+ int check;
+ int bit = (1 << (button - 1));
+
+ check = xf86CoreButtonState & bit;
+
+ DBG(5, ErrorF("xf86CheckButton "
+ "button=%d down=%d state=%d check=%d returns ",
+ button, down, xf86CoreButtonState, check));
+ if ((check && down) || (!check && !down)) {
+ DBG(5, ErrorF("FALSE\n"));
+ return FALSE;
+ }
+ xf86CoreButtonState ^= bit;
+
+ DBG(5, ErrorF("TRUE\n"));
+ return TRUE;
+}
+
+/***********************************************************************
+ *
+ * xf86ProcessCommonOptions --
+ *
+ * Process global options.
+ *
+ ***********************************************************************
+ */
+void
+xf86ProcessCommonOptions(LocalDevicePtr local,
+ pointer list)
+{
+ if (xf86SetBoolOption(list, "AlwaysCore", 0) ||
+ xf86SetBoolOption(list, "SendCoreEvents", 0)) {
+ local->flags |= XI86_ALWAYS_CORE;
+ xf86Msg(X_CONFIG, "%s: always reports core events\n", local->name);
+ }
+
+ if (xf86SetBoolOption(list, "CorePointer", 0)) {
+ local->flags |= XI86_CORE_POINTER;
+ xf86Msg(X_CONFIG, "%s: Core Pointer\n", local->name);
+ }
+
+ if (xf86SetBoolOption(list, "CoreKeyboard", 0)) {
+ local->flags |= XI86_CORE_KEYBOARD;
+ xf86Msg(X_CONFIG, "%s: Core Keyboard\n", local->name);
+ }
+
+ if (xf86SetBoolOption(list, "SendDragEvents", 1)) {
+ local->flags |= XI86_SEND_DRAG_EVENTS;
+ } else {
+ xf86Msg(X_CONFIG, "%s: doesn't report drag events\n", local->name);
+ }
+
+ local->history_size = xf86SetIntOption(list, "HistorySize", 0);
+
+ if (local->history_size > 0) {
+ xf86Msg(X_CONFIG, "%s: has a history of %d motions\n", local->name,
+ local->history_size);
+ }
+}
+
+/***********************************************************************
+ *
+ * xf86XinputFinalizeInit --
+ *
+ * Create and initialize an integer feedback to control the always
+ * core feature.
+ *
+ ***********************************************************************
+ */
+void
+xf86XinputFinalizeInit(DeviceIntPtr dev)
+{
+ LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate;
+
+ local->dxremaind = 0.0;
+ local->dyremaind = 0.0;
+
+ if (InitIntegerFeedbackClassDeviceStruct(dev, xf86AlwaysCoreControl) == FALSE) {
+ ErrorF("Unable to init integer feedback for always core feature\n");
+ } else {
+ local->always_core_feedback = dev->intfeed;
+ dev->intfeed->ctrl.integer_displayed = (local->flags & XI86_ALWAYS_CORE) ? 1 : 0;
+ }
+}
+
+/***********************************************************************
+ *
+ * xf86ActivateDevice --
+ *
+ * Initialize an input device.
+ *
+ ***********************************************************************
+ */
+void
+xf86ActivateDevice(LocalDevicePtr local)
+{
+ DeviceIntPtr dev;
+
+ if (local->flags & XI86_CONFIGURED) {
+ int open_on_init;
+
+ open_on_init = local->flags &
+ (XI86_OPEN_ON_INIT |
+ XI86_ALWAYS_CORE | XI86_CORE_POINTER | XI86_CORE_KEYBOARD);
+
+ dev = AddInputDevice(local->device_control,
+ open_on_init);
+ if (dev == NULL)
+ FatalError("Too many input devices");
+
+ local->atom = MakeAtom(local->type_name,
+ strlen(local->type_name),
+ TRUE);
+ AssignTypeAndName (dev, local->atom, local->name);
+ dev->public.devicePrivate = (pointer) local;
+ local->dev = dev;
+
+ xf86XinputFinalizeInit(dev);
+
+ /*
+ * XXX Can a single device instance be both core keyboard and
+ * core pointer? If so, this should be changed.
+ */
+ if (local->flags & XI86_CORE_POINTER)
+ RegisterPointerDevice(dev);
+ else if (local->flags & XI86_CORE_KEYBOARD)
+ RegisterKeyboardDevice(dev);
+#ifdef XINPUT
+ else
+ RegisterOtherDevice(dev);
+#endif
+
+ if (serverGeneration == 1)
+ xf86Msg(X_INFO, "XINPUT: Adding extended input device \"%s\" (type: %s)\n",
+ local->name, local->type_name);
+ }
+}
+
+
+#ifdef XINPUT
+/***********************************************************************
+ *
+ * Caller: ProcXOpenDevice
+ *
+ * This is the implementation-dependent routine to open an input device.
+ * Some implementations open all input devices when the server is first
+ * initialized, and never close them. Other implementations open only
+ * the X pointer and keyboard devices during server initialization,
+ * and only open other input devices when some client makes an
+ * XOpenDevice request. This entry point is for the latter type of
+ * implementation.
+ *
+ * If the physical device is not already open, do it here. In this case,
+ * you need to keep track of the fact that one or more clients has the
+ * device open, and physically close it when the last client that has
+ * it open does an XCloseDevice.
+ *
+ * The default implementation is to do nothing (assume all input devices
+ * are opened during X server initialization and kept open).
+ *
+ ***********************************************************************
+ */
+
+void
+OpenInputDevice(DeviceIntPtr dev,
+ ClientPtr client,
+ int *status)
+{
+ if (!dev->inited) {
+ *status = BadDevice;
+ } else {
+ if (!dev->public.on) {
+ if (!EnableDevice(dev)) {
+ *status = BadDevice;
+ } else {
+ /* to prevent ProcXOpenDevice to call EnableDevice again */
+ dev->startup = FALSE;
+ }
+ }
+ }
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXChangeKeyboardDevice
+ *
+ * This procedure does the implementation-dependent portion of the work
+ * needed to change the keyboard device.
+ *
+ * The X keyboard device has a FocusRec. If the device that has been
+ * made into the new X keyboard did not have a FocusRec,
+ * ProcXChangeKeyboardDevice will allocate one for it.
+ *
+ * If you do not want clients to be able to focus the old X keyboard
+ * device, call DeleteFocusClassDeviceStruct to free the FocusRec.
+ *
+ * If you support input devices with keys that you do not want to be
+ * used as the X keyboard, you need to check for them here and return
+ * a BadDevice error.
+ *
+ * The default implementation is to do nothing (assume you do want
+ * clients to be able to focus the old X keyboard). The commented-out
+ * sample code shows what you might do if you don't want the default.
+ *
+ ***********************************************************************
+ */
+
+int
+ChangeKeyboardDevice (DeviceIntPtr old_dev, DeviceIntPtr new_dev)
+{
+ /**********************************************************************
+ * DeleteFocusClassDeviceStruct(old_dev); * defined in xchgptr.c *
+ **********************************************************************/
+ return !Success;
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXChangePointerDevice
+ *
+ * This procedure does the implementation-dependent portion of the work
+ * needed to change the pointer device.
+ *
+ * The X pointer device does not have a FocusRec. If the device that
+ * has been made into the new X pointer had a FocusRec,
+ * ProcXChangePointerDevice will free it.
+ *
+ * If you want clients to be able to focus the old pointer device that
+ * has now become accessible through the input extension, you need to
+ * add a FocusRec to it here.
+ *
+ * The XChangePointerDevice protocol request also allows the client
+ * to choose which axes of the new pointer device are used to move
+ * the X cursor in the X- and Y- directions. If the axes are different
+ * than the default ones, you need to keep track of that here.
+ *
+ * If you support input devices with valuators that you do not want to be
+ * used as the X pointer, you need to check for them here and return a
+ * BadDevice error.
+ *
+ * The default implementation is to do nothing (assume you don't want
+ * clients to be able to focus the old X pointer). The commented-out
+ * sample code shows what you might do if you don't want the default.
+ *
+ ***********************************************************************
+ */
+
+int
+ChangePointerDevice (
+ DeviceIntPtr old_dev,
+ DeviceIntPtr new_dev,
+ unsigned char x,
+ unsigned char y)
+{
+ /************************************************************************
+ InitFocusClassDeviceStruct(old_dev); * allow focusing old ptr*
+
+ x_axis = x; * keep track of new x-axis*
+ y_axis = y; * keep track of new y-axis*
+ if (x_axis != 0 || y_axis != 1)
+ axes_changed = TRUE; * remember axes have changed*
+ else
+ axes_changed = FALSE;
+ *************************************************************************/
+
+ /*
+ * We don't allow axis swap or other exotic features.
+ */
+ if (x == 0 && y == 1) {
+ LocalDevicePtr old_local = (LocalDevicePtr)old_dev->public.devicePrivate;
+ LocalDevicePtr new_local = (LocalDevicePtr)new_dev->public.devicePrivate;
+
+ InitFocusClassDeviceStruct(old_dev);
+
+ /* Restore Extended motion history information */
+ old_dev->valuator->GetMotionProc = old_local->motion_history_proc;
+ old_dev->valuator->numMotionEvents = old_local->history_size;
+
+ /* Save Extended motion history information */
+ new_local->motion_history_proc = new_dev->valuator->GetMotionProc;
+ new_local->history_size = new_dev->valuator->numMotionEvents;
+
+ /* Set Core motion history information */
+ new_dev->valuator->GetMotionProc = miPointerGetMotionEvents;
+ new_dev->valuator->numMotionEvents = miPointerGetMotionBufferSize();
+
+ return Success;
+ }
+ else
+ return !Success;
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXCloseDevice
+ *
+ * Take care of implementation-dependent details of closing a device.
+ * Some implementations may actually close the device, others may just
+ * remove this clients interest in that device.
+ *
+ * The default implementation is to do nothing (assume all input devices
+ * are initialized during X server initialization and kept open).
+ *
+ ***********************************************************************
+ */
+
+void
+CloseInputDevice (DeviceIntPtr d, ClientPtr client)
+{
+ ErrorF("ProcXCloseDevice to close or not ?\n");
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXListInputDevices
+ *
+ * This is the implementation-dependent routine to initialize an input
+ * device to the point that information about it can be listed.
+ * Some implementations open all input devices when the server is first
+ * initialized, and never close them. Other implementations open only
+ * the X pointer and keyboard devices during server initialization,
+ * and only open other input devices when some client makes an
+ * XOpenDevice request. If some other process has the device open, the
+ * server may not be able to get information about the device to list it.
+ *
+ * This procedure should be used by implementations that do not initialize
+ * all input devices at server startup. It should do device-dependent
+ * initialization for any devices not previously initialized, and call
+ * AddInputDevice for each of those devices so that a DeviceIntRec will be
+ * created for them.
+ *
+ * The default implementation is to do nothing (assume all input devices
+ * are initialized during X server initialization and kept open).
+ * The commented-out sample code shows what you might do if you don't want
+ * the default.
+ *
+ ***********************************************************************
+ */
+
+void
+AddOtherInputDevices ()
+{
+}
+
+
+/****************************************************************************
+ *
+ * Caller: ProcXSetDeviceMode
+ *
+ * Change the mode of an extension device.
+ * This function is used to change the mode of a device from reporting
+ * relative motion to reporting absolute positional information, and
+ * vice versa.
+ * The default implementation below is that no such devices are supported.
+ *
+ ***********************************************************************
+ */
+
+int
+SetDeviceMode (ClientPtr client, DeviceIntPtr dev, int mode)
+{
+ LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate;
+
+ if (local->switch_mode) {
+ return (*local->switch_mode)(client, dev, mode);
+ }
+ else
+ return BadMatch;
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXSetDeviceValuators
+ *
+ * Set the value of valuators on an extension input device.
+ * This function is used to set the initial value of valuators on
+ * those input devices that are capable of reporting either relative
+ * motion or an absolute position, and allow an initial position to be set.
+ * The default implementation below is that no such devices are supported.
+ *
+ ***********************************************************************
+ */
+
+int
+SetDeviceValuators (ClientPtr client, DeviceIntPtr dev, int *valuators,
+ int first_valuator, int num_valuators)
+{
+ return BadMatch;
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXChangeDeviceControl
+ *
+ * Change the specified device controls on an extension input device.
+ *
+ ***********************************************************************
+ */
+
+int
+ChangeDeviceControl (ClientPtr client, DeviceIntPtr dev, xDeviceCtl *control)
+{
+ LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate;
+
+ if (!local->control_proc) {
+ return (BadMatch);
+ }
+ else {
+ return (*local->control_proc)(local, control);
+ }
+}
+#endif
+
+/*
+ * adapted from mieq.c to support extended events
+ *
+ */
+#define QUEUE_SIZE 256
+
+typedef struct _Event {
+ xEvent event;
+#ifdef XINPUT
+ deviceValuator val;
+#endif
+ ScreenPtr pScreen;
+} EventRec, *EventPtr;
+
+typedef struct _EventQueue {
+ HWEventQueueType head, tail;
+ CARD32 lastEventTime; /* to avoid time running backwards */
+ Bool lastMotion;
+ EventRec events[QUEUE_SIZE]; /* static allocation for signals */
+ DevicePtr pKbd, pPtr; /* device pointer, to get funcs */
+ ScreenPtr pEnqueueScreen; /* screen events are being delivered to */
+ ScreenPtr pDequeueScreen; /* screen events are being dispatched to */
+} EventQueueRec, *EventQueuePtr;
+
+static EventQueueRec xf86EventQueue;
+
+Bool
+xf86eqInit (DevicePtr pKbd, DevicePtr pPtr)
+{
+ xf86EventQueue.head = xf86EventQueue.tail = 0;
+ xf86EventQueue.lastEventTime = GetTimeInMillis ();
+ xf86EventQueue.pKbd = pKbd;
+ xf86EventQueue.pPtr = pPtr;
+ xf86EventQueue.lastMotion = FALSE;
+ xf86EventQueue.pEnqueueScreen = screenInfo.screens[0];
+ xf86EventQueue.pDequeueScreen = xf86EventQueue.pEnqueueScreen;
+ SetInputCheck (&xf86EventQueue.head, &xf86EventQueue.tail);
+ return TRUE;
+}
+
+/*
+ * Must be reentrant with ProcessInputEvents. Assumption: xf86eqEnqueue
+ * will never be interrupted. If this is called from both signal
+ * handlers and regular code, make sure the signal is suspended when
+ * called from regular code.
+ */
+
+void
+xf86eqEnqueue (xEvent *e)
+{
+ int oldtail, newtail;
+ Bool isMotion;
+#ifdef XINPUT
+ int count;
+
+ xf86AssertBlockedSIGIO ("xf86eqEnqueue");
+ switch (e->u.u.type) {
+ case KeyPress:
+ case KeyRelease:
+#ifdef XFreeXDGA
+ /* we do this here, because nobody seems to be calling
+ xf86PostKeyEvent(). We can't steal MotionNotify events here
+ because the motion-relative information has been lost already. */
+ if(DGAStealKeyEvent(xf86EventQueue.pEnqueueScreen->myNum, e))
+ return;
+#endif
+ /* fall through */
+ case ButtonPress:
+ case ButtonRelease:
+ case MotionNotify:
+ count = 1;
+ break;
+ default:
+#ifdef XFreeXDGA
+ if (DGAIsDgaEvent (e))
+ {
+ count = 1;
+ break;
+ }
+#endif
+ if (!((deviceKeyButtonPointer *) e)->deviceid & MORE_EVENTS) {
+ count = 1;
+ }
+ else {
+ count = 2;
+ }
+ break;
+ }
+#endif
+
+ oldtail = xf86EventQueue.tail;
+ isMotion = e->u.u.type == MotionNotify;
+ if (isMotion && xf86EventQueue.lastMotion && oldtail != xf86EventQueue.head) {
+ if (oldtail == 0)
+ oldtail = QUEUE_SIZE;
+ oldtail = oldtail - 1;
+ }
+ else {
+ newtail = oldtail + 1;
+ if (newtail == QUEUE_SIZE)
+ newtail = 0;
+ /* Toss events which come in late */
+ if (newtail == xf86EventQueue.head)
+ return;
+ xf86EventQueue.tail = newtail;
+ }
+
+ xf86EventQueue.lastMotion = isMotion;
+ xf86EventQueue.events[oldtail].event = *e;
+#ifdef XINPUT
+ if (count == 2) {
+ xf86EventQueue.events[oldtail].val = *((deviceValuator *) (((deviceKeyButtonPointer *) e)+1));
+ }
+#endif
+ /*
+ * Make sure that event times don't go backwards - this
+ * is "unnecessary", but very useful
+ */
+ if (e->u.keyButtonPointer.time < xf86EventQueue.lastEventTime &&
+ xf86EventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000) {
+
+ xf86EventQueue.events[oldtail].event.u.keyButtonPointer.time =
+ xf86EventQueue.lastEventTime;
+ }
+ xf86EventQueue.events[oldtail].pScreen = xf86EventQueue.pEnqueueScreen;
+}
+
+/*
+ * Call this from ProcessInputEvents()
+ */
+void
+xf86eqProcessInputEvents ()
+{
+ EventRec *e;
+ int x, y;
+ struct {
+ xEvent event;
+#ifdef XINPUT
+ deviceValuator val;
+#endif
+ } xe;
+#ifdef XINPUT
+ DeviceIntPtr dev;
+ int id, count;
+ deviceKeyButtonPointer *dev_xe;
+#endif
+
+ while (xf86EventQueue.head != xf86EventQueue.tail) {
+ if (screenIsSaved == SCREEN_SAVER_ON)
+ SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
+#ifdef DPMSExtension
+ if (DPMSPowerLevel != DPMSModeOn)
+ DPMSSet(DPMSModeOn);
+#endif
+
+ e = &xf86EventQueue.events[xf86EventQueue.head];
+ /*
+ * Assumption - screen switching can only occur on motion events
+ */
+ if (e->pScreen != xf86EventQueue.pDequeueScreen) {
+ xf86EventQueue.pDequeueScreen = e->pScreen;
+ x = e->event.u.keyButtonPointer.rootX;
+ y = e->event.u.keyButtonPointer.rootY;
+ if (xf86EventQueue.head == QUEUE_SIZE - 1)
+ xf86EventQueue.head = 0;
+ else
+ ++xf86EventQueue.head;
+ NewCurrentScreen (xf86EventQueue.pDequeueScreen, x, y);
+ }
+ else {
+ xe.event = e->event;
+ xe.val = e->val;
+ if (xf86EventQueue.head == QUEUE_SIZE - 1)
+ xf86EventQueue.head = 0;
+ else
+ ++xf86EventQueue.head;
+ switch (xe.event.u.u.type) {
+ case KeyPress:
+ case KeyRelease:
+ (*xf86EventQueue.pKbd->processInputProc)
+ (&xe.event, (DeviceIntPtr)xf86EventQueue.pKbd, 1);
+ break;
+#ifdef XINPUT
+ case ButtonPress:
+ case ButtonRelease:
+ case MotionNotify:
+ (*(inputInfo.pointer->public.processInputProc))
+ (&xe.event, (DeviceIntPtr)inputInfo.pointer, 1);
+ break;
+
+ default:
+#ifdef XFreeXDGA
+ if (DGADeliverEvent (xf86EventQueue.pDequeueScreen, &xe.event))
+ break;
+#endif
+ dev_xe = (deviceKeyButtonPointer *) &xe.event;
+ id = dev_xe->deviceid & DEVICE_BITS;
+ if (!(dev_xe->deviceid & MORE_EVENTS)) {
+ count = 1;
+ }
+ else {
+ count = 2;
+ }
+ dev = LookupDeviceIntRec(id);
+ if (dev == NULL) {
+ ErrorF("LookupDeviceIntRec id=0x%x not found\n", id);
+/* FatalError("xf86eqProcessInputEvents : device not found.\n");
+ */
+ break;
+ }
+ if (!dev->public.processInputProc) {
+ FatalError("xf86eqProcessInputEvents : device has no input proc.\n");
+ break;
+ }
+ (*dev->public.processInputProc)(&xe.event, dev, count);
+#else
+ default:
+ (*xf86EventQueue.pPtr->processInputProc)
+ (&xe.event, (DeviceIntPtr)xf86EventQueue.pPtr, 1);
+#endif
+ break;
+ }
+ }
+ }
+}
+
+void
+xf86eqSwitchScreen(ScreenPtr pScreen,
+ Bool fromDIX)
+{
+ xf86EventQueue.pEnqueueScreen = pScreen;
+
+ if (fromDIX)
+ xf86EventQueue.pDequeueScreen = pScreen;
+}
+
+/*
+ * convenient functions to post events
+ */
+
+void
+xf86PostMotionEvent(DeviceIntPtr device,
+ int is_absolute,
+ int first_valuator,
+ int num_valuators,
+ ...)
+{
+ va_list var;
+ int loop;
+ xEvent xE[2];
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE;
+ deviceValuator *xv = (deviceValuator*) xev+1;
+ LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate;
+ char *buff = 0;
+ Time current;
+ Bool is_core = xf86IsCorePointer(device);
+ Bool is_shared = xf86ShareCorePointer(device);
+ Bool drag = xf86SendDragEvents(device);
+ ValuatorClassPtr val = device->valuator;
+ int valuator[6];
+ int oldaxis[6];
+ int *axisvals;
+ int dx = 0, dy = 0;
+ float mult;
+ int x, y;
+ int loop_start;
+ int i;
+ int num;
+
+ DBG(5, ErrorF("xf86PostMotionEvent BEGIN 0x%x(%s) is_core=%s is_shared=%s is_absolute=%s\n",
+ device, device->name,
+ is_core ? "True" : "False",
+ is_shared ? "True" : "False",
+ is_absolute ? "True" : "False"));
+
+ xf86Info.lastEventTime = xev->time = current = GetTimeInMillis();
+
+ if (!is_core) {
+ if (HAS_MOTION_HISTORY(local)) {
+ buff = ((char *)local->motion_history +
+ (sizeof(INT32) * local->dev->valuator->numAxes + sizeof(Time)) * local->last);
+ }
+ }
+
+ if (num_valuators && (!val || (first_valuator + num_valuators > val->numAxes))) {
+ ErrorF("Bad valuators reported for device \"%s\"\n", device->name);
+ return;
+ }
+
+ axisvals = val->axisVal;
+
+ va_start(var, num_valuators);
+
+ loop_start = first_valuator;
+ for(loop=0; loop<num_valuators; loop++) {
+
+ valuator[loop%6] = va_arg(var,int);
+
+ if (loop % 6 == 5 || loop == num_valuators - 1) {
+ num = loop % 6 + 1;
+ /*
+ * Adjust first two relative valuators
+ */
+ if (!is_absolute && num_valuators >= 2 && loop_start == 0) {
+
+ dx = valuator[0];
+ dy = valuator[1];
+
+ /*
+ * Accelerate
+ */
+ if (device->ptrfeed && device->ptrfeed->ctrl.num) {
+ /* modeled from xf86Events.c */
+ if (device->ptrfeed->ctrl.threshold) {
+ if ((abs(dx) + abs(dy)) >= device->ptrfeed->ctrl.threshold) {
+ local->dxremaind = ((float)dx * (float)(device->ptrfeed->ctrl.num)) /
+ (float)(device->ptrfeed->ctrl.den) + local->dxremaind;
+ valuator[0] = (int)local->dxremaind;
+ local->dxremaind = local->dxremaind - (float)valuator[0];
+
+ local->dyremaind = ((float)dy * (float)(device->ptrfeed->ctrl.num)) /
+ (float)(device->ptrfeed->ctrl.den) + local->dyremaind;
+ valuator[1] = (int)local->dyremaind;
+ local->dyremaind = local->dyremaind - (float)valuator[1];
+ }
+ }
+ else if (dx || dy) {
+ mult = pow((float)(dx*dx+dy*dy),
+ ((float)(device->ptrfeed->ctrl.num) /
+ (float)(device->ptrfeed->ctrl.den) - 1.0) /
+ 2.0) / 2.0;
+ if (dx) {
+ local->dxremaind = mult * (float)dx + local->dxremaind;
+ valuator[0] = (int)local->dxremaind;
+ local->dxremaind = local->dxremaind - (float)valuator[0];
+ }
+ if (dy) {
+ local->dyremaind = mult * (float)dy + local->dyremaind;
+ valuator[1] = (int)local->dyremaind;
+ local->dyremaind = local->dyremaind - (float)valuator[1];
+ }
+ }
+ DBG(6, ErrorF("xf86PostMotionEvent acceleration v0=%d v1=%d\n",
+ valuator[0], valuator[1]));
+ }
+
+ /*
+ * Map current position back to device space in case
+ * the cursor was warped
+ */
+ if (is_core || is_shared)
+ {
+ miPointerPosition (&x, &y);
+ if (local->reverse_conversion_proc)
+ (*local->reverse_conversion_proc)(local, x, y, axisvals);
+ else
+ {
+ axisvals[0] = x;
+ axisvals[1] = y;
+ }
+ }
+ }
+
+ /*
+ * Update axes
+ */
+ for (i = 0; i < num; i++)
+ {
+ oldaxis[i] = axisvals[loop_start + i];
+ if (is_absolute)
+ axisvals[loop_start + i] = valuator[i];
+ else
+ axisvals[loop_start + i] += valuator[i];
+ }
+
+ /*
+ * Deliver extension event
+ */
+ if (!is_core) {
+ xev->type = DeviceMotionNotify;
+ xev->detail = 0;
+ xev->deviceid = device->id | MORE_EVENTS;
+
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+
+ xv->device_state = 0;
+ xv->num_valuators = num;
+ xv->first_valuator = loop_start;
+ memcpy (&xv->valuator0, &axisvals[loop_start],
+ sizeof(INT32)*xv->num_valuators);
+
+ if (HAS_MOTION_HISTORY(local)) {
+ *(Time*)buff = current;
+ memcpy(buff+sizeof(Time)+sizeof(INT32)*xv->first_valuator,
+ &axisvals[loop_start],
+ sizeof(INT32)*xv->num_valuators);
+ }
+ ENQUEUE(xE);
+ }
+
+ /*
+ * Deliver core event
+ */
+ if (is_core ||
+ (is_shared && num_valuators >= 2 && loop_start == 0)) {
+#ifdef XFreeXDGA
+ /*
+ * Let DGA peek at the event and steal it
+ */
+ xev->type = MotionNotify;
+ xev->detail = 0;
+ if (is_absolute)
+ {
+ dx = axisvals[0] - oldaxis[0];
+ dy = axisvals[1] - oldaxis[1];
+ }
+ if (DGAStealMouseEvent(xf86EventQueue.pEnqueueScreen->myNum,
+ xE, dx, dy))
+ continue;
+#endif
+ if (!(*local->conversion_proc)(local, loop_start, num,
+ axisvals[0], axisvals[1],
+ axisvals[2], axisvals[3],
+ axisvals[4], axisvals[5],
+ &x, &y))
+ continue;
+
+ if (drag)
+ miPointerAbsoluteCursor (x, y, current);
+ /*
+ * Retrieve the position
+ */
+ miPointerPosition (&x, &y);
+ if (local->reverse_conversion_proc)
+ (*local->reverse_conversion_proc)(local, x, y, axisvals);
+ else
+ {
+ axisvals[0] = x;
+ axisvals[1] = y;
+ }
+ }
+ loop_start += 6;
+ }
+ }
+ va_end(var);
+ if (HAS_MOTION_HISTORY(local)) {
+ local->last = (local->last + 1) % device->valuator->numMotionEvents;
+ if (local->last == local->first)
+ local->first = (local->first + 1) % device->valuator->numMotionEvents;
+ }
+ DBG(5, ErrorF("xf86PostMotionEvent END 0x%x(%s) is_core=%s is_shared=%s\n",
+ device, device->name,
+ is_core ? "True" : "False",
+ is_shared ? "True" : "False"));
+}
+
+void
+xf86PostProximityEvent(DeviceIntPtr device,
+ int is_in,
+ int first_valuator,
+ int num_valuators,
+ ...)
+{
+ va_list var;
+ int loop;
+ xEvent xE[2];
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE;
+ deviceValuator *xv = (deviceValuator*) xev+1;
+ ValuatorClassPtr val = device->valuator;
+ Bool is_core = xf86IsCorePointer(device);
+ Bool is_absolute = val && ((val->mode & 1) == Relative);
+
+ DBG(5, ErrorF("xf86PostProximityEvent BEGIN 0x%x(%s) prox=%s is_core=%s is_absolute=%s\n",
+ device, device->name, is_in ? "true" : "false",
+ is_core ? "True" : "False",
+ is_absolute ? "True" : "False"));
+
+ if (is_core) {
+ return;
+ }
+
+ if (num_valuators && (!val || (first_valuator + num_valuators > val->numAxes))) {
+ ErrorF("Bad valuators reported for device \"%s\"\n", device->name);
+ return;
+ }
+
+ xev->type = is_in ? ProximityIn : ProximityOut;
+ xev->detail = 0;
+ xev->deviceid = device->id | MORE_EVENTS;
+
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->device_state = 0;
+
+ if ((device->valuator->mode & 1) == Relative) {
+ num_valuators = 0;
+ }
+
+ if (num_valuators != 0) {
+ int *axisvals = val->axisVal;
+
+ va_start(var, num_valuators);
+
+ for(loop=0; loop<num_valuators; loop++) {
+ switch (loop % 6) {
+ case 0:
+ xv->valuator0 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 1:
+ xv->valuator1 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 2:
+ xv->valuator2 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 3:
+ xv->valuator3 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 4:
+ xv->valuator4 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 5:
+ xv->valuator5 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ }
+ if ((loop % 6 == 5) || (loop == num_valuators - 1)) {
+ xf86Info.lastEventTime = xev->time = GetTimeInMillis();
+
+ xv->num_valuators = (loop % 6) + 1;
+ xv->first_valuator = first_valuator + (loop / 6) * 6;
+ ENQUEUE(xE);
+ }
+ }
+ va_end(var);
+ }
+ else {
+ /* no valuator */
+ xf86Info.lastEventTime = xev->time = GetTimeInMillis();
+
+ xv->num_valuators = 0;
+ xv->first_valuator = 0;
+ ENQUEUE(xE);
+ }
+ DBG(5, ErrorF("xf86PostProximityEvent END 0x%x(%s) prox=%s is_core=%s is_absolute=%s\n",
+ device, device->name, is_in ? "true" : "false",
+ is_core ? "True" : "False",
+ is_absolute ? "True" : "False"));
+
+}
+
+void
+xf86PostButtonEvent(DeviceIntPtr device,
+ int is_absolute,
+ int button,
+ int is_down,
+ int first_valuator,
+ int num_valuators,
+ ...)
+{
+ va_list var;
+ int loop;
+ xEvent xE[2];
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE;
+ deviceValuator *xv = (deviceValuator*) xev+1;
+ ValuatorClassPtr val = device->valuator;
+ Bool is_core = xf86IsCorePointer(device);
+ Bool is_shared = xf86ShareCorePointer(device);
+
+ DBG(5, ErrorF("xf86PostButtonEvent BEGIN 0x%x(%s) button=%d down=%s is_core=%s is_shared=%s is_absolute=%s\n",
+ device, device->name, button,
+ is_down ? "True" : "False",
+ is_core ? "True" : "False",
+ is_shared ? "True" : "False",
+ is_absolute ? "True" : "False"));
+
+ /* Check the core pointer button state not to send an inconsistent
+ * event. This can happen with the AlwaysCore feature.
+ */
+ if ((is_core || is_shared) &&
+ !xf86CheckButton(device->button->map[button], is_down))
+ {
+ return;
+ }
+
+ if (num_valuators && (!val || (first_valuator + num_valuators > val->numAxes))) {
+ ErrorF("Bad valuators reported for device \"%s\"\n", device->name);
+ return;
+ }
+
+ if (!is_core) {
+ xev->type = is_down ? DeviceButtonPress : DeviceButtonRelease;
+ xev->detail = button;
+ xev->deviceid = device->id | MORE_EVENTS;
+
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->device_state = 0;
+
+ if (num_valuators != 0) {
+ int *axisvals = val->axisVal;
+
+ va_start(var, num_valuators);
+
+ for(loop=0; loop<num_valuators; loop++) {
+ switch (loop % 6) {
+ case 0:
+ xv->valuator0 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 1:
+ xv->valuator1 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 2:
+ xv->valuator2 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 3:
+ xv->valuator3 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 4:
+ xv->valuator4 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ case 5:
+ xv->valuator5 = is_absolute ? va_arg(var, int) : axisvals[loop];
+ break;
+ }
+ if ((loop % 6 == 5) || (loop == num_valuators - 1)) {
+ xf86Info.lastEventTime = xev->time = GetTimeInMillis();
+ xv->num_valuators = (loop % 6) + 1;
+ xv->first_valuator = first_valuator + (loop / 6) * 6;
+ ENQUEUE(xE);
+
+ }
+ }
+ va_end(var);
+ }
+ else {
+ /* no valuator */
+ xf86Info.lastEventTime = xev->time = GetTimeInMillis();
+ xv->num_valuators = 0;
+ xv->first_valuator = 0;
+ ENQUEUE(xE);
+ }
+ }
+
+ /* removed rootX/rootY as DIX sets these fields */
+ if (is_core || is_shared) {
+ xE->u.u.type = is_down ? ButtonPress : ButtonRelease;
+ xE->u.u.detail = device->button->map[button];
+ xf86Info.lastEventTime = xE->u.keyButtonPointer.time = GetTimeInMillis();
+
+#ifdef XFreeXDGA
+ if (!DGAStealMouseEvent(xf86EventQueue.pEnqueueScreen->myNum, xE, 0, 0))
+#endif
+ ENQUEUE(xE);
+ }
+ DBG(5, ErrorF("xf86PostButtonEvent END\n"));
+}
+
+void
+xf86PostKeyEvent(DeviceIntPtr device,
+ unsigned int key_code,
+ int is_down,
+ int is_absolute,
+ int first_valuator,
+ int num_valuators,
+ ...)
+{
+ va_list var;
+ int loop;
+ xEvent xE[2];
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE;
+ deviceValuator *xv = (deviceValuator*) xev+1;
+
+ va_start(var, num_valuators);
+
+ for(loop=0; loop<num_valuators; loop++) {
+ switch (loop % 6) {
+ case 0:
+ xv->valuator0 = va_arg(var, int);
+ break;
+ case 1:
+ xv->valuator1 = va_arg(var, int);
+ break;
+ case 2:
+ xv->valuator2 = va_arg(var, int);
+ break;
+ case 3:
+ xv->valuator3 = va_arg(var, int);
+ break;
+ case 4:
+ xv->valuator4 = va_arg(var, int);
+ break;
+ case 5:
+ xv->valuator5 = va_arg(var, int);
+ break;
+ }
+ if (((loop % 6 == 5) || (loop == num_valuators - 1))) {
+ xev->type = is_down ? DeviceKeyPress : DeviceKeyRelease;
+ xev->detail = key_code;
+
+ xf86Info.lastEventTime = xev->time = GetTimeInMillis();
+ xev->deviceid = device->id | MORE_EVENTS;
+
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->device_state = 0;
+ /* if the device is in the relative mode we don't have to send valuators */
+ xv->num_valuators = is_absolute ? (loop % 6) + 1 : 0;
+ xv->first_valuator = first_valuator + (loop / 6) * 6;
+
+ ENQUEUE(xE);
+ /* if the device is in the relative mode only one event is needed */
+ if (!is_absolute) break;
+ }
+ }
+ va_end(var);
+}
+
+void
+xf86PostKeyboardEvent(DeviceIntPtr device,
+ unsigned int key_code,
+ int is_down)
+{
+ xEvent xE[2];
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE;
+
+ if (xf86IsCoreKeyboard(device)) {
+ xev->type = is_down ? KeyPress : KeyRelease;
+ } else {
+ xev->type = is_down ? DeviceKeyPress : DeviceKeyRelease;
+ }
+ xev->detail = key_code;
+ xf86Info.lastEventTime = xev->time = GetTimeInMillis();
+
+#ifdef XFreeXDGA
+ /* if(!DGAStealKeyEvent(xf86EventQueue.pEnqueueScreen->myNum, xE)) */
+#endif
+ ENQUEUE(xE);
+}
+
+/*
+ * Motion history management.
+ */
+
+void
+xf86MotionHistoryAllocate(LocalDevicePtr local)
+{
+ ValuatorClassPtr valuator = local->dev->valuator;
+
+ if (!HAS_MOTION_HISTORY(local))
+ return;
+ if (local->motion_history) xfree(local->motion_history);
+ local->motion_history = xalloc((sizeof(INT32) * valuator->numAxes + sizeof(Time))
+ * valuator->numMotionEvents);
+ local->first = 0;
+ local->last = 0;
+}
+
+int
+xf86GetMotionEvents(DeviceIntPtr dev,
+ xTimecoord *buff,
+ unsigned long start,
+ unsigned long stop,
+ ScreenPtr pScreen)
+{
+ LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate;
+ ValuatorClassPtr valuator = dev->valuator;
+ int num = 0;
+ int loop = local->first;
+ int size;
+ Time current;
+
+ if (!HAS_MOTION_HISTORY(local))
+ return 0;
+
+ size = (sizeof(INT32) * valuator->numAxes + sizeof(Time));
+
+ while (loop != local->last) {
+ current = *(Time*)(((char *)local->motion_history)+loop*size);
+ if (current > stop)
+ return num;
+ if (current >= start) {
+ memcpy(((char *)buff)+size*num,
+ ((char *)local->motion_history)+loop*size, size);
+ num++;
+ }
+ loop = (loop + 1) % valuator->numMotionEvents;
+ }
+ return num;
+}
+
+LocalDevicePtr
+xf86FirstLocalDevice()
+{
+ return xf86InputDevs;
+}
+
+/*
+ * Cx - raw data from touch screen
+ * Sxhigh - scaled highest dimension
+ * (remember, this is of rows - 1 because of 0 origin)
+ * Sxlow - scaled lowest dimension
+ * Rxhigh - highest raw value from touch screen calibration
+ * Rxlow - lowest raw value from touch screen calibration
+ *
+ * This function is the same for X or Y coordinates.
+ * You may have to reverse the high and low values to compensate for
+ * different orgins on the touch screen vs X.
+ */
+
+int
+xf86ScaleAxis(int Cx,
+ int Sxhigh,
+ int Sxlow,
+ int Rxhigh,
+ int Rxlow )
+{
+ int X;
+ int dSx = Sxhigh - Sxlow;
+ int dRx = Rxhigh - Rxlow;
+
+ dSx = Sxhigh - Sxlow;
+ if (dRx) {
+ X = ((dSx * (Cx - Rxlow)) / dRx) + Sxlow;
+ }
+ else {
+ X = 0;
+ ErrorF ("Divide by Zero in xf86ScaleAxis");
+ }
+
+ if (X > Sxlow)
+ X = Sxlow;
+ if (X < Sxhigh)
+ X = Sxhigh;
+
+ return (X);
+}
+
+/*
+ * This function checks the given screen against the current screen and
+ * makes changes if appropriate. It should be called from an XInput driver's
+ * ReadInput function before any events are posted, if the device is screen
+ * specific like a touch screen.
+ */
+void
+xf86XInputSetScreen(LocalDevicePtr local,
+ int screen_number,
+ int x,
+ int y)
+{
+ if ((xf86IsCorePointer(local->dev) || xf86ShareCorePointer(local->dev)) &&
+ (miPointerCurrentScreen() != screenInfo.screens[screen_number])) {
+ miPointerSetNewScreen (screen_number, x, y);
+ }
+}
+
+
+void
+xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval, int maxval,
+ int resolution, int min_res, int max_res)
+{
+#ifdef XINPUT
+ if (maxval == -1) {
+ if (axnum == 0)
+ maxval = screenInfo.screens[0]->width - 1;
+ else if (axnum == 1)
+ maxval = screenInfo.screens[0]->height - 1;
+ /* else? */
+ }
+ InitValuatorAxisStruct(dev, axnum, minval, maxval, resolution, min_res,
+ max_res);
+#endif
+}
+
+/*
+ * Set the valuator values to be in synch with dix/event.c
+ * DefineInitialRootWindow().
+ */
+void
+xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum)
+{
+#ifdef XINPUT
+ if (axnum == 0)
+ dev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2;
+ else if (axnum == 1)
+ dev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2;
+#endif
+}
+
+/* end of xf86Xinput.c */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86Xinput.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Xinput.h
new file mode 100644
index 000000000..0c20f78fe
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86Xinput.h
@@ -0,0 +1,220 @@
+/* $XConsortium: xf86Xinput.h /main/11 1996/10/27 11:05:29 kaleb $ */
+/*
+ * Copyright 1995-1999 by Frederic Lepied, France. <Lepied@XFree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Frederic Lepied not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Frederic Lepied makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+ * Copyright (c) 2000-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).
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Xinput.h,v 3.36 2003/08/24 17:36:55 dawes Exp $ */
+
+#ifndef _xf86Xinput_h
+#define _xf86Xinput_h
+
+#ifndef NEED_EVENTS
+#define NEED_EVENTS
+#endif
+#include "xf86str.h"
+#include "inputstr.h"
+#ifdef XINPUT
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#include "XIstubs.h"
+#endif
+
+/* Input device flags */
+#define XI86_OPEN_ON_INIT 0x01 /* open the device at startup time */
+#define XI86_CONFIGURED 0x02 /* the device has been configured */
+#define XI86_ALWAYS_CORE 0x04 /* device always controls the pointer */
+/* the device sends Xinput and core pointer events */
+#define XI86_SEND_CORE_EVENTS XI86_ALWAYS_CORE
+/* if the device is the core pointer or is sending core events, and
+ * SEND_DRAG_EVENTS is false, and a buttons is done, then no motion events
+ * (mouse drag action) are sent. This is mainly to allow a touch screen to be
+ * used with netscape and other browsers which do strange things if the mouse
+ * moves between button down and button up. With a touch screen, this motion
+ * is common due to the user's finger moving slightly.
+ */
+#define XI86_SEND_DRAG_EVENTS 0x08
+#define XI86_CORE_POINTER 0x10 /* device is the core pointer */
+#define XI86_CORE_KEYBOARD 0x20 /* device is the core keyboard */
+#define XI86_POINTER_CAPABLE 0x40 /* capable of being a core pointer */
+#define XI86_KEYBOARD_CAPABLE 0x80 /* capable of being a core keyboard */
+
+#define XI_PRIVATE(dev) \
+ (((LocalDevicePtr)((dev)->public.devicePrivate))->private)
+
+#ifdef DBG
+#undef DBG
+#endif
+#define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;}
+
+#ifdef HAS_MOTION_HISTORY
+#undef HAS_MOTION_HISTORY
+#endif
+#define HAS_MOTION_HISTORY(local) ((local)->dev->valuator && (local)->dev->valuator->numMotionEvents)
+
+#ifdef XINPUT
+/* This holds the input driver entry and module information. */
+typedef struct _InputDriverRec {
+ int driverVersion;
+ char * driverName;
+ void (*Identify)(int flags);
+ struct _LocalDeviceRec *(*PreInit)(struct _InputDriverRec *drv,
+ IDevPtr dev, int flags);
+ void (*UnInit)(struct _InputDriverRec *drv,
+ struct _LocalDeviceRec *pInfo,
+ int flags);
+ pointer module;
+ int refCount;
+} InputDriverRec, *InputDriverPtr;
+#endif
+
+/* This is to input devices what the ScrnInfoRec is to screens. */
+
+typedef struct _LocalDeviceRec {
+ struct _LocalDeviceRec *next;
+ char * name;
+ int flags;
+
+ Bool (*device_control)(DeviceIntPtr device, int what);
+ void (*read_input)(struct _LocalDeviceRec *local);
+ int (*control_proc)(struct _LocalDeviceRec *local,
+ xDeviceCtl *control);
+ void (*close_proc)(struct _LocalDeviceRec *local);
+ int (*switch_mode)(ClientPtr client, DeviceIntPtr dev,
+ int mode);
+ Bool (*conversion_proc)(struct _LocalDeviceRec *local,
+ int first, int num, int v0,
+ int v1, int v2, int v3, int v4,
+ int v5, int *x, int *y);
+ Bool (*reverse_conversion_proc)(
+ struct _LocalDeviceRec *local,
+ int x, int y, int *valuators);
+
+ int fd;
+ Atom atom;
+ DeviceIntPtr dev;
+ pointer private;
+ int private_flags;
+ pointer motion_history;
+ ValuatorMotionProcPtr motion_history_proc;
+ unsigned int history_size; /* only for configuration purpose */
+ unsigned int first;
+ unsigned int last;
+ int old_x;
+ int old_y;
+ float dxremaind;
+ float dyremaind;
+ char * type_name;
+ IntegerFeedbackPtr always_core_feedback;
+ IDevPtr conf_idev;
+ InputDriverPtr drv;
+ pointer module;
+ pointer options;
+} LocalDeviceRec, *LocalDevicePtr, InputInfoRec, *InputInfoPtr;
+
+typedef struct _DeviceAssocRec
+{
+ char * config_section_name;
+ LocalDevicePtr (*device_allocate)(void);
+} DeviceAssocRec, *DeviceAssocPtr;
+
+/* xf86Globals.c */
+extern InputInfoPtr xf86InputDevs;
+
+/* xf86Xinput.c */
+int xf86IsCorePointer(DeviceIntPtr dev);
+int xf86IsCoreKeyboard(DeviceIntPtr dev);
+void xf86XInputSetSendCoreEvents(LocalDevicePtr local, Bool always);
+#define xf86AlwaysCore(a,b) xf86XInputSetSendCoreEvents(a,b)
+
+void InitExtInput(void);
+Bool xf86eqInit(DevicePtr pKbd, DevicePtr pPtr);
+void xf86eqEnqueue(struct _xEvent *event);
+void xf86eqProcessInputEvents (void);
+void xf86eqSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
+void xf86PostMotionEvent(DeviceIntPtr device, int is_absolute,
+ int first_valuator, int num_valuators, ...);
+void xf86PostProximityEvent(DeviceIntPtr device, int is_in,
+ int first_valuator, int num_valuators, ...);
+void xf86PostButtonEvent(DeviceIntPtr device, int is_absolute, int button,
+ int is_down, int first_valuator, int num_valuators,
+ ...);
+void xf86PostKeyEvent(DeviceIntPtr device, unsigned int key_code, int is_down,
+ int is_absolute, int first_valuator, int num_valuators,
+ ...);
+void xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int key_code,
+ int is_down);
+void xf86MotionHistoryAllocate(LocalDevicePtr local);
+int xf86GetMotionEvents(DeviceIntPtr dev, xTimecoord *buff,
+ unsigned long start, unsigned long stop,
+ ScreenPtr pScreen);
+void xf86XinputFinalizeInit(DeviceIntPtr dev);
+Bool xf86CheckButton(int button, int down);
+void xf86SwitchCoreDevice(LocalDevicePtr device, DeviceIntPtr core);
+LocalDevicePtr xf86FirstLocalDevice(void);
+int xf86ScaleAxis(int Cx, int Sxhigh, int Sxlow, int Rxhigh, int Rxlow);
+void xf86XInputSetScreen(LocalDevicePtr local, int screen_number, int x, int y);
+void xf86ProcessCommonOptions(InputInfoPtr pInfo, pointer options);
+void xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval,
+ int maxval, int resolution, int min_res,
+ int max_res);
+void xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum);
+void xf86AddEnabledDevice(InputInfoPtr pInfo);
+void xf86RemoveEnabledDevice(InputInfoPtr pInfo);
+
+/* xf86Helper.c */
+void xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags);
+void xf86DeleteInputDriver(int drvIndex);
+InputInfoPtr xf86AllocateInput(InputDriverPtr drv, int flags);
+void xf86DeleteInput(InputInfoPtr pInp, int flags);
+
+/* xf86Option.c */
+void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts,
+ pointer extraOpts);
+
+#endif /* _xf86Xinput_h */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86cmap.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86cmap.c
new file mode 100644
index 000000000..b77e9fb47
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86cmap.c
@@ -0,0 +1,1123 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86cmap.c,v 1.9 2005/09/05 07:43:51 daniels Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86cmap.c,v 1.25 2003/10/17 20:02:12 alanh Exp $ */
+/*
+ * Copyright (c) 1998-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).
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#if defined(_XOPEN_SOURCE) || defined(__QNXNTO__) \
+ || (defined(sun) && defined(__SVR4))
+#include <math.h>
+#else
+#define _XOPEN_SOURCE /* to get prototype for pow on some systems */
+#include <math.h>
+#undef _XOPEN_SOURCE
+#endif
+
+#include <X11/X.h>
+#include "misc.h"
+#include <X11/Xproto.h>
+#include "colormapst.h"
+#include "scrnintstr.h"
+
+#include "resource.h"
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+#include "xf86str.h"
+#include "micmap.h"
+
+#ifdef XFreeXDGA
+#define _XF86DGA_SERVER_
+#include <X11/extensions/xf86dgastr.h>
+#include "dgaproc.h"
+#endif
+
+#include "xf86cmap.h"
+
+#define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = \
+ ((CMapScreenPtr) (pScreen)->devPrivates[CMapScreenIndex].ptr)->field)
+#define SCREEN_EPILOGUE(pScreen, field, wrapper)\
+ ((pScreen)->field = wrapper)
+
+#define LOAD_PALETTE(pmap, index) \
+ ((pmap == miInstalledMaps[index]) && \
+ ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) || \
+ xf86Screens[index]->vtSema || pScreenPriv->isDGAmode))
+
+
+typedef struct _CMapLink {
+ ColormapPtr cmap;
+ struct _CMapLink *next;
+} CMapLink, *CMapLinkPtr;
+
+typedef struct {
+ ScrnInfoPtr pScrn;
+ CloseScreenProcPtr CloseScreen;
+ CreateColormapProcPtr CreateColormap;
+ DestroyColormapProcPtr DestroyColormap;
+ InstallColormapProcPtr InstallColormap;
+ StoreColorsProcPtr StoreColors;
+ Bool (*EnterVT)(int, int);
+ Bool (*SwitchMode)(int, DisplayModePtr, int);
+ int (*SetDGAMode)(int, int, DGADevicePtr);
+ int maxColors;
+ int sigRGBbits;
+ int gammaElements;
+ LOCO *gamma;
+ int *PreAllocIndices;
+ CMapLinkPtr maps;
+ unsigned int flags;
+ Bool isDGAmode;
+} CMapScreenRec, *CMapScreenPtr;
+
+typedef struct {
+ int numColors;
+ LOCO *colors;
+ Bool recalculate;
+ int overscan;
+} CMapColormapRec, *CMapColormapPtr;
+
+static unsigned long CMapGeneration = 0;
+static int CMapScreenIndex = -1;
+static int CMapColormapIndex = -1;
+
+static void CMapInstallColormap(ColormapPtr);
+static void CMapStoreColors(ColormapPtr, int, xColorItem *);
+static Bool CMapCloseScreen (int, ScreenPtr);
+static Bool CMapCreateColormap (ColormapPtr);
+static void CMapDestroyColormap (ColormapPtr);
+
+static Bool CMapEnterVT(int, int);
+static Bool CMapSwitchMode(int, DisplayModePtr, int);
+static int CMapSetDGAMode(int, int, DGADevicePtr);
+static int CMapChangeGamma(int, Gamma);
+
+static void ComputeGamma(CMapScreenPtr);
+static Bool CMapAllocateColormapPrivate(ColormapPtr);
+static Bool CMapInitDefMap(ColormapPtr,int);
+static void CMapRefreshColors(ColormapPtr, int, int*);
+static void CMapSetOverscan(ColormapPtr, int, int *);
+static void CMapReinstallMap(ColormapPtr);
+static void CMapUnwrapScreen(ScreenPtr pScreen);
+
+
+
+Bool xf86HandleColormaps(
+ ScreenPtr pScreen,
+ int maxColors,
+ int sigRGBbits,
+ xf86LoadPaletteProc *loadPalette,
+ xf86SetOverscanProc *setOverscan,
+ unsigned int flags
+){
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ ColormapPtr pDefMap = NULL;
+ CMapScreenPtr pScreenPriv;
+ LOCO *gamma;
+ int *indices;
+ int elements;
+
+ if(!maxColors || !sigRGBbits || !loadPalette)
+ return FALSE;
+
+ if(CMapGeneration != serverGeneration) {
+ if(((CMapScreenIndex = AllocateScreenPrivateIndex()) < 0) ||
+ ((CMapColormapIndex = AllocateColormapPrivateIndex(
+ CMapInitDefMap)) < 0))
+ return FALSE;
+ CMapGeneration = serverGeneration;
+ }
+
+ elements = 1 << sigRGBbits;
+
+ if(!(gamma = xalloc(elements * sizeof(LOCO))))
+ return FALSE;
+
+ if(!(indices = xalloc(maxColors * sizeof(int)))) {
+ xfree(gamma);
+ return FALSE;
+ }
+
+ if(!(pScreenPriv = xalloc(sizeof(CMapScreenRec)))) {
+ xfree(gamma);
+ xfree(indices);
+ return FALSE;
+ }
+
+ pScreen->devPrivates[CMapScreenIndex].ptr = (pointer)pScreenPriv;
+
+ pScreenPriv->CloseScreen = pScreen->CloseScreen;
+ pScreenPriv->CreateColormap = pScreen->CreateColormap;
+ pScreenPriv->DestroyColormap = pScreen->DestroyColormap;
+ pScreenPriv->InstallColormap = pScreen->InstallColormap;
+ pScreenPriv->StoreColors = pScreen->StoreColors;
+ pScreen->CloseScreen = CMapCloseScreen;
+ pScreen->CreateColormap = CMapCreateColormap;
+ pScreen->DestroyColormap = CMapDestroyColormap;
+ pScreen->InstallColormap = CMapInstallColormap;
+ pScreen->StoreColors = CMapStoreColors;
+
+ pScreenPriv->pScrn = pScrn;
+ pScrn->LoadPalette = loadPalette;
+ pScrn->SetOverscan = setOverscan;
+ pScreenPriv->maxColors = maxColors;
+ pScreenPriv->sigRGBbits = sigRGBbits;
+ pScreenPriv->gammaElements = elements;
+ pScreenPriv->gamma = gamma;
+ pScreenPriv->PreAllocIndices = indices;
+ pScreenPriv->maps = NULL;
+ pScreenPriv->flags = flags;
+ pScreenPriv->isDGAmode = FALSE;
+
+ pScreenPriv->EnterVT = pScrn->EnterVT;
+ pScreenPriv->SwitchMode = pScrn->SwitchMode;
+ pScreenPriv->SetDGAMode = pScrn->SetDGAMode;
+
+ if (!(flags & CMAP_LOAD_EVEN_IF_OFFSCREEN)) {
+ pScrn->EnterVT = CMapEnterVT;
+ if ((flags & CMAP_RELOAD_ON_MODE_SWITCH) && pScrn->SwitchMode)
+ pScrn->SwitchMode = CMapSwitchMode;
+ }
+#ifdef XFreeXDGA
+ pScrn->SetDGAMode = CMapSetDGAMode;
+#endif
+ pScrn->ChangeGamma = CMapChangeGamma;
+
+ ComputeGamma(pScreenPriv);
+
+ /* get the default map */
+
+ pDefMap = (ColormapPtr) LookupIDByType(pScreen->defColormap, RT_COLORMAP);
+
+ if(!CMapAllocateColormapPrivate(pDefMap)) {
+ CMapUnwrapScreen(pScreen);
+ return FALSE;
+ }
+
+ /* Force the initial map to be loaded */
+ miInstalledMaps[pScreen->myNum] = NULL;
+ CMapInstallColormap(pDefMap);
+ return TRUE;
+}
+
+static Bool
+CMapInitDefMap(ColormapPtr cmap, int index)
+{
+ return TRUE;
+}
+
+
+/**** Screen functions ****/
+
+
+static Bool
+CMapCloseScreen (int i, ScreenPtr pScreen)
+{
+ CMapUnwrapScreen(pScreen);
+
+ return (*pScreen->CloseScreen) (i, pScreen);
+}
+
+static Bool
+CMapColormapUseMax(VisualPtr pVisual, CMapScreenPtr pScreenPriv)
+{
+ if (pVisual->nplanes > 16)
+ return TRUE;
+ return ((1 << pVisual->nplanes) > pScreenPriv->maxColors);
+}
+
+static Bool
+CMapAllocateColormapPrivate(ColormapPtr pmap)
+{
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pmap->pScreen->devPrivates[CMapScreenIndex].ptr;
+ CMapColormapPtr pColPriv;
+ CMapLinkPtr pLink;
+ int numColors;
+ LOCO *colors;
+
+ if (CMapColormapUseMax(pmap->pVisual, pScreenPriv))
+ numColors = pmap->pVisual->ColormapEntries;
+ else
+ numColors = 1 << pmap->pVisual->nplanes;
+
+ if(!(colors = xalloc(numColors * sizeof(LOCO))))
+ return FALSE;
+
+ if(!(pColPriv = xalloc(sizeof(CMapColormapRec)))) {
+ xfree(colors);
+ return FALSE;
+ }
+
+ pmap->devPrivates[CMapColormapIndex].ptr = (pointer)pColPriv;
+
+ pColPriv->numColors = numColors;
+ pColPriv->colors = colors;
+ pColPriv->recalculate = TRUE;
+ pColPriv->overscan = -1;
+
+ /* add map to list */
+ pLink = xalloc(sizeof(CMapLink));
+ if(pLink) {
+ pLink->cmap = pmap;
+ pLink->next = pScreenPriv->maps;
+ pScreenPriv->maps = pLink;
+ }
+
+ return TRUE;
+}
+
+static Bool
+CMapCreateColormap (ColormapPtr pmap)
+{
+ ScreenPtr pScreen = pmap->pScreen;
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+ Bool ret = FALSE;
+
+ pScreen->CreateColormap = pScreenPriv->CreateColormap;
+ if((*pScreen->CreateColormap)(pmap)) {
+ if(CMapAllocateColormapPrivate(pmap))
+ ret = TRUE;
+ }
+ pScreen->CreateColormap = CMapCreateColormap;
+
+ return ret;
+}
+
+static void
+CMapDestroyColormap (ColormapPtr cmap)
+{
+ ScreenPtr pScreen = cmap->pScreen;
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+ CMapColormapPtr pColPriv =
+ (CMapColormapPtr) cmap->devPrivates[CMapColormapIndex].ptr;
+ CMapLinkPtr prevLink = NULL, pLink = pScreenPriv->maps;
+
+ if(pColPriv) {
+ if(pColPriv->colors) xfree(pColPriv->colors);
+ xfree(pColPriv);
+ }
+
+ /* remove map from list */
+ while(pLink) {
+ if(pLink->cmap == cmap) {
+ if(prevLink)
+ prevLink->next = pLink->next;
+ else
+ pScreenPriv->maps = pLink->next;
+ xfree(pLink);
+ break;
+ }
+ prevLink = pLink;
+ pLink = pLink->next;
+ }
+
+ if(pScreenPriv->DestroyColormap) {
+ pScreen->DestroyColormap = pScreenPriv->DestroyColormap;
+ (*pScreen->DestroyColormap)(cmap);
+ pScreen->DestroyColormap = CMapDestroyColormap;
+ }
+}
+
+
+
+static void
+CMapStoreColors(
+ ColormapPtr pmap,
+ int ndef,
+ xColorItem *pdefs
+){
+ ScreenPtr pScreen = pmap->pScreen;
+ VisualPtr pVisual = pmap->pVisual;
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+ int *indices = pScreenPriv->PreAllocIndices;
+ int num = ndef;
+
+ /* At the moment this isn't necessary since there's nobody below us */
+ pScreen->StoreColors = pScreenPriv->StoreColors;
+ (*pScreen->StoreColors)(pmap, ndef, pdefs);
+ pScreen->StoreColors = CMapStoreColors;
+
+ /* should never get here for these */
+ if( (pVisual->class == TrueColor) ||
+ (pVisual->class == StaticColor) ||
+ (pVisual->class == StaticGray))
+ return;
+
+ if(pVisual->class == DirectColor) {
+ CMapColormapPtr pColPriv =
+ (CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
+ int i;
+
+ if (CMapColormapUseMax(pVisual, pScreenPriv)) {
+ int index;
+
+ num = 0;
+ while(ndef--) {
+ if(pdefs[ndef].flags & DoRed) {
+ index = (pdefs[ndef].pixel & pVisual->redMask) >>
+ pVisual->offsetRed;
+ i = num;
+ while(i--)
+ if(indices[i] == index) break;
+ if(i == -1)
+ indices[num++] = index;
+ }
+ if(pdefs[ndef].flags & DoGreen) {
+ index = (pdefs[ndef].pixel & pVisual->greenMask) >>
+ pVisual->offsetGreen;
+ i = num;
+ while(i--)
+ if(indices[i] == index) break;
+ if(i == -1)
+ indices[num++] = index;
+ }
+ if(pdefs[ndef].flags & DoBlue) {
+ index = (pdefs[ndef].pixel & pVisual->blueMask) >>
+ pVisual->offsetBlue;
+ i = num;
+ while(i--)
+ if(indices[i] == index) break;
+ if(i == -1)
+ indices[num++] = index;
+ }
+ }
+
+ } else {
+ /* not really as overkill as it seems */
+ num = pColPriv->numColors;
+ for(i = 0; i < pColPriv->numColors; i++)
+ indices[i] = i;
+ }
+ } else {
+ while(ndef--)
+ indices[ndef] = pdefs[ndef].pixel;
+ }
+
+ CMapRefreshColors(pmap, num, indices);
+}
+
+
+static void
+CMapInstallColormap(ColormapPtr pmap)
+{
+ ScreenPtr pScreen = pmap->pScreen;
+ int index = pScreen->myNum;
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+
+ if (pmap == miInstalledMaps[index])
+ return;
+
+ pScreen->InstallColormap = pScreenPriv->InstallColormap;
+ (*pScreen->InstallColormap)(pmap);
+ pScreen->InstallColormap = CMapInstallColormap;
+
+ /* Important. We let the lower layers, namely DGA,
+ overwrite the choice of Colormap to install */
+ if (miInstalledMaps[index])
+ pmap = miInstalledMaps[index];
+
+ if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
+ (pmap->pVisual->class == TrueColor) &&
+ CMapColormapUseMax(pmap->pVisual, pScreenPriv))
+ return;
+
+ if(LOAD_PALETTE(pmap, index))
+ CMapReinstallMap(pmap);
+}
+
+
+/**** ScrnInfoRec functions ****/
+
+static Bool
+CMapEnterVT(int index, int flags)
+{
+ ScreenPtr pScreen = screenInfo.screens[index];
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+
+ if((*pScreenPriv->EnterVT)(index, flags)) {
+ if(miInstalledMaps[index])
+ CMapReinstallMap(miInstalledMaps[index]);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+static Bool
+CMapSwitchMode(int index, DisplayModePtr mode, int flags)
+{
+ ScreenPtr pScreen = screenInfo.screens[index];
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+
+ if((*pScreenPriv->SwitchMode)(index, mode, flags)) {
+ if(miInstalledMaps[index])
+ CMapReinstallMap(miInstalledMaps[index]);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+#ifdef XFreeXDGA
+static int
+CMapSetDGAMode(int index, int num, DGADevicePtr dev)
+{
+ ScreenPtr pScreen = screenInfo.screens[index];
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+ int ret;
+
+ ret = (*pScreenPriv->SetDGAMode)(index, num, dev);
+
+ pScreenPriv->isDGAmode = DGAActive(index);
+
+ if(!pScreenPriv->isDGAmode && miInstalledMaps[index]
+ && xf86Screens[pScreen->myNum]->vtSema)
+ CMapReinstallMap(miInstalledMaps[index]);
+
+ return ret;
+}
+#endif
+
+
+/**** Utilities ****/
+
+static void
+CMapReinstallMap(ColormapPtr pmap)
+{
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pmap->pScreen->devPrivates[CMapScreenIndex].ptr;
+ CMapColormapPtr cmapPriv =
+ (CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
+ ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum];
+ int i = cmapPriv->numColors;
+ int *indices = pScreenPriv->PreAllocIndices;
+
+ while(i--)
+ indices[i] = i;
+
+ if(cmapPriv->recalculate)
+ CMapRefreshColors(pmap, cmapPriv->numColors, indices);
+ else {
+ (*pScrn->LoadPalette)(pScrn, cmapPriv->numColors,
+ indices, cmapPriv->colors, pmap->pVisual);
+ if (pScrn->SetOverscan) {
+#ifdef DEBUGOVERSCAN
+ ErrorF("SetOverscan() called from CMapReinstallMap\n");
+#endif
+ pScrn->SetOverscan(pScrn, cmapPriv->overscan);
+ }
+ }
+
+ cmapPriv->recalculate = FALSE;
+}
+
+
+static void
+CMapRefreshColors(ColormapPtr pmap, int defs, int* indices)
+{
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pmap->pScreen->devPrivates[CMapScreenIndex].ptr;
+ CMapColormapPtr pColPriv =
+ (CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
+ VisualPtr pVisual = pmap->pVisual;
+ ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum];
+ int numColors, i;
+ LOCO *gamma, *colors;
+ EntryPtr entry;
+ int reds, greens, blues, maxValue, index, shift;
+
+ numColors = pColPriv->numColors;
+ shift = 16 - pScreenPriv->sigRGBbits;
+ maxValue = (1 << pScreenPriv->sigRGBbits) - 1;
+ gamma = pScreenPriv->gamma;
+ colors = pColPriv->colors;
+
+ reds = pVisual->redMask >> pVisual->offsetRed;
+ greens = pVisual->greenMask >> pVisual->offsetGreen;
+ blues = pVisual->blueMask >> pVisual->offsetBlue;
+
+ switch(pVisual->class) {
+ case StaticGray:
+ for(i = 0; i <= numColors - 1; i++) {
+ index = i * maxValue / numColors;
+ colors[i].red = gamma[index].red;
+ colors[i].green = gamma[index].green;
+ colors[i].blue = gamma[index].blue;
+ }
+ break;
+ case TrueColor:
+ if (CMapColormapUseMax(pVisual, pScreenPriv)) {
+ for(i = 0; i <= reds; i++)
+ colors[i].red = gamma[i * maxValue / reds].red;
+ for(i = 0; i <= greens; i++)
+ colors[i].green = gamma[i * maxValue / greens].green;
+ for(i = 0; i <= blues; i++)
+ colors[i].blue = gamma[i * maxValue / blues].blue;
+ break;
+ }
+ for(i = 0; i < numColors; i++) {
+ colors[i].red = gamma[((i >> pVisual->offsetRed) & reds) *
+ maxValue / reds].red;
+ colors[i].green = gamma[((i >> pVisual->offsetGreen) & greens) *
+ maxValue / greens].green;
+ colors[i].blue = gamma[((i >> pVisual->offsetBlue) & blues) *
+ maxValue / blues].blue;
+ }
+ break;
+ case StaticColor:
+ case PseudoColor:
+ case GrayScale:
+ for(i = 0; i < defs; i++) {
+ index = indices[i];
+ entry = (EntryPtr)&pmap->red[index];
+
+ if(entry->fShared) {
+ colors[index].red =
+ gamma[entry->co.shco.red->color >> shift].red;
+ colors[index].green =
+ gamma[entry->co.shco.green->color >> shift].green;
+ colors[index].blue =
+ gamma[entry->co.shco.blue->color >> shift].blue;
+ } else {
+ colors[index].red =
+ gamma[entry->co.local.red >> shift].red;
+ colors[index].green =
+ gamma[entry->co.local.green >> shift].green;
+ colors[index].blue =
+ gamma[entry->co.local.blue >> shift].blue;
+ }
+ }
+ break;
+ case DirectColor:
+ if (CMapColormapUseMax(pVisual, pScreenPriv)) {
+ for(i = 0; i < defs; i++) {
+ index = indices[i];
+ if(index <= reds)
+ colors[index].red =
+ gamma[pmap->red[index].co.local.red >> shift].red;
+ if(index <= greens)
+ colors[index].green =
+ gamma[pmap->green[index].co.local.green >> shift].green;
+ if(index <= blues)
+ colors[index].blue =
+ gamma[pmap->blue[index].co.local.blue >> shift].blue;
+
+ }
+ break;
+ }
+ for(i = 0; i < defs; i++) {
+ index = indices[i];
+
+ colors[index].red = gamma[pmap->red[
+ (index >> pVisual->offsetRed) & reds
+ ].co.local.red >> shift].red;
+ colors[index].green = gamma[pmap->green[
+ (index >> pVisual->offsetGreen) & greens
+ ].co.local.green >> shift].green;
+ colors[index].blue = gamma[pmap->blue[
+ (index >> pVisual->offsetBlue) & blues
+ ].co.local.blue >> shift].blue;
+ }
+ break;
+ }
+
+
+ if(LOAD_PALETTE(pmap, pmap->pScreen->myNum))
+ (*pScrn->LoadPalette)(pScreenPriv->pScrn, defs, indices,
+ colors, pmap->pVisual);
+
+ if (pScrn->SetOverscan)
+ CMapSetOverscan(pmap, defs, indices);
+
+}
+
+static Bool
+CMapCompareColors(LOCO *color1, LOCO *color2)
+{
+ /* return TRUE if the color1 is "closer" to black than color2 */
+#ifdef DEBUGOVERSCAN
+ ErrorF("#%02x%02x%02x vs #%02x%02x%02x (%d vs %d)\n",
+ color1->red, color1->green, color1->blue,
+ color2->red, color2->green, color2->blue,
+ color1->red + color1->green + color1->blue,
+ color2->red + color2->green + color2->blue);
+#endif
+ return (color1->red + color1->green + color1->blue <
+ color2->red + color2->green + color2->blue);
+}
+
+static void
+CMapSetOverscan(ColormapPtr pmap, int defs, int *indices)
+{
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pmap->pScreen->devPrivates[CMapScreenIndex].ptr;
+ CMapColormapPtr pColPriv =
+ (CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
+ ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum];
+ VisualPtr pVisual = pmap->pVisual;
+ int i;
+ LOCO *colors;
+ int index;
+ Bool newOverscan = FALSE;
+ int overscan, tmpOverscan;
+
+ colors = pColPriv->colors;
+ overscan = pColPriv->overscan;
+
+ /*
+ * Search for a new overscan index in the following cases:
+ *
+ * - The index hasn't yet been initialised.  In this case search
+ * for an index that is black or a close match to black.
+ *
+ * - The colour of the old index is changed. In this case search
+ * all indices for a black or close match to black.
+ *
+ * - The colour of the old index wasn't black. In this case only
+ * search the indices that were changed for a better match to black.
+ */
+
+ switch (pVisual->class) {
+ case StaticGray:
+ case TrueColor:
+ /* Should only come here once. Initialise the overscan index to 0 */
+ overscan = 0;
+ newOverscan = TRUE;
+ break;
+ case StaticColor:
+ /*
+ * Only come here once, but search for the overscan in the same way
+ * as for the other cases.
+ */
+ case DirectColor:
+ case PseudoColor:
+ case GrayScale:
+ if (overscan < 0 || overscan > pScreenPriv->maxColors - 1) {
+ /* Uninitialised */
+ newOverscan = TRUE;
+ } else {
+ /* Check if the overscan was changed */
+ for (i = 0; i < defs; i++) {
+ index = indices[i];
+ if (index == overscan) {
+ newOverscan = TRUE;
+ break;
+ }
+ }
+ }
+ if (newOverscan) {
+ /* The overscan is either uninitialised or it has been changed */
+
+ if (overscan < 0 || overscan > pScreenPriv->maxColors - 1)
+ tmpOverscan = pScreenPriv->maxColors - 1;
+ else
+ tmpOverscan = overscan;
+
+ /* search all entries for a close match to black */
+ for (i = pScreenPriv->maxColors - 1; i >= 0; i--) {
+ if (colors[i].red == 0 && colors[i].green == 0 &&
+ colors[i].blue == 0) {
+ overscan = i;
+#ifdef DEBUGOVERSCAN
+ ErrorF("Black found at index 0x%02x\n", i);
+#endif
+ break;
+ } else {
+#ifdef DEBUGOVERSCAN
+ ErrorF("0x%02x: ", i);
+#endif
+ if (CMapCompareColors(&colors[i], &colors[tmpOverscan])) {
+ tmpOverscan = i;
+#ifdef DEBUGOVERSCAN
+ ErrorF("possible \"Black\" at index 0x%02x\n", i);
+#endif
+ }
+ }
+ }
+ if (i < 0)
+ overscan = tmpOverscan;
+ } else {
+ /* Check of the old overscan wasn't black */
+ if (colors[overscan].red != 0 || colors[overscan].green != 0 ||
+ colors[overscan].blue != 0) {
+ int oldOverscan = tmpOverscan = overscan;
+ /* See of there is now a better match */
+ for (i = 0; i < defs; i++) {
+ index = indices[i];
+ if (colors[index].red == 0 && colors[index].green == 0 &&
+ colors[index].blue == 0) {
+ overscan = index;
+#ifdef DEBUGOVERSCAN
+ ErrorF("Black found at index 0x%02x\n", index);
+#endif
+ break;
+ } else {
+#ifdef DEBUGOVERSCAN
+ ErrorF("0x%02x: ", index);
+#endif
+ if (CMapCompareColors(&colors[index],
+ &colors[tmpOverscan])) {
+ tmpOverscan = index;
+#ifdef DEBUGOVERSCAN
+ ErrorF("possible \"Black\" at index 0x%02x\n",
+ index);
+#endif
+ }
+ }
+ }
+ if (i == defs)
+ overscan = tmpOverscan;
+ if (overscan != oldOverscan)
+ newOverscan = TRUE;
+ }
+ }
+ break;
+ }
+ if (newOverscan) {
+ pColPriv->overscan = overscan;
+ if (LOAD_PALETTE(pmap, pmap->pScreen->myNum)) {
+#ifdef DEBUGOVERSCAN
+ ErrorF("SetOverscan() called from CmapSetOverscan\n");
+#endif
+ pScrn->SetOverscan(pScreenPriv->pScrn, overscan);
+ }
+ }
+}
+
+static void
+CMapUnwrapScreen(ScreenPtr pScreen)
+{
+ CMapScreenPtr pScreenPriv =
+ (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+ pScreen->CloseScreen = pScreenPriv->CloseScreen;
+ pScreen->CreateColormap = pScreenPriv->CreateColormap;
+ pScreen->DestroyColormap = pScreenPriv->DestroyColormap;
+ pScreen->InstallColormap = pScreenPriv->InstallColormap;
+ pScreen->StoreColors = pScreenPriv->StoreColors;
+
+ pScrn->EnterVT = pScreenPriv->EnterVT;
+ pScrn->SwitchMode = pScreenPriv->SwitchMode;
+ pScrn->SetDGAMode = pScreenPriv->SetDGAMode;
+
+ xfree(pScreenPriv->gamma);
+ xfree(pScreenPriv->PreAllocIndices);
+ xfree(pScreenPriv);
+}
+
+
+static void
+ComputeGamma(CMapScreenPtr priv)
+{
+ int elements = priv->gammaElements - 1;
+ double RedGamma, GreenGamma, BlueGamma;
+ int i;
+
+#ifndef DONT_CHECK_GAMMA
+ /* This check is to catch drivers that are not initialising pScrn->gamma */
+ if (priv->pScrn->gamma.red < GAMMA_MIN ||
+ priv->pScrn->gamma.red > GAMMA_MAX ||
+ priv->pScrn->gamma.green < GAMMA_MIN ||
+ priv->pScrn->gamma.green > GAMMA_MAX ||
+ priv->pScrn->gamma.blue < GAMMA_MIN ||
+ priv->pScrn->gamma.blue > GAMMA_MAX) {
+
+ xf86DrvMsgVerb(priv->pScrn->scrnIndex, X_WARNING, 0,
+ "The %s driver didn't call xf86SetGamma() to initialise\n"
+ "\tthe gamma values.\n", priv->pScrn->driverName);
+ xf86DrvMsgVerb(priv->pScrn->scrnIndex, X_WARNING, 0,
+ "PLEASE FIX THE `%s' DRIVER!\n", priv->pScrn->driverName);
+ priv->pScrn->gamma.red = 1.0;
+ priv->pScrn->gamma.green = 1.0;
+ priv->pScrn->gamma.blue = 1.0;
+ }
+#endif
+
+ RedGamma = 1.0 / (double)priv->pScrn->gamma.red;
+ GreenGamma = 1.0 / (double)priv->pScrn->gamma.green;
+ BlueGamma = 1.0 / (double)priv->pScrn->gamma.blue;
+
+ for(i = 0; i <= elements; i++) {
+ if(RedGamma == 1.0)
+ priv->gamma[i].red = i;
+ else
+ priv->gamma[i].red = (CARD16)(pow((double)i/(double)elements,
+ RedGamma) * (double)elements + 0.5);
+
+ if(GreenGamma == 1.0)
+ priv->gamma[i].green = i;
+ else
+ priv->gamma[i].green = (CARD16)(pow((double)i/(double)elements,
+ GreenGamma) * (double)elements + 0.5);
+
+ if(BlueGamma == 1.0)
+ priv->gamma[i].blue = i;
+ else
+ priv->gamma[i].blue = (CARD16)(pow((double)i/(double)elements,
+ BlueGamma) * (double)elements + 0.5);
+ }
+}
+
+
+int
+CMapChangeGamma(
+ int index,
+ Gamma gamma
+){
+ ScrnInfoPtr pScrn = xf86Screens[index];
+ ScreenPtr pScreen = pScrn->pScreen;
+ CMapColormapPtr pColPriv;
+ CMapScreenPtr pScreenPriv;
+ CMapLinkPtr pLink;
+
+ /* Is this sufficient checking ? */
+ if(CMapScreenIndex == -1)
+ return BadImplementation;
+
+ pScreenPriv = (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+ if(!pScreenPriv)
+ return BadImplementation;
+
+ if (gamma.red < GAMMA_MIN || gamma.red > GAMMA_MAX ||
+ gamma.green < GAMMA_MIN || gamma.green > GAMMA_MAX ||
+ gamma.blue < GAMMA_MIN || gamma.blue > GAMMA_MAX)
+ return BadValue;
+
+ pScrn->gamma.red = gamma.red;
+ pScrn->gamma.green = gamma.green;
+ pScrn->gamma.blue = gamma.blue;
+
+ ComputeGamma(pScreenPriv);
+
+ /* mark all colormaps on this screen */
+ pLink = pScreenPriv->maps;
+ while(pLink) {
+ pColPriv =
+ (CMapColormapPtr) pLink->cmap->devPrivates[CMapColormapIndex].ptr;
+ pColPriv->recalculate = TRUE;
+ pLink = pLink->next;
+ }
+
+ if(miInstalledMaps[pScreen->myNum] &&
+ ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) ||
+ pScrn->vtSema || pScreenPriv->isDGAmode)) {
+ ColormapPtr pMap = miInstalledMaps[pScreen->myNum];
+
+ if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
+ (pMap->pVisual->class == TrueColor) &&
+ CMapColormapUseMax(pMap->pVisual, pScreenPriv)) {
+
+ /* if the current map doesn't have a palette look
+ for another map to change the gamma on. */
+
+ pLink = pScreenPriv->maps;
+ while(pLink) {
+ if(pLink->cmap->pVisual->class == PseudoColor)
+ break;
+ pLink = pLink->next;
+ }
+
+ if(pLink) {
+ /* need to trick CMapRefreshColors() into thinking
+ this is the currently installed map */
+ miInstalledMaps[pScreen->myNum] = pLink->cmap;
+ CMapReinstallMap(pLink->cmap);
+ miInstalledMaps[pScreen->myNum] = pMap;
+ }
+ } else
+ CMapReinstallMap(pMap);
+ }
+
+ return Success;
+}
+
+
+static void
+ComputeGammaRamp (
+ CMapScreenPtr priv,
+ unsigned short *red,
+ unsigned short *green,
+ unsigned short *blue
+){
+ int elements = priv->gammaElements;
+ LOCO *entry = priv->gamma;
+ int shift = 16 - priv->sigRGBbits;
+
+ while(elements--) {
+ entry->red = *(red++) >> shift;
+ entry->green = *(green++) >> shift;
+ entry->blue = *(blue++) >> shift;
+ entry++;
+ }
+}
+
+int
+xf86ChangeGammaRamp(
+ ScreenPtr pScreen,
+ int size,
+ unsigned short *red,
+ unsigned short *green,
+ unsigned short *blue
+){
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ CMapColormapPtr pColPriv;
+ CMapScreenPtr pScreenPriv;
+ CMapLinkPtr pLink;
+
+ if(CMapScreenIndex == -1)
+ return BadImplementation;
+
+ pScreenPriv = (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+ if(!pScreenPriv)
+ return BadImplementation;
+
+ if(pScreenPriv->gammaElements != size)
+ return BadValue;
+
+ ComputeGammaRamp(pScreenPriv, red, green, blue);
+
+ /* mark all colormaps on this screen */
+ pLink = pScreenPriv->maps;
+ while(pLink) {
+ pColPriv =
+ (CMapColormapPtr) pLink->cmap->devPrivates[CMapColormapIndex].ptr;
+ pColPriv->recalculate = TRUE;
+ pLink = pLink->next;
+ }
+
+ if(miInstalledMaps[pScreen->myNum] &&
+ ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) ||
+ pScrn->vtSema || pScreenPriv->isDGAmode)) {
+ ColormapPtr pMap = miInstalledMaps[pScreen->myNum];
+
+ if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
+ (pMap->pVisual->class == TrueColor) &&
+ CMapColormapUseMax(pMap->pVisual, pScreenPriv)) {
+
+ /* if the current map doesn't have a palette look
+ for another map to change the gamma on. */
+
+ pLink = pScreenPriv->maps;
+ while(pLink) {
+ if(pLink->cmap->pVisual->class == PseudoColor)
+ break;
+ pLink = pLink->next;
+ }
+
+ if(pLink) {
+ /* need to trick CMapRefreshColors() into thinking
+ this is the currently installed map */
+ miInstalledMaps[pScreen->myNum] = pLink->cmap;
+ CMapReinstallMap(pLink->cmap);
+ miInstalledMaps[pScreen->myNum] = pMap;
+ }
+ } else
+ CMapReinstallMap(pMap);
+ }
+
+ return Success;
+}
+
+int
+xf86GetGammaRampSize(ScreenPtr pScreen)
+{
+ CMapScreenPtr pScreenPriv;
+
+ if(CMapScreenIndex == -1) return 0;
+
+ pScreenPriv = (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+ if(!pScreenPriv) return 0;
+
+ return pScreenPriv->gammaElements;
+}
+
+int
+xf86GetGammaRamp(
+ ScreenPtr pScreen,
+ int size,
+ unsigned short *red,
+ unsigned short *green,
+ unsigned short *blue
+){
+ CMapScreenPtr pScreenPriv;
+ LOCO *entry;
+ int shift, sigbits;
+
+ if(CMapScreenIndex == -1)
+ return BadImplementation;
+
+ pScreenPriv = (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+ if(!pScreenPriv)
+ return BadImplementation;
+
+ if(size > pScreenPriv->gammaElements)
+ return BadValue;
+
+ entry = pScreenPriv->gamma;
+ sigbits = pScreenPriv->sigRGBbits;
+
+ while(size--) {
+ *red = entry->red << (16 - sigbits);
+ *green = entry->green << (16 - sigbits);
+ *blue = entry->blue << (16 - sigbits);
+ shift = sigbits;
+ while(shift < 16) {
+ *red |= *red >> shift;
+ *green |= *green >> shift;
+ *blue |= *blue >> shift;
+ shift += sigbits;
+ }
+ red++; green++; blue++;
+ entry++;
+ }
+
+ return Success;
+}
+
+int
+xf86ChangeGamma(
+ ScreenPtr pScreen,
+ Gamma gamma
+){
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+ if(pScrn->ChangeGamma)
+ return (*pScrn->ChangeGamma)(pScreen->myNum, gamma);
+
+ return Success; /* Success? */
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86cmap.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86cmap.h
new file mode 100644
index 000000000..4291b971a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86cmap.h
@@ -0,0 +1,76 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86cmap.h,v 1.9 2003/10/17 20:02:12 alanh Exp $ */
+
+/*
+ * Copyright (c) 1998-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 _XF86CMAP_H
+#define _XF86CMAP_H
+
+#include "xf86str.h"
+#include "colormapst.h"
+
+#define CMAP_PALETTED_TRUECOLOR 0x0000001
+#define CMAP_RELOAD_ON_MODE_SWITCH 0x0000002
+#define CMAP_LOAD_EVEN_IF_OFFSCREEN 0x0000004
+
+Bool xf86HandleColormaps(
+ ScreenPtr pScreen,
+ int maxCol,
+ int sigRGBbits,
+ xf86LoadPaletteProc *loadPalette,
+ xf86SetOverscanProc *setOverscan,
+ unsigned int flags
+);
+
+int
+xf86ChangeGamma(
+ ScreenPtr pScreen,
+ Gamma newGamma
+);
+
+int
+xf86ChangeGammaRamp(
+ ScreenPtr pScreen,
+ int size,
+ unsigned short *red,
+ unsigned short *green,
+ unsigned short *blue
+);
+
+int xf86GetGammaRampSize(ScreenPtr pScreen);
+
+int
+xf86GetGammaRamp(
+ ScreenPtr pScreen,
+ int size,
+ unsigned short *red,
+ unsigned short *green,
+ unsigned short *blue
+);
+
+#endif /* _XF86CMAP_H */
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86fbBus.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86fbBus.c
new file mode 100644
index 000000000..28a65302d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86fbBus.c
@@ -0,0 +1,97 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86fbBus.c,v 1.3 2003/08/24 17:36:55 dawes Exp $ */
+
+/*
+ * Copyright (c) 2000-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 interfaces to the bus-specific code
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Resources.h"
+
+#include "xf86Bus.h"
+
+#define XF86_OS_PRIVS
+#define NEED_OS_RAC_PROTOS
+#include "xf86_OSproc.h"
+
+#include "xf86RAC.h"
+
+Bool fbSlotClaimed = FALSE;
+
+int
+xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active)
+{
+ EntityPtr p;
+ int num;
+
+ num = xf86AllocateEntity();
+ p = xf86Entities[num];
+ p->driver = drvp;
+ p->chipset = 0;
+ p->busType = BUS_NONE;
+ p->active = active;
+ p->inUse = FALSE;
+ xf86AddDevToEntity(num, dev);
+ p->access = xnfcalloc(1,sizeof(EntityAccessRec));
+ p->access->fallback = &AccessNULL;
+ p->access->pAccess = &AccessNULL;
+ p->busAcc = NULL;
+
+ fbSlotClaimed = TRUE;
+ return num;
+}
+
+/*
+ * Get the list of FB "slots" claimed by a screen
+ */
+int
+xf86GetFbInfoForScreen(int scrnIndex)
+{
+ int num = 0;
+ int i;
+ EntityPtr p;
+
+ for (i = 0; i < xf86Screens[scrnIndex]->numEntities; i++) {
+ p = xf86Entities[xf86Screens[scrnIndex]->entityList[i]];
+ if (p->busType == BUS_NONE) {
+ num++;
+ }
+ }
+ return num;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86fbman.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86fbman.c
new file mode 100644
index 000000000..31c84c49f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86fbman.c
@@ -0,0 +1,1445 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86fbman.c,v 1.28 2003/11/03 05:11:03 tsi Exp $ */
+
+/*
+ * Copyright (c) 1998-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).
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "misc.h"
+#include "xf86.h"
+
+#include <X11/X.h>
+#include "scrnintstr.h"
+#include "regionstr.h"
+#include "xf86fbman.h"
+
+/*
+#define DEBUG
+*/
+
+static int xf86FBMangerIndex = -1;
+static unsigned long xf86ManagerGeneration = 0;
+
+Bool xf86RegisterOffscreenManager(
+ ScreenPtr pScreen,
+ FBManagerFuncsPtr funcs
+){
+
+ if(xf86ManagerGeneration != serverGeneration) {
+ if((xf86FBMangerIndex = AllocateScreenPrivateIndex()) < 0)
+ return FALSE;
+ xf86ManagerGeneration = serverGeneration;
+ }
+
+ pScreen->devPrivates[xf86FBMangerIndex].ptr = (pointer)funcs;
+
+ return TRUE;
+}
+
+
+Bool
+xf86FBManagerRunning(ScreenPtr pScreen)
+{
+ if(xf86FBMangerIndex < 0)
+ return FALSE;
+ if(!pScreen->devPrivates[xf86FBMangerIndex].ptr)
+ return FALSE;
+
+ return TRUE;
+}
+
+Bool
+xf86RegisterFreeBoxCallback(
+ ScreenPtr pScreen,
+ FreeBoxCallbackProcPtr FreeBoxCallback,
+ pointer devPriv
+){
+ FBManagerFuncsPtr funcs;
+
+ if(xf86FBMangerIndex < 0)
+ return FALSE;
+ if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return FALSE;
+
+ return (*funcs->RegisterFreeBoxCallback)(pScreen, FreeBoxCallback, devPriv);
+}
+
+
+FBAreaPtr
+xf86AllocateOffscreenArea(
+ ScreenPtr pScreen,
+ int w, int h,
+ int gran,
+ MoveAreaCallbackProcPtr moveCB,
+ RemoveAreaCallbackProcPtr removeCB,
+ pointer privData
+){
+ FBManagerFuncsPtr funcs;
+
+ if(xf86FBMangerIndex < 0)
+ return NULL;
+ if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return NULL;
+
+ return (*funcs->AllocateOffscreenArea)(
+ pScreen, w, h, gran, moveCB, removeCB, privData);
+}
+
+
+FBLinearPtr
+xf86AllocateOffscreenLinear(
+ ScreenPtr pScreen,
+ int length,
+ int gran,
+ MoveLinearCallbackProcPtr moveCB,
+ RemoveLinearCallbackProcPtr removeCB,
+ pointer privData
+){
+ FBManagerFuncsPtr funcs;
+
+ if(xf86FBMangerIndex < 0)
+ return NULL;
+ if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return NULL;
+
+ return (*funcs->AllocateOffscreenLinear)(
+ pScreen, length, gran, moveCB, removeCB, privData);
+}
+
+
+void
+xf86FreeOffscreenArea(FBAreaPtr area)
+{
+ FBManagerFuncsPtr funcs;
+
+ if(!area) return;
+
+ if(xf86FBMangerIndex < 0)
+ return;
+ if(!(funcs =
+ (FBManagerFuncsPtr)area->pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return;
+
+ (*funcs->FreeOffscreenArea)(area);
+
+ return;
+}
+
+
+void
+xf86FreeOffscreenLinear(FBLinearPtr linear)
+{
+ FBManagerFuncsPtr funcs;
+
+ if(!linear) return;
+
+ if(xf86FBMangerIndex < 0)
+ return;
+ if(!(funcs =
+ (FBManagerFuncsPtr)linear->pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return;
+
+ (*funcs->FreeOffscreenLinear)(linear);
+
+ return;
+}
+
+
+Bool
+xf86ResizeOffscreenArea(
+ FBAreaPtr resize,
+ int w, int h
+){
+ FBManagerFuncsPtr funcs;
+
+ if(!resize) return FALSE;
+
+ if(xf86FBMangerIndex < 0)
+ return FALSE;
+ if(!(funcs =
+ (FBManagerFuncsPtr)resize->pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return FALSE;
+
+ return (*funcs->ResizeOffscreenArea)(resize, w, h);
+}
+
+Bool
+xf86ResizeOffscreenLinear(
+ FBLinearPtr resize,
+ int size
+){
+ FBManagerFuncsPtr funcs;
+
+ if(!resize) return FALSE;
+
+ if(xf86FBMangerIndex < 0)
+ return FALSE;
+ if(!(funcs =
+ (FBManagerFuncsPtr)resize->pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return FALSE;
+
+ return (*funcs->ResizeOffscreenLinear)(resize, size);
+}
+
+
+Bool
+xf86QueryLargestOffscreenArea(
+ ScreenPtr pScreen,
+ int *w, int *h,
+ int gran,
+ int preferences,
+ int severity
+){
+ FBManagerFuncsPtr funcs;
+
+ *w = 0;
+ *h = 0;
+
+ if(xf86FBMangerIndex < 0)
+ return FALSE;
+ if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return FALSE;
+
+ return (*funcs->QueryLargestOffscreenArea)(
+ pScreen, w, h, gran, preferences, severity);
+}
+
+Bool
+xf86QueryLargestOffscreenLinear(
+ ScreenPtr pScreen,
+ int *size,
+ int gran,
+ int severity
+){
+ FBManagerFuncsPtr funcs;
+
+ *size = 0;
+
+ if(xf86FBMangerIndex < 0)
+ return FALSE;
+ if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return FALSE;
+
+ return (*funcs->QueryLargestOffscreenLinear)(
+ pScreen, size, gran, severity);
+}
+
+
+Bool
+xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
+{
+ FBManagerFuncsPtr funcs;
+
+ if(xf86FBMangerIndex < 0)
+ return FALSE;
+ if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return FALSE;
+
+ return (*funcs->PurgeOffscreenAreas)(pScreen);
+}
+
+/************************************************************\
+
+ Below is a specific implementation of an offscreen manager.
+
+\************************************************************/
+
+static unsigned long xf86FBGeneration = 0;
+static int xf86FBScreenIndex = -1;
+
+typedef struct _FBLink {
+ FBArea area;
+ struct _FBLink *next;
+} FBLink, *FBLinkPtr;
+
+typedef struct _FBLinearLink {
+ FBLinear linear;
+ int free; /* need to add free here as FBLinear is publicly accessible */
+ FBAreaPtr area; /* only used if allocation came from XY area */
+ struct _FBLinearLink *next;
+} FBLinearLink, *FBLinearLinkPtr;
+
+
+typedef struct {
+ ScreenPtr pScreen;
+ RegionPtr InitialBoxes;
+ RegionPtr FreeBoxes;
+ FBLinkPtr UsedAreas;
+ int NumUsedAreas;
+ FBLinearLinkPtr LinearAreas;
+ CloseScreenProcPtr CloseScreen;
+ int NumCallbacks;
+ FreeBoxCallbackProcPtr *FreeBoxesUpdateCallback;
+ DevUnion *devPrivates;
+} FBManager, *FBManagerPtr;
+
+
+static void
+SendCallFreeBoxCallbacks(FBManagerPtr offman)
+{
+ int i = offman->NumCallbacks;
+
+ while(i--) {
+ (*offman->FreeBoxesUpdateCallback[i])(
+ offman->pScreen, offman->FreeBoxes, offman->devPrivates[i].ptr);
+ }
+}
+
+static Bool
+localRegisterFreeBoxCallback(
+ ScreenPtr pScreen,
+ FreeBoxCallbackProcPtr FreeBoxCallback,
+ pointer devPriv
+){
+ FBManagerPtr offman;
+ FreeBoxCallbackProcPtr *newCallbacks;
+ DevUnion *newPrivates;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ newCallbacks = xrealloc( offman->FreeBoxesUpdateCallback,
+ sizeof(FreeBoxCallbackProcPtr) * (offman->NumCallbacks + 1));
+
+ newPrivates = xrealloc(offman->devPrivates,
+ sizeof(DevUnion) * (offman->NumCallbacks + 1));
+
+ if(!newCallbacks || !newPrivates)
+ return FALSE;
+
+ offman->FreeBoxesUpdateCallback = newCallbacks;
+ offman->devPrivates = newPrivates;
+
+ offman->FreeBoxesUpdateCallback[offman->NumCallbacks] = FreeBoxCallback;
+ offman->devPrivates[offman->NumCallbacks].ptr = devPriv;
+ offman->NumCallbacks++;
+
+ SendCallFreeBoxCallbacks(offman);
+
+ return TRUE;
+}
+
+
+static FBAreaPtr
+AllocateArea(
+ FBManagerPtr offman,
+ int w, int h,
+ int granularity,
+ MoveAreaCallbackProcPtr moveCB,
+ RemoveAreaCallbackProcPtr removeCB,
+ pointer privData
+){
+ ScreenPtr pScreen = offman->pScreen;
+ FBLinkPtr link = NULL;
+ FBAreaPtr area = NULL;
+ RegionRec NewReg;
+ int i, x = 0, num;
+ BoxPtr boxp;
+
+ if(granularity <= 1) granularity = 0;
+
+ boxp = REGION_RECTS(offman->FreeBoxes);
+ num = REGION_NUM_RECTS(offman->FreeBoxes);
+
+ /* look through the free boxes */
+ for(i = 0; i < num; i++, boxp++) {
+ x = boxp->x1;
+ if(granularity) {
+ int tmp = x % granularity;
+ if(tmp) x += (granularity - tmp);
+ }
+
+ if(((boxp->y2 - boxp->y1) < h) || ((boxp->x2 - x) < w))
+ continue;
+
+ link = xalloc(sizeof(FBLink));
+ if(!link) return NULL;
+
+ area = &(link->area);
+ link->next = offman->UsedAreas;
+ offman->UsedAreas = link;
+ offman->NumUsedAreas++;
+ break;
+ }
+
+ /* try to boot a removeable one out if we are not expendable ourselves */
+ if(!area && !removeCB) {
+ link = offman->UsedAreas;
+
+ while(link) {
+ if(!link->area.RemoveAreaCallback) {
+ link = link->next;
+ continue;
+ }
+
+ boxp = &(link->area.box);
+ x = boxp->x1;
+ if(granularity) {
+ int tmp = x % granularity;
+ if(tmp) x += (granularity - tmp);
+ }
+
+ if(((boxp->y2 - boxp->y1) < h) || ((boxp->x2 - x) < w)) {
+ link = link->next;
+ continue;
+ }
+
+ /* bye, bye */
+ (*link->area.RemoveAreaCallback)(&link->area);
+ REGION_INIT(pScreen, &NewReg, &(link->area.box), 1);
+ REGION_UNION(pScreen, offman->FreeBoxes, offman->FreeBoxes, &NewReg);
+ REGION_UNINIT(pScreen, &NewReg);
+
+ area = &(link->area);
+ break;
+ }
+ }
+
+ if(area) {
+ area->pScreen = pScreen;
+ area->granularity = granularity;
+ area->box.x1 = x;
+ area->box.x2 = x + w;
+ area->box.y1 = boxp->y1;
+ area->box.y2 = boxp->y1 + h;
+ area->MoveAreaCallback = moveCB;
+ area->RemoveAreaCallback = removeCB;
+ area->devPrivate.ptr = privData;
+
+ REGION_INIT(pScreen, &NewReg, &(area->box), 1);
+ REGION_SUBTRACT(pScreen, offman->FreeBoxes, offman->FreeBoxes, &NewReg);
+ REGION_UNINIT(pScreen, &NewReg);
+ }
+
+ return area;
+}
+
+static FBAreaPtr
+localAllocateOffscreenArea(
+ ScreenPtr pScreen,
+ int w, int h,
+ int gran,
+ MoveAreaCallbackProcPtr moveCB,
+ RemoveAreaCallbackProcPtr removeCB,
+ pointer privData
+){
+ FBManagerPtr offman;
+ FBAreaPtr area = NULL;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ if((area = AllocateArea(offman, w, h, gran, moveCB, removeCB, privData)))
+ SendCallFreeBoxCallbacks(offman);
+
+ return area;
+}
+
+
+static void
+localFreeOffscreenArea(FBAreaPtr area)
+{
+ FBManagerPtr offman;
+ FBLinkPtr pLink, pLinkPrev = NULL;
+ RegionRec FreedRegion;
+ ScreenPtr pScreen;
+
+ pScreen = area->pScreen;
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ pLink = offman->UsedAreas;
+ if(!pLink) return;
+
+ while(&(pLink->area) != area) {
+ pLinkPrev = pLink;
+ pLink = pLink->next;
+ if(!pLink) return;
+ }
+
+ /* put the area back into the pool */
+ REGION_INIT(pScreen, &FreedRegion, &(pLink->area.box), 1);
+ REGION_UNION(pScreen, offman->FreeBoxes, offman->FreeBoxes, &FreedRegion);
+ REGION_UNINIT(pScreen, &FreedRegion);
+
+ if(pLinkPrev)
+ pLinkPrev->next = pLink->next;
+ else offman->UsedAreas = pLink->next;
+
+ xfree(pLink);
+ offman->NumUsedAreas--;
+
+ SendCallFreeBoxCallbacks(offman);
+}
+
+
+
+static Bool
+localResizeOffscreenArea(
+ FBAreaPtr resize,
+ int w, int h
+){
+ FBManagerPtr offman;
+ ScreenPtr pScreen;
+ BoxRec OrigArea;
+ RegionRec FreedReg;
+ FBAreaPtr area = NULL;
+ FBLinkPtr pLink, newLink, pLinkPrev = NULL;
+
+ pScreen = resize->pScreen;
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ /* find this link */
+ if(!(pLink = offman->UsedAreas))
+ return FALSE;
+
+ while(&(pLink->area) != resize) {
+ pLinkPrev = pLink;
+ pLink = pLink->next;
+ if(!pLink) return FALSE;
+ }
+
+ OrigArea.x1 = resize->box.x1;
+ OrigArea.x2 = resize->box.x2;
+ OrigArea.y1 = resize->box.y1;
+ OrigArea.y2 = resize->box.y2;
+
+ /* if it's smaller, this is easy */
+
+ if((w <= (resize->box.x2 - resize->box.x1)) &&
+ (h <= (resize->box.y2 - resize->box.y1))) {
+ RegionRec NewReg;
+
+ resize->box.x2 = resize->box.x1 + w;
+ resize->box.y2 = resize->box.y1 + h;
+
+ if((resize->box.y2 == OrigArea.y2) &&
+ (resize->box.x2 == OrigArea.x2))
+ return TRUE;
+
+ REGION_INIT(pScreen, &FreedReg, &OrigArea, 1);
+ REGION_INIT(pScreen, &NewReg, &(resize->box), 1);
+ REGION_SUBTRACT(pScreen, &FreedReg, &FreedReg, &NewReg);
+ REGION_UNION(pScreen, offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
+ REGION_UNINIT(pScreen, &FreedReg);
+ REGION_UNINIT(pScreen, &NewReg);
+
+ SendCallFreeBoxCallbacks(offman);
+
+ return TRUE;
+ }
+
+
+ /* otherwise we remove the old region */
+
+ REGION_INIT(pScreen, &FreedReg, &OrigArea, 1);
+ REGION_UNION(pScreen, offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
+
+ /* remove the old link */
+ if(pLinkPrev)
+ pLinkPrev->next = pLink->next;
+ else offman->UsedAreas = pLink->next;
+
+ /* and try to add a new one */
+
+ if((area = AllocateArea(offman, w, h, resize->granularity,
+ resize->MoveAreaCallback, resize->RemoveAreaCallback,
+ resize->devPrivate.ptr))) {
+
+ /* copy data over to our link and replace the new with old */
+ memcpy(resize, area, sizeof(FBArea));
+
+ pLinkPrev = NULL;
+ newLink = offman->UsedAreas;
+
+ while(&(newLink->area) != area) {
+ pLinkPrev = newLink;
+ newLink = newLink->next;
+ }
+
+ if(pLinkPrev)
+ pLinkPrev->next = newLink->next;
+ else offman->UsedAreas = newLink->next;
+
+ pLink->next = offman->UsedAreas;
+ offman->UsedAreas = pLink;
+
+ xfree(newLink);
+
+ /* AllocateArea added one but we really only exchanged one */
+ offman->NumUsedAreas--;
+ } else {
+ /* reinstate the old region */
+ REGION_SUBTRACT(pScreen, offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
+ REGION_UNINIT(pScreen, &FreedReg);
+
+ pLink->next = offman->UsedAreas;
+ offman->UsedAreas = pLink;
+ return FALSE;
+ }
+
+
+ REGION_UNINIT(pScreen, &FreedReg);
+
+ SendCallFreeBoxCallbacks(offman);
+
+ return TRUE;
+}
+
+static Bool
+localQueryLargestOffscreenArea(
+ ScreenPtr pScreen,
+ int *width, int *height,
+ int granularity,
+ int preferences,
+ int severity
+){
+ FBManagerPtr offman;
+ RegionPtr newRegion = NULL;
+ BoxPtr pbox;
+ int nbox;
+ int x, w, h, area, oldArea;
+
+ *width = *height = oldArea = 0;
+
+ if(granularity <= 1) granularity = 0;
+
+ if((preferences < 0) || (preferences > 3))
+ return FALSE;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ if(severity < 0) severity = 0;
+ if(severity > 2) severity = 2;
+
+ switch(severity) {
+ case 2:
+ if(offman->NumUsedAreas) {
+ FBLinkPtr pLink;
+ RegionRec tmpRegion;
+ newRegion = REGION_CREATE(pScreen, NULL, 1);
+ REGION_COPY(pScreen, newRegion, offman->InitialBoxes);
+ pLink = offman->UsedAreas;
+
+ while(pLink) {
+ if(!pLink->area.RemoveAreaCallback) {
+ REGION_INIT(pScreen, &tmpRegion, &(pLink->area.box), 1);
+ REGION_SUBTRACT(pScreen, newRegion, newRegion, &tmpRegion);
+ REGION_UNINIT(pScreen, &tmpRegion);
+ }
+ pLink = pLink->next;
+ }
+
+ nbox = REGION_NUM_RECTS(newRegion);
+ pbox = REGION_RECTS(newRegion);
+ break;
+ }
+ case 1:
+ if(offman->NumUsedAreas) {
+ FBLinkPtr pLink;
+ RegionRec tmpRegion;
+ newRegion = REGION_CREATE(pScreen, NULL, 1);
+ REGION_COPY(pScreen, newRegion, offman->FreeBoxes);
+ pLink = offman->UsedAreas;
+
+ while(pLink) {
+ if(pLink->area.RemoveAreaCallback) {
+ REGION_INIT(pScreen, &tmpRegion, &(pLink->area.box), 1);
+ REGION_APPEND(pScreen, newRegion, &tmpRegion);
+ REGION_UNINIT(pScreen, &tmpRegion);
+ }
+ pLink = pLink->next;
+ }
+
+ nbox = REGION_NUM_RECTS(newRegion);
+ pbox = REGION_RECTS(newRegion);
+ break;
+ }
+ default:
+ nbox = REGION_NUM_RECTS(offman->FreeBoxes);
+ pbox = REGION_RECTS(offman->FreeBoxes);
+ break;
+ }
+
+ while(nbox--) {
+ x = pbox->x1;
+ if(granularity) {
+ int tmp = x % granularity;
+ if(tmp) x += (granularity - tmp);
+ }
+
+ w = pbox->x2 - x;
+ h = pbox->y2 - pbox->y1;
+ area = w * h;
+
+ if(w > 0) {
+ Bool gotIt = FALSE;
+ switch(preferences) {
+ case FAVOR_AREA_THEN_WIDTH:
+ if((area > oldArea) || ((area == oldArea) && (w > *width)))
+ gotIt = TRUE;
+ break;
+ case FAVOR_AREA_THEN_HEIGHT:
+ if((area > oldArea) || ((area == oldArea) && (h > *height)))
+ gotIt = TRUE;
+ break;
+ case FAVOR_WIDTH_THEN_AREA:
+ if((w > *width) || ((w == *width) && (area > oldArea)))
+ gotIt = TRUE;
+ break;
+ case FAVOR_HEIGHT_THEN_AREA:
+ if((h > *height) || ((h == *height) && (area > oldArea)))
+ gotIt = TRUE;
+ break;
+ }
+ if(gotIt) {
+ *width = w;
+ *height = h;
+ oldArea = area;
+ }
+ }
+ pbox++;
+ }
+
+ if(newRegion)
+ REGION_DESTROY(pScreen, newRegion);
+
+ return TRUE;
+}
+
+static Bool
+localPurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
+{
+ FBManagerPtr offman;
+ FBLinkPtr pLink, tmp, pPrev = NULL;
+ RegionRec FreedRegion;
+ Bool anyUsed = FALSE;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ pLink = offman->UsedAreas;
+ if(!pLink) return TRUE;
+
+ while(pLink) {
+ if(pLink->area.RemoveAreaCallback) {
+ (*pLink->area.RemoveAreaCallback)(&pLink->area);
+
+ REGION_INIT(pScreen, &FreedRegion, &(pLink->area.box), 1);
+ REGION_APPEND(pScreen, offman->FreeBoxes, &FreedRegion);
+ REGION_UNINIT(pScreen, &FreedRegion);
+
+ if(pPrev)
+ pPrev->next = pLink->next;
+ else offman->UsedAreas = pLink->next;
+
+ tmp = pLink;
+ pLink = pLink->next;
+ xfree(tmp);
+ offman->NumUsedAreas--;
+ anyUsed = TRUE;
+ } else {
+ pPrev = pLink;
+ pLink = pLink->next;
+ }
+ }
+
+ if(anyUsed) {
+ REGION_VALIDATE(pScreen, offman->FreeBoxes, &anyUsed);
+ SendCallFreeBoxCallbacks(offman);
+ }
+
+ return TRUE;
+}
+
+static void
+LinearMoveCBWrapper(FBAreaPtr from, FBAreaPtr to)
+{
+ /* this will never get called */
+}
+
+static void
+LinearRemoveCBWrapper(FBAreaPtr area)
+{
+ FBManagerPtr offman;
+ FBLinearLinkPtr pLink, pLinkPrev = NULL;
+ ScreenPtr pScreen = area->pScreen;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ pLink = offman->LinearAreas;
+ if(!pLink) return;
+
+ while(pLink->area != area) {
+ pLinkPrev = pLink;
+ pLink = pLink->next;
+ if(!pLink) return;
+ }
+
+ /* give the user the callback it is expecting */
+ (*pLink->linear.RemoveLinearCallback)(&(pLink->linear));
+
+ if(pLinkPrev)
+ pLinkPrev->next = pLink->next;
+ else offman->LinearAreas = pLink->next;
+
+ xfree(pLink);
+}
+
+#ifdef DEBUG
+static void
+Dump(FBLinearLinkPtr pLink)
+{
+ if (!pLink) ErrorF("MMmm, PLINK IS NULL!\n");
+
+ while (pLink) {
+ ErrorF(" Offset:%08x, Size:%08x, %s,%s\n",
+ pLink->linear.offset,
+ pLink->linear.size,
+ pLink->free ? "Free" : "Used",
+ pLink->area ? "Area" : "Linear");
+
+ pLink = pLink->next;
+ }
+}
+#endif
+
+static FBLinearPtr
+AllocateLinear(
+ FBManagerPtr offman,
+ int size,
+ int granularity,
+ pointer privData
+){
+ ScreenPtr pScreen = offman->pScreen;
+ FBLinearLinkPtr linear = NULL;
+ FBLinearLinkPtr newlink = NULL;
+ int offset, end;
+
+ if(size <= 0) return NULL;
+
+ if (!offman->LinearAreas) return NULL;
+
+ linear = offman->LinearAreas;
+ while (linear) {
+ /* Make sure we get a free area that's not an XY fallback case */
+ if (!linear->area && linear->free) {
+ offset = (linear->linear.offset + granularity) & ~granularity;
+ end = offset+size;
+ if (end <= (linear->linear.offset + linear->linear.size))
+ break;
+ }
+ linear = linear->next;
+ }
+ if (!linear)
+ return NULL;
+
+ /* break left */
+ if (offset > linear->linear.offset) {
+ newlink = xalloc(sizeof(FBLinearLink));
+ if (!newlink)
+ return NULL;
+ newlink->area = NULL;
+ newlink->linear.offset = offset;
+ newlink->linear.size = linear->linear.size - (offset - linear->linear.offset);
+ newlink->free = 1;
+ newlink->next = linear->next;
+ linear->linear.size -= newlink->linear.size;
+ linear->next = newlink;
+ linear = newlink;
+ }
+
+ /* break right */
+ if (size < linear->linear.size) {
+ newlink = xalloc(sizeof(FBLinearLink));
+ if (!newlink)
+ return NULL;
+ newlink->area = NULL;
+ newlink->linear.offset = offset + size;
+ newlink->linear.size = linear->linear.size - size;
+ newlink->free = 1;
+ newlink->next = linear->next;
+ linear->linear.size = size;
+ linear->next = newlink;
+ }
+
+ /* p = middle block */
+ linear->linear.granularity = granularity;
+ linear->free = 0;
+ linear->linear.pScreen = pScreen;
+ linear->linear.MoveLinearCallback = NULL;
+ linear->linear.RemoveLinearCallback = NULL;
+ linear->linear.devPrivate.ptr = NULL;
+
+#ifdef DEBUG
+ Dump(offman->LinearAreas);
+#endif
+
+ return &(linear->linear);
+}
+
+static FBLinearPtr
+localAllocateOffscreenLinear(
+ ScreenPtr pScreen,
+ int length,
+ int gran,
+ MoveLinearCallbackProcPtr moveCB,
+ RemoveLinearCallbackProcPtr removeCB,
+ pointer privData
+){
+ FBManagerPtr offman;
+ FBLinearLinkPtr link;
+ FBAreaPtr area;
+ FBLinearPtr linear = NULL;
+ BoxPtr extents;
+ int w, h, pitch;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ /* Try to allocate from linear memory first...... */
+#ifdef DEBUG
+ ErrorF("ALLOCATING LINEAR\n");
+#endif
+ if ((linear = AllocateLinear(offman, length, gran, privData)))
+ return linear;
+
+#ifdef DEBUG
+ ErrorF("NOPE, ALLOCATING AREA\n");
+#endif
+
+ if(!(link = xalloc(sizeof(FBLinearLink))))
+ return NULL;
+
+ /* No linear available, so try and pinch some from the XY areas */
+ extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
+ pitch = extents->x2 - extents->x1;
+
+ if(gran && ((gran > pitch) || (pitch % gran))) {
+ /* we can't match the specified alignment with XY allocations */
+ xfree(link);
+ return NULL;
+ }
+
+ if(length < pitch) { /* special case */
+ w = length;
+ h = 1;
+ } else {
+ w = pitch;
+ h = (length + pitch - 1) / pitch;
+ }
+
+ if((area = localAllocateOffscreenArea(pScreen, w, h, gran,
+ moveCB ? LinearMoveCBWrapper : NULL,
+ removeCB ? LinearRemoveCBWrapper : NULL,
+ privData)))
+ {
+ link->area = area;
+ link->free = 0;
+ link->next = offman->LinearAreas;
+ offman->LinearAreas = link;
+ linear = &(link->linear);
+ linear->pScreen = pScreen;
+ linear->size = h * w;
+ linear->offset = (pitch * area->box.y1) + area->box.x1;
+ linear->granularity = gran;
+ linear->MoveLinearCallback = moveCB;
+ linear->RemoveLinearCallback = removeCB;
+ linear->devPrivate.ptr = privData;
+ } else
+ xfree(link);
+
+#ifdef DEBUG
+ Dump(offman->LinearAreas);
+#endif
+
+ return linear;
+}
+
+
+static void
+localFreeOffscreenLinear(FBLinearPtr linear)
+{
+ FBManagerPtr offman;
+ FBLinearLinkPtr pLink, pLinkPrev = NULL;
+ ScreenPtr pScreen = linear->pScreen;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ pLink = offman->LinearAreas;
+ if(!pLink) return;
+
+ while(&(pLink->linear) != linear) {
+ pLinkPrev = pLink;
+ pLink = pLink->next;
+ if(!pLink) return;
+ }
+
+ if(pLink->area) { /* really an XY area */
+#ifdef DEBUG
+ ErrorF("FREEING AREA\n");
+#endif
+ localFreeOffscreenArea(pLink->area);
+ if(pLinkPrev)
+ pLinkPrev->next = pLink->next;
+ else offman->LinearAreas = pLink->next;
+ xfree(pLink);
+#ifdef DEBUG
+ Dump(offman->LinearAreas);
+#endif
+ return;
+ }
+
+ pLink->free = 1;
+
+ if (pLink->next && pLink->next->free) {
+ FBLinearLinkPtr p = pLink->next;
+ pLink->linear.size += p->linear.size;
+ pLink->next = p->next;
+ free(p);
+ }
+
+ if(pLinkPrev) {
+ if (pLinkPrev->next && pLinkPrev->next->free && !pLinkPrev->area) {
+ FBLinearLinkPtr p = pLinkPrev->next;
+ pLinkPrev->linear.size += p->linear.size;
+ pLinkPrev->next = p->next;
+ free(p);
+ }
+ }
+
+#ifdef DEBUG
+ ErrorF("FREEING LINEAR\n");
+ Dump(offman->LinearAreas);
+#endif
+}
+
+
+static Bool
+localResizeOffscreenLinear(FBLinearPtr resize, int length)
+{
+ FBManagerPtr offman;
+ FBLinearLinkPtr pLink;
+ ScreenPtr pScreen = resize->pScreen;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ pLink = offman->LinearAreas;
+ if(!pLink) return FALSE;
+
+ while(&(pLink->linear) != resize) {
+ pLink = pLink->next;
+ if(!pLink) return FALSE;
+ }
+
+ /* This could actually be alot smarter and try to move allocations
+ from XY to linear when available. For now if it was XY, we keep
+ it XY */
+
+ if(pLink->area) { /* really an XY area */
+ BoxPtr extents;
+ int pitch, w, h;
+
+ extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
+ pitch = extents->x2 - extents->x1;
+
+ if(length < pitch) { /* special case */
+ w = length;
+ h = 1;
+ } else {
+ w = pitch;
+ h = (length + pitch - 1) / pitch;
+ }
+
+ if(localResizeOffscreenArea(pLink->area, w, h)) {
+ resize->size = h * w;
+ resize->offset = (pitch * pLink->area->box.y1) + pLink->area->box.x1;
+ return TRUE;
+ }
+ } else {
+ /* TODO!!!! resize the linear area */
+ }
+
+ return FALSE;
+}
+
+
+static Bool
+localQueryLargestOffscreenLinear(
+ ScreenPtr pScreen,
+ int *size,
+ int gran,
+ int priority
+)
+{
+ FBManagerPtr offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+ FBLinearLinkPtr pLink;
+ FBLinearLinkPtr pLinkRet;
+
+ *size = 0;
+
+ pLink = offman->LinearAreas;
+
+ if (pLink && !pLink->area) {
+ pLinkRet = pLink;
+ while (pLink) {
+ if (pLink->free) {
+ if (pLink->linear.size > pLinkRet->linear.size)
+ pLinkRet = pLink;
+ }
+ pLink = pLink->next;
+ }
+
+ if (pLinkRet->free) {
+ *size = pLinkRet->linear.size;
+ return TRUE;
+ }
+ } else {
+ int w, h;
+
+ if(localQueryLargestOffscreenArea(pScreen, &w, &h, gran,
+ FAVOR_WIDTH_THEN_AREA, priority))
+ {
+ FBManagerPtr offman;
+ BoxPtr extents;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+ extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
+ if((extents->x2 - extents->x1) == w)
+ *size = w * h;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+
+
+static FBManagerFuncs xf86FBManFuncs = {
+ localAllocateOffscreenArea,
+ localFreeOffscreenArea,
+ localResizeOffscreenArea,
+ localQueryLargestOffscreenArea,
+ localRegisterFreeBoxCallback,
+ localAllocateOffscreenLinear,
+ localFreeOffscreenLinear,
+ localResizeOffscreenLinear,
+ localQueryLargestOffscreenLinear,
+ localPurgeUnlockedOffscreenAreas
+ };
+
+
+static Bool
+xf86FBCloseScreen (int i, ScreenPtr pScreen)
+{
+ FBLinkPtr pLink, tmp;
+ FBLinearLinkPtr pLinearLink, tmp2;
+ FBManagerPtr offman =
+ (FBManagerPtr) pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+
+ pScreen->CloseScreen = offman->CloseScreen;
+
+ pLink = offman->UsedAreas;
+ while(pLink) {
+ tmp = pLink;
+ pLink = pLink->next;
+ xfree(tmp);
+ }
+
+ pLinearLink = offman->LinearAreas;
+ while(pLinearLink) {
+ tmp2 = pLinearLink;
+ pLinearLink = pLinearLink->next;
+ xfree(tmp2);
+ }
+
+ REGION_DESTROY(pScreen, offman->InitialBoxes);
+ REGION_DESTROY(pScreen, offman->FreeBoxes);
+
+ xfree(offman->FreeBoxesUpdateCallback);
+ xfree(offman->devPrivates);
+ xfree(offman);
+ pScreen->devPrivates[xf86FBScreenIndex].ptr = NULL;
+
+ return (*pScreen->CloseScreen) (i, pScreen);
+}
+
+Bool
+xf86InitFBManager(
+ ScreenPtr pScreen,
+ BoxPtr FullBox
+){
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ RegionRec ScreenRegion;
+ RegionRec FullRegion;
+ BoxRec ScreenBox;
+ Bool ret;
+
+ ScreenBox.x1 = 0;
+ ScreenBox.y1 = 0;
+ ScreenBox.x2 = pScrn->virtualX;
+ ScreenBox.y2 = pScrn->virtualY;
+
+ if((FullBox->x1 > ScreenBox.x1) || (FullBox->y1 > ScreenBox.y1) ||
+ (FullBox->x2 < ScreenBox.x2) || (FullBox->y2 < ScreenBox.y2)) {
+ return FALSE;
+ }
+
+ if (FullBox->y2 < FullBox->y1) return FALSE;
+ if (FullBox->x2 < FullBox->x2) return FALSE;
+
+ REGION_INIT(pScreen, &ScreenRegion, &ScreenBox, 1);
+ REGION_INIT(pScreen, &FullRegion, FullBox, 1);
+
+ REGION_SUBTRACT(pScreen, &FullRegion, &FullRegion, &ScreenRegion);
+
+ ret = xf86InitFBManagerRegion(pScreen, &FullRegion);
+
+ REGION_UNINIT(pScreen, &ScreenRegion);
+ REGION_UNINIT(pScreen, &FullRegion);
+
+ return ret;
+}
+
+Bool
+xf86InitFBManagerArea(
+ ScreenPtr pScreen,
+ int PixelArea,
+ int Verbosity
+)
+{
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ xRectangle Rect[3];
+ RegionPtr pRegion, pScreenRegion;
+ int nRect;
+ Bool ret = FALSE;
+
+ if (PixelArea < (pScrn->displayWidth * pScrn->virtualY))
+ return FALSE;
+
+ Rect[0].x = Rect[0].y = 0;
+ Rect[0].width = pScrn->displayWidth;
+ Rect[0].height = PixelArea / pScrn->displayWidth;
+ nRect = 1;
+
+ /* Add a possible partial scanline */
+ if ((Rect[1].height = Rect[1].width = PixelArea % pScrn->displayWidth)) {
+ Rect[1].x = 0;
+ Rect[1].y = Rect[0].height;
+ Rect[1].height = 1;
+ nRect++;
+ }
+
+ /* Factor out virtual resolution */
+ pRegion = RECTS_TO_REGION(pScreen, nRect, Rect, 0);
+ if (pRegion) {
+ if (!REGION_NAR(pRegion)) {
+ Rect[2].x = Rect[2].y = 0;
+ Rect[2].width = pScrn->virtualX;
+ Rect[2].height = pScrn->virtualY;
+
+ pScreenRegion = RECTS_TO_REGION(pScreen, 1, &Rect[2], 0);
+ if (pScreenRegion) {
+ if (!REGION_NAR(pScreenRegion)) {
+ REGION_SUBTRACT(pScreen, pRegion, pRegion, pScreenRegion);
+
+ ret = xf86InitFBManagerRegion(pScreen, pRegion);
+
+ if (ret && xf86GetVerbosity() >= Verbosity) {
+ int scrnIndex = pScrn->scrnIndex;
+
+ xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
+ "Largest offscreen areas (with overlaps):\n");
+
+ if (Rect[2].width < Rect[0].width) {
+ xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
+ "\t%d x %d rectangle at %d,0\n",
+ Rect[0].width - Rect[2].width,
+ Rect[0].height,
+ Rect[2].width);
+ }
+ if (Rect[2].width < Rect[1].width) {
+ xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
+ "\t%d x %d rectangle at %d,0\n",
+ Rect[1].width - Rect[2].width,
+ Rect[0].height + Rect[1].height,
+ Rect[2].width);
+ }
+ if (Rect[2].height < Rect[0].height) {
+ xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
+ "\t%d x %d rectangle at 0,%d\n",
+ Rect[0].width,
+ Rect[0].height - Rect[2].height,
+ Rect[2].height);
+ }
+ if (Rect[1].height) {
+ xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity,
+ "\t%d x %d rectangle at 0,%d\n",
+ Rect[1].width,
+ Rect[0].height - Rect[2].height +
+ Rect[1].height,
+ Rect[2].height);
+ }
+ }
+ }
+
+ REGION_DESTROY(pScreen, pScreenRegion);
+ }
+ }
+
+ REGION_DESTROY(pScreen, pRegion);
+ }
+
+ return ret;
+}
+
+Bool
+xf86InitFBManagerRegion(
+ ScreenPtr pScreen,
+ RegionPtr FullRegion
+){
+ FBManagerPtr offman;
+
+ if(REGION_NIL(FullRegion))
+ return FALSE;
+
+ if(xf86FBGeneration != serverGeneration) {
+ if((xf86FBScreenIndex = AllocateScreenPrivateIndex()) < 0)
+ return FALSE;
+ xf86FBGeneration = serverGeneration;
+ }
+
+ if(!xf86RegisterOffscreenManager(pScreen, &xf86FBManFuncs))
+ return FALSE;
+
+ offman = xalloc(sizeof(FBManager));
+ if(!offman) return FALSE;
+
+ pScreen->devPrivates[xf86FBScreenIndex].ptr = (pointer)offman;
+
+ offman->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = xf86FBCloseScreen;
+
+ offman->InitialBoxes = REGION_CREATE(pScreen, NULL, 1);
+ offman->FreeBoxes = REGION_CREATE(pScreen, NULL, 1);
+
+ REGION_COPY(pScreen, offman->InitialBoxes, FullRegion);
+ REGION_COPY(pScreen, offman->FreeBoxes, FullRegion);
+
+ offman->pScreen = pScreen;
+ offman->UsedAreas = NULL;
+ offman->LinearAreas = NULL;
+ offman->NumUsedAreas = 0;
+ offman->NumCallbacks = 0;
+ offman->FreeBoxesUpdateCallback = NULL;
+ offman->devPrivates = NULL;
+
+ return TRUE;
+}
+
+Bool
+xf86InitFBManagerLinear(
+ ScreenPtr pScreen,
+ int offset,
+ int size
+){
+ FBManagerPtr offman;
+ FBLinearLinkPtr link;
+ FBLinearPtr linear;
+
+ if (size <= 0)
+ return FALSE;
+
+ /* we expect people to have called the Area setup first for pixmap cache */
+ if (!pScreen->devPrivates[xf86FBScreenIndex].ptr)
+ return FALSE;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ offman->LinearAreas = xalloc(sizeof(FBLinearLink));
+ if (!offman->LinearAreas)
+ return FALSE;
+
+ link = offman->LinearAreas;
+ link->area = NULL;
+ link->next = NULL;
+ link->free = 1;
+ linear = &(link->linear);
+ linear->pScreen = pScreen;
+ linear->size = size;
+ linear->offset = offset;
+ linear->granularity = 0;
+ linear->MoveLinearCallback = NULL;
+ linear->RemoveLinearCallback = NULL;
+ linear->devPrivate.ptr = NULL;
+
+ return TRUE;
+}
+
+
+/* This is an implementation specific function and should
+ disappear after the next release. People should use the
+ real linear functions instead */
+
+FBAreaPtr
+xf86AllocateLinearOffscreenArea (
+ ScreenPtr pScreen,
+ int length,
+ int gran,
+ MoveAreaCallbackProcPtr moveCB,
+ RemoveAreaCallbackProcPtr removeCB,
+ pointer privData
+){
+ FBManagerFuncsPtr funcs;
+ FBManagerPtr offman;
+ BoxPtr extents;
+ int w, h;
+
+ if(xf86FBMangerIndex < 0)
+ return NULL;
+ if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+ return NULL;
+
+ offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+
+ extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
+ w = extents->x2 - extents->x1;
+
+ if(gran && ((gran > w) || (w % gran))) {
+ /* we can't match the specified alignment with XY allocations */
+ return NULL;
+ }
+
+ if(length <= w) { /* special case */
+ h = 1;
+ w = length;
+ } else {
+ h = (length + w - 1) / w;
+ }
+
+ return (*funcs->AllocateOffscreenArea)(
+ pScreen, w, h, gran, moveCB, removeCB, privData);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86fbman.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86fbman.h
new file mode 100644
index 000000000..adb26a1f1
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86fbman.h
@@ -0,0 +1,227 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86fbman.h,v 1.14 2003/10/09 12:40:54 alanh Exp $ */
+
+/*
+ * Copyright (c) 1998-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 _XF86FBMAN_H
+#define _XF86FBMAN_H
+
+
+#include "scrnintstr.h"
+#include "regionstr.h"
+
+
+#define FAVOR_AREA_THEN_WIDTH 0
+#define FAVOR_AREA_THEN_HEIGHT 1
+#define FAVOR_WIDTH_THEN_AREA 2
+#define FAVOR_HEIGHT_THEN_AREA 3
+
+#define PRIORITY_LOW 0
+#define PRIORITY_NORMAL 1
+#define PRIORITY_EXTREME 2
+
+
+typedef struct _FBArea {
+ ScreenPtr pScreen;
+ BoxRec box;
+ int granularity;
+ void (*MoveAreaCallback)(struct _FBArea*, struct _FBArea*);
+ void (*RemoveAreaCallback)(struct _FBArea*);
+ DevUnion devPrivate;
+} FBArea, *FBAreaPtr;
+
+typedef struct _FBLinear {
+ ScreenPtr pScreen;
+ int size;
+ int offset;
+ int granularity;
+ void (*MoveLinearCallback)(struct _FBLinear*, struct _FBLinear*);
+ void (*RemoveLinearCallback)(struct _FBLinear*);
+ DevUnion devPrivate;
+} FBLinear, *FBLinearPtr;
+
+typedef void (*FreeBoxCallbackProcPtr)(ScreenPtr, RegionPtr, pointer);
+typedef void (*MoveAreaCallbackProcPtr)(FBAreaPtr, FBAreaPtr);
+typedef void (*RemoveAreaCallbackProcPtr)(FBAreaPtr);
+
+typedef void (*MoveLinearCallbackProcPtr)(FBLinearPtr, FBLinearPtr);
+typedef void (*RemoveLinearCallbackProcPtr)(FBLinearPtr);
+
+
+typedef struct {
+ FBAreaPtr (*AllocateOffscreenArea)(
+ ScreenPtr pScreen,
+ int w, int h,
+ int granularity,
+ MoveAreaCallbackProcPtr moveCB,
+ RemoveAreaCallbackProcPtr removeCB,
+ pointer privData);
+ void (*FreeOffscreenArea)(FBAreaPtr area);
+ Bool (*ResizeOffscreenArea)(FBAreaPtr area, int w, int h);
+ Bool (*QueryLargestOffscreenArea)(
+ ScreenPtr pScreen,
+ int *width, int *height,
+ int granularity,
+ int preferences,
+ int priority);
+ Bool (*RegisterFreeBoxCallback)(
+ ScreenPtr pScreen,
+ FreeBoxCallbackProcPtr FreeBoxCallback,
+ pointer devPriv);
+/* linear functions */
+ FBLinearPtr (*AllocateOffscreenLinear)(
+ ScreenPtr pScreen,
+ int size,
+ int granularity,
+ MoveLinearCallbackProcPtr moveCB,
+ RemoveLinearCallbackProcPtr removeCB,
+ pointer privData);
+ void (*FreeOffscreenLinear)(FBLinearPtr area);
+ Bool (*ResizeOffscreenLinear)(FBLinearPtr area, int size);
+ Bool (*QueryLargestOffscreenLinear)(
+ ScreenPtr pScreen,
+ int *size,
+ int granularity,
+ int priority);
+ Bool (*PurgeOffscreenAreas) (ScreenPtr);
+} FBManagerFuncs, *FBManagerFuncsPtr;
+
+
+Bool xf86RegisterOffscreenManager(
+ ScreenPtr pScreen,
+ FBManagerFuncsPtr funcs
+);
+
+Bool
+xf86InitFBManagerRegion(
+ ScreenPtr pScreen,
+ RegionPtr ScreenRegion
+);
+
+Bool
+xf86InitFBManagerArea(
+ ScreenPtr pScreen,
+ int PixalArea,
+ int Verbosity
+);
+
+Bool
+xf86InitFBManager(
+ ScreenPtr pScreen,
+ BoxPtr FullBox
+);
+
+Bool
+xf86InitFBManagerLinear(
+ ScreenPtr pScreen,
+ int offset,
+ int size
+);
+
+Bool
+xf86FBManagerRunning(
+ ScreenPtr pScreen
+);
+
+FBAreaPtr
+xf86AllocateOffscreenArea (
+ ScreenPtr pScreen,
+ int w, int h,
+ int granularity,
+ MoveAreaCallbackProcPtr moveCB,
+ RemoveAreaCallbackProcPtr removeCB,
+ pointer privData
+);
+
+FBAreaPtr
+xf86AllocateLinearOffscreenArea (
+ ScreenPtr pScreen,
+ int length,
+ int granularity,
+ MoveAreaCallbackProcPtr moveCB,
+ RemoveAreaCallbackProcPtr removeCB,
+ pointer privData
+);
+
+FBLinearPtr
+xf86AllocateOffscreenLinear (
+ ScreenPtr pScreen,
+ int length,
+ int granularity,
+ MoveLinearCallbackProcPtr moveCB,
+ RemoveLinearCallbackProcPtr removeCB,
+ pointer privData
+);
+
+void xf86FreeOffscreenArea(FBAreaPtr area);
+void xf86FreeOffscreenLinear(FBLinearPtr area);
+
+Bool
+xf86ResizeOffscreenArea(
+ FBAreaPtr resize,
+ int w, int h
+);
+
+Bool
+xf86ResizeOffscreenLinear(
+ FBLinearPtr resize,
+ int size
+);
+
+
+Bool
+xf86RegisterFreeBoxCallback(
+ ScreenPtr pScreen,
+ FreeBoxCallbackProcPtr FreeBoxCallback,
+ pointer devPriv
+);
+
+Bool
+xf86PurgeUnlockedOffscreenAreas(
+ ScreenPtr pScreen
+);
+
+
+Bool
+xf86QueryLargestOffscreenArea(
+ ScreenPtr pScreen,
+ int *width, int *height,
+ int granularity,
+ int preferences,
+ int priority
+);
+
+Bool
+xf86QueryLargestOffscreenLinear(
+ ScreenPtr pScreen,
+ int *size,
+ int granularity,
+ int priority
+);
+
+
+#endif /* _XF86FBMAN_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86isaBus.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86isaBus.c
new file mode 100644
index 000000000..2cad85de8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86isaBus.c
@@ -0,0 +1,142 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86isaBus.c,v 3.6 2003/08/24 17:36:55 dawes Exp $ */
+/*
+ * Copyright (c) 1997-2000 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 interfaces to the bus-specific code
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Resources.h"
+
+#include "xf86Bus.h"
+
+#define XF86_OS_PRIVS
+#define NEED_OS_RAC_PROTOS
+#include "xf86_OSproc.h"
+
+#include "xf86RAC.h"
+
+Bool isaSlotClaimed = FALSE;
+
+/*
+ * If the slot requested is already in use, return FALSE.
+ * Otherwise, claim the slot for the screen requesting it.
+ */
+
+int
+xf86ClaimIsaSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active)
+{
+ EntityPtr p;
+ BusAccPtr pbap = xf86BusAccInfo;
+ int num;
+
+ num = xf86AllocateEntity();
+ p = xf86Entities[num];
+ p->driver = drvp;
+ p->chipset = chipset;
+ p->busType = BUS_ISA;
+ p->active = active;
+ p->inUse = FALSE;
+ xf86AddDevToEntity(num, dev);
+ p->access = xnfcalloc(1,sizeof(EntityAccessRec));
+ p->access->fallback = &AccessNULL;
+ p->access->pAccess = &AccessNULL;
+ p->busAcc = NULL;
+ while (pbap) {
+ if (pbap->type == BUS_ISA)
+ p->busAcc = pbap;
+ pbap = pbap->next;
+ }
+ isaSlotClaimed = TRUE;
+ return num;
+}
+
+/*
+ * Get the list of ISA "slots" claimed by a screen
+ *
+ * Note: The ISA implementation here assumes that only one ISA "slot" type
+ * can be claimed by any one screen. That means a return value other than
+ * 0 or 1 isn't useful.
+ */
+int
+xf86GetIsaInfoForScreen(int scrnIndex)
+{
+ int num = 0;
+ int i;
+ EntityPtr p;
+
+ for (i = 0; i < xf86Screens[scrnIndex]->numEntities; i++) {
+ p = xf86Entities[xf86Screens[scrnIndex]->entityList[i]];
+ if (p->busType == BUS_ISA) {
+ num++;
+ }
+ }
+ return num;
+}
+
+/*
+ * Parse a BUS ID string, and return True if it is a ISA bus id.
+ */
+
+Bool
+xf86ParseIsaBusString(const char *busID)
+{
+ /*
+ * The format assumed to be "isa" or "isa:"
+ */
+ return (StringToBusType(busID,NULL) == BUS_ISA);
+}
+
+
+/*
+ * xf86IsPrimaryIsa() -- return TRUE if primary device
+ * is ISA.
+ */
+
+Bool
+xf86IsPrimaryIsa(void)
+{
+ return ( primaryBus.type == BUS_ISA );
+}
+
+void
+isaConvertRange2Host(resRange *pRange)
+{
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86noBus.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86noBus.c
new file mode 100644
index 000000000..09f2f4407
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86noBus.c
@@ -0,0 +1,75 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86noBus.c,v 1.2 2003/08/24 17:36:55 dawes Exp $ */
+
+/*
+ * Copyright (c) 2000-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).
+ */
+
+/*
+ * This file contains the interfaces to the bus-specific code
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Resources.h"
+
+#include "xf86Bus.h"
+
+#define XF86_OS_PRIVS
+#define NEED_OS_RAC_PROTOS
+#include "xf86_OSproc.h"
+
+#include "xf86RAC.h"
+
+int
+xf86ClaimNoSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active)
+{
+ EntityPtr p;
+ int num;
+
+ num = xf86AllocateEntity();
+ p = xf86Entities[num];
+ p->driver = drvp;
+ p->chipset = 0;
+ p->busType = BUS_NONE;
+ p->active = active;
+ p->inUse = FALSE;
+ xf86AddDevToEntity(num, dev);
+ p->access = xnfcalloc(1,sizeof(EntityAccessRec));
+ p->access->fallback = &AccessNULL;
+ p->access->pAccess = &AccessNULL;
+ p->busAcc = NULL;
+
+ return num;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86pciBus.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86pciBus.c
new file mode 100644
index 000000000..8fa199872
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86pciBus.c
@@ -0,0 +1,3506 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86pciBus.c,v 3.77 2003/11/03 05:11:03 tsi Exp $ */
+/*
+ * 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 interfaces to the bus-specific code
+ */
+#define INCLUDE_DEPRECATED 1
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <X11/X.h>
+#include "os.h"
+#include "Pci.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Resources.h"
+
+/* Bus-specific headers */
+#include "xf86PciData.h"
+
+#include "xf86Bus.h"
+
+#define XF86_OS_PRIVS
+#define NEED_OS_RAC_PROTOS
+#include "xf86_OSproc.h"
+
+#include "xf86RAC.h"
+
+/* Bus-specific globals */
+Bool pciSlotClaimed = FALSE;
+pciConfigPtr *xf86PciInfo = NULL; /* Full PCI probe info */
+pciVideoPtr *xf86PciVideoInfo = NULL; /* PCI probe for video hw */
+pciAccPtr * xf86PciAccInfo = NULL; /* PCI access related */
+
+/* pcidata globals */
+ScanPciSetupProcPtr xf86SetupPciIds = NULL;
+ScanPciCloseProcPtr xf86ClosePciIds = NULL;
+ScanPciFindByDeviceProcPtr xf86FindPciNamesByDevice = NULL;
+ScanPciFindBySubsysProcPtr xf86FindPciNamesBySubsys = NULL;
+ScanPciFindClassBySubsysProcPtr xf86FindPciClassBySubsys = NULL;
+ScanPciFindClassByDeviceProcPtr xf86FindPciClassByDevice = NULL;
+
+static resPtr pciAvoidRes = NULL;
+
+/* PCI buses */
+static PciBusPtr xf86PciBus = NULL;
+/* Bus-specific probe/sorting functions */
+
+/* PCI classes that get included in xf86PciVideoInfo */
+#define PCIINFOCLASSES(b,s) \
+ (((b) == PCI_CLASS_PREHISTORIC) || \
+ ((b) == PCI_CLASS_DISPLAY) || \
+ ((b) == PCI_CLASS_MULTIMEDIA && (s) == PCI_SUBCLASS_MULTIMEDIA_VIDEO) || \
+ ((b) == PCI_CLASS_PROCESSOR && (s) == PCI_SUBCLASS_PROCESSOR_COPROC))
+
+/*
+ * PCI classes that have messages printed always. The others are only
+ * have a message printed when the vendor/dev IDs are recognised.
+ */
+#define PCIALWAYSPRINTCLASSES(b,s) \
+ (((b) == PCI_CLASS_PREHISTORIC && (s) == PCI_SUBCLASS_PREHISTORIC_VGA) || \
+ ((b) == PCI_CLASS_DISPLAY) || \
+ ((b) == PCI_CLASS_MULTIMEDIA && (s) == PCI_SUBCLASS_MULTIMEDIA_VIDEO))
+
+/*
+ * PCI classes for which potentially destructive checking of the map sizes
+ * may be done. Any classes where this may be unsafe should be omitted
+ * from this list.
+ */
+#define PCINONSYSTEMCLASSES(b,s) PCIALWAYSPRINTCLASSES(b,s)
+
+/*
+ * PCI classes that use RAC
+ */
+#define PCISHAREDIOCLASSES(b,s) \
+ (((b) == PCI_CLASS_PREHISTORIC && (s) == PCI_SUBCLASS_PREHISTORIC_VGA) || \
+ ((b) == PCI_CLASS_DISPLAY && (s) == PCI_SUBCLASS_DISPLAY_VGA))
+
+#define PCI_MEM32_LENGTH_MAX 0xFFFFFFFF
+
+#define B2M(tag,base) pciBusAddrToHostAddr(tag,PCI_MEM,base)
+#define B2I(tag,base) pciBusAddrToHostAddr(tag,PCI_IO,base)
+#define B2H(tag,base,type) (((type & ResPhysMask) == ResMem) ? \
+ B2M(tag, base) : B2I(tag, base))
+#define M2B(tag,base) pciHostAddrToBusAddr(tag,PCI_MEM,base)
+#define I2B(tag,base) pciHostAddrToBusAddr(tag,PCI_IO,base)
+#define H2B(tag,base,type) (((type & ResPhysMask) == ResMem) ? \
+ M2B(tag, base) : I2B(tag, base))
+#define TAG(pvp) (pciTag(pvp->bus,pvp->device,pvp->func))
+#define SIZE(size) ((1 << size) - 1)
+#define PCI_SIZE(type,tag,size) (((type & ResPhysMask) == ResMem) \
+ ? pciBusAddrToHostAddr(tag,PCI_MEM_SIZE,size) \
+ : pciBusAddrToHostAddr(tag,PCI_IO_SIZE,size))
+#define PCI_M_RANGE(range,tag,begin,end,type) \
+ { \
+ RANGE(range, B2M(tag, begin), B2M(tag, end), \
+ RANGE_TYPE(type, xf86GetPciDomain(tag))); \
+ }
+#define PCI_I_RANGE(range,tag,begin,end,type) \
+ { \
+ RANGE(range, B2I(tag, begin), B2I(tag, end), \
+ RANGE_TYPE(type, xf86GetPciDomain(tag))); \
+ }
+#define PCI_X_RANGE(range,tag,begin,end,type) \
+{ if ((type & ResPhysMask) == ResMem) PCI_M_RANGE(range,tag,begin,end,type); \
+ else PCI_I_RANGE(range,tag,begin,end,type); }
+#define P_M_RANGE(range,tag,begin,size,type) \
+ PCI_M_RANGE(range,tag,begin,(begin + SIZE(size)),type)
+#define P_I_RANGE(range,tag,begin,size,type) \
+ PCI_I_RANGE(range,tag,begin,(begin + SIZE(size)),type)
+#define P_X_RANGE(range,tag,begin,size,type) \
+{ if ((type & ResPhysMask) == ResMem) P_M_RANGE(range,tag,begin,size,type); \
+ else P_I_RANGE(range,tag,begin,size,type); }
+#define PV_M_RANGE(range,pvp,i,type) \
+ P_M_RANGE(range,TAG(pvp),pvp->memBase[i],pvp->size[i],type)
+#define PV_B_RANGE(range,pvp,type) \
+ P_M_RANGE(range,TAG(pvp),pvp->biosBase,pvp->biosSize,type)
+#define PV_I_RANGE(range,pvp,i,type) \
+ P_I_RANGE(range,TAG(pvp),pvp->ioBase[i],pvp->size[i],type)
+
+static void getPciClassFlags(pciConfigPtr *pcrpp);
+static void pciConvertListToHost(int bus, int dev, int func, resPtr list);
+static PciBusPtr xf86GetPciBridgeInfo(void);
+
+void
+xf86FormatPciBusNumber(int busnum, char *buffer)
+{
+ /* 'buffer' should be at least 8 characters long */
+ if (busnum < 256)
+ sprintf(buffer, "%d", busnum);
+ else
+ sprintf(buffer, "%d@%d", busnum & 0x00ff, busnum >> 8);
+}
+
+static Bool
+IsBaseUnassigned(CARD32 base)
+{
+ CARD32 mask;
+
+ if (base & PCI_MAP_IO)
+ mask = ~PCI_MAP_IO_ATTR_MASK;
+ else
+ mask = ~PCI_MAP_MEMORY_ATTR_MASK;
+
+ base &= mask;
+ return (!base || (base == mask));
+}
+
+static Bool
+IsBaseUnassigned64(CARD32 base0, CARD32 base1)
+{
+ base0 &= ~PCI_MAP_MEMORY_ATTR_MASK;
+ base1 &= 0xffffffff;
+
+ return ((!base0 && !base1)
+ || ((base0 == ~PCI_MAP_MEMORY_ATTR_MASK)
+ && (base1 == 0xffffffff)));
+}
+
+static void
+FindPCIVideoInfo(void)
+{
+ pciConfigPtr pcrp, *pcrpp;
+ int i = 0, j, k;
+ int num = 0;
+ pciVideoPtr info;
+ int DoIsolateDeviceCheck = 0;
+
+ if (xf86IsolateDevice.bus || xf86IsolateDevice.device || xf86IsolateDevice.func)
+ DoIsolateDeviceCheck = 1;
+ pcrpp = xf86PciInfo = xf86scanpci(0);
+ getPciClassFlags(pcrpp);
+
+ if (pcrpp == NULL) {
+ xf86PciVideoInfo = NULL;
+ return;
+ }
+ xf86PciBus = xf86GetPciBridgeInfo();
+
+ while ((pcrp = pcrpp[i])) {
+ int baseclass;
+ int subclass;
+
+ if (pcrp->listed_class & 0xffff) {
+ baseclass = (pcrp->listed_class >> 8) & 0xff;
+ subclass = pcrp->listed_class & 0xff;
+ } else {
+ baseclass = pcrp->pci_base_class;
+ subclass = pcrp->pci_sub_class;
+ }
+
+ if (PCIINFOCLASSES(baseclass, subclass) &&
+ (DoIsolateDeviceCheck ?
+ (xf86IsolateDevice.bus == pcrp->busnum &&
+ xf86IsolateDevice.device == pcrp->devnum &&
+ xf86IsolateDevice.func == pcrp->funcnum) : 1)) {
+ num++;
+ xf86PciVideoInfo = xnfrealloc(xf86PciVideoInfo,
+ sizeof(pciVideoPtr) * (num + 1));
+ xf86PciVideoInfo[num] = NULL;
+ info = xf86PciVideoInfo[num - 1] = xnfalloc(sizeof(pciVideoRec));
+ info->validSize = FALSE;
+ info->vendor = pcrp->pci_vendor;
+ info->chipType = pcrp->pci_device;
+ info->chipRev = pcrp->pci_rev_id;
+ info->subsysVendor = pcrp->pci_subsys_vendor;
+ info->subsysCard = pcrp->pci_subsys_card;
+ info->bus = pcrp->busnum;
+ info->device = pcrp->devnum;
+ info->func = pcrp->funcnum;
+ info->class = baseclass;
+ info->subclass = pcrp->pci_sub_class;
+ info->interface = pcrp->pci_prog_if;
+ info->biosBase = PCIGETROM(pcrp->pci_baserom);
+ info->biosSize = pciGetBaseSize(pcrp->tag, 6, TRUE, NULL);
+ info->thisCard = pcrp;
+ info->validate = FALSE;
+#ifdef INCLUDE_XF86_NO_DOMAIN
+ if ((PCISHAREDIOCLASSES(baseclass, subclass))
+ && (pcrp->pci_command & PCI_CMD_IO_ENABLE) &&
+ (pcrp->pci_prog_if == 0)) {
+
+ /*
+ * Attempt to ensure that VGA is actually routed to this
+ * adapter on entry. This needs to be fixed when we finally
+ * grok host bridges (and multiple bus trees).
+ */
+ j = info->bus;
+ while (TRUE) {
+ PciBusPtr pBus = xf86PciBus;
+ while (pBus && j != pBus->secondary)
+ pBus = pBus->next;
+ if (!pBus || !(pBus->brcontrol & PCI_PCI_BRIDGE_VGA_EN))
+ break;
+ if (j == pBus->primary) {
+ if (primaryBus.type == BUS_NONE) {
+ /* assumption: primary adapter is always VGA */
+ primaryBus.type = BUS_PCI;
+ primaryBus.id.pci.bus = pcrp->busnum;
+ primaryBus.id.pci.device = pcrp->devnum;
+ primaryBus.id.pci.func = pcrp->funcnum;
+ } else if (primaryBus.type < BUS_last) {
+ xf86Msg(X_NOTICE,
+ "More than one primary device found\n");
+ primaryBus.type ^= (BusType)(-1);
+ }
+ break;
+ }
+ j = pBus->primary;
+ }
+ }
+#endif
+
+ for (j = 0; j < 6; j++) {
+ info->memBase[j] = 0;
+ info->ioBase[j] = 0;
+ if (PCINONSYSTEMCLASSES(baseclass, subclass)) {
+ info->size[j] =
+ pciGetBaseSize(pcrp->tag, j, TRUE, &info->validSize);
+ pcrp->minBasesize = info->validSize;
+ } else {
+ info->size[j] = pcrp->basesize[j];
+ info->validSize = pcrp->minBasesize;
+ }
+ info->type[j] = 0;
+ }
+
+ if (PCINONSYSTEMCLASSES(baseclass, subclass)) {
+ /*
+ * Check of a PCI base is unassigned. If so
+ * attempt to fix it. Validation will determine
+ * if the value was correct later on.
+ */
+ CARD32 *base = &pcrp->pci_base0;
+
+ for (j = 0; j < 6; j++) {
+ if (!PCI_MAP_IS64BITMEM(base[j])) {
+ if (info->size[j] && IsBaseUnassigned(base[j]))
+ base[j] = pciCheckForBrokenBase(pcrp->tag, j);
+ } else {
+ if (j == 5) /* bail out */
+ break;
+ if (info->size[j]
+ && IsBaseUnassigned64(base[j],base[j+1])) {
+ base[j] = pciCheckForBrokenBase(pcrp->tag, j);
+ j++;
+ base[j] = pciCheckForBrokenBase(pcrp->tag, j);
+ }
+ }
+ }
+ }
+
+ /*
+ * 64-bit base addresses are checked for and avoided on 32-bit
+ * platforms.
+ */
+ for (j = 0; j < 6; ++j) {
+ CARD32 bar = (&pcrp->pci_base0)[j];
+
+ if (bar != 0) {
+ if (bar & PCI_MAP_IO) {
+ info->ioBase[j] = (memType)PCIGETIO(bar);
+ info->type[j] = bar & PCI_MAP_IO_ATTR_MASK;
+ } else {
+ info->type[j] = bar & PCI_MAP_MEMORY_ATTR_MASK;
+ info->memBase[j] = (memType)PCIGETMEMORY(bar);
+ if (PCI_MAP_IS64BITMEM(bar)) {
+ if (j == 5) {
+ xf86MsgVerb(X_WARNING, 0,
+ "****BAR5 specified as 64-bit wide, "
+ "which is not possible. "
+ "Ignoring BAR5.****\n");
+ info->memBase[j] = 0;
+ } else {
+ CARD32 bar_hi = PCIGETMEMORY64HIGH((&pcrp->pci_base0)[j]);
+#if defined(LONG64) || defined(WORD64)
+ /* 64 bit architecture */
+ info->memBase[j] |=
+ (memType)bar_hi << 32;
+#else
+ if (bar_hi != 0)
+ info->memBase[j] = 0;
+#endif
+ ++j; /* Step over the next BAR */
+ }
+ }
+ }
+ }
+ }
+ info->listed_class = pcrp->listed_class;
+ }
+ i++;
+ }
+
+ /* If we haven't found a primary device try a different heuristic */
+ if (primaryBus.type == BUS_NONE && num) {
+ for (i = 0; i < num; i++) {
+ info = xf86PciVideoInfo[i];
+ pcrp = info->thisCard;
+
+ if ((pcrp->pci_command & PCI_CMD_MEM_ENABLE) &&
+ (num == 1 ||
+ ((info->class == PCI_CLASS_DISPLAY) &&
+ (info->subclass == PCI_SUBCLASS_DISPLAY_VGA)))) {
+ if (primaryBus.type == BUS_NONE) {
+ primaryBus.type = BUS_PCI;
+ primaryBus.id.pci.bus = pcrp->busnum;
+ primaryBus.id.pci.device = pcrp->devnum;
+ primaryBus.id.pci.func = pcrp->funcnum;
+ } else {
+ xf86Msg(X_NOTICE,
+ "More than one possible primary device found\n");
+ primaryBus.type ^= (BusType)(-1);
+ }
+ }
+ }
+ }
+
+ /* Print a summary of the video devices found */
+ for (k = 0; k < num; k++) {
+ const char *vendorname = NULL, *chipname = NULL;
+ const char *prim = " ";
+ char busnum[8];
+ Bool memdone = FALSE, iodone = FALSE;
+
+ i = 0;
+ info = xf86PciVideoInfo[k];
+ xf86FormatPciBusNumber(info->bus, busnum);
+ xf86FindPciNamesByDevice(info->vendor, info->chipType,
+ NOVENDOR, NOSUBSYS,
+ &vendorname, &chipname, NULL, NULL);
+ if ((!vendorname || !chipname) &&
+ !PCIALWAYSPRINTCLASSES(info->class, info->subclass))
+ continue;
+ if (xf86IsPrimaryPci(info))
+ prim = "*";
+
+ xf86Msg(X_PROBED, "PCI:%s(%s:%d:%d) ", prim, busnum, info->device,
+ info->func);
+ if (vendorname)
+ xf86ErrorF("%s ", vendorname);
+ else
+ xf86ErrorF("unknown vendor (0x%04x) ", info->vendor);
+ if (chipname)
+ xf86ErrorF("%s ", chipname);
+ else
+ xf86ErrorF("unknown chipset (0x%04x) ", info->chipType);
+ xf86ErrorF("rev %d", info->chipRev);
+ for (i = 0; i < 6; i++) {
+ if (info->memBase[i] &&
+ (info->memBase[i] < (memType)(-1 << info->size[i]))) {
+ if (!memdone) {
+ xf86ErrorF(", Mem @ ");
+ memdone = TRUE;
+ } else
+ xf86ErrorF(", ");
+ xf86ErrorF("0x%08lx/%d", info->memBase[i], info->size[i]);
+ }
+ }
+ for (i = 0; i < 6; i++) {
+ if (info->ioBase[i] &&
+ (info->ioBase[i] < (memType)(-1 << info->size[i]))) {
+ if (!iodone) {
+ xf86ErrorF(", I/O @ ");
+ iodone = TRUE;
+ } else
+ xf86ErrorF(", ");
+ xf86ErrorF("0x%04lx/%d", info->ioBase[i], info->size[i]);
+ }
+ }
+ if (info->biosBase &&
+ (info->biosBase < (memType)(-1 << info->biosSize)))
+ xf86ErrorF(", BIOS @ 0x%08lx/%d", info->biosBase, info->biosSize);
+ xf86ErrorF("\n");
+ }
+}
+
+/*
+ * fixPciSizeInfo() -- fix pci size info by testing it destructively
+ * (if not already done), fix pciVideoInfo and entry in the resource
+ * list.
+ */
+/*
+ * Note: once we have OS support to read the sizes GetBaseSize() will
+ * have to be wrapped by the OS layer. fixPciSizeInfo() should also
+ * be wrapped by the OS layer to do nothing if the size is always
+ * returned correctly by GetBaseSize(). It should however set validate
+ * in pciVideoRec if validation is required. ValidatePci() also needs
+ * to be wrapped by the OS layer. This may do nothing if the OS has
+ * already taken care of validation. fixPciResource() may be moved to
+ * OS layer with minimal changes. Once the wrapping layer is in place
+ * the common level and drivers should not reference these functions
+ * directly but thru the OS layer.
+ */
+
+static void
+fixPciSizeInfo(int entityIndex)
+{
+ pciVideoPtr pvp;
+ resPtr pAcc;
+ PCITAG tag;
+ int j;
+
+ if (! (pvp = xf86GetPciInfoForEntity(entityIndex))) return;
+ if (pvp->validSize) return;
+
+ tag = pciTag(pvp->bus,pvp->device,pvp->func);
+
+ for (j = 0; j < 6; j++) {
+ pAcc = Acc;
+ if (pvp->memBase[j])
+ while (pAcc) {
+ if (((pAcc->res_type & (ResPhysMask | ResBlock))
+ == (ResMem | ResBlock))
+ && (pAcc->block_begin == B2M(TAG(pvp),pvp->memBase[j]))
+ && (pAcc->block_end == B2M(TAG(pvp),pvp->memBase[j]
+ + SIZE(pvp->size[j])))) break;
+ pAcc = pAcc->next;
+ }
+ else if (pvp->ioBase[j])
+ while (pAcc) {
+ if (((pAcc->res_type & (ResPhysMask | ResBlock)) ==
+ (ResIo | ResBlock))
+ && (pAcc->block_begin == B2I(TAG(pvp),pvp->ioBase[j]))
+ && (pAcc->block_end == B2I(TAG(pvp),pvp->ioBase[j]
+ + SIZE(pvp->size[j])))) break;
+ pAcc = pAcc->next;
+ }
+ else continue;
+ pvp->size[j] = pciGetBaseSize(tag, j, TRUE, &pvp->validSize);
+ if (pAcc) {
+ pAcc->block_end = pvp->memBase[j] ?
+ B2M(TAG(pvp),pvp->memBase[j] + SIZE(pvp->size[j]))
+ : B2I(TAG(pvp),pvp->ioBase[j] + SIZE(pvp->size[j]));
+ pAcc->res_type &= ~ResEstimated;
+ pAcc->res_type |= ResBios;
+ }
+ }
+ if (pvp->biosBase) {
+ pAcc = Acc;
+ while (pAcc) {
+ if (((pAcc->res_type & (ResPhysMask | ResBlock)) ==
+ (ResMem | ResBlock))
+ && (pAcc->block_begin == B2M(TAG(pvp),pvp->biosBase))
+ && (pAcc->block_end == B2M(TAG(pvp),pvp->biosBase
+ + SIZE(pvp->biosSize)))) break;
+ pAcc = pAcc->next;
+ }
+ pvp->biosSize = pciGetBaseSize(tag, 6, TRUE, &pvp->validSize);
+ if (pAcc) {
+ pAcc->block_end = B2M(TAG(pvp),pvp->biosBase+SIZE(pvp->biosSize));
+ pAcc->res_type &= ~ResEstimated;
+ pAcc->res_type |= ResBios;
+ }
+ }
+}
+
+/*
+ * IO enable/disable related routines for PCI
+ */
+#define pArg ((pciArg*)arg)
+#define SETBITS PCI_CMD_IO_ENABLE
+static void
+pciIoAccessEnable(void* arg)
+{
+#ifdef DEBUG
+ ErrorF("pciIoAccessEnable: 0x%05lx\n", *(PCITAG *)arg);
+#endif
+ pArg->ctrl |= SETBITS | PCI_CMD_MASTER_ENABLE;
+ pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl);
+}
+
+static void
+pciIoAccessDisable(void* arg)
+{
+#ifdef DEBUG
+ ErrorF("pciIoAccessDisable: 0x%05lx\n", *(PCITAG *)arg);
+#endif
+ pArg->ctrl &= ~SETBITS;
+ pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl);
+}
+
+#undef SETBITS
+#define SETBITS (PCI_CMD_IO_ENABLE | PCI_CMD_MEM_ENABLE)
+static void
+pciIo_MemAccessEnable(void* arg)
+{
+#ifdef DEBUG
+ ErrorF("pciIo_MemAccessEnable: 0x%05lx\n", *(PCITAG *)arg);
+#endif
+ pArg->ctrl |= SETBITS | PCI_CMD_MASTER_ENABLE;
+ pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl);
+}
+
+static void
+pciIo_MemAccessDisable(void* arg)
+{
+#ifdef DEBUG
+ ErrorF("pciIo_MemAccessDisable: 0x%05lx\n", *(PCITAG *)arg);
+#endif
+ pArg->ctrl &= ~SETBITS;
+ pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl);
+}
+
+#undef SETBITS
+#define SETBITS (PCI_CMD_MEM_ENABLE)
+static void
+pciMemAccessEnable(void* arg)
+{
+#ifdef DEBUG
+ ErrorF("pciMemAccessEnable: 0x%05lx\n", *(PCITAG *)arg);
+#endif
+ pArg->ctrl |= SETBITS | PCI_CMD_MASTER_ENABLE;
+ pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl);
+}
+
+static void
+pciMemAccessDisable(void* arg)
+{
+#ifdef DEBUG
+ ErrorF("pciMemAccessDisable: 0x%05lx\n", *(PCITAG *)arg);
+#endif
+ pArg->ctrl &= ~SETBITS;
+ pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl);
+}
+#undef SETBITS
+#undef pArg
+
+
+/* move to OS layer */
+#define MASKBITS (PCI_PCI_BRIDGE_VGA_EN | PCI_PCI_BRIDGE_MASTER_ABORT_EN)
+static void
+pciBusAccessEnable(BusAccPtr ptr)
+{
+ PCITAG tag = ptr->busdep.pci.acc;
+ CARD16 ctrl;
+
+#ifdef DEBUG
+ ErrorF("pciBusAccessEnable: bus=%d\n", ptr->busdep.pci.bus);
+#endif
+ ctrl = pciReadWord(tag, PCI_PCI_BRIDGE_CONTROL_REG);
+ if ((ctrl & MASKBITS) != PCI_PCI_BRIDGE_VGA_EN) {
+ ctrl = (ctrl | PCI_PCI_BRIDGE_VGA_EN) &
+ ~(PCI_PCI_BRIDGE_MASTER_ABORT_EN | PCI_PCI_BRIDGE_SECONDARY_RESET);
+ pciWriteWord(tag, PCI_PCI_BRIDGE_CONTROL_REG, ctrl);
+ }
+}
+
+/* move to OS layer */
+static void
+pciBusAccessDisable(BusAccPtr ptr)
+{
+ PCITAG tag = ptr->busdep.pci.acc;
+ CARD16 ctrl;
+
+#ifdef DEBUG
+ ErrorF("pciBusAccessDisable: bus=%d\n", ptr->busdep.pci.bus);
+#endif
+ ctrl = pciReadWord(tag, PCI_PCI_BRIDGE_CONTROL_REG);
+ if (ctrl & MASKBITS) {
+ ctrl &= ~(MASKBITS | PCI_PCI_BRIDGE_SECONDARY_RESET);
+ pciWriteWord(tag, PCI_PCI_BRIDGE_CONTROL_REG, ctrl);
+ }
+}
+#undef MASKBITS
+
+/* move to OS layer */
+static void
+pciDrvBusAccessEnable(BusAccPtr ptr)
+{
+ int bus = ptr->busdep.pci.bus;
+
+#ifdef DEBUG
+ ErrorF("pciDrvBusAccessEnable: bus=%d\n", bus);
+#endif
+ (*pciBusInfo[bus]->funcs->pciControlBridge)(bus,
+ PCI_PCI_BRIDGE_VGA_EN,
+ PCI_PCI_BRIDGE_VGA_EN);
+}
+
+/* move to OS layer */
+static void
+pciDrvBusAccessDisable(BusAccPtr ptr)
+{
+ int bus = ptr->busdep.pci.bus;
+
+#ifdef DEBUG
+ ErrorF("pciDrvBusAccessDisable: bus=%d\n", bus);
+#endif
+ (*pciBusInfo[bus]->funcs->pciControlBridge)(bus,
+ PCI_PCI_BRIDGE_VGA_EN, 0);
+}
+
+
+static void
+pciSetBusAccess(BusAccPtr ptr)
+{
+#ifdef DEBUG
+ ErrorF("pciSetBusAccess: route VGA to bus %d\n", ptr->busdep.pci.bus);
+#endif
+
+ if (!ptr->primary && !ptr->current)
+ return;
+
+ if (ptr->current && ptr->current->disable_f)
+ (*ptr->current->disable_f)(ptr->current);
+ ptr->current = NULL;
+
+ /* walk down */
+ while (ptr->primary) { /* No enable for root bus */
+ if (ptr != ptr->primary->current) {
+ if (ptr->primary->current && ptr->primary->current->disable_f)
+ (*ptr->primary->current->disable_f)(ptr->primary->current);
+ if (ptr->enable_f)
+ (*ptr->enable_f)(ptr);
+ ptr->primary->current = ptr;
+ }
+ ptr = ptr->primary;
+ }
+}
+
+/* move to OS layer */
+static void
+savePciState(PCITAG tag, pciSavePtr ptr)
+{
+ int i;
+
+ ptr->command = pciReadLong(tag, PCI_CMD_STAT_REG);
+ for (i=0; i < 6; i++)
+ ptr->base[i] = pciReadLong(tag, PCI_CMD_BASE_REG + i*4);
+ ptr->biosBase = pciReadLong(tag, PCI_CMD_BIOS_REG);
+}
+
+/* move to OS layer */
+static void
+restorePciState(PCITAG tag, pciSavePtr ptr)
+{
+ int i;
+
+ /* disable card before setting anything */
+ pciSetBitsLong(tag, PCI_CMD_STAT_REG,
+ PCI_CMD_MEM_ENABLE | PCI_CMD_IO_ENABLE , 0);
+ pciWriteLong(tag,PCI_CMD_BIOS_REG, ptr->biosBase);
+ for (i=0; i<6; i++)
+ pciWriteLong(tag, PCI_CMD_BASE_REG + i*4, ptr->base[i]);
+ pciWriteLong(tag, PCI_CMD_STAT_REG, ptr->command);
+}
+
+/* move to OS layer */
+static void
+savePciBusState(BusAccPtr ptr)
+{
+ PCITAG tag = ptr->busdep.pci.acc;
+
+ ptr->busdep.pci.save.control =
+ pciReadWord(tag, PCI_PCI_BRIDGE_CONTROL_REG) &
+ ~PCI_PCI_BRIDGE_SECONDARY_RESET;
+ /* Allow master aborts to complete normally on non-root buses */
+ if (ptr->busdep.pci.save.control & PCI_PCI_BRIDGE_MASTER_ABORT_EN)
+ pciWriteWord(tag, PCI_PCI_BRIDGE_CONTROL_REG,
+ ptr->busdep.pci.save.control & ~PCI_PCI_BRIDGE_MASTER_ABORT_EN);
+}
+
+/* move to OS layer */
+#define MASKBITS (PCI_PCI_BRIDGE_VGA_EN | PCI_PCI_BRIDGE_MASTER_ABORT_EN)
+static void
+restorePciBusState(BusAccPtr ptr)
+{
+ PCITAG tag = ptr->busdep.pci.acc;
+ CARD16 ctrl;
+
+ /* Only restore the bits we've changed (and don't cause resets) */
+ ctrl = pciReadWord(tag, PCI_PCI_BRIDGE_CONTROL_REG);
+ if ((ctrl ^ ptr->busdep.pci.save.control) & MASKBITS) {
+ ctrl &= ~(MASKBITS | PCI_PCI_BRIDGE_SECONDARY_RESET);
+ ctrl |= ptr->busdep.pci.save.control & MASKBITS;
+ pciWriteWord(tag, PCI_PCI_BRIDGE_CONTROL_REG, ctrl);
+ }
+}
+#undef MASKBITS
+
+/* move to OS layer */
+static void
+savePciDrvBusState(BusAccPtr ptr)
+{
+ int bus = ptr->busdep.pci.bus;
+
+ ptr->busdep.pci.save.control =
+ (*pciBusInfo[bus]->funcs->pciControlBridge)(bus, 0, 0);
+ /* Allow master aborts to complete normally on this bus */
+ (*pciBusInfo[bus]->funcs->pciControlBridge)(bus,
+ PCI_PCI_BRIDGE_MASTER_ABORT_EN,
+ 0);
+}
+
+/* move to OS layer */
+static void
+restorePciDrvBusState(BusAccPtr ptr)
+{
+ int bus = ptr->busdep.pci.bus;
+
+ (*pciBusInfo[bus]->funcs->pciControlBridge)(bus, (CARD16)(-1),
+ ptr->busdep.pci.save.control);
+}
+
+
+static void
+disablePciBios(PCITAG tag)
+{
+ pciSetBitsLong(tag, PCI_CMD_BIOS_REG, PCI_CMD_BIOS_ENABLE, 0);
+}
+
+/* ????? */
+static void
+correctPciSize(memType base, memType oldsize, memType newsize,
+ unsigned long type)
+{
+ pciConfigPtr pcrp, *pcrpp;
+ pciVideoPtr pvp, *pvpp;
+ CARD32 *basep;
+ int i;
+ int old_bits = 0, new_bits = 0;
+
+ if (oldsize + 1) while (oldsize & 1) {
+ old_bits ++;
+ oldsize >>= 1;
+ }
+ if (newsize + 1) while (newsize & 1) {
+ new_bits ++;
+ newsize >>= 1;
+ }
+
+ for (pcrpp = xf86PciInfo, pcrp = *pcrpp; pcrp; pcrp = *++(pcrpp)) {
+
+ /* Only process devices with type 0 headers */
+ if ((pcrp->pci_header_type & 0x7f) != 0)
+ continue;
+
+ basep = &pcrp->pci_base0;
+ for (i = 0; i < 6; i++) {
+ if (basep[i] && (pcrp->basesize[i] == old_bits)) {
+ if ((((type & ResPhysMask) == ResIo) &&
+ PCI_MAP_IS_IO(basep[i]) &&
+ B2I(pcrp->tag,PCIGETIO(basep[i]) == base)) ||
+ (((type & ResPhysMask) == ResMem) &&
+ PCI_MAP_IS_MEM(basep[i]) &&
+ (((!PCI_MAP_IS64BITMEM(basep[i])) &&
+ (B2M(pcrp->tag,PCIGETMEMORY(basep[i])) == base))
+#if defined(LONG64) || defined(WORD64)
+ ||
+ (B2M(pcrp->tag,PCIGETMEMORY64(basep[i])) == base)
+#else
+ ||
+ (!basep[i+1]
+ && (B2M(pcrp->tag,PCIGETMEMORY(basep[i])) == base))
+#endif
+ ))) {
+ pcrp->basesize[i] = new_bits;
+ break; /* to next device */
+ }
+ }
+ if (PCI_MAP_IS64BITMEM(basep[i])) i++;
+ }
+ }
+
+ if (xf86PciVideoInfo) {
+ for (pvpp = xf86PciVideoInfo, pvp = *pvpp; pvp; pvp = *(++pvpp)) {
+
+ for (i = 0; i < 6; i++) {
+ if (pvp->size[i] == old_bits) {
+ if ((((type & ResPhysMask) == ResIo) && pvp->ioBase[i]
+ && (B2I(TAG(pvp),pvp->ioBase[i]) == base)) ||
+ (((type & ResPhysMask) == ResMem) && pvp->memBase[i]
+ && (B2M(TAG(pvp),pvp->memBase[i]) == base))) {
+ pvp->size[i] = new_bits;
+ break; /* to next device */
+ }
+ }
+ }
+ }
+ }
+}
+
+/* ????? */
+static void
+removeOverlapsWithBridges(int busIndex, resPtr target)
+{
+ PciBusPtr pbp;
+ resPtr tmp,bridgeRes = NULL;
+ resRange range;
+
+ if (!target)
+ return;
+
+ if (!ResCanOverlap(&target->val))
+ return;
+
+ range = target->val;
+
+ for (pbp=xf86PciBus; pbp; pbp = pbp->next) {
+ if (pbp->primary == busIndex) {
+ tmp = xf86DupResList(pbp->preferred_io);
+ bridgeRes = xf86JoinResLists(tmp,bridgeRes);
+ tmp = xf86DupResList(pbp->preferred_mem);
+ bridgeRes = xf86JoinResLists(tmp,bridgeRes);
+ tmp = xf86DupResList(pbp->preferred_pmem);
+ bridgeRes = xf86JoinResLists(tmp,bridgeRes);
+ }
+ }
+
+ RemoveOverlaps(target, bridgeRes, TRUE, TRUE);
+ if (range.rEnd > target->block_end) {
+ correctPciSize(range.rBegin, range.rEnd - range.rBegin,
+ target->block_end - target->block_begin,
+ target->res_type);
+ xf86MsgVerb(X_INFO, 3,
+ "PCI %s resource overlap reduced 0x%08lx from 0x%08lx to 0x%08lx\n",
+ ((target->res_type & ResPhysMask) == ResMem) ? "Memory" : "I/O",
+ range.rBegin, range.rEnd, target->block_end);
+ }
+ xf86FreeResList(bridgeRes);
+}
+
+/* ????? */
+static void
+xf86GetPciRes(resPtr *activeRes, resPtr *inactiveRes)
+{
+ pciConfigPtr pcrp, *pcrpp;
+ pciVideoPtr pvp, *pvpp;
+ CARD32 *basep;
+ int i;
+ resPtr pRes, tmp;
+ resRange range;
+ long resMisc;
+
+ if (activeRes)
+ *activeRes = NULL;
+ if (inactiveRes)
+ *inactiveRes = NULL;
+
+ if (!activeRes || !inactiveRes || !xf86PciInfo)
+ return;
+
+ if (xf86PciVideoInfo)
+ for (pvpp = xf86PciVideoInfo, pvp = *pvpp; pvp; pvp = *(++pvpp)) {
+ resPtr *res;
+
+ if (PCINONSYSTEMCLASSES(pvp->class, pvp->subclass))
+ resMisc = ResBios;
+ else
+ resMisc = 0;
+
+ if (((pciConfigPtr)pvp->thisCard)->pci_command
+ & (PCI_CMD_IO_ENABLE | PCI_CMD_MEM_ENABLE))
+ res = activeRes;
+ else
+ res = inactiveRes;
+
+ if (!pvp->validSize)
+ resMisc |= ResEstimated;
+
+ for (i = 0; i < 6; i++) {
+ if (pvp->ioBase[i] &&
+ (pvp->ioBase[i] < (memType)(-1 << pvp->size[i]))) {
+ PV_I_RANGE(range,pvp,i,ResExcIoBlock | resMisc);
+ tmp = xf86AddResToList(NULL, &range, -1);
+ removeOverlapsWithBridges(pvp->bus,tmp);
+ *res = xf86JoinResLists(tmp,*res);
+ } else if (pvp->memBase[i] &&
+ (pvp->memBase[i] < (memType)(-1 << pvp->size[i]))) {
+ PV_M_RANGE(range, pvp,i, ResExcMemBlock | resMisc);
+ tmp = xf86AddResToList(NULL, &range, -1);
+ removeOverlapsWithBridges(pvp->bus,tmp);
+ *res = xf86JoinResLists(tmp,*res);
+ }
+ }
+ /* FIXME!!!: Don't use BIOS resources for overlap
+ * checking but reserve them!
+ */
+ if (pvp->biosBase &&
+ (pvp->biosBase < (memType)(-1 << pvp->biosSize))) {
+ PV_B_RANGE(range, pvp, ResExcMemBlock | resMisc);
+ tmp = xf86AddResToList(NULL, &range, -1);
+ removeOverlapsWithBridges(pvp->bus,tmp);
+ *res = xf86JoinResLists(tmp,*res);
+ }
+ }
+
+ for (pcrpp = xf86PciInfo, pcrp = *pcrpp; pcrp; pcrp = *++(pcrpp)) {
+ resPtr *res;
+ CARD8 baseclass, subclass;
+
+ if (pcrp->listed_class & 0x0ffff) {
+ baseclass = pcrp->listed_class >> 8;
+ subclass = pcrp->listed_class;
+ } else {
+ baseclass = pcrp->pci_base_class;
+ subclass = pcrp->pci_sub_class;
+ }
+
+ if (PCIINFOCLASSES(baseclass, subclass))
+ continue;
+
+ /* Only process devices with type 0 headers */
+ if ((pcrp->pci_header_type & 0x7f) != 0)
+ continue;
+
+ if (!pcrp->minBasesize)
+ resMisc = ResEstimated;
+ else
+ resMisc = 0;
+
+ /*
+ * Allow resources allocated to host bridges to overlap. Perhaps, this
+ * needs to be specific to AGP-capable chipsets. AGP "memory"
+ * sometimes gets allocated within the range routed to the AGP bus.
+ */
+ if ((baseclass == PCI_CLASS_BRIDGE) &&
+ (subclass == PCI_SUBCLASS_BRIDGE_HOST))
+ resMisc |= ResOverlap;
+
+ basep = &pcrp->pci_base0;
+ for (i = 0; i < 6; i++) {
+ if (basep[i]) {
+ if (PCI_MAP_IS_IO(basep[i])) {
+ if (pcrp->pci_command & PCI_CMD_IO_ENABLE)
+ res = activeRes;
+ else
+ res = inactiveRes;
+ P_I_RANGE(range, pcrp->tag, PCIGETIO(basep[i]),
+ pcrp->basesize[i], ResExcIoBlock | resMisc)
+ } else if (!PCI_MAP_IS64BITMEM(basep[i])) {
+ if (pcrp->pci_command & PCI_CMD_MEM_ENABLE)
+ res = activeRes;
+ else
+ res = inactiveRes;
+ P_M_RANGE(range, pcrp->tag, PCIGETMEMORY(basep[i]),
+ pcrp->basesize[i], ResExcMemBlock | resMisc)
+ } else {
+ i++;
+#if defined(LONG64) || defined(WORD64)
+ P_M_RANGE(range,pcrp->tag,PCIGETMEMORY64(basep[i - 1]),
+ pcrp->basesize[i - 1], ResExcMemBlock | resMisc)
+#else
+ if (basep[i])
+ continue;
+ P_M_RANGE(range, pcrp->tag, PCIGETMEMORY(basep[i - 1]),
+ pcrp->basesize[i - 1], ResExcMemBlock | resMisc)
+#endif
+ if (pcrp->pci_command & PCI_CMD_MEM_ENABLE)
+ res = activeRes;
+ else
+ res = inactiveRes;
+ }
+ if (range.rBegin) { /* catch cases where PCI base is unset */
+ tmp = xf86AddResToList(NULL, &range, -1);
+ removeOverlapsWithBridges(pcrp->busnum,tmp);
+ *res = xf86JoinResLists(tmp,*res);
+ }
+ }
+ }
+
+ /* Ignore disabled non-video ROMs */
+ if ((pcrp->pci_command & PCI_CMD_MEM_ENABLE) &&
+ (pcrp->pci_baserom & PCI_MAP_ROM_DECODE_ENABLE)) {
+ P_M_RANGE(range,pcrp->tag,PCIGETROM(pcrp->pci_baserom),
+ pcrp->basesize[6], ResExcMemBlock | resMisc);
+ if (range.rBegin) {
+ tmp = xf86AddResToList(NULL, &range, -1);
+ removeOverlapsWithBridges(pcrp->busnum, tmp);
+ *activeRes = xf86JoinResLists(tmp, *activeRes);
+ }
+ }
+ }
+
+ if (*activeRes) {
+ xf86MsgVerb(X_INFO, 3, "Active PCI resource ranges:\n");
+ xf86PrintResList(3, *activeRes);
+ }
+ if (*inactiveRes) {
+ xf86MsgVerb(X_INFO, 3, "Inactive PCI resource ranges:\n");
+ xf86PrintResList(3, *inactiveRes);
+ }
+
+ /*
+ * Adjust ranges based on the assumption that there are no real
+ * overlaps in the PCI base allocations. This assumption should be
+ * reasonable in most cases. It may be possible to refine the
+ * approximated PCI base sizes by considering bus mapping information
+ * from PCI-PCI bridges.
+ */
+
+ if (*activeRes) {
+ /* Check for overlaps */
+ for (pRes = *activeRes; pRes; pRes = pRes->next) {
+ if (ResCanOverlap(&pRes->val)) {
+ range = pRes->val;
+
+ RemoveOverlaps(pRes, *activeRes, TRUE, TRUE);
+ RemoveOverlaps(pRes, *inactiveRes, TRUE,
+ (xf86Info.estimateSizesAggressively > 0));
+
+ if (range.rEnd > pRes->block_end) {
+ correctPciSize(range.rBegin, range.rEnd - range.rBegin,
+ pRes->block_end - pRes->block_begin,
+ pRes->res_type);
+ xf86MsgVerb(X_INFO, 3,
+ "PCI %s resource overlap reduced 0x%08lx"
+ " from 0x%08lx to 0x%08lx\n",
+ ((pRes->res_type & ResPhysMask) == ResMem) ?
+ "Memory" : "I/O",
+ range.rBegin, range.rEnd, pRes->block_end);
+ }
+ }
+ }
+ xf86MsgVerb(X_INFO, 3,
+ "Active PCI resource ranges after removing overlaps:\n");
+ xf86PrintResList(3, *activeRes);
+ }
+
+ if (*inactiveRes) {
+ /* Check for overlaps */
+ for (pRes = *inactiveRes; pRes; pRes = pRes->next) {
+ if (ResCanOverlap(&pRes->val)) {
+ range = pRes->val;
+
+ RemoveOverlaps(pRes, *activeRes, TRUE,
+ (xf86Info.estimateSizesAggressively > 1));
+ RemoveOverlaps(pRes, *inactiveRes, TRUE,
+ (xf86Info.estimateSizesAggressively > 1));
+
+ if (range.rEnd > pRes->block_end) {
+ correctPciSize(range.rBegin, range.rEnd - range.rBegin,
+ pRes->block_end - pRes->block_begin,
+ pRes->res_type);
+ xf86MsgVerb(X_INFO, 3,
+ "PCI %s resource overlap reduced 0x%08lx"
+ " from 0x%08lx to 0x%08lx\n",
+ ((pRes->res_type & ResPhysMask) == ResMem) ?
+ "Memory" : "I/O",
+ range.rBegin, range.rEnd, pRes->block_end);
+ }
+
+ }
+ }
+ xf86MsgVerb(X_INFO, 3,
+ "Inactive PCI resource ranges after removing overlaps:\n");
+ xf86PrintResList(3, *inactiveRes);
+ }
+}
+
+resPtr
+ResourceBrokerInitPci(resPtr *osRes)
+{
+ resPtr activeRes, inactiveRes;
+ resPtr tmp;
+
+ /* Get bus-specific system resources (PCI) */
+ xf86GetPciRes(&activeRes, &inactiveRes);
+
+ /*
+ * Adjust OS-reported resource ranges based on the assumption that there
+ * are no overlaps with the PCI base allocations. This should be a good
+ * assumption because writes to PCI address space won't be routed directly
+ * to host memory.
+ */
+
+ for (tmp = *osRes; tmp; tmp = tmp->next)
+ RemoveOverlaps(tmp, activeRes, FALSE, TRUE);
+
+ xf86MsgVerb(X_INFO, 3, "OS-reported resource ranges after removing"
+ " overlaps with PCI:\n");
+ xf86PrintResList(3, *osRes);
+
+ pciAvoidRes = xf86AddRangesToList(pciAvoidRes,PciAvoid,-1);
+ for (tmp = pciAvoidRes; tmp; tmp = tmp->next)
+ RemoveOverlaps(tmp, activeRes, FALSE, TRUE);
+ tmp = xf86DupResList(*osRes);
+ pciAvoidRes = xf86JoinResLists(pciAvoidRes,tmp);
+
+ return (xf86JoinResLists(activeRes,inactiveRes));
+}
+
+
+/*
+ * PCI Resource modification
+ */
+static Bool
+fixPciResource(int prt, memType alignment, pciVideoPtr pvp, unsigned long type)
+{
+ int res_n;
+ memType *p_base;
+ int *p_size;
+ unsigned char p_type;
+ resPtr AccTmp = NULL;
+ resPtr orgAcc = NULL;
+ resPtr *pAcc = &AccTmp;
+ resPtr avoid = NULL;
+ resRange range;
+ resPtr resSize = NULL;
+ resPtr w_tmp, w = NULL, w_2nd = NULL;
+ PCITAG tag;
+ PciBusPtr pbp = xf86PciBus;
+ pciConfigPtr pcp;
+ resPtr tmp;
+
+ if (!pvp) return FALSE;
+ tag = pciTag(pvp->bus,pvp->device,pvp->func);
+ pcp = pvp->thisCard;
+
+ type &= ResAccMask;
+ if (!type) type = ResShared;
+ if (prt < 6) {
+ if (pvp->memBase[prt]) {
+ type |= ResMem;
+ res_n = prt;
+ p_base = &(pvp->memBase[res_n]);
+ p_size = &(pvp->size[res_n]);
+ p_type = pvp->type[res_n];
+ if (!PCI_MAP_IS64BITMEM(pvp->type[res_n])) {
+ PCI_M_RANGE(range,tag,0,0xffffffff,ResExcMemBlock);
+ resSize = xf86AddResToList(resSize,&range,-1);
+ }
+ } else if (pvp->ioBase[prt]){
+ type |= ResIo;
+ res_n = prt;
+ p_base = &(pvp->ioBase[res_n]);
+ p_size = &(pvp->size[res_n]);
+ p_type = pvp->type[res_n];
+ PCI_I_RANGE(range, tag, 0, 0xffffffff, ResExcIoBlock);
+ resSize = xf86AddResToList(resSize, &range, -1);
+ } else return FALSE;
+ } else if (prt == 6) {
+ type |= ResMem;
+ res_n = 0xff; /* special flag for bios rom */
+ p_base = &(pvp->biosBase);
+ p_size = &(pvp->biosSize);
+ /* XXX This should also include the PCI_MAP_MEMORY_TYPE_MASK part */
+ p_type = 0;
+ PCI_M_RANGE(range,tag,0,0xffffffff,ResExcMemBlock);
+ resSize = xf86AddResToList(resSize,&range,-1);
+ } else return FALSE;
+
+ if (! *p_base) return FALSE;
+
+ type |= (range.type & ResDomain) | ResBlock;
+
+ /* setup avoid: PciAvoid is bus range: convert later */
+ avoid = xf86DupResList(pciAvoidRes);
+
+ while (pbp) {
+ if (pbp->secondary == pvp->bus) {
+ if ((type & ResPhysMask) == ResMem) {
+ if (((p_type & PCI_MAP_MEMORY_CACHABLE)
+#if 0 /*EE*/
+ || (res_n == 0xff)/* bios should also be prefetchable */
+#endif
+ )) {
+ if (pbp->preferred_pmem)
+ w = xf86FindIntersectOfLists(pbp->preferred_pmem,
+ ResRange);
+ else if (pbp->pmem)
+ w = xf86FindIntersectOfLists(pbp->pmem,ResRange);
+
+ if (pbp->preferred_mem)
+ w_2nd = xf86FindIntersectOfLists(pbp->preferred_mem,
+ ResRange);
+ else if (pbp->mem)
+ w_2nd = xf86FindIntersectOfLists(pbp->mem,
+ ResRange);
+ } else {
+ if (pbp->preferred_mem)
+ w = xf86FindIntersectOfLists(pbp->preferred_mem,
+ ResRange);
+ else if (pbp->mem)
+ w = xf86FindIntersectOfLists(pbp->mem,ResRange);
+ }
+ } else {
+ if (pbp->preferred_io)
+ w = xf86FindIntersectOfLists(pbp->preferred_io,ResRange);
+ if (pbp->io)
+ w = xf86FindIntersectOfLists(pbp->io,ResRange);
+ }
+ } else if (pbp->primary == pvp->bus) {
+ if ((type & ResPhysMask) == ResMem) {
+ tmp = xf86DupResList(pbp->preferred_pmem);
+ avoid = xf86JoinResLists(avoid, tmp);
+ tmp = xf86DupResList(pbp->preferred_mem);
+ avoid = xf86JoinResLists(avoid, tmp);
+ } else {
+ tmp = xf86DupResList(pbp->preferred_io);
+ avoid = xf86JoinResLists(avoid, tmp);
+ }
+ }
+ pbp = pbp->next;
+ }
+
+ /* convert bus based entries in avoid list to host base */
+ pciConvertListToHost(pvp->bus,pvp->device,pvp->func, avoid);
+
+ if (!w)
+ w = xf86DupResList(ResRange);
+ xf86MsgVerb(X_INFO, 3, "window:\n");
+ xf86PrintResList(3, w);
+ xf86MsgVerb(X_INFO, 3, "resSize:\n");
+ xf86PrintResList(3, resSize);
+
+ if (resSize) {
+ w_tmp = w;
+ w = xf86FindIntersectOfLists(w,resSize);
+ xf86FreeResList(w_tmp);
+ if (w_2nd) {
+ w_tmp = w_2nd;
+ w_2nd = xf86FindIntersectOfLists(w_2nd,resSize);
+ xf86FreeResList(w_tmp);
+ }
+ xf86FreeResList(resSize);
+ }
+ xf86MsgVerb(X_INFO, 3, "window fixed:\n");
+ xf86PrintResList(3, w);
+
+ if (!alignment)
+ alignment = (1 << (*p_size)) - 1;
+
+ /* Access list holds bios resources -- remove this one */
+#ifdef NOTYET
+ AccTmp = xf86DupResList(Acc);
+ while ((*pAcc)) {
+ if ((((*pAcc)->res_type & (type & ~ResAccMask))
+ == (type & ~ResAccMask))
+ && ((*pAcc)->block_begin == (B2H(tag,(*p_base),type)))
+ && ((*pAcc)->block_end == (B2H(tag,
+ (*p_base)+SIZE(*p_size),type)))) {
+ resPtr acc_tmp = (*pAcc)->next;
+ xfree((*pAcc));
+ (*pAcc) = acc_tmp;
+ break;
+ } else
+ pAcc = &((*pAcc)->next);
+ }
+ /* check if we really need to fix anything */
+ P_X_RANGE(range,tag,(*p_base),(*p_base) + SIZE((*p_size)),type);
+ if (!ChkConflict(&range,avoid,SETUP)
+ && !ChkConflict(&range,AccTmp,SETUP)
+ && ((B2H(tag,(*p_base),type) & PCI_SIZE(type,tag,alignment)
+ == range->block_begin)
+ && ((xf86IsSubsetOf(range,w)
+ || (w_2nd && xf86IsSubsetOf(range,w_2n))))) {
+#ifdef DEBUG
+ ErrorF("nothing to fix\n");
+#endif
+ xf86FreeResList(AccTmp);
+ xf86FreeResList(w);
+ xf86FreeResList(w_2nd);
+ xf86FreeResList(avoid);
+ return TRUE;
+ }
+#ifdef DEBUG
+ ErrorF("removing old resource\n");
+#endif
+ orgAcc = Acc;
+ Acc = AccTmp;
+#else
+ orgAcc = xf86DupResList(Acc);
+ pAcc = &Acc;
+ while (*pAcc) {
+ if ((((*pAcc)->res_type & (ResTypeMask|ResExtMask)) ==
+ (type & ~ResAccMask))
+ && ((*pAcc)->block_begin == B2H(tag,(*p_base),type))
+ && ((*pAcc)->block_end == B2H(tag,(*p_base) + SIZE(*p_size),
+ type))) {
+#ifdef DEBUG
+ ErrorF("removing old resource\n");
+#endif
+ tmp = *pAcc;
+ *pAcc = (*pAcc)->next;
+ tmp->next = NULL;
+ xf86FreeResList(tmp);
+ break;
+ } else
+ pAcc = &((*pAcc)->next);
+ }
+#endif
+
+#ifdef DEBUG
+ ErrorF("base: 0x%lx alignment: 0x%lx host alignment: 0x%lx size[bit]: 0x%x\n",
+ (*p_base),alignment,PCI_SIZE(type,tag,alignment),(*p_size));
+ xf86MsgVerb(X_INFO, 3, "window:\n");
+ xf86PrintResList(3, w);
+ if (w_2nd)
+ xf86MsgVerb(X_INFO, 3, "2nd window:\n");
+ xf86PrintResList(3, w_2nd);
+ xf86ErrorFVerb(3,"avoid:\n");
+ xf86PrintResList(3,avoid);
+#endif
+ w_tmp = w;
+ while (w) {
+ if ((type & ResTypeMask) == (w->res_type & ResTypeMask)) {
+#ifdef DEBUG
+ ErrorF("block_begin: 0x%lx block_end: 0x%lx\n",w->block_begin,
+ w->block_end);
+#endif
+ range = xf86GetBlock(type,PCI_SIZE(type,tag,alignment + 1),
+ w->block_begin, w->block_end,
+ PCI_SIZE(type,tag,alignment),avoid);
+ if (range.type != ResEnd)
+ break;
+ }
+ w = w->next;
+ }
+ xf86FreeResList(w_tmp);
+ /* if unsuccessful and memory prefetchable try non-prefetchable */
+ if (range.type == ResEnd && w_2nd) {
+ w_tmp = w_2nd;
+ while (w_2nd) {
+ if ((type & ResTypeMask) == (w_2nd->res_type & ResTypeMask)) {
+#ifdef DEBUG
+ ErrorF("block_begin: 0x%lx block_end: 0x%lx\n",w_2nd->block_begin,
+ w_2nd->block_end);
+#endif
+ range = xf86GetBlock(type,PCI_SIZE(type,tag,alignment + 1),
+ w_2nd->block_begin, w_2nd->block_end,
+ PCI_SIZE(type,tag,alignment),avoid);
+ if (range.type != ResEnd)
+ break;
+ }
+ w_2nd = w_2nd->next;
+ }
+ xf86FreeResList(w_tmp);
+ }
+ xf86FreeResList(avoid);
+
+ if (range.type == ResEnd) {
+ xf86MsgVerb(X_ERROR,3,"Cannot find a replacement memory range\n");
+ xf86FreeResList(Acc);
+ Acc = orgAcc;
+ return FALSE;
+ }
+ xf86FreeResList(orgAcc);
+#ifdef DEBUG
+ ErrorF("begin: 0x%lx, end: 0x%lx\n",range.a,range.b);
+#endif
+
+ (*p_size) = 0;
+ while (alignment >> (*p_size))
+ (*p_size)++;
+ (*p_base) = H2B(tag,range.rBegin,type);
+#ifdef DEBUG
+ ErrorF("New PCI res %i base: 0x%lx, size: 0x%lx, type %s\n",
+ res_n,(*p_base),(1 << (*p_size)),
+ ((type & ResPhysMask) == ResMem) ? "Mem" : "Io");
+#endif
+ if (res_n != 0xff) {
+ if ((type & ResPhysMask) == ResMem)
+ pvp->memBase[prt] = range.rBegin;
+ else
+ pvp->ioBase[prt] = range.rBegin;
+ ((CARD32 *)(&(pcp->pci_base0)))[res_n] =
+ (CARD32)(*p_base) | (CARD32)(p_type);
+ pciWriteLong(tag, PCI_CMD_BASE_REG + res_n * sizeof(CARD32),
+ ((CARD32 *)(&(pcp->pci_base0)))[res_n]);
+ if (PCI_MAP_IS64BITMEM(p_type)) {
+#if defined(LONG64) || defined(WORD64)
+ ((CARD32 *)(&(pcp->pci_base0)))[res_n + 1] =
+ (CARD32)(*p_base >> 32);
+ pciWriteLong(tag, PCI_CMD_BASE_REG + (res_n + 1) * sizeof(CARD32),
+ ((CARD32 *)(&(pcp->pci_base0)))[res_n + 1]);
+#else
+ ((CARD32 *)(&(pcp->pci_base0)))[res_n + 1] = 0;
+ pciWriteLong(tag, PCI_CMD_BASE_REG + (res_n + 1) * sizeof(CARD32),
+ 0);
+#endif
+ }
+ } else {
+ pvp->biosBase = range.rBegin;
+ pcp->pci_baserom = (pciReadLong(tag,PCI_CMD_BIOS_REG) & 0x01) |
+ (CARD32)(*p_base);
+ pciWriteLong(tag, PCI_CMD_BIOS_REG, pcp->pci_baserom);
+ }
+ /* @@@ fake BIOS allocated resource */
+ range.type |= ResBios;
+ Acc = xf86AddResToList(Acc, &range,-1);
+
+ return TRUE;
+
+}
+
+Bool
+xf86FixPciResource(int entityIndex, int prt, memType alignment,
+ unsigned long type)
+{
+ pciVideoPtr pvp = xf86GetPciInfoForEntity(entityIndex);
+ return fixPciResource(prt, alignment, pvp, type);
+}
+
+resPtr
+xf86ReallocatePciResources(int entityIndex, resPtr pRes)
+{
+ pciVideoPtr pvp = xf86GetPciInfoForEntity(entityIndex);
+ resPtr pBad = NULL,pResTmp;
+ unsigned int prt = 0;
+ int i;
+
+ if (!pvp) return pRes;
+
+ while (pRes) {
+ switch (pRes->res_type & ResPhysMask) {
+ case ResMem:
+ if (pRes->block_begin == B2M(TAG(pvp),pvp->biosBase) &&
+ pRes->block_end == B2M(TAG(pvp),pvp->biosBase
+ + SIZE(pvp->biosSize)))
+ prt = 6;
+ else for (i = 0 ; i < 6; i++)
+ if ((pRes->block_begin == B2M(TAG(pvp),pvp->memBase[i]))
+ && (pRes->block_end == B2M(TAG(pvp),pvp->memBase[i]
+ + SIZE(pvp->size[i])))) {
+ prt = i;
+ break;
+ }
+ break;
+ case ResIo:
+ for (i = 0 ; i < 6; i++)
+ if (pRes->block_begin == B2I(TAG(pvp),pvp->ioBase[i])
+ && pRes->block_end == B2I(TAG(pvp),pvp->ioBase[i]
+ + SIZE(pvp->size[i]))) {
+ prt = i;
+ break;
+ }
+ break;
+ }
+
+ if (!prt) return pRes;
+
+ pResTmp = pRes->next;
+ if (! fixPciResource(prt, 0, pvp, pRes->res_type)) {
+ pRes->next = pBad;
+ pBad = pRes;
+ } else
+ xfree(pRes);
+
+ pRes = pResTmp;
+ }
+ return pBad;
+}
+
+/*
+ * BIOS releated
+ */
+memType
+getValidBIOSBase(PCITAG tag, int num)
+{
+ pciVideoPtr pvp = NULL;
+ PciBusPtr pbp;
+ resPtr m = NULL;
+ resPtr tmp, avoid, mem = NULL;
+ resRange range;
+ memType ret;
+ int n = 0;
+ int i;
+ CARD32 biosSize, alignment;
+
+ if (!xf86PciVideoInfo) return 0;
+
+ while ((pvp = xf86PciVideoInfo[n++])) {
+ if (pciTag(pvp->bus,pvp->device,pvp->func) == tag)
+ break;
+ }
+ if (!pvp) return 0;
+
+ biosSize = pvp->biosSize;
+ alignment = (1 << biosSize) - 1;
+ if (biosSize > 24)
+ biosSize = 24;
+
+ switch ((romBaseSource)num) {
+ case ROM_BASE_PRESET:
+ return 0; /* This should not happen */
+ case ROM_BASE_BIOS:
+ /* In some cases the BIOS base register contains the size mask */
+ if ((memType)(-1 << biosSize) == PCIGETROM(pvp->biosBase))
+ return 0;
+ /* Make sure we don't conflict with our own mem resources */
+ for (i = 0; i < 6; i++) {
+ if (!pvp->memBase[i])
+ continue;
+ P_M_RANGE(range,TAG(pvp),pvp->memBase[i],pvp->size[i],
+ ResExcMemBlock);
+ mem = xf86AddResToList(mem,&range,-1);
+ }
+ P_M_RANGE(range, TAG(pvp),pvp->biosBase,biosSize,ResExcMemBlock);
+ ret = pvp->biosBase;
+ break;
+ case ROM_BASE_MEM0:
+ case ROM_BASE_MEM1:
+ case ROM_BASE_MEM2:
+ case ROM_BASE_MEM3:
+ case ROM_BASE_MEM4:
+ case ROM_BASE_MEM5:
+ if (!pvp->memBase[num] || (pvp->size[num] < biosSize))
+ return 0;
+ P_M_RANGE(range, TAG(pvp),pvp->memBase[num],biosSize,
+ ResExcMemBlock);
+ ret = pvp->memBase[num];
+ break;
+ case ROM_BASE_FIND:
+ ret = 0;
+ break;
+ default:
+ return 0; /* This should not happen */
+ }
+
+ /* Now find the ranges for validation */
+ avoid = xf86DupResList(pciAvoidRes);
+ pbp = xf86PciBus;
+ while (pbp) {
+ if (pbp->secondary == pvp->bus) {
+ if (pbp->preferred_pmem)
+ tmp = xf86DupResList(pbp->preferred_pmem);
+ else
+ tmp = xf86DupResList(pbp->pmem);
+ m = xf86JoinResLists(m,tmp);
+ if (pbp->preferred_mem)
+ tmp = xf86DupResList(pbp->preferred_mem);
+ else
+ tmp = xf86DupResList(pbp->mem);
+ m = xf86JoinResLists(m,tmp);
+ tmp = m;
+ while (tmp) {
+ tmp->block_end = min(tmp->block_end,PCI_MEM32_LENGTH_MAX);
+ tmp = tmp->next;
+ }
+ } else if ((pbp->primary == pvp->bus) &&
+ (pbp->secondary >= 0) &&
+ (pbp->primary != pbp->secondary)) {
+ tmp = xf86DupResList(pbp->preferred_pmem);
+ avoid = xf86JoinResLists(avoid, tmp);
+ tmp = xf86DupResList(pbp->pmem);
+ avoid = xf86JoinResLists(avoid, tmp);
+ tmp = xf86DupResList(pbp->preferred_mem);
+ avoid = xf86JoinResLists(avoid, tmp);
+ tmp = xf86DupResList(pbp->mem);
+ avoid = xf86JoinResLists(avoid, tmp);
+ }
+ pbp = pbp->next;
+ }
+ pciConvertListToHost(pvp->bus,pvp->device,pvp->func, avoid);
+ if (mem)
+ pciConvertListToHost(pvp->bus,pvp->device,pvp->func, mem);
+
+ if (!ret) {
+ /* Return a possible window */
+ while (m) {
+ range = xf86GetBlock(RANGE_TYPE(ResExcMemBlock, xf86GetPciDomain(tag)),
+ PCI_SIZE(ResMem, TAG(pvp), 1 << biosSize),
+ m->block_begin, m->block_end,
+ PCI_SIZE(ResMem, TAG(pvp), alignment),
+ avoid);
+ if (range.type != ResEnd) {
+ ret = M2B(TAG(pvp), range.rBase);
+ break;
+ }
+ m = m->next;
+ }
+ } else {
+#if !defined(__ia64__) /* on ia64, trust the kernel, don't look for overlaps */
+ if (!xf86IsSubsetOf(range, m) ||
+ ChkConflict(&range, avoid, SETUP)
+ || (mem && ChkConflict(&range, mem, SETUP)))
+ ret = 0;
+#endif
+ }
+
+ xf86FreeResList(avoid);
+ xf86FreeResList(m);
+ return ret;
+}
+
+/*
+ * xf86Bus.c interface
+ */
+
+void
+xf86PciProbe(void)
+{
+ /*
+ * Initialise the pcidata entry points.
+ */
+#ifdef XFree86LOADER
+ xf86SetupPciIds = (ScanPciSetupProcPtr)LoaderSymbol("ScanPciSetupPciIds");
+ xf86ClosePciIds = (ScanPciCloseProcPtr)LoaderSymbol("ScanPciClosePciIds");
+ xf86FindPciNamesByDevice =
+ (ScanPciFindByDeviceProcPtr)LoaderSymbol("ScanPciFindPciNamesByDevice");
+ xf86FindPciNamesBySubsys =
+ (ScanPciFindBySubsysProcPtr)LoaderSymbol("ScanPciFindPciNamesBySubsys");
+ xf86FindPciClassBySubsys =
+ (ScanPciFindClassBySubsysProcPtr)LoaderSymbol("ScanPciFindPciClassBySubsys");
+ xf86FindPciClassByDevice =
+ (ScanPciFindClassByDeviceProcPtr)LoaderSymbol("ScanPciFindPciClassByDevice");
+#else
+ xf86SetupPciIds = ScanPciSetupPciIds;
+ xf86ClosePciIds = ScanPciClosePciIds;
+ xf86FindPciNamesByDevice = ScanPciFindPciNamesByDevice;
+ xf86FindPciNamesBySubsys = ScanPciFindPciNamesBySubsys;
+ xf86FindPciClassBySubsys = ScanPciFindPciClassBySubsys;
+ xf86FindPciClassByDevice = ScanPciFindPciClassByDevice;
+#endif
+
+ if (!xf86SetupPciIds())
+ FatalError("xf86SetupPciIds() failed\n");
+
+ FindPCIVideoInfo();
+}
+
+static void alignBridgeRanges(PciBusPtr PciBusBase, PciBusPtr primary);
+
+static void
+printBridgeInfo(PciBusPtr PciBus)
+{
+ char primary[8], secondary[8], subordinate[8], brbus[8];
+
+ xf86FormatPciBusNumber(PciBus->primary, primary);
+ xf86FormatPciBusNumber(PciBus->secondary, secondary);
+ xf86FormatPciBusNumber(PciBus->subordinate, subordinate);
+ xf86FormatPciBusNumber(PciBus->brbus, brbus);
+
+ xf86MsgVerb(X_INFO, 3, "Bus %s: bridge is at (%s:%d:%d), (%s,%s,%s),"
+ " BCTRL: 0x%04x (VGA_EN is %s)\n",
+ secondary, brbus, PciBus->brdev, PciBus->brfunc,
+ primary, secondary, subordinate, PciBus->brcontrol,
+ (PciBus->brcontrol & PCI_PCI_BRIDGE_VGA_EN) ?
+ "set" : "cleared");
+ if (PciBus->preferred_io) {
+ xf86MsgVerb(X_INFO, 3,
+ "Bus %s I/O range:\n", secondary);
+ xf86PrintResList(3, PciBus->preferred_io);
+ }
+ if (PciBus->preferred_mem) {
+ xf86MsgVerb(X_INFO, 3,
+ "Bus %s non-prefetchable memory range:\n", secondary);
+ xf86PrintResList(3, PciBus->preferred_mem);
+ }
+ if (PciBus->preferred_pmem) {
+ xf86MsgVerb(X_INFO, 3,
+ "Bus %s prefetchable memory range:\n", secondary);
+ xf86PrintResList(3, PciBus->preferred_pmem);
+ }
+}
+
+static PciBusPtr
+xf86GetPciBridgeInfo(void)
+{
+ const pciConfigPtr *pcrpp;
+ pciConfigPtr pcrp;
+ pciBusInfo_t *pBusInfo;
+ resRange range;
+ PciBusPtr PciBus, PciBusBase = NULL;
+ PciBusPtr *pnPciBus = &PciBusBase;
+ int MaxBus = 0;
+ int i, domain;
+ int primary, secondary, subordinate;
+ memType base, limit;
+
+ resPtr pciBusAccWindows = xf86PciBusAccWindowsFromOS();
+
+ if (xf86PciInfo == NULL)
+ return NULL;
+
+ /* Add each bridge */
+ for (pcrpp = xf86PciInfo, pcrp = *pcrpp; pcrp; pcrp = *(++pcrpp)) {
+ if (pcrp->busnum > MaxBus)
+ MaxBus = pcrp->busnum;
+ if ((pcrp->pci_base_class == PCI_CLASS_BRIDGE) ||
+ (((pcrp->listed_class >> 8) & 0xff) == PCI_CLASS_BRIDGE)) {
+ int sub_class;
+ sub_class = (pcrp->listed_class & 0xffff) ?
+ (pcrp->listed_class & 0xff) : pcrp->pci_sub_class;
+ domain = xf86GetPciDomain(pcrp->tag);
+
+ switch (sub_class) {
+ case PCI_SUBCLASS_BRIDGE_PCI:
+ /* something fishy about the header? If so: just ignore! */
+ if ((pcrp->pci_header_type & 0x7f) != 0x01) {
+ xf86MsgVerb(X_WARNING, 3, "PCI-PCI bridge at %x:%x:%x has"
+ " unexpected header: 0x%x",
+ pcrp->busnum, pcrp->devnum,
+ pcrp->funcnum, pcrp->pci_header_type);
+ break;
+ }
+
+ domain = pcrp->busnum & 0x0000FF00;
+ primary = pcrp->busnum;
+ secondary = domain | pcrp->pci_secondary_bus_number;
+ subordinate = domain | pcrp->pci_subordinate_bus_number;
+
+ /* Is this the correct bridge? If not, ignore it */
+ pBusInfo = pcrp->businfo;
+ if (pBusInfo && (pcrp != pBusInfo->bridge)) {
+ xf86MsgVerb(X_WARNING, 3, "PCI bridge mismatch for bus %x:"
+ " %x:%x:%x and %x:%x:%x\n", secondary,
+ pcrp->busnum, pcrp->devnum, pcrp->funcnum,
+ pBusInfo->bridge->busnum,
+ pBusInfo->bridge->devnum,
+ pBusInfo->bridge->funcnum);
+ break;
+ }
+
+ if (pBusInfo && pBusInfo->funcs->pciGetBridgeBuses)
+ (*pBusInfo->funcs->pciGetBridgeBuses)(secondary,
+ &primary,
+ &secondary,
+ &subordinate);
+
+ if (!pcrp->fakeDevice && (primary >= secondary)) {
+ xf86MsgVerb(X_WARNING, 3, "Misconfigured PCI bridge"
+ " %x:%x:%x (%x,%x)\n",
+ pcrp->busnum, pcrp->devnum, pcrp->funcnum,
+ primary, secondary);
+ break;
+ }
+
+ *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec));
+ pnPciBus = &PciBus->next;
+
+ PciBus->primary = primary;
+ PciBus->secondary = secondary;
+ PciBus->subordinate = subordinate;
+
+ PciBus->brbus = pcrp->busnum;
+ PciBus->brdev = pcrp->devnum;
+ PciBus->brfunc = pcrp->funcnum;
+
+ PciBus->subclass = sub_class;
+ PciBus->interface = pcrp->pci_prog_if;
+
+ if (pBusInfo && pBusInfo->funcs->pciControlBridge)
+ PciBus->brcontrol =
+ (*pBusInfo->funcs->pciControlBridge)(secondary, 0, 0);
+ else
+ PciBus->brcontrol = pcrp->pci_bridge_control;
+
+ if (pBusInfo && pBusInfo->funcs->pciGetBridgeResources) {
+ (*pBusInfo->funcs->pciGetBridgeResources)(secondary,
+ (pointer *)&PciBus->preferred_io,
+ (pointer *)&PciBus->preferred_mem,
+ (pointer *)&PciBus->preferred_pmem);
+ break;
+ }
+
+ if ((pcrp->pci_command & PCI_CMD_IO_ENABLE) &&
+ (pcrp->pci_upper_io_base || pcrp->pci_io_base ||
+ pcrp->pci_upper_io_limit || pcrp->pci_io_limit)) {
+ base = (pcrp->pci_upper_io_base << 16) |
+ ((pcrp->pci_io_base & 0xf0u) << 8);
+ limit = (pcrp->pci_upper_io_limit << 16) |
+ ((pcrp->pci_io_limit & 0xf0u) << 8) | 0x0fff;
+ /*
+ * Deal with bridge ISA mode (256 wide ranges spaced 1K
+ * apart, but only in the first 64K).
+ */
+ if (pcrp->pci_bridge_control & PCI_PCI_BRIDGE_ISA_EN) {
+ while ((base <= (CARD16)(-1)) && (base <= limit)) {
+ PCI_I_RANGE(range, pcrp->tag,
+ base, base + (CARD8)(-1),
+ ResIo | ResBlock | ResExclusive);
+ PciBus->preferred_io =
+ xf86AddResToList(PciBus->preferred_io,
+ &range, -1);
+ base += 0x0400;
+ }
+ }
+ if (base <= limit) {
+ PCI_I_RANGE(range, pcrp->tag, base, limit,
+ ResIo | ResBlock | ResExclusive);
+ PciBus->preferred_io =
+ xf86AddResToList(PciBus->preferred_io, &range, -1);
+ }
+ }
+ if (pcrp->pci_command & PCI_CMD_MEM_ENABLE) {
+ /*
+ * The P2P spec requires these next two, but some bridges
+ * don't comply. Err on the side of caution, making the not
+ * so bold assumption that no bridge would ever re-route the
+ * bottom megabyte.
+ */
+ if (pcrp->pci_mem_base || pcrp->pci_mem_limit) {
+ base = pcrp->pci_mem_base & 0xfff0u;
+ limit = pcrp->pci_mem_limit & 0xfff0u;
+ if (base <= limit) {
+ PCI_M_RANGE(range, pcrp->tag,
+ base << 16, (limit << 16) | 0x0fffff,
+ ResMem | ResBlock | ResExclusive);
+ PciBus->preferred_mem =
+ xf86AddResToList(PciBus->preferred_mem, &range, -1);
+ }
+ }
+
+ if (pcrp->pci_prefetch_mem_base ||
+ pcrp->pci_prefetch_mem_limit ||
+ pcrp->pci_prefetch_upper_mem_base ||
+ pcrp->pci_prefetch_upper_mem_limit) {
+ base = pcrp->pci_prefetch_mem_base & 0xfff0u;
+ limit = pcrp->pci_prefetch_mem_limit & 0xfff0u;
+#if defined(LONG64) || defined(WORD64)
+ base |= (memType)pcrp->pci_prefetch_upper_mem_base << 16;
+ limit |= (memType)pcrp->pci_prefetch_upper_mem_limit << 16;
+#endif
+ if (base <= limit) {
+ PCI_M_RANGE(range, pcrp->tag,
+ base << 16, (limit << 16) | 0xfffff,
+ ResMem | ResBlock | ResExclusive);
+ PciBus->preferred_pmem =
+ xf86AddResToList(PciBus->preferred_pmem,
+ &range, -1);
+ }
+ }
+ }
+ break;
+
+ case PCI_SUBCLASS_BRIDGE_CARDBUS:
+ /* something fishy about the header? If so: just ignore! */
+ if ((pcrp->pci_header_type & 0x7f) != 0x02) {
+ xf86MsgVerb(X_WARNING, 3, "PCI-CardBus bridge at %x:%x:%x"
+ " has unexpected header: 0x%x",
+ pcrp->busnum, pcrp->devnum,
+ pcrp->funcnum, pcrp->pci_header_type);
+ break;
+ }
+
+ domain = pcrp->busnum & 0x0000FF00;
+ primary = pcrp->busnum;
+ secondary = domain | pcrp->pci_cb_cardbus_bus_number;
+ subordinate = domain | pcrp->pci_subordinate_bus_number;
+
+ /* Is this the correct bridge? If not, ignore it */
+ pBusInfo = pcrp->businfo;
+ if (pBusInfo && (pcrp != pBusInfo->bridge)) {
+ xf86MsgVerb(X_WARNING, 3, "CardBus bridge mismatch for bus"
+ " %x: %x:%x:%x and %x:%x:%x\n", secondary,
+ pcrp->busnum, pcrp->devnum, pcrp->funcnum,
+ pBusInfo->bridge->busnum,
+ pBusInfo->bridge->devnum,
+ pBusInfo->bridge->funcnum);
+ break;
+ }
+
+ if (pBusInfo && pBusInfo->funcs->pciGetBridgeBuses)
+ (*pBusInfo->funcs->pciGetBridgeBuses)(secondary,
+ &primary,
+ &secondary,
+ &subordinate);
+
+ if (primary >= secondary) {
+ if (pcrp->pci_cb_cardbus_bus_number != 0)
+ xf86MsgVerb(X_WARNING, 3, "Misconfigured CardBus"
+ " bridge %x:%x:%x (%x,%x)\n",
+ pcrp->busnum, pcrp->devnum, pcrp->funcnum,
+ primary, secondary);
+ break;
+ }
+
+ *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec));
+ pnPciBus = &PciBus->next;
+
+ PciBus->primary = primary;
+ PciBus->secondary = secondary;
+ PciBus->subordinate = subordinate;
+
+ PciBus->brbus = pcrp->busnum;
+ PciBus->brdev = pcrp->devnum;
+ PciBus->brfunc = pcrp->funcnum;
+
+ PciBus->subclass = sub_class;
+ PciBus->interface = pcrp->pci_prog_if;
+
+ if (pBusInfo && pBusInfo->funcs->pciControlBridge)
+ PciBus->brcontrol =
+ (*pBusInfo->funcs->pciControlBridge)(secondary, 0, 0);
+ else
+ PciBus->brcontrol = pcrp->pci_bridge_control;
+
+ if (pBusInfo && pBusInfo->funcs->pciGetBridgeResources) {
+ (*pBusInfo->funcs->pciGetBridgeResources)(secondary,
+ (pointer *)&PciBus->preferred_io,
+ (pointer *)&PciBus->preferred_mem,
+ (pointer *)&PciBus->preferred_pmem);
+ break;
+ }
+
+ if (pcrp->pci_command & PCI_CMD_IO_ENABLE) {
+ if (pcrp->pci_cb_iobase0) {
+ base = PCI_CB_IOBASE(pcrp->pci_cb_iobase0);
+ limit = PCI_CB_IOLIMIT(pcrp->pci_cb_iolimit0);
+
+ /*
+ * Deal with bridge ISA mode (256-wide ranges spaced 1K
+ * apart (start to start), but only in the first 64K).
+ */
+ if (pcrp->pci_bridge_control & PCI_PCI_BRIDGE_ISA_EN) {
+ while ((base <= (CARD16)(-1)) &&
+ (base <= limit)) {
+ PCI_I_RANGE(range, pcrp->tag,
+ base, base + (CARD8)(-1),
+ ResIo | ResBlock | ResExclusive);
+ PciBus->preferred_io =
+ xf86AddResToList(PciBus->preferred_io,
+ &range, -1);
+ base += 0x0400;
+ }
+ }
+
+ if (base <= limit) {
+ PCI_I_RANGE(range, pcrp->tag, base, limit,
+ ResIo | ResBlock | ResExclusive);
+ PciBus->preferred_io =
+ xf86AddResToList(PciBus->preferred_io,
+ &range, -1);
+ }
+ }
+
+ if (pcrp->pci_cb_iobase1) {
+ base = PCI_CB_IOBASE(pcrp->pci_cb_iobase1);
+ limit = PCI_CB_IOLIMIT(pcrp->pci_cb_iolimit1);
+
+ /*
+ * Deal with bridge ISA mode (256-wide ranges spaced 1K
+ * apart (start to start), but only in the first 64K).
+ */
+ if (pcrp->pci_bridge_control & PCI_PCI_BRIDGE_ISA_EN) {
+ while ((base <= (CARD16)(-1)) &&
+ (base <= limit)) {
+ PCI_I_RANGE(range, pcrp->tag,
+ base, base + (CARD8)(-1),
+ ResIo | ResBlock | ResExclusive);
+ PciBus->preferred_io =
+ xf86AddResToList(PciBus->preferred_io,
+ &range, -1);
+ base += 0x0400;
+ }
+ }
+
+ if (base <= limit) {
+ PCI_I_RANGE(range, pcrp->tag, base, limit,
+ ResIo | ResBlock | ResExclusive);
+ PciBus->preferred_io =
+ xf86AddResToList(PciBus->preferred_io,
+ &range, -1);
+ }
+ }
+ }
+
+ if (pcrp->pci_command & PCI_CMD_MEM_ENABLE) {
+ if ((pcrp->pci_cb_membase0) &&
+ (pcrp->pci_cb_membase0 <= pcrp->pci_cb_memlimit0)) {
+ PCI_M_RANGE(range, pcrp->tag,
+ pcrp->pci_cb_membase0 & ~0x0fff,
+ pcrp->pci_cb_memlimit0 | 0x0fff,
+ ResMem | ResBlock | ResExclusive);
+ if (pcrp->pci_bridge_control &
+ PCI_CB_BRIDGE_CTL_PREFETCH_MEM0)
+ PciBus->preferred_pmem =
+ xf86AddResToList(PciBus->preferred_pmem,
+ &range, -1);
+ else
+ PciBus->preferred_mem =
+ xf86AddResToList(PciBus->preferred_mem,
+ &range, -1);
+ }
+ if ((pcrp->pci_cb_membase1) &&
+ (pcrp->pci_cb_membase1 <= pcrp->pci_cb_memlimit1)) {
+ PCI_M_RANGE(range, pcrp->tag,
+ pcrp->pci_cb_membase1 & ~0x0fff,
+ pcrp->pci_cb_memlimit1 | 0x0fff,
+ ResMem | ResBlock | ResExclusive);
+ if (pcrp->pci_bridge_control &
+ PCI_CB_BRIDGE_CTL_PREFETCH_MEM1)
+ PciBus->preferred_pmem =
+ xf86AddResToList(PciBus->preferred_pmem,
+ &range, -1);
+ else
+ PciBus->preferred_mem =
+ xf86AddResToList(PciBus->preferred_mem,
+ &range, -1);
+ }
+ }
+
+ break;
+
+ case PCI_SUBCLASS_BRIDGE_ISA:
+ case PCI_SUBCLASS_BRIDGE_EISA:
+ case PCI_SUBCLASS_BRIDGE_MC:
+ *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec));
+ pnPciBus = &PciBus->next;
+ PciBus->primary = pcrp->busnum;
+ PciBus->secondary = PciBus->subordinate = -1;
+ PciBus->brbus = pcrp->busnum;
+ PciBus->brdev = pcrp->devnum;
+ PciBus->brfunc = pcrp->funcnum;
+ PciBus->subclass = sub_class;
+ PciBus->brcontrol = PCI_PCI_BRIDGE_VGA_EN;
+ break;
+
+ case PCI_SUBCLASS_BRIDGE_HOST:
+ /* Is this the correct bridge? If not, ignore bus info */
+ pBusInfo = pcrp->businfo;
+
+ if (!pBusInfo || pBusInfo == HOST_NO_BUS)
+ break;
+
+ secondary = 0;
+ /* Find "secondary" bus segment */
+ while (pBusInfo != pciBusInfo[secondary])
+ secondary++;
+ if (pcrp != pBusInfo->bridge) {
+ xf86MsgVerb(X_WARNING, 3, "Host bridge mismatch for"
+ " bus %x: %x:%x:%x and %x:%x:%x\n",
+ pBusInfo->primary_bus,
+ pcrp->busnum, pcrp->devnum, pcrp->funcnum,
+ pBusInfo->bridge->busnum,
+ pBusInfo->bridge->devnum,
+ pBusInfo->bridge->funcnum);
+ pBusInfo = NULL;
+ }
+
+ *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec));
+ pnPciBus = &PciBus->next;
+
+
+ PciBus->primary = PciBus->secondary = secondary;
+ PciBus->subordinate = pciNumBuses - 1;
+
+ if (pBusInfo->funcs->pciGetBridgeBuses)
+ (*pBusInfo->funcs->pciGetBridgeBuses)
+ (secondary,
+ &PciBus->primary,
+ &PciBus->secondary,
+ &PciBus->subordinate);
+
+ PciBus->brbus = pcrp->busnum;
+ PciBus->brdev = pcrp->devnum;
+ PciBus->brfunc = pcrp->funcnum;
+
+ PciBus->subclass = sub_class;
+
+ if (pBusInfo && pBusInfo->funcs->pciControlBridge)
+ PciBus->brcontrol =
+ (*pBusInfo->funcs->pciControlBridge)(secondary, 0, 0);
+ else
+ PciBus->brcontrol = PCI_PCI_BRIDGE_VGA_EN;
+
+ if (pBusInfo && pBusInfo->funcs->pciGetBridgeResources) {
+ (*pBusInfo->funcs->pciGetBridgeResources)
+ (secondary,
+ (pointer *)&PciBus->preferred_io,
+ (pointer *)&PciBus->preferred_mem,
+ (pointer *)&PciBus->preferred_pmem);
+ break;
+ }
+
+ PciBus->preferred_io =
+ xf86ExtractTypeFromList(pciBusAccWindows,
+ RANGE_TYPE(ResIo, domain));
+ PciBus->preferred_mem =
+ xf86ExtractTypeFromList(pciBusAccWindows,
+ RANGE_TYPE(ResMem, domain));
+ PciBus->preferred_pmem =
+ xf86ExtractTypeFromList(pciBusAccWindows,
+ RANGE_TYPE(ResMem, domain));
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+ for (i = 0; i <= MaxBus; i++) { /* find PCI buses not attached to bridge */
+ if (!pciBusInfo[i])
+ continue;
+ for (PciBus = PciBusBase; PciBus; PciBus = PciBus->next)
+ if (PciBus->secondary == i) break;
+ if (!PciBus) { /* We assume it's behind a HOST-PCI bridge */
+ /*
+ * Find the 'smallest' free HOST-PCI bridge, where 'small' is in
+ * the order of pciTag().
+ */
+ PCITAG minTag = 0xFFFFFFFF, tag;
+ PciBusPtr PciBusFound = NULL;
+ for (PciBus = PciBusBase; PciBus; PciBus = PciBus->next)
+ if ((PciBus->subclass == PCI_SUBCLASS_BRIDGE_HOST) &&
+ (PciBus->secondary == -1) &&
+ ((tag = pciTag(PciBus->brbus,PciBus->brdev,PciBus->brfunc))
+ < minTag) ) {
+ minTag = tag;
+ PciBusFound = PciBus;
+ }
+ if (PciBusFound)
+ PciBusFound->secondary = i;
+ else { /* if nothing found it may not be visible: create new */
+ /* Find a device on this bus */
+ domain = 0;
+ for (pcrpp = xf86PciInfo; (pcrp = *pcrpp); pcrpp++) {
+ if (pcrp->busnum == i) {
+ domain = xf86GetPciDomain(pcrp->tag);
+ break;
+ }
+ }
+ *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec));
+ pnPciBus = &PciBus->next;
+ PciBus->primary = PciBus->secondary = i;
+ PciBus->subclass = PCI_SUBCLASS_BRIDGE_HOST;
+ PciBus->brcontrol = PCI_PCI_BRIDGE_VGA_EN;
+ PciBus->preferred_io =
+ xf86ExtractTypeFromList(pciBusAccWindows,
+ RANGE_TYPE(ResIo, domain));
+ PciBus->preferred_mem =
+ xf86ExtractTypeFromList(pciBusAccWindows,
+ RANGE_TYPE(ResMem, domain));
+ PciBus->preferred_pmem =
+ xf86ExtractTypeFromList(pciBusAccWindows,
+ RANGE_TYPE(ResMem, domain));
+ }
+ }
+ }
+
+ for (PciBus = PciBusBase; PciBus; PciBus = PciBus->next) {
+ if (PciBus->primary == PciBus->secondary) {
+ alignBridgeRanges(PciBusBase, PciBus);
+ }
+ }
+
+ for (PciBus = PciBusBase; PciBus; PciBus = PciBus->next) {
+ switch (PciBus->subclass) {
+ case PCI_SUBCLASS_BRIDGE_PCI:
+ if (PciBus->interface == PCI_IF_BRIDGE_PCI_SUBTRACTIVE)
+ xf86MsgVerb(X_INFO, 3, "Subtractive PCI-to-PCI bridge:\n");
+ else
+ xf86MsgVerb(X_INFO, 3, "PCI-to-PCI bridge:\n");
+ break;
+ case PCI_SUBCLASS_BRIDGE_CARDBUS:
+ xf86MsgVerb(X_INFO, 3, "PCI-to-CardBus bridge:\n");
+ break;
+ case PCI_SUBCLASS_BRIDGE_HOST:
+ xf86MsgVerb(X_INFO, 3, "Host-to-PCI bridge:\n");
+ break;
+ case PCI_SUBCLASS_BRIDGE_ISA:
+ xf86MsgVerb(X_INFO, 3, "PCI-to-ISA bridge:\n");
+ break;
+ case PCI_SUBCLASS_BRIDGE_EISA:
+ xf86MsgVerb(X_INFO, 3, "PCI-to-EISA bridge:\n");
+ break;
+ case PCI_SUBCLASS_BRIDGE_MC:
+ xf86MsgVerb(X_INFO, 3, "PCI-to-MCA bridge:\n");
+ break;
+ default:
+ break;
+ }
+ printBridgeInfo(PciBus);
+ }
+ xf86FreeResList(pciBusAccWindows);
+ return PciBusBase;
+}
+
+static void
+alignBridgeRanges(PciBusPtr PciBusBase, PciBusPtr primary)
+{
+ PciBusPtr PciBus;
+
+ for (PciBus = PciBusBase; PciBus; PciBus = PciBus->next) {
+ if ((PciBus != primary) && (PciBus->primary != -1)
+ && (PciBus->primary == primary->secondary)) {
+ resPtr tmp;
+ tmp = xf86FindIntersectOfLists(primary->preferred_io,
+ PciBus->preferred_io);
+ xf86FreeResList(PciBus->preferred_io);
+ PciBus->preferred_io = tmp;
+ tmp = xf86FindIntersectOfLists(primary->preferred_pmem,
+ PciBus->preferred_pmem);
+ xf86FreeResList(PciBus->preferred_pmem);
+ PciBus->preferred_pmem = tmp;
+ tmp = xf86FindIntersectOfLists(primary->preferred_mem,
+ PciBus->preferred_mem);
+ xf86FreeResList(PciBus->preferred_mem);
+ PciBus->preferred_mem = tmp;
+
+ /* Deal with subtractive decoding */
+ switch (PciBus->subclass) {
+ case PCI_SUBCLASS_BRIDGE_PCI:
+ if (PciBus->interface != PCI_IF_BRIDGE_PCI_SUBTRACTIVE)
+ break;
+ /* Fall through */
+#if 0 /* Not yet */
+ case PCI_SUBCLASS_BRIDGE_ISA:
+ case PCI_SUBCLASS_BRIDGE_EISA:
+ case PCI_SUBCLASS_BRIDGE_MC:
+#endif
+ if (!(PciBus->io = primary->io))
+ PciBus->io = primary->preferred_io;
+ if (!(PciBus->mem = primary->mem))
+ PciBus->mem = primary->preferred_mem;
+ if (!(PciBus->pmem = primary->pmem))
+ PciBus->pmem = primary->preferred_pmem;
+ default:
+ break;
+ }
+
+ alignBridgeRanges(PciBusBase, PciBus);
+ }
+ }
+}
+
+void
+ValidatePci(void)
+{
+ pciVideoPtr pvp, pvp1;
+ PciBusPtr pbp;
+ pciConfigPtr pcrp, *pcrpp;
+ CARD32 *basep;
+ resPtr Sys;
+ resRange range;
+ int n = 0, m, i;
+
+ if (!xf86PciVideoInfo) return;
+
+ /*
+ * Mark all pciInfoRecs that need to be validated. These are
+ * the ones which have been assigned to a screen.
+ */
+ Sys = xf86DupResList(osRes);
+ /* Only validate graphics devices in use */
+ for (i=0; i<xf86NumScreens; i++) {
+ for (m = 0; m < xf86Screens[i]->numEntities; m++)
+ if ((pvp = xf86GetPciInfoForEntity(xf86Screens[i]->entityList[m])))
+ pvp->validate = TRUE;
+ }
+
+ /*
+ * Collect all background PCI resources we need to validate against.
+ * These are all resources which don't belong to PCINONSYSTEMCLASSES
+ * and which have not been assigned to an entity.
+ */
+ /* First get the PCIINFOCLASSES */
+ m = 0;
+ while ((pvp = xf86PciVideoInfo[m++])) {
+ /* is it a PCINONSYSTEMCLASS? */
+ if (PCINONSYSTEMCLASSES(pvp->class, pvp->subclass))
+ continue;
+ /* has it an Entity assigned to it? */
+ for (i=0; i<xf86NumEntities; i++) {
+ EntityPtr p = xf86Entities[i];
+ if (p->busType != BUS_PCI)
+ continue;
+ if (p->pciBusId.bus == pvp->bus
+ && p->pciBusId.device == pvp->device
+ && p->pciBusId.func == pvp->func)
+ break;
+ }
+ if (i != xf86NumEntities) /* found an Entity for this one */
+ continue;
+
+ for (i = 0; i<6; i++) {
+ if (pvp->ioBase[i]) {
+ PV_I_RANGE(range,pvp,i,ResExcIoBlock);
+ Sys = xf86AddResToList(Sys,&range,-1);
+ } else if (pvp->memBase[i]) {
+ PV_M_RANGE(range,pvp,i,ResExcMemBlock);
+ Sys = xf86AddResToList(Sys,&range,-1);
+ }
+ }
+ }
+ for (pcrpp = xf86PciInfo, pcrp = *pcrpp; pcrp; pcrp = *++(pcrpp)) {
+
+ /* These were handled above */
+ if (PCIINFOCLASSES(pcrp->pci_base_class, pcrp->pci_sub_class))
+ continue;
+
+ if ((pcrp->pci_header_type & 0x7f) ||
+ !(pcrp->pci_command & (PCI_CMD_IO_ENABLE | PCI_CMD_MEM_ENABLE)))
+ continue;
+
+ basep = &pcrp->pci_base0;
+ for (i = 0; i < 6; i++) {
+ if (basep[i]) {
+ if (PCI_MAP_IS_IO(basep[i])) {
+ if (!(pcrp->pci_command & PCI_CMD_IO_ENABLE))
+ continue;
+ P_I_RANGE(range, pcrp->tag, PCIGETIO(basep[i]),
+ pcrp->basesize[i], ResExcIoBlock)
+ } else if (!PCI_MAP_IS64BITMEM(basep[i])) {
+ if (!(pcrp->pci_command & PCI_CMD_MEM_ENABLE))
+ continue;
+ P_M_RANGE(range, pcrp->tag, PCIGETMEMORY(basep[i]),
+ pcrp->basesize[i], ResExcMemBlock)
+ } else {
+ i++;
+ if (!(pcrp->pci_command & PCI_CMD_MEM_ENABLE))
+ continue;
+#if defined(LONG64) || defined(WORD64)
+ P_M_RANGE(range, pcrp->tag, PCIGETMEMORY64(basep[i-1]),
+ pcrp->basesize[i-1], ResExcMemBlock)
+#else
+ if (basep[i])
+ continue;
+ P_M_RANGE(range, pcrp->tag, PCIGETMEMORY(basep[i-1]),
+ pcrp->basesize[i-1], ResExcMemBlock)
+#endif
+ }
+ Sys = xf86AddResToList(Sys, &range, -1);
+ }
+ }
+ if ((pcrp->pci_baserom) &&
+ (pcrp->pci_command & PCI_CMD_MEM_ENABLE) &&
+ (pcrp->pci_baserom & PCI_MAP_ROM_DECODE_ENABLE)) {
+ P_M_RANGE(range,pcrp->tag,PCIGETROM(pcrp->pci_baserom),
+ pcrp->basesize[6],ResExcMemBlock);
+ Sys = xf86AddResToList(Sys, &range, -1);
+ }
+ }
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3,"Sys:\n");
+ xf86PrintResList(3,Sys);
+#endif
+
+ /*
+ * The order the video devices are listed in is
+ * just right: the lower buses come first.
+ * This way we attempt to fix a conflict of
+ * a lower bus device with a higher bus device
+ * where we have more room to find different
+ * resources.
+ */
+ while ((pvp = xf86PciVideoInfo[n++])) {
+ resPtr res_mp = NULL, res_m_io = NULL;
+ resPtr NonSys;
+ resPtr tmp, avoid = NULL;
+
+ if (!pvp->validate) continue;
+ NonSys = xf86DupResList(Sys);
+ m = n;
+ while ((pvp1 = xf86PciVideoInfo[m++])) {
+ if (!pvp1->validate) continue;
+ for (i = 0; i<6; i++) {
+ if (pvp1->ioBase[i]) {
+ PV_I_RANGE(range,pvp1,i,ResExcIoBlock);
+ NonSys = xf86AddResToList(NonSys,&range,-1);
+ } else if (pvp1->memBase[i]) {
+ PV_M_RANGE(range,pvp1,i,ResExcMemBlock);
+ NonSys = xf86AddResToList(NonSys,&range,-1);
+ }
+ }
+ }
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3,"NonSys:\n");
+ xf86PrintResList(3,NonSys);
+#endif
+ pbp = xf86PciBus;
+ while (pbp) {
+ if (pbp->secondary == pvp->bus) {
+ if (pbp->preferred_pmem) {
+ /* keep prefetchable separate */
+ res_mp =
+ xf86FindIntersectOfLists(pbp->preferred_pmem, ResRange);
+ }
+ if (pbp->pmem) {
+ res_mp = xf86FindIntersectOfLists(pbp->pmem, ResRange);
+ }
+ if (pbp->preferred_mem) {
+ res_m_io =
+ xf86FindIntersectOfLists(pbp->preferred_mem, ResRange);
+ }
+ if (pbp->mem) {
+ res_m_io = xf86FindIntersectOfLists(pbp->mem, ResRange);
+ }
+ if (pbp->preferred_io) {
+ res_m_io = xf86JoinResLists(res_m_io,
+ xf86FindIntersectOfLists(pbp->preferred_io, ResRange));
+ }
+ if (pbp->io) {
+ res_m_io = xf86JoinResLists(res_m_io,
+ xf86FindIntersectOfLists(pbp->preferred_io, ResRange));
+ }
+ } else if ((pbp->primary == pvp->bus) &&
+ (pbp->secondary >= 0) &&
+ (pbp->primary != pbp->secondary)) {
+ tmp = xf86DupResList(pbp->preferred_pmem);
+ avoid = xf86JoinResLists(avoid, tmp);
+ tmp = xf86DupResList(pbp->preferred_mem);
+ avoid = xf86JoinResLists(avoid, tmp);
+ tmp = xf86DupResList(pbp->preferred_io);
+ avoid = xf86JoinResLists(avoid, tmp);
+ }
+ pbp = pbp->next;
+ }
+ if (res_m_io == NULL)
+ res_m_io = xf86DupResList(ResRange);
+
+ pciConvertListToHost(pvp->bus,pvp->device,pvp->func, avoid);
+
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3,"avoid:\n");
+ xf86PrintResList(3,avoid);
+ xf86MsgVerb(X_INFO, 3,"prefetchable Memory:\n");
+ xf86PrintResList(3,res_mp);
+ xf86MsgVerb(X_INFO, 3,"MEM/IO:\n");
+ xf86PrintResList(3,res_m_io);
+#endif
+ for (i = 0; i < 6; i++) {
+ int j;
+ resPtr own = NULL;
+ for (j = i+1; j < 6; j++) {
+ if (pvp->ioBase[j]) {
+ PV_I_RANGE(range,pvp,j,ResExcIoBlock);
+ own = xf86AddResToList(own,&range,-1);
+ } else if (pvp->memBase[j]) {
+ PV_M_RANGE(range,pvp,j,ResExcMemBlock);
+ own = xf86AddResToList(own,&range,-1);
+ }
+ }
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3, "own:\n");
+ xf86PrintResList(3, own);
+#endif
+ if (pvp->ioBase[i]) {
+ PV_I_RANGE(range,pvp,i,ResExcIoBlock);
+ if (xf86IsSubsetOf(range,res_m_io)
+ && ! ChkConflict(&range,own,SETUP)
+ && ! ChkConflict(&range,avoid,SETUP)
+ && ! ChkConflict(&range,NonSys,SETUP)) {
+ xf86FreeResList(own);
+ continue;
+ }
+ xf86MsgVerb(X_WARNING, 0,
+ "****INVALID IO ALLOCATION**** b: 0x%lx e: 0x%lx "
+ "correcting\a\n", range.rBegin,range.rEnd);
+#ifdef DEBUG
+ sleep(2);
+#endif
+ fixPciResource(i, 0, pvp, range.type);
+ } else if (pvp->memBase[i]) {
+ PV_M_RANGE(range,pvp,i,ResExcMemBlock);
+ if (pvp->type[i] & PCI_MAP_MEMORY_CACHABLE) {
+ if (xf86IsSubsetOf(range,res_mp)
+ && ! ChkConflict(&range,own,SETUP)
+ && ! ChkConflict(&range,avoid,SETUP)
+ && ! ChkConflict(&range,NonSys,SETUP)) {
+ xf86FreeResList(own);
+ continue;
+ }
+ }
+ if (xf86IsSubsetOf(range,res_m_io)
+ && ! ChkConflict(&range,own,SETUP)
+ && ! ChkConflict(&range,avoid,SETUP)
+ && ! ChkConflict(&range,NonSys,SETUP)) {
+ xf86FreeResList(own);
+ continue;
+ }
+ xf86MsgVerb(X_WARNING, 0,
+ "****INVALID MEM ALLOCATION**** b: 0x%lx e: 0x%lx "
+ "correcting\a\n", range.rBegin,range.rEnd);
+ if (ChkConflict(&range,own,SETUP)) {
+ xf86MsgVerb(X_INFO,3,"own\n");
+ xf86PrintResList(3,own);
+ }
+ if (ChkConflict(&range,avoid,SETUP)) {
+ xf86MsgVerb(X_INFO,3,"avoid\n");
+ xf86PrintResList(3,avoid);
+ }
+ if (ChkConflict(&range,NonSys,SETUP)) {
+ xf86MsgVerb(X_INFO,3,"NonSys\n");
+ xf86PrintResList(3,NonSys);
+ }
+
+#ifdef DEBUG
+ sleep(2);
+#endif
+ fixPciResource(i, 0, pvp, range.type);
+ }
+ xf86FreeResList(own);
+ }
+ xf86FreeResList(avoid);
+ xf86FreeResList(NonSys);
+ xf86FreeResList(res_mp);
+ xf86FreeResList(res_m_io);
+ }
+ xf86FreeResList(Sys);
+}
+
+resList
+GetImplicitPciResources(int entityIndex)
+{
+ pciVideoPtr pvp;
+ int i;
+ resList list = NULL;
+ int num = 0;
+
+ if (! (pvp = xf86GetPciInfoForEntity(entityIndex))) return NULL;
+
+ for (i = 0; i < 6; i++) {
+ if (pvp->ioBase[i]) {
+ list = xnfrealloc(list,sizeof(resRange) * (++num));
+ PV_I_RANGE(list[num - 1],pvp,i,ResShrIoBlock | ResBios);
+ } else if (pvp->memBase[i]) {
+ list = xnfrealloc(list,sizeof(resRange) * (++num));
+ PV_M_RANGE(list[num - 1],pvp,i,ResShrMemBlock | ResBios);
+ }
+ }
+#if 0
+ if (pvp->biosBase) {
+ list = xnfrealloc(list,sizeof(resRange) * (++num));
+ PV_B_RANGE(list[num - 1],pvp,ResShrMemBlock | ResBios);
+ }
+#endif
+ list = xnfrealloc(list,sizeof(resRange) * (++num));
+ list[num - 1].type = ResEnd;
+
+ return list;
+}
+
+void
+initPciState(void)
+{
+ int i = 0;
+ int j = 0;
+ pciVideoPtr pvp;
+ pciAccPtr pcaccp;
+
+ if (xf86PciAccInfo != NULL)
+ return;
+
+ if (xf86PciVideoInfo == NULL)
+ return;
+
+ while ((pvp = xf86PciVideoInfo[i]) != NULL) {
+ i++;
+ j++;
+ xf86PciAccInfo = xnfrealloc(xf86PciAccInfo,
+ sizeof(pciAccPtr) * (j + 1));
+ xf86PciAccInfo[j] = NULL;
+ pcaccp = xf86PciAccInfo[j - 1] = xnfalloc(sizeof(pciAccRec));
+ pcaccp->busnum = pvp->bus;
+ pcaccp->devnum = pvp->device;
+ pcaccp->funcnum = pvp->func;
+ pcaccp->arg.tag = pciTag(pvp->bus, pvp->device, pvp->func);
+ pcaccp->ioAccess.AccessDisable = pciIoAccessDisable;
+ pcaccp->ioAccess.AccessEnable = pciIoAccessEnable;
+ pcaccp->ioAccess.arg = &pcaccp->arg;
+ pcaccp->io_memAccess.AccessDisable = pciIo_MemAccessDisable;
+ pcaccp->io_memAccess.AccessEnable = pciIo_MemAccessEnable;
+ pcaccp->io_memAccess.arg = &pcaccp->arg;
+ pcaccp->memAccess.AccessDisable = pciMemAccessDisable;
+ pcaccp->memAccess.AccessEnable = pciMemAccessEnable;
+ pcaccp->memAccess.arg = &pcaccp->arg;
+ if (PCISHAREDIOCLASSES(pvp->class, pvp->subclass))
+ pcaccp->ctrl = TRUE;
+ else
+ pcaccp->ctrl = FALSE;
+ savePciState(pcaccp->arg.tag, &pcaccp->save);
+ pcaccp->arg.ctrl = pcaccp->save.command;
+ }
+}
+
+/*
+ * initPciBusState() - fill out the BusAccRec for a PCI bus.
+ * Theory: each bus is associated with one bridge connecting it
+ * to its parent bus. The address of a bridge is therefore stored
+ * in the BusAccRec of the bus it connects to. Each bus can
+ * have several bridges connecting secondary buses to it. Only one
+ * of these bridges can be open. Therefore the status of a bridge
+ * associated with a bus is stored in the BusAccRec of the parent
+ * the bridge connects to. The first member of the structure is
+ * a pointer to a function that open access to this bus. This function
+ * receives a pointer to the structure itself as argument. This
+ * design should be common to BusAccRecs of any type of buses we
+ * support. The remeinder of the structure is bus type specific.
+ * In this case it contains a pointer to the structure of the
+ * parent bus. Thus enabling access to a specific bus is simple:
+ * 1. Close any bridge going to secondary buses.
+ * 2. Climb down the ladder and enable any bridge on buses
+ * on the path from the CPU to this bus.
+ */
+
+void
+initPciBusState(void)
+{
+ BusAccPtr pbap, pbap_tmp;
+ PciBusPtr pbp = xf86PciBus;
+ pciBusInfo_t *pBusInfo;
+
+ while (pbp) {
+ pbap = xnfcalloc(1,sizeof(BusAccRec));
+ pbap->busdep.pci.bus = pbp->secondary;
+ pbap->busdep.pci.primary_bus = pbp->primary;
+ pbap->busdep_type = BUS_PCI;
+ pbap->busdep.pci.acc = PCITAG_SPECIAL;
+
+ if ((pbp->secondary >= 0) && (pbp->secondary < pciNumBuses) &&
+ (pBusInfo = pciBusInfo[pbp->secondary]) &&
+ pBusInfo->funcs->pciControlBridge) {
+ pbap->type = BUS_PCI;
+ pbap->save_f = savePciDrvBusState;
+ pbap->restore_f = restorePciDrvBusState;
+ pbap->set_f = pciSetBusAccess;
+ pbap->enable_f = pciDrvBusAccessEnable;
+ pbap->disable_f = pciDrvBusAccessDisable;
+ savePciDrvBusState(pbap);
+ } else switch (pbp->subclass) {
+ case PCI_SUBCLASS_BRIDGE_HOST:
+ pbap->type = BUS_PCI;
+ pbap->set_f = pciSetBusAccess;
+ break;
+ case PCI_SUBCLASS_BRIDGE_PCI:
+ case PCI_SUBCLASS_BRIDGE_CARDBUS:
+ pbap->type = BUS_PCI;
+ pbap->save_f = savePciBusState;
+ pbap->restore_f = restorePciBusState;
+ pbap->set_f = pciSetBusAccess;
+ pbap->enable_f = pciBusAccessEnable;
+ pbap->disable_f = pciBusAccessDisable;
+ pbap->busdep.pci.acc = pciTag(pbp->brbus,pbp->brdev,pbp->brfunc);
+ savePciBusState(pbap);
+ break;
+ case PCI_SUBCLASS_BRIDGE_ISA:
+ case PCI_SUBCLASS_BRIDGE_EISA:
+ case PCI_SUBCLASS_BRIDGE_MC:
+ pbap->type = BUS_ISA;
+ pbap->set_f = pciSetBusAccess;
+ break;
+ }
+ pbap->next = xf86BusAccInfo;
+ xf86BusAccInfo = pbap;
+ pbp = pbp->next;
+ }
+
+ pbap = xf86BusAccInfo;
+
+ while (pbap) {
+ pbap->primary = NULL;
+ if (pbap->busdep_type == BUS_PCI
+ && pbap->busdep.pci.primary_bus > -1) {
+ pbap_tmp = xf86BusAccInfo;
+ while (pbap_tmp) {
+ if (pbap_tmp->busdep_type == BUS_PCI &&
+ pbap_tmp->busdep.pci.bus == pbap->busdep.pci.primary_bus) {
+ /* Don't create loops */
+ if (pbap == pbap_tmp)
+ break;
+ pbap->primary = pbap_tmp;
+ break;
+ }
+ pbap_tmp = pbap_tmp->next;
+ }
+ }
+ pbap = pbap->next;
+ }
+}
+
+void
+PciStateEnter(void)
+{
+ pciAccPtr paccp;
+ int i = 0;
+
+ if (xf86PciAccInfo == NULL)
+ return;
+
+ while ((paccp = xf86PciAccInfo[i]) != NULL) {
+ i++;
+ if (!paccp->ctrl)
+ continue;
+ savePciState(paccp->arg.tag, &paccp->save);
+ restorePciState(paccp->arg.tag, &paccp->restore);
+ paccp->arg.ctrl = paccp->restore.command;
+ }
+}
+
+void
+PciBusStateEnter(void)
+{
+ BusAccPtr pbap = xf86BusAccInfo;
+
+ while (pbap) {
+ if (pbap->save_f)
+ pbap->save_f(pbap);
+ pbap = pbap->next;
+ }
+}
+
+void
+PciStateLeave(void)
+{
+ pciAccPtr paccp;
+ int i = 0;
+
+ if (xf86PciAccInfo == NULL)
+ return;
+
+ while ((paccp = xf86PciAccInfo[i]) != NULL) {
+ i++;
+ if (!paccp->ctrl)
+ continue;
+ savePciState(paccp->arg.tag, &paccp->restore);
+ restorePciState(paccp->arg.tag, &paccp->save);
+ }
+}
+
+void
+PciBusStateLeave(void)
+{
+ BusAccPtr pbap = xf86BusAccInfo;
+
+ while (pbap) {
+ if (pbap->restore_f)
+ pbap->restore_f(pbap);
+ pbap = pbap->next;
+ }
+}
+
+void
+DisablePciAccess(void)
+{
+ int i = 0;
+ pciAccPtr paccp;
+ if (xf86PciAccInfo == NULL)
+ return;
+
+ while ((paccp = xf86PciAccInfo[i]) != NULL) {
+ i++;
+ if (!paccp->ctrl) /* disable devices that are under control initially*/
+ continue;
+ pciIo_MemAccessDisable(paccp->io_memAccess.arg);
+ }
+}
+
+void
+DisablePciBusAccess(void)
+{
+ BusAccPtr pbap = xf86BusAccInfo;
+
+ while (pbap) {
+ if (pbap->disable_f)
+ pbap->disable_f(pbap);
+ if (pbap->primary)
+ pbap->primary->current = NULL;
+ pbap = pbap->next;
+ }
+}
+
+/*
+ * Public functions
+ */
+
+Bool
+xf86IsPciDevPresent(int bus, int dev, int func)
+{
+ int i = 0;
+ pciConfigPtr pcp;
+
+ while ((pcp = xf86PciInfo[i]) != NULL) {
+ if ((pcp->busnum == bus)
+ && (pcp->devnum == dev)
+ && (pcp->funcnum == func))
+ return TRUE;
+ i++;
+ }
+ return FALSE;
+}
+
+/*
+ * If the slot requested is already in use, return -1.
+ * Otherwise, claim the slot for the screen requesting it.
+ */
+
+int
+xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp,
+ int chipset, GDevPtr dev, Bool active)
+{
+ EntityPtr p = NULL;
+ pciAccPtr *ppaccp = xf86PciAccInfo;
+ BusAccPtr pbap = xf86BusAccInfo;
+
+ int num;
+
+ if (xf86CheckPciSlot(bus, device, func)) {
+ num = xf86AllocateEntity();
+ p = xf86Entities[num];
+ p->driver = drvp;
+ p->chipset = chipset;
+ p->busType = BUS_PCI;
+ p->pciBusId.bus = bus;
+ p->pciBusId.device = device;
+ p->pciBusId.func = func;
+ p->active = active;
+ p->inUse = FALSE;
+ if (dev)
+ xf86AddDevToEntity(num, dev);
+ /* Here we initialize the access structure */
+ p->access = xnfcalloc(1,sizeof(EntityAccessRec));
+ while (ppaccp && *ppaccp) {
+ if ((*ppaccp)->busnum == bus
+ && (*ppaccp)->devnum == device
+ && (*ppaccp)->funcnum == func) {
+ p->access->fallback = &(*ppaccp)->io_memAccess;
+ p->access->pAccess = &(*ppaccp)->io_memAccess;
+ (*ppaccp)->ctrl = TRUE; /* mark control if not already */
+ break;
+ }
+ ppaccp++;
+ }
+ if (!ppaccp || !*ppaccp) {
+ p->access->fallback = &AccessNULL;
+ p->access->pAccess = &AccessNULL;
+ }
+
+ p->busAcc = NULL;
+ while (pbap) {
+ if (pbap->type == BUS_PCI && pbap->busdep.pci.bus == bus)
+ p->busAcc = pbap;
+ pbap = pbap->next;
+ }
+ fixPciSizeInfo(num);
+
+ /* in case bios is enabled disable it */
+ disablePciBios(pciTag(bus,device,func));
+ pciSlotClaimed = TRUE;
+
+ if (active) {
+ /* Map in this domain's I/O space */
+ p->domainIO = xf86MapDomainIO(-1, VIDMEM_MMIO,
+ pciTag(bus, device, func), 0, 1);
+ }
+
+ return num;
+ } else
+ return -1;
+}
+
+/*
+ * Get xf86PciVideoInfo for a driver.
+ */
+pciVideoPtr *
+xf86GetPciVideoInfo(void)
+{
+ return xf86PciVideoInfo;
+}
+
+/* --- Used by ATI driver, but also more generally useful */
+
+/*
+ * Get the full xf86scanpci data.
+ */
+pciConfigPtr *
+xf86GetPciConfigInfo(void)
+{
+ return xf86PciInfo;
+}
+
+/*
+ * Enable a device and route VGA to it. This is intended for a driver's
+ * Probe(), before creating EntityRec's. Only one device can be thus enabled
+ * at any one time, and should be disabled when the driver is done with it.
+ *
+ * The following special calls are also available:
+ *
+ * pvp == NULL && rt == NONE disable previously enabled device
+ * pvp != NULL && rt == NONE ensure device is disabled
+ * pvp == NULL && rt != NONE disable >all< subsequent calls to this function
+ * (done from xf86PostProbe())
+ * The last combination has been removed! To do this cleanly we have
+ * to implement stages and need to test at each stage dependent function
+ * if it is allowed to execute.
+ *
+ * The device represented by pvp may not have been previously claimed.
+ */
+void
+xf86SetPciVideo(pciVideoPtr pvp, resType rt)
+{
+ static BusAccPtr pbap = NULL;
+ static xf86AccessPtr pAcc = NULL;
+ static Bool DoneProbes = FALSE;
+ pciAccPtr pcaccp;
+ int i;
+
+ if (DoneProbes)
+ return;
+
+ /* Disable previous access */
+ if (pAcc) {
+ if (pAcc->AccessDisable)
+ (*pAcc->AccessDisable)(pAcc->arg);
+ pAcc = NULL;
+ }
+ if (pbap) {
+ while (pbap->primary) {
+ if (pbap->disable_f)
+ (*pbap->disable_f)(pbap);
+ pbap->primary->current = NULL;
+ pbap = pbap->primary;
+ }
+ pbap = NULL;
+ }
+
+ /* Check for xf86PostProbe's magic combo */
+ if (!pvp) {
+ if (rt != NONE)
+ DoneProbes = TRUE;
+ return;
+ }
+
+ /* Validate device */
+ if (!xf86PciVideoInfo || !xf86PciAccInfo || !xf86BusAccInfo)
+ return;
+
+ for (i = 0; pvp != xf86PciVideoInfo[i]; i++)
+ if (!xf86PciVideoInfo[i])
+ return;
+
+ /* Ignore request for claimed adapters */
+ if (!xf86CheckPciSlot(pvp->bus, pvp->device, pvp->func))
+ return;
+
+ /* Find pciAccRec structure */
+ for (i = 0; ; i++) {
+ if (!(pcaccp = xf86PciAccInfo[i]))
+ return;
+ if ((pvp->bus == pcaccp->busnum) &&
+ (pvp->device == pcaccp->devnum) &&
+ (pvp->func == pcaccp->funcnum))
+ break;
+ }
+
+ if (rt == NONE) {
+ /* This is a call to ensure the adapter is disabled */
+ if (pcaccp->io_memAccess.AccessDisable)
+ (*pcaccp->io_memAccess.AccessDisable)(pcaccp->io_memAccess.arg);
+ return;
+ }
+
+ /* Find BusAccRec structure */
+ for (pbap = xf86BusAccInfo; ; pbap = pbap->next) {
+ if (!pbap)
+ return;
+ if (pvp->bus == pbap->busdep.pci.bus)
+ break;
+ }
+
+ /* Route VGA */
+ if (pbap->set_f)
+ (*pbap->set_f)(pbap);
+
+ /* Enable device */
+ switch (rt) {
+ case IO:
+ pAcc = &pcaccp->ioAccess;
+ break;
+ case MEM_IO:
+ pAcc = &pcaccp->io_memAccess;
+ break;
+ case MEM:
+ pAcc = &pcaccp->memAccess;
+ break;
+ default: /* no compiler noise */
+ break;
+ }
+
+ if (pAcc && pAcc->AccessEnable)
+ (*pAcc->AccessEnable)(pAcc->arg);
+}
+
+/*
+ * Parse a BUS ID string, and return the PCI bus parameters if it was
+ * in the correct format for a PCI bus id.
+ */
+
+Bool
+xf86ParsePciBusString(const char *busID, int *bus, int *device, int *func)
+{
+ /*
+ * The format is assumed to be "bus[@domain]:device[:func]", where domain,
+ * bus, device and func are decimal integers. domain and func may be
+ * omitted and assumed to be zero, although doing this isn't encouraged.
+ */
+
+ char *p, *s, *d;
+ const char *id;
+ int i;
+
+ if (StringToBusType(busID, &id) != BUS_PCI)
+ return FALSE;
+
+ s = xstrdup(id);
+ p = strtok(s, ":");
+ if (p == NULL || *p == 0) {
+ xfree(s);
+ return FALSE;
+ }
+ d = strpbrk(p, "@");
+ if (d != NULL) {
+ *(d++) = 0;
+ for (i = 0; d[i] != 0; i++) {
+ if (!isdigit(d[i])) {
+ xfree(s);
+ return FALSE;
+ }
+ }
+ }
+ for (i = 0; p[i] != 0; i++) {
+ if (!isdigit(p[i])) {
+ xfree(s);
+ return FALSE;
+ }
+ }
+ *bus = atoi(p);
+ if (d != NULL && *d != 0)
+ *bus += atoi(d) << 8;
+ p = strtok(NULL, ":");
+ if (p == NULL || *p == 0) {
+ xfree(s);
+ return FALSE;
+ }
+ for (i = 0; p[i] != 0; i++) {
+ if (!isdigit(p[i])) {
+ xfree(s);
+ return FALSE;
+ }
+ }
+ *device = atoi(p);
+ *func = 0;
+ p = strtok(NULL, ":");
+ if (p == NULL || *p == 0) {
+ xfree(s);
+ return TRUE;
+ }
+ for (i = 0; p[i] != 0; i++) {
+ if (!isdigit(p[i])) {
+ xfree(s);
+ return FALSE;
+ }
+ }
+ *func = atoi(p);
+ xfree(s);
+ return TRUE;
+}
+
+/*
+ * Compare a BUS ID string with a PCI bus id. Return TRUE if they match.
+ */
+
+Bool
+xf86ComparePciBusString(const char *busID, int bus, int device, int func)
+{
+ int ibus, idevice, ifunc;
+
+ if (xf86ParsePciBusString(busID, &ibus, &idevice, &ifunc)) {
+ return bus == ibus && device == idevice && func == ifunc;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * xf86IsPrimaryPci() -- return TRUE if primary device
+ * is PCI and bus, dev and func numbers match.
+ */
+
+Bool
+xf86IsPrimaryPci(pciVideoPtr pPci)
+{
+ if (primaryBus.type != BUS_PCI) return FALSE;
+ return (pPci->bus == primaryBus.id.pci.bus &&
+ pPci->device == primaryBus.id.pci.device &&
+ pPci->func == primaryBus.id.pci.func);
+}
+
+/*
+ * xf86CheckPciGAType() -- return type of PCI graphics adapter.
+ */
+int
+xf86CheckPciGAType(pciVideoPtr pPci)
+{
+ int i = 0;
+ pciConfigPtr pcp;
+
+ while ((pcp = xf86PciInfo[i]) != NULL) {
+ if (pPci->bus == pcp->busnum && pPci->device == pcp->devnum
+ && pPci->func == pcp->funcnum) {
+ if (pcp->pci_base_class == PCI_CLASS_PREHISTORIC &&
+ pcp->pci_sub_class == PCI_SUBCLASS_PREHISTORIC_VGA)
+ return PCI_CHIP_VGA ;
+ if (pcp->pci_base_class == PCI_CLASS_DISPLAY &&
+ pcp->pci_sub_class == PCI_SUBCLASS_DISPLAY_VGA) {
+ if (pcp->pci_prog_if == 0)
+ return PCI_CHIP_VGA ;
+ if (pcp->pci_prog_if == 1)
+ return PCI_CHIP_8514;
+ }
+ return -1;
+ }
+ i++;
+ }
+ return -1;
+}
+
+/*
+ * xf86GetPciInfoForEntity() -- Get the pciVideoRec of entity.
+ */
+pciVideoPtr
+xf86GetPciInfoForEntity(int entityIndex)
+{
+ pciVideoPtr *ppPci;
+ EntityPtr p;
+
+ if (entityIndex >= xf86NumEntities)
+ return NULL;
+
+ p = xf86Entities[entityIndex];
+ if (p->busType != BUS_PCI)
+ return NULL;
+
+ for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
+ if (p->pciBusId.bus == (*ppPci)->bus &&
+ p->pciBusId.device == (*ppPci)->device &&
+ p->pciBusId.func == (*ppPci)->func)
+ return (*ppPci);
+ }
+ return NULL;
+}
+
+int
+xf86GetPciEntity(int bus, int dev, int func)
+{
+ int i;
+
+ for (i = 0; i < xf86NumEntities; i++) {
+ EntityPtr p = xf86Entities[i];
+ if (p->busType != BUS_PCI) continue;
+
+ if (p->pciBusId.bus == bus &&
+ p->pciBusId.device == dev &&
+ p->pciBusId.func == func)
+ return i;
+ }
+ return -1;
+}
+
+/*
+ * xf86CheckPciMemBase() checks that the memory base value matches one of the
+ * PCI base address register values for the given PCI device.
+ */
+Bool
+xf86CheckPciMemBase(pciVideoPtr pPci, memType base)
+{
+ int i;
+
+ for (i = 0; i < 6; i++)
+ if (base == pPci->memBase[i])
+ return TRUE;
+ return FALSE;
+}
+
+/*
+ * Check if the slot requested is free. If it is already in use, return FALSE.
+ */
+
+Bool
+xf86CheckPciSlot(int bus, int device, int func)
+{
+ int i;
+ EntityPtr p;
+
+ for (i = 0; i < xf86NumEntities; i++) {
+ p = xf86Entities[i];
+ /* Check if this PCI slot is taken */
+ if (p->busType == BUS_PCI && p->pciBusId.bus == bus &&
+ p->pciBusId.device == device && p->pciBusId.func == func)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * This used to load the scanpci module. The pcidata module is now used
+ * (which the server always loads early). The main difference between the
+ * two modules is size, and the scanpci module should only ever be loaded
+ * when the X server is run with the -scanpci flag.
+ *
+ * To make sure that the required information is present in the pcidata
+ * module, add a PCI_VENDOR_* macro for the relevant vendor to xf86PciInfo.h,
+ * and add the class override data to ../etc/extrapci.ids.
+ */
+
+static void
+getPciClassFlags(pciConfigPtr *pcrpp)
+{
+ pciConfigPtr pcrp;
+ int i = 0;
+
+ if (!pcrpp)
+ return;
+ while ((pcrp = pcrpp[i])) {
+ if (!(pcrp->listed_class =
+ xf86FindPciClassBySubsys(pcrp->pci_subsys_vendor,
+ pcrp->pci_subsys_card))) {
+ pcrp->listed_class =
+ xf86FindPciClassByDevice(pcrp->pci_vendor, pcrp->pci_device);
+ }
+ i++;
+ }
+}
+
+/*
+ * xf86FindPciVendorDevice() xf86FindPciClass(): These functions
+ * are meant to be used by the pci bios emulation. Some bioses
+ * need to see if there are _other_ chips of the same type around
+ * so by setting pvp_exclude one pci device can be explicitely
+ * _excluded if required.
+ */
+pciVideoPtr
+xf86FindPciDeviceVendor(CARD16 vendorID, CARD16 deviceID,
+ char n, pciVideoPtr pvp_exclude)
+{
+ pciVideoPtr pvp, *ppvp;
+ n++;
+
+ for (ppvp = xf86PciVideoInfo, pvp =*ppvp; pvp ; pvp = *(++ppvp)) {
+ if (pvp == pvp_exclude) continue;
+ if ((pvp->vendor == vendorID) && (pvp->chipType == deviceID)) {
+ if (!(--n)) break;
+ }
+ }
+ return pvp;
+}
+
+pciVideoPtr
+xf86FindPciClass(CARD8 intf, CARD8 subClass, CARD16 class,
+ char n, pciVideoPtr pvp_exclude)
+{
+ pciVideoPtr pvp, *ppvp;
+ n++;
+
+ for (ppvp = xf86PciVideoInfo, pvp =*ppvp; pvp ; pvp = *(++ppvp)) {
+ if (pvp == pvp_exclude) continue;
+ if ((pvp->interface == intf) && (pvp->subclass == subClass)
+ && (pvp->class == class)) {
+ if (!(--n)) break;
+ }
+ }
+ return pvp;
+}
+
+/*
+ * This attempts to detect a multi-device card and sets up a list
+ * of pci tags of the devices of this card. On some of these
+ * cards the BIOS is not visible from all chipsets. We therefore
+ * need to use the BIOS from a chipset where it is visible.
+ * We do the following heuristics:
+ * If we detect only identical pci devices on a bus we assume it's
+ * a multi-device card. This assumption isn't true always, however.
+ * One might just use identical cards on a bus. We therefore don't
+ * detect this situation when we set up the PCI video info. Instead
+ * we wait until an attempt to read the BIOS fails.
+ */
+int
+pciTestMultiDeviceCard(int bus, int dev, int func, PCITAG** pTag)
+{
+ pciConfigPtr *ppcrp = xf86PciInfo;
+ pciConfigPtr pcrp = NULL;
+ int i,j;
+ Bool multicard = FALSE;
+ Bool multifunc = FALSE;
+ char str[256];
+ char *str1;
+
+ str1 = str;
+ if (!pTag)
+ return 0;
+
+ *pTag = NULL;
+
+ for (i=0; i < 8; i++) {
+ j = 0;
+
+ while (ppcrp[j]) {
+ if (ppcrp[j]->busnum == bus && ppcrp[j]->funcnum == i) {
+ pcrp = ppcrp[j];
+ break;
+ }
+ j++;
+ }
+
+ if (!pcrp) return 0;
+
+ /*
+ * we check all functions here: since multifunc devices need
+ * to implement func 0 we catch all devices on the bus when
+ * i = 0
+ */
+ if (pcrp->pci_header_type &0x80)
+ multifunc = TRUE;
+
+ j = 0;
+
+ while (ppcrp[j]) {
+ if (ppcrp[j]->busnum == bus && ppcrp[j]->funcnum == i
+ && ppcrp[j]->devnum != pcrp->devnum) {
+ /* don't test subsys ID here. It might be set by POST
+ - however some cards might not have been POSTed */
+ if (ppcrp[j]->pci_device_vendor != pcrp->pci_device_vendor
+ || ppcrp[j]->pci_header_type != pcrp->pci_header_type )
+ return 0;
+ else
+ multicard = TRUE;
+ }
+ j++;
+ }
+ if (!multifunc)
+ break;
+ }
+
+ if (!multicard)
+ return 0;
+
+ j = 0;
+ i = 0;
+ while (ppcrp[i]) {
+ if (ppcrp[i]->busnum == bus && ppcrp[i]->funcnum == func) {
+ str1 += sprintf(str1,"[%x:%x:%x]",ppcrp[i]->busnum,
+ ppcrp[i]->devnum,ppcrp[i]->funcnum);
+ *pTag = xnfrealloc(*pTag,sizeof(PCITAG) * (j + 1));
+ (*pTag)[j++] = pciTag(ppcrp[i]->busnum,
+ ppcrp[i]->devnum,ppcrp[i]->funcnum);
+ }
+ i++;
+ }
+ xf86MsgVerb(X_INFO,3,"Multi Device Card detected: %s\n",str);
+ return j;
+}
+
+static void
+pciTagConvertRange2Host(PCITAG tag, resRange *pRange)
+{
+ if (!(pRange->type & ResBus))
+ return;
+
+ switch(pRange->type & ResPhysMask) {
+ case ResMem:
+ switch(pRange->type & ResExtMask) {
+ case ResBlock:
+ pRange->rBegin = pciBusAddrToHostAddr(tag,PCI_MEM, pRange->rBegin);
+ pRange->rEnd = pciBusAddrToHostAddr(tag,PCI_MEM, pRange->rEnd);
+ break;
+ case ResSparse:
+ pRange->rBase = pciBusAddrToHostAddr(tag,PCI_MEM_SPARSE_BASE,
+ pRange->rBegin);
+ pRange->rMask = pciBusAddrToHostAddr(tag,PCI_MEM_SPARSE_MASK,
+ pRange->rEnd);
+ break;
+ }
+ break;
+ case ResIo:
+ switch(pRange->type & ResExtMask) {
+ case ResBlock:
+ pRange->rBegin = pciBusAddrToHostAddr(tag,PCI_IO, pRange->rBegin);
+ pRange->rEnd = pciBusAddrToHostAddr(tag,PCI_IO, pRange->rEnd);
+ break;
+ case ResSparse:
+ pRange->rBase = pciBusAddrToHostAddr(tag,PCI_IO_SPARSE_BASE
+ , pRange->rBegin);
+ pRange->rMask = pciBusAddrToHostAddr(tag,PCI_IO_SPARSE_MASK
+ , pRange->rEnd);
+ break;
+ }
+ break;
+ }
+
+ /* Set domain number */
+ pRange->type &= ~(ResDomain | ResBus);
+ pRange->type |= xf86GetPciDomain(tag) << 24;
+}
+
+static void
+pciConvertListToHost(int bus, int dev, int func, resPtr list)
+{
+ PCITAG tag = pciTag(bus,dev,func);
+ while (list) {
+ pciTagConvertRange2Host(tag, &list->val);
+ list = list->next;
+ }
+}
+
+static void
+updateAccessInfoStatusControlInfo(PCITAG tag, CARD32 ctrl)
+{
+ int i;
+
+ if (!xf86PciAccInfo)
+ return;
+
+ for (i = 0; xf86PciAccInfo[i] != NULL; i++) {
+ if (xf86PciAccInfo[i]->arg.tag == tag)
+ xf86PciAccInfo[i]->arg.ctrl = ctrl;
+ }
+}
+
+void
+pciConvertRange2Host(int entityIndex, resRange *pRange)
+{
+ PCITAG tag;
+ pciVideoPtr pvp;
+
+ pvp = xf86GetPciInfoForEntity(entityIndex);
+ if (!pvp) return;
+ tag = TAG(pvp);
+ pciTagConvertRange2Host(tag, pRange);
+}
+
+
+#ifdef INCLUDE_DEPRECATED
+void
+xf86EnablePciBusMaster(pciVideoPtr pPci, Bool enable)
+{
+ CARD32 temp;
+ PCITAG tag;
+
+ if (!pPci) return;
+
+ tag = pciTag(pPci->bus, pPci->device, pPci->func);
+ temp = pciReadLong(tag, PCI_CMD_STAT_REG);
+ if (enable) {
+ updateAccessInfoStatusControlInfo(tag, temp | PCI_CMD_MASTER_ENABLE);
+ pciWriteLong(tag, PCI_CMD_STAT_REG, temp | PCI_CMD_MASTER_ENABLE);
+ } else {
+ updateAccessInfoStatusControlInfo(tag, temp & ~PCI_CMD_MASTER_ENABLE);
+ pciWriteLong(tag, PCI_CMD_STAT_REG, temp & ~PCI_CMD_MASTER_ENABLE);
+ }
+}
+#endif /* INCLUDE_DEPRECATED */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86pciBus.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86pciBus.h
new file mode 100644
index 000000000..75d82fbcf
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86pciBus.h
@@ -0,0 +1,99 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86pciBus.h,v 3.10 2003/08/24 17:36:56 dawes Exp $ */
+
+/*
+ * Copyright (c) 1999-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_PCI_BUS_H
+#define _XF86_PCI_BUS_H
+
+#define PCITAG_SPECIAL pciTag(0xFF,0xFF,0xFF)
+
+typedef struct {
+ CARD32 command;
+ CARD32 base[6];
+ CARD32 biosBase;
+} pciSave, *pciSavePtr;
+
+typedef struct {
+ PCITAG tag;
+ CARD32 ctrl;
+} pciArg;
+
+typedef struct {
+ int busnum;
+ int devnum;
+ int funcnum;
+ pciArg arg;
+ xf86AccessRec ioAccess;
+ xf86AccessRec io_memAccess;
+ xf86AccessRec memAccess;
+ pciSave save;
+ pciSave restore;
+ Bool ctrl;
+} pciAccRec, *pciAccPtr;
+
+typedef union {
+ CARD16 control;
+} pciBridgesSave, *pciBridgesSavePtr;
+
+typedef struct pciBusRec {
+ int brbus, brdev, brfunc; /* ID of the bridge to this bus */
+ int primary, secondary, subordinate;
+ int subclass; /* bridge type */
+ int interface;
+ resPtr preferred_io; /* I/O range */
+ resPtr preferred_mem; /* non-prefetchable memory range */
+ resPtr preferred_pmem; /* prefetchable memory range */
+ resPtr io; /* for subtractive PCI-PCI bridges */
+ resPtr mem;
+ resPtr pmem;
+ int brcontrol; /* bridge_control byte */
+ struct pciBusRec *next;
+} PciBusRec, *PciBusPtr;
+
+void xf86PciProbe(void);
+void ValidatePci(void);
+resList GetImplicitPciResources(int entityIndex);
+void initPciState(void);
+void initPciBusState(void);
+void DisablePciAccess(void);
+void DisablePciBusAccess(void);
+void PciStateEnter(void);
+void PciBusStateEnter(void);
+void PciStateLeave(void);
+void PciBusStateLeave(void);
+resPtr ResourceBrokerInitPci(resPtr *osRes);
+void pciConvertRange2Host(int entityIndex, resRange *pRange);
+void isaConvertRange2Host(resRange *pRange);
+
+extern pciAccPtr * xf86PciAccInfo;
+
+#endif /* _XF86_PCI_BUS_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86sbusBus.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86sbusBus.c
new file mode 100644
index 000000000..3d6576f52
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86sbusBus.c
@@ -0,0 +1,709 @@
+/*
+ * SBUS bus-specific code.
+ *
+ * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
+ *
+ * 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
+ * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86sbusBus.c,v 3.6 2001/03/03 22:16:35 tsi Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Resources.h"
+#include "xf86cmap.h"
+
+#include "xf86Bus.h"
+
+#include "xf86sbusBus.h"
+#include "xf86Sbus.h"
+
+Bool sbusSlotClaimed = FALSE;
+
+static int xf86nSbusInfo;
+
+static void
+CheckSbusDevice(const char *device, int fbNum)
+{
+ int fd, i;
+ struct fbgattr fbattr;
+ sbusDevicePtr psdp;
+
+ fd = open(device, O_RDONLY, 0);
+ if (fd < 0)
+ return;
+ memset(&fbattr, 0, sizeof(fbattr));
+ if (ioctl(fd, FBIOGATTR, &fbattr) < 0) {
+ if (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0) {
+ close(fd);
+ return;
+ }
+ }
+ close(fd);
+ for (i = 0; sbusDeviceTable[i].devId; i++)
+ if (sbusDeviceTable[i].fbType == fbattr.fbtype.fb_type)
+ break;
+ if (! sbusDeviceTable[i].devId)
+ return;
+ xf86SbusInfo = xnfrealloc(xf86SbusInfo, sizeof(psdp) * (++xf86nSbusInfo + 1));
+ xf86SbusInfo[xf86nSbusInfo] = NULL;
+ xf86SbusInfo[xf86nSbusInfo - 1] = psdp = xnfcalloc(sizeof (sbusDevice), 1);
+ psdp->devId = sbusDeviceTable[i].devId;
+ psdp->fbNum = fbNum;
+ psdp->device = xnfstrdup(device);
+ psdp->width = fbattr.fbtype.fb_width;
+ psdp->height = fbattr.fbtype.fb_height;
+ psdp->fd = -1;
+}
+
+void
+xf86SbusProbe(void)
+{
+ int i, useProm = 0;
+ char fbDevName[32];
+ sbusDevicePtr psdp, *psdpp;
+
+ xf86SbusInfo = xalloc(sizeof(psdp));
+ *xf86SbusInfo = NULL;
+ for (i = 0; i < 32; i++) {
+ sprintf(fbDevName, "/dev/fb%d", i);
+ CheckSbusDevice(fbDevName, i);
+ }
+ if (sparcPromInit() >= 0) {
+ useProm = 1;
+ sparcPromAssignNodes();
+ }
+ for (psdpp = xf86SbusInfo; (psdp = *psdpp); psdpp++) {
+ for (i = 0; sbusDeviceTable[i].devId; i++)
+ if (sbusDeviceTable[i].devId == psdp->devId)
+ psdp->descr = sbusDeviceTable[i].descr;
+ /*
+ * If we can use PROM information and found the PROM node for this
+ * device, we can tell more about the card.
+ */
+ if (useProm && psdp->node.node) {
+ char *prop, *promPath;
+ int len, chiprev, vmsize;
+
+ switch (psdp->devId) {
+ case SBUS_DEVICE_MGX:
+ prop = sparcPromGetProperty(&psdp->node, "fb_size", &len);
+ if (prop && len == 4 && *(int *)prop == 0x400000)
+ psdp->descr = "Quantum 3D MGXplus with 4M VRAM";
+ break;
+ case SBUS_DEVICE_CG6:
+ chiprev = 0;
+ vmsize = 0;
+ prop = sparcPromGetProperty(&psdp->node, "chiprev", &len);
+ if (prop && len == 4)
+ chiprev = *(int *)prop;
+ prop = sparcPromGetProperty(&psdp->node, "vmsize", &len);
+ if (prop && len == 4)
+ vmsize = *(int *)prop;
+ switch (chiprev) {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ psdp->descr = "Sun Double width GX"; break;
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ psdp->descr = "Sun Single width GX"; break;
+ case 11:
+ switch (vmsize) {
+ case 2:
+ psdp->descr = "Sun Turbo GX with 1M VSIMM"; break;
+ case 4:
+ psdp->descr = "Sun Turbo GX Plus"; break;
+ default:
+ psdp->descr = "Sun Turbo GX"; break;
+ }
+ }
+ break;
+ case SBUS_DEVICE_CG14:
+ prop = sparcPromGetProperty(&psdp->node, "reg", &len);
+ vmsize = 0;
+ if (prop && !(len % 12) && len > 0)
+ vmsize = *(int *)(prop + len - 4);
+ switch (vmsize) {
+ case 0x400000:
+ psdp->descr = "Sun SX with 4M VSIMM"; break;
+ case 0x800000:
+ psdp->descr = "Sun SX with 8M VSIMM"; break;
+ }
+ break;
+ case SBUS_DEVICE_LEO:
+ prop = sparcPromGetProperty(&psdp->node, "model", &len);
+ if (prop && len > 0 && !strstr(prop, "501-2503"))
+ psdp->descr = "Sun Turbo ZX";
+ break;
+ case SBUS_DEVICE_TCX:
+ if (sparcPromGetBool(&psdp->node, "tcx-8-bit"))
+ psdp->descr = "Sun TCX (8bit)";
+ else
+ psdp->descr = "Sun TCX (S24)";
+ break;
+ case SBUS_DEVICE_FFB:
+ prop = sparcPromGetProperty(&psdp->node, "name", &len);
+ chiprev = 0;
+ prop = sparcPromGetProperty(&psdp->node, "board_type", &len);
+ if (prop && len == 4)
+ chiprev = *(int *)prop;
+ if (strstr (prop, "afb")) {
+ if (chiprev == 3)
+ psdp->descr = "Sun|Elite3D-M6 Horizontal";
+ } else {
+ switch (chiprev) {
+ case 0x08:
+ psdp->descr = "Sun FFB 67MHz Creator"; break;
+ case 0x0b:
+ psdp->descr = "Sun FFB 67MHz Creator 3D"; break;
+ case 0x1b:
+ psdp->descr = "Sun FFB 75MHz Creator 3D"; break;
+ case 0x20:
+ case 0x28:
+ psdp->descr = "Sun FFB2 Vertical Creator"; break;
+ case 0x23:
+ case 0x2b:
+ psdp->descr = "Sun FFB2 Vertical Creator 3D"; break;
+ case 0x30:
+ psdp->descr = "Sun FFB2+ Vertical Creator"; break;
+ case 0x33:
+ psdp->descr = "Sun FFB2+ Vertical Creator 3D"; break;
+ case 0x40:
+ case 0x48:
+ psdp->descr = "Sun FFB2 Horizontal Creator"; break;
+ case 0x43:
+ case 0x4b:
+ psdp->descr = "Sun FFB2 Horizontal Creator 3D"; break;
+ }
+ }
+ break;
+ }
+
+ xf86Msg(X_PROBED, "SBUS:(0x%08x) %s", psdp->node.node, psdp->descr);
+ promPath = sparcPromNode2Pathname (&psdp->node);
+ if (promPath) {
+ xf86ErrorF(" at %s", promPath);
+ xfree(promPath);
+ }
+ } else
+ xf86Msg(X_PROBED, "SBUS: %s", psdp->descr);
+ xf86ErrorF("\n");
+ }
+ if (useProm)
+ sparcPromClose();
+}
+
+/*
+ * Parse a BUS ID string, and return the SBUS bus parameters if it was
+ * in the correct format for a SBUS bus id.
+ */
+
+Bool
+xf86ParseSbusBusString(const char *busID, int *fbNum)
+{
+ /*
+ * The format is assumed to be one of:
+ * "fbN", e.g. "fb1", which means the device corresponding to /dev/fbN
+ * "nameN", e.g. "cgsix0", which means Nth instance of card NAME
+ * "/prompath", e.g. "/sbus@0,10001000/cgsix@3,0" which is PROM pathname
+ * to the device.
+ */
+
+ const char *id;
+ int i, len;
+
+ if (StringToBusType(busID, &id) != BUS_SBUS)
+ return FALSE;
+
+ if (*id != '/') {
+ if (!strncmp (id, "fb", 2)) {
+ if (!isdigit(id[2]))
+ return FALSE;
+ *fbNum = atoi(id + 2);
+ return TRUE;
+ } else {
+ sbusDevicePtr *psdpp;
+ int devId;
+
+ for (i = 0, len = 0; sbusDeviceTable[i].devId; i++) {
+ len = strlen(sbusDeviceTable[i].promName);
+ if (!strncmp (sbusDeviceTable[i].promName, id, len)
+ && isdigit(id[len]))
+ break;
+ }
+ devId = sbusDeviceTable[i].devId;
+ if (!devId) return FALSE;
+ i = atoi(id + len);
+ for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) {
+ if ((*psdpp)->devId != devId)
+ continue;
+ if (!i) {
+ *fbNum = (*psdpp)->fbNum;
+ return TRUE;
+ }
+ i--;
+ }
+ }
+ return FALSE;
+ }
+
+ if (sparcPromInit() >= 0) {
+ i = sparcPromPathname2Node(id);
+ sparcPromClose();
+ if (i) {
+ sbusDevicePtr *psdpp;
+ for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) {
+ if ((*psdpp)->node.node == i) {
+ *fbNum = (*psdpp)->fbNum;
+ return TRUE;
+ }
+ }
+ }
+ }
+ return FALSE;
+}
+
+/*
+ * Compare a BUS ID string with a SBUS bus id. Return TRUE if they match.
+ */
+
+Bool
+xf86CompareSbusBusString(const char *busID, int fbNum)
+{
+ int iFbNum;
+
+ if (xf86ParseSbusBusString(busID, &iFbNum)) {
+ return fbNum == iFbNum;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * Check if the slot requested is free. If it is already in use, return FALSE.
+ */
+
+Bool
+xf86CheckSbusSlot(int fbNum)
+{
+ int i;
+ EntityPtr p;
+
+ for (i = 0; i < xf86NumEntities; i++) {
+ p = xf86Entities[i];
+ /* Check if this SBUS slot is taken */
+ if (p->busType == BUS_SBUS && p->sbusBusId.fbNum == fbNum)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*
+ * If the slot requested is already in use, return -1.
+ * Otherwise, claim the slot for the screen requesting it.
+ */
+
+int
+xf86ClaimSbusSlot(sbusDevicePtr psdp, DriverPtr drvp,
+ GDevPtr dev, Bool active)
+{
+ EntityPtr p = NULL;
+
+ int num;
+
+ if (xf86CheckSbusSlot(psdp->fbNum)) {
+ num = xf86AllocateEntity();
+ p = xf86Entities[num];
+ p->driver = drvp;
+ p->chipset = -1;
+ p->busType = BUS_SBUS;
+ xf86AddDevToEntity(num, dev);
+ p->sbusBusId.fbNum = psdp->fbNum;
+ p->active = active;
+ p->inUse = FALSE;
+ /* Here we initialize the access structure */
+ p->access = xnfcalloc(1,sizeof(EntityAccessRec));
+ p->access->fallback = &AccessNULL;
+ p->access->pAccess = &AccessNULL;
+ sbusSlotClaimed = TRUE;
+ return num;
+ } else
+ return -1;
+}
+
+int
+xf86MatchSbusInstances(const char *driverName, int sbusDevId,
+ GDevPtr *devList, int numDevs, DriverPtr drvp,
+ int **foundEntities)
+{
+ int i,j;
+ sbusDevicePtr psdp, *psdpp;
+ int numClaimedInstances = 0;
+ int allocatedInstances = 0;
+ int numFound = 0;
+ GDevPtr devBus = NULL;
+ GDevPtr dev = NULL;
+ int *retEntities = NULL;
+ int useProm = 0;
+
+ struct Inst {
+ sbusDevicePtr sbus;
+ GDevPtr dev;
+ Bool claimed; /* BusID matches with a device section */
+ } *instances = NULL;
+
+ *foundEntities = NULL;
+ for (psdpp = xf86SbusInfo, psdp = *psdpp; psdp; psdp = *++psdpp) {
+ if (psdp->devId != sbusDevId)
+ continue;
+ if (psdp->fd == -2)
+ continue;
+ ++allocatedInstances;
+ instances = xnfrealloc(instances,
+ allocatedInstances * sizeof(struct Inst));
+ instances[allocatedInstances - 1].sbus = psdp;
+ instances[allocatedInstances - 1].dev = NULL;
+ instances[allocatedInstances - 1].claimed = FALSE;
+ numFound++;
+ }
+
+ /*
+ * This may be debatable, but if no SBUS devices with a matching vendor
+ * type is found, return zero now. It is probably not desirable to
+ * allow the config file to override this.
+ */
+ if (allocatedInstances <= 0) {
+ xfree(instances);
+ return 0;
+ }
+
+ if (xf86DoProbe) {
+ xfree(instances);
+ return numFound;
+ }
+
+ if (sparcPromInit() >= 0)
+ useProm = 1;
+
+ if (xf86DoConfigure && xf86DoConfigurePass1) {
+ GDevPtr pGDev;
+ int actualcards = 0;
+ for (i = 0; i < allocatedInstances; i++) {
+ actualcards++;
+ pGDev = xf86AddBusDeviceToConfigure(drvp->driverName, BUS_SBUS,
+ instances[i].sbus, -1);
+ if (pGDev) {
+ /*
+ * XF86Match???Instances() treat chipID and chipRev as
+ * overrides, so clobber them here.
+ */
+ pGDev->chipID = pGDev->chipRev = -1;
+ }
+ }
+ xfree(instances);
+ if (useProm)
+ sparcPromClose();
+ return actualcards;
+ }
+
+#ifdef DEBUG
+ ErrorF("%s instances found: %d\n", driverName, allocatedInstances);
+#endif
+
+ for (i = 0; i < allocatedInstances; i++) {
+ char *promPath = NULL;
+
+ psdp = instances[i].sbus;
+ devBus = NULL;
+ dev = NULL;
+ if (useProm && psdp->node.node)
+ promPath = sparcPromNode2Pathname(&psdp->node);
+
+ for (j = 0; j < numDevs; j++) {
+ if (devList[j]->busID && *devList[j]->busID) {
+ if (xf86CompareSbusBusString(devList[j]->busID, psdp->fbNum)) {
+ if (devBus)
+ xf86MsgVerb(X_WARNING,0,
+ "%s: More than one matching Device section for "
+ "instance (BusID: %s) found: %s\n",
+ driverName,devList[j]->identifier,
+ devList[j]->busID);
+ else
+ devBus = devList[j];
+ }
+ } else {
+ if (!dev && !devBus) {
+ if (promPath)
+ xf86Msg(X_PROBED, "Assigning device section with no busID to SBUS:%s\n",
+ promPath);
+ else
+ xf86Msg(X_PROBED, "Assigning device section with no busID to SBUS:fb%d\n",
+ psdp->fbNum);
+ dev = devList[j];
+ } else
+ xf86MsgVerb(X_WARNING, 0,
+ "%s: More than one matching Device section "
+ "found: %s\n", driverName, devList[j]->identifier);
+ }
+ }
+ if (devBus) dev = devBus; /* busID preferred */
+ if (!dev && psdp->fd != -2) {
+ if (promPath) {
+ xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section "
+ "for instance (BusID SBUS:%s) found\n",
+ driverName, promPath);
+ } else
+ xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section "
+ "for instance (BusID SBUS:fb%d) found\n",
+ driverName, psdp->fbNum);
+ } else if (dev) {
+ numClaimedInstances++;
+ instances[i].claimed = TRUE;
+ instances[i].dev = dev;
+ }
+ if (promPath)
+ xfree(promPath);
+ }
+
+#ifdef DEBUG
+ ErrorF("%s instances found: %d\n", driverName, numClaimedInstances);
+#endif
+
+ /*
+ * Of the claimed instances, check that another driver hasn't already
+ * claimed its slot.
+ */
+ numFound = 0;
+ for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) {
+ if (!instances[i].claimed)
+ continue;
+ psdp = instances[i].sbus;
+ if (!xf86CheckSbusSlot(psdp->fbNum))
+ continue;
+
+#ifdef DEBUG
+ ErrorF("%s: card at fb%d %08x is claimed by a Device section\n",
+ driverName, psdp->fbNum, psdp->node.node);
+#endif
+
+ /* Allocate an entry in the lists to be returned */
+ numFound++;
+ retEntities = xnfrealloc(retEntities, numFound * sizeof(int));
+ retEntities[numFound - 1]
+ = xf86ClaimSbusSlot(psdp, drvp, instances[i].dev,instances[i].dev->active ?
+ TRUE : FALSE);
+ }
+ xfree(instances);
+ if (numFound > 0) {
+ *foundEntities = retEntities;
+ }
+
+ if (useProm)
+ sparcPromClose();
+
+ return numFound;
+}
+
+/*
+ * xf86GetSbusInfoForEntity() -- Get the sbusDevicePtr of entity.
+ */
+sbusDevicePtr
+xf86GetSbusInfoForEntity(int entityIndex)
+{
+ sbusDevicePtr *psdpp;
+ EntityPtr p = xf86Entities[entityIndex];
+
+ if (entityIndex >= xf86NumEntities
+ || p->busType != BUS_SBUS) return NULL;
+
+ for (psdpp = xf86SbusInfo; *psdpp != NULL; psdpp++) {
+ if (p->sbusBusId.fbNum == (*psdpp)->fbNum)
+ return (*psdpp);
+ }
+ return NULL;
+}
+
+int
+xf86GetEntityForSbusInfo(sbusDevicePtr psdp)
+{
+ int i;
+
+ for (i = 0; i < xf86NumEntities; i++) {
+ EntityPtr p = xf86Entities[i];
+ if (p->busType != BUS_SBUS) continue;
+
+ if (p->sbusBusId.fbNum == psdp->fbNum)
+ return i;
+ }
+ return -1;
+}
+
+void
+xf86SbusUseBuiltinMode(ScrnInfoPtr pScrn, sbusDevicePtr psdp)
+{
+ DisplayModePtr mode;
+
+ mode = xnfcalloc(sizeof(DisplayModeRec), 1);
+ mode->name = "current";
+ mode->next = mode;
+ mode->prev = mode;
+ mode->type = M_T_BUILTIN;
+ mode->Clock = 100000000;
+ mode->HDisplay = psdp->width;
+ mode->HSyncStart = psdp->width;
+ mode->HSyncEnd = psdp->width;
+ mode->HTotal = psdp->width;
+ mode->VDisplay = psdp->height;
+ mode->VSyncStart = psdp->height;
+ mode->VSyncEnd = psdp->height;
+ mode->VTotal = psdp->height;
+ mode->SynthClock = mode->Clock;
+ mode->CrtcHDisplay = mode->HDisplay;
+ mode->CrtcHSyncStart = mode->HSyncStart;
+ mode->CrtcHSyncEnd = mode->HSyncEnd;
+ mode->CrtcHTotal = mode->HTotal;
+ mode->CrtcVDisplay = mode->VDisplay;
+ mode->CrtcVSyncStart = mode->VSyncStart;
+ mode->CrtcVSyncEnd = mode->VSyncEnd;
+ mode->CrtcVTotal = mode->VTotal;
+ mode->CrtcHAdjusted = FALSE;
+ mode->CrtcVAdjusted = FALSE;
+ pScrn->modes = mode;
+ pScrn->virtualX = psdp->width;
+ pScrn->virtualY = psdp->height;
+}
+
+static int sbusPaletteIndex = -1;
+static unsigned long sbusPaletteGeneration = 0;
+typedef struct _sbusCmap {
+ sbusDevicePtr psdp;
+ CloseScreenProcPtr CloseScreen;
+ Bool origCmapValid;
+ unsigned char origRed[16];
+ unsigned char origGreen[16];
+ unsigned char origBlue[16];
+} sbusCmapRec, *sbusCmapPtr;
+
+#define SBUSCMAPPTR(pScreen) ((sbusCmapPtr)((pScreen)->devPrivates[sbusPaletteIndex].ptr))
+
+static void
+xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
+ LOCO *colors, VisualPtr pVisual)
+{
+ int i, index;
+ sbusCmapPtr cmap;
+ struct fbcmap fbcmap;
+ unsigned char *data = ALLOCATE_LOCAL(numColors*3);
+
+ cmap = SBUSCMAPPTR(pScrn->pScreen);
+ if (!cmap) return;
+ fbcmap.count = 0;
+ fbcmap.index = indices[0];
+ fbcmap.red = data;
+ fbcmap.green = data + numColors;
+ fbcmap.blue = fbcmap.green + numColors;
+ for (i = 0; i < numColors; i++) {
+ index = indices[i];
+ if (fbcmap.count && index != fbcmap.index + fbcmap.count) {
+ ioctl (cmap->psdp->fd, FBIOPUTCMAP, &fbcmap);
+ fbcmap.count = 0;
+ fbcmap.index = index;
+ }
+ fbcmap.red[fbcmap.count] = colors[index].red;
+ fbcmap.green[fbcmap.count] = colors[index].green;
+ fbcmap.blue[fbcmap.count++] = colors[index].blue;
+ }
+ ioctl (cmap->psdp->fd, FBIOPUTCMAP, &fbcmap);
+ DEALLOCATE_LOCAL(data);
+}
+
+static Bool
+xf86SbusCmapCloseScreen(int i, ScreenPtr pScreen)
+{
+ sbusCmapPtr cmap;
+ struct fbcmap fbcmap;
+
+ cmap = SBUSCMAPPTR(pScreen);
+ if (cmap->origCmapValid) {
+ fbcmap.index = 0;
+ fbcmap.count = 16;
+ fbcmap.red = cmap->origRed;
+ fbcmap.green = cmap->origGreen;
+ fbcmap.blue = cmap->origBlue;
+ ioctl (cmap->psdp->fd, FBIOPUTCMAP, &fbcmap);
+ }
+ pScreen->CloseScreen = cmap->CloseScreen;
+ xfree (cmap);
+ return (*pScreen->CloseScreen) (i, pScreen);
+}
+
+Bool
+xf86SbusHandleColormaps(ScreenPtr pScreen, sbusDevicePtr psdp)
+{
+ sbusCmapPtr cmap;
+ struct fbcmap fbcmap;
+ unsigned char data[2];
+
+ if(sbusPaletteGeneration != serverGeneration) {
+ if((sbusPaletteIndex = AllocateScreenPrivateIndex()) < 0)
+ return FALSE;
+ sbusPaletteGeneration = serverGeneration;
+ }
+ cmap = xnfcalloc(1, sizeof(sbusCmapRec));
+ pScreen->devPrivates[sbusPaletteIndex].ptr = cmap;
+ cmap->psdp = psdp;
+ fbcmap.index = 0;
+ fbcmap.count = 16;
+ fbcmap.red = cmap->origRed;
+ fbcmap.green = cmap->origGreen;
+ fbcmap.blue = cmap->origBlue;
+ if (ioctl (psdp->fd, FBIOGETCMAP, &fbcmap) >= 0)
+ cmap->origCmapValid = TRUE;
+ fbcmap.index = 0;
+ fbcmap.count = 2;
+ fbcmap.red = data;
+ fbcmap.green = data;
+ fbcmap.blue = data;
+ if (pScreen->whitePixel == 0) {
+ data[0] = 255;
+ data[1] = 0;
+ } else {
+ data[0] = 0;
+ data[1] = 255;
+ }
+ ioctl (psdp->fd, FBIOPUTCMAP, &fbcmap);
+ cmap->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = xf86SbusCmapCloseScreen;
+ return xf86HandleColormaps(pScreen, 256, 8,
+ xf86SbusCmapLoadPalette, NULL, 0);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86sbusBus.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86sbusBus.h
new file mode 100644
index 000000000..81c1b84ac
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86sbusBus.h
@@ -0,0 +1,98 @@
+/*
+ * SBUS bus-specific declarations
+ *
+ * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
+ *
+ * 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
+ * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86sbusBus.h,v 3.4 2001/10/28 03:33:19 tsi Exp $ */
+
+#ifndef _XF86_SBUSBUS_H
+#define _XF86_SBUSBUS_H
+
+#include "xf86str.h"
+
+#define SBUS_DEVICE_BW2 0x0001
+#define SBUS_DEVICE_CG2 0x0002
+#define SBUS_DEVICE_CG3 0x0003
+#define SBUS_DEVICE_CG4 0x0004
+#define SBUS_DEVICE_CG6 0x0005
+#define SBUS_DEVICE_CG8 0x0006
+#define SBUS_DEVICE_CG12 0x0007
+#define SBUS_DEVICE_CG14 0x0008
+#define SBUS_DEVICE_LEO 0x0009
+#define SBUS_DEVICE_TCX 0x000a
+#define SBUS_DEVICE_FFB 0x000b
+#define SBUS_DEVICE_GT 0x000c
+#define SBUS_DEVICE_MGX 0x000d
+
+typedef struct sbus_prom_node {
+ int node;
+ /* Because of misdesigned openpromio */
+ int cookie[2];
+} sbusPromNode, *sbusPromNodePtr;
+
+typedef struct sbus_device {
+ int devId;
+ int fbNum;
+ int fd;
+ int width, height;
+ sbusPromNode node;
+ char *descr;
+ char *device;
+} sbusDevice, *sbusDevicePtr;
+
+extern struct sbus_devtable {
+ int devId;
+ int fbType;
+ char *promName;
+ char *descr;
+} sbusDeviceTable[];
+
+void xf86SbusProbe(void);
+extern sbusDevicePtr *xf86SbusInfo;
+
+int xf86MatchSbusInstances(const char *driverName, int sbusDevId,
+ GDevPtr *devList, int numDevs, DriverPtr drvp,
+ int **foundEntities);
+sbusDevicePtr xf86GetSbusInfoForEntity(int entityIndex);
+int xf86GetEntityForSbusInfo(sbusDevicePtr psdp);
+void xf86SbusUseBuiltinMode(ScrnInfoPtr pScrn, sbusDevicePtr psdp);
+pointer xf86MapSbusMem(sbusDevicePtr psdp, unsigned long offset,
+ unsigned long size);
+void xf86UnmapSbusMem(sbusDevicePtr psdp, pointer addr, unsigned long size);
+void xf86SbusHideOsHwCursor(sbusDevicePtr psdp);
+void xf86SbusSetOsHwCursorCmap(sbusDevicePtr psdp, int bg, int fg);
+Bool xf86SbusHandleColormaps(ScreenPtr pScreen, sbusDevicePtr psdp);
+
+extern int promRootNode;
+
+int promGetSibling(int node);
+int promGetChild(int node);
+char * promGetProperty(const char *prop, int *lenp);
+int promGetBool(const char *prop);
+
+int sparcPromInit(void);
+void sparcPromClose(void);
+char * sparcPromGetProperty(sbusPromNodePtr pnode, const char *prop, int *lenp);
+int sparcPromGetBool(sbusPromNodePtr pnode, const char *prop);
+void sparcPromAssignNodes(void);
+char * sparcPromNode2Pathname(sbusPromNodePtr pnode);
+int sparcPromPathname2Node(const char *pathName);
+
+#endif /* _XF86_SBUSBUS_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86str.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86str.h
new file mode 100644
index 000000000..82faaaac1
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86str.h
@@ -0,0 +1,1140 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86str.h,v 1.97 2003/10/30 17:36:56 tsi Exp $ */
+
+/*
+ * 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 definitions of the public XFree86 data structures/types.
+ * Any data structures that video drivers need to access should go here.
+ */
+
+#ifndef _XF86STR_H
+#define _XF86STR_H
+
+#include "misc.h"
+#include "input.h"
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "colormapst.h"
+#include "xf86Module.h"
+#include "xf86Opt.h"
+#include "xf86Pci.h"
+
+/*
+ * memType is of the size of the addressable memory (machine size)
+ * usually unsigned long.
+ */
+typedef unsigned long memType;
+
+/* Video mode flags */
+
+typedef enum {
+ V_PHSYNC = 0x0001,
+ V_NHSYNC = 0x0002,
+ V_PVSYNC = 0x0004,
+ V_NVSYNC = 0x0008,
+ V_INTERLACE = 0x0010,
+ V_DBLSCAN = 0x0020,
+ V_CSYNC = 0x0040,
+ V_PCSYNC = 0x0080,
+ V_NCSYNC = 0x0100,
+ V_HSKEW = 0x0200, /* hskew provided */
+ V_BCAST = 0x0400,
+ V_PIXMUX = 0x1000,
+ V_DBLCLK = 0x2000,
+ V_CLKDIV2 = 0x4000
+} ModeFlags;
+
+typedef enum {
+ INTERLACE_HALVE_V = 0x0001 /* Halve V values for interlacing */
+} CrtcAdjustFlags;
+
+/* Flags passed to ChipValidMode() */
+typedef enum {
+ MODECHECK_INITIAL = 0,
+ MODECHECK_FINAL = 1
+} ModeCheckFlags;
+
+/* These are possible return values for xf86CheckMode() and ValidMode() */
+typedef enum {
+ MODE_OK = 0, /* Mode OK */
+ MODE_HSYNC, /* hsync out of range */
+ MODE_VSYNC, /* vsync out of range */
+ MODE_H_ILLEGAL, /* mode has illegal horizontal timings */
+ MODE_V_ILLEGAL, /* mode has illegal horizontal timings */
+ MODE_BAD_WIDTH, /* requires an unsupported linepitch */
+ MODE_NOMODE, /* no mode with a maching name */
+ MODE_NO_INTERLACE, /* interlaced mode not supported */
+ MODE_NO_DBLESCAN, /* doublescan mode not supported */
+ MODE_NO_VSCAN, /* multiscan mode not supported */
+ MODE_MEM, /* insufficient video memory */
+ MODE_VIRTUAL_X, /* mode width too large for specified virtual size */
+ MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */
+ MODE_MEM_VIRT, /* insufficient video memory given virtual size */
+ MODE_NOCLOCK, /* no fixed clock available */
+ MODE_CLOCK_HIGH, /* clock required is too high */
+ MODE_CLOCK_LOW, /* clock required is too low */
+ MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */
+ MODE_BAD_HVALUE, /* horizontal timing was out of range */
+ MODE_BAD_VVALUE, /* vertical timing was out of range */
+ MODE_BAD_VSCAN, /* VScan value out of range */
+ MODE_HSYNC_NARROW, /* horizontal sync too narrow */
+ MODE_HSYNC_WIDE, /* horizontal sync too wide */
+ MODE_HBLANK_NARROW, /* horizontal blanking too narrow */
+ MODE_HBLANK_WIDE, /* horizontal blanking too wide */
+ MODE_VSYNC_NARROW, /* vertical sync too narrow */
+ MODE_VSYNC_WIDE, /* vertical sync too wide */
+ MODE_VBLANK_NARROW, /* vertical blanking too narrow */
+ MODE_VBLANK_WIDE, /* vertical blanking too wide */
+ MODE_PANEL, /* exceeds panel dimensions */
+ MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
+ MODE_ONE_WIDTH, /* only one width is supported */
+ MODE_ONE_HEIGHT, /* only one height is supported */
+ MODE_ONE_SIZE, /* only one resolution is supported */
+ MODE_BAD = -2, /* unspecified reason */
+ MODE_ERROR = -1 /* error condition */
+} ModeStatus;
+
+# define M_T_BUILTIN 0x01 /* built-in mode */
+# define M_T_CLOCK_C (0x02 | M_T_BUILTIN) /* built-in mode - configure clock */
+# define M_T_CRTC_C (0x04 | M_T_BUILTIN) /* built-in mode - configure CRTC */
+# define M_T_CLOCK_CRTC_C (M_T_CLOCK_C | M_T_CRTC_C)
+ /* built-in mode - configure CRTC and clock */
+# define M_T_DEFAULT 0x10 /* (VESA) default modes */
+# define M_T_USERDEF 0x20 /* One of the modes from the config file */
+
+/* Video mode */
+typedef struct _DisplayModeRec {
+ struct _DisplayModeRec * prev;
+ struct _DisplayModeRec * next;
+ char * name; /* identifier for the mode */
+ ModeStatus status;
+ int type;
+
+ /* These are the values that the user sees/provides */
+ int Clock; /* pixel clock freq (kHz) */
+ int HDisplay; /* horizontal timing */
+ int HSyncStart;
+ int HSyncEnd;
+ int HTotal;
+ int HSkew;
+ int VDisplay; /* vertical timing */
+ int VSyncStart;
+ int VSyncEnd;
+ int VTotal;
+ int VScan;
+ int Flags;
+
+ /* These are the values the hardware uses */
+ int ClockIndex;
+ int SynthClock; /* Actual clock freq to
+ * be programmed (kHz) */
+ int CrtcHDisplay;
+ int CrtcHBlankStart;
+ int CrtcHSyncStart;
+ int CrtcHSyncEnd;
+ int CrtcHBlankEnd;
+ int CrtcHTotal;
+ int CrtcHSkew;
+ int CrtcVDisplay;
+ int CrtcVBlankStart;
+ int CrtcVSyncStart;
+ int CrtcVSyncEnd;
+ int CrtcVBlankEnd;
+ int CrtcVTotal;
+ Bool CrtcHAdjusted;
+ Bool CrtcVAdjusted;
+ int PrivSize;
+ INT32 * Private;
+ int PrivFlags;
+
+ float HSync, VRefresh;
+} DisplayModeRec, *DisplayModePtr;
+
+/* The monitor description */
+
+#define MAX_HSYNC 8
+#define MAX_VREFRESH 8
+
+typedef struct { float hi, lo; } range;
+
+typedef struct { CARD32 red, green, blue; } rgb;
+
+typedef struct { float red, green, blue; } Gamma;
+
+/* The permitted gamma range is 1 / GAMMA_MAX <= g <= GAMMA_MAX */
+#define GAMMA_MAX 10.0
+#define GAMMA_MIN (1.0 / GAMMA_MAX)
+#define GAMMA_ZERO (GAMMA_MIN / 100.0)
+
+typedef struct {
+ char * id;
+ char * vendor;
+ char * model;
+ int nHsync;
+ range hsync[MAX_HSYNC];
+ int nVrefresh;
+ range vrefresh[MAX_VREFRESH];
+ DisplayModePtr Modes; /* Start of the monitor's mode list */
+ DisplayModePtr Last; /* End of the monitor's mode list */
+ Gamma gamma; /* Gamma of the monitor */
+ int widthmm;
+ int heightmm;
+ pointer options;
+ pointer DDC;
+} MonRec, *MonPtr;
+
+/* the list of clock ranges */
+typedef struct x_ClockRange {
+ struct x_ClockRange *next;
+ int minClock; /* (kHz) */
+ int maxClock; /* (kHz) */
+ int clockIndex; /* -1 for programmable clocks */
+ Bool interlaceAllowed;
+ Bool doubleScanAllowed;
+ int ClockMulFactor;
+ int ClockDivFactor;
+ int PrivFlags;
+} ClockRange, *ClockRangePtr;
+
+/* Need to store the strategy with clockRange for VidMode extension */
+typedef struct x_ClockRanges {
+ struct x_ClockRanges *next;
+ int minClock;
+ int maxClock;
+ int clockIndex; /* -1 for programmable clocks */
+ Bool interlaceAllowed;
+ Bool doubleScanAllowed;
+ int ClockMulFactor;
+ int ClockDivFactor;
+ int PrivFlags;
+ int strategy;
+} ClockRanges, *ClockRangesPtr;
+
+/*
+ * The driverFunc. xorgDriverFuncOp specifies the action driver should
+ * perform. If requested option is not supported function should return
+ * FALSE. pointer can be used to pass arguments to the function or
+ * to return data to the caller.
+ */
+typedef struct _ScrnInfoRec *ScrnInfoPtr;
+
+/* do not change order */
+typedef enum {
+ RR_GET_INFO,
+ RR_SET_CONFIG,
+ RR_GET_MODE_MM,
+ GET_REQUIRED_HW_INTERFACES = 10
+} xorgDriverFuncOp;
+
+typedef Bool xorgDriverFuncProc (ScrnInfoPtr, xorgDriverFuncOp,
+ pointer);
+
+/* RR_GET_INFO, RR_SET_CONFIG */
+typedef struct {
+ int rotation;
+ int rate;
+ int width;
+ int height;
+} xorgRRConfig;
+
+typedef union {
+ short RRRotations;
+ xorgRRConfig RRConfig;
+} xorgRRRotation, *xorgRRRotationPtr;
+
+/* RR_GET_MODE_MM */
+typedef struct {
+ DisplayModePtr mode;
+ int virtX;
+ int virtY;
+ int mmWidth;
+ int mmHeight;
+} xorgRRModeMM, *xorgRRModeMMPtr;
+
+/* GET_REQUIRED_HW_INTERFACES */
+#define HW_IO 1
+#define HW_MMIO 2
+#define NEED_IO_ENABLED(x) (x & HW_IO)
+
+typedef CARD32 xorgHWFlags;
+
+/*
+ * The driver list struct. This contains the information required for each
+ * driver before a ScrnInfoRec has been allocated.
+ */
+struct _DriverRec;
+
+typedef struct {
+ int driverVersion;
+ char * driverName;
+ void (*Identify)(int flags);
+ Bool (*Probe)(struct _DriverRec *drv, int flags);
+ const OptionInfoRec * (*AvailableOptions)(int chipid, int bustype);
+ pointer module;
+ int refCount;
+} DriverRec1;
+
+typedef struct _DriverRec {
+ int driverVersion;
+ char * driverName;
+ void (*Identify)(int flags);
+ Bool (*Probe)(struct _DriverRec *drv, int flags);
+ const OptionInfoRec * (*AvailableOptions)(int chipid, int bustype);
+ pointer module;
+ int refCount;
+ xorgDriverFuncProc *driverFunc;
+} DriverRec, *DriverPtr;
+
+/*
+ * AddDriver flags
+ */
+#define HaveDriverFuncs 1
+
+
+#ifdef XFree86LOADER
+/*
+ * The optional module list struct. This allows modules exporting helping
+ * functions to configuration tools, the Xserver, or any other
+ * application/module interested in such information.
+ */
+typedef struct _ModuleInfoRec {
+ int moduleVersion;
+ char * moduleName;
+ pointer module;
+ int refCount;
+ const OptionInfoRec * (*AvailableOptions)(void *unused);
+ pointer unused[8]; /* leave some space for more fields */
+} ModuleInfoRec, *ModuleInfoPtr;
+#endif
+
+/*
+ * These are the private bus types. New types can be added here. Types
+ * required for the public interface should be added to xf86str.h, with
+ * function prototypes added to xf86.h.
+ */
+
+/* Tolerate prior #include <linux/input.h> */
+#if defined(linux) && defined(_INPUT_H)
+#undef BUS_NONE
+#undef BUS_ISA
+#undef BUS_PCI
+#undef BUS_SBUS
+#undef BUS_last
+#endif
+
+typedef enum {
+ BUS_NONE,
+ BUS_ISA,
+ BUS_PCI,
+ BUS_SBUS,
+ BUS_last /* Keep last */
+} BusType;
+
+typedef struct {
+ int bus;
+ int device;
+ int func;
+} PciBusId;
+
+typedef struct {
+ unsigned int dummy;
+} IsaBusId;
+
+typedef struct {
+ int fbNum;
+} SbusBusId;
+
+typedef struct _bus {
+ BusType type;
+ union {
+ IsaBusId isa;
+ PciBusId pci;
+ SbusBusId sbus;
+ } id;
+} BusRec, *BusPtr;
+
+#define MAXCLOCKS 128
+typedef enum {
+ DAC_BPP8 = 0,
+ DAC_BPP16,
+ DAC_BPP24,
+ DAC_BPP32,
+ MAXDACSPEEDS
+} DacSpeedIndex;
+
+typedef struct {
+ char * identifier;
+ char * vendor;
+ char * board;
+ char * chipset;
+ char * ramdac;
+ char * driver;
+ struct _confscreenrec * myScreenSection;
+ Bool claimed;
+ int dacSpeeds[MAXDACSPEEDS];
+ int numclocks;
+ int clock[MAXCLOCKS];
+ char * clockchip;
+ char * busID;
+ Bool active;
+ Bool inUse;
+ int videoRam;
+ int textClockFreq;
+ unsigned long BiosBase; /* Base address of video BIOS */
+ unsigned long MemBase; /* Frame buffer base address */
+ unsigned long IOBase;
+ int chipID;
+ int chipRev;
+ pointer options;
+ int irq;
+ int screen; /* For multi-CRTC cards */
+} GDevRec, *GDevPtr;
+
+typedef int (*FindIsaDevProc)(GDevPtr dev);
+
+typedef struct {
+ char * identifier;
+ char * driver;
+ pointer commonOptions;
+ pointer extraOptions;
+} IDevRec, *IDevPtr;
+
+typedef struct {
+ int vendor;
+ int chipType;
+ int chipRev;
+ int subsysVendor;
+ int subsysCard;
+ int bus;
+ int device;
+ int func;
+ int class;
+ int subclass;
+ int interface;
+ memType memBase[6];
+ memType ioBase[6];
+ int size[6];
+ unsigned char type[6];
+ memType biosBase;
+ int biosSize;
+ pointer thisCard;
+ Bool validSize;
+ Bool validate;
+ CARD32 listed_class;
+} pciVideoRec, *pciVideoPtr;
+
+typedef struct {
+ int frameX0;
+ int frameY0;
+ int virtualX;
+ int virtualY;
+ int depth;
+ int fbbpp;
+ rgb weight;
+ rgb blackColour;
+ rgb whiteColour;
+ int defaultVisual;
+ char ** modes;
+ pointer options;
+} DispRec, *DispPtr;
+
+typedef struct _confxvportrec {
+ char * identifier;
+ pointer options;
+} confXvPortRec, *confXvPortPtr;
+
+typedef struct _confxvadaptrec {
+ char * identifier;
+ int numports;
+ confXvPortPtr ports;
+ pointer options;
+} confXvAdaptorRec, *confXvAdaptorPtr;
+
+typedef struct _confscreenrec {
+ char * id;
+ int screennum;
+ int defaultdepth;
+ int defaultbpp;
+ int defaultfbbpp;
+ MonPtr monitor;
+ GDevPtr device;
+ int numdisplays;
+ DispPtr displays;
+ int numxvadaptors;
+ confXvAdaptorPtr xvadaptors;
+ pointer options;
+} confScreenRec, *confScreenPtr;
+
+typedef enum {
+ PosObsolete = -1,
+ PosAbsolute = 0,
+ PosRightOf,
+ PosLeftOf,
+ PosAbove,
+ PosBelow,
+ PosRelative
+} PositionType;
+
+typedef struct _screenlayoutrec {
+ confScreenPtr screen;
+ char * topname;
+ confScreenPtr top;
+ char * bottomname;
+ confScreenPtr bottom;
+ char * leftname;
+ confScreenPtr left;
+ char * rightname;
+ confScreenPtr right;
+ PositionType where;
+ int x;
+ int y;
+ char * refname;
+ confScreenPtr refscreen;
+} screenLayoutRec, *screenLayoutPtr;
+
+typedef struct _serverlayoutrec {
+ char * id;
+ screenLayoutPtr screens;
+ GDevPtr inactives;
+ IDevPtr inputs;
+ pointer options;
+} serverLayoutRec, *serverLayoutPtr;
+
+typedef struct _confdribufferrec {
+ int count;
+ int size;
+ enum {
+ XF86DRI_WC_HINT = 0x0001 /* Placeholder: not implemented */
+ } flags;
+} confDRIBufferRec, *confDRIBufferPtr;
+
+typedef struct _confdrirec {
+ int group;
+ int mode;
+ int bufs_count;
+ confDRIBufferRec *bufs;
+} confDRIRec, *confDRIPtr;
+
+/* These values should be adjusted when new fields are added to ScrnInfoRec */
+#define NUM_RESERVED_INTS 16
+#define NUM_RESERVED_POINTERS 15
+#define NUM_RESERVED_FUNCS 11
+
+typedef pointer (*funcPointer)(void);
+
+/* flags for depth 24 pixmap options */
+typedef enum {
+ Pix24DontCare = 0,
+ Pix24Use24,
+ Pix24Use32
+} Pix24Flags;
+
+/* Power management events: so far we only support APM */
+
+typedef enum {
+ XF86_APM_UNKNOWN = -1,
+ XF86_APM_SYS_STANDBY,
+ XF86_APM_SYS_SUSPEND,
+ XF86_APM_CRITICAL_SUSPEND,
+ XF86_APM_USER_STANDBY,
+ XF86_APM_USER_SUSPEND,
+ XF86_APM_STANDBY_RESUME,
+ XF86_APM_NORMAL_RESUME,
+ XF86_APM_CRITICAL_RESUME,
+ XF86_APM_LOW_BATTERY,
+ XF86_APM_POWER_STATUS_CHANGE,
+ XF86_APM_UPDATE_TIME,
+ XF86_APM_CAPABILITY_CHANGED,
+ XF86_APM_STANDBY_FAILED,
+ XF86_APM_SUSPEND_FAILED
+} pmEvent;
+
+typedef enum {
+ PM_WAIT,
+ PM_CONTINUE,
+ PM_FAILED,
+ PM_NONE
+} pmWait;
+
+/*
+ * The IO access enabler struct. This contains the address for
+ * the IOEnable/IODisable funcs for their specific bus along
+ * with a pointer to data needed by them
+ */
+typedef struct _AccessRec {
+ void (*AccessDisable)(void *arg);
+ void (*AccessEnable)(void *arg);
+ void *arg;
+} xf86AccessRec, *xf86AccessPtr;
+
+typedef struct {
+ xf86AccessPtr mem;
+ xf86AccessPtr io;
+ xf86AccessPtr io_mem;
+} xf86SetAccessFuncRec, *xf86SetAccessFuncPtr;
+
+/* bus-access-related types */
+typedef enum {
+ NONE,
+ IO,
+ MEM_IO,
+ MEM
+} resType;
+
+typedef struct _EntityAccessRec {
+ xf86AccessPtr fallback;
+ xf86AccessPtr pAccess;
+ resType rt;
+ pointer busAcc;
+ struct _EntityAccessRec *next;
+} EntityAccessRec, *EntityAccessPtr;
+
+typedef struct _CurrAccRec {
+ EntityAccessPtr pMemAccess;
+ EntityAccessPtr pIoAccess;
+} xf86CurrentAccessRec, *xf86CurrentAccessPtr;
+
+/* new RAC */
+
+/* Resource Type values */
+#define ResNone ((unsigned long)(-1))
+
+#define ResMem 0x0001
+#define ResIo 0x0002
+#define ResIrq 0x0003
+#define ResDma 0x0004
+#define ResPciCfg 0x000e /* PCI Configuration space */
+#define ResPhysMask 0x000F
+
+#define ResExclusive 0x0010
+#define ResShared 0x0020
+#define ResAny 0x0040
+#define ResAccMask 0x0070
+#define ResUnused 0x0080
+
+#define ResUnusedOpr 0x0100
+#define ResDisableOpr 0x0200
+#define ResOprMask 0x0300
+
+#define ResBlock 0x0400
+#define ResSparse 0x0800
+#define ResExtMask 0x0C00
+
+#define ResEstimated 0x001000
+#define ResInit 0x002000
+#define ResBios 0x004000
+#define ResMiscMask 0x00F000
+
+#define ResBus 0x010000
+#define ResOverlap 0x020000
+
+#if defined(__alpha__) && defined(linux)
+# define ResDomain 0x1ff000000ul
+#else
+# define ResDomain 0xff000000ul
+#endif
+#define ResTypeMask (ResPhysMask | ResDomain) /* For conflict check */
+
+#define ResEnd ResNone
+
+#define ResExcMemBlock (ResMem | ResExclusive | ResBlock)
+#define ResExcIoBlock (ResIo | ResExclusive | ResBlock)
+#define ResShrMemBlock (ResMem | ResShared | ResBlock)
+#define ResShrIoBlock (ResIo | ResShared | ResBlock)
+#define ResExcUusdMemBlock (ResMem | ResExclusive | ResUnused | ResBlock)
+#define ResExcUusdIoBlock (ResIo | ResExclusive | ResUnused | ResBlock)
+#define ResShrUusdMemBlock (ResMem | ResShared | ResUnused | ResBlock)
+#define ResShrUusdIoBlock (ResIo | ResShared | ResUnused | ResBlock)
+#define ResExcUusdMemSparse (ResMem | ResExclusive | ResUnused | ResSparse)
+#define ResExcUusdIoSparse (ResIo | ResExclusive | ResUnused | ResSparse)
+#define ResShrUusdMemSparse (ResMem | ResShared | ResUnused | ResSparse)
+#define ResShrUusdIoSparse (ResIo | ResShared | ResUnused | ResSparse)
+
+#define ResExcMemSparse (ResMem | ResExclusive | ResSparse)
+#define ResExcIoSparse (ResIo | ResExclusive | ResSparse)
+#define ResShrMemSparse (ResMem | ResShared | ResSparse)
+#define ResShrIoSparse (ResIo | ResShared | ResSparse)
+#define ResUusdMemSparse (ResMem | ResUnused | ResSparse)
+#define ResUusdIoSparse (ResIo | ResUnused | ResSparse)
+
+#define ResIsMem(r) (((r)->type & ResPhysMask) == ResMem)
+#define ResIsIo(r) (((r)->type & ResPhysMask) == ResIo)
+#define ResIsExclusive(r) (((r)->type & ResAccMask) == ResExclusive)
+#define ResIsShared(r) (((r)->type & ResAccMask) == ResShared)
+#define ResIsUnused(r) (((r)->type & ResAccMask) == ResUnused)
+#define ResIsBlock(r) (((r)->type & ResExtMask) == ResBlock)
+#define ResIsSparse(r) (((r)->type & ResExtMask) == ResSparse)
+#define ResIsEstimated(r) (((r)->type & ResMiscMask) == ResEstimated)
+#define ResCanOverlap(r) (ResIsEstimated(r) || ((r)->type & ResOverlap))
+
+typedef struct {
+ unsigned long type; /* shared, exclusive, unused etc. */
+ memType a;
+ memType b;
+} resRange, *resList;
+
+#define RANGE_TYPE(type, domain) \
+ (((unsigned long)(domain) << 24) | ((type) & ~ResBus))
+#define RANGE(r,u,v,t) {\
+ (r).a = (u);\
+ (r).b = (v);\
+ (r).type = (t);\
+ }
+
+#define rBase a
+#define rMask b
+#define rBegin a
+#define rEnd b
+
+/* resource record */
+typedef struct _resRec *resPtr;
+typedef struct _resRec {
+ resRange val;
+ int entityIndex; /* who owns the resource */
+ resPtr next;
+} resRec;
+
+#define sparse_base val.rBase
+#define sparse_mask val.rMask
+#define block_begin val.rBegin
+#define block_end val.rEnd
+#define res_type val.type
+
+typedef struct {
+ int numChipset;
+ resRange *resList;
+} IsaChipsets;
+
+typedef struct {
+ int numChipset;
+ int PCIid;
+ resRange *resList;
+} PciChipsets;
+
+/* Entity properties */
+typedef void (*EntityProc)(int entityIndex,pointer private);
+
+typedef struct _entityInfo {
+ int index;
+ BusRec location;
+ int chipset;
+ Bool active;
+ resPtr resources;
+ GDevPtr device;
+ DriverPtr driver;
+} EntityInfoRec, *EntityInfoPtr;
+
+/* server states */
+
+typedef enum {
+ SETUP,
+ OPERATING
+} xf86State;
+
+typedef enum {
+ NOTIFY_SETUP_TRANSITION,
+ NOTIFY_SETUP,
+ NOTIFY_OPERATING,
+ NOTIFY_OPERATING_TRANSITION,
+ NOTIFY_ENABLE,
+ NOTIFY_ENTER,
+ NOTIFY_LEAVE
+} xf86NotifyState;
+
+typedef void (*xf86StateChangeNotificationCallbackFunc)(xf86NotifyState state,pointer);
+
+/* DGA */
+
+typedef struct {
+ int num; /* A unique identifier for the mode (num > 0) */
+ DisplayModePtr mode;
+ int flags; /* DGA_CONCURRENT_ACCESS, etc... */
+ int imageWidth; /* linear accessible portion (pixels) */
+ int imageHeight;
+ int pixmapWidth; /* Xlib accessible portion (pixels) */
+ int pixmapHeight; /* both fields ignored if no concurrent access */
+ int bytesPerScanline;
+ int byteOrder; /* MSBFirst, LSBFirst */
+ int depth;
+ int bitsPerPixel;
+ unsigned long red_mask;
+ unsigned long green_mask;
+ unsigned long blue_mask;
+ short visualClass;
+ int viewportWidth;
+ int viewportHeight;
+ int xViewportStep; /* viewport position granularity */
+ int yViewportStep;
+ int maxViewportX; /* max viewport origin */
+ int maxViewportY;
+ int viewportFlags; /* types of page flipping possible */
+ int offset; /* offset into physical memory */
+ unsigned char *address; /* server's mapped framebuffer */
+ int reserved1;
+ int reserved2;
+} DGAModeRec, *DGAModePtr;
+
+typedef struct {
+ DGAModePtr mode;
+ PixmapPtr pPix;
+} DGADeviceRec, *DGADevicePtr;
+
+/*
+ * Flags for driver Probe() functions.
+ */
+#define PROBE_DEFAULT 0x00
+#define PROBE_DETECT 0x01
+#define PROBE_TRYHARD 0x02
+
+/*
+ * Driver entry point types
+ */
+
+typedef Bool xf86ProbeProc (DriverPtr, int);
+typedef Bool xf86PreInitProc (ScrnInfoPtr, int);
+typedef Bool xf86ScreenInitProc (int, ScreenPtr, int, char**);
+typedef Bool xf86SwitchModeProc (int, DisplayModePtr, int);
+typedef void xf86AdjustFrameProc (int, int, int, int);
+typedef Bool xf86EnterVTProc (int, int);
+typedef void xf86LeaveVTProc (int, int);
+typedef void xf86FreeScreenProc (int, int);
+typedef ModeStatus xf86ValidModeProc (int, DisplayModePtr, Bool, int);
+typedef void xf86EnableDisableFBAccessProc(int, Bool);
+typedef int xf86SetDGAModeProc (int, int, DGADevicePtr);
+typedef int xf86ChangeGammaProc (int, Gamma);
+typedef void xf86PointerMovedProc (int, int, int);
+typedef Bool xf86PMEventProc (int, pmEvent, Bool);
+typedef int xf86HandleMessageProc (int, const char*, const char*, char**);
+typedef void xf86DPMSSetProc (ScrnInfoPtr, int, int);
+typedef void xf86LoadPaletteProc (ScrnInfoPtr, int, int *, LOCO *, VisualPtr);
+typedef void xf86SetOverscanProc (ScrnInfoPtr, int);
+
+
+/*
+ * ScrnInfoRec
+ *
+ * There is one of these for each screen, and it holds all the screen-specific
+ * information.
+ *
+ * Note: the size and layout must be kept the same across versions. New
+ * fields are to be added in place of the "reserved*" fields. No fields
+ * are to be dependent on compile-time defines.
+ */
+
+
+typedef struct _ScrnInfoRec {
+ int driverVersion;
+ char * driverName; /* canonical name used in */
+ /* the config file */
+ ScreenPtr pScreen; /* Pointer to the ScreenRec */
+ int scrnIndex; /* Number of this screen */
+ Bool configured; /* Is this screen valid */
+ int origIndex; /* initial number assigned to
+ * this screen before
+ * finalising the number of
+ * available screens */
+
+ /* Display-wide screenInfo values needed by this screen */
+ int imageByteOrder;
+ int bitmapScanlineUnit;
+ int bitmapScanlinePad;
+ int bitmapBitOrder;
+ int numFormats;
+ PixmapFormatRec formats[MAXFORMATS];
+ PixmapFormatRec fbFormat;
+
+ int bitsPerPixel; /* fb bpp */
+ Pix24Flags pixmap24; /* pixmap pref for depth 24 */
+ int depth; /* depth of default visual */
+ MessageType depthFrom; /* set from config? */
+ MessageType bitsPerPixelFrom; /* set from config? */
+ rgb weight; /* r/g/b weights */
+ rgb mask; /* rgb masks */
+ rgb offset; /* rgb offsets */
+ int rgbBits; /* Number of bits in r/g/b */
+ Gamma gamma; /* Gamma of the monitor */
+ int defaultVisual; /* default visual class */
+ int maxHValue; /* max horizontal timing */
+ int maxVValue; /* max vertical timing value */
+ int virtualX; /* Virtual width */
+ int virtualY; /* Virtual height */
+ int xInc; /* Horizontal timing increment */
+ MessageType virtualFrom; /* set from config? */
+ int displayWidth; /* memory pitch */
+ int frameX0; /* viewport position */
+ int frameY0;
+ int frameX1;
+ int frameY1;
+ int zoomLocked; /* Disallow mode changes */
+ DisplayModePtr modePool; /* list of compatible modes */
+ DisplayModePtr modes; /* list of actual modes */
+ DisplayModePtr currentMode; /* current mode
+ * This was previously
+ * overloaded with the modes
+ * field, which is a pointer
+ * into a circular list */
+ confScreenPtr confScreen; /* Screen config info */
+ MonPtr monitor; /* Monitor information */
+ DispPtr display; /* Display information */
+ int * entityList; /* List of device entities */
+ int numEntities;
+ int widthmm; /* physical display dimensions
+ * in mm */
+ int heightmm;
+ int xDpi; /* width DPI */
+ int yDpi; /* height DPI */
+ char * name; /* Name to prefix messages */
+ pointer driverPrivate; /* Driver private area */
+ DevUnion * privates; /* Other privates can hook in
+ * here */
+ DriverPtr drv; /* xf86DriverList[] entry */
+ pointer module; /* Pointer to module head */
+ int colorKey;
+ int overlayFlags;
+
+ /* Some of these may be moved out of here into the driver private area */
+
+ char * chipset; /* chipset name */
+ char * ramdac; /* ramdac name */
+ char * clockchip; /* clock name */
+ Bool progClock; /* clock is programmable */
+ int numClocks; /* number of clocks */
+ int clock[MAXCLOCKS]; /* list of clock frequencies */
+ int videoRam; /* amount of video ram (kb) */
+ unsigned long biosBase; /* Base address of video BIOS */
+ unsigned long memPhysBase; /* Physical address of FB */
+ unsigned long fbOffset; /* Offset of FB in the above */
+ IOADDRESS domainIOBase; /* Domain I/O base address */
+ int memClk; /* memory clock */
+ int textClockFreq; /* clock of text mode */
+ Bool flipPixels; /* swap default black/white */
+ pointer options;
+
+ int chipID;
+ int chipRev;
+ int racMemFlags;
+ int racIoFlags;
+ pointer access;
+ xf86CurrentAccessPtr CurrentAccess;
+ resType resourceType;
+ pointer busAccess;
+
+ /* Allow screens to be enabled/disabled individually */
+ Bool vtSema;
+ DevUnion pixmapPrivate; /* saved devPrivate from pixmap */
+
+ /* hw cursor moves at SIGIO time */
+ Bool silkenMouse;
+
+ /* Storage for clockRanges and adjustFlags for use with the VidMode ext */
+ ClockRangesPtr clockRanges;
+ int adjustFlags;
+
+ /*
+ * These can be used when the minor ABI version is incremented.
+ * The NUM_* parameters must be reduced appropriately to keep the
+ * structure size and alignment unchanged.
+ */
+ int reservedInt[NUM_RESERVED_INTS];
+
+ int * entityInstanceList;
+ pointer reservedPtr[NUM_RESERVED_POINTERS];
+
+ /*
+ * Driver entry points.
+ *
+ */
+
+ xf86ProbeProc *Probe;
+ xf86PreInitProc *PreInit;
+ xf86ScreenInitProc *ScreenInit;
+ xf86SwitchModeProc *SwitchMode;
+ xf86AdjustFrameProc *AdjustFrame;
+ xf86EnterVTProc *EnterVT;
+ xf86LeaveVTProc *LeaveVT;
+ xf86FreeScreenProc *FreeScreen;
+ xf86ValidModeProc *ValidMode;
+ xf86EnableDisableFBAccessProc *EnableDisableFBAccess;
+ xf86SetDGAModeProc *SetDGAMode;
+ xf86ChangeGammaProc *ChangeGamma;
+ xf86PointerMovedProc *PointerMoved;
+ xf86PMEventProc *PMEvent;
+ xf86HandleMessageProc *HandleMessage;
+ xf86DPMSSetProc *DPMSSet;
+ xf86LoadPaletteProc *LoadPalette;
+ xf86SetOverscanProc *SetOverscan;
+ xorgDriverFuncProc *DriverFunc;
+
+ /*
+ * This can be used when the minor ABI version is incremented.
+ * The NUM_* parameter must be reduced appropriately to keep the
+ * structure size and alignment unchanged.
+ */
+ funcPointer reservedFuncs[NUM_RESERVED_FUNCS];
+
+} ScrnInfoRec;
+
+
+typedef struct {
+ Bool (*OpenFramebuffer)(
+ ScrnInfoPtr pScrn,
+ char **name,
+ unsigned char **mem,
+ int *size,
+ int *offset,
+ int *extra
+ );
+ void (*CloseFramebuffer)(ScrnInfoPtr pScrn);
+ Bool (*SetMode)(ScrnInfoPtr pScrn, DGAModePtr pMode);
+ void (*SetViewport)(ScrnInfoPtr pScrn, int x, int y, int flags);
+ int (*GetViewport)(ScrnInfoPtr pScrn);
+ void (*Sync)(ScrnInfoPtr);
+ void (*FillRect)(
+ ScrnInfoPtr pScrn,
+ int x, int y, int w, int h,
+ unsigned long color
+ );
+ void (*BlitRect)(
+ ScrnInfoPtr pScrn,
+ int srcx, int srcy,
+ int w, int h,
+ int dstx, int dsty
+ );
+ void (*BlitTransRect)(
+ ScrnInfoPtr pScrn,
+ int srcx, int srcy,
+ int w, int h,
+ int dstx, int dsty,
+ unsigned long color
+ );
+} DGAFunctionRec, *DGAFunctionPtr;
+
+typedef struct {
+ int token; /* id of the token */
+ const char * name; /* token name */
+} SymTabRec, *SymTabPtr;
+
+/* flags for xf86LookupMode */
+typedef enum {
+ LOOKUP_DEFAULT = 0, /* Use default mode lookup method */
+ LOOKUP_BEST_REFRESH, /* Pick modes with best refresh */
+ LOOKUP_CLOSEST_CLOCK, /* Pick modes with the closest clock */
+ LOOKUP_LIST_ORDER, /* Pick first useful mode in list */
+ LOOKUP_CLKDIV2 = 0x0100, /* Allow half clocks */
+ LOOKUP_OPTIONAL_TOLERANCES = 0x0200 /* Allow missing hsync/vrefresh */
+} LookupModeFlags;
+
+#define NoDepth24Support 0x00
+#define Support24bppFb 0x01 /* 24bpp framebuffer supported */
+#define Support32bppFb 0x02 /* 32bpp framebuffer supported */
+#define SupportConvert24to32 0x04 /* Can convert 24bpp pixmap to 32bpp */
+#define SupportConvert32to24 0x08 /* Can convert 32bpp pixmap to 24bpp */
+#define PreferConvert24to32 0x10 /* prefer 24bpp pixmap to 32bpp conv */
+#define PreferConvert32to24 0x20 /* prefer 32bpp pixmap to 24bpp conv */
+
+
+/* For DPMS */
+typedef void (*DPMSSetProcPtr)(ScrnInfoPtr, int, int);
+
+/* Input handler proc */
+typedef void (*InputHandlerProc)(int fd, pointer data);
+
+/* These are used by xf86GetClocks */
+#define CLK_REG_SAVE -1
+#define CLK_REG_RESTORE -2
+
+/* xf86Debug.c */
+#ifdef BUILDDEBUG
+typedef struct {
+ long sec;
+ long usec;
+} xf86TsRec, *xf86TsPtr;
+#endif
+
+/*
+ * misc constants
+ */
+#define INTERLACE_REFRESH_WEIGHT 1.5
+#define SYNC_TOLERANCE 0.01 /* 1 percent */
+#define CLOCK_TOLERANCE 2000 /* Clock matching tolerance (2MHz) */
+
+
+#define OVERLAY_8_32_DUALFB 0x00000001
+#define OVERLAY_8_24_DUALFB 0x00000002
+#define OVERLAY_8_16_DUALFB 0x00000004
+#define OVERLAY_8_32_PLANAR 0x00000008
+
+#if 0
+#define LD_RESOLV_IFDONE 0 /* only check if no more
+ delays pending */
+#define LD_RESOLV_NOW 1 /* finish one delay step */
+#define LD_RESOLV_FORCE 2 /* force checking... */
+#endif
+
+/* Values of xf86Info.mouseFlags */
+#define MF_CLEAR_DTR 1
+#define MF_CLEAR_RTS 2
+
+/* Action Events */
+typedef enum {
+ ACTION_TERMINATE = 0, /* Terminate Server */
+ ACTION_NEXT_MODE = 10, /* Switch to next video mode */
+ ACTION_PREV_MODE,
+ ACTION_DISABLEGRAB = 20, /* Cancel server/pointer/kbd grabs */
+ ACTION_CLOSECLIENT, /* Kill client holding grab */
+ ACTION_SWITCHSCREEN = 100, /* VT switch */
+ ACTION_SWITCHSCREEN_NEXT,
+ ACTION_SWITCHSCREEN_PREV,
+ ACTION_MESSAGE = 9999 /* Generic message passing */
+} ActionEvent;
+
+/* xf86Versions.c */
+/*
+ * Never change existing values, and always assign values explicitly.
+ * NUM_BUILTIN_IFS must always be the last entry.
+ */
+typedef enum {
+ BUILTIN_IF_OSMOUSE = 0,
+ BUILTIN_IF_OSKBD = 1,
+ NUM_BUILTIN_IFS
+} BuiltinInterface;
+
+/*
+ * These are intentionally the same as the module version macros.
+ * It is possible to register a module as providing a specific interface,
+ * in which case the module's version is used. This feature isn't
+ * really ready for use yet though.
+ */
+
+#define BUILTIN_INTERFACE_VERSION_NUMERIC(maj, min, patch) \
+ ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF))
+#define GET_BUILTIN_INTERFACE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF)
+#define GET_BUILTIN_INTERFACE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF)
+#define GET_BUILTIN_INTERFACE_PATCH_VERSION(vers) ((vers) & 0xFFFF)
+
+#endif /* _XF86STR_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86xv.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xv.c
new file mode 100644
index 000000000..35695bd9e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xv.c
@@ -0,0 +1,2050 @@
+/*
+ * XFree86 Xv DDX written by Mark Vojkovich (markv@valinux.com)
+ */
+/*
+ * Copyright (c) 1998-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).
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86xv.c,v 1.37 2003/11/10 18:22:15 tsi Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "misc.h"
+#include "xf86.h"
+#include "xf86_OSproc.h"
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "scrnintstr.h"
+#include "regionstr.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "mivalidate.h"
+#include "validate.h"
+#include "resource.h"
+#include "gcstruct.h"
+#include "dixstruct.h"
+
+#include <X11/extensions/Xv.h>
+#include <X11/extensions/Xvproto.h>
+#include "xvdix.h"
+#ifdef XFree86LOADER
+#include "xvmodproc.h"
+#endif
+
+#include "xf86xvpriv.h"
+
+
+/* XvScreenRec fields */
+
+static Bool xf86XVCloseScreen(int, ScreenPtr);
+static int xf86XVQueryAdaptors(ScreenPtr, XvAdaptorPtr *, int *);
+
+/* XvAdaptorRec fields */
+
+static int xf86XVAllocatePort(unsigned long, XvPortPtr, XvPortPtr*);
+static int xf86XVFreePort(XvPortPtr);
+static int xf86XVPutVideo(ClientPtr, DrawablePtr,XvPortPtr, GCPtr,
+ INT16, INT16, CARD16, CARD16,
+ INT16, INT16, CARD16, CARD16);
+static int xf86XVPutStill(ClientPtr, DrawablePtr,XvPortPtr, GCPtr,
+ INT16, INT16, CARD16, CARD16,
+ INT16, INT16, CARD16, CARD16);
+static int xf86XVGetVideo(ClientPtr, DrawablePtr,XvPortPtr, GCPtr,
+ INT16, INT16, CARD16, CARD16,
+ INT16, INT16, CARD16, CARD16);
+static int xf86XVGetStill(ClientPtr, DrawablePtr,XvPortPtr, GCPtr,
+ INT16, INT16, CARD16, CARD16,
+ INT16, INT16, CARD16, CARD16);
+static int xf86XVStopVideo(ClientPtr, XvPortPtr, DrawablePtr);
+static int xf86XVSetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32);
+static int xf86XVGetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32*);
+static int xf86XVQueryBestSize(ClientPtr, XvPortPtr, CARD8,
+ CARD16, CARD16,CARD16, CARD16,
+ unsigned int*, unsigned int*);
+static int xf86XVPutImage(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+ INT16, INT16, CARD16, CARD16,
+ INT16, INT16, CARD16, CARD16,
+ XvImagePtr, unsigned char*, Bool,
+ CARD16, CARD16);
+static int xf86XVQueryImageAttributes(ClientPtr, XvPortPtr, XvImagePtr,
+ CARD16*, CARD16*, int*, int*);
+
+
+/* ScreenRec fields */
+
+static Bool xf86XVDestroyWindow(WindowPtr pWin);
+static void xf86XVWindowExposures(WindowPtr pWin, RegionPtr r1, RegionPtr r2);
+static void xf86XVClipNotify(WindowPtr pWin, int dx, int dy);
+
+/* ScrnInfoRec functions */
+
+static Bool xf86XVEnterVT(int, int);
+static void xf86XVLeaveVT(int, int);
+static void xf86XVAdjustFrame(int index, int x, int y, int flags);
+
+/* misc */
+
+static Bool xf86XVInitAdaptors(ScreenPtr, XF86VideoAdaptorPtr*, int);
+
+
+int XF86XVWindowIndex = -1;
+int XF86XvScreenIndex = -1;
+static unsigned long XF86XVGeneration = 0;
+static unsigned long PortResource = 0;
+
+#ifdef XFree86LOADER
+int (*XvGetScreenIndexProc)(void) = NULL;
+unsigned long (*XvGetRTPortProc)(void) = NULL;
+int (*XvScreenInitProc)(ScreenPtr) = NULL;
+#else
+int (*XvGetScreenIndexProc)(void) = XvGetScreenIndex;
+unsigned long (*XvGetRTPortProc)(void) = XvGetRTPort;
+int (*XvScreenInitProc)(ScreenPtr) = XvScreenInit;
+#endif
+
+
+#define GET_XV_SCREEN(pScreen) \
+ ((XvScreenPtr)((pScreen)->devPrivates[XF86XvScreenIndex].ptr))
+
+#define GET_XF86XV_SCREEN(pScreen) \
+ ((XF86XVScreenPtr)(GET_XV_SCREEN(pScreen)->devPriv.ptr))
+
+#define GET_XF86XV_WINDOW(pWin) \
+ ((XF86XVWindowPtr)((pWin)->devPrivates[XF86XVWindowIndex].ptr))
+
+static xf86XVInitGenericAdaptorPtr *GenDrivers = NULL;
+static int NumGenDrivers = 0;
+
+int
+xf86XVRegisterGenericAdaptorDriver(
+ xf86XVInitGenericAdaptorPtr InitFunc
+){
+ xf86XVInitGenericAdaptorPtr *newdrivers;
+
+ newdrivers = xrealloc(GenDrivers, sizeof(xf86XVInitGenericAdaptorPtr) *
+ (1 + NumGenDrivers));
+ if (!newdrivers)
+ return 0;
+ GenDrivers = newdrivers;
+
+ GenDrivers[NumGenDrivers++] = InitFunc;
+
+ return 1;
+}
+
+int
+xf86XVListGenericAdaptors(
+ ScrnInfoPtr pScrn,
+ XF86VideoAdaptorPtr **adaptors
+){
+ int i,j,n,num;
+ XF86VideoAdaptorPtr *DrivAdap,*new;
+
+ num = 0;
+ *adaptors = NULL;
+ /*
+ * The v4l driver registers itself first, but can use surfaces registered
+ * by other drivers. So, call the v4l driver last.
+ */
+ for (i = NumGenDrivers; --i >= 0; ) {
+ DrivAdap = NULL;
+ n = (*GenDrivers[i])(pScrn, &DrivAdap);
+ if (0 == n)
+ continue;
+ new = xrealloc(*adaptors, sizeof(XF86VideoAdaptorPtr) * (num+n));
+ if (NULL == new)
+ continue;
+ *adaptors = new;
+ for (j = 0; j < n; j++, num++)
+ (*adaptors)[num] = DrivAdap[j];
+ }
+ return num;
+}
+
+
+/**************** Offscreen surface stuff *******************/
+
+typedef struct {
+ XF86OffscreenImagePtr images;
+ int num;
+} OffscreenImageRec;
+
+static OffscreenImageRec OffscreenImages[MAXSCREENS];
+
+Bool
+xf86XVRegisterOffscreenImages(
+ ScreenPtr pScreen,
+ XF86OffscreenImagePtr images,
+ int num
+){
+ OffscreenImages[pScreen->myNum].num = num;
+ OffscreenImages[pScreen->myNum].images = images;
+
+ return TRUE;
+}
+
+XF86OffscreenImagePtr
+xf86XVQueryOffscreenImages(
+ ScreenPtr pScreen,
+ int *num
+){
+ *num = OffscreenImages[pScreen->myNum].num;
+ return OffscreenImages[pScreen->myNum].images;
+}
+
+
+XF86VideoAdaptorPtr
+xf86XVAllocateVideoAdaptorRec(ScrnInfoPtr pScrn)
+{
+ return xcalloc(1, sizeof(XF86VideoAdaptorRec));
+}
+
+void
+xf86XVFreeVideoAdaptorRec(XF86VideoAdaptorPtr ptr)
+{
+ xfree(ptr);
+}
+
+
+Bool
+xf86XVScreenInit(
+ ScreenPtr pScreen,
+ XF86VideoAdaptorPtr *adaptors,
+ int num
+){
+ ScrnInfoPtr pScrn;
+ XF86XVScreenPtr ScreenPriv;
+ XvScreenPtr pxvs;
+
+ if(num <= 0 ||
+ !XvGetScreenIndexProc || !XvGetRTPortProc || !XvScreenInitProc)
+ return FALSE;
+
+ if(XF86XVGeneration != serverGeneration) {
+ if((XF86XVWindowIndex = AllocateWindowPrivateIndex()) < 0)
+ return FALSE;
+ XF86XVGeneration = serverGeneration;
+ }
+
+ if(!AllocateWindowPrivate(pScreen,XF86XVWindowIndex,0))
+ return FALSE;
+
+ if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
+
+ XF86XvScreenIndex = (*XvGetScreenIndexProc)();
+ PortResource = (*XvGetRTPortProc)();
+
+ pxvs = GET_XV_SCREEN(pScreen);
+
+ /* Anyone initializing the Xv layer must provide these two.
+ The Xv di layer calls them without even checking if they exist! */
+
+ pxvs->ddCloseScreen = xf86XVCloseScreen;
+ pxvs->ddQueryAdaptors = xf86XVQueryAdaptors;
+
+ /* The Xv di layer provides us with a private hook so that we don't
+ have to allocate our own screen private. They also provide
+ a CloseScreen hook so that we don't have to wrap it. I'm not
+ sure that I appreciate that. */
+
+ ScreenPriv = xalloc(sizeof(XF86XVScreenRec));
+ pxvs->devPriv.ptr = (pointer)ScreenPriv;
+
+ if(!ScreenPriv) return FALSE;
+
+ pScrn = xf86Screens[pScreen->myNum];
+
+ ScreenPriv->videoGC = NULL; /* for the helper */
+
+ ScreenPriv->DestroyWindow = pScreen->DestroyWindow;
+ ScreenPriv->WindowExposures = pScreen->WindowExposures;
+ ScreenPriv->ClipNotify = pScreen->ClipNotify;
+ ScreenPriv->EnterVT = pScrn->EnterVT;
+ ScreenPriv->LeaveVT = pScrn->LeaveVT;
+ ScreenPriv->AdjustFrame = pScrn->AdjustFrame;
+
+ pScreen->DestroyWindow = xf86XVDestroyWindow;
+ pScreen->WindowExposures = xf86XVWindowExposures;
+ pScreen->ClipNotify = xf86XVClipNotify;
+ pScrn->EnterVT = xf86XVEnterVT;
+ pScrn->LeaveVT = xf86XVLeaveVT;
+ if(pScrn->AdjustFrame)
+ pScrn->AdjustFrame = xf86XVAdjustFrame;
+
+ if(!xf86XVInitAdaptors(pScreen, adaptors, num))
+ return FALSE;
+
+ return TRUE;
+}
+
+static void
+xf86XVFreeAdaptor(XvAdaptorPtr pAdaptor)
+{
+ int i;
+
+ xfree(pAdaptor->name);
+
+ if(pAdaptor->pEncodings) {
+ XvEncodingPtr pEncode = pAdaptor->pEncodings;
+
+ for(i = 0; i < pAdaptor->nEncodings; i++, pEncode++)
+ xfree(pEncode->name);
+ xfree(pAdaptor->pEncodings);
+ }
+
+ xfree(pAdaptor->pFormats);
+
+ if(pAdaptor->pPorts) {
+ XvPortPtr pPort = pAdaptor->pPorts;
+ XvPortRecPrivatePtr pPriv;
+
+ for(i = 0; i < pAdaptor->nPorts; i++, pPort++) {
+ pPriv = (XvPortRecPrivatePtr)pPort->devPriv.ptr;
+ if(pPriv) {
+ if(pPriv->clientClip)
+ REGION_DESTROY(pAdaptor->pScreen, pPriv->clientClip);
+ if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
+ REGION_DESTROY(pAdaptor->pScreen, pPriv->pCompositeClip);
+ xfree(pPriv);
+ }
+ }
+ xfree(pAdaptor->pPorts);
+ }
+
+ if(pAdaptor->nAttributes) {
+ XvAttributePtr pAttribute = pAdaptor->pAttributes;
+
+ for(i = 0; i < pAdaptor->nAttributes; i++, pAttribute++)
+ xfree(pAttribute->name);
+ xfree(pAdaptor->pAttributes);
+ }
+
+ xfree(pAdaptor->pImages);
+ xfree(pAdaptor->devPriv.ptr);
+}
+
+static Bool
+xf86XVInitAdaptors(
+ ScreenPtr pScreen,
+ XF86VideoAdaptorPtr *infoPtr,
+ int number
+) {
+ XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ XF86VideoAdaptorPtr adaptorPtr;
+ XvAdaptorPtr pAdaptor, pa;
+ XvAdaptorRecPrivatePtr adaptorPriv;
+ int na, numAdaptor;
+ XvPortRecPrivatePtr portPriv;
+ XvPortPtr pPort, pp;
+ int numPort;
+ XF86AttributePtr attributePtr;
+ XvAttributePtr pAttribute, pat;
+ XF86VideoFormatPtr formatPtr;
+ XvFormatPtr pFormat, pf;
+ int numFormat, totFormat;
+ XF86VideoEncodingPtr encodingPtr;
+ XvEncodingPtr pEncode, pe;
+ XF86ImagePtr imagePtr;
+ XvImagePtr pImage, pi;
+ int numVisuals;
+ VisualPtr pVisual;
+ int i;
+
+ pxvs->nAdaptors = 0;
+ pxvs->pAdaptors = NULL;
+
+ if(!(pAdaptor = xcalloc(number, sizeof(XvAdaptorRec))))
+ return FALSE;
+
+ for(pa = pAdaptor, na = 0, numAdaptor = 0; na < number; na++, adaptorPtr++) {
+ adaptorPtr = infoPtr[na];
+
+ if(!adaptorPtr->StopVideo || !adaptorPtr->SetPortAttribute ||
+ !adaptorPtr->GetPortAttribute || !adaptorPtr->QueryBestSize)
+ continue;
+
+ /* client libs expect at least one encoding */
+ if(!adaptorPtr->nEncodings || !adaptorPtr->pEncodings)
+ continue;
+
+ pa->type = adaptorPtr->type;
+
+ if(!adaptorPtr->PutVideo && !adaptorPtr->GetVideo)
+ pa->type &= ~XvVideoMask;
+
+ if(!adaptorPtr->PutStill && !adaptorPtr->GetStill)
+ pa->type &= ~XvStillMask;
+
+ if(!adaptorPtr->PutImage || !adaptorPtr->QueryImageAttributes)
+ pa->type &= ~XvImageMask;
+
+ if(!adaptorPtr->PutVideo && !adaptorPtr->PutImage &&
+ !adaptorPtr->PutStill)
+ pa->type &= ~XvInputMask;
+
+ if(!adaptorPtr->GetVideo && !adaptorPtr->GetStill)
+ pa->type &= ~XvOutputMask;
+
+ if(!(adaptorPtr->type & (XvPixmapMask | XvWindowMask)))
+ continue;
+ if(!(adaptorPtr->type & (XvImageMask | XvVideoMask | XvStillMask)))
+ continue;
+
+ pa->pScreen = pScreen;
+ pa->ddAllocatePort = xf86XVAllocatePort;
+ pa->ddFreePort = xf86XVFreePort;
+ pa->ddPutVideo = xf86XVPutVideo;
+ pa->ddPutStill = xf86XVPutStill;
+ pa->ddGetVideo = xf86XVGetVideo;
+ pa->ddGetStill = xf86XVGetStill;
+ pa->ddStopVideo = xf86XVStopVideo;
+ pa->ddPutImage = xf86XVPutImage;
+ pa->ddSetPortAttribute = xf86XVSetPortAttribute;
+ pa->ddGetPortAttribute = xf86XVGetPortAttribute;
+ pa->ddQueryBestSize = xf86XVQueryBestSize;
+ pa->ddQueryImageAttributes = xf86XVQueryImageAttributes;
+ if((pa->name = xalloc(strlen(adaptorPtr->name) + 1)))
+ strcpy(pa->name, adaptorPtr->name);
+
+ if(adaptorPtr->nEncodings &&
+ (pEncode = xcalloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) {
+
+ for(pe = pEncode, encodingPtr = adaptorPtr->pEncodings, i = 0;
+ i < adaptorPtr->nEncodings; pe++, i++, encodingPtr++)
+ {
+ pe->id = encodingPtr->id;
+ pe->pScreen = pScreen;
+ if((pe->name = xalloc(strlen(encodingPtr->name) + 1)))
+ strcpy(pe->name, encodingPtr->name);
+ pe->width = encodingPtr->width;
+ pe->height = encodingPtr->height;
+ pe->rate.numerator = encodingPtr->rate.numerator;
+ pe->rate.denominator = encodingPtr->rate.denominator;
+ }
+ pa->nEncodings = adaptorPtr->nEncodings;
+ pa->pEncodings = pEncode;
+ }
+
+ if(adaptorPtr->nImages &&
+ (pImage = xcalloc(adaptorPtr->nImages, sizeof(XvImageRec)))) {
+
+ for(i = 0, pi = pImage, imagePtr = adaptorPtr->pImages;
+ i < adaptorPtr->nImages; i++, pi++, imagePtr++)
+ {
+ pi->id = imagePtr->id;
+ pi->type = imagePtr->type;
+ pi->byte_order = imagePtr->byte_order;
+ memcpy(pi->guid, imagePtr->guid, 16);
+ pi->bits_per_pixel = imagePtr->bits_per_pixel;
+ pi->format = imagePtr->format;
+ pi->num_planes = imagePtr->num_planes;
+ pi->depth = imagePtr->depth;
+ pi->red_mask = imagePtr->red_mask;
+ pi->green_mask = imagePtr->green_mask;
+ pi->blue_mask = imagePtr->blue_mask;
+ pi->y_sample_bits = imagePtr->y_sample_bits;
+ pi->u_sample_bits = imagePtr->u_sample_bits;
+ pi->v_sample_bits = imagePtr->v_sample_bits;
+ pi->horz_y_period = imagePtr->horz_y_period;
+ pi->horz_u_period = imagePtr->horz_u_period;
+ pi->horz_v_period = imagePtr->horz_v_period;
+ pi->vert_y_period = imagePtr->vert_y_period;
+ pi->vert_u_period = imagePtr->vert_u_period;
+ pi->vert_v_period = imagePtr->vert_v_period;
+ memcpy(pi->component_order, imagePtr->component_order, 32);
+ pi->scanline_order = imagePtr->scanline_order;
+ }
+ pa->nImages = adaptorPtr->nImages;
+ pa->pImages = pImage;
+ }
+
+ if(adaptorPtr->nAttributes &&
+ (pAttribute = xcalloc(adaptorPtr->nAttributes, sizeof(XvAttributeRec))))
+ {
+ for(pat = pAttribute, attributePtr = adaptorPtr->pAttributes, i = 0;
+ i < adaptorPtr->nAttributes; pat++, i++, attributePtr++)
+ {
+ pat->flags = attributePtr->flags;
+ pat->min_value = attributePtr->min_value;
+ pat->max_value = attributePtr->max_value;
+ if((pat->name = xalloc(strlen(attributePtr->name) + 1)))
+ strcpy(pat->name, attributePtr->name);
+ }
+ pa->nAttributes = adaptorPtr->nAttributes;
+ pa->pAttributes = pAttribute;
+ }
+
+
+ totFormat = adaptorPtr->nFormats;
+
+ if(!(pFormat = xcalloc(totFormat, sizeof(XvFormatRec)))) {
+ xf86XVFreeAdaptor(pa);
+ continue;
+ }
+ for(pf = pFormat, i = 0, numFormat = 0, formatPtr = adaptorPtr->pFormats;
+ i < adaptorPtr->nFormats; i++, formatPtr++)
+ {
+ numVisuals = pScreen->numVisuals;
+ pVisual = pScreen->visuals;
+
+ while(numVisuals--) {
+ if((pVisual->class == formatPtr->class) &&
+ (pVisual->nplanes == formatPtr->depth)) {
+
+ if(numFormat >= totFormat) {
+ void *moreSpace;
+ totFormat *= 2;
+ moreSpace = xrealloc(pFormat,
+ totFormat * sizeof(XvFormatRec));
+ if(!moreSpace) break;
+ pFormat = moreSpace;
+ pf = pFormat + numFormat;
+ }
+
+ pf->visual = pVisual->vid;
+ pf->depth = formatPtr->depth;
+
+ pf++;
+ numFormat++;
+ }
+ pVisual++;
+ }
+ }
+ pa->nFormats = numFormat;
+ pa->pFormats = pFormat;
+ if(!numFormat) {
+ xf86XVFreeAdaptor(pa);
+ continue;
+ }
+
+ if(!(adaptorPriv = xcalloc(1, sizeof(XvAdaptorRecPrivate)))) {
+ xf86XVFreeAdaptor(pa);
+ continue;
+ }
+
+ adaptorPriv->flags = adaptorPtr->flags;
+ adaptorPriv->PutVideo = adaptorPtr->PutVideo;
+ adaptorPriv->PutStill = adaptorPtr->PutStill;
+ adaptorPriv->GetVideo = adaptorPtr->GetVideo;
+ adaptorPriv->GetStill = adaptorPtr->GetStill;
+ adaptorPriv->StopVideo = adaptorPtr->StopVideo;
+ adaptorPriv->SetPortAttribute = adaptorPtr->SetPortAttribute;
+ adaptorPriv->GetPortAttribute = adaptorPtr->GetPortAttribute;
+ adaptorPriv->QueryBestSize = adaptorPtr->QueryBestSize;
+ adaptorPriv->QueryImageAttributes = adaptorPtr->QueryImageAttributes;
+ adaptorPriv->PutImage = adaptorPtr->PutImage;
+ adaptorPriv->ReputImage = adaptorPtr->ReputImage;
+
+ pa->devPriv.ptr = (pointer)adaptorPriv;
+
+ if(!(pPort = xcalloc(adaptorPtr->nPorts, sizeof(XvPortRec)))) {
+ xf86XVFreeAdaptor(pa);
+ continue;
+ }
+ for(pp = pPort, i = 0, numPort = 0;
+ i < adaptorPtr->nPorts; i++) {
+
+ if(!(pp->id = FakeClientID(0)))
+ continue;
+
+ if(!(portPriv = xcalloc(1, sizeof(XvPortRecPrivate))))
+ continue;
+
+ if(!AddResource(pp->id, PortResource, pp)) {
+ xfree(portPriv);
+ continue;
+ }
+
+ pp->pAdaptor = pa;
+ pp->pNotify = (XvPortNotifyPtr)NULL;
+ pp->pDraw = (DrawablePtr)NULL;
+ pp->client = (ClientPtr)NULL;
+ pp->grab.client = (ClientPtr)NULL;
+ pp->time = currentTime;
+ pp->devPriv.ptr = portPriv;
+
+ portPriv->pScrn = pScrn;
+ portPriv->AdaptorRec = adaptorPriv;
+ portPriv->DevPriv.ptr = adaptorPtr->pPortPrivates[i].ptr;
+
+ pp++;
+ numPort++;
+ }
+ pa->nPorts = numPort;
+ pa->pPorts = pPort;
+ if(!numPort) {
+ xf86XVFreeAdaptor(pa);
+ continue;
+ }
+
+ pa->base_id = pPort->id;
+
+ pa++;
+ numAdaptor++;
+ }
+
+ if(numAdaptor) {
+ pxvs->nAdaptors = numAdaptor;
+ pxvs->pAdaptors = pAdaptor;
+ } else {
+ xfree(pAdaptor);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Video should be clipped to the intersection of the window cliplist
+ and the client cliplist specified in the GC for which the video was
+ initialized. When we need to reclip a window, the GC that started
+ the video may not even be around anymore. That's why we save the
+ client clip from the GC when the video is initialized. We then
+ use xf86XVUpdateCompositeClip to calculate the new composite clip
+ when we need it. This is different from what DEC did. They saved
+ the GC and used it's clip list when they needed to reclip the window,
+ even if the client clip was different from the one the video was
+ initialized with. If the original GC was destroyed, they had to stop
+ the video. I like the new method better (MArk).
+
+ This function only works for windows. Will need to rewrite when
+ (if) we support pixmap rendering.
+*/
+
+static void
+xf86XVUpdateCompositeClip(XvPortRecPrivatePtr portPriv)
+{
+ RegionPtr pregWin, pCompositeClip;
+ WindowPtr pWin;
+ ScreenPtr pScreen;
+ Bool freeCompClip = FALSE;
+
+ if(portPriv->pCompositeClip)
+ return;
+
+ pWin = (WindowPtr)portPriv->pDraw;
+ pScreen = pWin->drawable.pScreen;
+
+ /* get window clip list */
+ if(portPriv->subWindowMode == IncludeInferiors) {
+ pregWin = NotClippedByChildren(pWin);
+ freeCompClip = TRUE;
+ } else
+ pregWin = &pWin->clipList;
+
+ if(!portPriv->clientClip) {
+ portPriv->pCompositeClip = pregWin;
+ portPriv->FreeCompositeClip = freeCompClip;
+ return;
+ }
+
+ pCompositeClip = REGION_CREATE(pScreen, NullBox, 1);
+ REGION_COPY(pScreen, pCompositeClip, portPriv->clientClip);
+ REGION_TRANSLATE(pScreen, pCompositeClip,
+ portPriv->pDraw->x + portPriv->clipOrg.x,
+ portPriv->pDraw->y + portPriv->clipOrg.y);
+ REGION_INTERSECT(pScreen, pCompositeClip, pregWin, pCompositeClip);
+
+ portPriv->pCompositeClip = pCompositeClip;
+ portPriv->FreeCompositeClip = TRUE;
+
+ if(freeCompClip) {
+ REGION_DESTROY(pScreen, pregWin);
+ }
+}
+
+/* Save the current clientClip and update the CompositeClip whenever
+ we have a fresh GC */
+
+static void
+xf86XVCopyClip(
+ XvPortRecPrivatePtr portPriv,
+ GCPtr pGC
+){
+ ScreenPtr pScreen = pGC->pScreen;
+
+ /* copy the new clip if it exists */
+ if((pGC->clientClipType == CT_REGION) && pGC->clientClip) {
+ if(!portPriv->clientClip)
+ portPriv->clientClip = REGION_CREATE(pScreen, NullBox, 1);
+ /* Note: this is in window coordinates */
+ REGION_COPY(pScreen, portPriv->clientClip, pGC->clientClip);
+ } else if(portPriv->clientClip) { /* free the old clientClip */
+ REGION_DESTROY(pScreen, portPriv->clientClip);
+ portPriv->clientClip = NULL;
+ }
+
+ /* get rid of the old clip list */
+ if(portPriv->pCompositeClip && portPriv->FreeCompositeClip) {
+ REGION_DESTROY(pScreen, portPriv->pCompositeClip);
+ }
+
+ portPriv->clipOrg = pGC->clipOrg;
+ portPriv->pCompositeClip = pGC->pCompositeClip;
+ portPriv->FreeCompositeClip = FALSE;
+ portPriv->subWindowMode = pGC->subWindowMode;
+}
+
+static int
+xf86XVRegetVideo(XvPortRecPrivatePtr portPriv)
+{
+ RegionRec WinRegion;
+ RegionRec ClipRegion;
+ BoxRec WinBox;
+ ScreenPtr pScreen;
+ int ret = Success;
+ Bool clippedAway = FALSE;
+
+ pScreen = portPriv->pDraw->pScreen;
+ xf86XVUpdateCompositeClip(portPriv);
+
+ /* translate the video region to the screen */
+ WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x;
+ WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y;
+ WinBox.x2 = WinBox.x1 + portPriv->drw_w;
+ WinBox.y2 = WinBox.y1 + portPriv->drw_h;
+
+ /* clip to the window composite clip */
+ REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
+ REGION_NULL(pScreen, &ClipRegion);
+ REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+
+ /* that's all if it's totally obscured */
+ if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+ clippedAway = TRUE;
+ goto CLIP_VIDEO_BAILOUT;
+ }
+
+ if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
+ REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+ }
+
+ ret = (*portPriv->AdaptorRec->GetVideo)(portPriv->pScrn,
+ portPriv->vid_x, portPriv->vid_y,
+ WinBox.x1, WinBox.y1,
+ portPriv->vid_w, portPriv->vid_h,
+ portPriv->drw_w, portPriv->drw_h,
+ &ClipRegion, portPriv->DevPriv.ptr);
+
+ if(ret == Success)
+ portPriv->isOn = XV_ON;
+
+CLIP_VIDEO_BAILOUT:
+
+ if((clippedAway || (ret != Success)) && portPriv->isOn == XV_ON) {
+ (*portPriv->AdaptorRec->StopVideo)(
+ portPriv->pScrn, portPriv->DevPriv.ptr, FALSE);
+ portPriv->isOn = XV_PENDING;
+ }
+
+ /* This clip was copied and only good for one shot */
+ if(!portPriv->FreeCompositeClip)
+ portPriv->pCompositeClip = NULL;
+
+ REGION_UNINIT(pScreen, &WinRegion);
+ REGION_UNINIT(pScreen, &ClipRegion);
+
+ return ret;
+}
+
+
+static int
+xf86XVReputVideo(XvPortRecPrivatePtr portPriv)
+{
+ RegionRec WinRegion;
+ RegionRec ClipRegion;
+ BoxRec WinBox;
+ ScreenPtr pScreen;
+ int ret = Success;
+ Bool clippedAway = FALSE;
+
+ pScreen = portPriv->pDraw->pScreen;
+
+ xf86XVUpdateCompositeClip(portPriv);
+
+ /* translate the video region to the screen */
+ WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x;
+ WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y;
+ WinBox.x2 = WinBox.x1 + portPriv->drw_w;
+ WinBox.y2 = WinBox.y1 + portPriv->drw_h;
+
+ /* clip to the window composite clip */
+ REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
+ REGION_NULL(pScreen, &ClipRegion);
+ REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+
+ /* clip and translate to the viewport */
+ if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
+ RegionRec VPReg;
+ BoxRec VPBox;
+
+ VPBox.x1 = portPriv->pScrn->frameX0;
+ VPBox.y1 = portPriv->pScrn->frameY0;
+ VPBox.x2 = portPriv->pScrn->frameX1;
+ VPBox.y2 = portPriv->pScrn->frameY1;
+
+ REGION_INIT(pScreen, &VPReg, &VPBox, 1);
+ REGION_INTERSECT(pScreen, &ClipRegion, &ClipRegion, &VPReg);
+ REGION_UNINIT(pScreen, &VPReg);
+ }
+
+ /* that's all if it's totally obscured */
+ if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+ clippedAway = TRUE;
+ goto CLIP_VIDEO_BAILOUT;
+ }
+
+ /* bailout if we have to clip but the hardware doesn't support it */
+ if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
+ BoxPtr clipBox = REGION_RECTS(&ClipRegion);
+ if( (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+ (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
+ (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
+ {
+ clippedAway = TRUE;
+ goto CLIP_VIDEO_BAILOUT;
+ }
+ }
+
+ if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
+ REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+ }
+
+ ret = (*portPriv->AdaptorRec->PutVideo)(portPriv->pScrn,
+ portPriv->vid_x, portPriv->vid_y,
+ WinBox.x1, WinBox.y1,
+ portPriv->vid_w, portPriv->vid_h,
+ portPriv->drw_w, portPriv->drw_h,
+ &ClipRegion, portPriv->DevPriv.ptr);
+
+ if(ret == Success) portPriv->isOn = XV_ON;
+
+CLIP_VIDEO_BAILOUT:
+
+ if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) {
+ (*portPriv->AdaptorRec->StopVideo)(
+ portPriv->pScrn, portPriv->DevPriv.ptr, FALSE);
+ portPriv->isOn = XV_PENDING;
+ }
+
+ /* This clip was copied and only good for one shot */
+ if(!portPriv->FreeCompositeClip)
+ portPriv->pCompositeClip = NULL;
+
+ REGION_UNINIT(pScreen, &WinRegion);
+ REGION_UNINIT(pScreen, &ClipRegion);
+
+ return ret;
+}
+
+static int
+xf86XVReputImage(XvPortRecPrivatePtr portPriv)
+{
+ RegionRec WinRegion;
+ RegionRec ClipRegion;
+ BoxRec WinBox;
+ ScreenPtr pScreen;
+ int ret = Success;
+ Bool clippedAway = FALSE;
+
+ pScreen = portPriv->pDraw->pScreen;
+
+ xf86XVUpdateCompositeClip(portPriv);
+
+ /* translate the video region to the screen */
+ WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x;
+ WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y;
+ WinBox.x2 = WinBox.x1 + portPriv->drw_w;
+ WinBox.y2 = WinBox.y1 + portPriv->drw_h;
+
+ /* clip to the window composite clip */
+ REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
+ REGION_NULL(pScreen, &ClipRegion);
+ REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+
+ /* clip and translate to the viewport */
+ if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
+ RegionRec VPReg;
+ BoxRec VPBox;
+
+ VPBox.x1 = portPriv->pScrn->frameX0;
+ VPBox.y1 = portPriv->pScrn->frameY0;
+ VPBox.x2 = portPriv->pScrn->frameX1;
+ VPBox.y2 = portPriv->pScrn->frameY1;
+
+ REGION_INIT(pScreen, &VPReg, &VPBox, 1);
+ REGION_INTERSECT(pScreen, &ClipRegion, &ClipRegion, &VPReg);
+ REGION_UNINIT(pScreen, &VPReg);
+ }
+
+ /* that's all if it's totally obscured */
+ if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+ clippedAway = TRUE;
+ goto CLIP_VIDEO_BAILOUT;
+ }
+
+ /* bailout if we have to clip but the hardware doesn't support it */
+ if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
+ BoxPtr clipBox = REGION_RECTS(&ClipRegion);
+ if( (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+ (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
+ (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
+ {
+ clippedAway = TRUE;
+ goto CLIP_VIDEO_BAILOUT;
+ }
+ }
+
+ if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
+ REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+ }
+
+ ret = (*portPriv->AdaptorRec->ReputImage)(portPriv->pScrn,
+ WinBox.x1, WinBox.y1,
+ &ClipRegion, portPriv->DevPriv.ptr);
+
+ portPriv->isOn = (ret == Success) ? XV_ON : XV_OFF;
+
+CLIP_VIDEO_BAILOUT:
+
+ if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) {
+ (*portPriv->AdaptorRec->StopVideo)(
+ portPriv->pScrn, portPriv->DevPriv.ptr, FALSE);
+ portPriv->isOn = XV_PENDING;
+ }
+
+ /* This clip was copied and only good for one shot */
+ if(!portPriv->FreeCompositeClip)
+ portPriv->pCompositeClip = NULL;
+
+ REGION_UNINIT(pScreen, &WinRegion);
+ REGION_UNINIT(pScreen, &ClipRegion);
+
+ return ret;
+}
+
+
+static int
+xf86XVReputAllVideo(WindowPtr pWin, pointer data)
+{
+ XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin);
+
+ while(WinPriv) {
+ if(WinPriv->PortRec->type == XvInputMask)
+ xf86XVReputVideo(WinPriv->PortRec);
+ else
+ xf86XVRegetVideo(WinPriv->PortRec);
+ WinPriv = WinPriv->next;
+ }
+
+ return WT_WALKCHILDREN;
+}
+
+static int
+xf86XVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
+{
+ XF86XVWindowPtr winPriv, PrivRoot;
+
+ winPriv = PrivRoot = GET_XF86XV_WINDOW(pWin);
+
+ /* Enlist our port in the window private */
+ while(winPriv) {
+ if(winPriv->PortRec == portPriv) /* we're already listed */
+ break;
+ winPriv = winPriv->next;
+ }
+
+ if(!winPriv) {
+ winPriv = xalloc(sizeof(XF86XVWindowRec));
+ if(!winPriv) return BadAlloc;
+ winPriv->PortRec = portPriv;
+ winPriv->next = PrivRoot;
+ pWin->devPrivates[XF86XVWindowIndex].ptr = (pointer)winPriv;
+ }
+ return Success;
+}
+
+
+static void
+xf86XVRemovePortFromWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
+{
+ XF86XVWindowPtr winPriv, prevPriv = NULL;
+
+ winPriv = GET_XF86XV_WINDOW(pWin);
+
+ while(winPriv) {
+ if(winPriv->PortRec == portPriv) {
+ if(prevPriv)
+ prevPriv->next = winPriv->next;
+ else
+ pWin->devPrivates[XF86XVWindowIndex].ptr =
+ (pointer)winPriv->next;
+ xfree(winPriv);
+ break;
+ }
+ prevPriv = winPriv;
+ winPriv = winPriv->next;
+ }
+ portPriv->pDraw = NULL;
+}
+
+/**** ScreenRec fields ****/
+
+static Bool
+xf86XVDestroyWindow(WindowPtr pWin)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
+ XF86XVWindowPtr tmp, WinPriv = GET_XF86XV_WINDOW(pWin);
+ int ret;
+
+ while(WinPriv) {
+ XvPortRecPrivatePtr pPriv = WinPriv->PortRec;
+
+ if(pPriv->isOn > XV_OFF) {
+ (*pPriv->AdaptorRec->StopVideo)(
+ pPriv->pScrn, pPriv->DevPriv.ptr, TRUE);
+ pPriv->isOn = XV_OFF;
+ }
+
+ pPriv->pDraw = NULL;
+ tmp = WinPriv;
+ WinPriv = WinPriv->next;
+ xfree(tmp);
+ }
+
+ pWin->devPrivates[XF86XVWindowIndex].ptr = NULL;
+
+ pScreen->DestroyWindow = ScreenPriv->DestroyWindow;
+ ret = (*pScreen->DestroyWindow)(pWin);
+ pScreen->DestroyWindow = xf86XVDestroyWindow;
+
+ return ret;
+}
+
+
+static void
+xf86XVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
+ XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin);
+ XF86XVWindowPtr pPrev;
+ XvPortRecPrivatePtr pPriv;
+ Bool AreasExposed;
+
+ AreasExposed = (WinPriv && reg1 && REGION_NOTEMPTY(pScreen, reg1));
+
+ pScreen->WindowExposures = ScreenPriv->WindowExposures;
+ (*pScreen->WindowExposures)(pWin, reg1, reg2);
+ pScreen->WindowExposures = xf86XVWindowExposures;
+
+ /* filter out XClearWindow/Area */
+ if (!pWin->valdata) return;
+
+ pPrev = NULL;
+
+ while(WinPriv) {
+ pPriv = WinPriv->PortRec;
+
+ /* Reput anyone with a reput function */
+
+ switch(pPriv->type) {
+ case XvInputMask:
+ xf86XVReputVideo(pPriv);
+ break;
+ case XvOutputMask:
+ xf86XVRegetVideo(pPriv);
+ break;
+ default: /* overlaid still/image*/
+ if (pPriv->AdaptorRec->ReputImage)
+ xf86XVReputImage(pPriv);
+ else if(AreasExposed) {
+ XF86XVWindowPtr tmp;
+
+ if (pPriv->isOn == XV_ON) {
+ (*pPriv->AdaptorRec->StopVideo)(
+ pPriv->pScrn, pPriv->DevPriv.ptr, FALSE);
+ pPriv->isOn = XV_PENDING;
+ }
+ pPriv->pDraw = NULL;
+
+ if(!pPrev)
+ pWin->devPrivates[XF86XVWindowIndex].ptr =
+ (pointer)(WinPriv->next);
+ else
+ pPrev->next = WinPriv->next;
+ tmp = WinPriv;
+ WinPriv = WinPriv->next;
+ xfree(tmp);
+ continue;
+ }
+ break;
+ }
+ pPrev = WinPriv;
+ WinPriv = WinPriv->next;
+ }
+}
+
+
+static void
+xf86XVClipNotify(WindowPtr pWin, int dx, int dy)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
+ XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin);
+ XF86XVWindowPtr tmp, pPrev = NULL;
+ XvPortRecPrivatePtr pPriv;
+ Bool visible = (pWin->visibility == VisibilityUnobscured) ||
+ (pWin->visibility == VisibilityPartiallyObscured);
+
+ while(WinPriv) {
+ pPriv = WinPriv->PortRec;
+
+ if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
+ REGION_DESTROY(pScreen, pPriv->pCompositeClip);
+
+ pPriv->pCompositeClip = NULL;
+
+ /* Stop everything except images, but stop them too if the
+ window isn't visible. But we only remove the images. */
+
+ if(pPriv->type || !visible) {
+ if(pPriv->isOn == XV_ON) {
+ (*pPriv->AdaptorRec->StopVideo)(
+ pPriv->pScrn, pPriv->DevPriv.ptr, FALSE);
+ pPriv->isOn = XV_PENDING;
+ }
+
+ if(!pPriv->type) { /* overlaid still/image */
+ pPriv->pDraw = NULL;
+
+ if(!pPrev)
+ pWin->devPrivates[XF86XVWindowIndex].ptr =
+ (pointer)(WinPriv->next);
+ else
+ pPrev->next = WinPriv->next;
+ tmp = WinPriv;
+ WinPriv = WinPriv->next;
+ xfree(tmp);
+ continue;
+ }
+ }
+
+ pPrev = WinPriv;
+ WinPriv = WinPriv->next;
+ }
+
+ if(ScreenPriv->ClipNotify) {
+ pScreen->ClipNotify = ScreenPriv->ClipNotify;
+ (*pScreen->ClipNotify)(pWin, dx, dy);
+ pScreen->ClipNotify = xf86XVClipNotify;
+ }
+}
+
+
+
+/**** Required XvScreenRec fields ****/
+
+static Bool
+xf86XVCloseScreen(int i, ScreenPtr pScreen)
+{
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
+ XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
+ XvAdaptorPtr pa;
+ int c;
+
+ /* Clear offscreen images */
+ (void)memset(&OffscreenImages[pScreen->myNum], 0, sizeof(OffscreenImages[0]));
+
+ if(!ScreenPriv) return TRUE;
+
+ if(ScreenPriv->videoGC) {
+ FreeGC(ScreenPriv->videoGC, 0);
+ ScreenPriv->videoGC = NULL;
+ }
+
+ pScreen->DestroyWindow = ScreenPriv->DestroyWindow;
+ pScreen->WindowExposures = ScreenPriv->WindowExposures;
+ pScreen->ClipNotify = ScreenPriv->ClipNotify;
+
+ pScrn->EnterVT = ScreenPriv->EnterVT;
+ pScrn->LeaveVT = ScreenPriv->LeaveVT;
+ pScrn->AdjustFrame = ScreenPriv->AdjustFrame;
+
+ for(c = 0, pa = pxvs->pAdaptors; c < pxvs->nAdaptors; c++, pa++) {
+ xf86XVFreeAdaptor(pa);
+ }
+
+ xfree(pxvs->pAdaptors);
+ xfree(ScreenPriv);
+ return TRUE;
+}
+
+
+static int
+xf86XVQueryAdaptors(
+ ScreenPtr pScreen,
+ XvAdaptorPtr *p_pAdaptors,
+ int *p_nAdaptors
+){
+ XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
+
+ *p_nAdaptors = pxvs->nAdaptors;
+ *p_pAdaptors = pxvs->pAdaptors;
+
+ return (Success);
+}
+
+
+/**** ScrnInfoRec fields ****/
+
+static Bool
+xf86XVEnterVT(int index, int flags)
+{
+ ScreenPtr pScreen = screenInfo.screens[index];
+ XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
+ Bool ret;
+
+ ret = (*ScreenPriv->EnterVT)(index, flags);
+
+ if(ret) WalkTree(pScreen, xf86XVReputAllVideo, 0);
+
+ return ret;
+}
+
+static void
+xf86XVLeaveVT(int index, int flags)
+{
+ ScreenPtr pScreen = screenInfo.screens[index];
+ XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
+ XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
+ XvAdaptorPtr pAdaptor;
+ XvPortPtr pPort;
+ XvPortRecPrivatePtr pPriv;
+ int i, j;
+
+ for(i = 0; i < pxvs->nAdaptors; i++) {
+ pAdaptor = &pxvs->pAdaptors[i];
+ for(j = 0; j < pAdaptor->nPorts; j++) {
+ pPort = &pAdaptor->pPorts[j];
+ pPriv = (XvPortRecPrivatePtr)pPort->devPriv.ptr;
+ if(pPriv->isOn > XV_OFF) {
+
+ (*pPriv->AdaptorRec->StopVideo)(
+ pPriv->pScrn, pPriv->DevPriv.ptr, TRUE);
+ pPriv->isOn = XV_OFF;
+
+ if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
+ REGION_DESTROY(pScreen, pPriv->pCompositeClip);
+
+ pPriv->pCompositeClip = NULL;
+
+ if(!pPriv->type && pPriv->pDraw) { /* still */
+ xf86XVRemovePortFromWindow((WindowPtr)pPriv->pDraw, pPriv);
+ }
+ }
+ }
+ }
+
+ (*ScreenPriv->LeaveVT)(index, flags);
+}
+
+static void
+xf86XVAdjustFrame(int index, int x, int y, int flags)
+{
+ ScrnInfoPtr pScrn = xf86Screens[index];
+ ScreenPtr pScreen = pScrn->pScreen;
+ XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
+ XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
+ WindowPtr pWin;
+ XvAdaptorPtr pa;
+ int c, i;
+
+ if(ScreenPriv->AdjustFrame) {
+ pScrn->AdjustFrame = ScreenPriv->AdjustFrame;
+ (*pScrn->AdjustFrame)(index, x, y, flags);
+ pScrn->AdjustFrame = xf86XVAdjustFrame;
+ }
+
+ for(c = pxvs->nAdaptors, pa = pxvs->pAdaptors; c > 0; c--, pa++) {
+ XvPortPtr pPort = pa->pPorts;
+ XvPortRecPrivatePtr pPriv;
+
+ for(i = pa->nPorts; i > 0; i--, pPort++) {
+ pPriv = (XvPortRecPrivatePtr)pPort->devPriv.ptr;
+
+ if(!pPriv->type && (pPriv->isOn == XV_ON)) { /* overlaid still/image */
+
+ if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
+ REGION_DESTROY(pScreen, pPriv->pCompositeClip);
+
+ pPriv->pCompositeClip = NULL;
+
+ pWin = (WindowPtr)pPriv->pDraw;
+
+ if ((pPriv->AdaptorRec->ReputImage) &&
+ ((pWin->visibility == VisibilityUnobscured) ||
+ (pWin->visibility == VisibilityPartiallyObscured)))
+ {
+ xf86XVReputImage(pPriv);
+ } else {
+ (*pPriv->AdaptorRec->StopVideo)(
+ pPriv->pScrn, pPriv->DevPriv.ptr, FALSE);
+ xf86XVRemovePortFromWindow(pWin, pPriv);
+ pPriv->isOn = XV_PENDING;
+ continue;
+ }
+ }
+ }
+ }
+}
+
+
+/**** XvAdaptorRec fields ****/
+
+static int
+xf86XVAllocatePort(
+ unsigned long port,
+ XvPortPtr pPort,
+ XvPortPtr *ppPort
+){
+ *ppPort = pPort;
+ return Success;
+}
+
+
+
+static int
+xf86XVFreePort(XvPortPtr pPort)
+{
+ return Success;
+}
+
+
+static int
+xf86XVPutVideo(
+ ClientPtr client,
+ DrawablePtr pDraw,
+ XvPortPtr pPort,
+ GCPtr pGC,
+ INT16 vid_x, INT16 vid_y,
+ CARD16 vid_w, CARD16 vid_h,
+ INT16 drw_x, INT16 drw_y,
+ CARD16 drw_w, CARD16 drw_h
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+ int result;
+
+ /* No dumping video to pixmaps... For now anyhow */
+ if(pDraw->type != DRAWABLE_WINDOW) {
+ pPort->pDraw = (DrawablePtr)NULL;
+ return BadAlloc;
+ }
+
+ /* If we are changing windows, unregister our port in the old window */
+ if(portPriv->pDraw && (portPriv->pDraw != pDraw))
+ xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
+
+ /* Register our port with the new window */
+ result = xf86XVEnlistPortInWindow((WindowPtr)pDraw, portPriv);
+ if(result != Success) return result;
+
+ portPriv->pDraw = pDraw;
+ portPriv->type = XvInputMask;
+
+ /* save a copy of these parameters */
+ portPriv->vid_x = vid_x; portPriv->vid_y = vid_y;
+ portPriv->vid_w = vid_w; portPriv->vid_h = vid_h;
+ portPriv->drw_x = drw_x; portPriv->drw_y = drw_y;
+ portPriv->drw_w = drw_w; portPriv->drw_h = drw_h;
+
+ /* make sure we have the most recent copy of the clientClip */
+ xf86XVCopyClip(portPriv, pGC);
+
+ /* To indicate to the DI layer that we were successful */
+ pPort->pDraw = pDraw;
+
+ if(!portPriv->pScrn->vtSema) return Success; /* Success ? */
+
+ return(xf86XVReputVideo(portPriv));
+}
+
+static int
+xf86XVPutStill(
+ ClientPtr client,
+ DrawablePtr pDraw,
+ XvPortPtr pPort,
+ GCPtr pGC,
+ INT16 vid_x, INT16 vid_y,
+ CARD16 vid_w, CARD16 vid_h,
+ INT16 drw_x, INT16 drw_y,
+ CARD16 drw_w, CARD16 drw_h
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+ ScreenPtr pScreen;
+ RegionRec WinRegion;
+ RegionRec ClipRegion;
+ BoxRec WinBox;
+ int ret = Success;
+ Bool clippedAway = FALSE;
+
+ if (pDraw->type != DRAWABLE_WINDOW)
+ return BadAlloc;
+
+ if(!portPriv->pScrn->vtSema) return Success; /* Success ? */
+
+ pScreen = pDraw->pScreen;
+
+ WinBox.x1 = pDraw->x + drw_x;
+ WinBox.y1 = pDraw->y + drw_y;
+ WinBox.x2 = WinBox.x1 + drw_w;
+ WinBox.y2 = WinBox.y1 + drw_h;
+
+ REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
+ REGION_NULL(pScreen, &ClipRegion);
+ REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
+
+ if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
+ RegionRec VPReg;
+ BoxRec VPBox;
+
+ VPBox.x1 = portPriv->pScrn->frameX0;
+ VPBox.y1 = portPriv->pScrn->frameY0;
+ VPBox.x2 = portPriv->pScrn->frameX1;
+ VPBox.y2 = portPriv->pScrn->frameY1;
+
+ REGION_INIT(pScreen, &VPReg, &VPBox, 1);
+ REGION_INTERSECT(pScreen, &ClipRegion, &ClipRegion, &VPReg);
+ REGION_UNINIT(pScreen, &VPReg);
+ }
+
+ if(portPriv->pDraw) {
+ xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
+ }
+
+ if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+ clippedAway = TRUE;
+ goto PUT_STILL_BAILOUT;
+ }
+
+ if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
+ BoxPtr clipBox = REGION_RECTS(&ClipRegion);
+ if( (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+ (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
+ (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
+ {
+ clippedAway = TRUE;
+ goto PUT_STILL_BAILOUT;
+ }
+ }
+
+ if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
+ REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+ }
+
+ ret = (*portPriv->AdaptorRec->PutStill)(portPriv->pScrn,
+ vid_x, vid_y, WinBox.x1, WinBox.y1,
+ vid_w, vid_h, drw_w, drw_h,
+ &ClipRegion, portPriv->DevPriv.ptr);
+
+ if((ret == Success) &&
+ (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_STILLS)) {
+
+ xf86XVEnlistPortInWindow((WindowPtr)pDraw, portPriv);
+ portPriv->isOn = XV_ON;
+ portPriv->pDraw = pDraw;
+ portPriv->drw_x = drw_x; portPriv->drw_y = drw_y;
+ portPriv->drw_w = drw_w; portPriv->drw_h = drw_h;
+ portPriv->type = 0; /* no mask means it's transient and should
+ not be reput once it's removed */
+ pPort->pDraw = pDraw; /* make sure we can get stop requests */
+ }
+
+PUT_STILL_BAILOUT:
+
+ if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) {
+ (*portPriv->AdaptorRec->StopVideo)(
+ portPriv->pScrn, portPriv->DevPriv.ptr, FALSE);
+ portPriv->isOn = XV_PENDING;
+ }
+
+ REGION_UNINIT(pScreen, &WinRegion);
+ REGION_UNINIT(pScreen, &ClipRegion);
+
+ return ret;
+}
+
+static int
+xf86XVGetVideo(
+ ClientPtr client,
+ DrawablePtr pDraw,
+ XvPortPtr pPort,
+ GCPtr pGC,
+ INT16 vid_x, INT16 vid_y,
+ CARD16 vid_w, CARD16 vid_h,
+ INT16 drw_x, INT16 drw_y,
+ CARD16 drw_w, CARD16 drw_h
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+ int result;
+
+ /* No pixmaps... For now anyhow */
+ if(pDraw->type != DRAWABLE_WINDOW) {
+ pPort->pDraw = (DrawablePtr)NULL;
+ return BadAlloc;
+ }
+
+ /* If we are changing windows, unregister our port in the old window */
+ if(portPriv->pDraw && (portPriv->pDraw != pDraw))
+ xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
+
+ /* Register our port with the new window */
+ result = xf86XVEnlistPortInWindow((WindowPtr)pDraw, portPriv);
+ if(result != Success) return result;
+
+ portPriv->pDraw = pDraw;
+ portPriv->type = XvOutputMask;
+
+ /* save a copy of these parameters */
+ portPriv->vid_x = vid_x; portPriv->vid_y = vid_y;
+ portPriv->vid_w = vid_w; portPriv->vid_h = vid_h;
+ portPriv->drw_x = drw_x; portPriv->drw_y = drw_y;
+ portPriv->drw_w = drw_w; portPriv->drw_h = drw_h;
+
+ /* make sure we have the most recent copy of the clientClip */
+ xf86XVCopyClip(portPriv, pGC);
+
+ /* To indicate to the DI layer that we were successful */
+ pPort->pDraw = pDraw;
+
+ if(!portPriv->pScrn->vtSema) return Success; /* Success ? */
+
+ return(xf86XVRegetVideo(portPriv));
+}
+
+static int
+xf86XVGetStill(
+ ClientPtr client,
+ DrawablePtr pDraw,
+ XvPortPtr pPort,
+ GCPtr pGC,
+ INT16 vid_x, INT16 vid_y,
+ CARD16 vid_w, CARD16 vid_h,
+ INT16 drw_x, INT16 drw_y,
+ CARD16 drw_w, CARD16 drw_h
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+ ScreenPtr pScreen;
+ RegionRec WinRegion;
+ RegionRec ClipRegion;
+ BoxRec WinBox;
+ int ret = Success;
+ Bool clippedAway = FALSE;
+
+ if (pDraw->type != DRAWABLE_WINDOW)
+ return BadAlloc;
+
+ if(!portPriv->pScrn->vtSema) return Success; /* Success ? */
+
+ pScreen = pDraw->pScreen;
+
+ WinBox.x1 = pDraw->x + drw_x;
+ WinBox.y1 = pDraw->y + drw_y;
+ WinBox.x2 = WinBox.x1 + drw_w;
+ WinBox.y2 = WinBox.y1 + drw_h;
+
+ REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
+ REGION_NULL(pScreen, &ClipRegion);
+ REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
+
+ if(portPriv->pDraw) {
+ xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
+ }
+
+ if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+ clippedAway = TRUE;
+ goto GET_STILL_BAILOUT;
+ }
+
+ if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
+ REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+ }
+
+ ret = (*portPriv->AdaptorRec->GetStill)(portPriv->pScrn,
+ vid_x, vid_y, WinBox.x1, WinBox.y1,
+ vid_w, vid_h, drw_w, drw_h,
+ &ClipRegion, portPriv->DevPriv.ptr);
+
+GET_STILL_BAILOUT:
+
+ if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) {
+ (*portPriv->AdaptorRec->StopVideo)(
+ portPriv->pScrn, portPriv->DevPriv.ptr, FALSE);
+ portPriv->isOn = XV_PENDING;
+ }
+
+ REGION_UNINIT(pScreen, &WinRegion);
+ REGION_UNINIT(pScreen, &ClipRegion);
+
+ return ret;
+}
+
+
+
+static int
+xf86XVStopVideo(
+ ClientPtr client,
+ XvPortPtr pPort,
+ DrawablePtr pDraw
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+
+ if(pDraw->type != DRAWABLE_WINDOW)
+ return BadAlloc;
+
+ xf86XVRemovePortFromWindow((WindowPtr)pDraw, portPriv);
+
+ if(!portPriv->pScrn->vtSema) return Success; /* Success ? */
+
+ /* Must free resources. */
+
+ if(portPriv->isOn > XV_OFF) {
+ (*portPriv->AdaptorRec->StopVideo)(
+ portPriv->pScrn, portPriv->DevPriv.ptr, TRUE);
+ portPriv->isOn = XV_OFF;
+ }
+
+ return Success;
+}
+
+static int
+xf86XVSetPortAttribute(
+ ClientPtr client,
+ XvPortPtr pPort,
+ Atom attribute,
+ INT32 value
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+
+ return((*portPriv->AdaptorRec->SetPortAttribute)(portPriv->pScrn,
+ attribute, value, portPriv->DevPriv.ptr));
+}
+
+
+static int
+xf86XVGetPortAttribute(
+ ClientPtr client,
+ XvPortPtr pPort,
+ Atom attribute,
+ INT32 *p_value
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+
+ return((*portPriv->AdaptorRec->GetPortAttribute)(portPriv->pScrn,
+ attribute, p_value, portPriv->DevPriv.ptr));
+}
+
+
+
+static int
+xf86XVQueryBestSize(
+ ClientPtr client,
+ XvPortPtr pPort,
+ CARD8 motion,
+ CARD16 vid_w, CARD16 vid_h,
+ CARD16 drw_w, CARD16 drw_h,
+ unsigned int *p_w, unsigned int *p_h
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+
+ (*portPriv->AdaptorRec->QueryBestSize)(portPriv->pScrn,
+ (Bool)motion, vid_w, vid_h, drw_w, drw_h,
+ p_w, p_h, portPriv->DevPriv.ptr);
+
+ return Success;
+}
+
+
+static int
+xf86XVPutImage(
+ ClientPtr client,
+ DrawablePtr pDraw,
+ XvPortPtr pPort,
+ GCPtr pGC,
+ INT16 src_x, INT16 src_y,
+ CARD16 src_w, CARD16 src_h,
+ INT16 drw_x, INT16 drw_y,
+ CARD16 drw_w, CARD16 drw_h,
+ XvImagePtr format,
+ unsigned char* data,
+ Bool sync,
+ CARD16 width, CARD16 height
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+ ScreenPtr pScreen;
+ RegionRec WinRegion;
+ RegionRec ClipRegion;
+ BoxRec WinBox;
+ int ret = Success;
+ Bool clippedAway = FALSE;
+
+ if (pDraw->type != DRAWABLE_WINDOW)
+ return BadAlloc;
+
+ if(!portPriv->pScrn->vtSema) return Success; /* Success ? */
+
+ pScreen = pDraw->pScreen;
+
+ WinBox.x1 = pDraw->x + drw_x;
+ WinBox.y1 = pDraw->y + drw_y;
+ WinBox.x2 = WinBox.x1 + drw_w;
+ WinBox.y2 = WinBox.y1 + drw_h;
+
+ REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
+ REGION_NULL(pScreen, &ClipRegion);
+ REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
+
+ if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
+ RegionRec VPReg;
+ BoxRec VPBox;
+
+ VPBox.x1 = portPriv->pScrn->frameX0;
+ VPBox.y1 = portPriv->pScrn->frameY0;
+ VPBox.x2 = portPriv->pScrn->frameX1 + 1;
+ VPBox.y2 = portPriv->pScrn->frameY1 + 1;
+
+ REGION_INIT(pScreen, &VPReg, &VPBox, 1);
+ REGION_INTERSECT(pScreen, &ClipRegion, &ClipRegion, &VPReg);
+ REGION_UNINIT(pScreen, &VPReg);
+ }
+
+ if(portPriv->pDraw) {
+ xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
+ }
+
+ if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+ clippedAway = TRUE;
+ goto PUT_IMAGE_BAILOUT;
+ }
+
+ if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
+ BoxPtr clipBox = REGION_RECTS(&ClipRegion);
+ if( (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+ (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
+ (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
+ {
+ clippedAway = TRUE;
+ goto PUT_IMAGE_BAILOUT;
+ }
+ }
+
+ if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
+ REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+ }
+
+ ret = (*portPriv->AdaptorRec->PutImage)(portPriv->pScrn,
+ src_x, src_y, WinBox.x1, WinBox.y1,
+ src_w, src_h, drw_w, drw_h, format->id, data, width, height,
+ sync, &ClipRegion, portPriv->DevPriv.ptr);
+
+ if((ret == Success) &&
+ (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_IMAGES)) {
+
+ xf86XVEnlistPortInWindow((WindowPtr)pDraw, portPriv);
+ portPriv->isOn = XV_ON;
+ portPriv->pDraw = pDraw;
+ portPriv->drw_x = drw_x; portPriv->drw_y = drw_y;
+ portPriv->drw_w = drw_w; portPriv->drw_h = drw_h;
+ portPriv->type = 0; /* no mask means it's transient and should
+ not be reput once it's removed */
+ pPort->pDraw = pDraw; /* make sure we can get stop requests */
+ }
+
+PUT_IMAGE_BAILOUT:
+
+ if((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) {
+ (*portPriv->AdaptorRec->StopVideo)(
+ portPriv->pScrn, portPriv->DevPriv.ptr, FALSE);
+ portPriv->isOn = XV_PENDING;
+ }
+
+ REGION_UNINIT(pScreen, &WinRegion);
+ REGION_UNINIT(pScreen, &ClipRegion);
+
+ return ret;
+}
+
+
+static int
+xf86XVQueryImageAttributes(
+ ClientPtr client,
+ XvPortPtr pPort,
+ XvImagePtr format,
+ CARD16 *width,
+ CARD16 *height,
+ int *pitches,
+ int *offsets
+){
+ XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+
+ return (*portPriv->AdaptorRec->QueryImageAttributes)(portPriv->pScrn,
+ format->id, width, height, pitches, offsets);
+}
+
+void
+xf86XVFillKeyHelper (ScreenPtr pScreen, CARD32 key, RegionPtr clipboxes)
+{
+ XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
+ DrawablePtr root = &WindowTable[pScreen->myNum]->drawable;
+ XID pval[2];
+ BoxPtr pbox = REGION_RECTS(clipboxes);
+ int i, nbox = REGION_NUM_RECTS(clipboxes);
+ xRectangle *rects;
+
+ if(!xf86Screens[pScreen->myNum]->vtSema) return;
+
+ if(!ScreenPriv->videoGC) {
+ int status;
+ pval[0] = key;
+ pval[1] = IncludeInferiors;
+ ScreenPriv->videoGC = CreateGC(root, GCForeground | GCSubwindowMode,
+ pval, &status);
+ if(!ScreenPriv->videoGC) return;
+ ValidateGC(root, ScreenPriv->videoGC);
+ } else if (key != ScreenPriv->videoGC->fgPixel){
+ pval[0] = key;
+ ChangeGC(ScreenPriv->videoGC, GCForeground, pval);
+ ValidateGC(root, ScreenPriv->videoGC);
+ }
+
+ rects = ALLOCATE_LOCAL(nbox * sizeof(xRectangle));
+
+ for(i = 0; i < nbox; i++, pbox++) {
+ rects[i].x = pbox->x1;
+ rects[i].y = pbox->y1;
+ rects[i].width = pbox->x2 - pbox->x1;
+ rects[i].height = pbox->y2 - pbox->y1;
+ }
+
+ (*ScreenPriv->videoGC->ops->PolyFillRect)(
+ root, ScreenPriv->videoGC, nbox, rects);
+
+ DEALLOCATE_LOCAL(rects);
+}
+
+/* xf86XVClipVideoHelper -
+
+ Takes the dst box in standard X BoxRec form (top and left
+ edges inclusive, bottom and right exclusive). The new dst
+ box is returned. The source boundaries are given (x1, y1
+ inclusive, x2, y2 exclusive) and returned are the new source
+ boundaries in 16.16 fixed point.
+*/
+
+#define DummyScreen screenInfo.screens[0]
+
+Bool
+xf86XVClipVideoHelper(
+ BoxPtr dst,
+ INT32 *xa,
+ INT32 *xb,
+ INT32 *ya,
+ INT32 *yb,
+ RegionPtr reg,
+ INT32 width,
+ INT32 height
+){
+ double xsw, xdw, ysw, ydw;
+ INT32 delta;
+ BoxPtr extents = REGION_EXTENTS(DummyScreen, reg);
+ int diff;
+
+ xsw = (*xb - *xa) << 16;
+ xdw = dst->x2 - dst->x1;
+ ysw = (*yb - *ya) << 16;
+ ydw = dst->y2 - dst->y1;
+
+ *xa <<= 16; *xb <<= 16;
+ *ya <<= 16; *yb <<= 16;
+
+ diff = extents->x1 - dst->x1;
+ if (diff > 0) {
+ dst->x1 = extents->x1;
+ *xa += (diff * xsw) / xdw;
+ }
+ diff = dst->x2 - extents->x2;
+ if (diff > 0) {
+ dst->x2 = extents->x2;
+ *xb -= (diff * xsw) / xdw;
+ }
+ diff = extents->y1 - dst->y1;
+ if (diff > 0) {
+ dst->y1 = extents->y1;
+ *ya += (diff * ysw) / ydw;
+ }
+ diff = dst->y2 - extents->y2;
+ if (diff > 0) {
+ dst->y2 = extents->y2;
+ *yb -= (diff * ysw) / ydw;
+ }
+
+ if (*xa < 0) {
+ diff = (((-*xa) * xdw) + xsw - 1) / xsw;
+ dst->x1 += diff;
+ *xa += (diff * xsw) / xdw;
+ }
+ delta = *xb - (width << 16);
+ if (delta > 0) {
+ diff = ((delta * xdw) + xsw - 1) / xsw;
+ dst->x2 -= diff;
+ *xb -= (diff * xsw) / xdw;
+ }
+ if (*xa >= *xb) return FALSE;
+
+ if (*ya < 0) {
+ diff = (((-*ya) * ydw) + ysw - 1) / ysw;
+ dst->y1 += diff;
+ *ya += (diff * ysw) / ydw;
+ }
+ delta = *yb - (height << 16);
+ if (delta > 0) {
+ diff = ((delta * ydw) + ysw - 1) / ysw;
+ dst->y2 -= diff;
+ *yb -= (diff * ysw) / ydw;
+ }
+ if (*ya >= *yb) return FALSE;
+
+ if ((dst->x1 > extents->x1) || (dst->x2 < extents->x2) ||
+ (dst->y1 > extents->y1) || (dst->y2 < extents->y2))
+ {
+ RegionRec clipReg;
+ REGION_INIT(DummyScreen, &clipReg, dst, 1);
+ REGION_INTERSECT(DummyScreen, reg, reg, &clipReg);
+ REGION_UNINIT(DummyScreen, &clipReg);
+ }
+ return TRUE;
+}
+
+void
+xf86XVCopyYUV12ToPacked(
+ const void *srcy,
+ const void *srcv,
+ const void *srcu,
+ void *dst,
+ int srcPitchy,
+ int srcPitchuv,
+ int dstPitch,
+ int h,
+ int w
+){
+ CARD32 *Dst;
+ const CARD8 *Y, *U, *V;
+ int i, j;
+
+ w >>= 1;
+
+ for (j = 0; j < h; j++) {
+ Dst = dst;
+ Y = srcy; V = srcv; U = srcu;
+ i = w;
+ while (i >= 4) {
+#if X_BYTE_ORDER == X_LITTLE_ENDIAN
+ Dst[0] = Y[0] | (Y[1] << 16) | (U[0] << 8) | (V[0] << 24);
+ Dst[1] = Y[2] | (Y[3] << 16) | (U[1] << 8) | (V[1] << 24);
+ Dst[2] = Y[4] | (Y[5] << 16) | (U[2] << 8) | (V[2] << 24);
+ Dst[3] = Y[6] | (Y[7] << 16) | (U[3] << 8) | (V[3] << 24);
+#else
+ /* This assumes a little-endian framebuffer */
+ Dst[0] = (Y[0] << 24) | (Y[1] << 8) | (U[0] << 16) | V[0];
+ Dst[1] = (Y[2] << 24) | (Y[3] << 8) | (U[1] << 16) | V[1];
+ Dst[2] = (Y[4] << 24) | (Y[5] << 8) | (U[2] << 16) | V[2];
+ Dst[3] = (Y[6] << 24) | (Y[7] << 8) | (U[3] << 16) | V[3];
+#endif
+ Dst += 4; Y += 8; V += 4; U += 4;
+ i -= 4;
+ }
+
+ while (i--) {
+#if X_BYTE_ORDER == X_LITTLE_ENDIAN
+ Dst[0] = Y[0] | (Y[1] << 16) | (U[0] << 8) | (V[0] << 24);
+#else
+ /* This assumes a little-endian framebuffer */
+ Dst[0] = (Y[0] << 24) | (Y[1] << 8) | (U[0] << 16) | V[0];
+#endif
+ Dst++; Y += 2; V++; U++;
+ }
+
+ dst = (CARD8 *)dst + dstPitch;
+ srcy = (const CARD8 *)srcy + srcPitchy;
+ if (j & 1) {
+ srcu = (const CARD8 *)srcu + srcPitchuv;
+ srcv = (const CARD8 *)srcv + srcPitchuv;
+ }
+ }
+}
+
+void
+xf86XVCopyPacked(
+ const void *src,
+ void *dst,
+ int srcPitch,
+ int dstPitch,
+ int h,
+ int w
+){
+ const CARD32 *Src;
+ CARD32 *Dst;
+ int i;
+
+ w >>= 1;
+ while (--h >= 0) {
+ do {
+ Dst = dst; Src = src;
+ i = w;
+ while (i >= 4) {
+ Dst[0] = Src[0];
+ Dst[1] = Src[1];
+ Dst[2] = Src[2];
+ Dst[3] = Src[3];
+ Dst += 4; Src += 4; i -= 4;
+ }
+ if (!i) break;
+ Dst[0] = Src[0];
+ if (i == 1) break;
+ Dst[1] = Src[1];
+ if (i == 2) break;
+ Dst[2] = Src[2];
+ } while (0);
+
+ src = (const CARD8 *)src + srcPitch;
+ dst = (CARD8 *)dst + dstPitch;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86xv.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xv.h
new file mode 100644
index 000000000..316d6c9e5
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xv.h
@@ -0,0 +1,271 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86xv.h,v 1.25 2003/08/24 17:36:56 dawes Exp $ */
+
+/*
+ * Copyright (c) 1998-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).
+ */
+
+#ifndef _XF86XV_H_
+#define _XF86XV_H_
+
+#include "xvdix.h"
+#include "xf86str.h"
+
+#define VIDEO_NO_CLIPPING 0x00000001
+#define VIDEO_INVERT_CLIPLIST 0x00000002
+#define VIDEO_OVERLAID_IMAGES 0x00000004
+#define VIDEO_OVERLAID_STILLS 0x00000008
+#define VIDEO_CLIP_TO_VIEWPORT 0x00000010
+
+typedef struct {
+ int id;
+ int type;
+ int byte_order;
+ unsigned char guid[16];
+ int bits_per_pixel;
+ int format;
+ int num_planes;
+
+ /* for RGB formats only */
+ int depth;
+ unsigned int red_mask;
+ unsigned int green_mask;
+ unsigned int blue_mask;
+
+ /* for YUV formats only */
+ unsigned int y_sample_bits;
+ unsigned int u_sample_bits;
+ unsigned int v_sample_bits;
+ unsigned int horz_y_period;
+ unsigned int horz_u_period;
+ unsigned int horz_v_period;
+ unsigned int vert_y_period;
+ unsigned int vert_u_period;
+ unsigned int vert_v_period;
+ char component_order[32];
+ int scanline_order;
+} XF86ImageRec, *XF86ImagePtr;
+
+
+typedef struct {
+ ScrnInfoPtr pScrn;
+ int id;
+ unsigned short width, height;
+ int *pitches; /* bytes */
+ int *offsets; /* in bytes from start of framebuffer */
+ DevUnion devPrivate;
+} XF86SurfaceRec, *XF86SurfacePtr;
+
+
+typedef int (* PutVideoFuncPtr)( ScrnInfoPtr pScrn,
+ short vid_x, short vid_y, short drw_x, short drw_y,
+ short vid_w, short vid_h, short drw_w, short drw_h,
+ RegionPtr clipBoxes, pointer data );
+typedef int (* PutStillFuncPtr)( ScrnInfoPtr pScrn,
+ short vid_x, short vid_y, short drw_x, short drw_y,
+ short vid_w, short vid_h, short drw_w, short drw_h,
+ RegionPtr clipBoxes, pointer data );
+typedef int (* GetVideoFuncPtr)( ScrnInfoPtr pScrn,
+ short vid_x, short vid_y, short drw_x, short drw_y,
+ short vid_w, short vid_h, short drw_w, short drw_h,
+ RegionPtr clipBoxes, pointer data );
+typedef int (* GetStillFuncPtr)( ScrnInfoPtr pScrn,
+ short vid_x, short vid_y, short drw_x, short drw_y,
+ short vid_w, short vid_h, short drw_w, short drw_h,
+ RegionPtr clipBoxes, pointer data );
+typedef void (* StopVideoFuncPtr)(ScrnInfoPtr pScrn, pointer data, Bool Exit);
+typedef int (* SetPortAttributeFuncPtr)(ScrnInfoPtr pScrn, Atom attribute,
+ INT32 value, pointer data);
+typedef int (* GetPortAttributeFuncPtr)(ScrnInfoPtr pScrn, Atom attribute,
+ INT32 *value, pointer data);
+typedef void (* QueryBestSizeFuncPtr)(ScrnInfoPtr pScrn, Bool motion,
+ short vid_w, short vid_h, short drw_w, short drw_h,
+ unsigned int *p_w, unsigned int *p_h, pointer data);
+typedef int (* PutImageFuncPtr)( ScrnInfoPtr pScrn,
+ short src_x, short src_y, short drw_x, short drw_y,
+ short src_w, short src_h, short drw_w, short drw_h,
+ int image, unsigned char* buf, short width, short height, Bool Sync,
+ RegionPtr clipBoxes, pointer data );
+typedef int (* ReputImageFuncPtr)( ScrnInfoPtr pScrn, short drw_x, short drw_y,
+ RegionPtr clipBoxes, pointer data );
+typedef int (*QueryImageAttributesFuncPtr)(ScrnInfoPtr pScrn,
+ int image, unsigned short *width, unsigned short *height,
+ int *pitches, int *offsets);
+
+typedef enum {
+ XV_OFF,
+ XV_PENDING,
+ XV_ON
+} XvStatus;
+
+/*** this is what the driver needs to fill out ***/
+
+typedef struct {
+ int id;
+ char *name;
+ unsigned short width, height;
+ XvRationalRec rate;
+} XF86VideoEncodingRec, *XF86VideoEncodingPtr;
+
+typedef struct {
+ char depth;
+ short class;
+} XF86VideoFormatRec, *XF86VideoFormatPtr;
+
+typedef struct {
+ int flags;
+ int min_value;
+ int max_value;
+ char *name;
+} XF86AttributeRec, *XF86AttributePtr;
+
+typedef struct {
+ unsigned int type;
+ int flags;
+ char *name;
+ int nEncodings;
+ XF86VideoEncodingPtr pEncodings;
+ int nFormats;
+ XF86VideoFormatPtr pFormats;
+ int nPorts;
+ DevUnion *pPortPrivates;
+ int nAttributes;
+ XF86AttributePtr pAttributes;
+ int nImages;
+ XF86ImagePtr pImages;
+ PutVideoFuncPtr PutVideo;
+ PutStillFuncPtr PutStill;
+ GetVideoFuncPtr GetVideo;
+ GetStillFuncPtr GetStill;
+ StopVideoFuncPtr StopVideo;
+ SetPortAttributeFuncPtr SetPortAttribute;
+ GetPortAttributeFuncPtr GetPortAttribute;
+ QueryBestSizeFuncPtr QueryBestSize;
+ PutImageFuncPtr PutImage;
+ ReputImageFuncPtr ReputImage;
+ QueryImageAttributesFuncPtr QueryImageAttributes;
+} XF86VideoAdaptorRec, *XF86VideoAdaptorPtr;
+
+typedef struct {
+ XF86ImagePtr image;
+ int flags;
+ int (*alloc_surface)(ScrnInfoPtr pScrn,
+ int id,
+ unsigned short width,
+ unsigned short height,
+ XF86SurfacePtr surface);
+ int (*free_surface)(XF86SurfacePtr surface);
+ int (*display) (XF86SurfacePtr surface,
+ short vid_x, short vid_y,
+ short drw_x, short drw_y,
+ short vid_w, short vid_h,
+ short drw_w, short drw_h,
+ RegionPtr clipBoxes);
+ int (*stop) (XF86SurfacePtr surface);
+ int (*getAttribute) (ScrnInfoPtr pScrn, Atom attr, INT32 *value);
+ int (*setAttribute) (ScrnInfoPtr pScrn, Atom attr, INT32 value);
+ int max_width;
+ int max_height;
+ int num_attributes;
+ XF86AttributePtr attributes;
+} XF86OffscreenImageRec, *XF86OffscreenImagePtr;
+
+Bool
+xf86XVScreenInit(
+ ScreenPtr pScreen,
+ XF86VideoAdaptorPtr *Adaptors,
+ int num
+);
+
+typedef int (* xf86XVInitGenericAdaptorPtr)(ScrnInfoPtr pScrn,
+ XF86VideoAdaptorPtr **Adaptors);
+
+int
+xf86XVRegisterGenericAdaptorDriver(
+ xf86XVInitGenericAdaptorPtr InitFunc
+);
+
+int
+xf86XVListGenericAdaptors(
+ ScrnInfoPtr pScrn,
+ XF86VideoAdaptorPtr **Adaptors
+);
+
+Bool
+xf86XVRegisterOffscreenImages(
+ ScreenPtr pScreen,
+ XF86OffscreenImagePtr images,
+ int num
+);
+
+XF86OffscreenImagePtr
+xf86XVQueryOffscreenImages(
+ ScreenPtr pScreen,
+ int *num
+);
+
+XF86VideoAdaptorPtr xf86XVAllocateVideoAdaptorRec(ScrnInfoPtr pScrn);
+
+void xf86XVFreeVideoAdaptorRec(XF86VideoAdaptorPtr ptr);
+
+void
+xf86XVFillKeyHelper (ScreenPtr pScreen, CARD32 key, RegionPtr clipboxes);
+
+Bool
+xf86XVClipVideoHelper(
+ BoxPtr dst,
+ INT32 *xa,
+ INT32 *xb,
+ INT32 *ya,
+ INT32 *yb,
+ RegionPtr reg,
+ INT32 width,
+ INT32 height
+);
+
+void
+xf86XVCopyYUV12ToPacked(
+ const void *srcy,
+ const void *srcv,
+ const void *srcu,
+ void *dst,
+ int srcPitchy,
+ int srcPitchuv,
+ int dstPitch,
+ int h,
+ int w
+);
+
+void
+xf86XVCopyPacked(
+ const void *src,
+ void *dst,
+ int srcPitch,
+ int dstPitch,
+ int h,
+ int w
+);
+
+#endif /* _XF86XV_H_ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86xvmc.c b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xvmc.c
new file mode 100644
index 000000000..a39e1bd4d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xvmc.c
@@ -0,0 +1,243 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86xvmc.c,v 1.6 2003/10/08 22:31:59 mvojkovi Exp $ */
+
+/*
+ * Copyright (c) 2001-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
+
+#include "misc.h"
+#include "xf86.h"
+#include "xf86_OSproc.h"
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "scrnintstr.h"
+#include "resource.h"
+#include "dixstruct.h"
+
+#ifdef XFree86LOADER
+#include "xvmodproc.h"
+#endif
+
+#include "xf86xvpriv.h"
+#include "xf86xvmc.h"
+
+#ifdef XFree86LOADER
+int (*XvMCScreenInitProc)(ScreenPtr, int, XvMCAdaptorPtr) = NULL;
+#else
+int (*XvMCScreenInitProc)(ScreenPtr, int, XvMCAdaptorPtr) = XvMCScreenInit;
+#endif
+
+
+typedef struct {
+ CloseScreenProcPtr CloseScreen;
+ int num_adaptors;
+ XF86MCAdaptorPtr *adaptors;
+ XvMCAdaptorPtr dixinfo;
+} xf86XvMCScreenRec, *xf86XvMCScreenPtr;
+
+static unsigned long XF86XvMCGeneration = 0;
+static int XF86XvMCScreenIndex = -1;
+
+#define XF86XVMC_GET_PRIVATE(pScreen) \
+ (xf86XvMCScreenPtr)((pScreen)->devPrivates[XF86XvMCScreenIndex].ptr)
+
+
+static int
+xf86XvMCCreateContext (
+ XvPortPtr pPort,
+ XvMCContextPtr pContext,
+ int *num_priv,
+ CARD32 **priv
+)
+{
+ xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
+ ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
+
+ pContext->port_priv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
+
+ return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateContext)(
+ pScrn, pContext, num_priv, priv);
+}
+
+static void
+xf86XvMCDestroyContext ( XvMCContextPtr pContext)
+{
+ xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
+ ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
+
+ (*pScreenPriv->adaptors[pContext->adapt_num]->DestroyContext)(
+ pScrn, pContext);
+}
+
+static int
+xf86XvMCCreateSurface (
+ XvMCSurfacePtr pSurface,
+ int *num_priv,
+ CARD32 **priv
+)
+{
+ XvMCContextPtr pContext = pSurface->context;
+ xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
+ ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
+
+ return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSurface)(
+ pScrn, pSurface, num_priv, priv);
+}
+
+static void
+xf86XvMCDestroySurface (XvMCSurfacePtr pSurface)
+{
+ XvMCContextPtr pContext = pSurface->context;
+ xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
+ ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
+
+ (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySurface)(
+ pScrn, pSurface);
+}
+
+static int
+xf86XvMCCreateSubpicture (
+ XvMCSubpicturePtr pSubpicture,
+ int *num_priv,
+ CARD32 **priv
+)
+{
+ XvMCContextPtr pContext = pSubpicture->context;
+ xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
+ ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
+
+ return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSubpicture)(
+ pScrn, pSubpicture, num_priv, priv);
+}
+
+static void
+xf86XvMCDestroySubpicture (XvMCSubpicturePtr pSubpicture)
+{
+ XvMCContextPtr pContext = pSubpicture->context;
+ xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
+ ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
+
+ (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySubpicture)(
+ pScrn, pSubpicture);
+}
+
+
+static Bool
+xf86XvMCCloseScreen (int i, ScreenPtr pScreen)
+{
+ xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pScreen);
+
+ pScreen->CloseScreen = pScreenPriv->CloseScreen;
+
+ xfree(pScreenPriv->dixinfo);
+ xfree(pScreenPriv);
+
+ return (*pScreen->CloseScreen)(i, pScreen);
+}
+
+Bool xf86XvMCScreenInit(
+ ScreenPtr pScreen,
+ int num_adaptors,
+ XF86MCAdaptorPtr *adaptors
+)
+{
+ XvMCAdaptorPtr pAdapt;
+ xf86XvMCScreenPtr pScreenPriv;
+ XvScreenPtr pxvs =
+ (XvScreenPtr)(pScreen->devPrivates[XF86XvScreenIndex].ptr);
+
+ int i, j;
+
+ if(!XvMCScreenInitProc) return FALSE;
+
+ if(XF86XvMCGeneration != serverGeneration) {
+ if((XF86XvMCScreenIndex = AllocateScreenPrivateIndex()) < 0)
+ return FALSE;
+ XF86XvMCGeneration = serverGeneration;
+ }
+
+ if(!(pAdapt = xalloc(sizeof(XvMCAdaptorRec) * num_adaptors)))
+ return FALSE;
+
+ if(!(pScreenPriv = xalloc(sizeof(xf86XvMCScreenRec)))) {
+ xfree(pAdapt);
+ return FALSE;
+ }
+
+ pScreen->devPrivates[XF86XvMCScreenIndex].ptr = (pointer)pScreenPriv;
+
+ pScreenPriv->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = xf86XvMCCloseScreen;
+
+ pScreenPriv->num_adaptors = num_adaptors;
+ pScreenPriv->adaptors = adaptors;
+ pScreenPriv->dixinfo = pAdapt;
+
+ for(i = 0; i < num_adaptors; i++) {
+ pAdapt[i].xv_adaptor = NULL;
+ for(j = 0; j < pxvs->nAdaptors; j++) {
+ if(!strcmp((*adaptors)->name, pxvs->pAdaptors[j].name)) {
+ pAdapt[i].xv_adaptor = &(pxvs->pAdaptors[j]);
+ break;
+ }
+ }
+ if(!pAdapt[i].xv_adaptor) {
+ /* no adaptor by that name */
+ xfree(pAdapt);
+ return FALSE;
+ }
+ pAdapt[i].num_surfaces = (*adaptors)->num_surfaces;
+ pAdapt[i].surfaces = (XvMCSurfaceInfoPtr*)((*adaptors)->surfaces);
+ pAdapt[i].num_subpictures = (*adaptors)->num_subpictures;
+ pAdapt[i].subpictures = (XvImagePtr*)((*adaptors)->subpictures);
+ pAdapt[i].CreateContext = xf86XvMCCreateContext;
+ pAdapt[i].DestroyContext = xf86XvMCDestroyContext;
+ pAdapt[i].CreateSurface = xf86XvMCCreateSurface;
+ pAdapt[i].DestroySurface = xf86XvMCDestroySurface;
+ pAdapt[i].CreateSubpicture = xf86XvMCCreateSubpicture;
+ pAdapt[i].DestroySubpicture = xf86XvMCDestroySubpicture;
+ adaptors++;
+ }
+
+ if(Success != (*XvMCScreenInitProc)(pScreen, num_adaptors, pAdapt))
+ return FALSE;
+
+ return TRUE;
+}
+
+XF86MCAdaptorPtr xf86XvMCCreateAdaptorRec (void)
+{
+ return xcalloc(1, sizeof(XF86MCAdaptorRec));
+}
+
+void xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor)
+{
+ xfree(adaptor);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86xvmc.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xvmc.h
new file mode 100644
index 000000000..0b073aac8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xvmc.h
@@ -0,0 +1,164 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86xvmc.h,v 1.7 2003/10/08 22:31:59 mvojkovi Exp $ */
+
+/*
+ * Copyright (c) 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 _XF86XVMC_H
+#define _XF86XVMC_H
+
+#include "xvmcext.h"
+#include "xf86xv.h"
+
+typedef struct {
+ int num_xvimages;
+ int *xvimage_ids; /* reference the subpictures in the XF86MCAdaptorRec */
+} XF86MCImageIDList;
+
+typedef struct {
+ int surface_type_id; /* Driver generated. Must be unique on the port */
+ int chroma_format;
+ int color_description; /* no longer used */
+ unsigned short max_width;
+ unsigned short max_height;
+ unsigned short subpicture_max_width;
+ unsigned short subpicture_max_height;
+ int mc_type;
+ int flags;
+ XF86MCImageIDList *compatible_subpictures; /* can be null, if none */
+} XF86MCSurfaceInfoRec, *XF86MCSurfaceInfoPtr;
+
+
+/*
+ xf86XvMCCreateContextProc
+
+ DIX will fill everything out in the context except the driver_priv.
+ The port_priv holds the private data specified for the port when
+ Xv was initialized by the driver.
+ The driver may store whatever it wants in driver_priv and edit
+ the width, height and flags. If the driver wants to return something
+ to the client it can allocate space in priv and specify the number
+ of 32 bit words in num_priv. This must be dynamically allocated
+ space because DIX will free it after it passes it to the client.
+*/
+
+
+typedef int (*xf86XvMCCreateContextProcPtr) (
+ ScrnInfoPtr pScrn,
+ XvMCContextPtr context,
+ int *num_priv,
+ CARD32 **priv
+);
+
+typedef void (*xf86XvMCDestroyContextProcPtr) (
+ ScrnInfoPtr pScrn,
+ XvMCContextPtr context
+);
+
+/*
+ xf86XvMCCreateSurfaceProc
+
+ DIX will fill everything out in the surface except the driver_priv.
+ The driver may store whatever it wants in driver_priv. The driver
+ may pass data back to the client in the same manner as the
+ xf86XvMCCreateContextProc.
+*/
+
+
+typedef int (*xf86XvMCCreateSurfaceProcPtr) (
+ ScrnInfoPtr pScrn,
+ XvMCSurfacePtr surface,
+ int *num_priv,
+ CARD32 **priv
+);
+
+typedef void (*xf86XvMCDestroySurfaceProcPtr) (
+ ScrnInfoPtr pScrn,
+ XvMCSurfacePtr surface
+);
+
+/*
+ xf86XvMCCreateSubpictureProc
+
+ DIX will fill everything out in the subpicture except the driver_priv,
+ num_palette_entries, entry_bytes and component_order. The driver may
+ store whatever it wants in driver_priv and edit the width and height.
+ If it is a paletted subpicture the driver needs to fill out the
+ num_palette_entries, entry_bytes and component_order. These are
+ not communicated to the client until the time the surface is
+ created.
+
+ The driver may pass data back to the client in the same manner as the
+ xf86XvMCCreateContextProc.
+*/
+
+
+typedef int (*xf86XvMCCreateSubpictureProcPtr) (
+ ScrnInfoPtr pScrn,
+ XvMCSubpicturePtr subpicture,
+ int *num_priv,
+ CARD32 **priv
+);
+
+typedef void (*xf86XvMCDestroySubpictureProcPtr) (
+ ScrnInfoPtr pScrn,
+ XvMCSubpicturePtr subpicture
+);
+
+
+typedef struct {
+ char *name;
+ int num_surfaces;
+ XF86MCSurfaceInfoPtr *surfaces;
+ int num_subpictures;
+ XF86ImagePtr *subpictures;
+ xf86XvMCCreateContextProcPtr CreateContext;
+ xf86XvMCDestroyContextProcPtr DestroyContext;
+ xf86XvMCCreateSurfaceProcPtr CreateSurface;
+ xf86XvMCDestroySurfaceProcPtr DestroySurface;
+ xf86XvMCCreateSubpictureProcPtr CreateSubpicture;
+ xf86XvMCDestroySubpictureProcPtr DestroySubpicture;
+} XF86MCAdaptorRec, *XF86MCAdaptorPtr;
+
+/*
+ xf86XvMCScreenInit
+
+ Unlike Xv, the adaptor data is not copied from this structure.
+ This structure's data is used so it must stick around for the
+ life of the server. Note that it's an array of pointers not
+ an array of structures.
+*/
+
+Bool xf86XvMCScreenInit(
+ ScreenPtr pScreen,
+ int num_adaptors,
+ XF86MCAdaptorPtr *adaptors
+);
+
+XF86MCAdaptorPtr xf86XvMCCreateAdaptorRec (void);
+void xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor);
+
+#endif /* _XF86XVMC_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xf86xvpriv.h b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xvpriv.h
new file mode 100644
index 000000000..0d1efdafb
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xf86xvpriv.h
@@ -0,0 +1,86 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86xvpriv.h,v 1.2 2003/08/24 17:36:56 dawes Exp $ */
+
+/*
+ * Copyright (c) 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).
+ */
+
+#ifndef _XF86XVPRIV_H_
+#define _XF86XVPRIV_H_
+
+#include "xf86xv.h"
+
+/*** These are DDX layer privates ***/
+
+extern int XF86XvScreenIndex;
+
+typedef struct {
+ DestroyWindowProcPtr DestroyWindow;
+ ClipNotifyProcPtr ClipNotify;
+ WindowExposuresProcPtr WindowExposures;
+ void (*AdjustFrame)(int, int, int, int);
+ Bool (*EnterVT)(int, int);
+ void (*LeaveVT)(int, int);
+ GCPtr videoGC;
+} XF86XVScreenRec, *XF86XVScreenPtr;
+
+typedef struct {
+ int flags;
+ PutVideoFuncPtr PutVideo;
+ PutStillFuncPtr PutStill;
+ GetVideoFuncPtr GetVideo;
+ GetStillFuncPtr GetStill;
+ StopVideoFuncPtr StopVideo;
+ SetPortAttributeFuncPtr SetPortAttribute;
+ GetPortAttributeFuncPtr GetPortAttribute;
+ QueryBestSizeFuncPtr QueryBestSize;
+ PutImageFuncPtr PutImage;
+ ReputImageFuncPtr ReputImage;
+ QueryImageAttributesFuncPtr QueryImageAttributes;
+} XvAdaptorRecPrivate, *XvAdaptorRecPrivatePtr;
+
+typedef struct {
+ ScrnInfoPtr pScrn;
+ DrawablePtr pDraw;
+ unsigned char type;
+ unsigned int subWindowMode;
+ DDXPointRec clipOrg;
+ RegionPtr clientClip;
+ RegionPtr pCompositeClip;
+ Bool FreeCompositeClip;
+ XvAdaptorRecPrivatePtr AdaptorRec;
+ XvStatus isOn;
+ Bool moved;
+ int vid_x, vid_y, vid_w, vid_h;
+ int drw_x, drw_y, drw_w, drw_h;
+ DevUnion DevPriv;
+} XvPortRecPrivate, *XvPortRecPrivatePtr;
+
+typedef struct _XF86XVWindowRec{
+ XvPortRecPrivatePtr PortRec;
+ struct _XF86XVWindowRec *next;
+} XF86XVWindowRec, *XF86XVWindowPtr;
+
+#endif /* _XF86XVPRIV_H_ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xisb.c b/nx-X11/programs/Xserver/hw/xfree86/common/xisb.c
new file mode 100644
index 000000000..4ffc3ede4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xisb.c
@@ -0,0 +1,180 @@
+/*
+ * 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.
+ *
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xisb.c,v 1.5 2000/11/06 19:24:07 dawes Exp $ */
+
+/*
+ X Input Serial Buffer routines for use in any XInput driver that accesses
+ a serial device.
+*/
+
+
+/*****************************************************************************
+ * Standard Headers
+ ****************************************************************************/
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+
+#include <misc.h>
+#include <xf86.h>
+#include <xf86Version.h>
+#include <xf86_OSproc.h>
+#include <xf86_OSlib.h>
+#include <xf86Xinput.h>
+#include "xisb.h"
+
+/*****************************************************************************
+ * Local Headers
+ ****************************************************************************/
+
+/*****************************************************************************
+ * Variables without includable headers
+ ****************************************************************************/
+
+/*****************************************************************************
+ * Local Variables
+ ****************************************************************************/
+
+/*****************************************************************************
+ * Function Definitions
+ ****************************************************************************/
+
+XISBuffer *
+XisbNew (int fd, xf86ssize_t size)
+{
+ XISBuffer *b;
+
+ b = xalloc (sizeof (XISBuffer));
+ if (!b)
+ return (NULL);
+ b->buf = xalloc ((sizeof (unsigned char) * size));
+ if (!b->buf)
+ {
+ xfree (b);
+ return (NULL);
+ }
+
+ b->fd = fd;
+ b->trace = 0;
+ b->block_duration = 0;
+ b->current = 1; /* force it to be past the end to trigger initial read */
+ b->end = 0;
+ b->buffer_size = size;
+ return (b);
+}
+
+void
+XisbFree (XISBuffer *b)
+{
+ xfree (b->buf);
+ xfree (b);
+}
+
+int
+XisbRead (XISBuffer *b)
+{
+ int ret;
+
+ if (b->current >= b->end)
+ {
+ if (b->block_duration >= 0)
+ {
+ if (xf86WaitForInput (b->fd, b->block_duration) < 1)
+ return (-1);
+ }
+ else
+ {
+ /*
+ * automatically clear it so if XisbRead is called in a loop
+ * the next call will make sure there is data with select and
+ * thus prevent a blocking read
+ */
+ b->block_duration = 0;
+ }
+
+ ret = xf86ReadSerial (b->fd, b->buf, b->buffer_size);
+ switch (ret)
+ {
+ case 0:
+ return (-1); /* timeout */
+ case -1:
+ return (-2); /* error */
+ default:
+ b->end = ret;
+ b->current = 0;
+ break;
+ }
+ }
+ if (b->trace)
+ ErrorF ("read 0x%02x (%c)\n", b->buf[b->current],
+ isprint(b->buf[b->current])?b->buf[b->current]:'.');
+
+ return (b->buf[b->current++]);
+}
+
+/* the only purpose of this function is to provide output tracing */
+xf86ssize_t
+XisbWrite (XISBuffer *b, unsigned char *msg, xf86ssize_t len)
+{
+ if (b->trace)
+ {
+ int i = 0;
+ for (i = 0; i < len; i++)
+ ErrorF ("\t\twrote 0x%02x (%c)\n", msg[i], msg[i]);
+ }
+ return (xf86WriteSerial (b->fd, msg, len));
+}
+
+/* turn tracing of this buffer on (1) or off (0) */
+void
+XisbTrace (XISBuffer *b, int trace)
+{
+ b->trace = trace;
+}
+
+/*
+ * specify a block_duration of -1 when you know the buffer's fd is ready to
+ * read. After a read, it is automatically set to 0 so that the next read
+ * will use check to select for data and prevent a block.
+ * It is the caller's responsibility to set the block_duration to -1 if it
+ * knows that there is data to read (because the main select loop triggered
+ * the read) and want's to avoid the unnecessary overhead of the select call
+ *
+ * a zero or positive block duration will cause the select to block for the
+ * give duration in usecs.
+ */
+
+void
+XisbBlockDuration (XISBuffer *b, int block_duration)
+{
+ b->block_duration = block_duration;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xisb.h b/nx-X11/programs/Xserver/hw/xfree86/common/xisb.h
new file mode 100644
index 000000000..39ae2ee11
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xisb.h
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ *
+ */
+/* $XFree86$ */
+
+#ifndef _xisb_H_
+#define _xisb_H_
+
+/******************************************************************************
+ * Definitions
+ * structs, typedefs, #defines, enums
+ *****************************************************************************/
+
+typedef struct _XISBuffer
+{
+ int fd;
+ int trace;
+ int block_duration;
+ xf86ssize_t current; /* bytes read */
+ xf86ssize_t end;
+ xf86ssize_t buffer_size;
+ unsigned char *buf;
+} XISBuffer;
+
+/******************************************************************************
+ * Declarations
+ * variables: use xisb_LOC in front
+ * of globals.
+ * put locals in the .c file.
+ *****************************************************************************/
+XISBuffer * XisbNew (int fd, xf86ssize_t size);
+void XisbFree (XISBuffer *b);
+int XisbRead (XISBuffer *b);
+xf86ssize_t XisbWrite (XISBuffer *b, unsigned char *msg, xf86ssize_t len);
+void XisbTrace (XISBuffer *b, int trace);
+void XisbBlockDuration (XISBuffer *b, int block_duration);
+
+/*
+ * DO NOT PUT ANYTHING AFTER THIS ENDIF
+ */
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/common/xorgHelper.c b/nx-X11/programs/Xserver/hw/xfree86/common/xorgHelper.c
new file mode 100644
index 000000000..408583da8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/common/xorgHelper.c
@@ -0,0 +1,24 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xorgHelper.c,v 1.6 2005/07/03 08:53:42 daniels Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "servermd.h"
+#include "pixmapstr.h"
+#include "windowstr.h"
+#include "propertyst.h"
+#include "gcstruct.h"
+#include "loaderProcs.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xorgVersion.h"
+
+
+CARD32
+xorgGetVersion()
+{
+ return XORG_VERSION_CURRENT;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/Imakefile
new file mode 100644
index 000000000..648fdc762
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/Imakefile
@@ -0,0 +1,130 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/Imakefile,v 3.61 2003/11/03 05:11:51 tsi Exp $
+
+
+
+
+
+XCOMM $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/Imakefile,v 1.6 2005/12/01 02:15:38 ajax Exp $
+XCOMM $XConsortium: Imakefile /main/9 1996/10/25 15:38:46 kaleb $
+
+#include <Server.tmpl>
+
+#define IHaveSubdirs
+
+#if defined(i386Architecture) || defined(ia64Architecture) || \
+ (defined(SunArchitecture) && defined(SparcArchitecture)) || \
+ (defined(KFreeBSDArchitecture) && defined(AlphaArchitecture)) || \
+ (defined(KFreeBSDArchitecture) && defined(Sparc64Architecture)) || \
+ (defined(KFreeBSDArchitecture) && defined(PpcArchitecture)) || \
+ (defined(KNetBSDArchitecture) && defined(AlphaArchitecture)) || \
+ (defined(KNetBSDArchitecture) && defined(PpcArchitecture)) || \
+ (defined(KNetBSDArchitecture) && defined(SparcArchitecture)) || \
+ defined(KOpenBSDArchitecture) || defined(SGIArchitecture) || \
+ (defined(LynxOSArchitecture) && defined(PpcArchitecture)) || \
+ defined(AMD64Architecture) || defined(LinuxArchitecture) || \
+ defined(GNUMachArchitecture)
+BUS_SUBDIR = bus
+#endif
+
+#if defined(QNX4Architecture)
+OS_SUBDIR = qnx4
+#endif
+
+#if defined(NTOArchitecture)
+OS_SUBDIR = nto
+#endif
+
+#if defined(SVR3Architecture)
+# if defined(i386ScoArchitecture)
+OS_SUBDIR = sco
+# else
+OS_SUBDIR = sysv
+# endif
+#endif
+
+#if defined(SVR4Architecture)
+# if defined(SunArchitecture)
+OS_SUBDIR = sunos
+# elif defined(PmaxOSArchitecture)
+OS_SUBDIR = pmax
+# elif defined(DguxArchitecture)
+OS_SUBDIR = dgux
+# elif defined(SGIArchitecture)
+OS_SUBDIR = irix
+# elif defined(UnixWareArchitecture)
+OS_SUBDIR = usl
+# else
+OS_SUBDIR = sysv
+# endif
+#endif
+
+#if defined(LinuxArchitecture)
+OS_SUBDIR = linux
+#endif
+
+#if defined(LynxOSArchitecture)
+OS_SUBDIR = lynxos
+#endif
+
+#if defined(KFreeBSDArchitecture) || defined(NetBSDArchitecture) || \
+ defined(OpenBSDArchitecture)
+OS_SUBDIR = bsd
+#endif
+
+#if defined(BSDOSArchitecture)
+OS_SUBDIR = bsdi
+#endif
+
+#if defined(GNUMachArchitecture)
+OS_SUBDIR = hurd
+#endif
+
+#if defined(OS2Architecture)
+OS_SUBDIR = os2
+#endif
+
+#if defined(i386Sco325Architecture)
+OS_SUBDIR = sco
+#endif
+
+#if !DoLoadableServer
+
+#if BuildXF86DRI
+DRM_SRC = $(OS_SUBDIR)/drm/?*.c
+DRM_OBJ = $(OS_SUBDIR)/drm/?*.o
+DRM_DONES = $(OS_SUBDIR)/drm/DONE
+#endif
+
+#endif
+
+LIBDRM_DIR = ../../../../../extras/drm/libdrm
+
+SUBDIRS = $(OS_SUBDIR) $(BUS_SUBDIR) misc
+
+SRCS = $(OS_SUBDIR)/?*.c $(BUS_SUBDIR)/?*.c misc/?*.c $(DRM_SRC)
+OBJS = $(OS_SUBDIR)/?*.o $(BUS_SUBDIR)/?*.o misc/?*.o $(DRM_OBJ)
+
+DONES = $(OS_SUBDIR)/DONE $(BUS_SUBDIR)/DONE misc/DONE $(DRM_DONES)
+
+#if HasParallelMake
+MakeMutex($(SUBDIRS) $(OBJS) $(DONES))
+#endif
+
+#if HasGnuMake || HasBsdMake
+$(DONES): $(SUBDIRS)
+#endif
+
+NormalDepLibraryTarget(xf86_os,$(SUBDIRS) $(DONES),$(OBJS))
+
+ForceSubdirs($(SUBDIRS))
+
+DependSubdirs($(SUBDIRS))
+
+LinkSourceFile(xf86drm.h,$(LIBDRM_DIR))
+
+InstallDriverSDKNonExecFile(xf86_OSproc.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86_OSlib.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86_ansic.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86_libc.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(xf86drm.h,$(DRIVERSDKINCLUDEDIR))
+InstallDriverSDKNonExecFile(assyntax.h,$(DRIVERSDKINCLUDEDIR))
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/README.OS-lib b/nx-X11/programs/Xserver/hw/xfree86/os-support/README.OS-lib
new file mode 100644
index 000000000..43312e4e8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/README.OS-lib
@@ -0,0 +1,506 @@
+
+ README for XFree86 OS-support Layer
+ -----------------------------------
+
+Contents
+--------
+ 1) Overview
+ 2) Directory Layout
+ 3) Adding a new OS
+ 4) OS Support API
+
+1 - Overview
+------------
+ This directory contains the OS support layer functions for the XFree86
+servers. In addition, some miscellaneous server support functions (not
+OS-dependent) are included here, to take advantage of the fact that this
+library comes last in the linking order.
+
+Most of the functionality required to support a new OS is encapsulated in
+this library. It is hoped that all OS-specific details can be encapsulated,
+but that is not likely ever to be completely possible. Hence some minor
+changes will wind up being made in other parts of the server. The major
+design principles for this library are maintainability, readability, and
+portability. Sometimes these goals conflict; some somewhat arbitrary choices
+have been made in implementation.
+
+2 - Directory Layout
+--------------------
+ os-support/ Contains headers and documentation; no code
+ misc/ Non-OS-specific miscellaneous functions that
+ fit best into the link architecture this way.
+ shared/ Contains files with functions used by more than one
+ OS. These are symlinked into the OS subdirectories
+ at build time via Imakefile rules. This is alway
+ preferable to reproducing functions in more than one
+ OS library.
+ bsd/ OS support for the 386BSD/NetBSD/FreeBSD operating
+ systems.
+ bsdi/ OS support for the BSD/386 operating system.
+ linux/ OS support for the Linux operating system.
+ os2/ OS support for OS/2 2.11 and OS/2 Warp
+ sco/ OS support for the SCO SVR3.x operating system.
+ solx86/ OS support for the Solaris x86 operating system.
+ sysv/ OS support for all SVR4.0 and SVR4.2, and for
+ ISC and AT&T SVR3.2 operating systems.
+
+3 - Adding A New OS
+-------------------
+ Adding a support for a new operating system entails implementing all of
+the functions described in the API below. Many of these functions are no-ops
+for many operating systems, and appropriate files with dummy declarations are
+available in the 'shared' subdirectory.
+
+If your OS is sufficiently similar to an existing OS, you can make use of
+the existing subdirectory. One of the reasons for implementing this OS
+library was the unmaintainability of the spagetti-#ifdef code that existed
+before. You should try to avoid cluttering the code with #ifdef's. If
+you find that the subdirectory is getting cluttered, split off into a
+seperate subdirectory (e.g. as was done for SCO, rather than cluttering
+the 'sysv' subdirectory). You can split functions out of an existing
+subdirectory into the 'shared' subdirectory, if that is appropriate. Just
+remember to update the Imakefile for the old subdirectory.
+
+You will still likely have to make some small changes to other parts of
+the server. You should not put OS-specific #define's or #include's anywhere
+else in the server. These should all go in the "xf86_OSlib.h" header file
+in this directory.
+
+4 - OS Support API
+-----------------
+void xf86OpenConsole(void)
+{
+ /*
+ * Open console device, activate VTs, etc, etc. Fill in requisite
+ * pieces of xf86Info. Most of this code comes from xf86Init.c
+ */
+}
+
+void xf86CloseConsole(void)
+{
+ /*
+ * Close console at server exit.
+ */
+}
+
+Bool xf86VTSwitchPending(void)
+{
+ /*
+ * Returns TRUE iff there is a VT switch operation pending for
+ * the server. In the USL VT model, this is indicated via a
+ * signal handler. Should return FALSE always for OSs without
+ * VTs.
+ */
+}
+
+Bool xf86VTSwitchAway(void)
+{
+ /*
+ * Handles the OS-specific action for switching away from the active
+ * VT. Returns FALSE if the switch away fails. Should return
+ * FALSE always for OSs without VTs (then again, this function
+ * should never be called in that case).
+ */
+}
+
+Bool xf86VTSwitchTo(void)
+{
+ /*
+ * Handles the OS-specific action for switching to the active VT.
+ * Returns FALSE if the switch to fails. Should return TRUE
+ * always for OSs without VTs (then again, this function should
+ * never be called in that case).
+ */
+}
+
+Bool xf86LinearVidMem(void)
+{
+ /*
+ * Returns TRUE if the OS supports mapping linear frame buffers
+ * (ie memory at addresses above physical memory).
+ */
+}
+
+pointer xf86MapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ /*
+ * Handle mapping the video memory. Returns (pointer *)0 for
+ * failure; causes server exit. It is allowable to call FatalError()
+ * from inside this function and exit directly.
+ */
+}
+
+void xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ /*
+ * Handle unmapping the video memory. This should undo what
+ * xf86MapVidMem() does. Base is a pointer obtained from
+ * a previous call to xf86MapVidMem().
+ */
+}
+
+void xf86MapDisplay(int ScreenNum, int Region)
+{
+ /*
+ * For OSs that require the screen be mapped when entering a VT.
+ * A dummy function will be defined for OSs that don't require
+ * this (or don't have VTs at all).
+ */
+}
+
+void xf86UnMapDisplay(int ScreenNum, int Region)
+{
+ /*
+ * For Os that require that the screen be unmapped when leaving a
+ * VT. A dummy function will be defined for OSs that don't require
+ * this (or don't have VTs at all).
+ */
+}
+
+int xf86ReadBIOS(unsigned long Base, unsigned long Offset,
+ unsigned char *Buf, int Len)
+{
+ /*
+ * Read Len bytes from the BIOS at address Base, offset Offset,
+ * into buffer Buf. Returns -1 for failure or if the OS does
+ * not support reading the BIOS. This causes a driver probe
+ * to fail, but does not cause the server to abort.
+ */
+}
+
+
+void xf86EnableIOPorts(int ScreenNum)
+{
+ /*
+ * Enables I/O permissions. The OS layer should
+ * enable all I/O port access.
+ */
+}
+
+void xf86DisableIOPorts(int ScreenNum)
+{
+ /*
+ * Disables I/O permissions.
+ */
+}
+
+Bool xf86DisableInterrupts(void)
+{
+ /*
+ * Disable interrupts if allowed for this OS. Returns FALSE if
+ * this is not allowed or if the attempt fails for some reason.
+ */
+}
+
+void xf86EnableInterrupts(void)
+{
+ /*
+ * Reenable interrupts
+ */
+}
+
+int xf86ProcessArgument(int argc, char *argv[], int i)
+{
+ /*
+ * Process OS-specific command-line arguments. See
+ * ddxProcessArgument() for more info.
+ */
+}
+
+void xf86UseMsg(void)
+{
+ /*
+ * Print list of OS-specific command-line arguments. See
+ * ddxUseMsg() for more info.
+ */
+}
+
+void xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ /*
+ * Sound the keyboard bell. pitch is in Hz, duration in ms,
+ * loudness is in the range 0-100 (0 -> off). For systems
+ * where the loudness can't be controlled, scale the duration
+ * by loudness/50.
+ */
+}
+
+void xf86SetKbdLeds(int leds)
+{
+ /*
+ * Set the keyboard LEDs to the state indicated in leds
+ */
+}
+
+int xf86GetKbdLeds(void)
+{
+ /*
+ * Return the state of the keyboard LEDs. If the OS doesn't
+ * support this, return 0.
+ */
+}
+
+void xf86SetKbdRepeat(char rad)
+{
+ /*
+ * Set the keyboard repeat rate and delay according the
+ * the rad value. The lower 5 bits determine the repeat
+ * rate (lower value -> higher rate). The next 2 bits
+ * determine the delay.
+ * This should possibly be changed to take separate rate and
+ * delay parameters.
+ */
+}
+
+void xf86KbdInit(void)
+{
+ /*
+ * Save initial keyboard state. This is called at the start of
+ * each server generation.
+ */
+}
+
+int xf86KbdOn(void)
+{
+ /*
+ * Set the keyboard up for use with X. This is called whenever
+ * the server becomes active (ie at the start of each generation and
+ * whenever its VT becomes active). Return the file descriptor
+ * for keyboard input. Return -1 if there is no file descriptor
+ * to add as an input device. If there are errors encountered,
+ * call FatalError(). A return value of -1 is not considered an
+ * error condition.
+ */
+}
+
+int xf86KbdOff(void)
+{
+ /*
+ * Return the keyboard to the state saved by xf86KbdInit(). This is
+ * called at the end of a server generation, and also when the
+ * server's VT ceases being active. Returns the keyboard file
+ * descriptor. Returns -1 if there is no file descriptor to be
+ * removed as an input device. Errors should be handled the same
+ * way as in xf86KbdOn().
+ */
+}
+
+void xf86KbdEvents(void)
+{
+ /*
+ * Read characters from the keyboard device, and post the events
+ * by calling xf86PostKbdEvent(). Read as much as is available
+ * without waiting.
+ */
+}
+
+void xf86SetMouseSpeed(int old, int new, unsigned cflag)
+{
+ /*
+ * Set the speed of the mouse port. old is the previous speed,
+ * new is the new speed, and cflag is the value of the termio[s]
+ * c_cflag field. For mice that have programmable speed operation,
+ * this should send the appropriate commands to the mouse.
+ */
+}
+
+void xf86MouseInit(void)
+{
+ /*
+ * This is called at the start of each server generation. In most
+ * cases this is a noop. If the mouse must not be opened/closed
+ * when VT switching, the open should be done here.
+ */
+}
+
+int xf86MousedOn(void)
+{
+ /*
+ * Set the mouse up for use with X. This is called whenever
+ * the server becomes active (ie at the start of each generation and
+ * whenever its VT becomes active). This function normally opens
+ * the mouse device, and may call xf86SetupMouse() to initialise
+ * the mouse parameters. Return the file descriptor for mouse input.
+ * Return -1 if there is no file descriptor to add as an input
+ * device. If there are errors encountered, call FatalError().
+ * A return value of -1 is not considered an error condition.
+ */
+}
+
+int xf86MouseOff(Bool doclose)
+{
+ /*
+ * Release the mouse from use with X. This is called at the end
+ * of a server generation (with doclose==TRUE), and also when the
+ * server's VT ceases being active (with doclose==FALSE). If the
+ * mouse should not be opened/closed when VT switching, the close
+ * should be done here when doclose==TRUE. For other systems, the
+ * mouse device should be closed regardless of the doclose value.
+ * Returns the mouse file descriptor. Returns -1 if there is no
+ * file descriptor to be removed as an input device. Errors
+ * should be handled the same way as in xf86MouseOn().
+ */
+}
+
+void xf86MouseEvents(void)
+{
+ /*
+ * Read characters from the mouse device, and post the events
+ * by calling xf86PostMseEvent(). Read as much as is available
+ * without waiting. If the OS doesn't handle the mouse protocol
+ * translation, xf86MouseProtocol() may be called to do the
+ * translation and event posting. If the OS does handle the protocol
+ * translation, MOUSE_PROTOCOL_IN_KERNEL should be #define'd in
+ * xf86_OSlib.h.
+ */
+}
+
+int xf86OsMouseProc(DevicePtr pPointer, int what)
+{
+ /*
+ * Implements the device-proc for the pointer device when an
+ * OS-based mouse driver is being used (as opposed to the
+ * server's internal mouse driver). Implemented as any other
+ * device-proc in the server.
+ *
+ * This function only needs to be implemented if USE_OSMOUSE is
+ * defined for the OS.
+ */
+}
+
+int xf86OsMouseEvents(void)
+{
+ /*
+ * When supporting an OS-based mouse driver (as opposed to the
+ * server's internal mouse driver), read some events from the device
+ * and post them to the DIX layer through xf86PostMseEvent().
+ *
+ * This function only needs to be implemented if USE_OSMOUSE is
+ * defined for the OS.
+ */
+}
+
+void xf86OsMouseOption(int token, pointer lex_ptr)
+{
+ /*
+ * Used in parsing an OsMouse keyword from the Xconfig file.
+ * Passed the token type and a pointer to the token value.
+ * The function should do whatever is appropriate for the OS's
+ * mouse driver.
+ *
+ * This function only needs to be implemented if USE_OSMOUSE is
+ * defined for the OS.
+ */
+}
+
+/*
+ * The following functions are simply wrappers around the OS specific
+ * libc functions
+ */
+
+void *
+xf86memmove(void * dest, const void * src, INT32 n)
+{
+ return(memmove(dest,src,n));
+}
+
+void *
+xf86memset(void * s, int c, INT32 n)
+{
+ return(memset(s,c,n));
+}
+
+void *
+xf86memcpy(void * dest, const void * src, INT32 n)
+{
+ return(memcpy(dest,src,n));
+}
+
+int
+xf86memcmp(const void * s1, const void * s2, INT32 n)
+{
+ return(memcmp(s1,s2,n));
+}
+
+char *
+xf86strcat(char * dest, const char * src)
+{
+ return(strcat(dest,src));
+}
+
+char *
+xf86strcpy(char * dest, const char * src)
+{
+ return(strcpy(dest,src));
+}
+
+int
+xf86strcmp(const char * s1, const char * s2)
+{
+ return(strcmp(s1,s2));
+}
+
+int
+xf86strncmp(const char * s1, const char * s2, INT32 n)
+{
+ return(strncmp(s1,s2,n));
+}
+
+size_t
+xf86strlen(const char * s)
+{
+ return(strlen(s));
+}
+
+void
+xf86getsecs(INT32 * secs, INT32 * usecs)
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ *secs = tv.tv_sec;
+ *usecs= tv.tv_usec;
+
+ return;
+}
+
+double
+xf86exp(double x)
+{
+ return(exp(x));
+}
+
+double
+xf86log(double x)
+{
+ return(log(x));
+}
+
+double
+xf86pow(double x, double y)
+{
+ return(pow(x,y));
+}
+
+double
+xf86sqrt(double x)
+{
+ return(sqrt(x));
+}
+
+double
+xf86cos(double x)
+{
+ return(cos(x));
+}
+
+
+
+
+$XFree86: xc/programs/Xserver/hw/xfree86/os-support/README.OS-lib,v 3.9 2001/07/23 13:15:48 dawes Exp $
+
+
+
+
+
+$XConsortium: README.OS-lib /main/5 1996/02/21 17:50:28 kaleb $
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/assyntax.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/assyntax.h
new file mode 100644
index 000000000..13cc2f3e0
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/assyntax.h
@@ -0,0 +1,753 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/assyntax.h,v 3.13 2003/08/24 17:37:03 dawes Exp $ */
+
+#ifndef __ASSYNTAX_H__
+#define __ASSYNTAX_H__
+
+/*
+ * Copyright 1992 Vrije Universiteit, The Netherlands
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the Vrije Universiteit not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. The Vrije Universiteit makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * The Vrije Universiteit DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL The Vrije Universiteit BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * Copyright (c) 1993-1999 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).
+ */
+
+/* $XConsortium: assyntax.h /main/5 1996/02/21 17:50:49 kaleb $ */
+
+ /*
+ * assyntax.h
+ *
+ * Select the syntax appropriate to the 386 assembler being used
+ * To add support for more assemblers add more columns to the CHOICE
+ * macro. Note that register names must also have uppercase names
+ * to avoid macro recursion. e.g., #define ah %ah recurses!
+ *
+ * NB 1. Some of the macros for certain assemblers imply that the code is to
+ * run in protected mode!! Caveat emptor.
+ *
+ * NB 2. 486 specific instructions are not included. This is to discourage
+ * their accidental use in code that is intended to run on 386 and 486
+ * systems.
+ *
+ * Supported assemblers:
+ *
+ * (a) AT&T SysVr4 as(1): default
+ * (b) GNU Assembler gas: define USE_GAS or GNU_ASSEMBLER
+ * (c) Amsterdam Compiler kit: define ACK_ASSEMBLER
+ *
+ * The following naming conventions have been used to identify the various
+ * data types:
+ * _SR = segment register version
+ * Integer:
+ * _Q = quadword = 64 bits
+ * _L = long = 32 bits
+ * _W = short = 16 bits
+ * _B = byte = 8 bits
+ * Floating-point:
+ * _X = m80real = 80 bits
+ * _D = double = 64 bits
+ * _S = single = 32 bits
+ *
+ * Author: Gregory J. Sharp, Sept 1992
+ * Vrije Universiteit, Amsterdam, The Netherlands
+ */
+
+#if defined(USE_GAS) && !defined(GNU_ASSEMBLER)
+#define GNU_ASSEMBLER
+#endif
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || (defined (sun) && defined (i386) && defined (SVR4) && defined (__STDC__) && !defined (__GNUC__))
+#define CONCAT(x, y) x ## y
+#else
+#define CONCAT(x, y) x/**/y
+#endif
+
+#ifdef ACK_ASSEMBLER
+
+/* Assume we write code for 32-bit protected mode! */
+
+/* Redefine register names for GAS & AT&T assemblers */
+#define AL al
+#define AH ah
+#define AX ax
+#define EAX ax
+#define BL bl
+#define BH bh
+#define BX bx
+#define EBX bx
+#define CL cl
+#define CH ch
+#define CX cx
+#define ECX cx
+#define DL dl
+#define DH dh
+#define DX dx
+#define EDX dx
+#define BP bp
+#define EBP bp
+#define SI si
+#define ESI si
+#define DI di
+#define EDI di
+#define SP sp
+#define ESP sp
+#define CS cs
+#define SS ss
+#define DS ds
+#define ES es
+#define FS fs
+#define GS gs
+/* Control Registers */
+#define CR0 cr0
+#define CR1 cr1
+#define CR2 cr2
+#define CR3 cr3
+/* Debug Registers */
+#define DR0 dr0
+#define DR1 dr1
+#define DR2 dr2
+#define DR3 dr3
+#define DR4 dr4
+#define DR5 dr5
+#define DR6 dr6
+#define DR7 dr7
+/* Floating-point Stack */
+#define ST st
+
+#define AS_BEGIN .sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text
+
+
+#define _WTOG o16 /* word toggle for _W instructions */
+#define _LTOG /* long toggle for _L instructions */
+#define ADDR_TOGGLE a16
+#define OPSZ_TOGGLE o16
+#define USE16 .use16
+#define USE32 .use32
+
+#define CHOICE(a,b,c) c
+
+#else /* AT&T or GAS */
+
+/* Redefine register names for GAS & AT&T assemblers */
+#define AL %al
+#define AH %ah
+#define AX %ax
+#define EAX %eax
+#define BL %bl
+#define BH %bh
+#define BX %bx
+#define EBX %ebx
+#define CL %cl
+#define CH %ch
+#define CX %cx
+#define ECX %ecx
+#define DL %dl
+#define DH %dh
+#define DX %dx
+#define EDX %edx
+#define BP %bp
+#define EBP %ebp
+#define SI %si
+#define ESI %esi
+#define DI %di
+#define EDI %edi
+#define SP %sp
+#define ESP %esp
+#define CS %cs
+#define SS %ss
+#define DS %ds
+#define ES %es
+#define FS %fs
+#define GS %gs
+/* Control Registers */
+#define CR0 %cr0
+#define CR1 %cr1
+#define CR2 %cr2
+#define CR3 %cr3
+/* Debug Registers */
+#define DR0 %db0
+#define DR1 %db1
+#define DR2 %db2
+#define DR3 %db3
+#define DR4 %db4
+#define DR5 %db5
+#define DR6 %db6
+#define DR7 %db7
+/* Floating-point Stack */
+#define ST %st
+
+#define AS_BEGIN
+#define USE16
+#define USE32
+
+#ifdef GNU_ASSEMBLER
+
+#define ADDR_TOGGLE aword
+#define OPSZ_TOGGLE word
+
+#define CHOICE(a,b,c) b
+
+#else
+/*
+ * AT&T ASSEMBLER SYNTAX
+ * *********************
+ */
+#define CHOICE(a,b,c) a
+
+#define ADDR_TOGGLE addr16
+#define OPSZ_TOGGLE data16
+
+#endif /* GNU_ASSEMBLER */
+#endif /* ACK_ASSEMBLER */
+
+
+#if defined(__QNX__) || defined(Lynx) || (defined(SYSV) || defined(SVR4)) && !defined(ACK_ASSEMBLER) || defined(__ELF__) || defined(__GNU__)
+#define GLNAME(a) a
+#else
+#define GLNAME(a) CONCAT(_,a)
+#endif
+
+
+ /****************************************/
+ /* */
+ /* Select the various choices */
+ /* */
+ /****************************************/
+
+
+/* Redefine assembler directives */
+/*********************************/
+#define GLOBL CHOICE(.globl, .globl, .extern)
+#define ALIGNTEXT4 CHOICE(.align 4, .align ARG2(2,0x90), .align 4)
+#define ALIGNTEXT2 CHOICE(.align 2, .align ARG2(1,0x90), .align 2)
+/* ALIGNTEXT4ifNOP is the same as ALIGNTEXT4, but only if the space is
+ * guaranteed to be filled with NOPs. Otherwise it does nothing.
+ */
+#define ALIGNTEXT4ifNOP CHOICE(.align 4, .align ARG2(2,0x90), /*can't do it*/)
+#define ALIGNDATA4 CHOICE(.align 4, .align ARG2(2,0x0), .align 4)
+#define ALIGNDATA2 CHOICE(.align 2, .align ARG2(1,0x0), .align 2)
+#define FILE(s) CHOICE(.file s, .file s, .file s)
+#define STRING(s) CHOICE(.string s, .asciz s, .asciz s)
+#define D_LONG CHOICE(.long, .long, .data4)
+#define D_WORD CHOICE(.value, .short, .data2)
+#define D_BYTE CHOICE(.byte, .byte, .data1)
+#define SPACE CHOICE(.comm, .space, .space)
+#define COMM CHOICE(.comm, .comm, .comm)
+#define SEG_DATA CHOICE(.data, .data, .sect .data)
+#define SEG_TEXT CHOICE(.text, .text, .sect .text)
+#define SEG_BSS CHOICE(.bss, .bss, .sect .bss)
+
+#ifdef GNU_ASSEMBLER
+#define D_SPACE(n) . = . + n
+#else
+#define D_SPACE(n) .space n
+#endif
+
+/* Addressing Modes */
+/* Immediate Mode */
+#define ADDR(a) CHOICE(CONCAT($,a), CONCAT($,a), a)
+#define CONST(a) CHOICE(CONCAT($,a), CONCAT($,a), a)
+
+/* Indirect Mode */
+#define CONTENT(a) CHOICE(a, a, (a)) /* take contents of variable */
+#define REGIND(a) CHOICE((a), (a), (a)) /* Register a indirect */
+/* Register b indirect plus displacement a */
+#define REGOFF(a, b) CHOICE(a(b), a(b), a(b))
+/* Reg indirect Base + Index + Displacement - this is mainly for 16-bit mode
+ * which has no scaling
+ */
+#define REGBID(b,i,d) CHOICE(d(b,i), d(b,i), d(b)(i))
+/* Reg indirect Base + (Index * Scale) + Displacement */
+#define REGBISD(b,i,s,d) CHOICE(d(b,i,s), d(b,i,s), d(b)(i*s))
+/* Displaced Scaled Index: */
+#define REGDIS(d,i,s) CHOICE(d(,i,s), d(,i,s), d(i * s))
+/* Indexed Base: */
+#define REGBI(b,i) CHOICE((b,i), (b,i), (b)(i))
+/* Displaced Base: */
+#define REGDB(d,b) CHOICE(d(b), d(b), d(b))
+/* Variable indirect: */
+#define VARINDIRECT(var) CHOICE(*var, *var, (var))
+/* Use register contents as jump/call target: */
+#define CODEPTR(reg) CHOICE(*reg, *reg, reg)
+
+/* For expressions requiring bracketing
+ * eg. (CRT0_PM | CRT_EM)
+ */
+
+#define EXPR(a) CHOICE([a], (a), [a])
+#define ENOT(a) CHOICE(0!a, ~a, ~a)
+#define EMUL(a,b) CHOICE(a\*b, a*b, a*b)
+#define EDIV(a,b) CHOICE(a\/b, a/b, a/b)
+
+/*
+ * We have to beat the problem of commas within arguments to choice.
+ * eg. choice (add a,b, add b,a) will get argument mismatch. Luckily ANSI
+ * and other known cpp definitions evaluate arguments before substitution
+ * so the following works.
+ */
+#define ARG2(a, b) a,b
+#define ARG3(a,b,c) a,b,c
+
+/* Redefine assembler commands */
+#define AAA CHOICE(aaa, aaa, aaa)
+#define AAD CHOICE(aad, aad, aad)
+#define AAM CHOICE(aam, aam, aam)
+#define AAS CHOICE(aas, aas, aas)
+#define ADC_L(a, b) CHOICE(adcl ARG2(a,b), adcl ARG2(a,b), _LTOG adc ARG2(b,a))
+#define ADC_W(a, b) CHOICE(adcw ARG2(a,b), adcw ARG2(a,b), _WTOG adc ARG2(b,a))
+#define ADC_B(a, b) CHOICE(adcb ARG2(a,b), adcb ARG2(a,b), adcb ARG2(b,a))
+#define ADD_L(a, b) CHOICE(addl ARG2(a,b), addl ARG2(a,b), _LTOG add ARG2(b,a))
+#define ADD_W(a, b) CHOICE(addw ARG2(a,b), addw ARG2(a,b), _WTOG add ARG2(b,a))
+#define ADD_B(a, b) CHOICE(addb ARG2(a,b), addb ARG2(a,b), addb ARG2(b,a))
+#define AND_L(a, b) CHOICE(andl ARG2(a,b), andl ARG2(a,b), _LTOG and ARG2(b,a))
+#define AND_W(a, b) CHOICE(andw ARG2(a,b), andw ARG2(a,b), _WTOG and ARG2(b,a))
+#define AND_B(a, b) CHOICE(andb ARG2(a,b), andb ARG2(a,b), andb ARG2(b,a))
+#define ARPL(a,b) CHOICE(arpl ARG2(a,b), arpl ARG2(a,b), arpl ARG2(b,a))
+#define BOUND_L(a, b) CHOICE(boundl ARG2(a,b), boundl ARG2(b,a), _LTOG bound ARG2(b,a))
+#define BOUND_W(a, b) CHOICE(boundw ARG2(a,b), boundw ARG2(b,a), _WTOG bound ARG2(b,a))
+#define BSF_L(a, b) CHOICE(bsfl ARG2(a,b), bsfl ARG2(a,b), _LTOG bsf ARG2(b,a))
+#define BSF_W(a, b) CHOICE(bsfw ARG2(a,b), bsfw ARG2(a,b), _WTOG bsf ARG2(b,a))
+#define BSR_L(a, b) CHOICE(bsrl ARG2(a,b), bsrl ARG2(a,b), _LTOG bsr ARG2(b,a))
+#define BSR_W(a, b) CHOICE(bsrw ARG2(a,b), bsrw ARG2(a,b), _WTOG bsr ARG2(b,a))
+#define BT_L(a, b) CHOICE(btl ARG2(a,b), btl ARG2(a,b), _LTOG bt ARG2(b,a))
+#define BT_W(a, b) CHOICE(btw ARG2(a,b), btw ARG2(a,b), _WTOG bt ARG2(b,a))
+#define BTC_L(a, b) CHOICE(btcl ARG2(a,b), btcl ARG2(a,b), _LTOG btc ARG2(b,a))
+#define BTC_W(a, b) CHOICE(btcw ARG2(a,b), btcw ARG2(a,b), _WTOG btc ARG2(b,a))
+#define BTR_L(a, b) CHOICE(btrl ARG2(a,b), btrl ARG2(a,b), _LTOG btr ARG2(b,a))
+#define BTR_W(a, b) CHOICE(btrw ARG2(a,b), btrw ARG2(a,b), _WTOG btr ARG2(b,a))
+#define BTS_L(a, b) CHOICE(btsl ARG2(a,b), btsl ARG2(a,b), _LTOG bts ARG2(b,a))
+#define BTS_W(a, b) CHOICE(btsw ARG2(a,b), btsw ARG2(a,b), _WTOG bts ARG2(b,a))
+#define CALL(a) CHOICE(call a, call a, call a)
+#define CALLF(s,a) CHOICE(lcall ARG2(s,a), lcall ARG2(s,a), callf s:a)
+#define CBW CHOICE(cbtw, cbw, cbw)
+#define CWDE CHOICE(cwtd, cwde, cwde)
+#define CLC CHOICE(clc, clc, clc)
+#define CLD CHOICE(cld, cld, cld)
+#define CLI CHOICE(cli, cli, cli)
+#define CLTS CHOICE(clts, clts, clts)
+#define CMC CHOICE(cmc, cmc, cmc)
+#define CMP_L(a, b) CHOICE(cmpl ARG2(a,b), cmpl ARG2(a,b), _LTOG cmp ARG2(b,a))
+#define CMP_W(a, b) CHOICE(cmpw ARG2(a,b), cmpw ARG2(a,b), _WTOG cmp ARG2(b,a))
+#define CMP_B(a, b) CHOICE(cmpb ARG2(a,b), cmpb ARG2(a,b), cmpb ARG2(b,a))
+#define CMPS_L CHOICE(cmpsl, cmpsl, _LTOG cmps)
+#define CMPS_W CHOICE(cmpsw, cmpsw, _WTOG cmps)
+#define CMPS_B CHOICE(cmpsb, cmpsb, cmpsb)
+#define CWD CHOICE(cwtl, cwd, cwd)
+#define CDQ CHOICE(cltd, cdq, cdq)
+#define DAA CHOICE(daa, daa, daa)
+#define DAS CHOICE(das, das, das)
+#define DEC_L(a) CHOICE(decl a, decl a, _LTOG dec a)
+#define DEC_W(a) CHOICE(decw a, decw a, _WTOG dec a)
+#define DEC_B(a) CHOICE(decb a, decb a, decb a)
+#define DIV_L(a) CHOICE(divl a, divl a, div a)
+#define DIV_W(a) CHOICE(divw a, divw a, div a)
+#define DIV_B(a) CHOICE(divb a, divb a, divb a)
+#define ENTER(a,b) CHOICE(enter ARG2(a,b), enter ARG2(a,b), enter ARG2(b,a))
+#define HLT CHOICE(hlt, hlt, hlt)
+#define IDIV_L(a) CHOICE(idivl a, idivl a, _LTOG idiv a)
+#define IDIV_W(a) CHOICE(idivw a, idivw a, _WTOG idiv a)
+#define IDIV_B(a) CHOICE(idivb a, idivb a, idivb a)
+/* More forms than this for imul!! */
+#define IMUL_L(a, b) CHOICE(imull ARG2(a,b), imull ARG2(a,b), _LTOG imul ARG2(b,a))
+#define IMUL_W(a, b) CHOICE(imulw ARG2(a,b), imulw ARG2(a,b), _WTOG imul ARG2(b,a))
+#define IMUL_B(a) CHOICE(imulb a, imulb a, imulb a)
+#define IN_L CHOICE(inl (DX), inl ARG2(DX,EAX), _LTOG in DX)
+#define IN_W CHOICE(inw (DX), inw ARG2(DX,AX), _WTOG in DX)
+#define IN_B CHOICE(inb (DX), inb ARG2(DX,AL), inb DX)
+/* Please AS code writer: use the following ONLY, if you refer to ports<256
+ * directly, but not in IN1_W(DX), for instance, even if IN1_ looks nicer
+ */
+#if defined (sun)
+#define IN1_L(a) CHOICE(inl (a), inl ARG2(a,EAX), _LTOG in a)
+#define IN1_W(a) CHOICE(inw (a), inw ARG2(a,AX), _WTOG in a)
+#define IN1_B(a) CHOICE(inb (a), inb ARG2(a,AL), inb a)
+#else
+#define IN1_L(a) CHOICE(inl a, inl ARG2(a,EAX), _LTOG in a)
+#define IN1_W(a) CHOICE(inw a, inw ARG2(a,AX), _WTOG in a)
+#define IN1_B(a) CHOICE(inb a, inb ARG2(a,AL), inb a)
+#endif
+#define INC_L(a) CHOICE(incl a, incl a, _LTOG inc a)
+#define INC_W(a) CHOICE(incw a, incw a, _WTOG inc a)
+#define INC_B(a) CHOICE(incb a, incb a, incb a)
+#define INS_L CHOICE(insl, insl, _LTOG ins)
+#define INS_W CHOICE(insw, insw, _WTOG ins)
+#define INS_B CHOICE(insb, insb, insb)
+#define INT(a) CHOICE(int a, int a, int a)
+#define INT3 CHOICE(int CONST(3), int3, int CONST(3))
+#define INTO CHOICE(into, into, into)
+#define IRET CHOICE(iret, iret, iret)
+#define IRETD CHOICE(iret, iret, iretd)
+#define JA(a) CHOICE(ja a, ja a, ja a)
+#define JAE(a) CHOICE(jae a, jae a, jae a)
+#define JB(a) CHOICE(jb a, jb a, jb a)
+#define JBE(a) CHOICE(jbe a, jbe a, jbe a)
+#define JC(a) CHOICE(jc a, jc a, jc a)
+#define JE(a) CHOICE(je a, je a, je a)
+#define JG(a) CHOICE(jg a, jg a, jg a)
+#define JGE(a) CHOICE(jge a, jge a, jge a)
+#define JL(a) CHOICE(jl a, jl a, jl a)
+#define JLE(a) CHOICE(jle a, jle a, jle a)
+#define JNA(a) CHOICE(jna a, jna a, jna a)
+#define JNAE(a) CHOICE(jnae a, jnae a, jnae a)
+#define JNB(a) CHOICE(jnb a, jnb a, jnb a)
+#define JNBE(a) CHOICE(jnbe a, jnbe a, jnbe a)
+#define JNC(a) CHOICE(jnc a, jnc a, jnc a)
+#define JNE(a) CHOICE(jne a, jne a, jne a)
+#define JNG(a) CHOICE(jng a, jng a, jng a)
+#define JNGE(a) CHOICE(jnge a, jnge a, jnge a)
+#define JNL(a) CHOICE(jnl a, jnl a, jnl a)
+#define JNLE(a) CHOICE(jnle a, jnle a, jnle a)
+#define JNO(a) CHOICE(jno a, jno a, jno a)
+#define JNP(a) CHOICE(jnp a, jnp a, jnp a)
+#define JNS(a) CHOICE(jns a, jns a, jns a)
+#define JNZ(a) CHOICE(jnz a, jnz a, jnz a)
+#define JO(a) CHOICE(jo a, jo a, jo a)
+#define JP(a) CHOICE(jp a, jp a, jp a)
+#define JPE(a) CHOICE(jpe a, jpe a, jpe a)
+#define JPO(a) CHOICE(jpo a, jpo a, jpo a)
+#define JS(a) CHOICE(js a, js a, js a)
+#define JZ(a) CHOICE(jz a, jz a, jz a)
+#define JMP(a) CHOICE(jmp a, jmp a, jmp a)
+#define JMPF(s,a) CHOICE(ljmp ARG2(s,a), ljmp ARG2(s,a), jmpf s:a)
+#define LAHF CHOICE(lahf, lahf, lahf)
+#if !defined(_REAL_MODE) && !defined(_V86_MODE)
+#define LAR(a, b) CHOICE(lar ARG2(a, b), lar ARG2(a, b), lar ARG2(b, a))
+#endif
+#define LEA_L(a, b) CHOICE(leal ARG2(a,b), leal ARG2(a,b), _LTOG lea ARG2(b,a))
+#define LEA_W(a, b) CHOICE(leaw ARG2(a,b), leaw ARG2(a,b), _WTOG lea ARG2(b,a))
+#define LEAVE CHOICE(leave, leave, leave)
+#define LGDT(a) CHOICE(lgdt a, lgdt a, lgdt a)
+#define LIDT(a) CHOICE(lidt a, lidt a, lidt a)
+#define LDS(a, b) CHOICE(ldsl ARG2(a,b), lds ARG2(a,b), lds ARG2(b,a))
+#define LES(a, b) CHOICE(lesl ARG2(a,b), les ARG2(a,b), les ARG2(b,a))
+#define LFS(a, b) CHOICE(lfsl ARG2(a,b), lfs ARG2(a,b), lfs ARG2(b,a))
+#define LGS(a, b) CHOICE(lgsl ARG2(a,b), lgs ARG2(a,b), lgs ARG2(b,a))
+#define LSS(a, b) CHOICE(lssl ARG2(a,b), lss ARG2(a,b), lss ARG2(b,a))
+#define LLDT(a) CHOICE(lldt a, lldt a, lldt a)
+#define LMSW(a) CHOICE(lmsw a, lmsw a, lmsw a)
+#define LOCK CHOICE(lock, lock, lock)
+#define LODS_L CHOICE(lodsl, lodsl, _LTOG lods)
+#define LODS_W CHOICE(lodsw, lodsw, _WTOG lods)
+#define LODS_B CHOICE(lodsb, lodsb, lodsb)
+#define LOOP(a) CHOICE(loop a, loop a, loop a)
+#define LOOPE(a) CHOICE(loope a, loope a, loope a)
+#define LOOPZ(a) CHOICE(loopz a, loopz a, loopz a)
+#define LOOPNE(a) CHOICE(loopne a, loopne a, loopne a)
+#define LOOPNZ(a) CHOICE(loopnz a, loopnz a, loopnz a)
+#if !defined(_REAL_MODE) && !defined(_V86_MODE)
+#define LSL(a, b) CHOICE(lsl ARG2(a,b), lsl ARG2(a,b), lsl ARG2(b,a))
+#endif
+#define LTR(a) CHOICE(ltr a, ltr a, ltr a)
+#define MOV_SR(a, b) CHOICE(movw ARG2(a,b), mov ARG2(a,b), mov ARG2(b,a))
+#define MOV_L(a, b) CHOICE(movl ARG2(a,b), movl ARG2(a,b), _LTOG mov ARG2(b,a))
+#define MOV_W(a, b) CHOICE(movw ARG2(a,b), movw ARG2(a,b), _WTOG mov ARG2(b,a))
+#define MOV_B(a, b) CHOICE(movb ARG2(a,b), movb ARG2(a,b), movb ARG2(b,a))
+#define MOVS_L CHOICE(movsl, movsl, _LTOG movs)
+#define MOVS_W CHOICE(movsw, movsw, _WTOG movs)
+#define MOVS_B CHOICE(movsb, movsb, movsb)
+#define MOVSX_BL(a, b) CHOICE(movsbl ARG2(a,b), movsbl ARG2(a,b), movsx ARG2(b,a))
+#define MOVSX_BW(a, b) CHOICE(movsbw ARG2(a,b), movsbw ARG2(a,b), movsx ARG2(b,a))
+#define MOVSX_WL(a, b) CHOICE(movswl ARG2(a,b), movswl ARG2(a,b), movsx ARG2(b,a))
+#define MOVZX_BL(a, b) CHOICE(movzbl ARG2(a,b), movzbl ARG2(a,b), movzx ARG2(b,a))
+#define MOVZX_BW(a, b) CHOICE(movzbw ARG2(a,b), movzbw ARG2(a,b), movzx ARG2(b,a))
+#define MOVZX_WL(a, b) CHOICE(movzwl ARG2(a,b), movzwl ARG2(a,b), movzx ARG2(b,a))
+#define MUL_L(a) CHOICE(mull a, mull a, _LTOG mul a)
+#define MUL_W(a) CHOICE(mulw a, mulw a, _WTOG mul a)
+#define MUL_B(a) CHOICE(mulb a, mulb a, mulb a)
+#define NEG_L(a) CHOICE(negl a, negl a, _LTOG neg a)
+#define NEG_W(a) CHOICE(negw a, negw a, _WTOG neg a)
+#define NEG_B(a) CHOICE(negb a, negb a, negb a)
+#define NOP CHOICE(nop, nop, nop)
+#define NOT_L(a) CHOICE(notl a, notl a, _LTOG not a)
+#define NOT_W(a) CHOICE(notw a, notw a, _WTOG not a)
+#define NOT_B(a) CHOICE(notb a, notb a, notb a)
+#define OR_L(a,b) CHOICE(orl ARG2(a,b), orl ARG2(a,b), _LTOG or ARG2(b,a))
+#define OR_W(a,b) CHOICE(orw ARG2(a,b), orw ARG2(a,b), _WTOG or ARG2(b,a))
+#define OR_B(a,b) CHOICE(orb ARG2(a,b), orb ARG2(a,b), orb ARG2(b,a))
+#define OUT_L CHOICE(outl (DX), outl ARG2(EAX,DX), _LTOG out DX)
+#define OUT_W CHOICE(outw (DX), outw ARG2(AX,DX), _WTOG out DX)
+#define OUT_B CHOICE(outb (DX), outb ARG2(AL,DX), outb DX)
+/* Please AS code writer: use the following ONLY, if you refer to ports<256
+ * directly, but not in OUT1_W(DX), for instance, even if OUT1_ looks nicer
+ */
+#define OUT1_L(a) CHOICE(outl (a), outl ARG2(EAX,a), _LTOG out a)
+#define OUT1_W(a) CHOICE(outw (a), outw ARG2(AX,a), _WTOG out a)
+#define OUT1_B(a) CHOICE(outb (a), outb ARG2(AL,a), outb a)
+#define OUTS_L CHOICE(outsl, outsl, _LTOG outs)
+#define OUTS_W CHOICE(outsw, outsw, _WTOG outs)
+#define OUTS_B CHOICE(outsb, outsb, outsb)
+#define POP_SR(a) CHOICE(pop a, pop a, pop a)
+#define POP_L(a) CHOICE(popl a, popl a, _LTOG pop a)
+#define POP_W(a) CHOICE(popw a, popw a, _WTOG pop a)
+#define POPA_L CHOICE(popal, popal, _LTOG popa)
+#define POPA_W CHOICE(popaw, popaw, _WTOG popa)
+#define POPF_L CHOICE(popfl, popfl, _LTOG popf)
+#define POPF_W CHOICE(popfw, popfw, _WTOG popf)
+#define PUSH_SR(a) CHOICE(push a, push a, push a)
+#define PUSH_L(a) CHOICE(pushl a, pushl a, _LTOG push a)
+#define PUSH_W(a) CHOICE(pushw a, pushw a, _WTOG push a)
+#define PUSH_B(a) CHOICE(push a, pushb a, push a)
+#define PUSHA_L CHOICE(pushal, pushal, _LTOG pusha)
+#define PUSHA_W CHOICE(pushaw, pushaw, _WTOG pusha)
+#define PUSHF_L CHOICE(pushfl, pushfl, _LTOG pushf)
+#define PUSHF_W CHOICE(pushfw, pushfw, _WTOG pushf)
+#define RCL_L(a, b) CHOICE(rcll ARG2(a,b), rcll ARG2(a,b), _LTOG rcl ARG2(b,a))
+#define RCL_W(a, b) CHOICE(rclw ARG2(a,b), rclw ARG2(a,b), _WTOG rcl ARG2(b,a))
+#define RCL_B(a, b) CHOICE(rclb ARG2(a,b), rclb ARG2(a,b), rclb ARG2(b,a))
+#define RCR_L(a, b) CHOICE(rcrl ARG2(a,b), rcrl ARG2(a,b), _LTOG rcr ARG2(b,a))
+#define RCR_W(a, b) CHOICE(rcrw ARG2(a,b), rcrw ARG2(a,b), _WTOG rcr ARG2(b,a))
+#define RCR_B(a, b) CHOICE(rcrb ARG2(a,b), rcrb ARG2(a,b), rcrb ARG2(b,a))
+#define ROL_L(a, b) CHOICE(roll ARG2(a,b), roll ARG2(a,b), _LTOG rol ARG2(b,a))
+#define ROL_W(a, b) CHOICE(rolw ARG2(a,b), rolw ARG2(a,b), _WTOG rol ARG2(b,a))
+#define ROL_B(a, b) CHOICE(rolb ARG2(a,b), rolb ARG2(a,b), rolb ARG2(b,a))
+#define ROR_L(a, b) CHOICE(rorl ARG2(a,b), rorl ARG2(a,b), _LTOG ror ARG2(b,a))
+#define ROR_W(a, b) CHOICE(rorw ARG2(a,b), rorw ARG2(a,b), _WTOG ror ARG2(b,a))
+#define ROR_B(a, b) CHOICE(rorb ARG2(a,b), rorb ARG2(a,b), rorb ARG2(b,a))
+#define REP CHOICE(rep ;, rep ;, repe)
+#define REPE CHOICE(repz ;, repe ;, repe)
+#define REPNE CHOICE(repnz ;, repne ;, repne)
+#define REPNZ REPNE
+#define REPZ REPE
+#define RET CHOICE(ret, ret, ret)
+#define SAHF CHOICE(sahf, sahf, sahf)
+#define SAL_L(a, b) CHOICE(sall ARG2(a,b), sall ARG2(a,b), _LTOG sal ARG2(b,a))
+#define SAL_W(a, b) CHOICE(salw ARG2(a,b), salw ARG2(a,b), _WTOG sal ARG2(b,a))
+#define SAL_B(a, b) CHOICE(salb ARG2(a,b), salb ARG2(a,b), salb ARG2(b,a))
+#define SAR_L(a, b) CHOICE(sarl ARG2(a,b), sarl ARG2(a,b), _LTOG sar ARG2(b,a))
+#define SAR_W(a, b) CHOICE(sarw ARG2(a,b), sarw ARG2(a,b), _WTOG sar ARG2(b,a))
+#define SAR_B(a, b) CHOICE(sarb ARG2(a,b), sarb ARG2(a,b), sarb ARG2(b,a))
+#define SBB_L(a, b) CHOICE(sbbl ARG2(a,b), sbbl ARG2(a,b), _LTOG sbb ARG2(b,a))
+#define SBB_W(a, b) CHOICE(sbbw ARG2(a,b), sbbw ARG2(a,b), _WTOG sbb ARG2(b,a))
+#define SBB_B(a, b) CHOICE(sbbb ARG2(a,b), sbbb ARG2(a,b), sbbb ARG2(b,a))
+#define SCAS_L CHOICE(scasl, scasl, _LTOG scas)
+#define SCAS_W CHOICE(scasw, scasw, _WTOG scas)
+#define SCAS_B CHOICE(scasb, scasb, scasb)
+#define SETA(a) CHOICE(seta a, seta a, seta a)
+#define SETAE(a) CHOICE(setae a, setae a, setae a)
+#define SETB(a) CHOICE(setb a, setb a, setb a)
+#define SETBE(a) CHOICE(setbe a, setbe a, setbe a)
+#define SETC(a) CHOICE(setc a, setb a, setb a)
+#define SETE(a) CHOICE(sete a, sete a, sete a)
+#define SETG(a) CHOICE(setg a, setg a, setg a)
+#define SETGE(a) CHOICE(setge a, setge a, setge a)
+#define SETL(a) CHOICE(setl a, setl a, setl a)
+#define SETLE(a) CHOICE(setle a, setle a, setle a)
+#define SETNA(a) CHOICE(setna a, setna a, setna a)
+#define SETNAE(a) CHOICE(setnae a, setnae a, setnae a)
+#define SETNB(a) CHOICE(setnb a, setnb a, setnb a)
+#define SETNBE(a) CHOICE(setnbe a, setnbe a, setnbe a)
+#define SETNC(a) CHOICE(setnc a, setnb a, setnb a)
+#define SETNE(a) CHOICE(setne a, setne a, setne a)
+#define SETNG(a) CHOICE(setng a, setng a, setng a)
+#define SETNGE(a) CHOICE(setnge a, setnge a, setnge a)
+#define SETNL(a) CHOICE(setnl a, setnl a, setnl a)
+#define SETNLE(a) CHOICE(setnle a, setnle a, setnle a)
+#define SETNO(a) CHOICE(setno a, setno a, setno a)
+#define SETNP(a) CHOICE(setnp a, setnp a, setnp a)
+#define SETNS(a) CHOICE(setns a, setns a, setna a)
+#define SETNZ(a) CHOICE(setnz a, setnz a, setnz a)
+#define SETO(a) CHOICE(seto a, seto a, seto a)
+#define SETP(a) CHOICE(setp a, setp a, setp a)
+#define SETPE(a) CHOICE(setpe a, setpe a, setpe a)
+#define SETPO(a) CHOICE(setpo a, setpo a, setpo a)
+#define SETS(a) CHOICE(sets a, sets a, seta a)
+#define SETZ(a) CHOICE(setz a, setz a, setz a)
+#define SGDT(a) CHOICE(sgdt a, sgdt a, sgdt a)
+#define SIDT(a) CHOICE(sidt a, sidt a, sidt a)
+#define SHL_L(a, b) CHOICE(shll ARG2(a,b), shll ARG2(a,b), _LTOG shl ARG2(b,a))
+#define SHL_W(a, b) CHOICE(shlw ARG2(a,b), shlw ARG2(a,b), _WTOG shl ARG2(b,a))
+#define SHL_B(a, b) CHOICE(shlb ARG2(a,b), shlb ARG2(a,b), shlb ARG2(b,a))
+#define SHLD_L(a,b,c) CHOICE(shldl ARG3(a,b,c), shldl ARG3(a,b,c), _LTOG shld ARG3(c,b,a))
+#define SHLD2_L(a,b) CHOICE(shldl ARG2(a,b), shldl ARG3(CL,a,b), _LTOG shld ARG3(b,a,CL))
+#define SHLD_W(a,b,c) CHOICE(shldw ARG3(a,b,c), shldw ARG3(a,b,c), _WTOG shld ARG3(c,b,a))
+#define SHLD2_W(a,b) CHOICE(shldw ARG2(a,b), shldw ARG3(CL,a,b), _WTOG shld ARG3(b,a,CL))
+#define SHR_L(a, b) CHOICE(shrl ARG2(a,b), shrl ARG2(a,b), _LTOG shr ARG2(b,a))
+#define SHR_W(a, b) CHOICE(shrw ARG2(a,b), shrw ARG2(a,b), _WTOG shr ARG2(b,a))
+#define SHR_B(a, b) CHOICE(shrb ARG2(a,b), shrb ARG2(a,b), shrb ARG2(b,a))
+#define SHRD_L(a,b,c) CHOICE(shrdl ARG3(a,b,c), shrdl ARG3(a,b,c), _LTOG shrd ARG3(c,b,a))
+#define SHRD2_L(a,b) CHOICE(shrdl ARG2(a,b), shrdl ARG3(CL,a,b), _LTOG shrd ARG3(b,a,CL))
+#define SHRD_W(a,b,c) CHOICE(shrdw ARG3(a,b,c), shrdw ARG3(a,b,c), _WTOG shrd ARG3(c,b,a))
+#define SHRD2_W(a,b) CHOICE(shrdw ARG2(a,b), shrdw ARG3(CL,a,b), _WTOG shrd ARG3(b,a,CL))
+#define SLDT(a) CHOICE(sldt a, sldt a, sldt a)
+#define SMSW(a) CHOICE(smsw a, smsw a, smsw a)
+#define STC CHOICE(stc, stc, stc)
+#define STD CHOICE(std, std, std)
+#define STI CHOICE(sti, sti, sti)
+#define STOS_L CHOICE(stosl, stosl, _LTOG stos)
+#define STOS_W CHOICE(stosw, stosw, _WTOG stos)
+#define STOS_B CHOICE(stosb, stosb, stosb)
+#define STR(a) CHOICE(str a, str a, str a)
+#define SUB_L(a, b) CHOICE(subl ARG2(a,b), subl ARG2(a,b), _LTOG sub ARG2(b,a))
+#define SUB_W(a, b) CHOICE(subw ARG2(a,b), subw ARG2(a,b), _WTOG sub ARG2(b,a))
+#define SUB_B(a, b) CHOICE(subb ARG2(a,b), subb ARG2(a,b), subb ARG2(b,a))
+#define TEST_L(a, b) CHOICE(testl ARG2(a,b), testl ARG2(a,b), _LTOG test ARG2(b,a))
+#define TEST_W(a, b) CHOICE(testw ARG2(a,b), testw ARG2(a,b), _WTOG test ARG2(b,a))
+#define TEST_B(a, b) CHOICE(testb ARG2(a,b), testb ARG2(a,b), testb ARG2(b,a))
+#define VERR(a) CHOICE(verr a, verr a, verr a)
+#define VERW(a) CHOICE(verw a, verw a, verw a)
+#define WAIT CHOICE(wait, wait, wait)
+#define XCHG_L(a, b) CHOICE(xchgl ARG2(a,b), xchgl ARG2(a,b), _LTOG xchg ARG2(b,a))
+#define XCHG_W(a, b) CHOICE(xchgw ARG2(a,b), xchgw ARG2(a,b), _WTOG xchg ARG2(b,a))
+#define XCHG_B(a, b) CHOICE(xchgb ARG2(a,b), xchgb ARG2(a,b), xchgb ARG2(b,a))
+#define XLAT CHOICE(xlat, xlat, xlat)
+#define XOR_L(a, b) CHOICE(xorl ARG2(a,b), xorl ARG2(a,b), _LTOG xor ARG2(b,a))
+#define XOR_W(a, b) CHOICE(xorw ARG2(a,b), xorw ARG2(a,b), _WTOG xor ARG2(b,a))
+#define XOR_B(a, b) CHOICE(xorb ARG2(a,b), xorb ARG2(a,b), xorb ARG2(b,a))
+
+
+/* Floating Point Instructions */
+#define F2XM1 CHOICE(f2xm1, f2xm1, f2xm1)
+#define FABS CHOICE(fabs, fabs, fabs)
+#define FADD_D(a) CHOICE(faddl a, faddl a, faddd a)
+#define FADD_S(a) CHOICE(fadds a, fadds a, fadds a)
+#define FADD2(a, b) CHOICE(fadd ARG2(a,b), fadd ARG2(a,b), fadd ARG2(b,a))
+#define FADDP(a, b) CHOICE(faddp ARG2(a,b), faddp ARG2(a,b), faddp ARG2(b,a))
+#define FIADD_L(a) CHOICE(fiaddl a, fiaddl a, fiaddl a)
+#define FIADD_W(a) CHOICE(fiadd a, fiadds a, fiadds a)
+#define FBLD(a) CHOICE(fbld a, fbld a, fbld a)
+#define FBSTP(a) CHOICE(fbstp a, fbstp a, fbstp a)
+#define FCHS CHOICE(fchs, fchs, fchs)
+#define FCLEX CHOICE(fclex, wait; fnclex, wait; fclex)
+#define FNCLEX CHOICE(fnclex, fnclex, fclex)
+#define FCOM(a) CHOICE(fcom a, fcom a, fcom a)
+#define FCOM_D(a) CHOICE(fcoml a, fcoml a, fcomd a)
+#define FCOM_S(a) CHOICE(fcoms a, fcoms a, fcoms a)
+#define FCOMP(a) CHOICE(fcomp a, fcomp a, fcomp a)
+#define FCOMP_D(a) CHOICE(fcompl a, fcompl a, fcompd a)
+#define FCOMP_S(a) CHOICE(fcomps a, fcomps a, fcomps a)
+#define FCOMPP CHOICE(fcompp, fcompp, fcompp)
+#define FCOS CHOICE(fcos, fcos, fcos)
+#define FDECSTP CHOICE(fdecstp, fdecstp, fdecstp)
+#define FDIV_D(a) CHOICE(fdivl a, fdivl a, fdivd a)
+#define FDIV_S(a) CHOICE(fdivs a, fdivs a, fdivs a)
+#define FDIV2(a, b) CHOICE(fdiv ARG2(a,b), fdiv ARG2(a,b), fdiv ARG2(b,a))
+#define FDIVP(a, b) CHOICE(fdivp ARG2(a,b), fdivp ARG2(a,b), fdivp ARG2(b,a))
+#define FIDIV_L(a) CHOICE(fidivl a, fidivl a, fidivl a)
+#define FIDIV_W(a) CHOICE(fidiv a, fidivs a, fidivs a)
+#define FDIVR_D(a) CHOICE(fdivrl a, fdivrl a, fdivrd a)
+#define FDIVR_S(a) CHOICE(fdivrs a, fdivrs a, fdivrs a)
+#define FDIVR2(a, b) CHOICE(fdivr ARG2(a,b), fdivr ARG2(a,b), fdivr ARG2(b,a))
+#define FDIVRP(a, b) CHOICE(fdivrp ARG2(a,b), fdivrp ARG2(a,b), fdivrp ARG2(b,a))
+#define FIDIVR_L(a) CHOICE(fidivrl a, fidivrl a, fidivrl a)
+#define FIDIVR_W(a) CHOICE(fidivr a, fidivrs a, fidivrs a)
+#define FFREE(a) CHOICE(ffree a, ffree a, ffree a)
+#define FICOM_L(a) CHOICE(ficoml a, ficoml a, ficoml a)
+#define FICOM_W(a) CHOICE(ficom a, ficoms a, ficoms a)
+#define FICOMP_L(a) CHOICE(ficompl a, ficompl a, ficompl a)
+#define FICOMP_W(a) CHOICE(ficomp a, ficomps a, ficomps a)
+#define FILD_Q(a) CHOICE(fildll a, fildq a, fildq a)
+#define FILD_L(a) CHOICE(fildl a, fildl a, fildl a)
+#define FILD_W(a) CHOICE(fild a, filds a, filds a)
+#define FINCSTP CHOICE(fincstp, fincstp, fincstp)
+#define FINIT CHOICE(finit, wait; fninit, wait; finit)
+#define FNINIT CHOICE(fninit, fninit, finit)
+#define FIST_L(a) CHOICE(fistl a, fistl a, fistl a)
+#define FIST_W(a) CHOICE(fist a, fists a, fists a)
+#define FISTP_Q(a) CHOICE(fistpll a, fistpq a, fistpq a)
+#define FISTP_L(a) CHOICE(fistpl a, fistpl a, fistpl a)
+#define FISTP_W(a) CHOICE(fistp a, fistps a, fistps a)
+#define FLD_X(a) CHOICE(fldt a, fldt a, fldx a) /* 80 bit data type! */
+#define FLD_D(a) CHOICE(fldl a, fldl a, fldd a)
+#define FLD_S(a) CHOICE(flds a, flds a, flds a)
+#define FLD1 CHOICE(fld1, fld1, fld1)
+#define FLDL2T CHOICE(fldl2t, fldl2t, fldl2t)
+#define FLDL2E CHOICE(fldl2e, fldl2e, fldl2e)
+#define FLDPI CHOICE(fldpi, fldpi, fldpi)
+#define FLDLG2 CHOICE(fldlg2, fldlg2, fldlg2)
+#define FLDLN2 CHOICE(fldln2, fldln2, fldln2)
+#define FLDZ CHOICE(fldz, fldz, fldz)
+#define FLDCW(a) CHOICE(fldcw a, fldcw a, fldcw a)
+#define FLDENV(a) CHOICE(fldenv a, fldenv a, fldenv a)
+#define FMUL_S(a) CHOICE(fmuls a, fmuls a, fmuls a)
+#define FMUL_D(a) CHOICE(fmull a, fmull a, fmuld a)
+#define FMUL2(a, b) CHOICE(fmul ARG2(a,b), fmul ARG2(a,b), fmul ARG2(b,a))
+#define FMULP(a, b) CHOICE(fmulp ARG2(a,b), fmulp ARG2(a,b), fmulp ARG2(b,a))
+#define FIMUL_L(a) CHOICE(fimull a, fimull a, fimull a)
+#define FIMUL_W(a) CHOICE(fimul a, fimuls a, fimuls a)
+#define FNOP CHOICE(fnop, fnop, fnop)
+#define FPATAN CHOICE(fpatan, fpatan, fpatan)
+#define FPREM CHOICE(fprem, fprem, fprem)
+#define FPREM1 CHOICE(fprem1, fprem1, fprem1)
+#define FPTAN CHOICE(fptan, fptan, fptan)
+#define FRNDINT CHOICE(frndint, frndint, frndint)
+#define FRSTOR(a) CHOICE(frstor a, frstor a, frstor a)
+#define FSAVE(a) CHOICE(fsave a, wait; fnsave a, wait; fsave a)
+#define FNSAVE(a) CHOICE(fnsave a, fnsave a, fsave a)
+#define FSCALE CHOICE(fscale, fscale, fscale)
+#define FSIN CHOICE(fsin, fsin, fsin)
+#define FSINCOS CHOICE(fsincos, fsincos, fsincos)
+#define FSQRT CHOICE(fsqrt, fsqrt, fsqrt)
+#define FST_D(a) CHOICE(fstl a, fstl a, fstd a)
+#define FST_S(a) CHOICE(fsts a, fsts a, fsts a)
+#define FSTP_X(a) CHOICE(fstpt a, fstpt a, fstpx a)
+#define FSTP_D(a) CHOICE(fstpl a, fstpl a, fstpd a)
+#define FSTP_S(a) CHOICE(fstps a, fstps a, fstps a)
+#define FSTCW(a) CHOICE(fstcw a, wait; fnstcw a, wait; fstcw a)
+#define FNSTCW(a) CHOICE(fnstcw a, fnstcw a, fstcw a)
+#define FSTENV(a) CHOICE(fstenv a, wait; fnstenv a, fstenv a)
+#define FNSTENV(a) CHOICE(fnstenv a, fnstenv a, fstenv a)
+#define FSTSW(a) CHOICE(fstsw a, wait; fnstsw a, wait; fstsw a)
+#define FNSTSW(a) CHOICE(fnstsw a, fnstsw a, fstsw a)
+#define FSUB_S(a) CHOICE(fsubs a, fsubs a, fsubs a)
+#define FSUB_D(a) CHOICE(fsubl a, fsubl a, fsubd a)
+#define FSUB2(a, b) CHOICE(fsub ARG2(a,b), fsub ARG2(a,b), fsub ARG2(b,a))
+#define FSUBP(a, b) CHOICE(fsubp ARG2(a,b), fsubp ARG2(a,b), fsubp ARG2(b,a))
+#define FISUB_L(a) CHOICE(fisubl a, fisubl a, fisubl a)
+#define FISUB_W(a) CHOICE(fisub a, fisubs a, fisubs a)
+#define FSUBR_S(a) CHOICE(fsubrs a, fsubrs a, fsubrs a)
+#define FSUBR_D(a) CHOICE(fsubrl a, fsubrl a, fsubrd a)
+#define FSUBR2(a, b) CHOICE(fsubr ARG2(a,b), fsubr ARG2(a,b), fsubr ARG2(b,a))
+#define FSUBRP(a, b) CHOICE(fsubrp ARG2(a,b), fsubrp ARG2(a,b), fsubrp ARG2(b,a))
+#define FISUBR_L(a) CHOICE(fisubrl a, fisubrl a, fisubrl a)
+#define FISUBR_W(a) CHOICE(fisubr a, fisubrs a, fisubrs a)
+#define FTST CHOICE(ftst, ftst, ftst)
+#define FUCOM(a) CHOICE(fucom a, fucom a, fucom a)
+#define FUCOMP(a) CHOICE(fucomp a, fucomp a, fucomp a)
+#define FUCOMPP CHOICE(fucompp, fucompp, fucompp)
+#define FWAIT CHOICE(wait, wait, wait)
+#define FXAM CHOICE(fxam, fxam, fxam)
+#define FXCH(a) CHOICE(fxch a, fxch a, fxch a)
+#define FXTRACT CHOICE(fxtract, fxtract, fxtract)
+#define FYL2X CHOICE(fyl2x, fyl2x, fyl2x)
+#define FYL2XP1 CHOICE(fyl2xp1, fyl2xp1, fyl2xp1)
+
+#endif /* __ASSYNTAX_H__ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile
new file mode 100644
index 000000000..00309690e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile
@@ -0,0 +1,242 @@
+XCOMM $XConsortium: Imakefile /main/12 1996/10/27 11:06:35 kaleb $
+
+
+
+
+
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile,v 3.61 2003/10/07 22:30:00 herrb Exp $
+
+#include <Server.tmpl>
+
+#if defined(KFreeBSDArchitecture) || defined(NetBSDArchitecture) || defined(OpenBSDArchitecture)
+#if BuildXInputExt
+# if JoystickSupport
+ JOYSTICK_SRC = bsd_jstk.c
+# endif
+# if DoLoadableServer
+SHARED_CFLAGS = PositionIndependentCFlags
+# else
+# if JoystickSupport
+ JOYSTICK_OBJ = bsd_jstk.o
+# endif
+# endif
+#endif
+#endif
+
+#if defined(NetBSDArchitecture) \
+ && ((OSMajorVersion == 1 && OSMinorVersion >= 1) || OSMajorVersion >= 2)
+# if defined(AlphaArchitecture)
+ IOPERMDEFINES = -DUSE_ALPHA_PIO
+# elif defined(ArcArchitecture)
+ IOPERMDEFINES = -DUSE_ARC_MMAP
+# elif defined(Arm32Architecture)
+ IOPERMDEFINES = -DUSE_ARM32_MMAP
+# elif defined(PpcArchitecture) || \
+ defined(Sparc64Architecture)
+ IOPERM_SRC = ioperm_noop.c
+ IOPERM_OBJ = ioperm_noop.o
+# else
+ IOPERMDEFINES = -DUSE_I386_IOPL
+# endif
+#elif defined(OpenBSDArchitecture)
+# if defined(i386Architecture)
+ IOPERMDEFINES = -DUSE_I386_IOPL
+# elif defined(AMD64Architecture)
+ IOPERMDEFINES = -DUSE_AMD64_IOPL
+# else
+ IOPERM_SRC = ioperm_noop.c
+ IOPERM_OBJ = ioperm_noop.o
+# endif
+#elif defined(KFreeBSDArchitecture)
+# if defined(i386Architecture) || defined(AMD64Architecture)
+ IOPERMDEFINES = -DUSE_DEV_IO
+# elif defined(AlphaBsdArchitecture)
+ IOPERMDEFINES = -DUSE_ALPHA_PORTS
+# else
+ IOPERM_SRC = ioperm_noop.c
+ IOPERM_OBJ = ioperm_noop.o
+# endif
+#endif
+
+#if BuildXF86DRI
+DRI_SRC = sigio.c
+DRI_OBJ = sigio.o
+#endif
+
+MOUSESRC = bsd_mouse.c
+MOUSEOBJ = bsd_mouse.o
+
+KBDSRC = bsd_kbd.c bsd_KbdMap.c at_scancode.c
+KBDOBJ = bsd_kbd.o bsd_KbdMap.o at_scancode.o
+
+#if HasMTRRSupport
+MTRRDEFINES = -DHAS_MTRR_SUPPORT
+#endif
+
+#if defined(NetBSDArchitecture) && defined(HasMTRRBuiltin)
+MTRRDEFINES = -DHAS_MTRR_BUILTIN
+#endif
+
+SYSVIPCDEFINES = -DHAVE_SYSV_IPC
+
+#if UsbMouseSupport
+USBMOUSEDEFINES1 = -DUSBMOUSE_SUPPORT
+#if !HasLibUsb
+LIBUSBINCLUDES = -Ilibusb
+#define IHaveSubdirs
+SUBDIRS = libusb
+#else
+#if HasLibUsbHid
+USBMOUSEDEFINES2 = -DHAS_LIB_USB_HID
+#endif
+#endif
+#endif
+USBMOUSEDEFINES = $(USBMOUSEDEFINES1) $(USBMOUSEDEFINES2)
+
+#if (defined(OpenBSDArchitecture) || defined(NetBSDArchitecture)) && defined(i386Architecture)
+# if !defined(HasApmKqueue) || !HasApmKqueue
+APMSRC = bsd_apm.c
+APMOBJ = bsd_apm.o
+# else
+APMSRC = bsd_kqueue_apm.c
+APMOBJ = bsd_kqueue_apm.o
+# endif
+#else
+APMSRC = pm_noop.c
+APMOBJ = pm_noop.o
+#endif
+
+#if defined(KFreeBSDArchitecture) && (OSMajorVersion > 2)
+KMODSRC = bsd_kmod.c
+KMODOBJ = bsd_kmod.o
+#else
+KMODSRC = kmod_noop.c
+KMODOBJ = kmod_noop.o
+#endif
+
+#if defined(i386Architecture) || defined(ia64Architecture)
+RES_SRC=stdResource.c
+RES_OBJ=stdResource.o
+#else
+RES_SRC=bsdResource.c
+RES_OBJ=bsdResource.o
+#endif
+
+#if defined(AlphaArchitecture)
+AXP_SRC=bsd_ev56.c xf86Axp.c bsd_axp.c
+AXP_OBJ=bsd_ev56.o xf86Axp.o bsd_axp.o
+#endif
+
+#if (defined(KFreeBSDArchitecture) || defined(NetBSDArchitecture) || \
+ defined(OpenBSDArchitecture)) && HasAgpGart
+AGP_SRC=lnx_agp.c
+AGP_OBJ=lnx_agp.o
+#else
+AGP_SRC=agp_noop.c
+AGP_OBJ=agp_noop.o
+#endif
+
+#if defined(i386Architecture) || defined(AMD64Architecture)
+VIDEO_SRC = i386_video.c
+VIDEO_OBJ = i386_video.o
+#elif defined(AlphaArchitecture)
+VIDEO_SRC = alpha_video.c
+VIDEO_OBJ = alpha_video.o
+#elif defined(PpcArchitecture)
+VIDEO_SRC = ppc_video.c
+VIDEO_OBJ = ppc_video.o
+#elif defined(Arm32Architecture)
+VIDEO_SRC = arm_video.c
+VIDEO_OBJ = arm_video.o
+#elif defined(SparcArchitecture) || defined(Sparc64Architecture)
+VIDEO_SRC = sparc64_video.c
+VIDEO_OBJ = sparc64_video.o
+#else
+#error Unknown architecture !
+#endif
+
+SRCS = bsd_init.c $(VIDEO_SRC) bsd_io.c bsd_VTsw.c \
+ libc_wrapper.c $(IOPERM_SRC) std_kbdEv.c posix_tty.c $(MOUSESRC) \
+ $(RES_SRC) stdPci.c vidmem.c $(JOYSTICK_SRC) sigio.c $(APMSRC) \
+ $(AXP_SRC) $(KMODSRC) $(AGP_SRC) $(KBDSRC)
+
+OBJS = bsd_init.o $(VIDEO_OBJ) bsd_io.o bsd_VTsw.o \
+ libc_wrapper.o $(IOPERM_OBJ) std_kbdEv.o posix_tty.o $(MOUSEOBJ) \
+ $(RES_OBJ) stdPci.o vidmem.o $(JOYSTICK_OBJ) sigio.o $(APMOBJ) \
+ $(AXP_OBJ) $(KMODOBJ) $(AGP_OBJ) $(KBDOBJ)
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(SERVERSRC)/mi $(APINCLUDES) \
+ $(LIBUSBINCLUDES) -I$(XF86OSSRC)/shared -I$(DRMSRCDIR)/shared-core
+
+CONSDEFINES = XFree86ConsoleDefines
+RESDEFINES = -DUSESTDRES
+
+#if defined(HasNetBSDApertureDriver) && HasNetBSDApertureDriver
+APDEFINES = -DHAS_APERTURE_DRV
+#endif
+
+DEFINES = $(CONSDEFINES) $(APDEFINES) $(IOPERMDEFINES) $(RESDEFINES) \
+ $(MTRRDEFINES) $(USBMOUSEDEFINES) $(SYSVIPCDEFINES)
+
+#if defined(AlphaArchitecture)
+SpecialObjectRule(bsd_ev56.o, bsd_ev56.c, -mcpu=ev56)
+#endif
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+#if BuildXF86DRI
+#define IHaveSubdirs
+SUBDIRS = drm
+
+MakeSubdirs($(SUBDIRS))
+DependSubdirs($(SUBDIRS))
+#endif
+
+#if BuildXInputExt
+# if DoLoadableServer
+# if JoystickSupport
+AllTarget(bsd_jstk.o)
+#if 0
+InstallDynamicModule(bsd_jstk.o,$(MODULEDIR),input)
+#endif
+# endif
+# endif
+#endif
+
+#if !defined(NetBSDArchitecture) && !defined(OpenBSDArchitecture) || \
+ !defined(i386Architecture)
+LinkSourceFile(pm_noop.c,../shared)
+#endif
+LinkSourceFile(ioperm_noop.c,../shared)
+LinkSourceFile(std_kbdEv.c,../shared)
+LinkSourceFile(at_scancode.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(vidmem.c,../shared)
+LinkSourceFile(sigio.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+#if (defined(KFreeBSDArchitecture) || defined(NetBSDArchitecture) || \
+ defined(OpenBSDArchitecture)) && HasAgpGart
+LinkSourceFile(lnx_agp.c,../linux)
+#else
+LinkSourceFile(agp_noop.c,../shared)
+#endif
+#if defined(AlphaArchitecture)
+LinkSourceFile(xf86Axp.c,../shared)
+#endif
+
+DependTarget()
+
+#if UsbMouseSupport && !HasLibUsb
+MakeSubdirs($(SUBDIRS))
+
+DependSubdirs($(SUBDIRS))
+#endif
+
+#if 0
+InstallDriverSDKDynamicModule(bsd_jstk.o,$(DRIVERSDKMODULEDIR))
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c
new file mode 100644
index 000000000..ca0f0f8e7
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c
@@ -0,0 +1,735 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c,v 1.6 2003/12/30 15:18:30 herrb Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XConsortium: bsd_video.c /main/10 1996/10/25 11:37:57 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+
+#include <sys/param.h>
+#ifndef __NetBSD__
+# include <sys/sysctl.h>
+# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+# include <machine/sysarch.h>
+# endif
+# else
+# include <machine/sysarch.h>
+#endif
+
+#include "xf86Axp.h"
+
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#if defined(__NetBSD__) && !defined(MAP_FILE)
+#define MAP_FLAGS MAP_SHARED
+#else
+#define MAP_FLAGS (MAP_FILE | MAP_SHARED)
+#endif
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((caddr_t)-1)
+#endif
+
+axpDevice bsdGetAXP(void);
+
+#ifndef __NetBSD__
+extern unsigned long dense_base(void);
+
+static int axpSystem = -1;
+static unsigned long hae_thresh;
+static unsigned long hae_mask;
+static unsigned long bus_base;
+static unsigned long sparse_size;
+
+static unsigned long
+memory_base(void)
+{
+ static unsigned long base = 0;
+
+ if (base == 0) {
+ size_t len = sizeof(base);
+ int error;
+#ifdef __OpenBSD__
+ int mib[3];
+
+ mib[0] = CTL_MACHDEP;
+ mib[1] = CPU_CHIPSET;
+ mib[2] = CPU_CHIPSET_MEM;
+
+ if ((error = sysctl(mib, 3, &base, &len, NULL, 0)) < 0)
+#else
+ if ((error = sysctlbyname("hw.chipset.memory", &base, &len,
+ 0, 0)) < 0)
+#endif
+ FatalError("xf86MapVidMem: can't find memory\n");
+ }
+
+ return base;
+}
+
+static int
+has_bwx(void)
+{
+ static int bwx = 0;
+ size_t len = sizeof(bwx);
+ int error;
+#ifdef __OpenBSD__
+ int mib[3];
+
+ mib[0] = CTL_MACHDEP;
+ mib[1] = CPU_CHIPSET;
+ mib[2] = CPU_CHIPSET_BWX;
+
+ if ((error = sysctl(mib, 3, &bwx, &len, NULL, 0)) < 0)
+ return FALSE;
+ else
+ return bwx;
+#else
+ if ((error = sysctlbyname("hw.chipset.bwx", &bwx, &len, 0, 0)) < 0)
+ return FALSE;
+ else
+ return bwx;
+#endif
+}
+#else /* __NetBSD__ */
+static unsigned long hae_thresh = (1UL << 24);
+static unsigned long hae_mask = 0xf8000000UL; /* XXX - should use xf86AXP.c */
+static struct alpha_bus_window *abw;
+static int abw_count = -1;
+
+static void
+init_abw(void)
+{
+ if (abw_count < 0) {
+ abw_count = alpha_bus_getwindows(ALPHA_BUS_TYPE_PCI_MEM, &abw);
+ if (abw_count <= 0)
+ FatalError("init_abw: alpha_bus_getwindows failed\n");
+ }
+}
+
+static int
+has_bwx(void)
+{
+ if (abw_count < 0)
+ init_abw();
+
+ xf86Msg(X_INFO, "has_bwx = %d\n",
+ abw[0].abw_abst.abst_flags & ABST_BWX ? 1 : 0); /* XXXX */
+ return abw[0].abw_abst.abst_flags & ABST_BWX;
+}
+
+static unsigned long
+dense_base(void)
+{
+ if (abw_count < 0)
+ init_abw();
+
+ /* XXX check abst_flags for ABST_DENSE just to be safe? */
+ xf86Msg(X_INFO, "dense base = %#lx\n",
+ abw[0].abw_abst.abst_sys_start); /* XXXX */
+ return abw[0].abw_abst.abst_sys_start;
+}
+
+static unsigned long
+memory_base(void)
+{
+ if (abw_count < 0)
+ init_abw();
+
+ if (abw_count > 0) {
+ xf86Msg(X_INFO, "memory base = %#lx\n",
+ abw[1].abw_abst.abst_sys_start); /* XXXX */
+ return abw[1].abw_abst.abst_sys_start;
+ } else {
+ xf86Msg(X_INFO, "no memory base\n"); /* XXXX */
+ return 0;
+ }
+}
+#endif /* __NetBSD__ */
+
+#define BUS_BASE dense_base()
+#define BUS_BASE_BWX memory_base()
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+#ifdef __OpenBSD__
+#define SYSCTL_MSG "\tCheck that you have set 'machdep.allowaperture=1'\n"\
+ "\tin /etc/sysctl.conf and reboot your machine\n" \
+ "\trefer to xf86(4) for details"
+#endif
+
+static Bool useDevMem = FALSE;
+static int devMemFd = -1;
+
+#ifdef HAS_APERTURE_DRV
+#define DEV_APERTURE "/dev/xf86"
+#endif
+#define DEV_MEM "/dev/mem"
+
+static pointer mapVidMem(int, unsigned long, unsigned long, int);
+static void unmapVidMem(int, pointer, unsigned long);
+static pointer mapVidMemSparse(int, unsigned long, unsigned long, int);
+static void unmapVidMemSparse(int, pointer, unsigned long);
+
+/*
+ * Check if /dev/mem can be mmap'd. If it can't print a warning when
+ * "warn" is TRUE.
+ */
+static void
+checkDevMem(Bool warn)
+{
+ static Bool devMemChecked = FALSE;
+ int fd;
+ pointer base;
+
+ if (devMemChecked)
+ return;
+ devMemChecked = TRUE;
+
+#ifdef HAS_APERTURE_DRV
+ /* Try the aperture driver first */
+ if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) {
+ /* Try to map a page at the VGA address */
+ base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE,
+ MAP_FLAGS, fd, (off_t)0xA0000 + BUS_BASE);
+
+ if (base != MAP_FAILED) {
+ munmap((caddr_t)base, 4096);
+ devMemFd = fd;
+ useDevMem = TRUE;
+ xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n",
+ DEV_APERTURE);
+ return;
+ } else {
+ if (warn) {
+ xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n",
+ DEV_APERTURE, strerror(errno));
+ }
+ }
+ }
+#endif
+ if ((fd = open(DEV_MEM, O_RDWR)) >= 0) {
+ /* Try to map a page at the VGA address */
+ base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE,
+ MAP_FLAGS, fd, (off_t)0xA0000 + BUS_BASE);
+
+ if (base != MAP_FAILED) {
+ munmap((caddr_t)base, 4096);
+ devMemFd = fd;
+ useDevMem = TRUE;
+ return;
+ } else {
+ if (warn) {
+ xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ }
+ }
+ if (warn) {
+#ifndef HAS_APERTURE_DRV
+ xf86Msg(X_WARNING, "checkDevMem: failed to open/mmap %s (%s)\n",
+ DEV_MEM, strerror(errno));
+#else
+#ifndef __OpenBSD__
+ xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
+ "\t(%s)\n", DEV_APERTURE, DEV_MEM, strerror(errno));
+#else /* __OpenBSD__ */
+ xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
+ "\t(%s)\n%s", DEV_APERTURE, DEV_MEM, strerror(errno),
+ SYSCTL_MSG);
+#endif /* __OpenBSD__ */
+#endif
+ xf86ErrorF("\tlinear framebuffer access unavailable\n");
+ }
+ useDevMem = FALSE;
+ return;
+}
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ checkDevMem(TRUE);
+ pVidMem->linearSupported = useDevMem;
+
+ if (has_bwx()) {
+ xf86Msg(X_PROBED,"Machine type has 8/16 bit access\n");
+ pVidMem->mapMem = mapVidMem;
+ pVidMem->unmapMem = unmapVidMem;
+ } else {
+ xf86Msg(X_PROBED,"Machine needs sparse mapping\n");
+ pVidMem->mapMem = mapVidMemSparse;
+ pVidMem->unmapMem = unmapVidMemSparse;
+#ifndef __NetBSD__
+ if (axpSystem == -1)
+ axpSystem = bsdGetAXP();
+ hae_thresh = xf86AXPParams[axpSystem].hae_thresh;
+ hae_mask = xf86AXPParams[axpSystem].hae_mask;
+ sparse_size = xf86AXPParams[axpSystem].size;
+#endif /* __NetBSD__ */
+ }
+ pVidMem->initialised = TRUE;
+}
+
+static pointer
+mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ pointer base;
+
+ checkDevMem(FALSE);
+ Base = Base & ((1L<<32) - 1);
+
+ if (useDevMem)
+ {
+ if (devMemFd < 0)
+ {
+ FatalError("xf86MapVidMem: failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ base = mmap((caddr_t)0, Size,
+ (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX);
+ if (base == MAP_FAILED)
+ {
+ FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)\n",
+ "xf86MapVidMem", DEV_MEM, Size, Base,
+ strerror(errno));
+ }
+ return(base);
+ }
+
+ /* else, mmap /dev/vga */
+ if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000)
+ {
+ FatalError("%s: Address 0x%lx outside allowable range\n",
+ "xf86MapVidMem", Base);
+ }
+ base = mmap(0, Size,
+ (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_FLAGS, xf86Info.screenFd,
+ (unsigned long)Base + BUS_BASE);
+ if (base == MAP_FAILED)
+ {
+ FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
+ strerror(errno));
+ }
+ return(base);
+}
+
+static void
+unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap((caddr_t)Base, Size);
+}
+
+/*
+ * Read BIOS via mmap()ing DEV_MEM
+ */
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+ unsigned char *ptr;
+ int psize;
+ int mlen;
+
+ checkDevMem(TRUE);
+ if (devMemFd == -1) {
+ return(-1);
+ }
+
+ psize = xf86getpagesize();
+ Offset += Base & (psize - 1);
+ Base &= ~(psize - 1);
+ mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+ ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ,
+ MAP_SHARED, devMemFd, (off_t)Base+BUS_BASE);
+ if ((long)ptr == -1)
+ {
+ xf86Msg(X_WARNING,
+ "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n",
+ DEV_MEM, Len, Base, Offset, strerror(errno));
+ return(-1);
+ }
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
+ Base, ptr[0] | (ptr[1] << 8));
+#endif
+ (void)memcpy(Buf, (void *)(ptr + Offset), Len);
+ (void)munmap((caddr_t)ptr, mlen);
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)"
+ "-> %02x %02x %02x %02x...\n",
+ Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]);
+#endif
+ return(Len);
+}
+
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
+
+extern int ioperm(unsigned long from, unsigned long num, int on);
+
+Bool
+xf86EnableIO()
+{
+ if (!ioperm(0, 65536, TRUE))
+ return TRUE;
+ return FALSE;
+}
+
+void
+xf86DisableIO()
+{
+ return;
+}
+
+#endif /* __FreeBSD_kernel__ || __OpenBSD__ */
+
+#ifdef USE_ALPHA_PIO
+
+Bool
+xf86EnableIO()
+{
+ alpha_pci_io_enable(1);
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ alpha_pci_io_enable(0);
+}
+
+#endif /* USE_ALPHA_PIO */
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts()
+{
+
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+ return;
+}
+
+
+#define vuip volatile unsigned int *
+
+static unsigned long msb_set = 0;
+static pointer memSBase = 0;
+static pointer memBase = 0;
+
+extern int readDense8(pointer Base, register unsigned long Offset);
+extern int readDense16(pointer Base, register unsigned long Offset);
+extern int readDense32(pointer Base, register unsigned long Offset);
+extern void
+writeDenseNB8(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDenseNB16(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDenseNB32(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDense8(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDense16(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDense32(int Value, pointer Base, register unsigned long Offset);
+
+static int readSparse8(pointer Base, register unsigned long Offset);
+static int readSparse16(pointer Base, register unsigned long Offset);
+static int readSparse32(pointer Base, register unsigned long Offset);
+static void
+writeSparseNB8(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparseNB16(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparseNB32(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparse8(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparse16(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparse32(int Value, pointer Base, register unsigned long Offset);
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+extern int sysarch(int, void *);
+#endif
+
+struct parms {
+ u_int64_t hae;
+};
+
+#ifndef __NetBSD__
+static int
+sethae(u_int64_t hae)
+{
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#ifndef ALPHA_SETHAE
+#define ALPHA_SETHAE 0
+#endif
+ struct parms p;
+ p.hae = hae;
+ return (sysarch(ALPHA_SETHAE, (char *)&p));
+#endif
+#ifdef __OpenBSD__
+ return -1;
+#endif
+}
+#endif /* __NetBSD__ */
+
+static pointer
+mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ static Bool was_here = FALSE;
+
+ if (!was_here) {
+ was_here = TRUE;
+
+ checkDevMem(FALSE);
+
+ xf86WriteMmio8 = writeSparse8;
+ xf86WriteMmio16 = writeSparse16;
+ xf86WriteMmio32 = writeSparse32;
+ xf86WriteMmioNB8 = writeSparseNB8;
+ xf86WriteMmioNB16 = writeSparseNB16;
+ xf86WriteMmioNB32 = writeSparseNB32;
+ xf86ReadMmio8 = readSparse8;
+ xf86ReadMmio16 = readSparse16;
+ xf86ReadMmio32 = readSparse32;
+
+ memBase = mmap((caddr_t)0, 0x100000000,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED, devMemFd,
+ (off_t) BUS_BASE);
+ memSBase = mmap((caddr_t)0, 0x100000000,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED, devMemFd,
+ (off_t) BUS_BASE_BWX);
+
+ if (memSBase == MAP_FAILED || memBase == MAP_FAILED) {
+ FatalError("xf86MapVidMem: Could not mmap framebuffer (%s)\n",
+ strerror(errno));
+ }
+ }
+ return (pointer)((unsigned long)memBase + Base);
+}
+
+static void
+unmapVidMemSparse(int ScreenNum, pointer Base, unsigned long Size)
+{
+}
+
+static int
+readSparse8(pointer Base, register unsigned long Offset)
+{
+ register unsigned long result, shift;
+ register unsigned long msb;
+ mem_barrier();
+ Offset += (unsigned long)Base - (unsigned long)memBase;
+ shift = (Offset & 0x3) << 3;
+ if (Offset >= (hae_thresh)) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+#ifndef __NetBSD__
+ sethae(msb);
+#endif
+ msb_set = msb;
+ }
+ }
+ result = *(vuip) ((unsigned long)memSBase + (Offset << 5));
+ result >>= shift;
+ return 0xffUL & result;
+}
+
+static int
+readSparse16(pointer Base, register unsigned long Offset)
+{
+ register unsigned long result, shift;
+ register unsigned long msb;
+
+ mem_barrier();
+ Offset += (unsigned long)Base - (unsigned long)memBase;
+ shift = (Offset & 0x2) << 3;
+ if (Offset >= (hae_thresh)) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+#ifndef __NetBSD__
+ sethae(msb);
+#endif
+ msb_set = msb;
+ }
+ }
+ result = *(vuip)((unsigned long)memSBase+(Offset<<5)+(1<<(5-2)));
+ result >>= shift;
+ return 0xffffUL & result;
+}
+
+static int
+readSparse32(pointer Base, register unsigned long Offset)
+{
+ mem_barrier();
+ return *(vuip)((unsigned long)Base+(Offset));
+}
+
+static void
+writeSparse8(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned long msb;
+ register unsigned int b = Value & 0xffU;
+
+ write_mem_barrier();
+ Offset += (unsigned long)Base - (unsigned long)memBase;
+ if (Offset >= (hae_thresh)) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+#ifndef __NetBSD__
+ sethae(msb);
+#endif
+ msb_set = msb;
+ }
+ }
+ *(vuip) ((unsigned long)memSBase + (Offset << 5)) = b * 0x01010101;
+}
+
+static void
+writeSparse16(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned long msb;
+ register unsigned int w = Value & 0xffffU;
+
+ write_mem_barrier();
+ Offset += (unsigned long)Base - (unsigned long)memBase;
+ if (Offset >= (hae_thresh)) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+#ifndef __NetBSD__
+ sethae(msb);
+#endif
+ msb_set = msb;
+ }
+ }
+ *(vuip)((unsigned long)memSBase+(Offset<<5)+(1<<(5-2))) =
+ w * 0x00010001;
+
+}
+
+static void
+writeSparse32(int Value, pointer Base, register unsigned long Offset)
+{
+ write_mem_barrier();
+ *(vuip)((unsigned long)Base + (Offset)) = Value;
+ return;
+}
+
+static void
+writeSparseNB8(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned long msb;
+ register unsigned int b = Value & 0xffU;
+
+ Offset += (unsigned long)Base - (unsigned long)memBase;
+ if (Offset >= (hae_thresh)) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+#ifndef __NetBSD__
+ sethae(msb);
+#endif
+ msb_set = msb;
+ }
+ }
+ *(vuip) ((unsigned long)memSBase + (Offset << 5)) = b * 0x01010101;
+}
+
+static void
+writeSparseNB16(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned long msb;
+ register unsigned int w = Value & 0xffffU;
+
+ Offset += (unsigned long)Base - (unsigned long)memBase;
+ if (Offset >= (hae_thresh)) {
+ msb = Offset & hae_mask ;
+ Offset -= msb;
+ if (msb_set != msb) {
+#ifndef __NetBSD__
+ sethae(msb);
+#endif
+ msb_set = msb;
+ }
+ }
+ *(vuip)((unsigned long)memSBase+(Offset<<5)+(1<<(5-2))) =
+ w * 0x00010001;
+}
+
+static void
+writeSparseNB32(int Value, pointer Base, register unsigned long Offset)
+{
+ *(vuip)((unsigned long)Base + (Offset)) = Value;
+ return;
+}
+
+void (*xf86WriteMmio8)(int Value, pointer Base, unsigned long Offset)
+ = writeDense8;
+void (*xf86WriteMmio16)(int Value, pointer Base, unsigned long Offset)
+ = writeDense16;
+void (*xf86WriteMmio32)(int Value, pointer Base, unsigned long Offset)
+ = writeDense32;
+void (*xf86WriteMmioNB8)(int Value, pointer Base, unsigned long Offset)
+ = writeDenseNB8;
+void (*xf86WriteMmioNB16)(int Value, pointer Base, unsigned long Offset)
+ = writeDenseNB16;
+void (*xf86WriteMmioNB32)(int Value, pointer Base, unsigned long Offset)
+ = writeDenseNB32;
+int (*xf86ReadMmio8)(pointer Base, unsigned long Offset)
+ = readDense8;
+int (*xf86ReadMmio16)(pointer Base, unsigned long Offset)
+ = readDense16;
+int (*xf86ReadMmio32)(pointer Base, unsigned long Offset)
+ = readDense32;
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c
new file mode 100644
index 000000000..98fb8f993
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c
@@ -0,0 +1,690 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c,v 1.1tsi Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+ * The ARM32 code here carries the following copyright:
+ *
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ * This software is furnished under license and may be used and copied only in
+ * accordance with the following terms and conditions. Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * this software in source and/or binary form. No title or ownership is
+ * transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and retain
+ * this copyright notice and list of conditions as they appear in the
+ * source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of Digital
+ * Equipment Corporation. Neither the "Digital Equipment Corporation"
+ * name nor any trademark or logo of Digital Equipment Corporation may be
+ * used to endorse or promote products derived from this software without
+ * the prior written permission of Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied warranties,
+ * including but not limited to, any implied warranties of merchantability,
+ * fitness for a particular purpose, or non-infringement are disclaimed.
+ * In no event shall DIGITAL be liable for any damages whatsoever, and in
+ * particular, DIGITAL shall not be liable for special, indirect,
+ * consequential, or incidental damages or damages for lost profits, loss
+ * of revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise, even
+ * if advised of the possibility of such damage.
+ *
+ */
+
+/* $XConsortium: bsd_video.c /main/10 1996/10/25 11:37:57 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#ifdef __arm32__
+#include "machine/devmap.h"
+struct memAccess
+{
+ int ioctl;
+ struct map_info memInfo;
+ pointer regionVirtBase;
+ Bool Checked;
+ Bool OK;
+};
+
+static pointer xf86MapInfoMap();
+static void xf86MapInfoUnmap();
+static struct memAccess *checkMapInfo();
+extern int vgaPhysLinearBase;
+
+/* A memAccess structure is needed for each possible region */
+struct memAccess vgaMemInfo = { CONSOLE_GET_MEM_INFO, NULL, NULL,
+ FALSE, FALSE };
+struct memAccess linearMemInfo = { CONSOLE_GET_LINEAR_INFO, NULL, NULL,
+ FALSE, FALSE };
+struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL,
+ FALSE, FALSE };
+#endif /* __arm32__ */
+
+#if defined(__NetBSD__) && !defined(MAP_FILE)
+#define MAP_FLAGS MAP_SHARED
+#else
+#define MAP_FLAGS (MAP_FILE | MAP_SHARED)
+#endif
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((caddr_t)-1)
+#endif
+
+
+#define BUS_BASE 0L
+#define BUS_BASE_BWX 0L
+
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+static Bool useDevMem = FALSE;
+static int devMemFd = -1;
+
+#define DEV_MEM "/dev/mem"
+
+static pointer mapVidMem(int, unsigned long, unsigned long, int);
+static void unmapVidMem(int, pointer, unsigned long);
+
+/*
+ * Check if /dev/mem can be mmap'd. If it can't print a warning when
+ * "warn" is TRUE.
+ */
+static void
+checkDevMem(Bool warn)
+{
+ static Bool devMemChecked = FALSE;
+ int fd;
+ pointer base;
+
+ if (devMemChecked)
+ return;
+ devMemChecked = TRUE;
+
+ if ((fd = open(DEV_MEM, O_RDWR)) >= 0)
+ {
+ /* Try to map a page at the VGA address */
+ base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE,
+ MAP_FLAGS, fd, (off_t)0xA0000 + BUS_BASE);
+
+ if (base != MAP_FAILED)
+ {
+ munmap((caddr_t)base, 4096);
+ devMemFd = fd;
+ useDevMem = TRUE;
+ return;
+ } else {
+ /* This should not happen */
+ if (warn)
+ {
+ xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ useDevMem = FALSE;
+ return;
+ }
+ }
+ if (warn)
+ {
+ xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ useDevMem = FALSE;
+ return;
+}
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+
+ checkDevMem(TRUE);
+ pVidMem->linearSupported = useDevMem;
+ pVidMem->mapMem = armMapVidMem;
+ pVidMem->unmapVidMem = armUnmapVidMem;
+
+ pVidMem->initialised = TRUE;
+}
+
+static pointer
+mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ pointer base;
+
+ checkDevMem(FALSE);
+
+ if (useDevMem)
+ {
+ if (devMemFd < 0)
+ {
+ FatalError("xf86MapVidMem: failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ base = mmap((caddr_t)0, Size,
+ (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX);
+ if (base == MAP_FAILED)
+ {
+ FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n",
+ "xf86MapVidMem", DEV_MEM, Size, Base,
+ strerror(errno));
+ }
+ return(base);
+ }
+
+ /* else, mmap /dev/vga */
+ if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000)
+ {
+ FatalError("%s: Address 0x%x outside allowable range\n",
+ "xf86MapVidMem", Base);
+ }
+ base = mmap(0, Size,
+ (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_FLAGS, xf86Info.screenFd,
+ (unsigned long)Base - 0xA0000);
+ if (base == MAP_FAILED)
+ {
+ FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
+ strerror(errno));
+ }
+ return(base);
+}
+
+static void
+unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap((caddr_t)Base, Size);
+}
+
+/*
+ * Read BIOS via mmap()ing DEV_MEM
+ */
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+ unsigned char *ptr;
+ int psize;
+ int mlen;
+
+ checkDevMem(TRUE);
+ if (devMemFd == -1) {
+ return(-1);
+ }
+
+ psize = xf86getpagesize();
+ Offset += Base & (psize - 1);
+ Base &= ~(psize - 1);
+ mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+ ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ,
+ MAP_SHARED, devMemFd, (off_t)Base+BUS_BASE);
+ if ((long)ptr == -1)
+ {
+ xf86Msg(X_WARNING,
+ "xf86ReadBIOS: %s mmap[s=%x,a=%x,o=%x] failed (%s)\n",
+ DEV_MEM, Len, Base, Offset, strerror(errno));
+ return(-1);
+ }
+#ifdef DEBUG
+ ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
+ Base, ptr[0] | (ptr[1] << 8));
+#endif
+ (void)memcpy(Buf, (void *)(ptr + Offset), Len);
+ (void)munmap((caddr_t)ptr, mlen);
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)"
+ "-> %02x %02x %02x %02x...\n",
+ Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]);
+#endif
+ return(Len);
+}
+
+
+/* XXX This needs to be updated for the ND */
+
+/*
+** Find out whether the console driver provides memory mapping information
+** for the specified region and return the map_info pointer. Print a warning if required.
+*/
+static struct memAccess *
+checkMapInfo(Bool warn, int Region)
+{
+ struct memAccess *memAccP;
+
+ switch (Region)
+ {
+ case VGA_REGION:
+ memAccP = &vgaMemInfo;
+ break;
+
+ case LINEAR_REGION:
+ memAccP = &linearMemInfo;
+ break;
+
+ case MMIO_REGION:
+ memAccP = &ioMemInfo;
+ break;
+
+ default:
+ return NULL;
+ break;
+ }
+
+ if(!memAccP->Checked)
+ {
+ if(ioctl(xf86Info.screenFd, memAccP->ioctl, &(memAccP->memInfo)) == -1)
+ {
+ if(warn)
+ {
+ xf86Msg(X_WARNING,
+ "checkMapInfo: failed to get map info for region %d\n\t(%s)\n",
+ Region, strerror(errno));
+ }
+ }
+ else
+ {
+ if(memAccP->memInfo.u.map_info_mmap.map_offset
+ != MAP_INFO_UNKNOWN)
+ memAccP->OK = TRUE;
+ }
+ memAccP->Checked = TRUE;
+ }
+ if (memAccP->OK)
+ {
+ return memAccP;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+static pointer
+xf86MapInfoMap(struct memAccess *memInfoP, pointer Base, unsigned long Size)
+{
+ struct map_info *mapInfoP = &(memInfoP->memInfo);
+
+ if (mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN)
+ {
+ Size = (unsigned long)Base + Size;
+ }
+ else
+ {
+ Size = mapInfoP->u.map_info_mmap.map_size;
+ }
+
+ switch(mapInfoP->method)
+ {
+ case MAP_MMAP:
+ /* Need to remap if size is unknown because we may not have
+ mapped the whole region initially */
+ if(memInfoP->regionVirtBase == NULL ||
+ mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN)
+ {
+ if((memInfoP->regionVirtBase =
+ mmap((caddr_t)0,
+ Size,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ xf86Info.screenFd,
+ (unsigned long)mapInfoP->u.map_info_mmap.map_offset))
+ == (pointer)-1)
+ {
+ FatalError("xf86MapInfoMap: Failed to map memory at 0x%x\n\t%s\n",
+ mapInfoP->u.map_info_mmap.map_offset, strerror(errno));
+ }
+ if(mapInfoP->u.map_info_mmap.internal_offset > 0)
+ memInfoP->regionVirtBase +=
+ mapInfoP->u.map_info_mmap.internal_offset;
+ }
+ break;
+
+ default:
+ FatalError("xf86MapInfoMap: Unsuported mapping method\n");
+ break;
+ }
+
+ return (pointer)((int)memInfoP->regionVirtBase + (int)Base);
+}
+
+static void
+xf86MapInfoUnmap(struct memAccess *memInfoP, unsigned long Size)
+{
+ struct map_info *mapInfoP = &(memInfoP->memInfo);
+
+ switch(mapInfoP->method)
+ {
+ case MAP_MMAP:
+ if(memInfoP->regionVirtBase != NULL)
+ {
+ if(mapInfoP->u.map_info_mmap.map_size != MAP_INFO_UNKNOWN)
+ Size = mapInfoP->u.map_info_mmap.map_size;
+ munmap((caddr_t)memInfoP->regionVirtBase, Size);
+ memInfoP->regionVirtBase = NULL;
+ }
+ break;
+ default:
+ FatalError("xf86MapInfoMap: Unsuported mapping method\n");
+ break;
+ }
+}
+
+static pointer
+armMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ struct memAccess *memInfoP;
+
+ if((memInfoP = checkMapInfo(FALSE, Region)) != NULL)
+ {
+ /*
+ ** xf86 passes in a physical address offset from the start
+ ** of physical memory, but xf86MapInfoMap expects an
+ ** offset from the start of the specified region - it gets
+ ** the physical address of the region from the display driver.
+ */
+ switch(Region)
+ {
+ case LINEAR_REGION:
+ if (vgaPhysLinearBase)
+ {
+ Base -= vgaPhysLinearBase;
+ }
+ break;
+ case VGA_REGION:
+ Base -= 0xA0000;
+ break;
+ }
+
+ base = xf86MapInfoMap(memInfoP, Base, Size);
+ return (base);
+ }
+ return mapVidMem(ScreenNum, Base, Size, flags);
+}
+
+static void
+armUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ struct memAccess *memInfoP;
+
+ if((memInfoP = checkMapInfo(FALSE, Region)) != NULL)
+ {
+ xf86MapInfoUnmap(memInfoP, Base, Size);
+ }
+ unmapVidMem(ScreenNum, Base, Size);
+}
+
+#ifdef USE_DEV_IO
+static int IoFd = -1;
+
+Bool
+xf86EnableIO()
+{
+ if (IoFd >= 0)
+ return TRUE;
+
+ if ((IoFd = open("/dev/io", O_RDWR)) == -1)
+ {
+ xf86Msg(X_WARNING,"xf86EnableIO: "
+ "Failed to open /dev/io for extended I/O\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ if (IoFd < 0)
+ return;
+
+ close(IoFd);
+ IoFd = -1;
+ return;
+}
+
+#endif
+
+#if defined(USE_ARC_MMAP) || defined(__arm32__)
+
+Bool
+xf86EnableIO()
+{
+ int fd;
+ pointer base;
+
+ if (ExtendedEnabled)
+ return TRUE;
+
+ if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) {
+ /* Try to map a page at the pccons I/O space */
+ base = (pointer)mmap((caddr_t)0, 65536, PROT_READ | PROT_WRITE,
+ MAP_FLAGS, fd, (off_t)0x0000);
+
+ if (base != (pointer)-1) {
+ IOPortBase = base;
+ }
+ else {
+ xf86Msg(X_WARNING,"EnableIO: failed to mmap %s (%s)\n",
+ "/dev/ttyC0", strerror(errno));
+ return FALSE;
+ }
+ }
+ else {
+ xf86Msg("EnableIO: failed to open %s (%s)\n",
+ "/dev/ttyC0", strerror(errno));
+ return FALSE;
+ }
+
+ ExtendedEnabled = TRUE;
+
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ return;
+}
+
+#endif /* USE_ARC_MMAP */
+
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts()
+{
+
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+
+ return;
+}
+
+
+
+#if 0
+/*
+ * XXX This is here for reference. It needs to be handled differently for the
+ * ND.
+ */
+#if defined(USE_ARC_MMAP) || defined(__arm32__)
+
+#ifdef USE_ARM32_MMAP
+#define DEV_MEM_IOBASE 0x43000000
+#endif
+
+static Bool ScreenEnabled[MAXSCREENS];
+static Bool ExtendedEnabled = FALSE;
+static Bool InitDone = FALSE;
+
+Bool
+xf86EnableIOPorts(ScreenNum)
+int ScreenNum;
+{
+ int i;
+ int fd;
+ pointer base;
+
+#ifdef __arm32__
+ struct memAccess *memInfoP;
+ int *Size;
+#endif
+
+ ScreenEnabled[ScreenNum] = TRUE;
+
+ if (ExtendedEnabled)
+ return TRUE;
+
+#ifdef USE_ARC_MMAP
+ if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) {
+ /* Try to map a page at the pccons I/O space */
+ base = (pointer)mmap((caddr_t)0, 65536, PROT_READ | PROT_WRITE,
+ MAP_FLAGS, fd, (off_t)0x0000);
+
+ if (base != (pointer)-1) {
+ IOPortBase = base;
+ }
+ else {
+ xf86Msg(X_ERROR,
+ "EnableIOPorts: failed to mmap %s (%s)\n",
+ "/dev/ttyC0", strerror(errno));
+ }
+ }
+ else {
+ xf86Msg(X_ERROR, "EnableIOPorts: failed to open %s (%s)\n",
+ "/dev/ttyC0", strerror(errno));
+ }
+#endif
+
+#ifdef __arm32__
+ IOPortBase = (unsigned int)-1;
+
+ if((memInfoP = checkMapInfo(TRUE, MMIO_REGION)) != NULL)
+ {
+ /*
+ * xf86MapInfoMap maps an offset from the start of video IO
+ * space (e.g. 0x3B0), but IOPortBase is expected to map to
+ * physical address 0x000, so subtract the start of video I/O
+ * space from the result. This is safe for now becase we
+ * actually mmap the start of the page, then the start of video
+ * I/O space is added as an internal offset.
+ */
+ IOPortBase = (unsigned int)xf86MapInfoMap(memInfoP,
+ (caddr_t)0x0, 0L)
+ - memInfoP->memInfo.u.map_info_mmap.internal_offset;
+ ExtendedEnabled = TRUE;
+ return TRUE;
+ }
+#ifdef USE_ARM32_MMAP
+ checkDevMem(TRUE);
+
+ if (devMemFd >= 0 && useDevMem)
+ {
+ base = (pointer)mmap((caddr_t)0, 0x400, PROT_READ | PROT_WRITE,
+ MAP_FLAGS, devMemFd, (off_t)DEV_MEM_IOBASE);
+
+ if (base != (pointer)-1)
+ IOPortBase = (unsigned int)base;
+ }
+
+ if (IOPortBase == (unsigned int)-1)
+ {
+ xf86Msg(X_WARNING,"xf86EnableIOPorts: failed to open mem device or map IO base. \n\
+Make sure you have the Aperture Driver installed, or a kernel built with the INSECURE option\n");
+ return FALSE;
+ }
+#else
+ /* We don't have the IOBASE, so we can't map the address */
+ xf86Msg(X_WARNING,"xf86EnableIOPorts: failed to open mem device or map IO base. \n\
+Try building the server with USE_ARM32_MMAP defined\n");
+ return FALSE;
+#endif
+#endif
+
+ ExtendedEnabled = TRUE;
+
+ return TRUE;
+}
+
+void
+xf86DisableIOPorts(ScreenNum)
+int ScreenNum;
+{
+ int i;
+#ifdef __arm32__
+ struct memAccess *memInfoP;
+#endif
+
+ ScreenEnabled[ScreenNum] = FALSE;
+
+#ifdef __arm32__
+ if((memInfoP = checkMapInfo(FALSE, MMIO_REGION)) != NULL)
+ {
+ xf86MapInfoUnmap(memInfoP, 0);
+ }
+#endif
+
+#ifdef USE_ARM32_MMAP
+ if (!ExtendedEnabled)
+ return;
+
+ for (i = 0; i < MAXSCREENS; i++)
+ if (ScreenEnabled[i])
+ return;
+
+ munmap((caddr_t)IOPortBase, 0x400);
+ IOPortBase = (unsigned int)-1;
+ ExtendedEnabled = FALSE;
+#endif
+
+ return;
+}
+
+#endif /* USE_ARC_MMAP || USE_ARM32_MMAP */
+#endif
+
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsdResource.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsdResource.c
new file mode 100644
index 000000000..d38230a83
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsdResource.c
@@ -0,0 +1,194 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsdResource.c,v 1.6 2001/02/16 14:45:10 tsi Exp $ */
+
+/* Resource information code */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Privstr.h"
+#include "xf86Pci.h"
+#include "xf86Resources.h"
+#define NEED_OS_RAC_PROTOS
+#include "xf86_OSlib.h"
+
+/* Avoid Imakefile changes */
+#include "bus/Pci.h"
+
+resRange PciAvoid[] = {_PCI_AVOID_PC_STYLE, _END};
+
+#ifdef INCLUDE_XF86_NO_DOMAIN
+
+#if defined(__alpha__) || defined(__sparc64__) || defined(__amd64__)
+
+resPtr
+xf86BusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+resPtr
+xf86PciBusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ /*
+ * Only allow the upper half of the pci memory range to be used
+ * for allocation. The lower half includes magic regions for DMA.
+ * XXX this is not right for XP1000's and similar where we use the
+ * region 0x40000000-0xbfffffff for DMA but this only matters if
+ * the bios screws up the pci region mappings.
+ */
+ RANGE(range, 0x80000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#ifdef INCLUDE_UNUSED
+
+resPtr
+xf86IsaBusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#endif /* INCLUDE_UNUSED */
+
+resPtr
+xf86AccResFromOS(resPtr ret)
+{
+ resRange range;
+
+ /*
+ * Fallback is to claim the following areas:
+ *
+ * 0x000c0000 - 0x000effff location of VGA and other extensions ROMS
+ */
+
+ RANGE(range, 0x000c0000, 0x000effff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /*
+ * Fallback would be to claim well known ports in the 0x0 - 0x3ff range
+ * along with their sparse I/O aliases, but that's too imprecise. Instead
+ * claim a bare minimum here.
+ */
+ RANGE(range, 0x00000000, 0x000000ff, ResExcIoBlock); /* For mainboard */
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /*
+ * At minimum, the top and bottom resources must be claimed, so that
+ * resources that are (or appear to be) unallocated can be relocated.
+ */
+ RANGE(range, 0x00000000, 0x00000000, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xffffffff, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+/* RANGE(range, 0x00000000, 0x00000000, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1); */
+ RANGE(range, 0xffffffff, 0xffffffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /* XXX add others */
+ return ret;
+}
+
+#elif defined(__powerpc__)
+
+resPtr
+xf86BusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+resPtr
+xf86PciBusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#ifdef INCLUDE_UNUSED
+
+resPtr
+xf86IsaBusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#endif /* INCLUDE_UNUSED */
+
+resPtr
+xf86AccResFromOS(resPtr ret)
+{
+ resRange range;
+
+ /*
+ * At minimum, the top and bottom resources must be claimed, so that
+ * resources that are (or appear to be) unallocated can be relocated.
+ */
+ RANGE(range, 0x00000000, 0x00000000, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xffffffff, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x00000000, 0x00000000, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x0000ffff, 0x0000ffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ return ret;
+}
+
+#else
+
+#error : Put your platform dependent code here!!
+
+#endif
+
+#endif /* INCLUDE_XF86_NO_DOMAIN */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_KbdMap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_KbdMap.c
new file mode 100644
index 000000000..d225c1f38
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_KbdMap.c
@@ -0,0 +1,1087 @@
+/* $XFree86$ */
+
+/*
+ * Slightly modified xf86KbdBSD.c which is
+ *
+ * Derived from xf86Kbd.c by S_ren Schmidt (sos@login.dkuug.dk)
+ * which is Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ * and from xf86KbdCODrv.c by Holger Veit
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+#include "atKeynames.h"
+#include "xf86Keymap.h"
+#include "bsd_kbd.h"
+
+#if (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)) && defined(GIO_KEYMAP)
+#define KD_GET_ENTRY(i,n) \
+ eascii_to_x[((keymap.key[i].spcl << (n+1)) & 0x100) + keymap.key[i].map[n]]
+
+static unsigned char remap[NUM_KEYCODES] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0x69, 0x65, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+
+/* This table assumes the ibm code page 437 coding for characters
+ * > 0x80. They are returned in this form by PCVT */
+static KeySym eascii_to_x[512] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex,
+ XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla,
+ XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis,
+ XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring,
+ XK_Eacute, XK_ae, XK_AE, XK_ocircumflex,
+ XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave,
+ XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent,
+ XK_sterling, XK_yen, XK_paragraph, XK_section,
+ XK_aacute, XK_iacute, XK_oacute, XK_uacute,
+ XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine,
+ XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf,
+ XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi,
+ XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau,
+ XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta,
+ XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection,
+ XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal,
+ XK_topintegral, XK_botintegral, XK_division, XK_similarequal,
+ XK_degree, NoSymbol, NoSymbol, XK_radical,
+ XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol,
+
+ /*
+ * special marked entries (256 + x)
+ */
+
+ /* This has been checked against what syscons actually does */
+ NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R,
+ XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L,
+ XK_ISO_Left_Tab,XK_Control_L, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_F1,
+ XK_F2, XK_F3, XK_F4, XK_F5,
+ XK_F6, XK_F7, XK_F8, XK_F9,
+ XK_F10, XK_F11, XK_F12, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Control_R, XK_Alt_R, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol
+};
+
+#ifdef __OpenBSD__
+/* don't mark AltR and CtrlR for remapping, since they
+ * cannot be remapped by pccons */
+static unsigned char pccons_remap[128] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+
+/* This table assumes an iso8859_1 encoding for the characters
+ * > 80, as returned by pccons */
+static KeySym latin1_to_x[256] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_nobreakspace,XK_exclamdown, XK_cent, XK_sterling,
+ XK_currency, XK_yen, XK_brokenbar, XK_section,
+ XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft,
+ XK_notsign, XK_hyphen, XK_registered, XK_macron,
+ XK_degree, XK_plusminus, XK_twosuperior, XK_threesuperior,
+ XK_acute, XK_mu, XK_paragraph, XK_periodcentered,
+ XK_cedilla, XK_onesuperior, XK_masculine, XK_guillemotright,
+ XK_onequarter, XK_onehalf, XK_threequarters,XK_questiondown,
+ XK_Agrave, XK_Aacute, XK_Acircumflex, XK_Atilde,
+ XK_Adiaeresis, XK_Aring, XK_AE, XK_Ccedilla,
+ XK_Egrave, XK_Eacute, XK_Ecircumflex, XK_Ediaeresis,
+ XK_Igrave, XK_Iacute, XK_Icircumflex, XK_Idiaeresis,
+ XK_ETH, XK_Ntilde, XK_Ograve, XK_Oacute,
+ XK_Ocircumflex, XK_Otilde, XK_Odiaeresis, XK_multiply,
+ XK_Ooblique, XK_Ugrave, XK_Uacute, XK_Ucircumflex,
+ XK_Udiaeresis, XK_Yacute, XK_THORN, XK_ssharp,
+ XK_agrave, XK_aacute, XK_acircumflex, XK_atilde,
+ XK_adiaeresis, XK_aring, XK_ae, XK_ccedilla,
+ XK_egrave, XK_eacute, XK_ecircumflex, XK_ediaeresis,
+ XK_igrave, XK_iacute, XK_icircumflex, XK_idiaeresis,
+ XK_eth, XK_ntilde, XK_ograve, XK_oacute,
+ XK_ocircumflex, XK_otilde, XK_odiaeresis, XK_division,
+ XK_oslash, XK_ugrave, XK_uacute, XK_ucircumflex,
+ XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis
+ };
+#endif
+
+#ifdef SYSCONS_SUPPORT
+static
+unsigned char sysconsCODEMap[] = {
+ KEY_KP_Enter, KEY_RCtrl, KEY_KP_Divide, KEY_Print,
+ KEY_AltLang, KEY_KP_7, KEY_KP_8, KEY_KP_9,
+ KEY_KP_4, KEY_KP_6, KEY_KP_1, KEY_KP_2,
+ KEY_KP_3, KEY_KP_0, KEY_KP_Decimal, KEY_Pause,
+ KEY_LMeta, KEY_RMeta, KEY_Menu, KEY_Break
+};
+static
+TransMapRec sysconsCODE = {
+ 0x59,
+ 0x6d,
+ sysconsCODEMap
+};
+#endif
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+
+#ifdef WSCONS_SUPPORT
+
+static CARD8 wsUsbMap[] = {
+ /* 0 */ KEY_NOTUSED,
+ /* 1 */ KEY_NOTUSED,
+ /* 2 */ KEY_NOTUSED,
+ /* 3 */ KEY_NOTUSED,
+ /* 4 */ KEY_A,
+ /* 5 */ KEY_B,
+ /* 6 */ KEY_C,
+ /* 7 */ KEY_D,
+ /* 8 */ KEY_E,
+ /* 9 */ KEY_F,
+ /* 10 */ KEY_G,
+ /* 11 */ KEY_H,
+ /* 12 */ KEY_I,
+ /* 13 */ KEY_J,
+ /* 14 */ KEY_K,
+ /* 15 */ KEY_L,
+ /* 16 */ KEY_M,
+ /* 17 */ KEY_N,
+ /* 18 */ KEY_O,
+ /* 19 */ KEY_P,
+ /* 20 */ KEY_Q,
+ /* 21 */ KEY_R,
+ /* 22 */ KEY_S,
+ /* 23 */ KEY_T,
+ /* 24 */ KEY_U,
+ /* 25 */ KEY_V,
+ /* 26 */ KEY_W,
+ /* 27 */ KEY_X,
+ /* 28 */ KEY_Y,
+ /* 29 */ KEY_Z,
+ /* 30 */ KEY_1, /* 1 !*/
+ /* 31 */ KEY_2, /* 2 @ */
+ /* 32 */ KEY_3, /* 3 # */
+ /* 33 */ KEY_4, /* 4 $ */
+ /* 34 */ KEY_5, /* 5 % */
+ /* 35 */ KEY_6, /* 6 ^ */
+ /* 36 */ KEY_7, /* 7 & */
+ /* 37 */ KEY_8, /* 8 * */
+ /* 38 */ KEY_9, /* 9 ( */
+ /* 39 */ KEY_0, /* 0 ) */
+ /* 40 */ KEY_Enter, /* Return */
+ /* 41 */ KEY_Escape, /* Escape */
+ /* 42 */ KEY_BackSpace, /* Backspace Delete */
+ /* 43 */ KEY_Tab, /* Tab */
+ /* 44 */ KEY_Space, /* Space */
+ /* 45 */ KEY_Minus, /* - _ */
+ /* 46 */ KEY_Equal, /* = + */
+ /* 47 */ KEY_LBrace, /* [ { */
+ /* 48 */ KEY_RBrace, /* ] } */
+ /* 49 */ KEY_BSlash, /* \ | */
+ /* 50 */ KEY_BSlash2, /* \ _ # ~ on some keyboards */
+ /* 51 */ KEY_SemiColon, /* ; : */
+ /* 52 */ KEY_Quote, /* ' " */
+ /* 53 */ KEY_Tilde, /* ` ~ */
+ /* 54 */ KEY_Comma, /* , < */
+ /* 55 */ KEY_Period, /* . > */
+ /* 56 */ KEY_Slash, /* / ? */
+ /* 57 */ KEY_CapsLock, /* Caps Lock */
+ /* 58 */ KEY_F1, /* F1 */
+ /* 59 */ KEY_F2, /* F2 */
+ /* 60 */ KEY_F3, /* F3 */
+ /* 61 */ KEY_F4, /* F4 */
+ /* 62 */ KEY_F5, /* F5 */
+ /* 63 */ KEY_F6, /* F6 */
+ /* 64 */ KEY_F7, /* F7 */
+ /* 65 */ KEY_F8, /* F8 */
+ /* 66 */ KEY_F9, /* F9 */
+ /* 67 */ KEY_F10, /* F10 */
+ /* 68 */ KEY_F11, /* F11 */
+ /* 69 */ KEY_F12, /* F12 */
+ /* 70 */ KEY_Print, /* PrintScrn SysReq */
+ /* 71 */ KEY_ScrollLock, /* Scroll Lock */
+ /* 72 */ KEY_Pause, /* Pause Break */
+ /* 73 */ KEY_Insert, /* Insert XXX Help on some Mac Keyboards */
+ /* 74 */ KEY_Home, /* Home */
+ /* 75 */ KEY_PgUp, /* Page Up */
+ /* 76 */ KEY_Delete, /* Delete */
+ /* 77 */ KEY_End, /* End */
+ /* 78 */ KEY_PgDown, /* Page Down */
+ /* 79 */ KEY_Right, /* Right Arrow */
+ /* 80 */ KEY_Left, /* Left Arrow */
+ /* 81 */ KEY_Down, /* Down Arrow */
+ /* 82 */ KEY_Up, /* Up Arrow */
+ /* 83 */ KEY_NumLock, /* Num Lock */
+ /* 84 */ KEY_KP_Divide, /* Keypad / */
+ /* 85 */ KEY_KP_Multiply, /* Keypad * */
+ /* 86 */ KEY_KP_Minus, /* Keypad - */
+ /* 87 */ KEY_KP_Plus, /* Keypad + */
+ /* 88 */ KEY_KP_Enter, /* Keypad Enter */
+ /* 89 */ KEY_KP_1, /* Keypad 1 End */
+ /* 90 */ KEY_KP_2, /* Keypad 2 Down */
+ /* 91 */ KEY_KP_3, /* Keypad 3 Pg Down */
+ /* 92 */ KEY_KP_4, /* Keypad 4 Left */
+ /* 93 */ KEY_KP_5, /* Keypad 5 */
+ /* 94 */ KEY_KP_6, /* Keypad 6 */
+ /* 95 */ KEY_KP_7, /* Keypad 7 Home */
+ /* 96 */ KEY_KP_8, /* Keypad 8 Up */
+ /* 97 */ KEY_KP_9, /* KEypad 9 Pg Up */
+ /* 98 */ KEY_KP_0, /* Keypad 0 Ins */
+ /* 99 */ KEY_KP_Decimal, /* Keypad . Del */
+ /* 100 */ KEY_Less, /* < > on some keyboards */
+ /* 101 */ KEY_Menu, /* Menu */
+ /* 102 */ KEY_NOTUSED,
+ /* 103 */ KEY_KP_Equal, /* Keypad = on Mac keyboards */
+ /* 104 */ KEY_NOTUSED,
+ /* 105 */ KEY_NOTUSED,
+ /* 106 */ KEY_NOTUSED,
+ /* 107 */ KEY_NOTUSED,
+ /* 108 */ KEY_NOTUSED,
+ /* 109 */ KEY_NOTUSED,
+ /* 110 */ KEY_NOTUSED,
+ /* 111 */ KEY_NOTUSED,
+ /* 112 */ KEY_NOTUSED,
+ /* 113 */ KEY_NOTUSED,
+ /* 114 */ KEY_NOTUSED,
+ /* 115 */ KEY_NOTUSED,
+ /* 116 */ KEY_NOTUSED,
+ /* 117 */ KEY_NOTUSED,
+ /* 118 */ KEY_NOTUSED,
+ /* 119 */ KEY_NOTUSED,
+ /* 120 */ KEY_NOTUSED,
+ /* 121 */ KEY_NOTUSED,
+ /* 122 */ KEY_NOTUSED,
+ /* 123 */ KEY_NOTUSED,
+ /* 124 */ KEY_NOTUSED,
+ /* 125 */ KEY_NOTUSED,
+ /* 126 */ KEY_NOTUSED,
+ /* 127 */ KEY_NOTUSED,
+ /* 128 */ KEY_NOTUSED,
+ /* 129 */ KEY_NOTUSED,
+ /* 130 */ KEY_NOTUSED,
+ /* 131 */ KEY_NOTUSED,
+ /* 132 */ KEY_NOTUSED,
+ /* 133 */ KEY_NOTUSED,
+ /* 134 */ KEY_NOTUSED,
+ /* 135 */ KEY_NOTUSED,
+ /* 136 */ KEY_NOTUSED,
+ /* 137 */ KEY_NOTUSED,
+ /* 138 */ KEY_NOTUSED,
+ /* 139 */ KEY_NOTUSED,
+ /* 140 */ KEY_NOTUSED,
+ /* 141 */ KEY_NOTUSED,
+ /* 142 */ KEY_NOTUSED,
+ /* 143 */ KEY_NOTUSED,
+ /* 144 */ KEY_NOTUSED,
+ /* 145 */ KEY_NOTUSED,
+ /* 146 */ KEY_NOTUSED,
+ /* 147 */ KEY_NOTUSED,
+ /* 148 */ KEY_NOTUSED,
+ /* 149 */ KEY_NOTUSED,
+ /* 150 */ KEY_NOTUSED,
+ /* 151 */ KEY_NOTUSED,
+ /* 152 */ KEY_NOTUSED,
+ /* 153 */ KEY_NOTUSED,
+ /* 154 */ KEY_NOTUSED,
+ /* 155 */ KEY_NOTUSED,
+ /* 156 */ KEY_NOTUSED,
+ /* 157 */ KEY_NOTUSED,
+ /* 158 */ KEY_NOTUSED,
+ /* 159 */ KEY_NOTUSED,
+ /* 160 */ KEY_NOTUSED,
+ /* 161 */ KEY_NOTUSED,
+ /* 162 */ KEY_NOTUSED,
+ /* 163 */ KEY_NOTUSED,
+ /* 164 */ KEY_NOTUSED,
+ /* 165 */ KEY_NOTUSED,
+ /* 166 */ KEY_NOTUSED,
+ /* 167 */ KEY_NOTUSED,
+ /* 168 */ KEY_NOTUSED,
+ /* 169 */ KEY_NOTUSED,
+ /* 170 */ KEY_NOTUSED,
+ /* 171 */ KEY_NOTUSED,
+ /* 172 */ KEY_NOTUSED,
+ /* 173 */ KEY_NOTUSED,
+ /* 174 */ KEY_NOTUSED,
+ /* 175 */ KEY_NOTUSED,
+ /* 176 */ KEY_NOTUSED,
+ /* 177 */ KEY_NOTUSED,
+ /* 178 */ KEY_NOTUSED,
+ /* 179 */ KEY_NOTUSED,
+ /* 180 */ KEY_NOTUSED,
+ /* 181 */ KEY_NOTUSED,
+ /* 182 */ KEY_NOTUSED,
+ /* 183 */ KEY_NOTUSED,
+ /* 184 */ KEY_NOTUSED,
+ /* 185 */ KEY_NOTUSED,
+ /* 186 */ KEY_NOTUSED,
+ /* 187 */ KEY_NOTUSED,
+ /* 188 */ KEY_NOTUSED,
+ /* 189 */ KEY_NOTUSED,
+ /* 190 */ KEY_NOTUSED,
+ /* 191 */ KEY_NOTUSED,
+ /* 192 */ KEY_NOTUSED,
+ /* 193 */ KEY_NOTUSED,
+ /* 194 */ KEY_NOTUSED,
+ /* 195 */ KEY_NOTUSED,
+ /* 196 */ KEY_NOTUSED,
+ /* 197 */ KEY_NOTUSED,
+ /* 198 */ KEY_NOTUSED,
+ /* 199 */ KEY_NOTUSED,
+ /* 200 */ KEY_NOTUSED,
+ /* 201 */ KEY_NOTUSED,
+ /* 202 */ KEY_NOTUSED,
+ /* 203 */ KEY_NOTUSED,
+ /* 204 */ KEY_NOTUSED,
+ /* 205 */ KEY_NOTUSED,
+ /* 206 */ KEY_NOTUSED,
+ /* 207 */ KEY_NOTUSED,
+ /* 208 */ KEY_NOTUSED,
+ /* 209 */ KEY_NOTUSED,
+ /* 210 */ KEY_NOTUSED,
+ /* 211 */ KEY_NOTUSED,
+ /* 212 */ KEY_NOTUSED,
+ /* 213 */ KEY_NOTUSED,
+ /* 214 */ KEY_NOTUSED,
+ /* 215 */ KEY_NOTUSED,
+ /* 216 */ KEY_NOTUSED,
+ /* 217 */ KEY_NOTUSED,
+ /* 218 */ KEY_NOTUSED,
+ /* 219 */ KEY_NOTUSED,
+ /* 220 */ KEY_NOTUSED,
+ /* 221 */ KEY_NOTUSED,
+ /* 222 */ KEY_NOTUSED,
+ /* 223 */ KEY_NOTUSED,
+ /* 224 */ KEY_LCtrl, /* Left Control */
+ /* 225 */ KEY_ShiftL, /* Left Shift */
+ /* 226 */ KEY_Alt, /* Left Alt */
+ /* 227 */ KEY_LMeta, /* Left Meta */
+ /* 228 */ KEY_RCtrl, /* Right Control */
+ /* 229 */ KEY_ShiftR, /* Right Shift */
+ /* 230 */ KEY_AltLang, /* Right Alt, AKA AltGr */
+ /* 231 */ KEY_LMeta, /* Right Meta XXX */
+};
+#define WS_USB_MAP_SIZE (sizeof(wsUsbMap)/sizeof(unsigned char))
+
+static
+TransMapRec wsUsb = {
+ 0,
+ WS_USB_MAP_SIZE,
+ wsUsbMap
+};
+
+/* Map for adb keyboards */
+static CARD8 wsAdbMap[] = {
+ /* 0 */ KEY_A,
+ /* 1 */ KEY_S,
+ /* 2 */ KEY_D,
+ /* 3 */ KEY_F,
+ /* 4 */ KEY_H,
+ /* 5 */ KEY_G,
+ /* 6 */ KEY_Z,
+ /* 7 */ KEY_X,
+ /* 8 */ KEY_C,
+ /* 9 */ KEY_V,
+ /* 10 */ KEY_UNKNOWN, /* @ # on french keyboards */
+ /* 11 */ KEY_B,
+ /* 12 */ KEY_Q,
+ /* 13 */ KEY_W,
+ /* 14 */ KEY_E,
+ /* 15 */ KEY_R,
+ /* 16 */ KEY_Y,
+ /* 17 */ KEY_T,
+ /* 18 */ KEY_1,
+ /* 19 */ KEY_2,
+ /* 20 */ KEY_3,
+ /* 21 */ KEY_4,
+ /* 22 */ KEY_6,
+ /* 23 */ KEY_5,
+ /* 24 */ KEY_Equal,
+ /* 25 */ KEY_9,
+ /* 26 */ KEY_7,
+ /* 27 */ KEY_Minus,
+ /* 28 */ KEY_8,
+ /* 29 */ KEY_0,
+ /* 30 */ KEY_RBrace,
+ /* 31 */ KEY_O,
+ /* 32 */ KEY_U,
+ /* 33 */ KEY_LBrace,
+ /* 34 */ KEY_I,
+ /* 35 */ KEY_P,
+ /* 36 */ KEY_Enter,
+ /* 37 */ KEY_L,
+ /* 38 */ KEY_J,
+ /* 39 */ KEY_Quote,
+ /* 40 */ KEY_K,
+ /* 41 */ KEY_SemiColon,
+ /* 42 */ KEY_BSlash,
+ /* 43 */ KEY_Comma,
+ /* 44 */ KEY_Slash,
+ /* 45 */ KEY_N,
+ /* 46 */ KEY_M,
+ /* 47 */ KEY_Period,
+ /* 48 */ KEY_Tab,
+ /* 49 */ KEY_Space,
+ /* 50 */ KEY_Tilde,
+ /* 51 */ KEY_Delete,
+ /* 52 */ KEY_AltLang,
+ /* 53 */ KEY_Escape,
+ /* 54 */ KEY_LCtrl,
+ /* 55 */ KEY_Alt,
+ /* 56 */ KEY_ShiftL,
+ /* 57 */ KEY_CapsLock,
+ /* 58 */ KEY_LMeta,
+ /* 59 */ KEY_Left,
+ /* 60 */ KEY_Right,
+ /* 61 */ KEY_Down,
+ /* 62 */ KEY_Up,
+ /* 63 */ KEY_UNKNOWN, /* Fn */
+ /* 64 */ KEY_NOTUSED,
+ /* 65 */ KEY_KP_Decimal,
+ /* 66 */ KEY_NOTUSED,
+ /* 67 */ KEY_KP_Multiply,
+ /* 68 */ KEY_NOTUSED,
+ /* 69 */ KEY_KP_Plus,
+ /* 70 */ KEY_NOTUSED,
+ /* 71 */ KEY_UNKNOWN, /* Clear */
+ /* 72 */ KEY_NOTUSED,
+ /* 73 */ KEY_NOTUSED,
+ /* 74 */ KEY_NOTUSED,
+ /* 75 */ KEY_KP_Divide,
+ /* 76 */ KEY_KP_Enter,
+ /* 77 */ KEY_NOTUSED,
+ /* 78 */ KEY_KP_Minus,
+ /* 79 */ KEY_NOTUSED,
+ /* 80 */ KEY_NOTUSED,
+ /* 81 */ KEY_KP_Equal, /* Keypad = */
+ /* 82 */ KEY_KP_0,
+ /* 83 */ KEY_KP_1,
+ /* 84 */ KEY_KP_2,
+ /* 85 */ KEY_KP_3,
+ /* 86 */ KEY_KP_4,
+ /* 87 */ KEY_KP_5,
+ /* 88 */ KEY_KP_6,
+ /* 89 */ KEY_KP_7,
+ /* 90 */ KEY_NOTUSED,
+ /* 91 */ KEY_KP_8,
+ /* 92 */ KEY_KP_9,
+ /* 93 */ KEY_NOTUSED,
+ /* 94 */ KEY_NOTUSED,
+ /* 95 */ KEY_UNKNOWN, /* Keypad , */
+ /* 96 */ KEY_F5,
+ /* 97 */ KEY_F6,
+ /* 98 */ KEY_F7,
+ /* 99 */ KEY_F3,
+ /* 100 */ KEY_F8,
+ /* 101 */ KEY_F9,
+ /* 102 */ KEY_NOTUSED,
+ /* 103 */ KEY_F11,
+ /* 104 */ KEY_NOTUSED,
+ /* 105 */ KEY_NOTUSED,
+ /* 106 */ KEY_KP_Enter,
+ /* 107 */ KEY_NOTUSED,
+ /* 108 */ KEY_NOTUSED,
+ /* 109 */ KEY_F10,
+ /* 110 */ KEY_NOTUSED,
+ /* 111 */ KEY_F12,
+ /* 112 */ KEY_NOTUSED,
+ /* 113 */ KEY_NOTUSED,
+ /* 114 */ KEY_NOTUSED,
+ /* 115 */ KEY_Home,
+ /* 116 */ KEY_PgUp,
+ /* 117 */ KEY_NOTUSED,
+ /* 118 */ KEY_F4,
+ /* 119 */ KEY_End,
+ /* 120 */ KEY_F2,
+ /* 121 */ KEY_PgDown,
+ /* 122 */ KEY_F1
+};
+#define WS_ADB_MAP_SIZE (sizeof(wsAdbMap)/sizeof(unsigned char))
+
+static
+TransMapRec wsAdb = {
+ 0,
+ WS_ADB_MAP_SIZE,
+ wsAdbMap
+};
+
+static CARD8 wsSunMap[] = {
+ /* 0x00 */ KEY_Help,
+ /* 0x01 */ KEY_L1, /* stop */
+ /* 0x02 */ KEY_AudioLower, /* BrightnessDown / S-VolumeDown */
+ /* 0x03 */ KEY_L2, /* again */
+ /* 0x04 */ KEY_AudioRaise, /* BridgtnessUp / S-VolumeUp */
+ /* 0x05 */ KEY_F1,
+ /* 0x06 */ KEY_F2,
+ /* 0x07 */ KEY_F10,
+ /* 0x08 */ KEY_F3,
+ /* 0x09 */ KEY_F11,
+ /* 0x0a */ KEY_F4,
+ /* 0x0b */ KEY_F12,
+ /* 0x0c */ KEY_F5,
+ /* 0x0d */ KEY_AltLang,
+ /* 0x0e */ KEY_F6,
+ /* 0x0f */ KEY_NOTUSED,
+ /* 0x10 */ KEY_F7,
+ /* 0x11 */ KEY_F8,
+ /* 0x12 */ KEY_F9,
+ /* 0x13 */ KEY_Alt,
+ /* 0x14 */ KEY_Up,
+ /* 0x15 */ KEY_Pause,
+ /* 0x16 */ KEY_Print,
+ /* 0x17 */ KEY_ScrollLock,
+ /* 0x18 */ KEY_Left,
+ /* 0x19 */ KEY_L3, /* props */
+ /* 0x1a */ KEY_L4, /* undo */
+ /* 0x1b */ KEY_Down,
+ /* 0x1c */ KEY_Right,
+ /* 0x1d */ KEY_Escape,
+ /* 0x1e */ KEY_1,
+ /* 0x1f */ KEY_2,
+ /* 0x20 */ KEY_3,
+ /* 0x21 */ KEY_4,
+ /* 0x22 */ KEY_5,
+ /* 0x23 */ KEY_6,
+ /* 0x24 */ KEY_7,
+ /* 0x25 */ KEY_8,
+ /* 0x26 */ KEY_9,
+ /* 0x27 */ KEY_0,
+ /* 0x28 */ KEY_Minus,
+ /* 0x29 */ KEY_Equal,
+ /* 0x2a */ KEY_Tilde,
+ /* 0x2b */ KEY_BackSpace,
+ /* 0x2c */ KEY_Insert,
+ /* 0x2d */ KEY_Mute, /* Audio Mute */
+ /* 0x2e */ KEY_KP_Divide,
+ /* 0x2f */ KEY_KP_Multiply,
+ /* 0x30 */ KEY_NOTUSED,
+ /* 0x31 */ KEY_L5, /* front */
+ /* 0x32 */ KEY_KP_Decimal,
+ /* 0x33 */ KEY_L6, /* copy */
+ /* 0x34 */ KEY_Home,
+ /* 0x35 */ KEY_Tab,
+ /* 0x36 */ KEY_Q,
+ /* 0x37 */ KEY_W,
+ /* 0x38 */ KEY_E,
+ /* 0x39 */ KEY_R,
+ /* 0x3a */ KEY_T,
+ /* 0x3b */ KEY_Y,
+ /* 0x3c */ KEY_U,
+ /* 0x3d */ KEY_I,
+ /* 0x3e */ KEY_O,
+ /* 0x3f */ KEY_P,
+ /* 0x40 */ KEY_LBrace,
+ /* 0x41 */ KEY_RBrace,
+ /* 0x42 */ KEY_Delete,
+ /* 0x43 */ KEY_Menu, /* compose */
+ /* 0x44 */ KEY_KP_7,
+ /* 0x45 */ KEY_KP_8,
+ /* 0x46 */ KEY_KP_9,
+ /* 0x47 */ KEY_KP_Minus,
+ /* 0x48 */ KEY_L7, /* open */
+ /* 0x49 */ KEY_L8, /* paste */
+ /* 0x4a */ KEY_End,
+ /* 0x4b */ KEY_NOTUSED,
+ /* 0x4c */ KEY_LCtrl,
+ /* 0x4d */ KEY_A,
+ /* 0x4e */ KEY_S,
+ /* 0x4f */ KEY_D,
+ /* 0x50 */ KEY_F,
+ /* 0x51 */ KEY_G,
+ /* 0x52 */ KEY_H,
+ /* 0x53 */ KEY_J,
+ /* 0x54 */ KEY_K,
+ /* 0x55 */ KEY_L,
+ /* 0x56 */ KEY_SemiColon,
+ /* 0x57 */ KEY_Quote,
+ /* 0x58 */ KEY_BSlash,
+ /* 0x59 */ KEY_Enter,
+ /* 0x5a */ KEY_KP_Enter,
+ /* 0x5b */ KEY_KP_4,
+ /* 0x5c */ KEY_KP_5,
+ /* 0x5d */ KEY_KP_6,
+ /* 0x5e */ KEY_KP_0,
+ /* 0x5f */ KEY_L9, /* find */
+ /* 0x60 */ KEY_PgUp,
+ /* 0x61 */ KEY_L10, /* cut */
+ /* 0x62 */ KEY_NumLock,
+ /* 0x63 */ KEY_ShiftL,
+ /* 0x64 */ KEY_Z,
+ /* 0x65 */ KEY_X,
+ /* 0x66 */ KEY_C,
+ /* 0x67 */ KEY_V,
+ /* 0x68 */ KEY_B,
+ /* 0x69 */ KEY_N,
+ /* 0x6a */ KEY_M,
+ /* 0x6b */ KEY_Comma,
+ /* 0x6c */ KEY_Period,
+ /* 0x6d */ KEY_Slash,
+ /* 0x6e */ KEY_ShiftR,
+ /* 0x6f */ KEY_NOTUSED, /* linefeed */
+ /* 0x70 */ KEY_KP_1,
+ /* 0x71 */ KEY_KP_2,
+ /* 0x72 */ KEY_KP_3,
+ /* 0x73 */ KEY_NOTUSED,
+ /* 0x74 */ KEY_NOTUSED,
+ /* 0x75 */ KEY_NOTUSED,
+ /* 0x76 */ KEY_NOTUSED, /* help */
+ /* 0x77 */ KEY_CapsLock,
+ /* 0x78 */ KEY_LMeta,
+ /* 0x79 */ KEY_Space,
+ /* 0x7a */ KEY_RMeta,
+ /* 0x7b */ KEY_PgDown,
+ /* 0x7c */ KEY_Less, /* < > on some keyboards */
+ /* 0x7d */ KEY_KP_Plus,
+ /* 0x7e */ KEY_NOTUSED,
+ /* 0x7f */ KEY_NOTUSED
+};
+#define WS_SUN_MAP_SIZE (sizeof(wsSunMap)/sizeof(unsigned char))
+
+static
+TransMapRec wsSun = {
+ 0,
+ WS_SUN_MAP_SIZE,
+ wsSunMap
+};
+
+#endif /* WSCONS_SUPPORT */
+
+/*ARGSUSED*/
+
+/*
+ * KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+void
+KbdGetMapping (InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ KeySym *k;
+ int i;
+
+#ifndef __bsdi__
+ switch (pKbd->consType) {
+
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+#if defined(__OpenBSD__)
+ /*
+ * on OpenBSD, the pccons keymap is programmable, too
+ */
+ {
+ pccons_keymap_t keymap[KB_NUM_KEYS];
+ if (ioctl(pInfo->fd, CONSOLE_GET_KEYMAP, &keymap) != -1) {
+ for (i = 0; i < KB_NUM_KEYS; i++)
+ if (pccons_remap[i]) {
+ k = map + (pccons_remap[i] << 2);
+ switch (keymap[i].type) {
+ case KB_ASCII:
+ /* For ASCII keys, there is only one char in the keymap */
+ k[0] = latin1_to_x[(unsigned char)keymap[i].unshift[0]];
+ k[1] = latin1_to_x[(unsigned char)keymap[i].shift[0]];
+ k[2] = latin1_to_x[(unsigned char)keymap[i].altgr[0]];
+ k[3] = latin1_to_x[(unsigned char)keymap[i].shift_altgr[0]];
+ break;
+ case KB_SCROLL:
+ k[0] = XK_Scroll_Lock;
+ goto special;
+ case KB_NUM:
+ k[0] = XK_Num_Lock;
+ goto special;
+ case KB_CAPS:
+ k[0] = XK_Caps_Lock;
+ goto special;
+ case KB_SHIFT:
+ switch (keymap[i].unshift[0]) {
+ case 1:
+ /* left shift */
+ k[0] = XK_Shift_L;
+ break;
+ case 2:
+ /* right shift */
+ k[0] = XK_Shift_R;
+ break;
+ default:
+ k[0] = NoSymbol;
+ }
+ goto special;
+ case KB_CTL:
+ k[0] = XK_Control_L;
+ goto special;
+ case KB_ALT:
+ k[0] = XK_Alt_L;
+ goto special;
+ case KB_FUNC:
+ switch (keymap[i].unshift[2]) {
+ case 'M':
+ k[0] = XK_F1;
+ break;
+ case 'N':
+ k[0] = XK_F2;
+ break;
+ case 'O':
+ k[0] = XK_F3;
+ break;
+ case 'P':
+ k[0] = XK_F4;
+ break;
+ case 'Q':
+ k[0] = XK_F5;
+ break;
+ case 'R':
+ k[0] = XK_F6;
+ break;
+ case 'S':
+ k[0] = XK_F7;
+ break;
+ case 'T':
+ k[0] = XK_F8;
+ break;
+ case 'U':
+ k[0] = XK_F9;
+ break;
+ case 'V':
+ k[0] = XK_F10;
+ break;
+ case 'W':
+ k[0] = XK_F11;
+ break;
+ case 'X':
+ k[0] = XK_F12;
+ break;
+ default:
+ k[0] = NoSymbol;
+ break;
+ }
+ goto special;
+ default:
+ k[0] = NoSymbol;
+ special:
+ k[1] = k[2] = k[3] = NoSymbol;
+ }
+ }
+ } else {
+ ErrorF("Can't read pccons keymap\n");
+ }
+ }
+#endif /* __OpenBSD__ */
+ break;
+#endif
+
+/*
+ * XXX wscons has no GIO_KEYMAP
+ */
+#if (defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)) && defined(GIO_KEYMAP)
+ case SYSCONS:
+ case PCVT:
+ {
+ keymap_t keymap;
+
+ if (ioctl(pInfo->fd, GIO_KEYMAP, &keymap) != -1) {
+ for (i = 0; i < keymap.n_keys && i < NUM_KEYCODES; i++)
+ if (remap[i]) {
+ k = map + (remap[i] << 2);
+ k[0] = KD_GET_ENTRY(i,0); /* non-shifed */
+ k[1] = KD_GET_ENTRY(i,1); /* shifted */
+ k[2] = KD_GET_ENTRY(i,4); /* alt */
+ k[3] = KD_GET_ENTRY(i,5); /* alt - shifted */
+ if (k[3] == k[2]) k[3] = NoSymbol;
+ if (k[2] == k[1]) k[2] = NoSymbol;
+ if (k[1] == k[0]) k[1] = NoSymbol;
+ if (k[0] == k[2] && k[1] == k[3])
+ k[2] = k[3] = NoSymbol;
+ }
+ }
+ }
+ break;
+#endif /* SYSCONS || PCVT */
+
+ }
+#endif /* !bsdi */
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+ pKbd->kbdType = 0;
+
+ pKeySyms->map = map;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+
+ switch(pKbd->consType) {
+#ifdef SYSCONS_SUPPORT
+ case SYSCONS:
+ if (pKbd->CustomKeycodes)
+ pKbd->scancodeMap = &sysconsCODE;
+ else
+ pKbd->RemapScanCode = ATScancode;
+ break;
+#endif
+#if defined(PCCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case PCCONS:
+ case PCVT:
+ pKbd->RemapScanCode = ATScancode;
+ break;
+#endif
+#ifdef WSCONS_SUPPORT
+ case WSCONS:
+ if (!pKbd->isConsole) {
+ switch (pKbd->wsKbdType) {
+ case WSKBD_TYPE_PC_XT:
+ case WSKBD_TYPE_PC_AT:
+ pKbd->RemapScanCode = ATScancode;
+ break;
+ case WSKBD_TYPE_USB:
+ pKbd->scancodeMap = &wsUsb;
+ break;
+#ifdef WSKBD_TYPE_ADB
+ case WSKBD_TYPE_ADB:
+ pKbd->scancodeMap = &wsAdb;
+ break;
+#endif
+#ifdef WSKBD_TYPE_SUN
+#ifdef WSKBD_TYPE_SUN5
+ case WSKBD_TYPE_SUN5:
+#endif
+ case WSKBD_TYPE_SUN:
+ pKbd->scancodeMap = &wsSun;
+ break;
+#endif
+ default:
+ ErrorF("Unknown wskbd type %d\n", pKbd->wsKbdType);
+ }
+ } else {
+ pKbd->RemapScanCode = ATScancode;
+ }
+ break;
+#endif
+ }
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_VTsw.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_VTsw.c
new file mode 100644
index 000000000..d97782dc6
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_VTsw.c
@@ -0,0 +1,96 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_VTsw.c,v 3.5.4.3 1998/06/05 16:23:03 dawes Exp $ */
+/*
+ * Derived from VTsw_usl.c which is
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ * by S_ren Schmidt (sos@login.dkuug.dk)
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: bsd_VTsw.c /main/4 1996/02/21 17:50:57 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * Handle the VT-switching interface for OSs that use USL-style ioctl()s
+ * (the bsd, sysv, sco, and linux subdirs).
+ */
+
+/*
+ * This function is the signal handler for the VT-switching signal. It
+ * is only referenced inside the OS-support layer.
+ */
+void
+xf86VTRequest(int sig)
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) {
+ xf86Info.vtRequestsPending = TRUE;
+ }
+#endif
+ return;
+}
+
+Bool
+xf86VTSwitchPending()
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) {
+ return(xf86Info.vtRequestsPending ? TRUE : FALSE);
+ }
+#endif
+ return FALSE;
+}
+
+Bool
+xf86VTSwitchAway()
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) {
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, 1) < 0)
+ return(FALSE);
+ else
+ return(TRUE);
+ }
+#endif
+ return FALSE;
+}
+
+Bool
+xf86VTSwitchTo()
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) {
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
+ return(FALSE);
+ else
+ return(TRUE);
+ }
+#endif
+ return(TRUE);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_apm.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_apm.c
new file mode 100644
index 000000000..c8e204307
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_apm.c
@@ -0,0 +1,141 @@
+/* $XFree86$ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSproc.h"
+#include "xf86_OSlib.h"
+
+#include <machine/apmvar.h>
+
+#define APM_DEVICE "/dev/apm"
+
+static pointer APMihPtr = NULL;
+static void bsdCloseAPM(void);
+
+static struct {
+ u_int apmBsd;
+ pmEvent xf86;
+} bsdToXF86Array [] = {
+ { APM_STANDBY_REQ, XF86_APM_SYS_STANDBY },
+ { APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND },
+ { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME },
+ { APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME },
+ { APM_BATTERY_LOW, XF86_APM_LOW_BATTERY },
+ { APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE },
+ { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME },
+ { APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND },
+ { APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY },
+ { APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND },
+ { APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME },
+#ifdef APM_CAPABILITY_CHANGE
+ { APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED },
+#endif
+};
+
+#define numApmEvents (sizeof(bsdToXF86Array) / sizeof(bsdToXF86Array[0]))
+
+static pmEvent
+bsdToXF86(int type)
+{
+ int i;
+
+ for (i = 0; i < numApmEvents; i++) {
+ if (type == bsdToXF86Array[i].apmBsd) {
+ return bsdToXF86Array[i].xf86;
+ }
+ }
+ return XF86_APM_UNKNOWN;
+}
+
+/*
+ * APM events can be requested direclty from /dev/apm
+ */
+static int
+bsdPMGetEventFromOS(int fd, pmEvent *events, int num)
+{
+ struct apm_event_info bsdEvent;
+ int i;
+
+ for (i = 0; i < num; i++) {
+
+ if (ioctl(fd, APM_IOC_NEXTEVENT, &bsdEvent) < 0) {
+ if (errno != EAGAIN) {
+ xf86Msg(X_WARNING, "bsdPMGetEventFromOS: APM_IOC_NEXTEVENT"
+ " errno = %d\n", errno);
+ }
+ break;
+ }
+ events[i] = bsdToXF86(bsdEvent.type);
+ }
+ return i;
+}
+
+/*
+ * XXX This won't work on /dev/apm !
+ * We should either use /dev/apm_ctl (and kill apmd(8))
+ * or talk to apmd (but its protocol is not publically available)...
+ */
+static pmWait
+bsdPMConfirmEventToOs(int fd, pmEvent event)
+{
+ switch (event) {
+ case XF86_APM_SYS_STANDBY:
+ case XF86_APM_USER_STANDBY:
+ if (ioctl( fd, APM_IOC_STANDBY, NULL ) == 0)
+ return PM_WAIT; /* should we stop the Xserver in standby, too? */
+ else
+ return PM_NONE;
+ case XF86_APM_SYS_SUSPEND:
+ case XF86_APM_CRITICAL_SUSPEND:
+ case XF86_APM_USER_SUSPEND:
+ if (ioctl( fd, APM_IOC_SUSPEND, NULL ) == 0)
+ return PM_WAIT;
+ else
+ return PM_NONE;
+ case XF86_APM_STANDBY_RESUME:
+ case XF86_APM_NORMAL_RESUME:
+ case XF86_APM_CRITICAL_RESUME:
+ case XF86_APM_STANDBY_FAILED:
+ case XF86_APM_SUSPEND_FAILED:
+ return PM_CONTINUE;
+ default:
+ return PM_NONE;
+ }
+}
+
+PMClose
+xf86OSPMOpen(void)
+{
+ int fd;
+
+ if (APMihPtr || !xf86Info.pmFlag) {
+ return NULL;
+ }
+
+ if ((fd = open(APM_DEVICE, O_RDWR)) == -1) {
+ return NULL;
+ }
+ xf86PMGetEventFromOs = bsdPMGetEventFromOS;
+ xf86PMConfirmEventToOs = bsdPMConfirmEventToOs;
+ APMihPtr = xf86AddInputHandler(fd, xf86HandlePMEvents, NULL);
+ return bsdCloseAPM;
+}
+
+static void
+bsdCloseAPM(void)
+{
+ int fd;
+
+ if (APMihPtr) {
+ fd = xf86RemoveInputHandler(APMihPtr);
+ close(fd);
+ APMihPtr = NULL;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_axp.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_axp.c
new file mode 100644
index 000000000..00b928a5e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_axp.c
@@ -0,0 +1,73 @@
+/* $XFree86: bsd_axp.c,v 1.2 2002/10/29 23:19:13 herrb Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Axp.h"
+#include <sys/param.h>
+#include "xf86_OSlib.h"
+#include <stdio.h>
+#include <sys/sysctl.h>
+
+axpDevice bsdGetAXP(void);
+
+/*
+ * BSD does a very nice job providing system information to
+ * user space programs. Unfortunately it doesn't provide all
+ * the information required. Therefore we just obtain the
+ * system type and look up the rest from a list we maintain
+ * ourselves.
+ */
+
+typedef struct {
+ char *name;
+ int type;
+} _AXP;
+
+static _AXP axpList[] = {
+ {"apecs",APECS},
+ {"pyxis",PYXIS},
+ {"cia",CIA},
+ {"irongate",IRONGATE},
+ {"lca",LCA},
+ {"t2",T2},
+ {"tsunami",TSUNAMI},
+ {NULL,NONE}
+};
+
+axpDevice
+bsdGetAXP(void)
+{
+ int i;
+ char sysname[64];
+ size_t len = sizeof(sysname);
+
+#ifdef __OpenBSD__
+ int mib[3];
+ int error;
+
+ mib[0] = CTL_MACHDEP;
+ mib[1] = CPU_CHIPSET;
+ mib[2] = CPU_CHIPSET_TYPE;
+
+ if ((error = sysctl(mib, 3, &sysname, &len, NULL, 0)) < 0)
+#else
+ if ((sysctlbyname("hw.chipset.type", &sysname, &len,
+ 0, 0)) < 0)
+#endif
+ FatalError("bsdGetAXP: can't find machine type\n");
+#ifdef DEBUG
+ xf86Msg(X_INFO,"AXP is a: %s\n",sysname);
+#endif
+ for (i=0;;i++) {
+ if (axpList[i].name == NULL)
+ return NONE;
+ if (!strcmp(sysname, axpList[i].name))
+ return axpList[i].type;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_ev56.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_ev56.c
new file mode 100644
index 000000000..62952a343
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_ev56.c
@@ -0,0 +1,91 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_ev56.c,v 1.1 2000/03/05 16:59:17 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+int readDense8(pointer Base, register unsigned long Offset);
+int readDense16(pointer Base, register unsigned long Offset);
+int readDense32(pointer Base, register unsigned long Offset);
+void
+writeDenseNB8(int Value, pointer Base, register unsigned long Offset);
+void
+writeDenseNB16(int Value, pointer Base, register unsigned long Offset);
+void
+writeDenseNB32(int Value, pointer Base, register unsigned long Offset);
+void
+writeDense8(int Value, pointer Base, register unsigned long Offset);
+void
+writeDense16(int Value, pointer Base, register unsigned long Offset);
+void
+writeDense32(int Value, pointer Base, register unsigned long Offset);
+
+int
+readDense8(pointer Base, register unsigned long Offset)
+{
+ mem_barrier();
+ return *(volatile CARD8*) ((unsigned long)Base+(Offset));
+}
+
+int
+readDense16(pointer Base, register unsigned long Offset)
+{
+ mem_barrier();
+ return *(volatile CARD16*) ((unsigned long)Base+(Offset));
+}
+
+int
+readDense32(pointer Base, register unsigned long Offset)
+{
+ mem_barrier();
+ return *(volatile CARD32*)((unsigned long)Base+(Offset));
+}
+
+void
+writeDenseNB8(int Value, pointer Base, register unsigned long Offset)
+{
+ *(volatile CARD8*)((unsigned long)Base+(Offset)) = Value;
+}
+
+void
+writeDenseNB16(int Value, pointer Base, register unsigned long Offset)
+{
+ *(volatile CARD16*)((unsigned long)Base + (Offset)) = Value;
+}
+
+void
+writeDenseNB32(int Value, pointer Base, register unsigned long Offset)
+{
+ *(volatile CARD32*)((unsigned long)Base+(Offset)) = Value;
+}
+
+void
+writeDense8(int Value, pointer Base, register unsigned long Offset)
+{
+ write_mem_barrier();
+ *(volatile CARD8 *)((unsigned long)Base+(Offset)) = Value;
+}
+
+void
+writeDense16(int Value, pointer Base, register unsigned long Offset)
+{
+ write_mem_barrier();
+ *(volatile CARD16 *)((unsigned long)Base+(Offset)) = Value;
+}
+
+void
+writeDense32(int Value, pointer Base, register unsigned long Offset)
+{
+ write_mem_barrier();
+ *(volatile CARD32 *)((unsigned long)Base+(Offset)) = Value;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c
new file mode 100644
index 000000000..4d883a2be
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c
@@ -0,0 +1,738 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c,v 3.21 2003/09/24 02:43:34 dawes Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: bsd_init.c /main/8 1996/10/23 13:13:05 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include <sys/utsname.h>
+#include <sys/ioctl.h>
+#include <stdlib.h>
+#include <errno.h>
+
+static Bool KeepTty = FALSE;
+static int devConsoleFd = -1;
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+static int VTnum = -1;
+static int initialVT = -1;
+#endif
+
+#ifdef PCCONS_SUPPORT
+/* Stock 0.1 386bsd pccons console driver interface */
+#ifndef __OpenBSD__
+# define PCCONS_CONSOLE_DEV1 "/dev/ttyv0"
+#else
+# define PCCONS_CONSOLE_DEV1 "/dev/ttyC0"
+#endif
+#define PCCONS_CONSOLE_DEV2 "/dev/vga"
+#define PCCONS_CONSOLE_MODE O_RDWR|O_NDELAY
+#endif
+
+#ifdef SYSCONS_SUPPORT
+/* The FreeBSD 1.1 version syscons driver uses /dev/ttyv0 */
+#define SYSCONS_CONSOLE_DEV1 "/dev/ttyv0"
+#define SYSCONS_CONSOLE_DEV2 "/dev/vga"
+#define SYSCONS_CONSOLE_MODE O_RDWR|O_NDELAY
+#endif
+
+#ifdef PCVT_SUPPORT
+/* Hellmuth Michaelis' pcvt driver */
+#ifndef __OpenBSD__
+# define PCVT_CONSOLE_DEV "/dev/ttyv0"
+#else
+# define PCVT_CONSOLE_DEV "/dev/ttyC0"
+#endif
+#define PCVT_CONSOLE_MODE O_RDWR|O_NDELAY
+#endif
+
+#if defined(WSCONS_SUPPORT) && defined(__NetBSD__)
+/* NetBSD's new console driver */
+#define WSCONS_PCVT_COMPAT_CONSOLE_DEV "/dev/ttyE0"
+#endif
+
+#ifdef __GLIBC__
+#define setpgrp setpgid
+#endif
+
+#define CHECK_DRIVER_MSG \
+ "Check your kernel's console driver configuration and /dev entries"
+
+static char *supported_drivers[] = {
+#ifdef PCCONS_SUPPORT
+ "pccons (with X support)",
+#endif
+#ifdef SYSCONS_SUPPORT
+ "syscons",
+#endif
+#ifdef PCVT_SUPPORT
+ "pcvt",
+#endif
+#ifdef WSCONS_SUPPORT
+ "wscons",
+#endif
+};
+
+
+/*
+ * Functions to probe for the existance of a supported console driver.
+ * Any function returns either a valid file descriptor (driver probed
+ * succesfully), -1 (driver not found), or uses FatalError() if the
+ * driver was found but proved to not support the required mode to run
+ * an X server.
+ */
+
+typedef int (*xf86ConsOpen_t)(void);
+
+#ifdef PCCONS_SUPPORT
+static int xf86OpenPccons(void);
+#endif /* PCCONS_SUPPORT */
+
+#ifdef SYSCONS_SUPPORT
+static int xf86OpenSyscons(void);
+#endif /* SYSCONS_SUPPORT */
+
+#ifdef PCVT_SUPPORT
+static int xf86OpenPcvt(void);
+#endif /* PCVT_SUPPORT */
+
+#ifdef WSCONS_SUPPORT
+static int xf86OpenWScons(void);
+#endif
+
+/*
+ * The sequence of the driver probes is important; start with the
+ * driver that is best distinguishable, and end with the most generic
+ * driver. (Otherwise, pcvt would also probe as syscons, and either
+ * pcvt or syscons might succesfully probe as pccons.)
+ */
+static xf86ConsOpen_t xf86ConsTab[] = {
+#ifdef PCVT_SUPPORT
+ xf86OpenPcvt,
+#endif
+#ifdef SYSCONS_SUPPORT
+ xf86OpenSyscons,
+#endif
+#ifdef PCCONS_SUPPORT
+ xf86OpenPccons,
+#endif
+#ifdef WSCONS_SUPPORT
+ xf86OpenWScons,
+#endif
+ (xf86ConsOpen_t)NULL
+};
+
+
+void
+xf86OpenConsole()
+{
+ int i, fd = -1;
+ xf86ConsOpen_t *driver;
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ int result;
+ struct utsname uts;
+ vtmode_t vtmode;
+#endif
+
+ if (serverGeneration == 1)
+ {
+ /* check if we are run with euid==0 */
+ if (geteuid() != 0)
+ {
+ FatalError("xf86OpenConsole: Server must be suid root");
+ }
+
+ if (!KeepTty)
+ {
+ /*
+ * detaching the controlling tty solves problems of kbd character
+ * loss. This is not interesting for CO driver, because it is
+ * exclusive.
+ */
+ setpgrp(0, getpid());
+ if ((i = open("/dev/tty",O_RDWR)) >= 0)
+ {
+ ioctl(i,TIOCNOTTY,(char *)0);
+ close(i);
+ }
+ }
+
+ /* detect which driver we are running on */
+ for (driver = xf86ConsTab; *driver; driver++)
+ {
+ if ((fd = (*driver)()) >= 0)
+ break;
+ }
+
+ /* Check that a supported console driver was found */
+ if (fd < 0)
+ {
+ char cons_drivers[80] = {0, };
+ for (i = 0; i < sizeof(supported_drivers) / sizeof(char *); i++)
+ {
+ if (i)
+ {
+ strcat(cons_drivers, ", ");
+ }
+ strcat(cons_drivers, supported_drivers[i]);
+ }
+ FatalError(
+ "%s: No console driver found\n\tSupported drivers: %s\n\t%s",
+ "xf86OpenConsole", cons_drivers, CHECK_DRIVER_MSG);
+ }
+#if 0 /* stdin is already closed in OsInit() */
+ fclose(stdin);
+#endif
+ xf86Info.consoleFd = fd;
+ xf86Info.screenFd = fd;
+
+ switch (xf86Info.consType)
+ {
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+ if (ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_ON, 0) < 0)
+ {
+ FatalError("%s: CONSOLE_X_MODE_ON failed (%s)\n%s",
+ "xf86OpenConsole", strerror(errno),
+ CHECK_DRIVER_MSG);
+ }
+ /*
+ * Hack to prevent keyboard hanging when syslogd closes
+ * /dev/console
+ */
+ if ((devConsoleFd = open("/dev/console", O_WRONLY,0)) < 0)
+ {
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: couldn't open /dev/console (%s)\n",
+ strerror(errno));
+ }
+ break;
+#endif
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ /* as of FreeBSD 2.2.8, syscons driver does not need the #1 vt
+ * switching anymore. Here we check for FreeBSD 3.1 and up.
+ * Add cases for other *BSD that behave the same.
+ */
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ uname (&uts);
+ i = atof(uts.release) * 100;
+ if (i >= 310) goto acquire_vt;
+#endif
+ /* otherwise fall through */
+ case PCVT:
+ /*
+ * First activate the #1 VT. This is a hack to allow a server
+ * to be started while another one is active. There should be
+ * a better way.
+ */
+ if (initialVT != 1) {
+
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) != 0)
+ {
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ sleep(1);
+ }
+
+acquire_vt:
+ /*
+ * now get the VT
+ */
+ SYSCALL(result =
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno));
+ if (result != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ SYSCALL(result =
+ ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno));
+ if (result != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
+ }
+
+ signal(SIGUSR1, xf86VTRequest);
+
+ vtmode.mode = VT_PROCESS;
+ vtmode.relsig = SIGUSR1;
+ vtmode.acqsig = SIGUSR1;
+ vtmode.frsig = SIGUSR1;
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &vtmode) < 0)
+ {
+ FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed");
+ }
+#if !defined(USE_DEV_IO) && !defined(USE_I386_IOPL)
+ if (ioctl(xf86Info.consoleFd, KDENABIO, 0) < 0)
+ {
+ FatalError("xf86OpenConsole: KDENABIO failed (%s)",
+ strerror(errno));
+ }
+#endif
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
+ {
+ FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed");
+ }
+ break;
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+#ifdef WSCONS_SUPPORT
+ case WSCONS:
+ fprintf(stderr, "xf86OpenConsole\n");
+ /* xf86Info.consoleFd = open("/dev/wskbd0", 0); */
+ break;
+#endif
+ }
+ }
+ else
+ {
+ /* serverGeneration != 1 */
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT)
+ {
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ }
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+ }
+ return;
+}
+
+
+#ifdef PCCONS_SUPPORT
+
+static int
+xf86OpenPccons()
+{
+ int fd = -1;
+
+ if ((fd = open(PCCONS_CONSOLE_DEV1, PCCONS_CONSOLE_MODE, 0))
+ >= 0 ||
+ (fd = open(PCCONS_CONSOLE_DEV2, PCCONS_CONSOLE_MODE, 0))
+ >= 0)
+ {
+ if (ioctl(fd, CONSOLE_X_MODE_OFF, 0) < 0)
+ {
+ FatalError(
+ "%s: CONSOLE_X_MODE_OFF failed (%s)\n%s\n%s",
+ "xf86OpenPccons",
+ strerror(errno),
+ "Was expecting pccons driver with X support",
+ CHECK_DRIVER_MSG);
+ }
+ xf86Info.consType = PCCONS;
+ xf86Msg(X_PROBED, "Using pccons driver with X support\n");
+ }
+ return fd;
+}
+
+#endif /* PCCONS_SUPPORT */
+
+#ifdef SYSCONS_SUPPORT
+
+static int
+xf86OpenSyscons()
+{
+ int fd = -1;
+ vtmode_t vtmode;
+ char vtname[12];
+ struct stat status;
+ long syscons_version;
+ MessageType from;
+
+ /* Check for syscons */
+ if ((fd = open(SYSCONS_CONSOLE_DEV1, SYSCONS_CONSOLE_MODE, 0)) >= 0
+ || (fd = open(SYSCONS_CONSOLE_DEV2, SYSCONS_CONSOLE_MODE, 0)) >= 0)
+ {
+ if (ioctl(fd, VT_GETMODE, &vtmode) >= 0)
+ {
+ /* Get syscons version */
+ if (ioctl(fd, CONS_GETVERS, &syscons_version) < 0)
+ {
+ syscons_version = 0;
+ }
+
+ xf86Info.vtno = VTnum;
+ from = X_CMDLINE;
+
+#ifdef VT_GETACTIVE
+ if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0)
+ initialVT = -1;
+#endif
+ if (xf86Info.vtno == -1)
+ {
+ /*
+ * For old syscons versions (<0x100), VT_OPENQRY returns
+ * the current VT rather than the next free VT. In this
+ * case, the server gets started on the current VT instead
+ * of the next free VT.
+ */
+
+#if 0
+ /* check for the fixed VT_OPENQRY */
+ if (syscons_version >= 0x100)
+ {
+#endif
+ if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0)
+ {
+ /* No free VTs */
+ xf86Info.vtno = -1;
+ }
+#if 0
+ }
+#endif
+
+ if (xf86Info.vtno == -1)
+ {
+ /*
+ * All VTs are in use. If initialVT was found, use it.
+ * Otherwise, if stdin is a VT, use that one.
+ * XXX stdin is already closed, so this won't work.
+ */
+ if (initialVT != -1)
+ {
+ xf86Info.vtno = initialVT;
+ }
+ else if ((fstat(0, &status) >= 0)
+ && S_ISCHR(status.st_mode)
+ && (ioctl(0, VT_GETMODE, &vtmode) >= 0))
+ {
+ /* stdin is a VT */
+ xf86Info.vtno = minor(status.st_rdev) + 1;
+ }
+ else
+ {
+ if (syscons_version >= 0x100)
+ {
+ FatalError("%s: Cannot find a free VT",
+ "xf86OpenSyscons");
+ }
+ /* Should no longer reach here */
+ FatalError("%s: %s %s\n\t%s %s",
+ "xf86OpenSyscons",
+ "syscons versions prior to 1.0 require",
+ "either the",
+ "server's stdin be a VT",
+ "or the use of the vtxx server option");
+ }
+ }
+ from = X_PROBED;
+ }
+
+ close(fd);
+#ifndef __OpenBSD__
+ sprintf(vtname, "/dev/ttyv%01x", xf86Info.vtno - 1);
+#else
+ sprintf(vtname, "/dev/ttyC%01x", xf86Info.vtno - 1);
+#endif
+ if ((fd = open(vtname, SYSCONS_CONSOLE_MODE, 0)) < 0)
+ {
+ FatalError("xf86OpenSyscons: Cannot open %s (%s)",
+ vtname, strerror(errno));
+ }
+ if (ioctl(fd, VT_GETMODE, &vtmode) < 0)
+ {
+ FatalError("xf86OpenSyscons: VT_GETMODE failed");
+ }
+ xf86Info.consType = SYSCONS;
+ xf86Msg(X_PROBED, "Using syscons driver with X support");
+ if (syscons_version >= 0x100)
+ {
+ xf86ErrorF(" (version %ld.%ld)\n", syscons_version >> 8,
+ syscons_version & 0xFF);
+ }
+ else
+ {
+ xf86ErrorF(" (version 0.x)\n");
+ }
+ xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno);
+ }
+ else
+ {
+ /* VT_GETMODE failed, probably not syscons */
+ close(fd);
+ fd = -1;
+ }
+ }
+ return fd;
+}
+
+#endif /* SYSCONS_SUPPORT */
+
+
+#ifdef PCVT_SUPPORT
+
+static int
+xf86OpenPcvt()
+{
+ /* This looks much like syscons, since pcvt is API compatible */
+ int fd = -1;
+ vtmode_t vtmode;
+ char vtname[12], *vtprefix;
+ struct stat status;
+ struct pcvtid pcvt_version;
+
+#ifndef __OpenBSD__
+ vtprefix = "/dev/ttyv";
+#else
+ vtprefix = "/dev/ttyC";
+#endif
+
+ fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0);
+#ifdef WSCONS_PCVT_COMPAT_CONSOLE_DEV
+ if (fd < 0)
+ {
+ fd = open(WSCONS_PCVT_COMPAT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0);
+ vtprefix = "/dev/ttyE";
+ }
+#endif
+ if (fd >= 0)
+ {
+ if (ioctl(fd, VGAPCVTID, &pcvt_version) >= 0)
+ {
+ if(ioctl(fd, VT_GETMODE, &vtmode) < 0)
+ {
+ FatalError("%s: VT_GETMODE failed\n%s%s\n%s",
+ "xf86OpenPcvt",
+ "Found pcvt driver but X11 seems to be",
+ " not supported.", CHECK_DRIVER_MSG);
+ }
+
+ xf86Info.vtno = VTnum;
+
+ if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0)
+ initialVT = -1;
+
+ if (xf86Info.vtno == -1)
+ {
+ if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0)
+ {
+ /* No free VTs */
+ xf86Info.vtno = -1;
+ }
+
+ if (xf86Info.vtno == -1)
+ {
+ /*
+ * All VTs are in use. If initialVT was found, use it.
+ * Otherwise, if stdin is a VT, use that one.
+ * XXX stdin is already closed, so this won't work.
+ */
+ if (initialVT != -1)
+ {
+ xf86Info.vtno = initialVT;
+ }
+ else if ((fstat(0, &status) >= 0)
+ && S_ISCHR(status.st_mode)
+ && (ioctl(0, VT_GETMODE, &vtmode) >= 0))
+ {
+ /* stdin is a VT */
+ xf86Info.vtno = minor(status.st_rdev) + 1;
+ }
+ else
+ {
+ FatalError("%s: Cannot find a free VT",
+ "xf86OpenPcvt");
+ }
+ }
+ }
+
+ close(fd);
+ sprintf(vtname, "%s%01x", vtprefix, xf86Info.vtno - 1);
+ if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0)
+ {
+ FatalError("xf86OpenPcvt: Cannot open %s (%s)",
+ vtname, strerror(errno));
+ }
+ if (ioctl(fd, VT_GETMODE, &vtmode) < 0)
+ {
+ FatalError("xf86OpenPcvt: VT_GETMODE failed");
+ }
+ xf86Info.consType = PCVT;
+#ifdef WSCONS_SUPPORT
+ xf86Msg(X_PROBED,
+ "Using wscons driver in pcvt compatibility mode "
+ "(version %d.%d)\n",
+ pcvt_version.rmajor, pcvt_version.rminor);
+#else
+ xf86Msg(X_PROBED, "Using pcvt driver (version %d.%d)\n",
+ pcvt_version.rmajor, pcvt_version.rminor);
+#endif
+ }
+ else
+ {
+ /* Not pcvt */
+ close(fd);
+ fd = -1;
+ }
+ }
+ return fd;
+}
+
+#endif /* PCVT_SUPPORT */
+
+#ifdef WSCONS_SUPPORT
+
+static int
+xf86OpenWScons()
+{
+ int fd = -1;
+ int mode = WSDISPLAYIO_MODE_MAPPED;
+ int i;
+ char ttyname[16];
+
+ /* XXX Is this ok? */
+ for (i = 0; i < 8; i++) {
+#if defined(__NetBSD__)
+ sprintf(ttyname, "/dev/ttyE%d", i);
+#elif defined(__OpenBSD__)
+ sprintf(ttyname, "/dev/ttyC%d", i);
+#endif
+ if ((fd = open(ttyname, 2)) != -1)
+ break;
+ }
+ if (fd != -1) {
+ if (ioctl(fd, WSDISPLAYIO_SMODE, &mode) < 0) {
+ FatalError("%s: WSDISPLAYIO_MODE_MAPPED failed (%s)\n%s",
+ "xf86OpenConsole", strerror(errno),
+ CHECK_DRIVER_MSG);
+ }
+ xf86Info.consType = WSCONS;
+ xf86Msg(X_PROBED, "Using wscons driver\n");
+ }
+ return fd;
+}
+
+#endif /* WSCONS_SUPPORT */
+
+void
+xf86CloseConsole()
+{
+#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ struct vt_mode VT;
+#endif
+
+ switch (xf86Info.consType)
+ {
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+ ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_OFF, 0);
+ break;
+#endif /* PCCONS_SUPPORT */
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode */
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
+ {
+ VT.mode = VT_AUTO;
+ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* dflt vt handling */
+ }
+#if !defined(USE_DEV_IO) && !defined(USE_I386_IOPL)
+ if (ioctl(xf86Info.consoleFd, KDDISABIO, 0) < 0)
+ {
+ xf86FatalError("xf86CloseConsole: KDDISABIO failed (%s)",
+ strerror(errno));
+ }
+#endif
+ if (initialVT != -1)
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, initialVT);
+ break;
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+#ifdef WSCONS_SUPPORT
+ case WSCONS:
+ {
+ int mode = WSDISPLAYIO_MODE_EMUL;
+ ioctl(xf86Info.screenFd, WSDISPLAYIO_SMODE, &mode);
+ break;
+ }
+#endif
+ }
+
+ if (xf86Info.screenFd != xf86Info.consoleFd)
+ {
+ close(xf86Info.screenFd);
+ close(xf86Info.consoleFd);
+ if ((xf86Info.consoleFd = open("/dev/console",O_RDONLY,0)) <0)
+ {
+ xf86FatalError("xf86CloseConsole: Cannot open /dev/console (%s)",
+ strerror(errno));
+ }
+ }
+ close(xf86Info.consoleFd);
+ if (devConsoleFd >= 0)
+ close(devConsoleFd);
+ return;
+}
+
+int
+xf86ProcessArgument(int argc, char *argv[], int i)
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful
+ * when debugging (so the server can receive keyboard signals.
+ */
+ if (!strcmp(argv[i], "-keeptty"))
+ {
+ KeepTty = TRUE;
+ return(1);
+ }
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0 ||
+ VTnum < 1 || VTnum > 12)
+ {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ return(1);
+ }
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+ return(0);
+}
+
+void
+xf86UseMsg()
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ ErrorF("vtXX use the specified VT number (1-12)\n");
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_io.c
new file mode 100644
index 000000000..3b1f58889
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_io.c
@@ -0,0 +1,294 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_io.c,v 3.22 2002/05/18 21:15:16 herrb Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Dawes make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID DAWES DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID DAWES BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: bsd_io.c /main/11 1996/10/19 18:06:07 kaleb $ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <termios.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#ifdef WSCONS_SUPPORT
+#define KBD_FD(i) ((i).kbdFd != -1 ? (i).kbdFd : (i).consoleFd)
+#endif
+
+void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+#ifdef WSCONS_SUPPORT
+ struct wskbd_bell_data wsb;
+#endif
+
+ if (loudness && pitch)
+ {
+#ifdef PCCONS_SUPPORT
+ int data[2];
+#endif
+
+ switch (xf86Info.consType) {
+
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+ data[0] = pitch;
+ data[1] = (duration * loudness) / 50;
+ ioctl(xf86Info.consoleFd, CONSOLE_X_BELL, data);
+ break;
+#endif
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDMKTONE,
+ ((1193190 / pitch) & 0xffff) |
+ (((unsigned long)duration*loudness/50)<<16));
+ break;
+#endif
+#if defined (WSCONS_SUPPORT)
+ case WSCONS:
+ wsb.which = WSKBD_BELL_DOALL;
+ wsb.pitch = pitch;
+ wsb.period = duration;
+ wsb.volume = loudness;
+ ioctl(KBD_FD(xf86Info), WSKBDIO_COMPLEXBELL,
+ &wsb);
+ break;
+#endif
+ }
+ }
+}
+
+void
+xf86SetKbdLeds(int leds)
+{
+ switch (xf86Info.consType) {
+
+ case PCCONS:
+ break;
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDSETLED, leds);
+ break;
+#endif
+#if defined(WSCONS_SUPPORT)
+ case WSCONS:
+ ioctl(KBD_FD(xf86Info), WSKBDIO_SETLEDS, &leds);
+ break;
+#endif
+ }
+}
+
+int
+xf86GetKbdLeds()
+{
+ int leds = 0;
+
+ switch (xf86Info.consType) {
+
+ case PCCONS:
+ break;
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDGETLED, &leds);
+ break;
+#endif
+#if defined(WSCONS_SUPPORT)
+ case WSCONS:
+ ioctl(KBD_FD(xf86Info), WSKBDIO_GETLEDS, &leds);
+ break;
+#endif
+ }
+ return(leds);
+}
+
+void
+xf86SetKbdRepeat(char rad)
+{
+ switch (xf86Info.consType) {
+
+ case PCCONS:
+ break;
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDSETRAD, rad);
+ break;
+#endif
+ }
+}
+
+#if defined(SYSCONS_SUPPORT) || defined(PCCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
+static struct termios kbdtty;
+#endif
+
+void
+xf86KbdInit()
+{
+ switch (xf86Info.consType) {
+
+#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case PCCONS:
+ case SYSCONS:
+ case PCVT:
+ tcgetattr(xf86Info.consoleFd, &kbdtty);
+ break;
+#endif
+#if defined WSCONS_SUPPORT
+ case WSCONS:
+ if (xf86Info.kbdFd != -1)
+ xf86FlushInput(xf86Info.kbdFd);
+ else
+ tcgetattr(xf86Info.consoleFd, &kbdtty);
+ break;
+#endif
+ }
+}
+
+int
+xf86KbdOn()
+{
+ struct termios nTty;
+#ifdef WSCONS_SUPPORT
+ int option;
+#endif
+
+
+ switch (xf86Info.consType) {
+
+#if defined(SYSCONS_SUPPORT) || defined(PCCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ case SYSCONS:
+ case PCCONS:
+ case PCVT:
+ nTty = kbdtty;
+ nTty.c_iflag = IGNPAR | IGNBRK;
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME] = 0;
+ nTty.c_cc[VMIN] = 1;
+ cfsetispeed(&nTty, 9600);
+ cfsetospeed(&nTty, 9600);
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty);
+
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW);
+#endif
+ break;
+#endif
+#ifdef WSCONS_SUPPORT
+ case WSCONS:
+ if (xf86Info.kbdFd == -1) {
+ nTty = kbdtty;
+ nTty.c_iflag = IGNPAR | IGNBRK;
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME] = 0;
+ nTty.c_cc[VMIN] = 1;
+ cfsetispeed(&nTty, 9600);
+ cfsetospeed(&nTty, 9600);
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty);
+ option = WSKBD_RAW;
+ if (ioctl(xf86Info.consoleFd, WSKBDIO_SETMODE,
+ &option) == -1)
+ FatalError("can't switch keyboard to raw mode. "
+ "Enable support for it in the kernel\n"
+ "or use for example:\n\n"
+ "Option \"Protocol\" \"wskbd\"\n"
+ "Option \"Device\" \"/dev/wskbd0\"\n"
+ "\nin your XF86Config(5) file\n");
+ } else {
+ return xf86Info.kbdFd;
+ }
+#endif
+ }
+ return(xf86Info.consoleFd);
+}
+
+int
+xf86KbdOff()
+{
+#ifdef WSCONS_SUPPORT
+ int option;
+#endif
+
+ switch (xf86Info.consType) {
+
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDSKBMODE, K_XLATE);
+ /* FALL THROUGH */
+#endif
+#if defined(SYSCONS_SUPPORT) || defined(PCCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ case PCCONS:
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &kbdtty);
+ break;
+#endif
+#ifdef WSCONS_SUPPORT
+ case WSCONS:
+ if (xf86Info.kbdFd != -1) {
+ return xf86Info.kbdFd;
+ } else {
+ option = WSKBD_TRANSLATED;
+ ioctl(xf86Info.consoleFd, WSKBDIO_SETMODE, &option);
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &kbdtty);
+ }
+ break;
+#endif
+ }
+ return(xf86Info.consoleFd);
+}
+
+#ifdef WSCONS_SUPPORT
+
+#define NUMEVENTS 64
+
+void
+xf86WSKbdEvents(void)
+{
+ static struct wscons_event events[NUMEVENTS];
+ int n, i;
+
+ n = read(xf86Info.kbdFd, events, sizeof events);
+ if (n <= 0)
+ return;
+ n /= sizeof(struct wscons_event);
+ for (i = 0; i < n; i++)
+ xf86PostWSKbdEvent(&events[i]);
+}
+
+#endif /* WSCONS_SUPPORT */
+
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_jstk.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_jstk.c
new file mode 100644
index 000000000..00f457b88
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_jstk.c
@@ -0,0 +1,189 @@
+/*
+ * Copyright 1995 by Frederic Lepied, France. <fred@sugix.frmug.fr.net>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Frederic Lepied not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Frederic Lepied makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* Modified for FreeBSD by David Dawes <dawes@XFree86.org> */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_jstk.c,v 3.7 1998/07/25 16:56:34 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <machine/joystick.h>
+#include <fcntl.h>
+
+#ifdef XFree86LOADER
+#include "misc.h"
+#include "xf86_libc.h"
+#endif
+#include "xf86.h"
+
+#define JS_RETURN sizeof(struct joystick)
+
+/***********************************************************************
+ *
+ * xf86JoystickOn --
+ *
+ * open the device and init timeout according to the device value.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickOn(char * name, int *timeout, int *centerX, int *centerY)
+{
+ int status;
+ int changed = 0;
+ int timeinmicros;
+ struct joystick js;
+
+#ifdef DEBUG
+ ErrorF("xf86JoystickOn: %s\n", name);
+#endif
+
+ if ((status = open(name, O_RDWR | O_NDELAY, 0)) < 0)
+ {
+ xf86Msg(X_WARNING, "xf86JoystickOn: Cannot open joystick '%s' (%s)\n",
+ name, strerror(errno));
+ return -1;
+ }
+
+ if (*timeout <= 0) {
+ /* Use the current setting */
+ ioctl(status, JOY_GETTIMEOUT, (char *)&timeinmicros);
+ *timeout = timeinmicros / 1000;
+ if (*timeout == 0)
+ *timeout = 1;
+ changed = 1;
+ }
+ /* Maximum allowed timeout in the FreeBSD driver is 10ms */
+ if (*timeout > 10) {
+ *timeout = 10;
+ changed = 1;
+ }
+
+ if (changed)
+ xf86Msg(X_PROBED, "Joystick: timeout value = %d\n", *timeout);
+
+ timeinmicros = *timeout * 1000;
+
+ /* Assume the joystick is centred when this is called */
+ read(status, &js, JS_RETURN);
+ if (*centerX < 0) {
+ *centerX = js.x;
+ xf86Msg(X_PROBED, "Joystick: CenterX set to %d\n", *centerX);
+ }
+ if (*centerY < 0) {
+ *centerY = js.y;
+ xf86Msg(X_PROBED, "Joystick: CenterY set to %d\n", *centerY);
+ }
+
+ return status;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickInit --
+ *
+ * called when X device is initialized.
+ *
+ ***********************************************************************
+ */
+
+void
+xf86JoystickInit()
+{
+ return;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickOff --
+ *
+ * close the handle.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickOff(int *fd, int doclose)
+{
+ int oldfd;
+
+ if (((oldfd = *fd) >= 0) && doclose) {
+ close(*fd);
+ *fd = -1;
+ }
+ return oldfd;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickGetState --
+ *
+ * return the state of buttons and the position of the joystick.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickGetState(int fd, int *x, int *y, int *buttons)
+{
+ struct joystick js;
+ int status;
+
+ status = read(fd, &js, JS_RETURN);
+
+ if (status != JS_RETURN)
+ {
+ Error("Joystick read");
+ return 0;
+ }
+
+ *x = js.x;
+ *y = js.y;
+ *buttons = js.b1 | (js.b2 << 1);
+#ifdef DEBUG
+ ErrorF("xf86JoystickGetState: x = %d, y = %d, buttons = %d\n", *x, *y,
+ *buttons);
+#endif
+
+ return 1;
+}
+
+#ifdef XFree86LOADER
+/*
+ * Entry point for XFree86 Loader
+ */
+void
+bsd_jstkModuleInit(pointer *data, INT32 *magic)
+{
+ *magic = MAGIC_DONE;
+ *data = NULL;
+}
+#endif
+/* end of bsd_jstk.c */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.c
new file mode 100644
index 000000000..18219e5bc
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.c
@@ -0,0 +1,573 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.c,v 1.8 2003/11/04 03:16:58 tsi Exp $ */
+
+/*
+ * Copyright (c) 2002 by The XFree86 Project, Inc.
+ * Author: Ivan Pascal.
+ *
+ * Based on the code from bsd_io.c which is
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <termios.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+#include "atKeynames.h"
+#include "bsd_kbd.h"
+
+extern Bool VTSwitchEnabled;
+#ifdef USE_VT_SYSREQ
+extern Bool VTSysreqToggle;
+#endif
+
+static KbdProtocolRec protocols[] = {
+ {"standard", PROT_STD },
+#ifdef WSCONS_SUPPORT
+ {"wskbd", PROT_WSCONS },
+#endif
+ { NULL, PROT_UNKNOWN_KBD }
+};
+
+typedef struct {
+ struct termios kbdtty;
+} BsdKbdPrivRec, *BsdKbdPrivPtr;
+
+static
+int KbdInit(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ BsdKbdPrivPtr priv = (BsdKbdPrivPtr) pKbd->private;
+
+ if (pKbd->isConsole) {
+ switch (pKbd->consType) {
+#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) || defined (WSCONS_SUPPORT)
+ case PCCONS:
+ case SYSCONS:
+ case PCVT:
+#if defined WSCONS_SUPPORT
+ case WSCONS:
+#endif
+ tcgetattr(pInfo->fd, &(priv->kbdtty));
+#endif
+ break;
+ }
+ }
+
+ return Success;
+}
+
+static void
+SetKbdLeds(InputInfoPtr pInfo, int leds)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int real_leds = 0;
+
+#ifdef LED_CAP
+ if (leds & XLED1) real_leds |= LED_CAP;
+#endif
+#ifdef LED_NUM
+ if (leds & XLED2) real_leds |= LED_NUM;
+#endif
+#ifdef LED_SCR
+ if (leds & XLED3) real_leds |= LED_SCR;
+ if (leds & XLED4) real_leds |= LED_SCR;
+#endif
+
+ switch (pKbd->consType) {
+
+ case PCCONS:
+ break;
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(pInfo->fd, KDSETLED, real_leds);
+ break;
+#endif
+#if defined(WSCONS_SUPPORT)
+ case WSCONS:
+ ioctl(pInfo->fd, WSKBDIO_SETLEDS, &real_leds);
+ break;
+#endif
+ }
+}
+
+static int
+GetKbdLeds(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int leds = 0, real_leds = 0;
+
+ switch (pKbd->consType) {
+ case PCCONS:
+ break;
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(pInfo->fd, KDGETLED, &real_leds);
+ break;
+#endif
+#if defined(WSCONS_SUPPORT)
+ case WSCONS:
+ ioctl(pInfo->fd, WSKBDIO_GETLEDS, &real_leds);
+ break;
+#endif
+ }
+
+#ifdef LED_CAP
+ if (real_leds & LED_CAP) leds |= XLED1;
+#endif
+#ifdef LED_NUM
+ if (real_leds & LED_NUM) leds |= XLED2;
+#endif
+#ifdef LED_SCR
+ if (real_leds & LED_SCR) leds |= XLED3;
+#endif
+
+ return(leds);
+}
+
+static void
+SetKbdRepeat(InputInfoPtr pInfo, char rad)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ switch (pKbd->consType) {
+
+ case PCCONS:
+ break;
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(pInfo->fd, KDSETRAD, rad);
+ break;
+#endif
+ }
+}
+
+static int
+KbdOn(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+#if defined(SYSCONS_SUPPORT) || defined(PCCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
+ BsdKbdPrivPtr priv = (BsdKbdPrivPtr) pKbd->private;
+ struct termios nTty;
+#endif
+#ifdef WSCONS_SUPPORT
+ int option;
+#endif
+
+ if (pKbd->isConsole) {
+ switch (pKbd->consType) {
+
+#if defined(SYSCONS_SUPPORT) || defined(PCCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
+ case SYSCONS:
+ case PCCONS:
+ case PCVT:
+#ifdef WSCONS_SUPPORT
+ case WSCONS:
+#endif
+ nTty = priv->kbdtty;
+ nTty.c_iflag = IGNPAR | IGNBRK;
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME] = 0;
+ nTty.c_cc[VMIN] = 1;
+ cfsetispeed(&nTty, 9600);
+ cfsetospeed(&nTty, 9600);
+ if (tcsetattr(pInfo->fd, TCSANOW, &nTty) < 0) {
+ xf86Msg(X_ERROR, "KbdOn: tcsetattr: %s\n",
+ strerror(errno));
+ }
+ break;
+#endif
+ }
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) || defined (WSCONS_SUPPORT)
+ switch (pKbd->consType) {
+ case SYSCONS:
+ case PCVT:
+#ifdef K_CODE
+ if (pKbd->CustomKeycodes)
+ ioctl(pInfo->fd, KDSKBMODE, K_CODE);
+ else
+ ioctl(pInfo->fd, KDSKBMODE, K_RAW);
+#else
+ ioctl(pInfo->fd, KDSKBMODE, K_RAW);
+#endif
+ break;
+#endif
+#ifdef WSCONS_SUPPORT
+ case WSCONS:
+ option = WSKBD_RAW;
+ if (ioctl(pInfo->fd, WSKBDIO_SETMODE, &option) == -1) {
+ FatalError("can't switch keyboard to raw mode. "
+ "Enable support for it in the kernel\n"
+ "or use for example:\n\n"
+ "Option \"Protocol\" \"wskbd\"\n"
+ "Option \"Device\" \"/dev/wskbd0\"\n"
+ "\nin your xorg.conf(5) file\n");
+ }
+ break;
+#endif
+ }
+ }
+ return Success;
+}
+
+static int
+KbdOff(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ BsdKbdPrivPtr priv = (BsdKbdPrivPtr) pKbd->private;
+#ifdef WSCONS_SUPPORT
+ int option;
+#endif
+
+ if (pKbd->isConsole) {
+ switch (pKbd->consType) {
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(pInfo->fd, KDSKBMODE, K_XLATE);
+ /* FALL THROUGH */
+#endif
+#if defined(SYSCONS_SUPPORT) || defined(PCCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ case PCCONS:
+ tcsetattr(pInfo->fd, TCSANOW, &(priv->kbdtty));
+ break;
+#endif
+#ifdef WSCONS_SUPPORT
+ case WSCONS:
+ option = WSKBD_TRANSLATED;
+ ioctl(xf86Info.consoleFd, WSKBDIO_SETMODE, &option);
+ tcsetattr(pInfo->fd, TCSANOW, &(priv->kbdtty));
+ break;
+#endif
+ }
+ }
+ return Success;
+}
+
+static void
+SoundBell(InputInfoPtr pInfo, int loudness, int pitch, int duration)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+#ifdef WSCONS_SUPPORT
+ struct wskbd_bell_data wsb;
+#endif
+
+ if (loudness && pitch) {
+ switch (pKbd->consType) {
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+ { int data[2];
+ data[0] = pitch;
+ data[1] = (duration * loudness) / 50;
+ ioctl(pInfo->fd, CONSOLE_X_BELL, data);
+ break;
+ }
+#endif
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(pInfo->fd, KDMKTONE,
+ ((1193190 / pitch) & 0xffff) |
+ (((unsigned long)duration*loudness/50)<<16));
+ break;
+#endif
+#if defined (WSCONS_SUPPORT)
+ case WSCONS:
+ wsb.which = WSKBD_BELL_DOALL;
+ wsb.pitch = pitch;
+ wsb.period = duration;
+ wsb.volume = loudness;
+ ioctl(pInfo->fd, WSKBDIO_COMPLEXBELL, &wsb);
+ break;
+#endif
+ }
+ }
+}
+
+#define ModifierSet(k) ((modifiers & (k)) == (k))
+
+static
+Bool SpecialKey(InputInfoPtr pInfo, int key, Bool down, int modifiers)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+
+ if(!pKbd->vtSwitchSupported)
+ return FALSE;
+
+ if ((ModifierSet(ControlMask | AltMask)) ||
+ (ModifierSet(ControlMask | AltLangMask))) {
+ if (VTSwitchEnabled && !xf86Info.vtSysreq && !xf86Info.dontVTSwitch) {
+ switch (key) {
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+#ifdef VT_ACTIVATE
+ if (down) {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F1 + 1);
+ return TRUE;
+ }
+#endif
+ case KEY_F11:
+ case KEY_F12:
+#ifdef VT_ACTIVATE
+ if (down) {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F11 + 11);
+ return TRUE;
+ }
+#endif
+ }
+ }
+ }
+#ifdef USE_VT_SYSREQ
+ if (VTSwitchEnabled && xf86Info.vtSysreq && !xf86Info.dontVTSwitch) {
+ switch (key) {
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ if (VTSysreqToggle && down) {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F1 + 1);
+ VTSysreqToggle = FALSE;
+ return TRUE;
+ }
+ break;
+ case KEY_F11:
+ case KEY_F12:
+ if (VTSysreqToggle && down) {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F11 + 11);
+ VTSysreqToggle = FALSE;
+ return TRUE;
+ }
+ break;
+ /* Ignore these keys -- ie don't let them cancel an alt-sysreq */
+ case KEY_Alt:
+ case KEY_AltLang:
+ break;
+ case KEY_SysReqest:
+ if ((ModifierSet(AltMask) || ModifierSet(AltLangMask)) && down)
+ VTSysreqToggle = TRUE;
+ break;
+ default:
+ /*
+ * We only land here when Alt-SysReq is followed by a
+ * non-switching key.
+ */
+ if (VTSysreqToggle)
+ VTSysreqToggle = FALSE;
+ }
+ }
+#endif /* USE_VT_SYSREQ */
+
+ return FALSE;
+}
+
+static void
+stdReadInput(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ unsigned char rBuf[64];
+ int nBytes, i;
+ if ((nBytes = read( pInfo->fd, (char *)rBuf, sizeof(rBuf))) > 0) {
+ for (i = 0; i < nBytes; i++)
+ pKbd->PostEvent(pInfo, rBuf[i] & 0x7f,
+ rBuf[i] & 0x80 ? FALSE : TRUE);
+ }
+}
+
+#ifdef WSCONS_SUPPORT
+
+static void
+WSReadInput(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ struct wscons_event events[64];
+ int type;
+ int blocked, n, i;
+
+ if ((n = read( pInfo->fd, events, sizeof(events))) > 0) {
+ n /= sizeof(struct wscons_event);
+ for (i = 0; i < n; i++) {
+ type = events[i].type;
+ if (type == WSCONS_EVENT_KEY_UP || type == WSCONS_EVENT_KEY_DOWN) {
+ /* It seems better to block SIGIO there */
+ blocked = xf86BlockSIGIO();
+ pKbd->PostEvent(pInfo, (unsigned int)(events[i].value),
+ type == WSCONS_EVENT_KEY_DOWN ? TRUE : FALSE);
+ xf86UnblockSIGIO(blocked);
+ }
+ } /* for */
+ }
+}
+
+static void
+printWsType(char *type, char *devname)
+{
+ xf86Msg(X_PROBED, "%s: Keyboard type: %s\n", type, devname);
+}
+#endif
+
+static Bool
+OpenKeyboard(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int i;
+ KbdProtocolId prot = PROT_UNKNOWN_KBD;
+ char *s;
+
+ s = xf86SetStrOption(pInfo->options, "Protocol", NULL);
+ for (i = 0; protocols[i].name; i++) {
+ if (xf86NameCmp(s, protocols[i].name) == 0) {
+ prot = protocols[i].id;
+ break;
+ }
+ }
+
+ switch (prot) {
+ case PROT_STD:
+ pInfo->read_input = stdReadInput;
+ break;
+#ifdef WSCONS_SUPPORT
+ case PROT_WSCONS:
+ pInfo->read_input = WSReadInput;
+ break;
+#endif
+ default:
+ xf86Msg(X_ERROR,"\"%s\" is not a valid keyboard protocol name\n", s);
+ xfree(s);
+ return FALSE;
+ }
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, s);
+ xfree(s);
+
+ s = xf86SetStrOption(pInfo->options, "Device", NULL);
+ if (s == NULL) {
+ if (prot == PROT_WSCONS) {
+ xf86Msg(X_ERROR,"A \"device\" option is required with"
+ " the \"wskbd\" keyboard protocol\n");
+ return FALSE;
+ } else {
+ pInfo->fd = xf86Info.consoleFd;
+ pKbd->isConsole = TRUE;
+ pKbd->consType = xf86Info.consType;
+ }
+ } else {
+ pInfo->fd = open(s, O_RDONLY | O_NONBLOCK | O_EXCL);
+ if (pInfo->fd == -1) {
+ xf86Msg(X_ERROR, "%s: cannot open \"%s\"\n", pInfo->name, s);
+ xfree(s);
+ return FALSE;
+ }
+ pKbd->isConsole = FALSE;
+ pKbd->consType = xf86Info.consType;
+ xfree(s);
+ }
+
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (pKbd->isConsole &&
+ ((pKbd->consType == SYSCONS) || (pKbd->consType == PCVT)))
+ pKbd->vtSwitchSupported = TRUE;
+#endif
+
+#ifdef WSCONS_SUPPORT
+ if( prot == PROT_WSCONS) {
+ pKbd->consType = WSCONS;
+ /* Find out keyboard type */
+ if (ioctl(pInfo->fd, WSKBDIO_GTYPE, &(pKbd->wsKbdType)) == -1) {
+ xf86Msg(X_ERROR, "%s: cannot get keyboard type", pInfo->name);
+ close(pInfo->fd);
+ return FALSE;
+ }
+ switch (pKbd->wsKbdType) {
+ case WSKBD_TYPE_PC_XT:
+ printWsType("XT", pInfo->name);
+ break;
+ case WSKBD_TYPE_PC_AT:
+ printWsType("AT", pInfo->name);
+ break;
+ case WSKBD_TYPE_USB:
+ printWsType("USB", pInfo->name);
+ break;
+#ifdef WSKBD_TYPE_ADB
+ case WSKBD_TYPE_ADB:
+ printWsType("ADB", pInfo->name);
+ break;
+#endif
+#ifdef WSKBD_TYPE_SUN
+ case WSKBD_TYPE_SUN:
+ printWsType("Sun", pInfo->name);
+ break;
+#endif
+#ifdef WSKBD_TYPE_SUN5
+ case WSKBD_TYPE_SUN5:
+ xf86Msg(X_PROBED, "Keyboard type: Sun5\n");
+ break;
+#endif
+ default:
+ xf86Msg(X_ERROR, "%s: Unsupported wskbd type \"%d\"",
+ pInfo->name, pKbd->wsKbdType);
+ close(pInfo->fd);
+ return FALSE;
+ }
+ }
+#endif
+ return TRUE;
+}
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = pInfo->private;
+
+ pKbd->KbdInit = KbdInit;
+ pKbd->KbdOn = KbdOn;
+ pKbd->KbdOff = KbdOff;
+ pKbd->Bell = SoundBell;
+ pKbd->SetLeds = SetKbdLeds;
+ pKbd->GetLeds = GetKbdLeds;
+ pKbd->SetKbdRepeat = SetKbdRepeat;
+ pKbd->KbdGetMapping = KbdGetMapping;
+ pKbd->SpecialKey = SpecialKey;
+
+ pKbd->RemapScanCode = NULL;
+ pKbd->GetSpecialKey = NULL;
+
+ pKbd->OpenKeyboard = OpenKeyboard;
+ pKbd->vtSwitchSupported = FALSE;
+ pKbd->CustomKeycodes = FALSE;
+
+ pKbd->private = xcalloc(sizeof(BsdKbdPrivRec), 1);
+ if (pKbd->private == NULL) {
+ xf86Msg(X_ERROR,"can't allocate keyboard OS private data\n");
+ return FALSE;
+ }
+ return TRUE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.h
new file mode 100644
index 000000000..7b9cd434e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kbd.h
@@ -0,0 +1,5 @@
+/* $XFree86$ */
+
+extern void KbdGetMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms,
+ CARD8 *pModMap);
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kmod.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kmod.c
new file mode 100644
index 000000000..ecaf78028
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kmod.c
@@ -0,0 +1,31 @@
+/* $XFree86$ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/linker.h>
+
+#include "xf86_OSproc.h"
+#include "xf86_ansic.h"
+
+/*
+ * Load a FreeBSD kernel module.
+ * This is used by the DRI/DRM to load a DRM kernel module when
+ * the X server starts. It could be used for other purposes in the future.
+ * Input:
+ * modName - name of the kernel module (Ex: "tdfx")
+ * Return:
+ * 0 for failure, 1 for success
+ */
+int xf86LoadKernelModule(const char *modName)
+{
+ if (kldload(modName) != -1)
+ return 1;
+ else
+ return 0;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c
new file mode 100644
index 000000000..5215d54e4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c
@@ -0,0 +1,203 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c,v 1.5 2002/07/30 23:24:32 herrb Exp $ */
+/*
+ * Copyright (C) 2001 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, 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 XFREE86 PROJECT 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 XFree86 Project
+ * 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 XFree86 Project.
+ */
+/* $OpenBSD: bsd_kqueue_apm.c,v 1.5 2002/07/30 23:07:42 matthieu Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSproc.h"
+#include "xf86_OSlib.h"
+
+#include <sys/event.h>
+#include <machine/apmvar.h>
+
+#define _PATH_APM_SOCKET "/var/run/apmdev"
+#define _PATH_APM_DEV "/dev/apm"
+#define _PATH_APM_CTLDEV "/dev/apmctl"
+
+static pointer APMihPtr = NULL;
+static int devFd = -1;
+static int ctlFd = -1;
+static void bsdCloseAPM(void);
+
+static struct {
+ u_int apmBsd;
+ pmEvent xf86;
+} bsdToXF86Array [] = {
+ { APM_STANDBY_REQ, XF86_APM_SYS_STANDBY },
+ { APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND },
+ { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME },
+ { APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME },
+ { APM_BATTERY_LOW, XF86_APM_LOW_BATTERY },
+ { APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE },
+ { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME },
+ { APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND },
+ { APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY },
+ { APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND },
+ { APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME },
+#ifdef APM_CAPABILITY_CHANGE
+ { APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED },
+#endif
+};
+
+#define numApmEvents (sizeof(bsdToXF86Array) / sizeof(bsdToXF86Array[0]))
+
+static pmEvent
+bsdToXF86(int type)
+{
+ int i;
+
+ for (i = 0; i < numApmEvents; i++) {
+ if (type == bsdToXF86Array[i].apmBsd) {
+ return bsdToXF86Array[i].xf86;
+ }
+ }
+ return XF86_APM_UNKNOWN;
+}
+
+/*
+ * APM events can be requested direclty from /dev/apm
+ */
+static int
+bsdPMGetEventFromOS(int kq, pmEvent *events, int num)
+{
+ struct kevent ev;
+ int i, result;
+ struct timespec ts = { 0, 0 };
+
+ for (i = 0; i < num; i++) {
+ result = kevent(kq, NULL, 0, &ev, 1, &ts);
+ if (result == 0 || APM_EVENT_TYPE(ev.data) == APM_NOEVENT) {
+ /* no event */
+ break;
+ } else if (result < 0) {
+ xf86Msg(X_WARNING, "bsdPMGetEventFromOS: kevent returns"
+ " errno = %d\n", errno);
+ break;
+ }
+ events[i] = bsdToXF86(APM_EVENT_TYPE(ev.data));
+ }
+ return i;
+}
+
+/*
+ * If apmd(8) is running, he will get the events and handle them,
+ * so, we've nothing to do here.
+ * Otherwise, opening /dev/apmctl will succeed and we have to send the
+ * confirmations to /dev/apmctl.
+ */
+static pmWait
+bsdPMConfirmEventToOs(int dummyfd, pmEvent event)
+{
+ if (ctlFd < 0) {
+ if ((ctlFd = open(_PATH_APM_CTLDEV, O_RDWR)) < 0) {
+ return PM_NONE;
+ }
+ }
+ /* apmctl open succeedeed */
+ switch (event) {
+ case XF86_APM_SYS_STANDBY:
+ case XF86_APM_USER_STANDBY:
+ if (ioctl( ctlFd, APM_IOC_STANDBY, NULL ) == 0)
+ return PM_WAIT; /* should we stop the Xserver in standby, too? */
+ else
+ return PM_NONE;
+
+ case XF86_APM_SYS_SUSPEND:
+ case XF86_APM_CRITICAL_SUSPEND:
+ case XF86_APM_USER_SUSPEND:
+ if (ioctl( ctlFd, APM_IOC_SUSPEND, NULL ) == 0)
+ return PM_WAIT;
+ else
+ return PM_NONE;
+ break;
+ case XF86_APM_STANDBY_RESUME:
+ case XF86_APM_NORMAL_RESUME:
+ case XF86_APM_CRITICAL_RESUME:
+ case XF86_APM_STANDBY_FAILED:
+ case XF86_APM_SUSPEND_FAILED:
+ return PM_CONTINUE;
+ break;
+ default:
+ return PM_NONE;
+ }
+}
+
+PMClose
+xf86OSPMOpen(void)
+{
+ int kq;
+ struct kevent ev;
+
+ if (APMihPtr || !xf86Info.pmFlag) {
+ return NULL;
+ }
+ if ((devFd = open(_PATH_APM_DEV, O_RDONLY)) == -1) {
+ return NULL;
+ }
+ if ((kq = kqueue()) <= 0) {
+ close(devFd);
+ return NULL;
+ }
+ EV_SET(&ev, devFd, EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR,
+ 0, 0, NULL);
+ if (kevent(kq, &ev, 1, NULL, 0, NULL) < 0) {
+ close(devFd);
+ return NULL;
+ }
+
+ xf86PMGetEventFromOs = bsdPMGetEventFromOS;
+ xf86PMConfirmEventToOs = bsdPMConfirmEventToOs;
+ APMihPtr = xf86AddInputHandler(kq, xf86HandlePMEvents, NULL);
+ return bsdCloseAPM;
+}
+
+static void
+bsdCloseAPM(void)
+{
+ int kq;
+
+ if (APMihPtr) {
+ kq = xf86RemoveInputHandler(APMihPtr);
+ close(devFd);
+ devFd = -1;
+ close(kq);
+ if (ctlFd >= 0) {
+ close(ctlFd);
+ ctlFd = -1;
+ }
+ APMihPtr = NULL;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_mouse.c
new file mode 100644
index 000000000..6ef300197
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/bsd_mouse.c
@@ -0,0 +1,792 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_mouse.c,v 1.28 2004/02/06 17:15:36 tsi Exp $ */
+
+/*
+ * Copyright (c) 1999-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
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "xisb.h"
+#include "mipointer.h"
+#ifdef WSCONS_SUPPORT
+#include <dev/wscons/wsconsio.h>
+#endif
+#ifdef USBMOUSE_SUPPORT
+#ifdef HAS_LIB_USB_HID
+#include <usbhid.h>
+#else
+#include "usb.h"
+#endif
+
+#include <dev/usb/usb.h>
+#ifdef USB_GET_REPORT_ID
+#define USB_NEW_HID
+#endif
+
+#define HUP_GENERIC_DESKTOP 0x0001
+#define HUP_BUTTON 0x0009
+
+#define HUG_X 0x0030
+#define HUG_Y 0x0031
+#define HUG_Z 0x0032
+#define HUG_WHEEL 0x0038
+
+#define HID_USAGE2(p,u) (((p) << 16) | u)
+
+/* The UMS mices have middle button as number 3 */
+#define UMS_BUT(i) ((i) == 0 ? 2 : (i) == 1 ? 0 : (i) == 2 ? 1 : (i))
+#endif /* USBMOUSE_SUPPORT */
+
+#ifdef USBMOUSE_SUPPORT
+static void usbSigioReadInput (int fd, void *closure);
+#endif
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+/* These are for FreeBSD */
+#define DEFAULT_MOUSE_DEV "/dev/mouse"
+#define DEFAULT_SYSMOUSE_DEV "/dev/sysmouse"
+#define DEFAULT_PS2_DEV "/dev/psm0"
+
+static const char *mouseDevs[] = {
+ DEFAULT_MOUSE_DEV,
+ DEFAULT_SYSMOUSE_DEV,
+ DEFAULT_PS2_DEV,
+ NULL
+};
+#elif defined(__OpenBSD__) && defined(WSCONS_SUPPORT)
+/* Only wsmouse mices are autoconfigured for now on OpenBSD */
+#define DEFAULT_WSMOUSE_DEV "/dev/wsmouse"
+#define DEFAULT_WSMOUSE0_DEV "/dev/wsmouse0"
+
+static const char *mouseDevs[] = {
+ DEFAULT_WSMOUSE_DEV,
+ DEFAULT_WSMOUSE0_DEV,
+ NULL
+};
+#endif
+
+static int
+SupportedInterfaces(void)
+{
+#if defined(__NetBSD__)
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_AUTO;
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_AUTO | MSE_MISC;
+#else
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO;
+#endif
+}
+
+/* Names of protocols that are handled internally here. */
+static const char *internalNames[] = {
+#if defined(WSCONS_SUPPORT)
+ "WSMouse",
+#endif
+#if defined(USBMOUSE_SUPPORT)
+ "usb",
+#endif
+ NULL
+};
+
+/*
+ * Names of MSC_MISC protocols that the OS supports. These are decoded by
+ * main "mouse" driver.
+ */
+static const char *miscNames[] = {
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ "SysMouse",
+#endif
+ NULL
+};
+
+static const char **
+BuiltinNames(void)
+{
+ return internalNames;
+}
+
+static Bool
+CheckProtocol(const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++)
+ if (xf86NameCmp(protocol, internalNames[i]) == 0)
+ return TRUE;
+ for (i = 0; miscNames[i]; i++)
+ if (xf86NameCmp(protocol, miscNames[i]) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+static const char *
+DefaultProtocol(void)
+{
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ return "Auto";
+#elif defined(__OpenBSD__) && defined(WSCONS_SUPPORT)
+ return "WSMouse";
+#else
+ return NULL;
+#endif
+}
+
+#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && defined(MOUSE_PROTO_SYSMOUSE)
+static struct {
+ int dproto;
+ const char *name;
+} devproto[] = {
+ { MOUSE_PROTO_MS, "Microsoft" },
+ { MOUSE_PROTO_MSC, "MouseSystems" },
+ { MOUSE_PROTO_LOGI, "Logitech" },
+ { MOUSE_PROTO_MM, "MMSeries" },
+ { MOUSE_PROTO_LOGIMOUSEMAN, "MouseMan" },
+ { MOUSE_PROTO_BUS, "BusMouse" },
+ { MOUSE_PROTO_INPORT, "BusMouse" },
+ { MOUSE_PROTO_PS2, "PS/2" },
+ { MOUSE_PROTO_HITTAB, "MMHitTab" },
+ { MOUSE_PROTO_GLIDEPOINT, "GlidePoint" },
+ { MOUSE_PROTO_INTELLI, "Intellimouse" },
+ { MOUSE_PROTO_THINK, "ThinkingMouse" },
+ { MOUSE_PROTO_SYSMOUSE, "SysMouse" }
+};
+
+static const char *
+SetupAuto(InputInfoPtr pInfo, int *protoPara)
+{
+ int i;
+ mousehw_t hw;
+ mousemode_t mode;
+
+ if (pInfo->fd == -1)
+ return NULL;
+
+ /* set the driver operation level, if applicable */
+ i = 1;
+ ioctl(pInfo->fd, MOUSE_SETLEVEL, &i);
+
+ /* interrogate the driver and get some intelligence on the device. */
+ hw.iftype = MOUSE_IF_UNKNOWN;
+ hw.model = MOUSE_MODEL_GENERIC;
+ ioctl(pInfo->fd, MOUSE_GETHWINFO, &hw);
+ xf86MsgVerb(X_INFO, 3, "%s: SetupAuto: hw.iftype is %d, hw.model is %d\n",
+ pInfo->name, hw.iftype, hw.model);
+ if (ioctl(pInfo->fd, MOUSE_GETMODE, &mode) == 0) {
+ for (i = 0; i < sizeof(devproto)/sizeof(devproto[0]); ++i) {
+ if (mode.protocol == devproto[i].dproto) {
+ /* override some parameters */
+ if (protoPara) {
+ protoPara[4] = mode.packetsize;
+ protoPara[0] = mode.syncmask[0];
+ protoPara[1] = mode.syncmask[1];
+ }
+ xf86MsgVerb(X_INFO, 3, "%s: SetupAuto: protocol is %s\n",
+ pInfo->name, devproto[i].name);
+ return devproto[i].name;
+ }
+ }
+ }
+ return NULL;
+}
+
+static void
+SetSysMouseRes(InputInfoPtr pInfo, const char *protocol, int rate, int res)
+{
+ mousemode_t mode;
+ MouseDevPtr pMse;
+
+ pMse = pInfo->private;
+
+ mode.rate = rate > 0 ? rate : -1;
+ mode.resolution = res > 0 ? res : -1;
+ mode.accelfactor = -1;
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ if (pMse->autoProbe ||
+ (protocol && xf86NameCmp(protocol, "SysMouse") == 0)) {
+ /*
+ * As the FreeBSD sysmouse driver defaults to protocol level 0
+ * everytime it is opened we enforce protocol level 1 again at
+ * this point.
+ */
+ mode.level = 1;
+ } else
+ mode.level = -1;
+#else
+ mode.level = -1;
+#endif
+ ioctl(pInfo->fd, MOUSE_SETMODE, &mode);
+}
+#endif
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+
+#define MOUSED_PID_FILE "/var/run/moused.pid"
+
+/*
+ * Try to check if moused is running. DEFAULT_SYSMOUSE_DEV is useless without
+ * it. There doesn't seem to be a better way of checking.
+ */
+static Bool
+MousedRunning(void)
+{
+ FILE *f = NULL;
+ unsigned int pid;
+
+ if ((f = fopen(MOUSED_PID_FILE, "r")) != NULL) {
+ if (fscanf(f, "%u", &pid) == 1 && pid > 0) {
+ if (kill(pid, 0) == 0) {
+ fclose(f);
+ return TRUE;
+ }
+ }
+ fclose(f);
+ }
+ return FALSE;
+}
+
+static const char *
+FindDevice(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ int fd = -1;
+ const char **pdev, *dev = NULL;
+ Bool devMouse = FALSE;
+ struct stat devMouseStat;
+ struct stat sb;
+
+ for (pdev = mouseDevs; *pdev; pdev++) {
+ SYSCALL (fd = open(*pdev, O_RDWR | O_NONBLOCK));
+ if (fd == -1) {
+#ifdef DEBUG
+ ErrorF("Cannot open %s (%s)\n", *pdev, strerror(errno));
+#endif
+ } else {
+ /*
+ * /dev/mouse is held until checks for matches with other devices
+ * are done. This is so that when it points to /dev/sysmouse,
+ * the test for whether /dev/sysmouse is usable can be made.
+ */
+ if (!strcmp(*pdev, DEFAULT_MOUSE_DEV)) {
+ if (fstat(fd, &devMouseStat) == 0)
+ devMouse = TRUE;
+ close(fd);
+ continue;
+ } else if (!strcmp(*pdev, DEFAULT_SYSMOUSE_DEV)) {
+ /* Check if /dev/mouse is the same as /dev/sysmouse. */
+ if (devMouse && fstat(fd, &sb) == 0 &&
+ devMouseStat.st_dev == sb.st_dev &&
+ devMouseStat.st_ino == sb.st_ino) {
+ /* If the same, use /dev/sysmouse. */
+ devMouse = FALSE;
+ }
+ close(fd);
+ if (MousedRunning())
+ break;
+ else {
+#ifdef DEBUG
+ ErrorF("moused isn't running\n");
+#endif
+ }
+ } else {
+ close(fd);
+ break;
+ }
+ }
+ }
+
+ if (*pdev)
+ dev = *pdev;
+ else if (devMouse)
+ dev = DEFAULT_MOUSE_DEV;
+
+ if (dev) {
+ /* Set the Device option. */
+ pInfo->conf_idev->commonOptions =
+ xf86AddNewOption(pInfo->conf_idev->commonOptions, "Device", dev);
+ xf86Msg(X_INFO, "%s: Setting Device option to \"%s\"\n",
+ pInfo->name, dev);
+ }
+
+ return *pdev;
+}
+#endif
+
+#if defined(__OpenBSD__) && defined(WSCONS_SUPPORT)
+
+/* Only support wsmouse configuration for now */
+static const char *
+SetupAuto(InputInfoPtr pInfo, int *protoPara)
+{
+
+ xf86MsgVerb(X_INFO, 3, "%s: SetupAuto: protocol is %s\n",
+ pInfo->name, "wsmouse");
+ return "wsmouse";
+}
+
+static void
+SetMouseRes(InputInfoPtr pInfo, const char *protocol, int rate, int res)
+{
+
+ xf86MsgVerb(X_INFO, 3, "%s: SetMouseRes: protocol %s rate %d res %d\n",
+ pInfo->name, protocol, rate, res);
+}
+
+static const char *
+FindDevice(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ int fd = -1;
+ const char **pdev;
+
+ for (pdev = mouseDevs; *pdev; pdev++) {
+ SYSCALL(fd = open(*pdev, O_RDWR | O_NONBLOCK));
+ if (fd != -1) {
+ /* Set the Device option. */
+ pInfo->conf_idev->commonOptions =
+ xf86AddNewOption(pInfo->conf_idev->commonOptions,
+ "Device", *pdev);
+ xf86Msg(X_INFO, "%s: found Device \"%s\"\n",
+ pInfo->name, *pdev);
+ close(fd);
+ break;
+ }
+ }
+ return *pdev;
+}
+#endif /* __OpenBSD__ && WSCONS_SUPPORT */
+
+#ifdef WSCONS_SUPPORT
+#define NUMEVENTS 64
+
+static void
+wsconsReadInput(InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse;
+ static struct wscons_event eventList[NUMEVENTS];
+ int n, c;
+ struct wscons_event *event = eventList;
+ unsigned char *pBuf;
+
+ pMse = pInfo->private;
+
+ XisbBlockDuration(pMse->buffer, -1);
+ pBuf = (unsigned char *)eventList;
+ n = 0;
+ while ((c = XisbRead(pMse->buffer)) >= 0 && n < sizeof(eventList)) {
+ pBuf[n++] = (unsigned char)c;
+ }
+
+ if (n == 0)
+ return;
+
+ n /= sizeof(struct wscons_event);
+ while( n-- ) {
+ int buttons = pMse->lastButtons;
+ int dx = 0, dy = 0, dz = 0, dw = 0;
+ switch (event->type) {
+ case WSCONS_EVENT_MOUSE_UP:
+#define BUTBIT (1 << (event->value <= 2 ? 2 - event->value : event->value))
+ buttons &= ~BUTBIT;
+ break;
+ case WSCONS_EVENT_MOUSE_DOWN:
+ buttons |= BUTBIT;
+ break;
+ case WSCONS_EVENT_MOUSE_DELTA_X:
+ dx = event->value;
+ break;
+ case WSCONS_EVENT_MOUSE_DELTA_Y:
+ dy = -event->value;
+ break;
+#ifdef WSCONS_EVENT_MOUSE_DELTA_Z
+ case WSCONS_EVENT_MOUSE_DELTA_Z:
+ dz = event->value;
+ break;
+#endif
+ default:
+ xf86Msg(X_WARNING, "%s: bad wsmouse event type=%d\n", pInfo->name,
+ event->type);
+ ++event;
+ continue;
+ }
+
+ pMse->PostEvent(pInfo, buttons, dx, dy, dz, dw);
+ ++event;
+ }
+ return;
+}
+
+
+/* This function is called when the protocol is "wsmouse". */
+static Bool
+wsconsPreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ MouseDevPtr pMse = pInfo->private;
+
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ /* Check if the device can be opened. */
+ pInfo->fd = xf86OpenSerial(pInfo->options);
+ if (pInfo->fd == -1) {
+ if (xf86GetAllowMouseOpenFail())
+ xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
+ else {
+ xf86Msg(X_ERROR, "%s: cannot open input device\n", pInfo->name);
+ xfree(pMse);
+ return FALSE;
+ }
+ }
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local input proc. */
+ pInfo->read_input = wsconsReadInput;
+ pMse->xisbscale = sizeof(struct wscons_event);
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+#endif
+
+#if defined(USBMOUSE_SUPPORT)
+
+typedef struct _UsbMseRec {
+ int packetSize;
+ int iid;
+ hid_item_t loc_x; /* x locator item */
+ hid_item_t loc_y; /* y locator item */
+ hid_item_t loc_z; /* z (wheel) locator item */
+ hid_item_t loc_btn[MSE_MAXBUTTONS]; /* buttons locator items */
+ unsigned char *buffer;
+} UsbMseRec, *UsbMsePtr;
+
+static int
+usbMouseProc(DeviceIntPtr pPointer, int what)
+{
+ InputInfoPtr pInfo;
+ MouseDevPtr pMse;
+ UsbMsePtr pUsbMse;
+ unsigned char map[MSE_MAXBUTTONS + 1];
+ int nbuttons;
+
+ pInfo = pPointer->public.devicePrivate;
+ pMse = pInfo->private;
+ pMse->device = pPointer;
+ pUsbMse = pMse->mousePriv;
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+
+ for (nbuttons = 0; nbuttons < MSE_MAXBUTTONS; ++nbuttons)
+ map[nbuttons + 1] = nbuttons + 1;
+
+ InitPointerDeviceStruct((DevicePtr)pPointer,
+ map,
+ min(pMse->buttons, MSE_MAXBUTTONS),
+ miPointerGetMotionEvents,
+ pMse->Ctrl,
+ miPointerGetMotionBufferSize());
+
+ /* X valuator */
+ xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 0);
+ /* Y valuator */
+ xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 1);
+ xf86MotionHistoryAllocate(pInfo);
+ break;
+
+ case DEVICE_ON:
+ pInfo->fd = xf86OpenSerial(pInfo->options);
+ if (pInfo->fd == -1)
+ xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
+ else {
+ pMse->buffer = XisbNew(pInfo->fd, pUsbMse->packetSize);
+ if (!pMse->buffer) {
+ xfree(pMse);
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+ } else {
+ xf86FlushInput(pInfo->fd);
+ if (!xf86InstallSIGIOHandler (pInfo->fd, usbSigioReadInput,
+ pInfo))
+ AddEnabledDevice(pInfo->fd);
+ }
+ }
+ pMse->lastButtons = 0;
+ pMse->lastMappedButtons = 0;
+ pMse->emulateState = 0;
+ pPointer->public.on = TRUE;
+ break;
+
+ case DEVICE_OFF:
+ case DEVICE_CLOSE:
+ if (pInfo->fd != -1) {
+ RemoveEnabledDevice(pInfo->fd);
+ if (pUsbMse->packetSize > 8 && pUsbMse->buffer) {
+ xfree(pUsbMse->buffer);
+ }
+ if (pMse->buffer) {
+ XisbFree(pMse->buffer);
+ pMse->buffer = NULL;
+ }
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+ }
+ pPointer->public.on = FALSE;
+ usleep(300000);
+ break;
+ }
+ return Success;
+}
+
+static void
+usbReadInput(InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse;
+ UsbMsePtr pUsbMse;
+ int buttons = pMse->lastButtons;
+ int dx = 0, dy = 0, dz = 0, dw = 0;
+ int n, c;
+ unsigned char *pBuf;
+
+ pMse = pInfo->private;
+ pUsbMse = pMse->mousePriv;
+
+ XisbBlockDuration(pMse->buffer, -1);
+ pBuf = pUsbMse->buffer;
+ n = 0;
+ while ((c = XisbRead(pMse->buffer)) >= 0 && n < pUsbMse->packetSize) {
+ pBuf[n++] = (unsigned char)c;
+ }
+ if (n == 0)
+ return;
+ if (n != pUsbMse->packetSize) {
+ xf86Msg(X_WARNING, "%s: incomplete packet, size %d\n", pInfo->name,
+ n);
+ }
+ /* discard packets with an id that don't match the mouse */
+ /* XXX this is probably not the right thing */
+ if (pUsbMse->iid != 0) {
+ if (*pBuf++ != pUsbMse->iid)
+ return;
+ }
+ dx = hid_get_data(pBuf, &pUsbMse->loc_x);
+ dy = hid_get_data(pBuf, &pUsbMse->loc_y);
+ dz = hid_get_data(pBuf, &pUsbMse->loc_z);
+
+ buttons = 0;
+ for (n = 0; n < pMse->buttons; n++) {
+ if (hid_get_data(pBuf, &pUsbMse->loc_btn[n]))
+ buttons |= (1 << UMS_BUT(n));
+ }
+ pMse->PostEvent(pInfo, buttons, dx, dy, dz, dw);
+ return;
+}
+
+static void
+usbSigioReadInput (int fd, void *closure)
+{
+ usbReadInput ((InputInfoPtr) closure);
+}
+
+/* This function is called when the protocol is "usb". */
+static Bool
+usbPreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ MouseDevPtr pMse = pInfo->private;
+ UsbMsePtr pUsbMse;
+ report_desc_t reportDesc;
+ int i;
+
+ pUsbMse = xalloc(sizeof(UsbMseRec));
+ if (pUsbMse == NULL) {
+ xf86Msg(X_ERROR, "%s: cannot allocate UsbMouseRec\n", pInfo->name);
+ xfree(pMse);
+ return FALSE;
+ }
+
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ /* Check if the device can be opened. */
+ pInfo->fd = xf86OpenSerial(pInfo->options);
+ if (pInfo->fd == -1) {
+ if (xf86GetAllowMouseOpenFail())
+ xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
+ else {
+ xf86Msg(X_ERROR, "%s: cannot open input device\n", pInfo->name);
+ xfree(pUsbMse);
+ xfree(pMse);
+ return FALSE;
+ }
+ }
+ /* Get USB informations */
+ reportDesc = hid_get_report_desc(pInfo->fd);
+ /* Get packet size & iid */
+#ifdef USB_NEW_HID
+ if (ioctl(pInfo->fd, USB_GET_REPORT_ID, &pUsbMse->iid) == -1) {
+ xf86Msg(X_ERROR, "Error ioctl USB_GET_REPORT_ID on %s : %s\n",
+ pInfo->name, strerror(errno));
+ return FALSE;
+ }
+ pUsbMse->packetSize = hid_report_size(reportDesc, hid_input,
+ pUsbMse->iid);
+#else
+ pUsbMse->packetSize = hid_report_size(reportDesc, hid_input,
+ &pUsbMse->iid);
+#endif
+ /* Allocate buffer */
+ if (pUsbMse->packetSize <= 8) {
+ pUsbMse->buffer = pMse->protoBuf;
+ } else {
+ pUsbMse->buffer = xalloc(pUsbMse->packetSize);
+ }
+ if (pUsbMse->buffer == NULL) {
+ xf86Msg(X_ERROR, "%s: cannot allocate buffer\n", pInfo->name);
+ xfree(pUsbMse);
+ xfree(pMse);
+ xf86CloseSerial(pInfo->fd);
+ return FALSE;
+ }
+#ifdef USB_NEW_HID
+ if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
+ hid_input, &pUsbMse->loc_x, pUsbMse->iid) < 0) {
+ xf86Msg(X_WARNING, "%s: no x locator\n", pInfo->name);
+ }
+ if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
+ hid_input, &pUsbMse->loc_y, pUsbMse->iid) < 0) {
+ xf86Msg(X_WARNING, "%s: no y locator\n", pInfo->name);
+ }
+ if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
+ hid_input, &pUsbMse->loc_z, pUsbMse->iid) < 0) {
+ }
+#else
+ if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
+ hid_input, &pUsbMse->loc_x) < 0) {
+ xf86Msg(X_WARNING, "%s: no x locator\n", pInfo->name);
+ }
+ if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
+ hid_input, &pUsbMse->loc_y) < 0) {
+ xf86Msg(X_WARNING, "%s: no y locator\n", pInfo->name);
+ }
+ if (hid_locate(reportDesc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
+ hid_input, &pUsbMse->loc_z) < 0) {
+ }
+#endif
+ /* Probe for number of buttons */
+ for (i = 1; i <= MSE_MAXBUTTONS; i++) {
+ if (!hid_locate(reportDesc, HID_USAGE2(HUP_BUTTON, i),
+ hid_input, &pUsbMse->loc_btn[i-1]
+#ifdef USB_NEW_HID
+ , pUsbMse->iid
+#endif
+ ))
+ break;
+ }
+ pMse->buttons = i-1;
+
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+
+ /* Private structure */
+ pMse->mousePriv = pUsbMse;
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local procs. */
+ pInfo->device_control = usbMouseProc;
+ pInfo->read_input = usbReadInput;
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+#endif /* USBMOUSE */
+
+static Bool
+bsdMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ /* The protocol is guaranteed to be one of the internalNames[] */
+#ifdef WSCONS_SUPPORT
+ if (xf86NameCmp(protocol, "WSMouse") == 0) {
+ return wsconsPreInit(pInfo, protocol, flags);
+ }
+#endif
+#ifdef USBMOUSE_SUPPORT
+ if (xf86NameCmp(protocol, "usb") == 0) {
+ return usbPreInit(pInfo, protocol, flags);
+ }
+#endif
+ return TRUE;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+ p->BuiltinNames = BuiltinNames;
+ p->DefaultProtocol = DefaultProtocol;
+ p->CheckProtocol = CheckProtocol;
+#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && defined(MOUSE_PROTO_SYSMOUSE)
+ p->SetupAuto = SetupAuto;
+ p->SetPS2Res = SetSysMouseRes;
+ p->SetBMRes = SetSysMouseRes;
+ p->SetMiscRes = SetSysMouseRes;
+#endif
+#if defined(__OpenBSD__) && defined(WSCONS_SUPPORT)
+ p->SetupAuto = SetupAuto;
+ p->SetMiscRes = SetMouseRes;
+#endif
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
+ p->FindDevice = FindDevice;
+#endif
+ p->PreInit = bsdMousePreInit;
+ return p;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/drm/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/drm/Imakefile
new file mode 100644
index 000000000..9cb04a516
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/drm/Imakefile
@@ -0,0 +1,63 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/drm/Imakefile,v 1.14 2003/05/08 21:49:01 herrb Exp $
+XCOMM $PI: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/Imakefile,v 1.7 1999/09/14 19:55:15 faith Exp $
+
+#define IHaveModules
+#include <Server.tmpl>
+
+#if DoLoadableServer
+MSRC = drmmodule.c
+MOBJ = drmmodule.o
+#endif
+
+#if BuildXF86DRI
+#if HasMTRRSupport
+MTRR_DEFINES = -DHAS_MTRR_SUPPORT
+#endif
+
+#if defined(KFreeBSDArchitecture)
+OS_SUBDIR = freebsd
+#elif defined(NetBSDArchitecture)
+OS_SUBDIR = netbsd
+#elif defined(OpenBSDArchitecture)
+OS_SUBDIR = openbsd
+#else
+OS_SUBDIR = extensions
+#endif
+
+ SRCS = xf86drm.c \
+ xf86drmHash.c \
+ xf86drmRandom.c \
+ xf86drmSL.c \
+ $(MSRC)
+
+ OBJS = xf86drm.o \
+ xf86drmHash.o \
+ xf86drmRandom.o \
+ xf86drmSL.o \
+ $(MOBJ)
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC) -I../.. -I$(DRMSRCDIR)/bsd-core \
+ -I$(DRMSRCDIR)/shared-core
+
+DEFINES = $(MTRR_DEFINES) $(GLX_DEFINES)
+
+ModuleObjectRule()
+LibraryModuleTarget(drm,$(OBJS))
+NormalLintTarget($(SRCS))
+
+InstallLibraryModule(drm,$(MODULEDIR),$(OS_SUBDIR))
+#endif
+
+DependTarget()
+
+LIBDRM_DIR = ../../../../../../../extras/drm/libdrm
+#if DoLoadableServer
+LinkSourceFile(drmmodule.c,$(XF86OSSRC)/linux/drm)
+#endif
+LinkSourceFile(xf86drm.c,$(LIBDRM_DIR))
+LinkSourceFile(xf86drmHash.c,$(LIBDRM_DIR))
+LinkSourceFile(xf86drmRandom.c,$(LIBDRM_DIR))
+LinkSourceFile(xf86drmSL.c,$(LIBDRM_DIR))
+
+InstallDriverSDKLibraryModule(drm,$(DRIVERSDKMODULEDIR),$(OS_SUBDIR))
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c
new file mode 100644
index 000000000..3f4cdb010
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c
@@ -0,0 +1,999 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c,v 1.4 2003/09/24 02:43:34 dawes Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XConsortium: bsd_video.c /main/10 1996/10/25 11:37:57 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+
+#include <errno.h>
+#include <sys/mman.h>
+
+#ifdef HAS_MTRR_SUPPORT
+#ifndef __NetBSD__
+#include <sys/types.h>
+#include <sys/memrange.h>
+#else
+#include "memrange.h"
+#endif
+#define X_MTRR_ID "XFree86"
+#endif
+
+#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
+#include <machine/mtrr.h>
+#include <machine/sysarch.h>
+#include <sys/queue.h>
+#endif
+
+#if defined(__OpenBSD__) && defined(__amd64__)
+#include <machine/mtrr.h>
+#include <machine/sysarch.h>
+#endif
+
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#if defined(__NetBSD__) && !defined(MAP_FILE)
+#define MAP_FLAGS MAP_SHARED
+#else
+#define MAP_FLAGS (MAP_FILE | MAP_SHARED)
+#endif
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((caddr_t)-1)
+#endif
+
+#ifdef __OpenBSD__
+#define SYSCTL_MSG "\tCheck that you have set 'machdep.allowaperture=1'\n"\
+ "\tin /etc/sysctl.conf and reboot your machine\n" \
+ "\trefer to xf86(4) for details"
+#define SYSCTL_MSG2 \
+ "Check that you have set 'machdep.allowaperture=2'\n" \
+ "\tin /etc/sysctl.conf and reboot your machine\n" \
+ "\trefer to xf86(4) for details"
+#endif
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+static Bool useDevMem = FALSE;
+static int devMemFd = -1;
+
+#ifdef HAS_APERTURE_DRV
+#define DEV_APERTURE "/dev/xf86"
+#endif
+#define DEV_MEM "/dev/mem"
+
+static pointer mapVidMem(int, unsigned long, unsigned long, int);
+static void unmapVidMem(int, pointer, unsigned long);
+
+#ifdef HAS_MTRR_SUPPORT
+static pointer setWC(int, unsigned long, unsigned long, Bool, MessageType);
+static void undoWC(int, pointer);
+static Bool cleanMTRR(void);
+#endif
+#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
+static pointer NetBSDsetWC(int, unsigned long, unsigned long, Bool,
+ MessageType);
+static void NetBSDundoWC(int, pointer);
+#endif
+#if defined(__amd64__) && defined(__OpenBSD__)
+static pointer amd64setWC(int, unsigned long, unsigned long, Bool,
+ MessageType);
+static void amd64undoWC(int, pointer);
+#endif
+
+/*
+ * Check if /dev/mem can be mmap'd. If it can't print a warning when
+ * "warn" is TRUE.
+ */
+static void
+checkDevMem(Bool warn)
+{
+ static Bool devMemChecked = FALSE;
+ int fd;
+ pointer base;
+
+ if (devMemChecked)
+ return;
+ devMemChecked = TRUE;
+
+ if ((fd = open(DEV_MEM, O_RDWR)) >= 0)
+ {
+ /* Try to map a page at the VGA address */
+ base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE,
+ MAP_FLAGS, fd, (off_t)0xA0000);
+
+ if (base != MAP_FAILED)
+ {
+ munmap((caddr_t)base, 4096);
+ devMemFd = fd;
+ useDevMem = TRUE;
+ return;
+ } else {
+ /* This should not happen */
+ if (warn)
+ {
+ xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ useDevMem = FALSE;
+ return;
+ }
+ }
+#ifndef HAS_APERTURE_DRV
+ if (warn)
+ {
+ xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ useDevMem = FALSE;
+ return;
+#else
+ /* Failed to open /dev/mem, try the aperture driver */
+ if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0)
+ {
+ /* Try to map a page at the VGA address */
+ base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE,
+ MAP_FLAGS, fd, (off_t)0xA0000);
+
+ if (base != MAP_FAILED)
+ {
+ munmap((caddr_t)base, 4096);
+ devMemFd = fd;
+ useDevMem = TRUE;
+ xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n",
+ DEV_APERTURE);
+ return;
+ } else {
+
+ if (warn)
+ {
+ xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n",
+ DEV_APERTURE, strerror(errno));
+ }
+ }
+ } else {
+ if (warn)
+ {
+#ifndef __OpenBSD__
+ xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
+ "\t(%s)\n", DEV_MEM, DEV_APERTURE, strerror(errno));
+#else /* __OpenBSD__ */
+ xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
+ "\t(%s)\n%s", DEV_MEM, DEV_APERTURE, strerror(errno),
+ SYSCTL_MSG);
+#endif /* __OpenBSD__ */
+ }
+ }
+
+ useDevMem = FALSE;
+ return;
+
+#endif
+}
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ checkDevMem(TRUE);
+ pVidMem->linearSupported = useDevMem;
+ pVidMem->mapMem = mapVidMem;
+ pVidMem->unmapMem = unmapVidMem;
+
+#ifdef HAS_MTRR_SUPPORT
+ if (useDevMem) {
+ if (cleanMTRR()) {
+ pVidMem->setWC = setWC;
+ pVidMem->undoWC = undoWC;
+ }
+ }
+#endif
+#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
+ pVidMem->setWC = NetBSDsetWC;
+ pVidMem->undoWC = NetBSDundoWC;
+#endif
+#if defined(__amd64__) && defined(__OpenBSD__)
+ pVidMem->setWC = amd64setWC;
+ pVidMem->undoWC = amd64undoWC;
+#endif
+ pVidMem->initialised = TRUE;
+}
+
+static pointer
+mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ pointer base;
+
+ checkDevMem(FALSE);
+
+ if (useDevMem)
+ {
+ if (devMemFd < 0)
+ {
+ FatalError("xf86MapVidMem: failed to open %s (%s)",
+ DEV_MEM, strerror(errno));
+ }
+ base = mmap((caddr_t)0, Size,
+ (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_FLAGS, devMemFd, (off_t)Base);
+ if (base == MAP_FAILED)
+ {
+ FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)",
+ "xf86MapVidMem", DEV_MEM, Size, Base,
+ strerror(errno));
+ }
+ return(base);
+ }
+
+ /* else, mmap /dev/vga */
+ if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000)
+ {
+ FatalError("%s: Address 0x%lx outside allowable range",
+ "xf86MapVidMem", Base);
+ }
+ base = mmap(0, Size,
+ (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_FLAGS, xf86Info.screenFd,
+ (unsigned long)Base - 0xA0000
+ );
+ if (base == MAP_FAILED)
+ {
+ FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)",
+ strerror(errno));
+ }
+ return(base);
+}
+
+static void
+unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap((caddr_t)Base, Size);
+}
+
+/*
+ * Read BIOS via mmap()ing DEV_MEM
+ */
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+ unsigned char *ptr;
+ int psize;
+ int mlen;
+
+ checkDevMem(TRUE);
+ if (devMemFd == -1) {
+ return(-1);
+ }
+
+ psize = xf86getpagesize();
+ Offset += Base & (psize - 1);
+ Base &= ~(psize - 1);
+ mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+ ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ,
+ MAP_SHARED, devMemFd, (off_t)Base);
+ if ((long)ptr == -1)
+ {
+ xf86Msg(X_WARNING,
+ "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n",
+ DEV_MEM, Len, Base, Offset, strerror(errno));
+#ifdef __OpenBSD__
+ if (Base < 0xa0000) {
+ xf86Msg(X_WARNING, SYSCTL_MSG2);
+ }
+#endif
+ return(-1);
+ }
+#ifdef DEBUG
+ ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
+ Base, ptr[0] | (ptr[1] << 8));
+#endif
+ (void)memcpy(Buf, (void *)(ptr + Offset), Len);
+ (void)munmap((caddr_t)ptr, mlen);
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)"
+ "-> %02x %02x %02x %02x...\n",
+ Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]);
+#endif
+ return(Len);
+}
+
+#ifdef USE_I386_IOPL
+/***************************************************************************/
+/* I/O Permissions section */
+/***************************************************************************/
+
+static Bool ExtendedEnabled = FALSE;
+
+Bool
+xf86EnableIO()
+{
+ if (ExtendedEnabled)
+ return TRUE;
+
+ if (i386_iopl(TRUE) < 0)
+ {
+#ifndef __OpenBSD__
+ xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O",
+ "xf86EnableIO");
+#else
+ xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n%s",
+ "xf86EnableIO", SYSCTL_MSG);
+#endif
+ return FALSE;
+ }
+ ExtendedEnabled = TRUE;
+
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ if (!ExtendedEnabled)
+ return;
+
+ i386_iopl(FALSE);
+ ExtendedEnabled = FALSE;
+
+ return;
+}
+
+#endif /* USE_I386_IOPL */
+
+#ifdef USE_AMD64_IOPL
+/***************************************************************************/
+/* I/O Permissions section */
+/***************************************************************************/
+
+static Bool ExtendedEnabled = FALSE;
+
+Bool
+xf86EnableIO()
+{
+ if (ExtendedEnabled)
+ return TRUE;
+
+ if (amd64_iopl(TRUE) < 0)
+ {
+#ifndef __OpenBSD__
+ xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O",
+ "xf86EnableIO");
+#else
+ xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n%s",
+ "xf86EnableIO", SYSCTL_MSG);
+#endif
+ return FALSE;
+ }
+ ExtendedEnabled = TRUE;
+
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ if (!ExtendedEnabled)
+ return;
+
+ if (amd64_iopl(FALSE) == 0) {
+ ExtendedEnabled = FALSE;
+ }
+ /* Otherwise, the X server has revoqued its root uid,
+ and thus cannot give up IO privileges any more */
+
+ return;
+}
+
+#endif /* USE_AMD64_IOPL */
+
+#ifdef USE_DEV_IO
+static int IoFd = -1;
+
+Bool
+xf86EnableIO()
+{
+ if (IoFd >= 0)
+ return TRUE;
+
+ if ((IoFd = open("/dev/io", O_RDWR)) == -1)
+ {
+ xf86Msg(X_WARNING,"xf86EnableIO: "
+ "Failed to open /dev/io for extended I/O");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ if (IoFd < 0)
+ return;
+
+ close(IoFd);
+ IoFd = -1;
+ return;
+}
+
+#endif
+
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts()
+{
+
+#ifdef __GNUC__
+ __asm__ __volatile__("cli");
+#else
+ asm("cli");
+#endif /* __GNUC__ */
+
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+
+#ifdef __GNUC__
+ __asm__ __volatile__("sti");
+#else
+ asm("sti");
+#endif /* __GNUC__ */
+
+ return;
+}
+
+
+#ifdef __NetBSD__
+/***************************************************************************/
+/* Set TV output mode */
+/***************************************************************************/
+void
+xf86SetTVOut(int mode)
+{
+ switch (xf86Info.consType)
+ {
+#ifdef PCCONS_SUPPORT
+ case PCCONS:{
+
+ if (ioctl (xf86Info.consoleFd, CONSOLE_X_TV_ON, &mode) < 0)
+ {
+ xf86Msg(X_WARNING,
+ "xf86SetTVOut: Could not set console to TV output, %s\n",
+ strerror(errno));
+ }
+ }
+ break;
+#endif /* PCCONS_SUPPORT */
+
+ default:
+ FatalError("Xf86SetTVOut: Unsupported console");
+ break;
+ }
+ return;
+}
+
+void
+xf86SetRGBOut()
+{
+ switch (xf86Info.consType)
+ {
+#ifdef PCCONS_SUPPORT
+ case PCCONS:{
+
+ if (ioctl (xf86Info.consoleFd, CONSOLE_X_TV_OFF, 0) < 0)
+ {
+ xf86Msg(X_WARNING,
+ "xf86SetTVOut: Could not set console to RGB output, %s\n",
+ strerror(errno));
+ }
+ }
+ break;
+#endif /* PCCONS_SUPPORT */
+
+ default:
+ FatalError("Xf86SetTVOut: Unsupported console");
+ break;
+ }
+ return;
+}
+#endif
+
+#ifdef HAS_MTRR_SUPPORT
+/* memory range (MTRR) support for FreeBSD */
+
+/*
+ * This code is experimental. Some parts may be overkill, and other parts
+ * may be incomplete.
+ */
+
+/*
+ * getAllRanges returns the full list of memory ranges with attributes set.
+ */
+
+static struct mem_range_desc *
+getAllRanges(int *nmr)
+{
+ struct mem_range_desc *mrd;
+ struct mem_range_op mro;
+
+ /*
+ * Find how many ranges there are. If this fails, then the kernel
+ * probably doesn't have MTRR support.
+ */
+ mro.mo_arg[0] = 0;
+ if (ioctl(devMemFd, MEMRANGE_GET, &mro))
+ return NULL;
+ *nmr = mro.mo_arg[0];
+ mrd = xnfalloc(*nmr * sizeof(struct mem_range_desc));
+ mro.mo_arg[0] = *nmr;
+ mro.mo_desc = mrd;
+ if (ioctl(devMemFd, MEMRANGE_GET, &mro)) {
+ xfree(mrd);
+ return NULL;
+ }
+ return mrd;
+}
+
+/*
+ * cleanMTRR removes any memory attribute that may be left by a previous
+ * X server. Normally there won't be any, but this takes care of the
+ * case where a server crashed without being able finish cleaning up.
+ */
+
+static Bool
+cleanMTRR()
+{
+ struct mem_range_desc *mrd;
+ struct mem_range_op mro;
+ int nmr, i;
+
+ /* This shouldn't happen */
+ if (devMemFd < 0)
+ return FALSE;
+
+ if (!(mrd = getAllRanges(&nmr)))
+ return FALSE;
+
+ for (i = 0; i < nmr; i++) {
+ if (strcmp(mrd[i].mr_owner, X_MTRR_ID) == 0 &&
+ (mrd[i].mr_flags & MDF_ACTIVE)) {
+#ifdef DEBUG
+ ErrorF("Clean for (0x%lx,0x%lx)\n",
+ (unsigned long)mrd[i].mr_base,
+ (unsigned long)rd[i].mr_len);
+#endif
+ if (mrd[i].mr_flags & MDF_FIXACTIVE) {
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ mrd[i].mr_flags = MDF_UNCACHEABLE;
+ } else {
+ mro.mo_arg[0] = MEMRANGE_SET_REMOVE;
+ }
+ mro.mo_desc = mrd + i;
+ ioctl(devMemFd, MEMRANGE_SET, &mro);
+ }
+ }
+#ifdef DEBUG
+ sleep(10);
+#endif
+ xfree(mrd);
+ return TRUE;
+}
+
+typedef struct x_RangeRec {
+ struct mem_range_desc mrd;
+ Bool wasWC;
+ struct x_RangeRec * next;
+} RangeRec, *RangePtr;
+
+static void
+freeRangeList(RangePtr range)
+{
+ RangePtr rp;
+
+ while (range) {
+ rp = range;
+ range = rp->next;
+ xfree(rp);
+ }
+}
+
+static RangePtr
+dupRangeList(RangePtr list)
+{
+ RangePtr new = NULL, rp, p;
+
+ rp = list;
+ while (rp) {
+ p = xnfalloc(sizeof(RangeRec));
+ *p = *rp;
+ p->next = new;
+ new = p;
+ rp = rp->next;
+ }
+ return new;
+}
+
+static RangePtr
+sortRangeList(RangePtr list)
+{
+ RangePtr rp1, rp2, copy, sorted = NULL, minp, prev, minprev;
+ unsigned long minBase;
+
+ /* Sort by base address */
+ rp1 = copy = dupRangeList(list);
+ while (rp1) {
+ minBase = rp1->mrd.mr_base;
+ minp = rp1;
+ minprev = NULL;
+ prev = rp1;
+ rp2 = rp1->next;
+ while (rp2) {
+ if (rp2->mrd.mr_base < minBase) {
+ minBase = rp2->mrd.mr_base;
+ minp = rp2;
+ minprev = prev;
+ }
+ prev = rp2;
+ rp2 = rp2->next;
+ }
+ if (minprev) {
+ minprev->next = minp->next;
+ rp1 = copy;
+ } else {
+ rp1 = minp->next;
+ }
+ minp->next = sorted;
+ sorted = minp;
+ }
+ return sorted;
+}
+
+/*
+ * findRanges returns a list of ranges that overlap the specified range.
+ */
+
+static void
+findRanges(unsigned long base, unsigned long size, RangePtr *ucp, RangePtr *wcp)
+{
+ struct mem_range_desc *mrd;
+ int nmr, i;
+ RangePtr rp, *p;
+
+ if (!(mrd = getAllRanges(&nmr)))
+ return;
+
+ for (i = 0; i < nmr; i++) {
+ if ((mrd[i].mr_flags & MDF_ACTIVE) &&
+ mrd[i].mr_base < base + size &&
+ mrd[i].mr_base + mrd[i].mr_len > base) {
+ if (mrd[i].mr_flags & MDF_WRITECOMBINE)
+ p = wcp;
+ else if (mrd[i].mr_flags & MDF_UNCACHEABLE)
+ p = ucp;
+ else
+ continue;
+ rp = xnfalloc(sizeof(RangeRec));
+ rp->mrd = mrd[i];
+ rp->next = *p;
+ *p = rp;
+ }
+ }
+ xfree(mrd);
+}
+
+/*
+ * This checks if the existing overlapping ranges fully cover the requested
+ * range. Is this overkill?
+ */
+
+static Bool
+fullCoverage(unsigned long base, unsigned long size, RangePtr overlap)
+{
+ RangePtr rp1, sorted = NULL;
+ unsigned long end;
+
+ sorted = sortRangeList(overlap);
+ /* Look for gaps */
+ rp1 = sorted;
+ end = base + size;
+ while (rp1) {
+ if (rp1->mrd.mr_base > base) {
+ freeRangeList(sorted);
+ return FALSE;
+ } else {
+ base = rp1->mrd.mr_base + rp1->mrd.mr_len;
+ }
+ if (base >= end) {
+ freeRangeList(sorted);
+ return TRUE;
+ }
+ rp1 = rp1->next;
+ }
+ freeRangeList(sorted);
+ return FALSE;
+}
+
+static pointer
+addWC(int screenNum, unsigned long base, unsigned long size, MessageType from)
+{
+ RangePtr uc = NULL, wc = NULL, retlist = NULL;
+ struct mem_range_desc mrd;
+ struct mem_range_op mro;
+
+ findRanges(base, size, &uc, &wc);
+
+ /* See of the full range is already WC */
+ if (!uc && fullCoverage(base, size, wc)) {
+ xf86DrvMsg(screenNum, from,
+ "Write-combining range (0x%lx,0x%lx) was already set\n",
+ base, size);
+ return NULL;
+ }
+
+ /* Otherwise, try to add the new range */
+ mrd.mr_base = base;
+ mrd.mr_len = size;
+ strcpy(mrd.mr_owner, X_MTRR_ID);
+ mrd.mr_flags = MDF_WRITECOMBINE;
+ mro.mo_desc = &mrd;
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "Failed to set write-combining range "
+ "(0x%lx,0x%lx)\n", base, size);
+ return NULL;
+ } else {
+ xf86DrvMsg(screenNum, from,
+ "Write-combining range (0x%lx,0x%lx)\n", base, size);
+ retlist = xnfalloc(sizeof(RangeRec));
+ retlist->mrd = mrd;
+ retlist->wasWC = FALSE;
+ retlist->next = NULL;
+ return retlist;
+ }
+}
+
+static pointer
+delWC(int screenNum, unsigned long base, unsigned long size, MessageType from)
+{
+ RangePtr uc = NULL, wc = NULL, retlist = NULL;
+ struct mem_range_desc mrd;
+ struct mem_range_op mro;
+
+ findRanges(base, size, &uc, &wc);
+
+ /*
+ * See of the full range is already not WC, or if there is full
+ * coverage from UC ranges.
+ */
+ if (!wc || fullCoverage(base, size, uc)) {
+ xf86DrvMsg(screenNum, from,
+ "Write-combining range (0x%lx,0x%lx) was already clear\n",
+ base, size);
+ return NULL;
+ }
+
+ /* Otherwise, try to add the new range */
+ mrd.mr_base = base;
+ mrd.mr_len = size;
+ strcpy(mrd.mr_owner, X_MTRR_ID);
+ mrd.mr_flags = MDF_UNCACHEABLE;
+ mro.mo_desc = &mrd;
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "Failed to remove write-combining range "
+ "(0x%lx,0x%lx)\n", base, size);
+ /* XXX Should then remove all of the overlapping WC ranges */
+ return NULL;
+ } else {
+ xf86DrvMsg(screenNum, from,
+ "Removed Write-combining range (0x%lx,0x%lx)\n",
+ base, size);
+ retlist = xnfalloc(sizeof(RangeRec));
+ retlist->mrd = mrd;
+ retlist->wasWC = TRUE;
+ retlist->next = NULL;
+ return retlist;
+ }
+}
+
+static pointer
+setWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
+ MessageType from)
+{
+ if (enable)
+ return addWC(screenNum, base, size, from);
+ else
+ return delWC(screenNum, base, size, from);
+}
+
+static void
+undoWC(int screenNum, pointer list)
+{
+ RangePtr rp;
+ struct mem_range_op mro;
+ Bool failed;
+
+ rp = list;
+ while (rp) {
+#ifdef DEBUG
+ ErrorF("Undo for (0x%lx,0x%lx), %d\n",
+ (unsigned long)rp->mrd.mr_base,
+ (unsigned long)rp->mrd.mr_len, rp->wasWC);
+#endif
+ failed = FALSE;
+ if (rp->wasWC) {
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ rp->mrd.mr_flags = MDF_WRITECOMBINE;
+ strcpy(rp->mrd.mr_owner, "unknown");
+ } else {
+ mro.mo_arg[0] = MEMRANGE_SET_REMOVE;
+ }
+ mro.mo_desc = &rp->mrd;
+
+ if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
+ if (!rp->wasWC) {
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ rp->mrd.mr_flags = MDF_UNCACHEABLE;
+ strcpy(rp->mrd.mr_owner, "unknown");
+ if (ioctl(devMemFd, MEMRANGE_SET, &mro))
+ failed = TRUE;
+ } else
+ failed = TRUE;
+ }
+ if (failed) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "Failed to restore MTRR range (0x%lx,0x%lx)\n",
+ (unsigned long)rp->mrd.mr_base,
+ (unsigned long)rp->mrd.mr_len);
+ }
+ rp = rp->next;
+ }
+}
+
+#endif /* HAS_MTRR_SUPPORT */
+
+
+#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
+static pointer
+NetBSDsetWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
+ MessageType from)
+{
+ struct mtrr *mtrrp;
+ int n;
+
+ xf86DrvMsg(screenNum, X_WARNING,
+ "%s MTRR %lx - %lx\n", enable ? "set" : "remove",
+ base, (base + size));
+
+ mtrrp = xnfalloc(sizeof (struct mtrr));
+ mtrrp->base = base;
+ mtrrp->len = size;
+ mtrrp->type = MTRR_TYPE_WC;
+
+ /*
+ * MTRR_PRIVATE will make this MTRR get reset automatically
+ * if this process exits, so we have no need for an explicit
+ * cleanup operation when starting a new server.
+ */
+
+ if (enable)
+ mtrrp->flags = MTRR_VALID | MTRR_PRIVATE;
+ else
+ mtrrp->flags = 0;
+ n = 1;
+
+ if (i386_set_mtrr(mtrrp, &n) < 0) {
+ xfree(mtrrp);
+ return NULL;
+ }
+ return mtrrp;
+}
+
+static void
+NetBSDundoWC(int screenNum, pointer list)
+{
+ struct mtrr *mtrrp = (struct mtrr *)list;
+ int n;
+
+ if (mtrrp == NULL)
+ return;
+ n = 1;
+ mtrrp->flags &= ~MTRR_VALID;
+ i386_set_mtrr(mtrrp, &n);
+ xfree(mtrrp);
+}
+#endif
+
+#if defined(__OpenBSD__) && defined(__amd64__)
+static pointer
+amd64setWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
+ MessageType from)
+{
+ struct mtrr *mtrrp;
+ int n;
+
+ xf86DrvMsg(screenNum, X_WARNING,
+ "%s MTRR %lx - %lx\n", enable ? "set" : "remove",
+ base, (base + size));
+
+ mtrrp = xnfalloc(sizeof (struct mtrr));
+ mtrrp->base = base;
+ mtrrp->len = size;
+ mtrrp->type = MTRR_TYPE_WC;
+
+ /*
+ * MTRR_PRIVATE will make this MTRR get reset automatically
+ * if this process exits, so we have no need for an explicit
+ * cleanup operation when starting a new server.
+ */
+
+ if (enable)
+ mtrrp->flags = MTRR_VALID | MTRR_PRIVATE;
+ else
+ mtrrp->flags = 0;
+ n = 1;
+
+ if (amd64_set_mtrr(mtrrp, &n) < 0) {
+ xfree(mtrrp);
+ return NULL;
+ }
+ return mtrrp;
+}
+
+static void
+amd64undoWC(int screenNum, pointer list)
+{
+ struct mtrr *mtrrp = (struct mtrr *)list;
+ int n;
+
+ if (mtrrp == NULL)
+ return;
+ n = 1;
+ mtrrp->flags &= ~MTRR_VALID;
+ amd64_set_mtrr(mtrrp, &n);
+ xfree(mtrrp);
+}
+#endif /* OpenBSD/amd64 */
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/Imakefile
new file mode 100644
index 000000000..15b784797
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/Imakefile
@@ -0,0 +1,10 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/libusb/Imakefile,v 1.1.2.1 1999/12/01 12:49:27 hohndel Exp $
+
+#include <Server.tmpl>
+
+SRCS = data.c descr.c parse.c usage.c
+OBJS = data.o descr.o parse.o usage.o
+
+NormalLibraryObjectRule()
+NormalLibraryTarget(usb,$(OBJS))
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/data.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/data.c
new file mode 100644
index 000000000..0ac1a63bc
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/data.c
@@ -0,0 +1,95 @@
+/* $NetBSD: data.c,v 1.6 1999/09/20 04:48:12 lukem Exp $ */
+
+/*
+ * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/libusb/data.c,v 1.1.2.2 1999/12/03 10:12:41 hohndel Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include "usb.h"
+
+int
+hid_get_data(void *p, hid_item_t *h)
+{
+ unsigned char *buf;
+ unsigned int hpos;
+ unsigned int hsize;
+ int data;
+ int i, end, offs;
+
+ _DIAGASSERT(p != NULL);
+ _DIAGASSERT(h != NULL);
+
+ buf = p;
+ hpos = h->pos; /* bit position of data */
+ hsize = h->report_size; /* bit length of data */
+
+ if (hsize == 0)
+ return (0);
+ offs = hpos / 8;
+ end = (hpos + hsize) / 8 - offs;
+ data = 0;
+ for (i = 0; i <= end; i++)
+ data |= buf[offs + i] << (i*8);
+ data >>= hpos % 8;
+ data &= (1 << hsize) - 1;
+ if (h->logical_minimum < 0) {
+ /* Need to sign extend */
+ hsize = sizeof data * 8 - hsize;
+ data = (data << hsize) >> hsize;
+ }
+ return (data);
+}
+
+void
+hid_set_data(void *p, hid_item_t *h, int data)
+{
+ unsigned char *buf;
+ unsigned int hpos;
+ unsigned int hsize;
+ int i, end, offs;
+
+ _DIAGASSERT(p != NULL);
+ _DIAGASSERT(h != NULL);
+
+ buf = p;
+ hpos = h->pos; /* bit position of data */
+ hsize = h->report_size; /* bit length of data */
+
+ if (hsize != 32)
+ data &= (1 << hsize) - 1;
+ data <<= (hpos % 8);
+
+ offs = hpos / 8;
+ end = (hpos + hsize) / 8 - offs;
+ data = 0;
+ for (i = 0; i <= end; i++)
+ buf[offs + i] |= (data >> (i*8)) & 0xff;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/descr.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/descr.c
new file mode 100644
index 000000000..2306d2f58
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/descr.c
@@ -0,0 +1,76 @@
+/* $NetBSD: descr.c,v 1.7 1999/10/13 17:48:04 drochner Exp $ */
+
+/*
+ * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/libusb/descr.c,v 1.1.2.2 1999/12/03 10:12:42 hohndel Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/types.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <dev/usb/usb.h>
+
+#include "usb.h"
+#include "usbvar.h"
+
+report_desc_t
+hid_get_report_desc(fd)
+ int fd;
+{
+ struct usb_ctl_report_desc rep;
+ report_desc_t r;
+
+ _DIAGASSERT(fd != -1);
+
+ rep.size = 0;
+ if (ioctl(fd, USB_GET_REPORT_DESC, &rep) < 0)
+ return (0);
+ r = malloc(sizeof *r + rep.size);
+ if (r == 0) {
+ errno = ENOMEM;
+ return (0);
+ }
+ r->size = rep.size;
+ memcpy(r->data, rep.data, (unsigned int)rep.size);
+ return (r);
+}
+
+void
+hid_dispose_report_desc(r)
+ report_desc_t r;
+{
+
+ free(r);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/parse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/parse.c
new file mode 100644
index 000000000..feff9779a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/parse.c
@@ -0,0 +1,404 @@
+/* $NetBSD: parse.c,v 1.7 1999/10/13 17:48:04 drochner Exp $ */
+
+/*
+ * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/libusb/parse.c,v 1.1.2.2 1999/12/03 10:12:42 hohndel Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+
+#include "usb.h"
+#include "usbvar.h"
+
+#define MAXUSAGE 100
+struct hid_data {
+ u_char *start;
+ u_char *end;
+ u_char *p;
+ hid_item_t cur;
+ unsigned int usages[MAXUSAGE];
+ int nusage;
+ int minset;
+ int multi;
+ int multimax;
+ int kindset;
+};
+
+static int min(int x, int y) { return x < y ? x : y; }
+
+static void
+hid_clear_local(hid_item_t *c)
+{
+
+ _DIAGASSERT(c != NULL);
+
+ c->usage = 0;
+ c->usage_minimum = 0;
+ c->usage_maximum = 0;
+ c->designator_index = 0;
+ c->designator_minimum = 0;
+ c->designator_maximum = 0;
+ c->string_index = 0;
+ c->string_minimum = 0;
+ c->string_maximum = 0;
+ c->set_delimiter = 0;
+}
+
+hid_data_t
+hid_start_parse(report_desc_t d, int kindset)
+{
+ struct hid_data *s;
+
+ _DIAGASSERT(d != NULL);
+
+ s = malloc(sizeof *s);
+ memset(s, 0, sizeof *s);
+ s->start = s->p = d->data;
+ s->end = d->data + d->size;
+ s->kindset = kindset;
+ return (s);
+}
+
+void
+hid_end_parse(hid_data_t s)
+{
+
+ _DIAGASSERT(s != NULL);
+
+ while (s->cur.next) {
+ hid_item_t *hi = s->cur.next->next;
+ free(s->cur.next);
+ s->cur.next = hi;
+ }
+ free(s);
+}
+
+int
+hid_get_item(hid_data_t s, hid_item_t *h)
+{
+ hid_item_t *c;
+ unsigned int bTag = 0, bType = 0, bSize;
+ unsigned char *data;
+ int dval;
+ unsigned char *p;
+ hid_item_t *hi;
+ int i;
+
+ _DIAGASSERT(s != NULL);
+ _DIAGASSERT(h != NULL);
+
+ c = &s->cur;
+
+ top:
+ if (s->multimax) {
+ if (s->multi < s->multimax) {
+ c->usage = s->usages[min(s->multi, s->nusage-1)];
+ s->multi++;
+ *h = *c;
+ c->pos += c->report_size;
+ h->next = 0;
+ return (1);
+ } else {
+ c->report_count = s->multimax;
+ s->multimax = 0;
+ s->nusage = 0;
+ hid_clear_local(c);
+ }
+ }
+ for (;;) {
+ p = s->p;
+ if (p >= s->end)
+ return (0);
+
+ bSize = *p++;
+ if (bSize == 0xfe) {
+ /* long item */
+ bSize = *p++;
+ bSize |= *p++ << 8;
+ bTag = *p++;
+ data = p;
+ p += bSize;
+ } else {
+ /* short item */
+ bTag = bSize >> 4;
+ bType = (bSize >> 2) & 3;
+ bSize &= 3;
+ if (bSize == 3) bSize = 4;
+ data = p;
+ p += bSize;
+ }
+ s->p = p;
+ /*
+ * The spec is unclear if the data is signed or unsigned.
+ */
+ switch(bSize) {
+ case 0:
+ dval = 0;
+ break;
+ case 1:
+ dval = (int8_t)*data++;
+ break;
+ case 2:
+ dval = *data++;
+ dval |= *data++ << 8;
+ dval = (int16_t)dval;
+ break;
+ case 4:
+ dval = *data++;
+ dval |= *data++ << 8;
+ dval |= *data++ << 16;
+ dval |= *data++ << 24;
+ break;
+ default:
+ return (-1);
+ }
+
+ switch (bType) {
+ case 0: /* Main */
+ switch (bTag) {
+ case 8: /* Input */
+ if (!(s->kindset & (1 << hid_input)))
+ continue;
+ c->kind = hid_input;
+ c->flags = dval;
+ ret:
+ if (c->flags & HIO_VARIABLE) {
+ s->multimax = c->report_count;
+ s->multi = 0;
+ c->report_count = 1;
+ if (s->minset) {
+ for (i = c->usage_minimum;
+ i <= c->usage_maximum;
+ i++) {
+ s->usages[s->nusage] = i;
+ if (s->nusage < MAXUSAGE-1)
+ s->nusage++;
+ }
+ s->minset = 0;
+ }
+ goto top;
+ } else {
+ if (s->minset)
+ c->usage = c->usage_minimum;
+ *h = *c;
+ h->next = 0;
+ c->pos += c->report_size * c->report_count;
+ hid_clear_local(c);
+ s->minset = 0;
+ return (1);
+ }
+ case 9: /* Output */
+ if (!(s->kindset & (1 << hid_output)))
+ continue;
+ c->kind = hid_output;
+ c->flags = dval;
+ goto ret;
+ case 10: /* Collection */
+ c->kind = hid_collection;
+ c->collection = dval;
+ c->collevel++;
+ *h = *c;
+ hid_clear_local(c);
+ s->nusage = 0;
+ return (1);
+ case 11: /* Feature */
+ if (!(s->kindset & (1 << hid_feature)))
+ continue;
+ c->kind = hid_feature;
+ c->flags = dval;
+ goto ret;
+ case 12: /* End collection */
+ c->kind = hid_endcollection;
+ c->collevel--;
+ *h = *c;
+ hid_clear_local(c);
+ s->nusage = 0;
+ return (1);
+ default:
+ return (-2);
+ }
+
+ case 1: /* Global */
+ switch (bTag) {
+ case 0:
+ c->_usage_page = dval << 16;
+ break;
+ case 1:
+ c->logical_minimum = dval;
+ break;
+ case 2:
+ c->logical_maximum = dval;
+ break;
+ case 3:
+ c->physical_maximum = dval;
+ break;
+ case 4:
+ c->physical_maximum = dval;
+ break;
+ case 5:
+ c->unit_exponent = dval;
+ break;
+ case 6:
+ c->unit = dval;
+ break;
+ case 7:
+ c->report_size = dval;
+ break;
+ case 8:
+ c->report_ID = dval;
+ break;
+ case 9:
+ c->report_count = dval;
+ break;
+ case 10: /* Push */
+ hi = malloc(sizeof *hi);
+ *hi = s->cur;
+ c->next = hi;
+ break;
+ case 11: /* Pop */
+ hi = c->next;
+ s->cur = *hi;
+ free(hi);
+ break;
+ default:
+ return (-3);
+ }
+ break;
+ case 2: /* Local */
+ switch (bTag) {
+ case 0:
+ if (bSize == 1)
+ dval = c->_usage_page | (dval&0xff);
+ else if (bSize == 2)
+ dval = c->_usage_page | (dval&0xffff);
+ c->usage = dval;
+ if (s->nusage < MAXUSAGE)
+ s->usages[s->nusage++] = dval;
+ /* else XXX */
+ break;
+ case 1:
+ s->minset = 1;
+ if (bSize == 1)
+ dval = c->_usage_page | (dval&0xff);
+ else if (bSize == 2)
+ dval = c->_usage_page | (dval&0xffff);
+ c->usage_minimum = dval;
+ break;
+ case 2:
+ if (bSize == 1)
+ dval = c->_usage_page | (dval&0xff);
+ else if (bSize == 2)
+ dval = c->_usage_page | (dval&0xffff);
+ c->usage_maximum = dval;
+ break;
+ case 3:
+ c->designator_index = dval;
+ break;
+ case 4:
+ c->designator_minimum = dval;
+ break;
+ case 5:
+ c->designator_maximum = dval;
+ break;
+ case 7:
+ c->string_index = dval;
+ break;
+ case 8:
+ c->string_minimum = dval;
+ break;
+ case 9:
+ c->string_maximum = dval;
+ break;
+ case 10:
+ c->set_delimiter = dval;
+ break;
+ default:
+ return (-4);
+ }
+ break;
+ default:
+ return (-5);
+ }
+ }
+}
+
+int
+hid_report_size(report_desc_t r, enum hid_kind k, int *idp)
+{
+ struct hid_data *d;
+ hid_item_t h;
+ int size, id;
+
+ _DIAGASSERT(r != NULL);
+ /* idp may be NULL */
+
+ id = 0;
+ if (idp)
+ *idp = 0;
+ memset(&h, 0, sizeof h);
+ for (d = hid_start_parse(r, 1<<k); hid_get_item(d, &h); ) {
+ if (h.report_ID != 0) {
+ if (idp)
+ *idp = h.report_ID;
+ id = 8;
+ }
+ }
+ hid_end_parse(d);
+ size = h.pos + id;
+ return ((size + 7) / 8);
+}
+
+int
+hid_locate(desc, u, k, h)
+ report_desc_t desc;
+ unsigned int u;
+ enum hid_kind k;
+ hid_item_t *h;
+{
+ hid_data_t d;
+
+ _DIAGASSERT(desc != NULL);
+ _DIAGASSERT(h != NULL);
+
+ for (d = hid_start_parse(desc, 1<<k); hid_get_item(d, h); ) {
+ if (h->kind == k && !(h->flags & HIO_CONST) && h->usage == u) {
+ hid_end_parse(d);
+ return (1);
+ }
+ }
+ hid_end_parse(d);
+ h->report_size = 0;
+ return (0);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usage.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usage.c
new file mode 100644
index 000000000..f909ee691
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usage.c
@@ -0,0 +1,199 @@
+/* $NetBSD: usage.c,v 1.4 1999/07/02 15:46:53 simonb Exp $ */
+
+/*
+ * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/libusb/usage.c,v 1.1.2.2 1999/12/03 10:12:42 hohndel Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "usb.h"
+
+#define _PATH_HIDTABLE "/usr/share/misc/usb_hid_usages"
+
+struct usage_in_page {
+ char *name;
+ int usage;
+};
+
+static struct usage_page {
+ char *name;
+ int usage;
+ struct usage_in_page *page_contents;
+ int pagesize, pagesizemax;
+} *pages;
+static int npages, npagesmax;
+
+#ifdef DEBUG
+void
+dump_hid_table(void)
+{
+ int i, j;
+
+ for (i = 0; i < npages; i++) {
+ printf("%d\t%s\n", pages[i].usage, pages[i].name);
+ for (j = 0; j < pages[i].pagesize; j++) {
+ printf("\t%d\t%s\n", pages[i].page_contents[j].usage,
+ pages[i].page_contents[j].name);
+ }
+ }
+}
+#endif
+
+void
+hid_init(char *hidname)
+{
+ FILE *f;
+ char line[100], name[100], *p, *n;
+ int no;
+ int lineno;
+ struct usage_page *curpage = 0;
+
+ if (hidname == 0)
+ hidname = _PATH_HIDTABLE;
+
+ f = fopen(hidname, "r");
+ if (f == NULL)
+ err(1, "%s", hidname);
+ for (lineno = 1; ; lineno++) {
+ if (fgets(line, sizeof line, f) == NULL)
+ break;
+ if (line[0] == '#')
+ continue;
+ for (p = line; *p && isspace(*p); p++)
+ ;
+ if (!*p)
+ continue;
+ if (sscanf(line, " * %[^\n]", name) == 1)
+ no = -1;
+ else if (sscanf(line, " 0x%x %[^\n]", &no, name) != 2 &&
+ sscanf(line, " %d %[^\n]", &no, name) != 2)
+ errx(1, "file %s, line %d, syntax error\n",
+ hidname, lineno);
+ for (p = name; *p; p++)
+ if (isspace(*p) || *p == '.')
+ *p = '_';
+ n = strdup(name);
+ if (!n)
+ err(1, "strdup");
+ if (isspace(line[0])) {
+ if (!curpage)
+ errx(1, "file %s, line %d, syntax error\n",
+ hidname, lineno);
+ if (curpage->pagesize >= curpage->pagesizemax) {
+ curpage->pagesizemax += 10;
+ curpage->page_contents =
+ realloc(curpage->page_contents,
+ curpage->pagesizemax *
+ sizeof (struct usage_in_page));
+ if (!curpage->page_contents)
+ err(1, "realloc");
+ }
+ curpage->page_contents[curpage->pagesize].name = n;
+ curpage->page_contents[curpage->pagesize].usage = no;
+ curpage->pagesize++;
+ } else {
+ if (npages >= npagesmax) {
+ if (pages == 0) {
+ npagesmax = 5;
+ pages = malloc(npagesmax *
+ sizeof (struct usage_page));
+ } else {
+ npagesmax += 5;
+ pages = realloc(pages,
+ npagesmax *
+ sizeof (struct usage_page));
+ }
+ if (!pages)
+ err(1, "alloc");
+ }
+ curpage = &pages[npages++];
+ curpage->name = n;
+ curpage->usage = no;
+ curpage->pagesize = 0;
+ curpage->pagesizemax = 10;
+ curpage->page_contents =
+ malloc(curpage->pagesizemax *
+ sizeof (struct usage_in_page));
+ if (!curpage->page_contents)
+ err(1, "malloc");
+ }
+ }
+ fclose(f);
+#ifdef DEBUG
+ dump_hid_table();
+#endif
+}
+
+char *
+hid_usage_page(int i)
+{
+ static char b[10];
+ int k;
+
+ if (!pages)
+ errx(1, "no hid table\n");
+
+ for (k = 0; k < npages; k++)
+ if (pages[k].usage == i)
+ return pages[k].name;
+ sprintf(b, "0x%02x", i);
+ return b;
+}
+
+char *
+hid_usage_in_page(unsigned int u)
+{
+ int page = HID_PAGE(u);
+ int i = HID_USAGE(u);
+ static char b[100];
+ int j, k, us;
+
+ for (k = 0; k < npages; k++)
+ if (pages[k].usage == page)
+ break;
+ if (k >= npages)
+ goto bad;
+ for (j = 0; j < pages[k].pagesize; j++) {
+ us = pages[k].page_contents[j].usage;
+ if (us == -1) {
+ sprintf(b, pages[k].page_contents[j].name, i);
+ return b;
+ }
+ if (us == i)
+ return pages[k].page_contents[j].name;
+ }
+ bad:
+ sprintf(b, "0x%02x", i);
+ return b;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb.3 b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb.3
new file mode 100644
index 000000000..db0b1b08f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb.3
@@ -0,0 +1,191 @@
+.\" $NetBSD: usb.3,v 1.9 1999/11/08 22:33:40 augustss Exp $
+.\"
+.\" Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $XFree86: xc/programs/Xserver/hw/xfree86/os-support/libusb/usb.3,v 1.1.2.2 1999/12/03 10:12:42 hohndel Exp $
+.\"
+.Dd May 11, 1999
+.Dt USB 3
+.Os
+.Sh NAME
+.Nm usb ,
+.Nm hid_get_report_desc ,
+.Nm hid_dispose_report_desc ,
+.Nm hid_start_parse ,
+.Nm hid_end_parse ,
+.Nm hid_get_item ,
+.Nm hid_report_size ,
+.Nm hid_locate ,
+.Nm hid_usage_page ,
+.Nm hid_usage_in_page ,
+.Nm hid_init ,
+.Nm hid_get_data ,
+.Nm hid_set_data
+.Nd USB HID access routines
+.Sh LIBRARY
+.Lb libusb
+.Sh SYNOPSIS
+.Fd #include <usb.h>
+.Ft report_desc_t
+.Fn hid_get_report_desc "int file"
+.Ft void
+.Fn hid_dispose_report_desc "report_desc_t d"
+.Ft hid_data_t
+.Fn hid_start_parse "report_desc_t d" "int kindset"
+.Ft void
+.Fn hid_end_parse "hid_data_t s"
+.Ft int
+.Fn hid_get_item "hid_data_t s" "hid_item_t *h"
+.Ft int
+.Fn hid_report_size "report_desc_t d" "hid_kind_t k" "int *idp"
+.Ft int
+.Fn hid_locate "report_desc_t d" "u_int usage" "hid_kind_t k" "hid_item_t *h"
+.Ft char *
+.Fn hid_usage_page "int i"
+.Ft char *
+.Fn hid_usage_in_page "u_int u"
+.Ft void
+.Fn hid_init "char *file"
+.Ft int
+.Fn hid_get_data "void *data" "hid_item_t *h"
+.Ft void
+.Fn hid_set_data "void *data" "hid_item_t *h" "u_int data"
+.Sh DESCRIPTION
+The
+.Nm
+library provides routines to extract data from USB Human Interface Devices.
+.Ss INTRODUCTION
+USB HID devices send and receive data layed out a device dependent
+way. The
+.Nm
+library contains routines to extract the
+.Em report descriptor
+which contains the data layout information and then use this information.
+.Pp
+The routines can be divided into four parts: extraction of the descriptor,
+parsing of the descriptor, translating to/from symbolic names, and
+data manipulation.
+.Ss DESCRIPTOR FUNCTIONS
+A report descriptor can be obtained by calling
+.Fn hid_get_report_desc
+with a file descriptor obtained by opening a
+.Xr uhid 4
+device.
+When the report descriptor is no longer needed it should be freed
+by calling
+.Fn hid_dispose_report_desc .
+The type
+.Fa report_desc_t
+is opaque and should be used when calling the parsing functions.
+.Ss DESCRIPTOR PARSING FUNCTIONS
+To parse the report descriptor the
+.Fn hid_start_parse
+function should be called with a report descriptor and a set that
+describes which items that are interesting. The set is obtained
+by oring together values
+.Fa "(1 << k)"
+where
+.Fa k
+is an item of type
+.Fa hid_kind_t .
+The function returns
+.Fa NULL
+if the initialization fails, otherwise an opaque value to be used
+in subsequent calls.
+After parsing the
+.Fn hid_end_parse
+function should be called to free internal data structures.
+.Pp
+To iterate through all the items in the report descriptor
+.Fn hid_get_item
+should be called while it returns a value greater than 0.
+When the report descriptor ends it will returns 0; a syntax
+error within the report descriptor will cause a return value less
+than 0.
+The struct pointed to by
+.Fa h
+will be filled with the relevant data for the item.
+The definition of
+.Fa hid_item_t
+can be found in
+.Pa <usb.h>
+and the meaning of the components in the USB HID documentation.
+.Pp
+Data should be read/written to the device in the size of
+the report. The size of a report (of a certain kind) can be
+computed by the
+.Fn hid_report_size
+function. If the report is prefixed by an ID byte it is
+stored at
+.Fa idp ,
+otherwise it will contain 0.
+.Pp
+To locate a single item the
+.Fn hid_locate
+function can be used. It should be given the usage code of
+the item and its kind and it will fill the item and return
+non-zero if the item was found.
+.Pp
+.Ss NAME TRANSLATION FUNCTIONS
+The function
+.Fn hid_usage_page
+will return the symbolic name of a usage page, and the function
+.Fn hid_usage_in_page
+will return the symbolic name of the usage within the page.
+Both these functions may return a pointer to static data.
+Before either of these functions can be called the usage table
+must be parsed, this is done by calling
+.Fn hid_init
+with the name of the table. Passing
+.Fa NULL
+to this function will cause it to use the default table.
+.Ss DATA EXTRACTION FUNCTIONS
+Given the data obtained from a HID device and an item in the
+report descriptor the
+.Fn hid_get_data
+function extracts the value of the item.
+Conversely
+.Fn hid_set_data
+can be used to put data into a report (which must be zeroed first).
+.Sh EXAMPLE
+Not yet.
+.Sh FILES
+.Pa /usr/share/misc/usb_hid_usages
+The default HID usage table.
+.Sh BUGS
+This man page is woefully incomplete.
+.Sh SEE ALSO
+The
+.Tn USB
+specifications can be found at
+.Dv http://www.usb.org/developers/docs.htm .
+.Pp
+.Xr hid 4 ,
+.Xr usb 4 .
+.Sh HISTORY
+The
+.Nm
+library first appeared in
+.Nx 1.5 .
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb.h
new file mode 100644
index 000000000..445428118
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb.h
@@ -0,0 +1,95 @@
+/* $NetBSD: usb.h,v 1.5 1999/07/02 15:46:53 simonb Exp $ */
+
+/*
+ * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/libusb/usb.h,v 1.1.2.2 1999/12/03 10:12:43 hohndel Exp $ */
+
+#define _DIAGASSERT(e) assert(e)
+
+typedef struct report_desc *report_desc_t;
+
+typedef struct hid_data *hid_data_t;
+
+typedef enum hid_kind {
+ hid_input, hid_output, hid_feature, hid_collection, hid_endcollection
+}hid_kind_t;
+
+typedef struct hid_item {
+ /* Global */
+ int _usage_page;
+ int logical_minimum;
+ int logical_maximum;
+ int physical_minimum;
+ int physical_maximum;
+ int unit_exponent;
+ int unit;
+ int report_size;
+ int report_ID;
+ int report_count;
+ /* Local */
+ unsigned int usage;
+ int usage_minimum;
+ int usage_maximum;
+ int designator_index;
+ int designator_minimum;
+ int designator_maximum;
+ int string_index;
+ int string_minimum;
+ int string_maximum;
+ int set_delimiter;
+ /* Misc */
+ int collection;
+ int collevel;
+ enum hid_kind kind;
+ unsigned int flags;
+ /* Absolute data position (bits) */
+ unsigned int pos;
+ /* */
+ struct hid_item *next;
+} hid_item_t;
+
+#define HID_PAGE(u) ((u) >> 16)
+#define HID_USAGE(u) ((u) & 0xffff)
+
+/* Obtaining a report descriptor, descr.c: */
+report_desc_t hid_get_report_desc __P((int file));
+void hid_dispose_report_desc __P((report_desc_t));
+
+/* Parsing of a HID report descriptor, parse.c: */
+hid_data_t hid_start_parse __P((report_desc_t d, int kindset));
+void hid_end_parse __P((hid_data_t s));
+int hid_get_item __P((hid_data_t s, hid_item_t *h));
+int hid_report_size __P((report_desc_t d, enum hid_kind k, int *idp));
+int hid_locate __P((report_desc_t d, unsigned int usage, enum hid_kind k, hid_item_t *h));
+
+/* Conversion to/from usage names, usage.c: */
+char *hid_usage_page __P((int i));
+char *hid_usage_in_page __P((unsigned int u));
+void hid_init __P((char *file));
+
+/* Extracting/insertion of data, data.c: */
+int hid_get_data __P((void *p, hid_item_t *h));
+void hid_set_data __P((void *p, hid_item_t *h, int data));
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb_hid_usages b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb_hid_usages
new file mode 100644
index 000000000..02f122028
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usb_hid_usages
@@ -0,0 +1,1079 @@
+# $NetBSD: usb_hid_usages,v 1.3 1999/07/02 15:46:53 simonb Exp $
+#
+# USB HID usage table
+# Syntax:
+# - lines that do not start with a white space give the number and name of
+# a usage page.
+# - lines that start with a white space give the number and name of
+# a usage with the last given page.
+# If the number is * then the line matches all usages and the name
+# is a printf formatting string that will be given the usage number.
+#
+# $XFree86: xc/programs/Xserver/hw/xfree86/os-support/libusb/usb_hid_usages,v 1.1.2.2 1999/12/03 10:12:43 hohndel Exp $
+#
+1 Generic Desktop
+ 0x00 Undefined
+ 0x01 Pointer
+ 0x02 Mouse
+ 0x03 Reserved
+ 0x04 Joystick
+ 0x05 Game Pad
+ 0x06 Keyboard
+ 0x07 Keypad
+ 0x08 Multi-axis Controller
+ 0x30 X
+ 0x31 Y
+ 0x32 Z
+ 0x33 Rx
+ 0x34 Ry
+ 0x35 Rz
+ 0x36 Slider
+ 0x37 Dial
+ 0x38 Wheel
+ 0x39 Hat Switch
+ 0x3A Counted Buffer
+ 0x3B Byte Count
+ 0x3C Motion Wakeup
+ 0x40 Vx
+ 0x41 Vy
+ 0x42 Vz
+ 0x43 Vbrx
+ 0x44 Vbry
+ 0x45 Vbrx
+ 0x46 Vno
+ 0x80 System Control
+ 0x81 System Power Down
+ 0x82 System Sleep
+ 0x83 System Wake Up
+ 0x84 System Context Menu
+ 0x85 System Main Menu
+ 0x86 System App Menu
+ 0x87 System Menu Help
+ 0x88 System Menu Exit
+ 0x89 System Menu Select
+ 0x8A System Menu Right
+ 0x8B System Menu Left
+ 0x8C System Menu Up
+ 0x8D System Menu Down
+ 0x90 D-pad Up
+ 0x91 D-pad Down
+ 0x92 D-pad Right
+ 0x93 D-pad Left
+
+2 Simulation Controls
+ 0x00 Undefined
+ 0x01 Flight Simulation Device
+ 0x02 Automobile Simulation Device
+ 0x03 Tank Simulation Device
+ 0x04 Spaceship Simulation Device
+ 0x05 Submarine Simulation Device
+ 0x06 Sailing Simulation Device
+ 0x07 Motorcycle Simulation Device
+ 0x08 Sports Simulation Device
+ 0x09 Airplane Simulation Device
+ 0x0A Helicopter Simulation Device
+ 0x0B Magic Carpet Simulation Device
+ 0x0C Bicycle
+ 0x20 Flight Control Stick
+ 0x21 Flight Stick
+ 0x22 Cyclic Control
+ 0x23 Cyclic Trim
+ 0x24 Flight Yoke
+ 0x25 Track Control
+ 0x26 Driving Control
+ 0xB0 Aileron
+ 0xB1 Aileron Trim
+ 0xB2 Anti-Torque Control
+ 0xB3 Auto-pilot Enable
+ 0xB4 Chaff Release
+ 0xB5 Collective Control
+ 0xB6 Dive Brake
+ 0xB7 Electronic Counter Measures
+ 0xB8 Elevator
+ 0xB9 Elevator Trim
+ 0xBA Rudder
+ 0xBB Throttle
+ 0xBC Flight Communication
+ 0xBD Flare Release
+ 0xBE Landing Gear
+ 0xBF Toe Brake
+ 0xC0 Trigger
+ 0xC1 Weapons Arm
+ 0xC2 Weapons Select
+ 0xC3 Wing Flaps
+ 0xC4 Accelerator
+ 0xC5 Brake
+ 0xC6 Clutch
+ 0xC7 Shifter
+ 0xC8 Steering
+ 0xC9 Turret Direction
+ 0xCA Barrel Elevation
+ 0xCB Dive Plane
+ 0xCC Ballast
+ 0xCD Bicycle Crank
+ 0xCE Handle Bars
+ 0xCF Front Brake
+ 0xD0 Rear Brake
+
+3 VR Controls
+ 0x00 Unidentified
+ 0x01 Belt
+ 0x02 Body Suit
+ 0x03 Flexor
+ 0x04 Glove
+ 0x05 Head Tracker
+ 0x06 Head Mounted Display
+ 0x07 Hand Tracker
+ 0x08 Oculometer
+ 0x09 Vest
+ 0x0A Animatronic Device
+ 0x20 Stereo Enable
+ 0x21 Display Enable
+
+4 Sports Controls
+ 0x00 Unidentified
+ 0x01 Baseball Bat
+ 0x02 Golf Club
+ 0x03 Rowing Machine
+ 0x04 Treadmill
+ 0x30 Oar
+ 0x31 Slope
+ 0x32 Rate
+ 0x33 Stick Speed
+ 0x34 Stick Face Angle
+ 0x35 Stick Heel/Toe
+ 0x36 Stick Follow Through
+ 0x37 Stick Tempo
+ 0x38 Stick Type
+ 0x39 Stick Height
+ 0x50 Putter
+ 0x51 1 Iron
+ 0x52 2 Iron
+ 0x53 3 Iron
+ 0x54 4 Iron
+ 0x55 5 Iron
+ 0x56 6 Iron
+ 0x57 7 Iron
+ 0x58 8 Iron
+ 0x59 9 Iron
+ 0x5A 10 Iron
+ 0x5B 11 Iron
+ 0x5C Sand Wedge
+ 0x5D Loft Wedge
+ 0x5E Power Wedge
+ 0x5F 1 Wood
+ 0x60 3 Wood
+ 0x61 5 Wood
+ 0x62 7 Wood
+ 0x63 9 Wood
+
+5 Game Controls
+ 0x00 Undefined
+ 0x01 3D Game Controller
+ 0x02 Pinball Device
+ 0x03 Gun Device
+ 0x20 Point of View
+ 0x21 Turn Right/Left
+ 0x22 Pitch Right/Left
+ 0x23 Roll Forward/Backward
+ 0x24 Move Right/Left
+ 0x25 Move Forward/Backward
+ 0x26 Move Up/Down
+ 0x27 Lean Right/Left
+ 0x28 Lean Forward/Backward
+ 0x29 Height of POV
+ 0x2A Flipper
+ 0x2B Secondary Flipper
+ 0x2C Bump
+ 0x2D New Game
+ 0x2E Shoot Ball
+ 0x2F Player
+ 0x30 Gun Bolt
+ 0x31 Gun Clip
+ 0x32 Gun Selector
+ 0x33 Gun Single Shot
+ 0x34 Gun Burst
+ 0x35 Gun Automatic
+ 0x36 Gun Safety
+ 0x37 Gamepad Fire/Jump
+ 0x39 Gamepad Trigger
+
+7 Keyboard
+ 0x00 Reserved (no event indicated)
+ 0x01 Keyboard ErrorRollOver
+ 0x02 Keyboard POSTFail
+ 0x03 Keyboard ErrorUndefined
+ 0x04 Keyboard a and A
+ 0x05 Keyboard b and B
+ 0x06 Keyboard c and C
+ 0x07 Keyboard d and D
+ 0x08 Keyboard e and E
+ 0x09 Keyboard f and F
+ 0x0A Keyboard g and G
+ 0x0B Keyboard h and H
+ 0x0C Keyboard i and I
+ 0x0D Keyboard j and J
+ 0x0E Keyboard k and K
+ 0x0F Keyboard l and L
+ 0x10 Keyboard m and M
+ 0x11 Keyboard n and N
+ 0x12 Keyboard o and O
+ 0x13 Keyboard p and P
+ 0x14 Keyboard q and Q
+ 0x15 Keyboard r and R
+ 0x16 Keyboard s and S
+ 0x17 Keyboard t and T
+ 0x18 Keyboard u and U
+ 0x19 Keyboard v and V
+ 0x1A Keyboard w and W
+ 0x1B Keyboard x and X
+ 0x1C Keyboard y and Y
+ 0x1D Keyboard z and Z
+ 0x1E Keyboard 1 and !
+ 0x1F Keyboard 2 and @
+ 0x20 Keyboard 3 and #
+ 0x21 Keyboard 4 and $
+ 0x22 Keyboard 5 and %
+ 0x23 Keyboard 6 and ^
+ 0x24 Keyboard 7 and &
+ 0x25 Keyboard 8 and *
+ 0x26 Keyboard 9 and (
+ 0x27 Keyboard 0 and )
+ 0x28 Keyboard Return (ENTER)
+ 0x29 Keyboard ESCAPE
+ 0x2A Keyboard DELETE (Backspace)
+ 0x2B Keyboard Tab
+ 0x2C Keyboard Spacebar
+ 0x2D Keyboard - and (underscore)
+ 0x2E Keyboard = and +
+ 0x2F Keyboard [ and {
+ 0x30 Keyboard ] and }
+ 0x31 Keyboard \ and |
+ 0x32 Keyboard Non-US # and ~
+ 0x33 Keyboard ; and :
+ 0x34 Keyboard ' and "
+ 0x35 Keyboard Grave Accent and Tilde
+ 0x36 Keyboard, and <
+ 0x37 Keyboard . and >
+ 0x38 Keyboard / and ?
+ 0x39 Keyboard Caps Lock
+ 0x3A Keyboard F1
+ 0x3B Keyboard F2
+ 0x3C Keyboard F3
+ 0x3D Keyboard F4
+ 0x3E Keyboard F5
+ 0x3F Keyboard F6
+ 0x40 Keyboard F7
+ 0x41 Keyboard F8
+ 0x42 Keyboard F9
+ 0x43 Keyboard F10
+ 0x44 Keyboard F11
+ 0x45 Keyboard F12
+ 0x46 Keyboard PrintScreen
+ 0x47 Keyboard Scroll Lock
+ 0x48 Keyboard Pause
+ 0x49 Keyboard Insert
+ 0x4A Keyboard Home
+ 0x4B Keyboard PageUp
+ 0x4C Keyboard Delete Forward
+ 0x4D Keyboard End
+ 0x4E Keyboard PageDown
+ 0x4F Keyboard RightArrow
+ 0x50 Keyboard LeftArrow
+ 0x51 Keyboard DownArrow
+ 0x52 Keyboard UpArrow
+ 0x53 Keypad Num Lock and Clear
+ 0x54 Keypad /
+ 0x55 Keypad *
+ 0x56 Keypad -
+ 0x57 Keypad +
+ 0x58 Keypad ENTER
+ 0x59 Keypad 1 and End
+ 0x5A Keypad 2 and Down Arrow
+ 0x5B Keypad 3 and PageDn
+ 0x5C Keypad 4 and Left Arrow
+ 0x5D Keypad 5
+ 0x5E Keypad 6 and Right Arrow
+ 0x5F Keypad 7 and Home
+ 0x60 Keypad 8 and Up Arrow
+ 0x61 Keypad 9 and PageUp
+ 0x62 Keypad 0 and Insert
+ 0x63 Keypad . and Delete
+ 0x64 Keyboard Non-US \ and |
+ 0x65 Keyboard Application
+ 0x66 Keyboard Power
+ 0x67 Keypad =
+ 0x68 Keyboard F13
+ 0x69 Keyboard F14
+ 0x6A Keyboard F15
+ 0x6B Keyboard F16
+ 0x6C Keyboard F17
+ 0x6D Keyboard F18
+ 0x6E Keyboard F19
+ 0x6F Keyboard F20
+ 0x70 Keyboard F21
+ 0x71 Keyboard F22
+ 0x72 Keyboard F23
+ 0x73 Keyboard F24
+ 0x74 Keyboard Execute
+ 0x75 Keyboard Help
+ 0x76 Keyboard Menu
+ 0x77 Keyboard Select
+ 0x78 Keyboard Stop
+ 0x79 Keyboard Again
+ 0x7A Keyboard Undo
+ 0x7B Keyboard Cut
+ 0x7C Keyboard Copy
+ 0x7D Keyboard Paste
+ 0x7E Keyboard Find
+ 0x7F Keyboard Mute
+ 0x80 Keyboard Volume Up
+ 0x81 Keyboard Volume Down
+ 0x82 Keyboard Locking Caps Lock
+ 0x83 Keyboard Locking Num Lock
+ 0x84 Keyboard Locking Scroll Lock
+ 0x85 Keypad Comma
+ 0x86 Keypad Equal Sign
+ 0x87 Keyboard International1
+ 0x88 Keyboard International2
+ 0x89 Keyboard International3
+ 0x8A Keyboard International4
+ 0x8B Keyboard International5
+ 0x8C Keyboard International6
+ 0x8D Keyboard International7
+ 0x8E Keyboard International8
+ 0x8F Keyboard International9
+ 0x90 Keyboard LANG1
+ 0x91 Keyboard LANG2
+ 0x92 Keyboard LANG3
+ 0x93 Keyboard LANG4
+ 0x94 Keyboard LANG5
+ 0x95 Keyboard LANG6
+ 0x96 Keyboard LANG7
+ 0x97 Keyboard LANG8
+ 0x98 Keyboard LANG9
+ 0x99 Keyboard Alternate Erase
+ 0x9A Keyboard SysReq/Attention
+ 0x9B Keyboard Cancel
+ 0x9C Keyboard Clear
+ 0x9D Keyboard Prior
+ 0x9E Keyboard Return
+ 0x9F Keyboard Separator
+ 0xA0 Keyboard Out
+ 0xA1 Keyboard Oper
+ 0xA2 Keyboard Clear/Again
+ 0xA3 Keyboard CrSel/Props
+ 0xA4 Keyboard ExSel
+ 0xE0 Keyboard LeftControl
+ 0xE1 Keyboard LeftShift
+ 0xE2 Keyboard LeftAlt
+ 0xE3 Keyboard Left GUI
+ 0xE4 Keyboard RightControl
+ 0xE5 Keyboard RightShift
+ 0xE6 Keyboard RightAlt
+ 0xE7 Keyboard Right GUI
+
+8 LEDs
+ 0x00 Undefined
+ 0x01 Num Lock
+ 0x02 Caps Lock
+ 0x03 Scroll Lock
+ 0x04 Compose
+ 0x05 Kana
+ 0x06 Power
+ 0x07 Shift
+ 0x08 Do Not Disturb
+ 0x09 Mute
+ 0x0A Tone Enable
+ 0x0B High Cut Filter
+ 0x0C Low Cut Filter
+ 0x0D Equalizer Enable
+ 0x0E Sound Field On
+ 0x0F Surround Field On
+ 0x10 Repeat
+ 0x11 Stereo
+ 0x12 Sampling Rate Detect
+ 0x13 Spinning
+ 0x14 CAV
+ 0x15 CLV
+ 0x16 Recording Format Detect
+ 0x17 Off-Hook
+ 0x18 Ring
+ 0x19 Message Waiting
+ 0x1A Data Mode
+ 0x1B Battery Operation
+ 0x1C Battery OK
+ 0x1D Battery Low
+ 0x1E Speaker
+ 0x1F Head Set
+ 0x20 Hold
+ 0x21 Microphone
+ 0x22 Coverage
+ 0x23 Night Mode
+ 0x24 Send Calls
+ 0x25 Call Pickup
+ 0x26 Conference
+ 0x27 Stand-by
+ 0x28 Camera On
+ 0x29 Camera Off
+ 0x2A On-Line
+ 0x2B Off-Line
+ 0x2C Busy
+ 0x2D Ready
+ 0x2E Paper-Out
+ 0x2F Paper-Jam
+ 0x30 Remote
+ 0x31 Forward
+ 0x32 Reverse
+ 0x33 Stop
+ 0x34 Rewind
+ 0x35 Fast Forward
+ 0x36 Play
+ 0x37 Pause
+ 0x38 Record
+ 0x39 Error
+ 0x3A Usage Selected Indicator
+ 0x3B Usage In Use Indicator
+ 0x3C Usage Multi Mode Indicator
+ 0x3D Indicator On
+ 0x3E Indicator Flash
+ 0x3F Indicator Slow Blink
+ 0x40 Indicator Fast Blink
+ 0x41 Indicator Off
+ 0x42 Flash On Time
+ 0x43 Slow Blink On Time
+ 0x44 Slow Blink Off Time
+ 0x45 Fast Blink On Time
+ 0x46 Fast Blink Off Time
+ 0x47 Usage Indicator Color
+ 0x48 Red
+ 0x49 Green
+ 0x4A Amber
+ 0x4B Generic Indicator
+ 0x4C System Suspend
+ 0x4D External Power Connected
+ 0x4C-FFFF Reserved
+
+9 Button
+ 0x00 No Button Pressed
+ * Button %d
+
+10 Ordinal
+ 0x00 Unused
+ * Instance %d
+
+11 Telephony
+ 0x00 Unassigned
+ 0x01 Phone
+ 0x02 Answering Machine
+ 0x03 Message Controls
+ 0x04 Handset
+ 0x05 Headset
+ 0x06 Telephony Key Pad
+ 0x07 Programmable Button
+ 0x20 Hook Switch
+ 0x21 Flash
+ 0x22 Feature
+ 0x23 Hold
+ 0x24 Redial
+ 0x25 Transfer
+ 0x26 Drop
+ 0x27 Park
+ 0x28 Forward Calls
+ 0x29 Alternate Function
+ 0x2A Line
+ 0x2B Speaker Phone
+ 0x2C Conference
+ 0x2D Ring Enable
+ 0x2E Ring Select
+ 0x2F Phone Mute
+ 0x30 Caller ID
+ 0x50 Speed Dial
+ 0x51 Store Number
+ 0x52 Recall Number
+ 0x53 Phone Directory
+ 0x70 Voice Mail
+ 0x71 Screen Calls
+ 0x72 Do Not Disturb
+ 0x73 Message
+ 0x74 Answer On/Off
+ 0x90 Inside Dial Tone
+ 0x91 Outside Dial Tone
+ 0x92 Inside Ring Tone
+ 0x93 Outside Ring Tone
+ 0x94 Priority Ring Tone
+ 0x95 Inside Ringback
+ 0x96 Priority Ringback
+ 0x97 Line Busy Tone
+ 0x98 Reorder Tone
+ 0x99 Call Waiting Tone
+ 0x9A Confirmation Tone 1
+ 0x9B Confirmation Tone 2
+ 0x9C Tones Off
+ 0xB0 Phone Key 0
+ 0xB1 Phone Key 1
+ 0xB2 Phone Key 2
+ 0xB3 Phone Key 3
+ 0xB4 Phone Key 4
+ 0xB5 Phone Key 5
+ 0xB6 Phone Key 6
+ 0xB7 Phone Key 7
+ 0xB8 Phone Key 8
+ 0xB9 Phone Key 9
+ 0xBA Phone Key Star
+ 0xBB Phone Key Pound
+ 0xBC Phone Key A
+ 0xBD Phone Key B
+ 0xBE Phone Key C
+ 0xBF Phone Key D
+
+12 Consumer
+ 0x00 Unassigned
+ 0x01 Consumer Control
+ 0x02 Numeric Key Pad
+ 0x03 Programmable Buttons
+ 0x20 +10
+ 0x21 +100
+ 0x22 AM/PM
+ 0x30 Power
+ 0x31 Reset
+ 0x32 Sleep
+ 0x33 Sleep After
+ 0x34 Sleep Mode
+ 0x35 Illumination
+ 0x36 Function Buttons
+ 0x40 Menu
+ 0x41 Menu Pick
+ 0x42 Menu Up
+ 0x43 Menu Down
+ 0x44 Menu Left
+ 0x45 Menu Right
+ 0x46 Menu Escape
+ 0x47 Menu Value Increase
+ 0x48 Menu Value Decrease
+ 0x60 Data On Screen
+ 0x61 Closed Caption
+ 0x62 Closed Caption Select
+ 0x63 VCR/TV
+ 0x64 Broadcast Mode
+ 0x65 Snapshot
+ 0x66 Still
+ 0x80 Selection
+ 0x81 Assign Selection
+ 0x82 Mode Step
+ 0x83 Recall Last
+ 0x84 Enter Channel
+ 0x85 Order Movie
+ 0x86 Channel
+ 0x87 Media Selection
+ 0x88 Media Select Computer
+ 0x89 Media Select TV
+ 0x8A Media Select WWW
+ 0x8B Media Select DVD
+ 0x8C Media Select Telephone
+ 0x8D Media Select Program Guide
+ 0x8E Media Select Video Phone
+ 0x8F Media Select Games
+ 0x90 Media Select Messages
+ 0x91 Media Select CD
+ 0x92 Media Select VCR
+ 0x93 Media Select Tuner
+ 0x94 Quit
+ 0x95 Help
+ 0x96 Media Select Tape
+ 0x97 Media Select Cable
+ 0x98 Media Select Satellite
+ 0x99 Media Select Security
+ 0x9A Media Select Home
+ 0x9B Media Select Call
+ 0x9C Channel Increment
+ 0x9D Channel Decrement
+ 0x9E Media Select SAP
+ 0xA0 VCR Plus
+ 0xA1 Once
+ 0xA2 Daily
+ 0xA3 Weekly
+ 0xA4 Monthly
+ 0xB0 Play
+ 0xB1 Pause
+ 0xB2 Record
+ 0xB3 Fast Forward
+ 0xB4 Rewind
+ 0xB5 Scan Next Track
+ 0xB6 Scan Previous Track
+ 0xB7 Stop
+ 0xB8 Eject
+ 0xB9 Random Play
+ 0xBA Select DisC
+ 0xBB Enter Disc
+ 0xBC Repeat
+ 0xBD Tracking
+ 0xBE Track Normal
+ 0xBF Slow Tracking
+ 0xC0 Frame Forward
+ 0xC1 Frame Back
+ 0xC2 Mark
+ 0xC3 Clear Mark
+ 0xC4 Repeat From Mark
+ 0xC5 Return To Mark
+ 0xC6 Search Mark Forward
+ 0xC7 Search Mark Backwards
+ 0xC8 Counter Reset
+ 0xC9 Show Counter
+ 0xCA Tracking Increment
+ 0xCB Tracking Decrement
+ 0xE0 Volume
+ 0xE1 Balance
+ 0xE2 Mute
+ 0xE3 Bass
+ 0xE4 Treble
+ 0xE5 Bass Boost
+ 0xE6 Surround Mode
+ 0xE7 Loudness
+ 0xE8 MPX
+ 0xE9 Volume Up
+ 0xEA Volume Down
+ 0xF0 Speed Select
+ 0xF1 Playback Speed
+ 0xF2 Standard Play
+ 0xF3 Long Play
+ 0xF4 Extended Play
+ 0xF5 Slow
+ 0x100 Fan Enable
+ 0x101 Fan Speed
+ 0x102 Light
+ 0x103 Light Illumination Level
+ 0x104 Climate Control Enable
+ 0x105 Room Temperature
+ 0x106 Security Enable
+ 0x107 Fire Alarm
+ 0x108 Police Alarm
+ 0x150 Balance Right
+ 0x151 Balance Left
+ 0x152 Bass Increment
+ 0x153 Bass Decrement
+ 0x154 Treble Increment
+ 0x155 Treble Decrement
+ 0x160 Speaker System
+ 0x161 Channel Left
+ 0x162 Channel Right
+ 0x163 Channel Center
+ 0x164 Channel Front
+ 0x165 Channel Center Front
+ 0x166 Channel Side
+ 0x167 Channel Surround
+ 0x168 Channel Low Frequency Enhancement
+ 0x169 Channel Top
+ 0x16A Channel Unknown
+ 0x170 Sub-channel
+ 0x171 Sub-channel Increment
+ 0x172 Sub-channel Decrement
+ 0x173 Alternate Audio Increment
+ 0x174 Alternate Audio Decrement
+ 0x180 Application Launch Buttons
+ 0x181 AL Launch Button Configuration Tool
+ 0x182 AL Programmable Button Configuration
+ 0x183 AL Consumer Control Configuration
+ 0x184 AL Word Processor
+ 0x185 AL Text Editor
+ 0x186 AL Spreadsheet
+ 0x187 AL Graphics Editor
+ 0x188 AL Presentation App
+ 0x189 AL Database App
+ 0x18A AL Email Reader
+ 0x18B AL Newsreader
+ 0x18C AL Voicemail
+ 0x18D AL Contacts/Address Book
+ 0x18E AL Calendar/Schedule
+ 0x18F AL Task/Project Manager
+ 0x190 AL Log/Journal/Timecard
+ 0x191 AL Checkbook/Finance
+ 0x192 AL Calculator
+ 0x193 AL A/V Capture/Playback
+ 0x194 AL Local Machine Browser
+ 0x195 AL LAN/WAN Browser
+ 0x196 AL Internet Browser
+ 0x197 AL Remote Networking/ISP Connect
+ 0x198 AL Network Conference
+ 0x199 AL Network Chat
+ 0x19A AL Telephony/Dialer
+ 0x19B AL Logon
+ 0x19C AL Logoff
+ 0x19D AL Logon/Logoff
+ 0x19E AL Terminal Lock/Screensaver
+ 0x19F AL Control Panel
+ 0x1A0 AL Command Line Processor/Run
+ 0x1A1 AL Process/Task Manager
+ 0x1A2 AL Select Tast/Application
+ 0x1A3 AL Next Task/Application
+ 0x1A4 AL Previous Task/Application
+ 0x1A5 AL Preemptive Halt Task/Application
+ 0x200 Generic GUI Application Controls
+ 0x201 AC New
+ 0x202 AC Open
+ 0x203 AC Close
+ 0x204 AC Exit
+ 0x205 AC Maximize
+ 0x206 AC Minimize
+ 0x207 AC Save
+ 0x208 AC Print
+ 0x209 AC Properties
+ 0x21A AC Undo
+ 0x21B AC Copy
+ 0x21C AC Cut
+ 0x21D AC Paste
+ 0x21E AC Select All
+ 0x21F AC Find
+ 0x220 AC Find and Replace
+ 0x221 AC Search
+ 0x222 AC Go To
+ 0x223 AC Home
+ 0x224 AC Back
+ 0x225 AC Forward
+ 0x226 AC Stop
+ 0x227 AC Refresh
+ 0x228 AC Previous Link
+ 0x229 AC Next Link
+ 0x22A AC Bookmarks
+ 0x22B AC History
+ 0x22C AC Subscriptions
+ 0x22D AC Zoom In
+ 0x22E AC Zoom Out
+ 0x22F AC Zoom
+ 0x230 AC Full Screen View
+ 0x231 AC Normal View
+ 0x232 AC View Toggle
+ 0x233 AC Scroll Up
+ 0x234 AC Scroll Down
+ 0x235 AC Scroll
+ 0x236 AC Pan Left
+ 0x237 AC Pan Right
+ 0x238 AC Pan
+ 0x239 AC New Window
+ 0x23A AC Tile Horizontally
+ 0x23B AC Tile Vertically
+ 0x23C AC Format
+
+13 Digitizer
+ 0x00 Undefined
+ 0x01 Digitizer
+ 0x02 Pen
+ 0x03 Light Pen
+ 0x04 Touch Screen
+ 0x05 Touch Pad
+ 0x06 White Board
+ 0x07 Coordinate Measuring Machine
+ 0x08 3-D Digitizer
+ 0x09 Stereo Plotter
+ 0x0A Articulated Arm
+ 0x0B Armature
+ 0x0C Multiple Point Digitizer
+ 0x0D Free Space Wand
+ 0x20 Stylus
+ 0x21 Puck
+ 0x22 Finger
+ 0x30 Tip Pressure
+ 0x31 Barrel Pressure
+ 0x32 In Range
+ 0x33 Touch
+ 0x34 Untouch
+ 0x35 Tap
+ 0x36 Quality
+ 0x37 Data Valid
+ 0x38 Transducer Index
+ 0x39 Tablet Function Keys
+ 0x3A Program Change Keys
+ 0x3B Battery Strength
+ 0x3C Invert
+ 0x3D X Tilt
+ 0x3E Y Tilt
+ 0x3F Azimuth
+ 0x40 Altitude
+ 0x41 Twist
+ 0x42 Tip Switch
+ 0x43 Secondary Tip Switch
+ 0x44 Barrel Switch
+ 0x45 Eraser
+ 0x46 Tablet Pick
+
+15 Physical Interface Device
+
+16 Unicode
+ * Unicode Char u%04x
+
+20 Alphnumeric Display
+ 0x00 Undefined
+ 0x01 Alphanumeric Display
+ 0x20 Display Attributes Report
+ 0x21 ASCII Character Set
+ 0x22 Data Read Back
+ 0x23 Font Read Back
+ 0x24 Display Control Report
+ 0x25 Clear Display
+ 0x26 Display Enable
+ 0x27 Screen Saver Delay
+ 0x28 Screen Saver Enable
+ 0x29 Vertical Scroll
+ 0x2A Horizontal Scroll
+ 0x2B Character Report
+ 0x2C Display Data
+ 0x2D Display Status
+ 0x2E Stat Not Ready
+ 0x2F Stat Ready
+ 0x30 Err Not a loadable character
+ 0x31 Err Font data cannot be read
+ 0x32 Cursor Position Report
+ 0x33 Row
+ 0x34 Column
+ 0x35 Rows
+ 0x36 Columns
+ 0x37 Cursor Pixel Positioning
+ 0x38 Cursor Mode
+ 0x39 Cursor Enable
+ 0x3A Cursor Blink
+ 0x3B Font Report
+ 0x3C Font Data
+ 0x3D Character Width
+ 0x3E Character Height
+ 0x3F Character Spacing Horizontal
+ 0x40 Character Spacing Vertical
+ 0x41 Unicode Character Set
+
+128 Monitor
+ 0x00 Undefined
+ 0x01 Monitor Control
+ 0x02 EDID Information
+ 0x03 VDIF Information
+ 0x04 VESA Version
+ 0x05 On Screen Display
+ 0x06 Auto Size Center
+ 0x07 Polarity Horz Synch
+ 0x08 Polarity Vert Synch
+ 0x09 Sync Type
+ 0x0A Screen Position
+ 0x0B Horizontal Frequency
+ 0x0C Vertical Frequency
+
+129 Monitor Enumerated Values
+ 0x00 unassigned
+ * ENUM %d
+
+130 VESA Virtual Controls
+ 0x10 Brightness
+ 0x12 Contrast
+ 0x16 Video Gain Red
+ 0x18 Video Gain Green
+ 0x1A Video Gain Blue
+ 0x1C Focus
+ 0x20 Horizontal Position
+ 0x22 Horizontal Size
+ 0x24 Horizontal Pincushion
+ 0x26 Horizontal Pincushion Balance
+ 0x28 Horizontal Misconvergence
+ 0x2A Horizontal Linearity
+ 0x2C Horizontal Linearity Balance
+ 0x30 Vertical Position
+ 0x32 Vertical Size
+ 0x34 Vertical Pincushion
+ 0x36 Vertical Pincushion Balance
+ 0x38 Vertical Misconvergence
+ 0x3A Vertical Linearity
+ 0x3C Vertical Linearity Balance
+ 0x40 Parallelogram Distortion
+ 0x42 Trapezoidal Distortion
+ 0x44 Tilt
+ 0x46 Top Corner Distortion Control
+ 0x48 Top Corner Distortion Balance
+ 0x4A Bottom Corner Distortion Control
+ 0x4C Bottom Corner Distortion Balance
+ 0x56 Moiré Horizontal
+ 0x58 Moiré Vertical
+ 0x5E Input Level Select
+ 0x60 Input Source Select
+ 0x62 Stereo Mode
+ 0x6C Video Black Level Red
+ 0x6E Video Black Level Green
+ 0x70 Video Black Level Blue
+
+131 VESA Command
+ 0x00 Undefined
+ 0x01 Settings
+ 0x02 Degauss
+
+132 Power Device
+ 0x00 Undefined
+ 0x01 iName
+ 0x02 PresentStatus
+ 0x03 ChangedStatus
+ 0x04 UPS
+ 0x05 PowerSupply
+ 0x10 BatterySystem
+ 0x11 BatterySystemID
+ 0x12 Battery
+ 0x13 BatteryID
+ 0x14 Charger
+ 0x15 ChargerID
+ 0x16 PowerConverter
+ 0x17 PowerConverterID
+ 0x18 OutletSystem
+ 0x19 OutletSystemID
+ 0x1A Input
+ 0x1B InputID
+ 0x1C Output
+ 0x1D OutputID
+ 0x1E Flow
+ 0x1F FlowID
+ 0x20 Outlet
+ 0x21 OutletID
+ 0x22 Gang
+ 0x23 GangID
+ 0x24 Sink
+ 0x25 SinkID
+ 0x30 Voltage
+ 0x31 Current
+ 0x32 Frequency
+ 0x33 ApparentPower
+ 0x34 ActivePower
+ 0x35 PercentLoad
+ 0x36 Temperature
+ 0x37 Humidity
+ 0x40 ConfigVoltage
+ 0x41 ConfigCurrent
+ 0x42 ConfigFrequency
+ 0x43 ConfigApparentPower
+ 0x44 ConfigActivePower
+ 0x45 ConfigPercentLoad
+ 0x46 ConfigTemperature
+ 0x47 ConfigHumidity
+ 0x50 SwitchOnControl
+ 0x51 SwitchOffControl
+ 0x52 ToggleControl
+ 0x53 LowVoltageTransfer
+ 0x54 HighVoltageTransfer
+ 0x55 DelayBeforeReboot
+ 0x56 DelayBeforeStartup
+ 0x57 DelayBeforeShutdown
+ 0x58 Test
+ 0x59 Vendorspecificcommand
+ 0x60 Present
+ 0x61 Good
+ 0x62 InternalFailure
+ 0x63 VoltageOutOfRange
+ 0x64 FrequencyOutOfRange
+ 0x65 Overload
+ 0x66 OverCharged
+ 0x67 OverTemperature
+ 0x68 ShutdownRequested
+ 0x69 ShutdownImminent
+ 0x6A VendorSpecificAnswerValid
+ 0x6B SwitchOn/Off
+ 0x6C Switcheble
+ 0x6D Used
+ 0x6E Boost
+ 0x6F Buck
+ 0x70 Initialized
+ 0x71 Tested
+
+133 Battery System
+ 0x00 Undefined
+ 0x01 SMBBatteryMode
+ 0x02 SMBBatteryStatus
+ 0x03 SMBAlarmWarning
+ 0x04 SMBChargerMode
+ 0x05 SMBChargerStatus
+ 0x06 SMBChargerSpecInfo
+ 0x07 SMBSelectorState
+ 0x08 SMBSelectorPreset
+ 0x09 SMBSelectorInfo
+ 0x10 OptionalMfgFunction1
+ 0x11 OptionalMfgFunction2
+ 0x12 OptionalMfgFunction3
+ 0x13 OptionalMfgFunction4
+ 0x14 OptionalMfgFunction5
+ 0x15 ConnectionToSMBus
+ 0x16 OutputConnection
+ 0x17 ChargerConnection
+ 0x18 BatteryInsertion
+ 0x19 Usenext
+ 0x1A OKToUse
+ 0x28 ManufacturerAccess
+ 0x29 RemainingCapacityLimit
+ 0x2A RemainingTimeLimit
+ 0x2B AtRate
+ 0x2C CapacityMode
+ 0x2D BroadcastToCharger
+ 0x2E PrimaryBattery
+ 0x2F ChargeController
+ 0x40 TerminateCharge
+ 0x41 TermminateDischarge
+ 0x42 BelowRemainingCapacityLimit
+ 0x43 RemainingTimeLimitExpired
+ 0x44 Charging
+ 0x45 Discharging
+ 0x46 FullyCharged
+ 0x47 FullyDischarged
+ 0x48 ConditionningFlag
+ 0x49 AtRateOK
+ 0x4A SMBErrorCode
+ 0x4B NeedReplacement
+ 0x60 AtRateTimeToFull
+ 0x61 AtRateTimeToEmpty
+ 0x62 AverageCurrent
+ 0x63 Maxerror
+ 0x64 RelativeStateOfCharge
+ 0x65 AbsoluteStateOfCharge
+ 0x66 RemainingCapacity
+ 0x67 FullChargeCapacity
+ 0x68 RunTimeToEmpty
+ 0x69 AverageTimeToEmpty
+ 0x6A AverageTimeToFull
+ 0x6B CycleCount
+ 0x80 BattPackModelLevel
+ 0x81 InternalChargeController
+ 0x82 PrimaryBatterySupport
+ 0x83 DesignCapacity
+ 0x84 SpecificationInfo
+ 0x85 ManufacturerDate
+ 0x86 SerialNumber
+ 0x87 iManufacturerName
+ 0x88 iDevicename
+ 0x89 iDeviceChemistery
+ 0x8A iManufacturerData
+ 0x8B Rechargeable
+ 0x8C WarningCapacityLimit
+ 0x8D CapacityGranularity1
+ 0x8E CapacityGranularity2
+ 0xC0 InhibitCharge
+ 0xC1 EnablePolling
+ 0xC2 ResetToZero
+ 0xD0 ACPresent
+ 0xD1 BatteryPresent
+ 0xD2 PowerFail
+ 0xD3 AlarmInhibited
+ 0xD4 ThermistorUnderRange
+ 0xD5 ThermistorHot
+ 0xD6 ThermistorCold
+ 0xD7 ThermistorOverRange
+ 0xD8 VoltageOutOfRange
+ 0xD9 CurrentOutOfRange
+ 0xDA CurrentNotRegulated
+ 0xDB VoltageNotRegulated
+ 0xDC MasterMode
+ 0xDD ChargerBattery/HostControlled
+ 0xF0 ChargerSpecInfo
+ 0xF1 ChargerSpecRef
+ 0xF2 Level2
+ 0xF3 Level3
+
+140 Bar Code Scanner
+
+141 Scale Device
+
+144 Camera Control
+
+145 Arcade Device
+
+# Some Micro$oft non-standard extensions
+0xff00 Microsoft
+ 0xe9 Base Up
+ 0xea Base Down
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usbvar.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usbvar.h
new file mode 100644
index 000000000..60883dd47
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/libusb/usbvar.h
@@ -0,0 +1,34 @@
+/* $NetBSD: usbvar.h,v 1.2 1999/05/11 21:15:46 augustss Exp $ */
+
+/*
+ * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/libusb/usbvar.h,v 1.1.2.2 1999/12/03 10:12:43 hohndel Exp $ */
+
+struct report_desc {
+ unsigned int size;
+ unsigned char data[1];
+};
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/memrange.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/memrange.h
new file mode 100644
index 000000000..0f4b270f4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/memrange.h
@@ -0,0 +1,72 @@
+/*
+ * Memory range attribute operations, peformed on /dev/mem
+ *
+ * $FreeBSD: src/sys/sys/memrange.h,v 1.4 1999/12/29 04:24:44 peter Exp $
+ */
+/* $XFree86$ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _MEMRANGE_H
+#define _MEMRANGE_H
+
+/* Memory range attributes */
+#define MDF_UNCACHEABLE (1<<0) /* region not cached */
+#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine"
+ * action */
+#define MDF_WRITETHROUGH (1<<2) /* write-through cached */
+#define MDF_WRITEBACK (1<<3) /* write-back cached */
+#define MDF_WRITEPROTECT (1<<4) /* read-only region */
+#define MDF_ATTRMASK (0x00ffffff)
+
+#define MDF_FIXBASE (1<<24) /* fixed base */
+#define MDF_FIXLEN (1<<25) /* fixed length */
+#define MDF_FIRMWARE (1<<26) /* set by firmware (XXX not useful?) */
+#define MDF_ACTIVE (1<<27) /* currently active */
+#define MDF_BOGUS (1<<28) /* we don't like it */
+#define MDF_FIXACTIVE (1<<29) /* can't be turned off */
+#define MDF_BUSY (1<<30) /* range is in use */
+
+struct mem_range_desc {
+ u_int64_t mr_base;
+ u_int64_t mr_len;
+ int mr_flags;
+ char mr_owner[8];
+};
+
+struct mem_range_op {
+ struct mem_range_desc *mo_desc;
+ int mo_arg[2];
+#define MEMRANGE_SET_UPDATE 0
+#define MEMRANGE_SET_REMOVE 1
+ /* XXX want a flag that says "set and undo when I exit" */
+};
+#define MEMRANGE_GET _IOWR('m', 50, struct mem_range_op)
+#define MEMRANGE_SET _IOW('m', 51, struct mem_range_op)
+
+#ifdef _KERNEL
+
+struct mem_range_softc;
+struct mem_range_ops {
+ void (*init) __P((struct mem_range_softc * sc));
+ int (*set) __P((struct mem_range_softc * sc, struct mem_range_desc * mrd, int *arg));
+ void (*initAP) __P((struct mem_range_softc * sc));
+};
+
+struct mem_range_softc {
+ struct mem_range_ops *mr_op;
+ int mr_cap;
+ int mr_ndesc;
+ struct mem_range_desc *mr_desc;
+};
+
+extern struct mem_range_softc mem_range_softc;
+
+extern int mem_range_attr_get __P((struct mem_range_desc * mrd, int *arg));
+extern int mem_range_attr_set __P((struct mem_range_desc * mrd, int *arg));
+extern void mem_range_AP_init __P((void));
+#endif
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/ppc_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/ppc_video.c
new file mode 100644
index 000000000..edcb20c1b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/ppc_video.c
@@ -0,0 +1,141 @@
+/* $XFree86: ppc_video.c,v 1.5 2003/03/14 13:46:04 tsi Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XConsortium: bsd_video.c /main/10 1996/10/25 11:37:57 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#include "bus/Pci.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((caddr_t)-1)
+#endif
+
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+#ifndef __OpenBSD__
+#define DEV_MEM "/dev/mem"
+#else
+#define DEV_MEM "/dev/xf86"
+#endif
+
+static pointer ppcMapVidMem(int, unsigned long, unsigned long, int flags);
+static void ppcUnmapVidMem(int, pointer, unsigned long);
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ pVidMem->linearSupported = TRUE;
+ pVidMem->mapMem = ppcMapVidMem;
+ pVidMem->unmapMem = ppcUnmapVidMem;
+ pVidMem->initialised = TRUE;
+}
+
+
+volatile unsigned char *ioBase = MAP_FAILED;
+
+static pointer
+ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ int fd = xf86Info.screenFd;
+ pointer base;
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d",
+ Base, Size, fd);
+#endif
+
+ base = mmap(0, Size,
+ (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, fd, Base);
+ if (base == MAP_FAILED)
+ FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)",
+ "xf86MapVidMem", Size, Base, strerror(errno));
+
+ return base;
+}
+
+static void
+ppcUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap(Base, Size);
+}
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+ int rv;
+ static int kmem = -1;
+
+ if (kmem == -1) {
+ kmem = open(DEV_MEM, 2);
+ if (kmem == -1) {
+ FatalError("xf86ReadBIOS: open %s", DEV_MEM);
+ }
+ }
+
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n",
+ Base, Offset, Len);
+#endif
+
+
+ lseek(kmem, Base + Offset, 0);
+ rv = read(kmem, Buf, Len);
+
+ return rv;
+}
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts()
+{
+
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/sparc64_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/sparc64_video.c
new file mode 100644
index 000000000..d9dfcca31
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsd/sparc64_video.c
@@ -0,0 +1,113 @@
+/* $XFree86: sparc64_video.c,v 1.2 2003/03/14 13:46:04 tsi Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+
+/* $XConsortium: bsd_video.c /main/10 1996/10/25 11:37:57 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((caddr_t)-1)
+#endif
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+static pointer sparc64MapVidMem(int, unsigned long, unsigned long, int);
+static void sparc64UnmapVidMem(int, pointer, unsigned long);
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ pVidMem->linearSupported = TRUE;
+ pVidMem->mapMem = sparc64MapVidMem;
+ pVidMem->unmapMem = sparc64UnmapVidMem;
+ pVidMem->initialised = TRUE;
+}
+
+static pointer
+sparc64MapVidMem(int ScreenNum, unsigned long Base, unsigned long Size,
+ int flags)
+{
+ int fd = xf86Info.screenFd;
+ pointer base;
+
+#ifdef DEBUG
+ xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d",
+ Base, Size, fd);
+#endif
+
+ base = mmap(0, Size,
+ (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, fd, Base);
+ if (base == MAP_FAILED)
+ FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)",
+ "xf86MapVidMem", Size, Base, strerror(errno));
+ return base;
+}
+
+static void
+sparc64UnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap(Base, Size);
+}
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+
+ return (0);
+}
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts()
+{
+
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/Imakefile
new file mode 100644
index 000000000..820f76c20
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/Imakefile
@@ -0,0 +1,46 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsdi/Imakefile,v 3.14 2002/10/11 01:46:58 dawes Exp $
+
+
+
+
+XCOMM $XConsortium: Imakefile /main/4 1996/09/28 17:23:38 rws $
+
+#include <Server.tmpl>
+
+MOUSESRC = bsdi_mouse.c
+MOUSEOBJ = bsdi_mouse.o
+
+SRCS = bsdi_init.c bsdi_video.c bsdi_io.c bios_devmem.c \
+ VTsw_noop.c std_kbdEv.c posix_tty.c $(MOUSESRC) \
+ libc_wrapper.c stdResource.c stdPci.c sigiostubs.c pm_noop.c \
+ kmod_noop.c agp_noop.c
+
+OBJS = bsdi_init.o bsdi_video.o bsdi_io.o bios_devmem.o \
+ VTsw_noop.o std_kbdEv.o posix_tty.o $(MOUSEOBJ) \
+ libc_wrapper.o stdResource.o stdPci.o sigiostubs.o pm_noop.o \
+ kmod_noop.o agp_noop.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC)
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+LinkSourceFile(bios_devmem.c,../shared)
+LinkSourceFile(VTsw_noop.c,../shared)
+LinkSourceFile(std_kbdEv.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+
+DependTarget()
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_init.c
new file mode 100644
index 000000000..5a166ed26
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_init.c
@@ -0,0 +1,156 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_init.c,v 3.5.4.2 1998/06/05 16:23:08 dawes Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: bsdi_init.c /main/5 1996/02/21 17:51:15 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include <sys/param.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+extern Bool RunFromSmartParent;
+
+static Bool KeepTty = FALSE;
+
+#if BSD >= 199306
+static void
+NonBlockConsoleOff()
+{
+ register int i;
+
+ i = fcntl(2, F_GETFL, 0);
+ if (i >= 0)
+ (void) fcntl(2, F_SETFL, i & ~FNDELAY);
+}
+#endif
+
+void
+xf86OpenConsole()
+{
+ int i, fd;
+
+ if (serverGeneration == 1)
+ {
+ /* check if we're run with euid==0 */
+ if (geteuid() != 0)
+ {
+ FatalError("xf86OpenConsole: Server must be suid root\n");
+ }
+
+ if (!KeepTty)
+ {
+#if BSD >= 199306
+ if (RunFromSmartParent) {
+ if (atexit(NonBlockConsoleOff))
+ xf86Msg(X_WARNING,
+ "InitOutput: can't register NBIO exit handler\n");
+ i = fcntl(2, F_GETFL, 0);
+ if (i >= 0)
+ i = fcntl(2, F_SETFL, i | FNDELAY);
+ if (i < 0)
+ xf86Msg(X_WARNING,
+ "InitOutput: can't put stderr in non-block mode\n");
+ }
+#else
+ /*
+ * detaching the controlling tty solves problems of kbd character
+ * loss. This is not interesting for CO driver, because it is
+ * exclusive.
+ */
+ setpgrp(0, getpid());
+ if ((i = open("/dev/tty",O_RDWR)) >= 0)
+ {
+ ioctl(i,TIOCNOTTY,(char *)0);
+ close(i);
+ }
+#endif
+ }
+
+ if ((xf86Info.consoleFd = open("/dev/kbd", O_RDWR|O_NDELAY,0)) < 0)
+ {
+ FatalError("xf86OpenConsole: Cannot open /dev/kbd (%s)\n",
+ strerror(errno));
+ }
+ if ((xf86Info.screenFd = open("/dev/vga", O_RDWR|O_NDELAY,0)) < 0)
+ {
+ FatalError("xf86OpenConsole: Cannot open /dev/vga (%s)\n",
+ strerror(errno));
+ }
+
+ if (ioctl(xf86Info.consoleFd, PCCONIOCRAW, 0) < 0)
+ {
+ FatalError("%s: PCCONIOCRAW failed (%s)\n",
+ "xf86OpenConsole", strerror(errno));
+ }
+ }
+ return;
+}
+
+void
+xf86CloseConsole()
+{
+ ioctl (xf86Info.consoleFd, PCCONIOCCOOK, 0);
+
+ if (xf86Info.screenFd != xf86Info.consoleFd)
+ {
+ close(xf86Info.screenFd);
+ }
+ close(xf86Info.consoleFd);
+ return;
+}
+
+int
+xf86ProcessArgument (int argc, char *argv[], int i)
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful
+ * when debugging (so the server can receive keyboard signals.
+ */
+ if (!strcmp(argv[i], "-keeptty"))
+ {
+ KeepTty = TRUE;
+ return(1);
+ }
+ return(0);
+}
+
+void
+xf86UseMsg()
+{
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_io.c
new file mode 100644
index 000000000..e37bf308c
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_io.c
@@ -0,0 +1,110 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_io.c,v 3.13 2002/10/11 01:40:34 dawes Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Dawes make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID DAWES DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID DAWES BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: bsdi_io.c /main/10 1996/10/19 18:06:13 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ if (loudness && pitch)
+ {
+ int data[2];
+
+ data[0] = pitch;
+ data[1] = (duration * loudness) / 50;
+ ioctl(xf86Info.consoleFd, PCCONIOCBEEP, data);
+ }
+}
+
+void
+xf86SetKbdLeds(int leds)
+{
+ ioctl(xf86Info.consoleFd, PCCONIOCSETLED, &leds);
+}
+
+int
+xf86GetKbdLeds()
+{
+ return(0);
+}
+
+void
+xf86SetKbdRepeat(char rad)
+{
+ return;
+}
+
+static struct termio kbdtty;
+
+void
+xf86KbdInit()
+{
+ tcgetattr(xf86Info.consoleFd, &kbdtty);
+}
+
+int
+xf86KbdOn()
+{
+ struct termios nTty;
+
+ nTty = kbdtty;
+ nTty.c_iflag = IGNPAR | IGNBRK;
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME] = 0;
+ nTty.c_cc[VMIN] = 1;
+ cfsetispeed(&nTty, 9600);
+ cfsetospeed(&nTty, 9600);
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty);
+ return(xf86Info.consoleFd);
+}
+
+int
+xf86KbdOff()
+{
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &kbdtty);
+ return(xf86Info.consoleFd);
+}
+
+#include "xf86OSKbd.h"
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_mouse.c
new file mode 100644
index 000000000..fb50cfcee
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_mouse.c
@@ -0,0 +1,34 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_mouse.c,v 1.1 1999/05/22 08:40:10 dawes Exp $ */
+
+/*
+ * Copyright 1999 by The XFree86 Project, Inc.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+
+static int
+SupportedInterfaces(void)
+{
+ /* XXX This needs to be checked. */
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+ return p;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_video.c
new file mode 100644
index 000000000..5b1e474c7
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_video.c
@@ -0,0 +1,182 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsdi/bsdi_video.c,v 3.10 2003/03/14 13:46:05 tsi Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: bsdi_video.c /main/4 1996/02/21 17:51:22 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+pointer
+xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
+{
+ pointer base;
+
+ /* just try the mapping, and either it will work, or not */
+ base = mmap(0, Size,
+ (Flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_FILE, xf86Info.screenFd, Base - 0xA0000);
+ if (base == MAP_FAILED)
+ {
+ FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s) at 0x%x\n",
+ strerror(errno), Base);
+ }
+ return(base);
+}
+
+void
+xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap((caddr_t)Base, Size);
+}
+
+Bool
+xf86LinearVidMem()
+{
+ return(TRUE);
+}
+
+/***************************************************************************/
+/* I/O Permissions section */
+/***************************************************************************/
+
+/*
+ * BSDI has a single system-wide TSS I/O bitmap that covers ports up to
+ * 0xFFFF. By default, the TSS has ports 0x3B0-0x3DF enabled.
+ *
+ * It also allows the IOPL to be enabled or disabled on a per-process
+ * basis. Here, we use the IOPL only.
+ */
+
+static Bool ExtendedEnabled = FALSE;
+
+Bool
+xf86EnableIO()
+{
+ if (ExtendedEnabled)
+ return TRUE;
+
+ if (ioctl(xf86Info.consoleFd, PCCONENABIOPL, 0) < 0)
+ {
+ xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n",
+ "xf86EnableIOPorts");
+ return FALSE;
+ }
+ ExtendedEnabled = TRUE;
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ if (!ExtendedEnabled)
+ return;
+
+ ioctl(xf86Info.consoleFd, PCCONDISABIOPL, 0);
+ ExtendedEnabled = FALSE;
+}
+
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts()
+{
+ if (!ExtendedEnabled)
+ {
+ if (ioctl(xf86Info.consoleFd, PCCONENABIOPL, 0) < 0)
+ {
+ return(FALSE);
+ }
+ }
+
+#ifdef __GNUC__
+ __asm__ __volatile__("cli");
+#else
+ asm("cli");
+#endif /* __GNUC__ */
+
+ if (!ExtendedEnabled)
+ {
+ ioctl(xf86Info.consoleFd, PCCONDISABIOPL, 0);
+ }
+
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+ if (!ExtendedEnabled)
+ {
+ ioctl(xf86Info.consoleFd, PCCONENABIOPL, 0);
+ }
+
+#ifdef __GNUC__
+ __asm__ __volatile__("sti");
+#else
+ asm("sti");
+#endif /* __GNUC__ */
+
+ if (!ExtendedEnabled)
+ {
+ ioctl(xf86Info.consoleFd, PCCONDISABIOPL, 0);
+ }
+
+ return;
+}
+
+void
+xf86MapReadSideEffects(int ScreenNum, int Flags, pointer Base,
+ unsigned long Size)
+{
+}
+
+Bool
+xf86CheckMTRR(int ScreenNum)
+{
+ return FALSE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.c
new file mode 100644
index 000000000..255dfa12f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.c
@@ -0,0 +1,470 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.c,v 1.4 2003/08/29 21:08:06 tsi Exp $ */
+/*
+ * Copyright (C) 2002-2003 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, 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
+ * XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+
+/*
+ * This file contains the glue necessary for support of Intel's 460GX chipset.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "460gxPCI.h"
+#include "xf86.h"
+#include "Pci.h"
+
+/* 460GX register definitions */
+/* SAC at 0:10:0 */
+#define CBN 0x0040
+/* SAC at CBN:0:0 */
+#define DEVNPRES 0x0070
+/* SAC at CBN:1[0-7]:0 */
+#define BUSNO 0x0048
+#define SUBNO 0x0049
+#define VGASE 0x0080
+#define PCIS 0x0084
+#define IOR 0x008C
+#define IORD 0x008E /* CBN:10:0 only */
+/* PXB at CBN:1[0-7]:1 */
+#define ERRCMD 0x0046
+
+static int cbn_460gx = -1;
+static CARD32 cbdevs_460gx = 0;
+static CARD16 iord_460gx;
+static int busno_460gx[8], subno_460gx[8];
+static CARD8 pcis_460gx[8], ior_460gx[8];
+static CARD8 has_err_460gx[8], err_460gx[8];
+static CARD8 iomap_460gx[16]; /* One for each 4k */
+static pciBusFuncs_t BusFuncs_460gx;
+
+static pciConfigPtr
+Verify460GXBus(int bus)
+{
+ pciConfigPtr pPCI;
+
+ if ((bus < 0) || (bus >= pciNumBuses) ||
+ !pciBusInfo[bus] || !(pPCI = pciBusInfo[bus]->bridge) ||
+ (pPCI->busnum != cbn_460gx) || (pPCI->funcnum != 0) ||
+ (pPCI->devnum < 0x10) || (pPCI->devnum > 0x17))
+ return NULL;
+
+ return pPCI;
+}
+
+/*
+ * This function is called to emulate the various settings in a P2P or CardBus
+ * bridge's control register using one of a 460GX's SAC host bridges.
+ */
+static CARD16
+Control460GXBridge(int bus, CARD16 mask, CARD16 value)
+{
+ pciConfigPtr pPCI;
+ PCITAG tag;
+ CARD16 current = 0;
+ CARD8 tmp;
+
+ if ((pPCI = Verify460GXBus(bus))) {
+ /* Start with VGA enablement */
+ tmp = pciReadByte(pPCI->tag, VGASE);
+ if (tmp & 0x01) {
+ current |= PCI_PCI_BRIDGE_VGA_EN;
+ if ((mask & PCI_PCI_BRIDGE_VGA_EN) &&
+ !(value & PCI_PCI_BRIDGE_VGA_EN))
+ pciWriteByte(pPCI->tag, VGASE, tmp & ~0x01);
+ } else {
+ if (mask & value & PCI_PCI_BRIDGE_VGA_EN)
+ pciWriteByte(pPCI->tag, VGASE, tmp | 0x01);
+ }
+
+ /* Move on to master abort failure enablement */
+ if (has_err_460gx[pPCI->devnum - 0x10]) {
+ tag = PCI_MAKE_TAG(pPCI->busnum, pPCI->devnum, pPCI->funcnum + 1);
+ tmp = pciReadByte(tag, ERRCMD);
+ if (tmp & 0x01) {
+ current |= PCI_PCI_BRIDGE_MASTER_ABORT_EN;
+ if ((mask & PCI_PCI_BRIDGE_MASTER_ABORT_EN) &&
+ !(value & PCI_PCI_BRIDGE_MASTER_ABORT_EN))
+ pciWriteByte(tag, ERRCMD, tmp & ~0x01);
+ } else {
+ if (mask & value & PCI_PCI_BRIDGE_MASTER_ABORT_EN)
+ pciWriteByte(tag, ERRCMD, tmp | 0x01);
+ }
+ }
+
+ /* Put emulation of any other P2P bridge control here */
+ }
+
+ return (current & ~mask) | (value & mask);
+}
+
+/*
+ * Retrieve various bus numbers representing the connections provided by 460GX
+ * host bridges.
+ */
+static void
+Get460GXBridgeBuses(int bus, int *primary, int *secondary, int *subordinate)
+{
+ pciConfigPtr pPCI = Verify460GXBus(bus);
+ int i;
+
+ /* The returned bus numbers are initialised by the caller */
+
+ if (!pPCI)
+ return;
+
+ i = pPCI->devnum - 0x10;
+
+ /* These are not modified, so no need to re-read them */
+ if (primary)
+ *primary = pPCI->busnum;
+ if (secondary)
+ *secondary = busno_460gx[i];
+ if (subordinate)
+ *subordinate = subno_460gx[i];
+}
+
+/* Retrieves a list of the resources routed to a host bridge's secondary bus */
+static void
+Get460GXBridgeResources(int bus,
+ pointer *ppIoRes,
+ pointer *ppMemRes,
+ pointer *ppPmemRes)
+{
+ pciConfigPtr pPCI = Verify460GXBus(bus);
+ resRange range;
+ unsigned int i, j;
+
+ if (ppIoRes) {
+ xf86FreeResList(*ppIoRes);
+ *ppIoRes = NULL;
+
+ if (pPCI) {
+ for (i = 0; i <= 0x0F; i++) {
+ if (iomap_460gx[i] != pPCI->devnum)
+ continue;
+
+ RANGE(range, i << 12, ((i + 1) << 12) - 1,
+ RANGE_TYPE(ResExcIoBlock, 0));
+ *ppIoRes = xf86AddResToList(*ppIoRes, &range, -1);
+ }
+ }
+ }
+
+ if (ppMemRes) {
+ xf86FreeResList(*ppMemRes);
+ *ppMemRes = NULL;
+
+ if (pPCI) {
+ if (!(i = (pPCI->devnum - 0x10)))
+ j = 127; /* (4GB - 32M) / 32M */
+ else
+ j = pcis_460gx[i - 1] & 0x7F;
+
+ i = pcis_460gx[i] & 0x7F;
+ if (i < j) {
+ RANGE(range, i << 25, (j << 25) - 1,
+ RANGE_TYPE(ResExcMemBlock, 0));
+ *ppMemRes = xf86AddResToList(*ppMemRes, &range, -1);
+ }
+ }
+ }
+
+ if (ppPmemRes) {
+ xf86FreeResList(*ppPmemRes);
+ *ppPmemRes = NULL;
+ }
+}
+
+/*
+ * This checks for, and validates, the presence of the 460GX chipset, and sets
+ * cbn_460gx to a positive value accordingly. This function returns TRUE if
+ * the chipset scan is to be stopped, or FALSE if the scan is to move on to the
+ * next chipset.
+ */
+
+Bool
+xorgProbe460GX(scanpciWrapperOpt flags)
+{
+ pciBusInfo_t *pBusInfo;
+ PCITAG tag;
+
+ /* Bus zero should already be set up */
+ if (!(pBusInfo = pciBusInfo[0])) {
+ cbn_460gx = -1;
+ return FALSE;
+ }
+ /* First look for a 460GX's primary host bridge */
+ tag = PCI_MAKE_TAG(0, 0x10, 0);
+ if (pciReadLong(tag, PCI_ID_REG) == DEVID(VENDOR_INTEL, CHIP_460GX_SAC)) {
+ return TRUE;
+ }
+
+ cbn_460gx = -1;
+
+ return FALSE;
+}
+
+void
+xf86PreScan460GX(void)
+{
+ pciBusInfo_t *pBusInfo;
+ PCITAG tag;
+ CARD32 tmp;
+ int i, devno;
+
+ if (!(pBusInfo = pciBusInfo[0]))
+ return;
+
+ /* Get CBN (Chipset bus number) */
+ tag = PCI_MAKE_TAG(0, 0x10, 0);
+ if (!(cbn_460gx = (unsigned int)pciReadByte(tag, CBN))) {
+ /* Sanity check failed */
+ cbn_460gx = -1;
+ return;
+ }
+
+ if (pciNumBuses <= cbn_460gx)
+ pciNumBuses = cbn_460gx + 1;
+
+ /* Set up bus CBN */
+ if (!pciBusInfo[cbn_460gx]) {
+ pciBusInfo[cbn_460gx] = xnfalloc(sizeof(pciBusInfo_t));
+ *pciBusInfo[cbn_460gx] = *pBusInfo;
+ }
+
+ tag = PCI_MAKE_TAG(cbn_460gx, 0, 0);
+ if (pciReadLong(tag, PCI_ID_REG) != DEVID(VENDOR_INTEL, CHIP_460GX_SAC)) {
+ /* Sanity check failed */
+ cbn_460gx = -1;
+ return;
+ }
+
+ /*
+ * Find out which CBN devices the firmware thinks are present. Of these,
+ * we are only interested in devices 0x10 through 0x17.
+ */
+ cbdevs_460gx = pciReadLong(tag, DEVNPRES);
+
+ for (i = 0, devno = 0x10; devno <= 0x17; i++, devno++) {
+ tag = PCI_MAKE_TAG(cbn_460gx, devno, 0);
+ if (pciReadLong(tag, PCI_ID_REG) !=
+ DEVID(VENDOR_INTEL, CHIP_460GX_SAC)) {
+ /* Sanity check failed */
+ cbn_460gx = -1;
+ return;
+ }
+
+ if (devno == 0x10)
+ iord_460gx = pciReadWord(tag, IORD);
+
+ busno_460gx[i] = (unsigned int)pciReadByte(tag, BUSNO);
+ subno_460gx[i] = (unsigned int)pciReadByte(tag, SUBNO);
+ pcis_460gx[i] = pciReadByte(tag, PCIS);
+ ior_460gx[i] = pciReadByte(tag, IOR);
+
+ has_err_460gx[i] = err_460gx[i] = 0; /* Insurance */
+
+ tag = PCI_MAKE_TAG(cbn_460gx, devno, 1);
+ tmp = pciReadLong(tag, PCI_ID_REG);
+ switch (tmp) {
+ case DEVID(VENDOR_INTEL, CHIP_460GX_PXB):
+ case DEVID(VENDOR_INTEL, CHIP_460GX_WXB):
+ if (cbdevs_460gx & (1 << devno)) {
+ /* Sanity check failed */
+ cbn_460gx = -1;
+ return;
+ }
+
+ /*
+ * XXX I don't have WXB docs, but PCI register dumps indicate that
+ * the registers we are interested in are consistent with those of
+ * the PXB.
+ */
+ err_460gx[i] = pciReadByte(tag, ERRCMD);
+ has_err_460gx[i] = 1;
+ break;
+
+ case DEVID(VENDOR_INTEL, CHIP_460GX_GXB_1):
+ if (cbdevs_460gx & (1 << devno)) {
+ /* Sanity check failed */
+ cbn_460gx = -1;
+ return;
+ }
+
+ /*
+ * XXX GXB isn't documented to have an ERRCMD register, nor any
+ * other means of failing master aborts. For now, assume master
+ * aborts are always allowed to complete normally.
+ */
+ break;
+
+ default:
+ if (((CARD16)(tmp + 1U) <= (CARD16)1U) &&
+ (cbdevs_460gx & (1U << devno)))
+ break;
+ /* Sanity check failed */
+ cbn_460gx = -1;
+ return;
+ }
+ }
+
+ /* Allow master aborts to complete normally */
+ for (i = 0, devno = 0x10; devno <= 0x17; i++, devno++) {
+ if (!(err_460gx[i] & 0x01))
+ continue;
+
+ pciWriteByte(PCI_MAKE_TAG(cbn_460gx, devno, 1),
+ ERRCMD, err_460gx[i] & ~0x01);
+ }
+
+ /*
+ * The 460GX spec says that any access to buses higher than CBN will be
+ * master-aborted. It seems possible however that this is not the case in
+ * all 460GX implementations. For now, limit the bus scan to CBN, unless
+ * we have already found a higher bus number.
+ */
+ for (i = 0; subno_460gx[i] < cbn_460gx; ) {
+ if (++i < 8)
+ continue;
+
+ pciMaxBusNum = cbn_460gx + 1;
+ break;
+ }
+
+ return;
+}
+
+/* This does some 460GX-related processing after the PCI bus scan */
+void
+xf86PostScan460GX(void)
+{
+ pciConfigPtr pPCI, *ppPCI;
+ pciBusInfo_t *pBusInfo;
+ int i, j, devno;
+
+ if (cbn_460gx <= 0)
+ return;
+
+ /* Set up our extra bus functions */
+ BusFuncs_460gx = *(pciBusInfo[0]->funcs);
+ BusFuncs_460gx.pciControlBridge = Control460GXBridge;
+ BusFuncs_460gx.pciGetBridgeBuses = Get460GXBridgeBuses;
+ BusFuncs_460gx.pciGetBridgeResources = Get460GXBridgeResources;
+
+ /*
+ * Mark all host bridges so that they are ignored by the upper-level
+ * xf86GetPciBridgeInfo() function. This marking is later clobbered by the
+ * tail end of xf86scanpci() for those bridges that actually have bus
+ * segments associated with them.
+ */
+ ppPCI = xf86scanpci(0); /* Recursion is only apparent */
+ while ((pPCI = *ppPCI++)) {
+ if ((pPCI->pci_base_class == PCI_CLASS_BRIDGE) &&
+ (pPCI->pci_sub_class == PCI_SUBCLASS_BRIDGE_HOST))
+ pPCI->businfo = HOST_NO_BUS;
+ }
+
+ ppPCI = xf86scanpci(0); /* Recursion is only apparent */
+ j = 0;
+
+ /*
+ * Fix up CBN bus linkage. This is somewhat arbitrary. The bridge chosen
+ * for this must be a CBN device so that bus CBN can be recognised as the
+ * root segment. It also cannot be any of the bus expanders (devices
+ * CBN:0x10:0 through CBN:0x17:0 nor any of their functions). For now, we
+ * chose the SAC host bridge at CBN:0:0.
+ */
+ pBusInfo = pciBusInfo[cbn_460gx];
+ pBusInfo->bridge = pciBusInfo[0]->bridge; /* Just in case */
+ while ((pPCI = *ppPCI++)) {
+ if (pPCI->busnum < cbn_460gx)
+ continue;
+ if (pPCI->busnum > cbn_460gx)
+ break;
+ if (pPCI->devnum < 0)
+ continue;
+ if (pPCI->devnum > 0)
+ break;
+ if (pPCI->funcnum < 0)
+ continue;
+ if (pPCI->funcnum > 0)
+ break;
+
+ pBusInfo->bridge = pPCI;
+ pBusInfo->secondary = FALSE;
+ pBusInfo->primary_bus = cbn_460gx;
+ break;
+ }
+
+ for (i = 0, devno = 0x10; devno <= 0x17; i++, devno++) {
+ /* Restore ERRCMD registers */
+ if (err_460gx[i] & 0x01)
+ pciWriteByte(PCI_MAKE_TAG(cbn_460gx, devno, 1),
+ ERRCMD, err_460gx[i]);
+
+ if (!(cbdevs_460gx & (1 << devno))) {
+ while ((pPCI = *ppPCI++)) {
+ if (pPCI->busnum < cbn_460gx)
+ continue;
+ if (pPCI->busnum > cbn_460gx)
+ break;
+ if (pPCI->devnum < devno)
+ continue;
+ if (pPCI->devnum > devno)
+ break;
+ if (pPCI->funcnum < 0)
+ continue;
+ if (pPCI->funcnum > 0)
+ break;
+
+ if ((pBusInfo == pciBusInfo[busno_460gx[i]]))
+ break;
+
+ /* Fix bus linkage */
+ pBusInfo->bridge = pPCI;
+ pBusInfo->secondary = TRUE;
+ pBusInfo->primary_bus = cbn_460gx;
+
+ /* Plug in chipset routines */
+ pBusInfo->funcs = &BusFuncs_460gx;
+ break;
+ }
+ }
+
+ /* Decode IOR registers */
+ for(; j <= (ior_460gx[i] & 0x0F); j++)
+ iomap_460gx[j] = devno;
+ }
+
+ /* The bottom 4k of I/O space is always routed to PCI0a */
+ iomap_460gx[0] = 0x10;
+
+ /* Decode IORD register */
+ for (j = 1; j <= 0x0F; j++)
+ if (iord_460gx & (1 << j))
+ iomap_460gx[j] = 0x10;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.h
new file mode 100644
index 000000000..65a19b2f0
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.h
@@ -0,0 +1,42 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/460gxPCI.h,v 1.1 2003/01/02 18:12:48 tsi Exp $ */
+/*
+ * Copyright (C) 2002-2003 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, 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
+ * XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef PCI_460GX_H
+#define PCI_460GX_H 1
+
+#include <X11/Xdefs.h>
+#include <Pci.h>
+
+Bool xorgProbe460GX(scanpciWrapperOpt flags);
+void xf86PreScan460GX(void);
+void xf86PostScan460GX(void);
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Imakefile
new file mode 100644
index 000000000..bae6ee7c2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Imakefile
@@ -0,0 +1,165 @@
+XCOMM $XConsortium: Imakefile /main/16 1996/10/27 18:07:43 kaleb $
+
+
+
+
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/Imakefile,v 1.29tsi Exp $
+
+#include <Server.tmpl>
+
+#if defined(LinuxArchitecture) && defined(AlphaArchitecture)
+
+XCOMM Alpha (Linux) PCI driver
+
+PCIDRVRSRC = axpPci.c
+PCIDRVROBJ = axpPci.o
+
+#elif defined(LinuxArchitecture) && defined(SparcArchitecture)
+
+XCOMM Sparc SBUS driver and generic Linux PCI driver
+
+PCIDRVRSRC = sparcPci.c linuxPci.c
+PCIDRVROBJ = sparcPci.o linuxPci.o
+SBUSDRVSRC = Sbus.c
+SBUSDRVOBJ = Sbus.o
+
+#elif defined(SunArchitecture) && defined(SparcArchitecture)
+
+XCOMM Sparc SBUS & PCI drivers
+
+PCIDRVRSRC = sparcPci.c
+PCIDRVROBJ = sparcPci.o
+SBUSDRVSRC = Sbus.c
+SBUSDRVOBJ = Sbus.o
+
+#elif defined(LinuxArchitecture) && \
+ (defined(PpcArchitecture) || \
+ defined(Ppc64Architecture) || \
+ defined(MipsArchitecture) || \
+ defined(ia64Architecture) || \
+ defined(Mc68020Architecture) || \
+ defined(Arm32Architecture) || \
+ defined(HPArchitecture) || \
+ defined(s390Architecture) || \
+ defined(SuperHArchitecture) || \
+ defined(SuperHebArchitecture))
+
+XCOMM generic linux PCI driver (using /proc/bus/pci, requires kernel 2.2)
+
+PCIDRVRSRC = linuxPci.c
+PCIDRVROBJ = linuxPci.o
+
+#elif defined(OpenBSDArchitecture) && \
+ (defined(PpcArchitecture) || \
+ defined(AlphaArchitecture) || \
+ defined(Sparc64Architecture))
+
+XCOMM OpenBSD/alpha, OpenBSD/powerpc and OpenBSD/sparc64
+
+PCIDRVRSRC = freebsdPci.c
+PCIDRVROBJ = freebsdPci.o
+
+#elif defined(NetBSDArchitecture) && defined(PpcArchitecture)
+
+XCOMM NetBSD/powerpc
+
+PCIDRVRSRC = netbsdPci.c
+PCIDRVROBJ = netbsdPci.o
+
+#elif defined(FreeBSDArchitecture) && defined(PpcArchitecture)
+
+XCOMM FreeBSD/PowerPC PCI driver (using /dev/pci)
+
+PCIDRVRSRC = freebsdPci.c
+PCIDRVROBJ = freebsdPci.o
+
+#elif defined(PpcArchitecture)
+
+XCOMM PowerPC PCI drivers
+
+PCIDRVRSRC = ppcPci.c
+PCIDRVROBJ = ppcPci.o
+
+#elif defined(LinuxArchitecture) && \
+ (defined(i386Architecture) || defined(AMD64Architecture))
+
+XCOMM ix86 PCI driver with OS fallback for Linux
+
+PCIDRVRSRC = ix86Pci.c linuxPci.c
+PCIDRVROBJ = ix86Pci.o linuxPci.o
+
+#elif defined(KFreeBSDArchitecture) && \
+ (defined(AlphaArchitecture) || defined(AMD64Architecture))
+
+XCOMM generic FreeBSD PCI driver (using /dev/pci)
+
+PCIDRVRSRC = freebsdPci.c
+PCIDRVROBJ = freebsdPci.o
+
+#elif defined(KFreeBSDArchitecture) && defined(Sparc64Architecture)
+
+XCOMM Sparc SBUS & PCI drivers
+
+PCIDRVRSRC = freebsdPci.c
+PCIDRVROBJ = freebsdPci.o
+SBUSDRVSRC = Sbus.c
+SBUSDRVOBJ = Sbus.o
+
+#elif defined(NetBSDArchitecture) && defined(AlphaArchitecture)
+
+XCOMM Alpha (NetBSD) PCI driver
+
+PCIDRVRSRC = netbsdPci.c
+PCIDRVROBJ = netbsdPci.o
+
+#elif defined(i386Architecture) || \
+ defined(ia64Architecture) || \
+ defined(AMD64Architecture)
+
+XCOMM ix86 PCI driver
+
+PCIDRVRSRC = ix86Pci.c
+PCIDRVROBJ = ix86Pci.o
+XCOMM PCIDRVRSRC = linuxPci.c
+XCOMM PCIDRVROBJ = linuxPci.o
+
+#else
+XCOMM no PCI driver -- shouldn't get here
+#endif
+
+#if defined(SparcArchitecture)
+# if !defined(SunArchitecture)
+PCIARCHSRC = sparcPci.c
+PCIARCHOBJ = sparcPci.o
+# endif
+#elif defined(ia64Architecture)
+PCIARCHSRC = 460gxPCI.c e8870PCI.c zx1PCI.c altixPCI.c
+PCIARCHOBJ = 460gxPCI.o e8870PCI.o zx1PCI.o altixPCI.o
+#endif
+
+SRCS = Pci.c $(PCIDRVRSRC) $(SBUSDRVSRC) $(PCIARCHSRC)
+OBJS = Pci.o $(PCIDRVROBJ) $(SBUSDRVOBJ) $(PCIARCHOBJ)
+
+INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86OSSRC) \
+ -I$(SERVERSRC)/include -I$(XINCLUDESRC)
+
+NormalLibraryObjectRule()
+SubdirLibraryRule($(OBJS))
+
+/*
+ * egcs 1.1.2 as provided with some Linux distributions has an optimisation
+ * bug that results in bad code for this file.
+ */
+#if Egcs112Bug
+SpecialCObjectRule(Pci,NullParameter,-O0)
+#endif
+
+#if defined(SunArchitecture) && defined(SparcArchitecture)
+
+LFS_DEFINES = `getconf LFS_CFLAGS`
+
+SpecialCObjectRule(sparcPci,NullParameter,$(LFS_DEFINES))
+
+#endif
+
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Pci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Pci.c
new file mode 100644
index 000000000..4e71eb614
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Pci.c
@@ -0,0 +1,1453 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/Pci.c,v 1.82 2004/01/16 15:39:04 tsi Exp $ */
+/*
+ * Pci.c - New server PCI access functions
+ *
+ * The XFree86 server PCI access functions have been reimplemented as a
+ * framework that allows each supported platform/OS to have their own
+ * platform/OS specific pci driver.
+ *
+ * All of the public PCI access functions exported to the other parts of
+ * the server are declared in Pci.h and defined herein. These include:
+ * pciInit() - Initialize PCI access functions
+ * pciFindFirst() - Find a PCI device by dev/vend id
+ * pciFindNext() - Find another PCI device by dev/vend id
+ * pciReadLong() - Read a 32 bit value from a device's cfg space
+ * pciReadWord() - Read a 16 bit value from a device's cfg space
+ * pciReadByte() - Read an 8 bit value from a device's cfg space
+ * pciWriteLong() - Write a 32 bit value to a device's cfg space
+ * pciWriteWord() - Write a 16 bit value to a device's cfg space
+ * pciWriteByte() - Write an 8 bit value to a device's cfg space
+ * pciSetBitsLong() - Write a 32 bit value against a mask
+ * pciSetBitsByte() - Write an 8 bit value against a mask
+ * pciTag() - Return tag for a given PCI bus, device, &
+ * function
+ * pciBusAddrToHostAddr() - Convert a PCI address to a host address
+ * pciHostAddrToBusAddr() - Convert a host address to a PCI address
+ * pciGetBaseSize() - Returns the number of bits in a PCI base
+ * addr mapping
+ * xf86MapPciMem() - Like xf86MapVidMem() except function expects
+ * a PCI address and a PCITAG that identifies
+ * a PCI device
+ * xf86ReadPciBIOS() - Like xf86ReadBIOS() but can handle PCI/host
+ * address translation and BIOS decode enabling
+ * xf86scanpci() - Return info about all PCI devices
+ * xf86GetPciDomain() - Return domain number from a PCITAG
+ * xf86MapDomainMemory() - Like xf86MapPciMem() but can handle
+ * domain/host address translation
+ * xf86MapDomainIO() - Maps PCI I/O spaces
+ * xf86ReadDomainMemory() - Like xf86ReadPciBIOS() but can handle
+ * domain/host address translation
+ *
+ * The actual PCI backend driver is selected by the pciInit() function
+ * (see below) using either compile time definitions, run-time checks,
+ * or both.
+ *
+ * Certain generic functions are provided that make the implementation
+ * of certain well behaved platforms (e.g. those supporting PCI config
+ * mechanism 1 or some thing close to it) very easy.
+ *
+ * Less well behaved platforms/OS's can roll their own functions.
+ *
+ * To add support for another platform/OS, add a call to fooPciInit() within
+ * pciInit() below under the correct compile time definition or run-time
+ * conditional.
+ *
+ * The fooPciInit() procedure must do three things:
+ * 1) Initialize the pciBusTable[] for all primary PCI buses including
+ * the per domain PCI access functions (readLong, writeLong,
+ * addrBusToHost, and addrHostToBus).
+ *
+ * 2) Add entries to pciBusTable[] for configured secondary buses. This
+ * step may be skipped if a platform is using the generic findFirst/
+ * findNext functions because these procedures will automatically
+ * discover and add secondary buses dynamically.
+ *
+ * 3) Overide default settings for global PCI access functions if
+ * required. These include pciFindFirstFP, pciFindNextFP,
+ * Of course, if you choose not to use one of the generic
+ * functions, you will need to provide a platform specifc replacement.
+ *
+ * Gary Barton
+ * Concurrent Computer Corporation
+ * garyb@gate.net
+ *
+ */
+
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * This software is derived from the original XFree86 PCI code
+ * which includes the following copyright notices as well:
+ *
+ * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of the above listed copyright holder(s)
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. The above listed
+ * copyright holder(s) make(s) no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * This code is also based heavily on the code in FreeBSD-current, which was
+ * written by Wolfgang Stanglmeier, and contains the following copyright:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/*
+ * Copyright (c) 1999-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
+
+#include <errno.h>
+#include <signal.h>
+#include <X11/Xarch.h>
+#include "compiler.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSproc.h"
+#include "Pci.h"
+
+#define PCI_MFDEV_SUPPORT 1 /* Include PCI multifunction device support */
+#define PCI_BRIDGE_SUPPORT 1 /* Include support for PCI-to-PCI bridges */
+
+/*
+ * Global data
+ */
+static int pciInitialized = 0;
+
+CARD32 pciDevid; /* Requested device/vendor ID (after mask) */
+CARD32 pciDevidMask; /* Bit mask applied (AND) before comparison */
+ /* of real devid's with requested */
+
+int pciBusNum; /* Bus Number of current device */
+int pciDevNum; /* Device number of current device */
+int pciFuncNum; /* Function number of current device */
+PCITAG pciDeviceTag; /* Tag for current device */
+
+pciBusInfo_t *pciBusInfo[MAX_PCI_BUSES] = { NULL, };
+int pciNumBuses = 0; /* Actual number of PCI buses */
+int pciMaxBusNum = MAX_PCI_BUSES;
+static Bool inProbe = FALSE;
+
+static pciConfigPtr pci_devp[MAX_PCI_DEVICES + 1] = {NULL, };
+
+/*
+ * Platform specific PCI function pointers.
+ *
+ * NOTE: A platform/OS specific pci init procedure can override these defaults
+ * by setting them to the appropriate platform dependent functions.
+ */
+PCITAG (*pciFindFirstFP)(void) = pciGenFindFirst;
+PCITAG (*pciFindNextFP)(void) = pciGenFindNext;
+
+/*
+ * pciInit - choose correct platform/OS specific PCI init routine
+ */
+void
+pciInit()
+{
+ if (pciInitialized)
+ return;
+
+ pciInitialized = 1;
+
+ /* XXX */
+#if defined(DEBUGPCI)
+ if (DEBUGPCI >= xf86Verbose)
+ xf86Verbose = DEBUGPCI;
+#endif
+
+ ARCH_PCI_INIT();
+#if defined(ARCH_PCI_OS_INIT)
+ if (pciNumBuses <= 0)
+ ARCH_PCI_OS_INIT();
+#endif
+}
+
+PCITAG
+pciFindFirst(CARD32 id, CARD32 mask)
+{
+#ifdef DEBUGPCI
+ ErrorF("pciFindFirst(0x%lx, 0x%lx), pciInit = %d\n", id, mask, pciInitialized);
+#endif
+ pciInit();
+
+ pciDevid = id & mask;
+ pciDevidMask = mask;
+
+ return((*pciFindFirstFP)());
+}
+
+PCITAG
+pciFindNext(void)
+{
+#ifdef DEBUGPCI
+ ErrorF("pciFindNext(), pciInit = %d\n", pciInitialized);
+#endif
+ pciInit();
+
+ return((*pciFindNextFP)());
+}
+
+CARD32
+pciReadLong(PCITAG tag, int offset)
+{
+ int bus = PCI_BUS_FROM_TAG(tag);
+
+#ifdef DEBUGPCI
+ ErrorF("pciReadLong(0x%lx, %d)\n", tag, offset);
+#endif
+ pciInit();
+
+ if ((bus >= 0) && ((bus < pciNumBuses) || inProbe) && pciBusInfo[bus] &&
+ pciBusInfo[bus]->funcs->pciReadLong) {
+ CARD32 rv = (*pciBusInfo[bus]->funcs->pciReadLong)(tag, offset);
+
+ PCITRACE(1, ("pciReadLong: tag=0x%x [b=%d,d=%d,f=%d] returns 0x%08x\n",
+ tag, bus, PCI_DEV_FROM_TAG(tag), PCI_FUNC_FROM_TAG(tag), rv));
+ return(rv);
+ }
+
+ return(PCI_NOT_FOUND);
+}
+
+CARD16
+pciReadWord(PCITAG tag, int offset)
+{
+ CARD32 tmp;
+ int shift = (offset & 3) * 8;
+ int aligned_offset = offset & ~3;
+ int bus = PCI_BUS_FROM_TAG(tag);
+
+ if (shift != 0 && shift != 16)
+ FatalError("pciReadWord: Alignment error: Cannot read 16 bits "
+ "at offset %d\n", offset);
+
+ pciInit();
+
+ if ((bus >= 0) && ((bus < pciNumBuses) || inProbe) && pciBusInfo[bus] &&
+ pciBusInfo[bus]->funcs->pciReadWord) {
+ CARD32 rv = (*pciBusInfo[bus]->funcs->pciReadWord)(tag, offset);
+
+ return(rv);
+ } else {
+ tmp = pciReadLong(tag, aligned_offset);
+
+ return((CARD16)((tmp >> shift) & 0xffff));
+ }
+}
+
+CARD8
+pciReadByte(PCITAG tag, int offset)
+{
+ CARD32 tmp;
+ int shift = (offset & 3) * 8;
+ int aligned_offset = offset & ~3;
+ int bus = PCI_BUS_FROM_TAG(tag);
+
+ pciInit();
+
+ if ((bus >= 0) && ((bus < pciNumBuses) || inProbe) && pciBusInfo[bus] &&
+ pciBusInfo[bus]->funcs->pciReadByte) {
+ CARD8 rv = (*pciBusInfo[bus]->funcs->pciReadByte)(tag, offset);
+
+ return(rv);
+ } else {
+ tmp = pciReadLong(tag, aligned_offset);
+
+ return((CARD8)((tmp >> shift) & 0xff));
+ }
+}
+
+void
+pciWriteLong(PCITAG tag, int offset, CARD32 val)
+{
+ int bus = PCI_BUS_FROM_TAG(tag);
+
+ pciInit();
+
+ if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] &&
+ pciBusInfo[bus]->funcs->pciWriteLong)
+ (*pciBusInfo[bus]->funcs->pciWriteLong)(tag, offset, val);
+}
+
+void
+pciWriteWord(PCITAG tag, int offset, CARD16 val)
+{
+ CARD32 tmp;
+ int aligned_offset = offset & ~3;
+ int shift = (offset & 3) * 8;
+ int bus = PCI_BUS_FROM_TAG(tag);
+
+ if (shift != 0 && shift != 16)
+ FatalError("pciWriteWord: Alignment Error: Cannot read 16 bits "
+ "from offset %d\n", offset);
+
+ pciInit();
+
+ if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] &&
+ pciBusInfo[bus]->funcs->pciWriteWord) {
+ (*pciBusInfo[bus]->funcs->pciWriteWord)(tag, offset, val);
+ } else {
+ tmp = pciReadLong(tag, aligned_offset);
+
+ tmp &= ~(0xffffL << shift);
+ tmp |= (((CARD32)val) << shift);
+
+ pciWriteLong(tag, aligned_offset, tmp);
+ }
+}
+
+void
+pciWriteByte(PCITAG tag, int offset, CARD8 val)
+{
+ CARD32 tmp;
+ int aligned_offset = offset & ~3;
+ int shift = (offset & 3) *8 ;
+ int bus = PCI_BUS_FROM_TAG(tag);
+
+ pciInit();
+
+ if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] &&
+ pciBusInfo[bus]->funcs->pciWriteByte) {
+ (*pciBusInfo[bus]->funcs->pciWriteByte)(tag, offset, val);
+ } else {
+
+ tmp = pciReadLong(tag, aligned_offset);
+
+ tmp &= ~(0xffL << shift);
+ tmp |= (((CARD32)val) << shift);
+
+ pciWriteLong(tag, aligned_offset, tmp);
+ }
+}
+
+void
+pciSetBitsLong(PCITAG tag, int offset, CARD32 mask, CARD32 val)
+{
+ int bus = PCI_BUS_FROM_TAG(tag);
+
+#ifdef DEBUGPCI
+ ErrorF("pciReadLong(0x%lx, %d)\n", tag, offset);
+#endif
+ pciInit();
+
+ if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] &&
+ pciBusInfo[bus]->funcs->pciSetBitsLong) {
+ (*pciBusInfo[bus]->funcs->pciSetBitsLong)(tag, offset, mask, val);
+ }
+}
+
+void
+pciSetBitsByte(PCITAG tag, int offset, CARD8 mask, CARD8 val)
+{
+ CARD32 tmp_mask, tmp_val;
+ int aligned_offset = offset & ~3;
+ int shift = (offset & 3) *8 ;
+
+ tmp_mask = mask << shift;
+ tmp_val = val << shift;
+ pciSetBitsLong(tag, aligned_offset, tmp_mask, tmp_val);
+}
+
+ADDRESS
+pciBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr)
+{
+ int bus = PCI_BUS_FROM_TAG(tag);
+
+ pciInit();
+
+ if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] &&
+ pciBusInfo[bus]->funcs->pciAddrBusToHost)
+ return (*pciBusInfo[bus]->funcs->pciAddrBusToHost)(tag, type, addr);
+ else
+ return(addr);
+}
+
+ADDRESS
+pciHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr)
+{
+ int bus = PCI_BUS_FROM_TAG(tag);
+
+ pciInit();
+
+ if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] &&
+ pciBusInfo[bus]->funcs->pciAddrHostToBus)
+ return (*pciBusInfo[bus]->funcs->pciAddrHostToBus)(tag, type, addr);
+ else
+ return(addr);
+}
+
+/*
+ * pciGetBaseSize() returns the size of a PCI base address mapping in bits.
+ * The index identifies the base register: 0-5 are the six standard registers,
+ * and 6 is the ROM base register. If destructive is TRUE, it will write
+ * to the base address register to get an accurate result. Otherwise it
+ * makes a conservative guess based on the alignment of the already allocated
+ * address. If the result is accurate (ie, not an over-estimate), this is
+ * indicated by setting *min to TRUE (when min is non-NULL). This happens
+ * when either the destructive flag is set, the information is supplied by
+ * the OS if the OS supports this.
+ */
+
+int
+pciGetBaseSize(PCITAG tag, int index, Bool destructive, Bool *min)
+{
+ int offset;
+ CARD32 addr1;
+ CARD32 addr2;
+ CARD32 mask1;
+ CARD32 mask2;
+ int bits = 0;
+
+ /*
+ * Eventually a function for this should be added to pciBusFuncs_t, but for
+ * now we'll just use a simple method based on the alignment of the already
+ * allocated address.
+ */
+
+ /*
+ * silently ignore bogus index values. Valid values are 0-6. 0-5 are
+ * the 6 base address registers, and 6 is the ROM base address register.
+ */
+ if (index < 0 || index > 6)
+ return 0;
+
+ pciInit();
+
+ if (xf86GetPciSizeFromOS(tag, index, &bits)) {
+ if (min)
+ *min = TRUE;
+ return bits;
+ }
+
+ if (min)
+ *min = destructive;
+
+ /* Get the PCI offset */
+ if (index == 6)
+ offset = PCI_MAP_ROM_REG;
+ else
+ offset = PCI_MAP_REG_START + (index << 2);
+
+ addr1 = pciReadLong(tag, offset);
+ /*
+ * Check if this is the second part of a 64 bit address.
+ * XXX need to check how endianness affects 64 bit addresses.
+ */
+ if (index > 0 && index < 6) {
+ addr2 = pciReadLong(tag, offset - 4);
+ if (PCI_MAP_IS_MEM(addr2) && PCI_MAP_IS64BITMEM(addr2))
+ return 0;
+ }
+
+ if (destructive) {
+ pciWriteLong(tag, offset, 0xffffffff);
+ mask1 = pciReadLong(tag, offset);
+ pciWriteLong(tag, offset, addr1);
+ } else {
+ mask1 = addr1;
+ }
+
+ /* Check if this is the first part of a 64 bit address. */
+ if (index < 5 && PCI_MAP_IS_MEM(mask1) && PCI_MAP_IS64BITMEM(mask1)) {
+ if (PCIGETMEMORY(mask1) == 0) {
+ addr2 = pciReadLong(tag, offset + 4);
+ if (destructive) {
+ pciWriteLong(tag, offset + 4, 0xffffffff);
+ mask2 = pciReadLong(tag, offset + 4);
+ pciWriteLong(tag, offset + 4, addr2);
+ } else {
+ mask2 = addr2;
+ }
+ if (mask2 == 0)
+ return 0;
+ bits = 32;
+ while ((mask2 & 1) == 0) {
+ bits++;
+ mask2 >>= 1;
+ }
+ if (bits > 32)
+ return bits;
+ }
+ }
+ if (index < 6)
+ if (PCI_MAP_IS_MEM(mask1))
+ mask1 = PCIGETMEMORY(mask1);
+ else
+ mask1 = PCIGETIO(mask1);
+ else
+ mask1 = PCIGETROM(mask1);
+ if (mask1 == 0)
+ return 0;
+ bits = 0;
+ while ((mask1 & 1) == 0) {
+ bits++;
+ mask1 >>= 1;
+ }
+ /* I/O maps can be no larger than 8 bits */
+
+ if ((index < 6) && PCI_MAP_IS_IO(addr1) && bits > 8)
+ bits = 8;
+ /* ROM maps can be no larger than 24 bits */
+ if (index == 6 && bits > 24)
+ bits = 24;
+ return bits;
+}
+
+PCITAG
+pciTag(int busnum, int devnum, int funcnum)
+{
+ return(PCI_MAKE_TAG(busnum,devnum,funcnum));
+}
+
+#if defined(PCI_MFDEV_SUPPORT) || defined(PowerMAX_OS)
+
+Bool
+pciMfDev(int busnum, int devnum)
+{
+ PCITAG tag0, tag1;
+ CARD32 id0, id1, val;
+
+ /* Detect a multi-function device that complies to the PCI 2.0 spec */
+
+ tag0 = PCI_MAKE_TAG(busnum, devnum, 0);
+ id0 = pciReadLong(tag0, PCI_ID_REG);
+ if ((CARD16)(id0 + 1) <= (CARD16)1UL)
+ return FALSE;
+
+ val = pciReadLong(tag0, PCI_HEADER_MISC) & 0x00ff0000;
+ if ((val != 0x00ff0000) && (val & PCI_HEADER_MULTIFUNCTION))
+ return TRUE;
+
+ /*
+ * Now, to find non-compliant devices...
+ * If there is a valid ID for function 1 and the ID for func 0 and 1
+ * are different, or the base0 values of func 0 and 1 are differend,
+ * then assume there is a multi-function device.
+ */
+ tag1 = PCI_MAKE_TAG(busnum, devnum, 1);
+ id1 = pciReadLong(tag1, PCI_ID_REG);
+ if ((CARD16)(id1 + 1) <= (CARD16)1UL)
+ return FALSE;
+
+ /* Vendor IDs should match */
+ if ((id0 ^ id1) & 0x0000ffff)
+ return FALSE;
+
+ if ((id0 != id1) ||
+ /* Note the following test is valid for header types 0, 1 and 2 */
+ (pciReadLong(tag0, PCI_MAP_REG_START) !=
+ pciReadLong(tag1, PCI_MAP_REG_START)))
+ return TRUE;
+
+ return FALSE;
+}
+
+#endif
+
+/*
+ * Generic find/read/write functions
+ */
+PCITAG
+pciGenFindNext(void)
+{
+ CARD32 devid, tmp;
+ int sec_bus, pri_bus;
+ static int previousBus = 0;
+ Bool speculativeProbe = FALSE;
+ unsigned char base_class, sub_class;
+
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext\n");
+#endif
+
+ for (;;) {
+
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext: pciBusNum %d\n", pciBusNum);
+#endif
+ if (pciBusNum == -1) {
+ /*
+ * Start at top of the order
+ */
+ if (pciNumBuses <= 0)
+ return(PCI_NOT_FOUND);
+
+ /* Skip ahead to the first bus defined by pciInit() */
+ for (pciBusNum = 0; !pciBusInfo[pciBusNum]; ++pciBusNum);
+ pciFuncNum = 0;
+ pciDevNum = 0;
+ previousBus = pciBusNum; /* make sure previousBus exists */
+ } else {
+#ifdef PCI_MFDEV_SUPPORT
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext: pciFuncNum %d\n", pciFuncNum);
+#endif
+ /*
+ * Somewhere in middle of order. Determine who's
+ * next up
+ */
+ if (pciFuncNum == 0) {
+ /*
+ * Is current dev a multifunction device?
+ */
+ if (!speculativeProbe && pciMfDev(pciBusNum, pciDevNum))
+ /* Probe for other functions */
+ pciFuncNum = 1;
+ else
+ /*
+ * No more functions this device. Next
+ * device please
+ */
+ pciDevNum ++;
+ } else if (++pciFuncNum >= 8) {
+ /* No more functions for this device. Next device please */
+ pciFuncNum = 0;
+ pciDevNum ++;
+ }
+#else
+ pciDevNum ++;
+#endif
+ if (pciDevNum >= 32 ||
+ !pciBusInfo[pciBusNum] ||
+ pciDevNum >= pciBusInfo[pciBusNum]->numDevices) {
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext: next bus\n");
+#endif
+ /*
+ * No more devices for this bus. Next bus please
+ */
+ if (speculativeProbe) {
+ NextSpeculativeBus:
+ xfree(pciBusInfo[pciBusNum]);
+ pciBusInfo[pciBusNum] = NULL;
+ speculativeProbe = FALSE;
+ }
+
+ if (++pciBusNum >= pciMaxBusNum) {
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext: out of buses\n");
+#endif
+ /* No more buses. All done for now */
+ return(PCI_NOT_FOUND);
+ }
+
+ pciDevNum = 0;
+ }
+ }
+
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext: pciBusInfo[%d] = 0x%lx\n", pciBusNum, pciBusInfo[pciBusNum]);
+#endif
+ if (!pciBusInfo[pciBusNum]) {
+ pciBusInfo[pciBusNum] = xnfalloc(sizeof(pciBusInfo_t));
+ *pciBusInfo[pciBusNum] = *pciBusInfo[previousBus];
+
+ speculativeProbe = TRUE;
+ }
+
+ /*
+ * At this point, pciBusNum, pciDevNum, and pciFuncNum have been
+ * advanced to the next device. Compute the tag, and read the
+ * device/vendor ID field.
+ */
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext: [%d, %d, %d]\n", pciBusNum, pciDevNum, pciFuncNum);
+#endif
+ pciDeviceTag = PCI_MAKE_TAG(pciBusNum, pciDevNum, pciFuncNum);
+ inProbe = TRUE;
+ devid = pciReadLong(pciDeviceTag, PCI_ID_REG);
+ inProbe = FALSE;
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext: pciDeviceTag = 0x%lx, devid = 0x%lx\n", pciDeviceTag, devid);
+#endif
+ if ((CARD16)(devid + 1U) <= (CARD16)1UL)
+ continue; /* Nobody home. Next device please */
+
+ /*
+ * Some devices mis-decode configuration cycles in such a way as to
+ * create phantom buses.
+ */
+ if (speculativeProbe && (pciDevNum == 0) && (pciFuncNum == 0) &&
+ (PCI_BUS_NO_DOMAIN(pciBusNum) > 0)) {
+ for (;;) {
+ if (++pciDevNum >= pciBusInfo[pciBusNum]->numDevices)
+ goto NextSpeculativeBus;
+ if (devid !=
+ pciReadLong(PCI_MAKE_TAG(pciBusNum, pciDevNum, 0),
+ PCI_ID_REG))
+ break;
+ }
+
+ pciDevNum = 0;
+ }
+
+ if (pciNumBuses <= pciBusNum)
+ pciNumBuses = pciBusNum + 1;
+
+ speculativeProbe = FALSE;
+ previousBus = pciBusNum;
+
+#ifdef PCI_BRIDGE_SUPPORT
+ /*
+ * Before checking for a specific devid, look for enabled
+ * PCI to PCI bridge devices. If one is found, create and
+ * initialize a bus info record (if one does not already exist).
+ */
+ tmp = pciReadLong(pciDeviceTag, PCI_CLASS_REG);
+ base_class = PCI_CLASS_EXTRACT(tmp);
+ sub_class = PCI_SUBCLASS_EXTRACT(tmp);
+ if ((base_class == PCI_CLASS_BRIDGE) &&
+ ((sub_class == PCI_SUBCLASS_BRIDGE_PCI) ||
+ (sub_class == PCI_SUBCLASS_BRIDGE_CARDBUS))) {
+ tmp = pciReadLong(pciDeviceTag, PCI_PCI_BRIDGE_BUS_REG);
+ sec_bus = PCI_SECONDARY_BUS_EXTRACT(tmp, pciDeviceTag);
+ pri_bus = PCI_PRIMARY_BUS_EXTRACT(tmp, pciDeviceTag);
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext: pri_bus %d sec_bus %d\n",
+ pri_bus, sec_bus);
+#endif
+ if (pciBusNum != pri_bus) {
+ /* Some bridges do not implement the primary bus register */
+ if ((PCI_BUS_NO_DOMAIN(pri_bus) != 0) ||
+ (sub_class != PCI_SUBCLASS_BRIDGE_CARDBUS))
+ xf86Msg(X_WARNING,
+ "pciGenFindNext: primary bus mismatch on PCI"
+ " bridge 0x%08lx (0x%02x, 0x%02x)\n",
+ pciDeviceTag, pciBusNum, pri_bus);
+ pri_bus = pciBusNum;
+ }
+ if ((pri_bus < sec_bus) && (sec_bus < pciMaxBusNum) &&
+ pciBusInfo[pri_bus]) {
+ /*
+ * Found a secondary PCI bus
+ */
+ if (!pciBusInfo[sec_bus]) {
+ pciBusInfo[sec_bus] = xnfalloc(sizeof(pciBusInfo_t));
+
+ /* Copy parents settings... */
+ *pciBusInfo[sec_bus] = *pciBusInfo[pri_bus];
+ }
+
+ /* ...but not everything same as parent */
+ pciBusInfo[sec_bus]->primary_bus = pri_bus;
+ pciBusInfo[sec_bus]->secondary = TRUE;
+ pciBusInfo[sec_bus]->numDevices = 32;
+
+ if (pciNumBuses <= sec_bus)
+ pciNumBuses = sec_bus + 1;
+ }
+ }
+#endif
+
+ /*
+ * Does this device match the requested devid after
+ * applying mask?
+ */
+#ifdef DEBUGPCI
+ ErrorF("pciGenFindNext: pciDevidMask = 0x%lx, pciDevid = 0x%lx\n", pciDevidMask, pciDevid);
+#endif
+ if ((devid & pciDevidMask) == pciDevid)
+ /* Yes - Return it. Otherwise, next device */
+ return(pciDeviceTag); /* got a match */
+
+ } /* for */
+ /*NOTREACHED*/
+}
+
+PCITAG
+pciGenFindFirst(void)
+{
+ /* Reset PCI bus number to start from top */
+ pciBusNum = -1;
+
+ return pciGenFindNext();
+}
+
+CARD32
+pciByteSwap(CARD32 u)
+{
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+# if defined(__powerpc__) && defined(PowerMAX_OS)
+ CARD32 tmp;
+
+ __inst_stwbrx(u, &tmp, 0);
+
+ return(tmp);
+
+# else /* !PowerMAX_OS */
+
+ return lswapl(u);
+
+# endif /* !PowerMAX_OS */
+
+#else /* !BIG_ENDIAN */
+
+ return(u);
+
+#endif
+}
+
+ADDRESS
+pciAddrNOOP(PCITAG tag, PciAddrType type, ADDRESS addr)
+{
+ return(addr);
+}
+
+pciConfigPtr *
+xf86scanpci(int flags)
+{
+ pciConfigPtr devp;
+ pciBusInfo_t *busp;
+ int idx = 0, i;
+ PCITAG tag;
+ static Bool done = FALSE;
+
+ /*
+ * if we haven't found PCI devices checking for pci_devp may
+ * result in an endless recursion if platform/OS specific PCI
+ * bus probing code calls this function from with in it.
+ */
+ if (done || pci_devp[0])
+ return pci_devp;
+
+ done = TRUE;
+
+ pciInit();
+
+#ifdef XF86SCANPCI_WRAPPER
+ XF86SCANPCI_WRAPPER(SCANPCI_INIT);
+#endif
+
+ tag = pciFindFirst(0,0); /* 0 mask means match any valid device */
+ /* Check if no devices, return now */
+ if (tag == PCI_NOT_FOUND) {
+#ifdef XF86SCANPCI_WRAPPER
+ XF86SCANPCI_WRAPPER(SCANPCI_TERM);
+#endif
+ return NULL;
+ }
+
+#ifdef DEBUGPCI
+ ErrorF("xf86scanpci: tag = 0x%lx\n", tag);
+#endif
+#ifndef OLD_FORMAT
+ xf86MsgVerb(X_INFO, 2, "PCI: PCI scan (all values are in hex)\n");
+#endif
+
+ while (idx < MAX_PCI_DEVICES && tag != PCI_NOT_FOUND) {
+ devp = xcalloc(1, sizeof(pciDevice));
+ if (!devp) {
+ xf86Msg(X_ERROR,
+ "xf86scanpci: Out of memory after %d devices!!\n", idx);
+ return (pciConfigPtr *)NULL;
+ }
+
+ /* Identify pci device by bus, dev, func, and tag */
+ devp->tag = tag;
+ devp->busnum = PCI_BUS_FROM_TAG(tag);
+ devp->devnum = PCI_DEV_FROM_TAG(tag);
+ devp->funcnum = PCI_FUNC_FROM_TAG(tag);
+
+ /* Read config space for this device */
+ for (i = 0; i < 17; i++) /* PCI hdr plus 1st dev spec dword */
+ devp->cfgspc.dwords[i] = pciReadLong(tag, i * sizeof(CARD32));
+
+ /* Some broken devices don't implement this field... */
+ if (devp->pci_header_type == 0xff)
+ devp->pci_header_type = 0;
+
+ switch (devp->pci_header_type & 0x7f) {
+ case 0:
+ /* Get base address sizes for type 0 headers */
+ for (i = 0; i < 7; i++)
+ devp->basesize[i] =
+ pciGetBaseSize(tag, i, FALSE, &devp->minBasesize);
+ break;
+
+ case 1:
+ case 2:
+ /* Allow master aborts to complete normally on secondary buses */
+ if (!(devp->pci_bridge_control & PCI_PCI_BRIDGE_MASTER_ABORT_EN))
+ break;
+ pciWriteByte(tag, PCI_PCI_BRIDGE_CONTROL_REG,
+ devp->pci_bridge_control &
+ ~(PCI_PCI_BRIDGE_MASTER_ABORT_EN |
+ PCI_PCI_BRIDGE_SECONDARY_RESET));
+ break;
+
+ default:
+ break;
+ }
+
+#ifdef OLD_FORMAT
+ xf86MsgVerb(X_INFO, 2, "PCI: BusID 0x%.2x,0x%02x,0x%1x "
+ "ID 0x%04x,0x%04x Rev 0x%02x Class 0x%02x,0x%02x\n",
+ devp->busnum, devp->devnum, devp->funcnum,
+ devp->pci_vendor, devp->pci_device, devp->pci_rev_id,
+ devp->pci_base_class, devp->pci_sub_class);
+#else
+ xf86MsgVerb(X_INFO, 2, "PCI: %.2x:%02x:%1x: chip %04x,%04x"
+ " card %04x,%04x rev %02x class %02x,%02x,%02x hdr %02x\n",
+ devp->busnum, devp->devnum, devp->funcnum,
+ devp->pci_vendor, devp->pci_device,
+ devp->pci_subsys_vendor, devp->pci_subsys_card,
+ devp->pci_rev_id, devp->pci_base_class,
+ devp->pci_sub_class, devp->pci_prog_if,
+ devp->pci_header_type);
+#endif
+
+ pci_devp[idx++] = devp;
+ tag = pciFindNext();
+
+#ifdef DEBUGPCI
+ ErrorF("xf86scanpci: tag = pciFindNext = 0x%lx\n", tag);
+#endif
+ }
+
+ /* Restore modified data (in reverse order), and link buses */
+ while (--idx >= 0) {
+ devp = pci_devp[idx];
+ switch (devp->pci_header_type & 0x7f) {
+ case 0:
+ if ((devp->pci_base_class != PCI_CLASS_BRIDGE) ||
+ (devp->pci_sub_class != PCI_SUBCLASS_BRIDGE_HOST))
+ break;
+ pciBusInfo[devp->busnum]->bridge = devp;
+ pciBusInfo[devp->busnum]->primary_bus = devp->busnum;
+ break;
+
+ case 1:
+ case 2:
+ i = PCI_SECONDARY_BUS_EXTRACT(devp->pci_pp_bus_register, devp->tag);
+ if (i > devp->busnum) {
+ if (pciBusInfo[i]) {
+ pciBusInfo[i]->bridge = devp;
+ /*
+ * The back link needs to be set here, and is unlikely to
+ * change.
+ */
+ devp->businfo = pciBusInfo[i];
+ }
+#ifdef ARCH_PCI_PCI_BRIDGE
+ ARCH_PCI_PCI_BRIDGE(devp);
+#endif
+ }
+ if (!(devp->pci_bridge_control & PCI_PCI_BRIDGE_MASTER_ABORT_EN))
+ break;
+ pciWriteByte(devp->tag, PCI_PCI_BRIDGE_CONTROL_REG,
+ devp->pci_bridge_control & ~PCI_PCI_BRIDGE_SECONDARY_RESET);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+#ifdef XF86SCANPCI_WRAPPER
+ XF86SCANPCI_WRAPPER(SCANPCI_TERM);
+#endif
+
+ /*
+ * Lastly, link bridges to their secondary bus, after the architecture has
+ * had a chance to modify these assignments.
+ */
+ for (idx = 0; idx < pciNumBuses; idx++) {
+ if (!(busp = pciBusInfo[idx]) || !(devp = busp->bridge))
+ continue;
+ devp->businfo = busp;
+ }
+
+#ifndef OLD_FORMAT
+ xf86MsgVerb(X_INFO, 2, "PCI: End of PCI scan\n");
+#endif
+
+ return pci_devp;
+}
+
+CARD32
+pciCheckForBrokenBase(PCITAG Tag,int basereg)
+{
+ pciWriteLong(Tag, PCI_MAP_REG_START + (basereg << 2), 0xffffffff);
+ return pciReadLong(Tag, PCI_MAP_REG_START + (basereg << 2));
+}
+
+#if defined(INCLUDE_XF86_MAP_PCI_MEM)
+
+pointer
+xf86MapPciMem(int ScreenNum, int Flags, PCITAG Tag, ADDRESS Base,
+ unsigned long Size)
+{
+ ADDRESS hostbase = pciBusAddrToHostAddr(Tag, PCI_MEM,Base);
+ pointer base;
+ CARD32 save = 0;
+
+ /*
+ * If there are possible read side-effects, disable memory while
+ * doing the mapping.
+ */
+ if (Flags & VIDMEM_READSIDEEFFECT) {
+ save = pciReadLong(Tag, PCI_CMD_STAT_REG);
+ pciWriteLong(Tag, PCI_CMD_STAT_REG,
+ save & ~PCI_CMD_MEM_ENABLE);
+ }
+ base = xf86MapDomainMemory(ScreenNum, Flags, Tag, hostbase, Size);
+ if (!base) {
+ FatalError("xf86MapPciMem: Could not mmap PCI memory "
+ "[base=0x%lx,hostbase=0x%lx,size=%lx] (%s)\n",
+ Base, hostbase, Size, strerror(errno));
+ }
+ /*
+ * If read side-effects, do whatever might be needed to prevent
+ * unintended reads, then restore PCI_CMD_STAT_REG.
+ */
+ if (Flags & VIDMEM_READSIDEEFFECT) {
+ xf86MapReadSideEffects(ScreenNum, Flags, base, Size);
+ pciWriteLong(Tag, PCI_CMD_STAT_REG, save);
+ }
+ return((pointer)base);
+}
+
+static int
+handlePciBIOS(PCITAG Tag, int basereg,
+ int (*func)(PCITAG, CARD8*, ADDRESS, pointer),
+ pointer args)
+{
+ CARD32 romsave = 0;
+ int i;
+ romBaseSource b_reg;
+ ADDRESS hostbase;
+ CARD8 tmp[64];
+ int ret = 0;
+
+ romsave = pciReadLong(Tag, PCI_MAP_ROM_REG);
+
+ for (i = ROM_BASE_PRESET; i <= ROM_BASE_FIND; i++) {
+ memType savebase = 0, newbase, romaddr;
+
+ switch (i) {
+ case ROM_BASE_PRESET:
+ /* Does the driver have a preference? */
+ if (basereg > ROM_BASE_PRESET && basereg <= ROM_BASE_FIND)
+ b_reg = basereg;
+ else
+ b_reg = ++i;
+ break;
+ case ROM_BASE_FIND:
+ /*
+ * If we have something that looks like a valid address
+ * in romsave, it's probably not going to help to try
+ * to guess a new address and reprogram it.
+ */
+ if (PCIGETROM(romsave)) {
+ pciWriteLong(Tag, PCI_MAP_ROM_REG, PCI_MAP_ROM_ADDRESS_MASK);
+ if (romsave != pciReadLong(Tag, PCI_MAP_ROM_REG)) {
+ pciWriteLong(Tag, PCI_MAP_ROM_REG, romsave);
+ continue;
+ }
+ }
+ default:
+ b_reg = i;
+ }
+
+ if (!(newbase = getValidBIOSBase(Tag, b_reg)))
+ continue; /* no valid address found */
+
+ romaddr = PCIGETROM(newbase);
+
+ /* if we use a mem base save it and move it out of the way */
+ if (b_reg >= 0 && b_reg <= 5) {
+ savebase = pciReadLong(Tag, PCI_MAP_REG_START+(b_reg<<2));
+ xf86MsgVerb(X_INFO,5,"xf86ReadPciBios: modifying membase[%i]"
+ " for device %i:%i:%i\n", basereg,
+ (int)PCI_BUS_FROM_TAG(Tag), (int)PCI_DEV_FROM_TAG(Tag),
+ (int)PCI_FUNC_FROM_TAG(Tag));
+ pciWriteLong(Tag, PCI_MAP_REG_START + (b_reg << 2),
+ (CARD32)~0);
+ }
+ /* Set ROM base address and enable ROM address decoding */
+ pciWriteLong(Tag, PCI_MAP_ROM_REG, romaddr
+ | PCI_MAP_ROM_DECODE_ENABLE);
+
+ hostbase = pciBusAddrToHostAddr(Tag, PCI_MEM, PCIGETROM(romaddr));
+
+ if ((xf86ReadDomainMemory(Tag, hostbase, sizeof(tmp), tmp) !=
+ sizeof(tmp)) ||
+ (tmp[0] != 0x55) || (tmp[1] != 0xaa) || !tmp[2] ) {
+ /* Restore the base registers if they were changed. */
+ pciWriteLong(Tag, PCI_MAP_ROM_REG, romsave);
+ if (savebase) pciWriteLong(Tag, PCI_MAP_REG_START + (b_reg << 2),
+ (CARD32) savebase);
+
+ /* No BIOS found: try another address */
+ continue;
+ }
+
+ ret = (*func)(Tag, tmp, hostbase, args);
+
+ /* Restore the base register if it was changed. */
+ if (savebase) pciWriteLong(Tag, PCI_MAP_REG_START + (b_reg << 2),
+ (CARD32) savebase);
+ /* Restore ROM address decoding */
+ pciWriteLong(Tag, PCI_MAP_ROM_REG, romsave);
+
+ return ret;
+ }
+ /* Restore ROM address decoding */
+ pciWriteLong(Tag, PCI_MAP_ROM_REG, romsave);
+ return 0;
+}
+
+typedef struct {
+ unsigned long Offset;
+ int Len;
+ unsigned char *Buf;
+ PciBiosType BiosType;
+} readBios, *readBiosPtr;
+
+static int
+readPciBios(PCITAG Tag, CARD8* tmp, ADDRESS hostbase, pointer args)
+{
+ unsigned int image_length = 0;
+ readBiosPtr rd = args;
+ int ret;
+
+ /* We found a PCI BIOS Image. Now we look for the correct type */
+ while ((tmp[0] == 0x55) && (tmp[1] == 0xAA)) {
+ unsigned short data_off = tmp[0x18] | (tmp[0x19] << 8);
+ unsigned char data[0x18];
+ unsigned char type;
+
+ if ((xf86ReadDomainMemory(Tag, hostbase + data_off, sizeof(data), data)
+ != sizeof(data)) ||
+ (data[0] != 'P') ||
+ (data[1] != 'C') ||
+ (data[2] != 'I') ||
+ (data[3] != 'R'))
+ break;
+ type = data[0x14];
+#ifdef PRINT_PCI
+ ErrorF("data segment in BIOS: 0x%x, type: 0x%x\n", data_off, type);
+#endif
+ if (type != rd->BiosType) { /* not correct image: find next one */
+ unsigned char indicator = data[0x15];
+ unsigned int i_length;
+ if (indicator & 0x80) /* last image */
+ break;
+ i_length = (data[0x10] | (data[0x11] << 8)) << 9;
+#ifdef PRINT_PCI
+ ErrorF("data image length: 0x%x, ind: 0x%x\n",
+ image_length, indicator);
+#endif
+ hostbase += i_length;
+ if (xf86ReadDomainMemory(Tag, hostbase, sizeof(tmp), tmp)
+ != sizeof(tmp))
+ break;
+ continue;
+ }
+ /* OK, we have a PCI BIOS Image of the correct type */
+
+ if (rd->BiosType == PCI_BIOS_PC)
+ image_length = tmp[2] << 9;
+ else
+ image_length = (data[0x10] | (data[0x11] << 8)) << 9;
+#ifdef PRINT_PCI
+ ErrorF("BIOS length: 0x%x\n", image_length);
+#endif
+ break;
+ }
+
+ ret = 0;
+ if (image_length) {
+
+ /*
+ * if no length is given return the full lenght,
+ * Offset 0. Beware: Area pointed to by Buf must
+ * be large enough!
+ */
+ if (rd->Len == 0) {
+ rd->Len = image_length;
+ rd->Offset = 0;
+ }
+ if ((rd->Offset) > (image_length)) {
+ xf86Msg(X_WARNING,"xf86ReadPciBios: requesting data past "
+ "end of BIOS %li > %i\n",(rd->Offset) , (image_length));
+ } else {
+ if ((rd->Offset + rd->Len) > (image_length)) {
+ rd->Len = (image_length) - rd->Offset;
+ xf86MsgVerb(X_INFO,3,"Truncating PCI BIOS Length to %i\n",rd->Len);
+ }
+ }
+
+ /* Read BIOS */
+ ret = xf86ReadDomainMemory(Tag, hostbase + rd->Offset, rd->Len, rd->Buf);
+ }
+
+ return ret;
+}
+
+static int
+getPciBIOSTypes(PCITAG Tag, CARD8* tmp, ADDRESS hostbase, pointer arg)
+{
+ int n = 0;
+ PciBiosType *Buf = arg;
+
+ /* We found a PCI BIOS Image. Now we collect the types type */
+ do {
+ unsigned short data_off = tmp[0x18] | (tmp[0x19] << 8);
+ unsigned char data[0x16];
+ unsigned int i_length;
+
+ if ((xf86ReadDomainMemory(Tag, hostbase + data_off, sizeof(data), data)
+ != sizeof(data)) ||
+ (data[0] != 'P') ||
+ (data[1] != 'C') ||
+ (data[2] != 'I') ||
+ (data[3] != 'R'))
+ break;
+
+ if (data[0x14] >= PCI_BIOS_OTHER)
+ *Buf++ = PCI_BIOS_OTHER;
+ else
+ *Buf++ = data[0x14];
+
+ n++;
+ if (data[0x15] & 0x80) /* last image */
+ break;
+#ifdef PRINT_PCI
+ ErrorF("data segment in BIOS: 0x%x, type: 0x%x\n", data_off, type);
+#endif
+ i_length = (data[0x10] | (data[0x11] << 8)) << 9;
+#ifdef PRINT_PCI
+ ErrorF("data image length: 0x%x, ind: 0x%x\n",
+ image_length, indicator);
+#endif
+ hostbase += i_length;
+ if (xf86ReadDomainMemory(Tag, hostbase, sizeof(tmp), tmp)
+ != sizeof(tmp))
+ break;
+ continue;
+ } while ((tmp[0] == 0x55) && (tmp[1] == 0xAA));
+ return n;
+}
+
+typedef CARD32 (*ReadProcPtr)(PCITAG, int);
+typedef void (*WriteProcPtr)(PCITAG, int, CARD32);
+
+static int
+HandlePciBios(PCITAG Tag, int basereg,
+ int (*func)(PCITAG, CARD8*, ADDRESS, pointer),
+ pointer ptr)
+{
+ int n, num;
+ CARD32 Acc1, Acc2;
+ PCITAG *pTag;
+ int i;
+
+ n = handlePciBIOS(Tag,basereg,func,ptr);
+ if (n)
+ return n;
+
+ num = pciTestMultiDeviceCard(PCI_BUS_FROM_TAG(Tag),
+ PCI_DEV_FROM_TAG(Tag),
+ PCI_FUNC_FROM_TAG(Tag),&pTag);
+
+ if (!num) return 0;
+
+#define PCI_ENA (PCI_CMD_MEM_ENABLE | PCI_CMD_IO_ENABLE)
+ Acc1 = pciReadLong(Tag, PCI_CMD_STAT_REG);
+ pciWriteLong(Tag, PCI_CMD_STAT_REG, (Acc1 & ~PCI_ENA));
+
+ for (i = 0; i < num; i++) {
+ Acc2 = pciReadLong(pTag[i], PCI_CMD_STAT_REG);
+ pciWriteLong(pTag[i], PCI_CMD_STAT_REG, (Acc2 | PCI_ENA));
+
+ n = handlePciBIOS(pTag[i],0,func,ptr);
+
+ pciWriteLong(pTag[i], PCI_CMD_STAT_REG, Acc2);
+ if (n)
+ break;
+ }
+ pciWriteLong(Tag, PCI_CMD_STAT_REG, Acc1);
+ return n;
+}
+
+int
+xf86ReadPciBIOS(unsigned long Offset, PCITAG Tag, int basereg,
+ unsigned char *Buf, int Len)
+{
+ return xf86ReadPciBIOSByType(Offset, Tag, basereg, Buf, Len, PCI_BIOS_PC);
+}
+
+int
+xf86ReadPciBIOSByType(unsigned long Offset, PCITAG Tag, int basereg,
+ unsigned char *Buf, int Len, PciBiosType Type)
+{
+
+ readBios rb;
+ rb.Offset = Offset;
+ rb.Len = Len;
+ rb.Buf = Buf;
+ rb.BiosType = Type;
+
+ return HandlePciBios(Tag, basereg, readPciBios, &rb);
+}
+
+int
+xf86GetAvailablePciBIOSTypes(PCITAG Tag, int basereg, PciBiosType *Buf)
+{
+ return HandlePciBios(Tag, basereg, getPciBIOSTypes, (pointer) Buf);
+}
+
+#endif /* INCLUDE_XF86_MAP_PCI_MEM */
+
+#ifdef INCLUDE_XF86_NO_DOMAIN
+
+int
+xf86GetPciDomain(PCITAG Tag)
+{
+ return 0;
+}
+
+pointer
+xf86MapDomainMemory(int ScreenNum, int Flags, PCITAG Tag,
+ ADDRESS Base, unsigned long Size)
+{
+ return xf86MapVidMem(ScreenNum, Flags, Base, Size);
+}
+
+IOADDRESS
+xf86MapDomainIO(int ScreenNum, int Flags, PCITAG Tag,
+ IOADDRESS Base, unsigned long Size)
+{
+ return Base;
+}
+
+int
+xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
+{
+ int ret, length, rlength;
+
+ /* Read in 64kB chunks */
+ ret = 0;
+ while ((length = Len) > 0) {
+ if (length > 0x010000) length = 0x010000;
+ rlength = xf86ReadBIOS(Base, 0, Buf, length);
+ if (rlength < 0) {
+ ret = rlength;
+ break;
+ }
+ ret += rlength;
+ if (rlength < length) break;
+ Base += rlength;
+ Buf += rlength;
+ Len -= rlength;
+ }
+
+ return ret;
+}
+
+#endif /* INCLUDE_XF86_NO_DOMAIN */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Pci.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Pci.h
new file mode 100644
index 000000000..70293d3f4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Pci.h
@@ -0,0 +1,449 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/Pci.h,v 1.45 2004/02/02 03:55:31 dawes Exp $ */
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * This file is derived in part from the original xf86_PCI.h that included
+ * following copyright message:
+ *
+ * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of the above listed copyright holder(s)
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. The above listed
+ * copyright holder(s) make(s) no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
+ * Copyright (c) 1999-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 has the private Pci definitions. The public ones are imported
+ * from xf86Pci.h. Drivers should not use this file.
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _PCI_H
+#define _PCI_H 1
+
+#include <X11/Xarch.h>
+#include <X11/Xfuncproto.h>
+#include "xf86Pci.h"
+#include "xf86PciInfo.h"
+
+/*
+ * Global Definitions
+ */
+#define MAX_PCI_DEVICES 128 /* Max number of devices accomodated */
+ /* by xf86scanpci */
+#if defined(sun) && defined(SVR4) && defined(sparc)
+# define MAX_PCI_BUSES 4096 /* Max number of PCI buses */
+#elif defined(__alpha__) && defined (linux)
+# define MAX_PCI_DOMAINS 512
+# define PCI_DOM_MASK 0x01fful
+# define MAX_PCI_BUSES (MAX_PCI_DOMAINS*256) /* 256 per domain */
+#else
+# define MAX_PCI_BUSES 256 /* Max number of PCI buses */
+#endif
+
+#define DEVID(vendor, device) \
+ ((CARD32)((PCI_##device << 16) | PCI_##vendor))
+
+#ifndef PCI_DOM_MASK
+# define PCI_DOM_MASK 0x0ffu
+#endif
+#define PCI_DOMBUS_MASK (((PCI_DOM_MASK) << 8) | 0x0ffu)
+
+/*
+ * "b" contains an optional domain number.
+ */
+#define PCI_MAKE_TAG(b,d,f) ((((b) & (PCI_DOMBUS_MASK)) << 16) | \
+ (((d) & 0x00001fu) << 11) | \
+ (((f) & 0x000007u) << 8))
+
+#define PCI_MAKE_BUS(d,b) ((((d) & (PCI_DOM_MASK)) << 8) | ((b) & 0xffu))
+
+#define PCI_DOM_FROM_TAG(tag) (((tag) >> 24) & (PCI_DOM_MASK))
+#define PCI_BUS_FROM_TAG(tag) (((tag) >> 16) & (PCI_DOMBUS_MASK))
+#define PCI_DEV_FROM_TAG(tag) (((tag) & 0x0000f800u) >> 11)
+#define PCI_FUNC_FROM_TAG(tag) (((tag) & 0x00000700u) >> 8)
+
+#define PCI_DFN_FROM_TAG(tag) (((tag) & 0x0000ff00u) >> 8)
+#define PCI_BDEV_FROM_TAG(tag) ((tag) & 0x00fff800u)
+
+#define PCI_DOM_FROM_BUS(bus) (((bus) >> 8) & (PCI_DOM_MASK))
+#define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu)
+#define PCI_TAG_NO_DOMAIN(tag) ((tag) & 0x00ffff00u)
+
+/*
+ * Macros for bus numbers found in P2P headers.
+ */
+#define PCI_PRIMARY_BUS_EXTRACT(x, tag) \
+ ((((x) & PCI_PRIMARY_BUS_MASK ) >> 0) | (PCI_DOM_FROM_TAG(tag) << 8))
+#define PCI_SECONDARY_BUS_EXTRACT(x, tag) \
+ ((((x) & PCI_SECONDARY_BUS_MASK ) >> 8) | (PCI_DOM_FROM_TAG(tag) << 8))
+#define PCI_SUBORDINATE_BUS_EXTRACT(x, tag) \
+ ((((x) & PCI_SUBORDINATE_BUS_MASK) >> 16) | (PCI_DOM_FROM_TAG(tag) << 8))
+
+#define PCI_PRIMARY_BUS_INSERT(x, y) \
+ (((x) & ~PCI_PRIMARY_BUS_MASK ) | (((y) & 0xffu) << 0))
+#define PCI_SECONDARY_BUS_INSERT(x, y) \
+ (((x) & ~PCI_SECONDARY_BUS_MASK ) | (((y) & 0xffu) << 8))
+#define PCI_SUBORDINATE_BUS_INSERT(x, y) \
+ (((x) & ~PCI_SUBORDINATE_BUS_MASK) | (((y) & 0xffu) << 16))
+
+/* Ditto for CardBus bridges */
+#define PCI_CB_PRIMARY_BUS_EXTRACT(x, tag) \
+ PCI_PRIMARY_BUS_EXTRACT(x, tag)
+#define PCI_CB_CARDBUS_BUS_EXTRACT(x, tag) \
+ PCI_SECONDARY_BUS_EXTRACT(x, tag)
+#define PCI_CB_SUBORDINATE_BUS_EXTRACT(x, tag) \
+ PCI_SUBORDINATE_BUS_EXTRACT(x, tag)
+
+#define PCI_CB_PRIMARY_BUS_INSERT(x, tag) \
+ PCI_PRIMARY_BUS_INSERT(x, tag)
+#define PCI_CB_CARDBUS_BUS_INSERT(x, tag) \
+ PCI_SECONDARY_BUS_INSERT(x, tag)
+#define PCI_CB_SUBORDINATE_BUS_INSERT(x, tag) \
+ PCI_SUBORDINATE_BUS_INSERT(x, tag)
+
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+#define PCI_CPU(val) (((val >> 24) & 0x000000ff) | \
+ ((val >> 8) & 0x0000ff00) | \
+ ((val << 8) & 0x00ff0000) | \
+ ((val << 24) & 0xff000000))
+#define PCI_CPU16(val) (((val >> 8) & 0x000000ff) | \
+ ((val << 8) & 0x0000ff00))
+#else
+#define PCI_CPU(val) (val)
+#define PCI_CPU16(val) (val)
+#endif
+
+/*
+ * Debug Macros/Definitions
+ */
+/* #define DEBUGPCI 2 */ /* Disable/enable trace in PCI code */
+
+#if defined(DEBUGPCI)
+
+# define PCITRACE(lvl,printfargs) \
+ if (lvl > xf86Verbose) { \
+ ErrorF printfargs; \
+ }
+
+#else /* !defined(DEBUGPCI) */
+
+# define PCITRACE(lvl,printfargs)
+
+#endif /* !defined(DEBUGPCI) */
+
+/*
+ * PCI Config mechanism definitions
+ */
+#define PCI_EN 0x80000000
+
+#define PCI_CFGMECH1_ADDRESS_REG 0xCF8
+#define PCI_CFGMECH1_DATA_REG 0xCFC
+
+#define PCI_CFGMECH1_MAXDEV 32
+
+/*
+ * Select architecture specific PCI init function
+ */
+#if defined(__alpha__)
+# if defined(linux)
+# define ARCH_PCI_INIT axpPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# elif defined(__FreeBSD__) || defined(__OpenBSD__)
+# define ARCH_PCI_INIT freebsdPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# elif defined(__NetBSD__)
+# define ARCH_PCI_INIT netbsdPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+#elif defined(__arm__)
+# if defined(linux)
+# define ARCH_PCI_INIT linuxPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+#elif defined(__hppa__)
+# if defined(linux)
+# define ARCH_PCI_INIT linuxPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+#elif defined(__ia64__)
+# if defined(linux)
+# define ARCH_PCI_INIT linuxPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# elif defined(FreeBSD)
+# define ARCH_PCI_INIT freebsdPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+# define XF86SCANPCI_WRAPPER ia64ScanPCIWrapper
+#elif defined(__i386__) || defined(i386)
+# define ARCH_PCI_INIT ix86PciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# if defined(linux)
+# define ARCH_PCI_OS_INIT linuxPciInit
+# endif
+#elif defined(__mc68000__)
+# if defined(linux)
+# define ARCH_PCI_INIT linuxPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+#elif defined(__mips__)
+# if defined(linux)
+# define ARCH_PCI_INIT linuxPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+#elif defined(__powerpc__) || defined(__powerpc64__)
+# if defined(linux)
+# define ARCH_PCI_INIT linuxPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN /* Needs kernel work to remove */
+# elif defined(__FreeBSD__) || defined(__OpenBSD__)
+# define ARCH_PCI_INIT freebsdPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# elif defined(__NetBSD__)
+# define ARCH_PCI_INIT netbsdPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# elif defined(PowerMAX_OS) /* This port is broken */
+# define ARCH_PCI_INIT ppcPciInit
+# else
+# define ARCH_PCI_INIT ppcPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+#elif defined(__s390__)
+# if defined(linux)
+# define ARCH_PCI_INIT linuxPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+#elif defined(__sh__)
+# if defined(linux)
+# define ARCH_PCI_INIT linuxPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+#elif defined(__sparc__) || defined(sparc)
+# if defined(linux)
+# define ARCH_PCI_INIT linuxPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# elif defined(sun)
+# define ARCH_PCI_INIT sparcPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# elif (defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(__sparc64__)
+# define ARCH_PCI_INIT freebsdPciInit
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# endif
+# if !defined(__FreeBSD__)
+# define ARCH_PCI_PCI_BRIDGE sparcPciPciBridge
+# endif
+#elif defined(__amd64__) || defined(__amd64)
+# if defined(__FreeBSD__)
+# define ARCH_PCI_INIT freebsdPciInit
+# else
+# define ARCH_PCI_INIT ix86PciInit
+# endif
+# define INCLUDE_XF86_MAP_PCI_MEM
+# define INCLUDE_XF86_NO_DOMAIN
+# if defined(linux)
+# define ARCH_PCI_OS_INIT linuxPciInit
+# endif
+#endif
+
+#ifndef ARCH_PCI_INIT
+#error No PCI support available for this architecture/OS combination
+#endif
+
+extern void ARCH_PCI_INIT(void);
+#if defined(ARCH_PCI_OS_INIT)
+extern void ARCH_PCI_OS_INIT(void);
+#endif
+
+#if defined(ARCH_PCI_PCI_BRIDGE)
+extern void ARCH_PCI_PCI_BRIDGE(pciConfigPtr pPCI);
+#endif
+
+#if defined(XF86SCANPCI_WRAPPER)
+typedef enum {
+ SCANPCI_INIT,
+ SCANPCI_TERM
+} scanpciWrapperOpt;
+extern void XF86SCANPCI_WRAPPER(scanpciWrapperOpt flags);
+#endif
+
+/*
+ * Table of functions used to access a specific PCI bus domain
+ * (e.g. a primary PCI bus and all of its secondaries)
+ */
+typedef struct pci_bus_funcs {
+ CARD32 (*pciReadLong)(PCITAG, int);
+ void (*pciWriteLong)(PCITAG, int, CARD32);
+ void (*pciSetBitsLong)(PCITAG, int, CARD32, CARD32);
+ ADDRESS (*pciAddrHostToBus)(PCITAG, PciAddrType, ADDRESS);
+ ADDRESS (*pciAddrBusToHost)(PCITAG, PciAddrType, ADDRESS);
+ /*
+ * The next three are optional. If NULL, the corresponding function is
+ * to be performed generically.
+ */
+ CARD16 (*pciControlBridge)(int, CARD16, CARD16);
+ void (*pciGetBridgeBuses)(int, int *, int *, int *);
+ /* Use pointer's to avoid #include recursion */
+ void (*pciGetBridgeResources)(int, pointer *, pointer *, pointer *);
+
+ /* These are optional and will be implemented using read long
+ * if not present. */
+ CARD8 (*pciReadByte)(PCITAG, int);
+ void (*pciWriteByte)(PCITAG, int, CARD8);
+ CARD16 (*pciReadWord)(PCITAG, int);
+ void (*pciWriteWord)(PCITAG, int, CARD16);
+
+} pciBusFuncs_t, *pciBusFuncs_p;
+
+/*
+ * pciBusInfo_t - One structure per defined PCI bus
+ */
+typedef struct pci_bus_info {
+ unsigned char configMech; /* PCI config type to use */
+ unsigned char numDevices; /* Range of valid devnums */
+ unsigned char secondary; /* Boolean: bus is a secondary */
+ int primary_bus; /* Parent bus */
+#ifdef PowerMAX_OS
+ unsigned long ppc_io_base; /* PowerPC I/O spc membase */
+ unsigned long ppc_io_size; /* PowerPC I/O spc size */
+#endif
+ pciBusFuncs_p funcs; /* PCI access functions */
+ void *pciBusPriv; /* Implementation private data */
+ pciConfigPtr bridge; /* bridge that opens this bus */
+} pciBusInfo_t;
+
+#define HOST_NO_BUS ((pciBusInfo_t *)(-1))
+
+/* configMech values */
+#define PCI_CFG_MECH_UNKNOWN 0 /* Not yet known */
+#define PCI_CFG_MECH_1 1 /* Most machines */
+#define PCI_CFG_MECH_2 2 /* Older PC's */
+#define PCI_CFG_MECH_OTHER 3 /* Something else */
+
+/* Generic PCI service functions and helpers */
+PCITAG pciGenFindFirst(void);
+PCITAG pciGenFindNext(void);
+CARD32 pciCfgMech1Read(PCITAG tag, int offset);
+void pciCfgMech1Write(PCITAG tag, int offset, CARD32 val);
+void pciCfgMech1SetBits(PCITAG tag, int offset, CARD32 mask,
+ CARD32 val);
+CARD32 pciByteSwap(CARD32);
+Bool pciMfDev(int, int);
+ADDRESS pciAddrNOOP(PCITAG tag, PciAddrType type, ADDRESS);
+
+extern PCITAG (*pciFindFirstFP)(void);
+extern PCITAG (*pciFindNextFP)(void);
+
+extern CARD32 pciDevid;
+extern CARD32 pciDevidMask;
+
+extern int pciMaxBusNum;
+
+extern int pciBusNum;
+extern int pciDevNum;
+extern int pciFuncNum;
+extern PCITAG pciDeviceTag;
+
+extern pciBusInfo_t *pciBusInfo[];
+
+#endif /* _PCI_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Sbus.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Sbus.c
new file mode 100644
index 000000000..168bc669e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/Sbus.c
@@ -0,0 +1,637 @@
+/*
+ * SBUS and OpenPROM access functions.
+ *
+ * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
+ *
+ * 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
+ * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/Sbus.c,v 1.2tsi Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#ifdef sun
+#include <sys/utsname.h>
+#endif
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include "xf86sbusBus.h"
+#include "xf86Sbus.h"
+
+int promRootNode;
+
+static int promFd = -1;
+static int promCurrentNode;
+static int promOpenCount = 0;
+static int promP1275 = -1;
+#define MAX_PROP 128
+#define MAX_VAL (4096-128-4)
+static struct openpromio *promOpio;
+
+sbusDevicePtr *xf86SbusInfo = NULL;
+
+struct sbus_devtable sbusDeviceTable[] = {
+ { SBUS_DEVICE_BW2, FBTYPE_SUN2BW, "bwtwo", "Sun Monochrome (bwtwo)" },
+ { SBUS_DEVICE_CG2, FBTYPE_SUN2COLOR, "cgtwo", "Sun Color2 (cgtwo)" },
+ { SBUS_DEVICE_CG3, FBTYPE_SUN3COLOR, "cgthree", "Sun Color3 (cgthree)" },
+ { SBUS_DEVICE_CG4, FBTYPE_SUN4COLOR, "cgfour", "Sun Color4 (cgfour)" },
+ { SBUS_DEVICE_CG6, FBTYPE_SUNFAST_COLOR, "cgsix", "Sun GX" },
+ { SBUS_DEVICE_CG8, FBTYPE_MEMCOLOR, "cgeight", "Sun CG8/RasterOps" },
+ { SBUS_DEVICE_CG12, FBTYPE_SUNGP3, "cgtwelve", "Sun GS (cgtwelve)" },
+ { SBUS_DEVICE_CG14, FBTYPE_MDICOLOR, "cgfourteen", "Sun SX" },
+ { SBUS_DEVICE_GT, FBTYPE_SUNGT, "gt", "Sun Graphics Tower" },
+ { SBUS_DEVICE_MGX, -1, "mgx", "Quantum 3D MGXplus" },
+ { SBUS_DEVICE_LEO, FBTYPE_SUNLEO, "leo", "Sun ZX or Turbo ZX" },
+ { SBUS_DEVICE_TCX, FBTYPE_TCXCOLOR, "tcx", "Sun TCX" },
+ { SBUS_DEVICE_FFB, FBTYPE_CREATOR, "ffb", "Sun FFB" },
+ { SBUS_DEVICE_FFB, FBTYPE_CREATOR, "afb", "Sun Elite3D" },
+ { 0, 0, NULL }
+};
+
+int
+promGetSibling(int node)
+{
+ promOpio->oprom_size = sizeof(int);
+
+ if (node == -1) return 0;
+ *(int *)promOpio->oprom_array = node;
+ if (ioctl(promFd, OPROMNEXT, promOpio) < 0)
+ return 0;
+ promCurrentNode = *(int *)promOpio->oprom_array;
+ return *(int *)promOpio->oprom_array;
+}
+
+int
+promGetChild(int node)
+{
+ promOpio->oprom_size = sizeof(int);
+
+ if (!node || node == -1) return 0;
+ *(int *)promOpio->oprom_array = node;
+ if (ioctl(promFd, OPROMCHILD, promOpio) < 0)
+ return 0;
+ promCurrentNode = *(int *)promOpio->oprom_array;
+ return *(int *)promOpio->oprom_array;
+}
+
+char *
+promGetProperty(const char *prop, int *lenp)
+{
+ promOpio->oprom_size = MAX_VAL;
+
+ strcpy(promOpio->oprom_array, prop);
+ if (ioctl(promFd, OPROMGETPROP, promOpio) < 0)
+ return 0;
+ if (lenp) *lenp = promOpio->oprom_size;
+ return promOpio->oprom_array;
+}
+
+int
+promGetBool(const char *prop)
+{
+ promOpio->oprom_size = 0;
+
+ *(int *)promOpio->oprom_array = 0;
+ for (;;) {
+ promOpio->oprom_size = MAX_PROP;
+ if (ioctl(promFd, OPROMNXTPROP, promOpio) < 0)
+ return 0;
+ if (!promOpio->oprom_size)
+ return 0;
+ if (!strcmp(promOpio->oprom_array, prop))
+ return 1;
+ }
+}
+
+#define PROM_NODE_SIBLING 0x01
+#define PROM_NODE_PREF 0x02
+#define PROM_NODE_SBUS 0x04
+#define PROM_NODE_EBUS 0x08
+#define PROM_NODE_PCI 0x10
+
+static int
+promSetNode(sbusPromNodePtr pnode)
+{
+ int node;
+
+ if (!pnode->node || pnode->node == -1)
+ return -1;
+ if (pnode->cookie[0] & PROM_NODE_SIBLING)
+ node = promGetSibling(pnode->cookie[1]);
+ else
+ node = promGetChild(pnode->cookie[1]);
+ if (pnode->node != node)
+ return -1;
+ return 0;
+}
+
+static void
+promIsP1275(void)
+{
+#ifdef linux
+ FILE *f;
+ char buffer[1024];
+
+ if (promP1275 != -1)
+ return;
+ promP1275 = 0;
+ f = fopen("/proc/cpuinfo","r");
+ if (!f) return;
+ while (fgets(buffer, 1024, f) != NULL)
+ if (!strncmp (buffer, "type", 4) && strstr (buffer, "sun4u")) {
+ promP1275 = 1;
+ break;
+ }
+ fclose(f);
+#elif defined(sun)
+ struct utsname buffer;
+
+ if ((uname(&buffer) >= 0) && !strcmp(buffer.machine, "sun4u"))
+ promP1275 = TRUE;
+ else
+ promP1275 = FALSE;
+#elif defined(__FreeBSD__)
+ promP1275 = TRUE;
+#else
+#error Missing promIsP1275() function for this OS
+#endif
+}
+
+void
+sparcPromClose(void)
+{
+ if (promOpenCount > 1) {
+ promOpenCount--;
+ return;
+ }
+ if (promFd != -1) {
+ close(promFd);
+ promFd = -1;
+ }
+ if (promOpio) {
+ xfree(promOpio);
+ promOpio = NULL;
+ }
+ promOpenCount = 0;
+}
+
+int
+sparcPromInit(void)
+{
+ if (promOpenCount) {
+ promOpenCount++;
+ return 0;
+ }
+ promFd = open("/dev/openprom", O_RDONLY, 0);
+ if (promFd == -1)
+ return -1;
+ promOpio = (struct openpromio *)xalloc(4096);
+ if (!promOpio) {
+ sparcPromClose();
+ return -1;
+ }
+ promRootNode = promGetSibling(0);
+ if (!promRootNode) {
+ sparcPromClose();
+ return -1;
+ }
+ promIsP1275();
+ promOpenCount++;
+
+ return 0;
+}
+
+char *
+sparcPromGetProperty(sbusPromNodePtr pnode, const char *prop, int *lenp)
+{
+ if (promSetNode(pnode))
+ return NULL;
+ return promGetProperty(prop, lenp);
+}
+
+int
+sparcPromGetBool(sbusPromNodePtr pnode, const char *prop)
+{
+ if (promSetNode(pnode))
+ return 0;
+ return promGetBool(prop);
+}
+
+static void
+promWalkAssignNodes(int node, int oldnode, int flags, sbusDevicePtr *devicePtrs)
+{
+ int nextnode;
+ int len, sbus = flags & PROM_NODE_SBUS;
+ char *prop;
+ int devId, i, j;
+ sbusPromNode pNode, pNode2;
+
+ prop = promGetProperty("device_type", &len);
+ if (prop && (len > 0)) do {
+ if (!strcmp(prop, "display")) {
+ prop = promGetProperty("name", &len);
+ if (!prop || len <= 0)
+ break;
+ while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',')
+ prop++;
+ for (i = 0; sbusDeviceTable[i].devId; i++)
+ if (!strcmp(prop, sbusDeviceTable[i].promName))
+ break;
+ devId = sbusDeviceTable[i].devId;
+ if (!devId)
+ break;
+ if (!sbus) {
+ if (devId == SBUS_DEVICE_FFB) {
+ /*
+ * All /SUNW,ffb outside of SBUS tree come before all
+ * /SUNW,afb outside of SBUS tree in Linux.
+ */
+ if (!strcmp(prop, "afb"))
+ flags |= PROM_NODE_PREF;
+ } else if (devId != SBUS_DEVICE_CG14)
+ break;
+ }
+ for (i = 0; i < 32; i++) {
+ if (!devicePtrs[i] || devicePtrs[i]->devId != devId)
+ continue;
+ if (devicePtrs[i]->node.node) {
+ if ((devicePtrs[i]->node.cookie[0] & ~PROM_NODE_SIBLING) <=
+ (flags & ~PROM_NODE_SIBLING))
+ continue;
+ for (j = i + 1, pNode = devicePtrs[i]->node; j < 32; j++) {
+ if (!devicePtrs[j] || devicePtrs[j]->devId != devId)
+ continue;
+ pNode2 = devicePtrs[j]->node;
+ devicePtrs[j]->node = pNode;
+ pNode = pNode2;
+ }
+ }
+ devicePtrs[i]->node.node = node;
+ devicePtrs[i]->node.cookie[0] = flags;
+ devicePtrs[i]->node.cookie[1] = oldnode;
+ break;
+ }
+ break;
+ }
+ } while (0);
+
+ prop = promGetProperty("name", &len);
+ if (prop && len > 0) {
+ if (!strcmp(prop, "sbus") || !strcmp(prop, "sbi"))
+ sbus = PROM_NODE_SBUS;
+ }
+
+ nextnode = promGetChild(node);
+ if (nextnode)
+ promWalkAssignNodes(nextnode, node, sbus, devicePtrs);
+
+ nextnode = promGetSibling(node);
+ if (nextnode)
+ promWalkAssignNodes(nextnode, node, PROM_NODE_SIBLING | sbus, devicePtrs);
+}
+
+void
+sparcPromAssignNodes(void)
+{
+ sbusDevicePtr psdp, *psdpp;
+ int n, holes = 0, i, j;
+ FILE *f;
+ sbusDevicePtr devicePtrs[32];
+
+ (void)memset(devicePtrs, 0, sizeof(devicePtrs));
+ for (psdpp = xf86SbusInfo, n = 0; (psdp = *psdpp); psdpp++, n++) {
+ if (psdp->fbNum != n)
+ holes = 1;
+ devicePtrs[psdp->fbNum] = psdp;
+ }
+ if (holes && (f = fopen("/proc/fb", "r")) != NULL) {
+ /* We could not open one of fb devices, check /proc/fb to see what
+ * were the types of the cards missed. */
+ char buffer[64];
+ int fbNum, devId;
+ static struct {
+ int devId;
+ char *prefix;
+ } procFbPrefixes[] = {
+ { SBUS_DEVICE_BW2, "BWtwo" },
+ { SBUS_DEVICE_CG14, "CGfourteen" },
+ { SBUS_DEVICE_CG6, "CGsix" },
+ { SBUS_DEVICE_CG3, "CGthree" },
+ { SBUS_DEVICE_FFB, "Creator" },
+ { SBUS_DEVICE_FFB, "Elite 3D" },
+ { SBUS_DEVICE_LEO, "Leo" },
+ { SBUS_DEVICE_TCX, "TCX" },
+ { 0, NULL },
+ };
+
+ while (fscanf(f, "%d %63s\n", &fbNum, buffer) == 2) {
+ for (i = 0; procFbPrefixes[i].devId; i++)
+ if (! strncmp(procFbPrefixes[i].prefix, buffer,
+ strlen(procFbPrefixes[i].prefix)))
+ break;
+ devId = procFbPrefixes[i].devId;
+ if (! devId) continue;
+ if (devicePtrs[fbNum]) {
+ if (devicePtrs[fbNum]->devId != devId)
+ xf86ErrorF("Inconsistent /proc/fb with FBIOGATTR\n");
+ } else if (!devicePtrs[fbNum]) {
+ devicePtrs[fbNum] = psdp = xnfcalloc(sizeof (sbusDevice), 1);
+ psdp->devId = devId;
+ psdp->fbNum = fbNum;
+ psdp->fd = -2;
+ }
+ }
+ fclose(f);
+ }
+ promGetSibling(0);
+ promWalkAssignNodes(promRootNode, 0, PROM_NODE_PREF, devicePtrs);
+ for (i = 0, j = 0; i < 32; i++)
+ if (devicePtrs[i] && devicePtrs[i]->fbNum == -1)
+ j++;
+ xf86SbusInfo = xnfrealloc(xf86SbusInfo, sizeof(psdp) * (n + j + 1));
+ for (i = 0, psdpp = xf86SbusInfo; i < 32; i++)
+ if (devicePtrs[i]) {
+ if (devicePtrs[i]->fbNum == -1) {
+ memmove(psdpp + 1, psdpp, sizeof(psdpp) * (n + 1));
+ *psdpp = devicePtrs[i];
+ } else
+ n--;
+ }
+}
+
+static char *
+promGetReg(int type)
+{
+ char *prop;
+ int len;
+ static char regstr[40];
+
+ regstr[0] = 0;
+ prop = promGetProperty("reg", &len);
+ if (prop && len >= 4) {
+ unsigned int *reg = (unsigned int *)prop;
+ if (!promP1275 || (type == PROM_NODE_SBUS) || (type == PROM_NODE_EBUS))
+ sprintf (regstr, "@%x,%x", reg[0], reg[1]);
+ else if (type == PROM_NODE_PCI) {
+ if ((reg[0] >> 8) & 7)
+ sprintf (regstr, "@%x,%x", (reg[0] >> 11) & 0x1f, (reg[0] >> 8) & 7);
+ else
+ sprintf (regstr, "@%x", (reg[0] >> 11) & 0x1f);
+ } else if (len == 4)
+ sprintf (regstr, "@%x", reg[0]);
+ else {
+ unsigned int regs[2];
+
+ /* Things get more complicated on UPA. If upa-portid exists,
+ then address is @upa-portid,second-int-in-reg, otherwise
+ it is @first-int-in-reg/16,second-int-in-reg (well, probably
+ upa-portid always exists, but just to be safe). */
+ memcpy (regs, reg, sizeof(regs));
+ prop = promGetProperty("upa-portid", &len);
+ if (prop && len == 4) {
+ reg = (unsigned int *)prop;
+ sprintf (regstr, "@%x,%x", reg[0], regs[1]);
+ } else
+ sprintf (regstr, "@%x,%x", regs[0] >> 4, regs[1]);
+ }
+ }
+ return regstr;
+}
+
+static int
+promWalkNode2Pathname(char *path, int parent, int node, int searchNode, int type)
+{
+ int nextnode;
+ int len, ntype = type;
+ char *prop, *p;
+
+ prop = promGetProperty("name", &len);
+ *path = '/';
+ if (!prop || len <= 0)
+ return 0;
+ if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type)
+ ntype = PROM_NODE_SBUS;
+ else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI)
+ ntype = PROM_NODE_EBUS;
+ else if (!strcmp(prop, "pci") && !type)
+ ntype = PROM_NODE_PCI;
+ strcpy (path + 1, prop);
+ p = promGetReg(type);
+ if (*p)
+ strcat (path, p);
+ if (node == searchNode)
+ return 1;
+ nextnode = promGetChild(node);
+ if (nextnode &&
+ promWalkNode2Pathname(strchr(path, 0), node, nextnode, searchNode, ntype))
+ return 1;
+ nextnode = promGetSibling(node);
+ if (nextnode &&
+ promWalkNode2Pathname(path, parent, nextnode, searchNode, type))
+ return 1;
+ return 0;
+}
+
+char *
+sparcPromNode2Pathname(sbusPromNodePtr pnode)
+{
+ char *ret;
+
+ if (!pnode->node) return NULL;
+ ret = xalloc(4096);
+ if (!ret) return NULL;
+ if (promWalkNode2Pathname(ret, promRootNode, promGetChild(promRootNode), pnode->node, 0))
+ return ret;
+ xfree(ret);
+ return NULL;
+}
+
+static int
+promWalkPathname2Node(char *name, char *regstr, int parent, int type)
+{
+ int len, node, ret;
+ char *prop, *p;
+
+ for (;;) {
+ prop = promGetProperty("name", &len);
+ if (!prop || len <= 0)
+ return 0;
+ if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type)
+ type = PROM_NODE_SBUS;
+ else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI)
+ type = PROM_NODE_EBUS;
+ else if (!strcmp(prop, "pci") && !type)
+ type = PROM_NODE_PCI;
+ for (node = promGetChild(parent); node; node = promGetSibling(node)) {
+ prop = promGetProperty("name", &len);
+ if (!prop || len <= 0)
+ continue;
+ if (*name && strcmp(name, prop))
+ continue;
+ if (*regstr) {
+ p = promGetReg(type);
+ if (! *p || strcmp(p + 1, regstr))
+ continue;
+ }
+ break;
+ }
+ if (!node) {
+ for (node = promGetChild(parent); node; node = promGetSibling(node)) {
+ ret = promWalkPathname2Node(name, regstr, node, type);
+ if (ret) return ret;
+ }
+ return 0;
+ }
+ name = strchr(regstr, 0) + 1;
+ if (! *name)
+ return node;
+ p = strchr(name, '/');
+ if (p)
+ *p = 0;
+ else
+ p = strchr(name, 0);
+ regstr = strchr(name, '@');
+ if (regstr)
+ *regstr++ = 0;
+ else
+ regstr = p;
+ if (name == regstr)
+ return 0;
+ parent = node;
+ }
+}
+
+int
+sparcPromPathname2Node(const char *pathName)
+{
+ int i;
+ char *name, *regstr, *p;
+
+ i = strlen(pathName);
+ name = xalloc(i + 2);
+ if (! name) return 0;
+ strcpy (name, pathName);
+ name [i + 1] = 0;
+ if (name[0] != '/')
+ return 0;
+ p = strchr(name + 1, '/');
+ if (p)
+ *p = 0;
+ else
+ p = strchr(name, 0);
+ regstr = strchr(name, '@');
+ if (regstr)
+ *regstr++ = 0;
+ else
+ regstr = p;
+ if (name + 1 == regstr)
+ return 0;
+ promGetSibling(0);
+ i = promWalkPathname2Node(name + 1, regstr, promRootNode, 0);
+ xfree(name);
+ return i;
+}
+
+pointer
+xf86MapSbusMem(sbusDevicePtr psdp, unsigned long offset, unsigned long size)
+{
+ pointer ret;
+ unsigned long pagemask = xf86getpagesize() - 1;
+ unsigned long off = offset & ~pagemask;
+ unsigned long len = ((offset + size + pagemask) & ~pagemask) - off;
+
+ if (psdp->fd == -1) {
+ psdp->fd = open(psdp->device, O_RDWR);
+ if (psdp->fd == -1)
+ return NULL;
+ } else if (psdp->fd < 0)
+ return NULL;
+
+ ret = (pointer) mmap (NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE,
+ psdp->fd, off);
+ if (ret == (pointer) -1) {
+ ret = (pointer) mmap (NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED,
+ psdp->fd, off);
+ }
+ if (ret == (pointer) -1)
+ return NULL;
+
+ return (char *)ret + (offset - off);
+}
+
+void
+xf86UnmapSbusMem(sbusDevicePtr psdp, pointer addr, unsigned long size)
+{
+ unsigned long mask = xf86getpagesize() - 1;
+ unsigned long base = (unsigned long)addr & ~mask;
+ unsigned long len = (((unsigned long)addr + size + mask) & ~mask) - base;
+
+ munmap ((pointer)base, len);
+}
+
+/* Tell OS that we are driving the HW cursor ourselves. */
+void
+xf86SbusHideOsHwCursor(sbusDevicePtr psdp)
+{
+ struct fbcursor fbcursor;
+ unsigned char zeros[8];
+
+ memset(&fbcursor, 0, sizeof(fbcursor));
+ memset(&zeros, 0, sizeof(zeros));
+ fbcursor.cmap.count = 2;
+ fbcursor.cmap.red = zeros;
+ fbcursor.cmap.green = zeros;
+ fbcursor.cmap.blue = zeros;
+ fbcursor.image = (char *)zeros;
+ fbcursor.mask = (char *)zeros;
+ fbcursor.size.x = 32;
+ fbcursor.size.y = 1;
+ fbcursor.set = FB_CUR_SETALL;
+ ioctl(psdp->fd, FBIOSCURSOR, &fbcursor);
+}
+
+/* Set HW cursor colormap. */
+void
+xf86SbusSetOsHwCursorCmap(sbusDevicePtr psdp, int bg, int fg)
+{
+ struct fbcursor fbcursor;
+ unsigned char red[2], green[2], blue[2];
+
+ memset(&fbcursor, 0, sizeof(fbcursor));
+ red[0] = bg >> 16;
+ green[0] = bg >> 8;
+ blue[0] = bg;
+ red[1] = fg >> 16;
+ green[1] = fg >> 8;
+ blue[1] = fg;
+ fbcursor.cmap.count = 2;
+ fbcursor.cmap.red = red;
+ fbcursor.cmap.green = green;
+ fbcursor.cmap.blue = blue;
+ fbcursor.set = FB_CUR_SETCMAP;
+ ioctl(psdp->fd, FBIOSCURSOR, &fbcursor);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/altixPCI.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/altixPCI.c
new file mode 100644
index 000000000..010f6619a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/altixPCI.c
@@ -0,0 +1,120 @@
+/*
+ * This file contains the glue necessary for support of SGI's Altix chipset.
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include "altixPCI.h"
+#include "xf86.h"
+#include "Pci.h"
+
+/*
+ * get_dev_on_bus - Return the first device we find on segnum, busnum
+ *
+ * Walk all the PCI devices and return the first one found on segnum, busnum.
+ * There may be a better way to do this in some xf86* function I don't know
+ * about.
+ */
+static pciDevice *get_dev_on_bus(unsigned int segnum, unsigned int busnum)
+{
+ pciDevice **pdev = xf86scanpci(0);
+ int i;
+
+ for (i = 0; pdev[i] != NULL; i++)
+ if (PCI_DOM_FROM_TAG(pdev[i]->tag) == segnum &&
+ pdev[i]->busnum == busnum)
+ return pdev[i];
+ /* Should never get here... */
+ ErrorF("No PCI device found on %04x:%02x??", segnum, busnum);
+ return NULL;
+}
+
+/*
+ * get_bridge_info - fill in the bridge info for bus_info based on pdev
+ *
+ * Find the parent bus for pdev if it exists, otherwise assume pdev *is*
+ * the parent bus. We need this on Altix because our bridges are transparent.
+ */
+static void get_bridge_info(pciBusInfo_t *bus_info, pciDevice *pdev)
+{
+ unsigned int parent_segnum, segnum = PCI_DOM_FROM_TAG(pdev->tag);
+ unsigned int parent_busnum, busnum = pdev->busnum;
+ char bridge_path[] = "/sys/class/pci_bus/0000:00/bridge";
+ char bridge_target[] = "../../../devices/pci0000:00";
+
+ /* Path to this device's bridge */
+ sprintf(bridge_path, "/sys/class/pci_bus/%04x:%02x/bridge", segnum,
+ busnum);
+
+ if (readlink(bridge_path, bridge_target, strlen(bridge_target)) < 0) {
+ perror("failed to dereference bridge link");
+ ErrorF("failed to dereference bridge link, aborting\n");
+ exit(-1);
+ }
+
+ sscanf(bridge_target, "../../../devices/pci%04x:%02x", &parent_segnum,
+ &parent_busnum);
+
+ /*
+ * If there's no bridge or the bridge points to the device, use
+ * pdev as the bridge
+ */
+ if (segnum == parent_segnum && busnum == parent_busnum) {
+ bus_info->bridge = pdev;
+ bus_info->secondary = FALSE;
+ bus_info->primary_bus = busnum;
+ } else {
+ bus_info->bridge = get_dev_on_bus(parent_segnum,
+ parent_busnum);
+ bus_info->secondary = TRUE;
+ bus_info->primary_bus = parent_busnum;
+ }
+ pdev->businfo = bus_info;
+ pdev->pci_base_class = PCI_CLASS_DISPLAY;
+ pdev->pci_sub_class = PCI_SUBCLASS_PREHISTORIC_VGA;
+}
+
+void xf86PreScanAltix(void)
+{
+ /* Nothing to see here... */
+}
+
+void xf86PostScanAltix(void)
+{
+ pciConfigPtr *pdev;
+ pciBusInfo_t *bus_info;
+ int prevBusNum, curBusNum, idx;
+
+ /*
+ * Altix PCI bridges are invisible to userspace, so we make each device
+ * look like it's its own bridge unless it actually has a parent (as in
+ * the case of PCI to PCI bridges).
+ */
+ bus_info = pciBusInfo[0];
+ pdev = xf86scanpci(0);
+ prevBusNum = curBusNum = pdev[0]->busnum;
+ bus_info = pciBusInfo[curBusNum];
+ bus_info->bridge = pdev[0];
+ bus_info->secondary = FALSE;
+ bus_info->primary_bus = curBusNum;
+
+ /* Walk all the PCI devices, assigning their bridge info */
+ for (idx = 0; pdev[idx] != NULL; idx++) {
+ if (pdev[idx]->busnum == prevBusNum)
+ continue; /* Already fixed up this bus */
+
+ curBusNum = pdev[idx]->busnum;
+ bus_info = pciBusInfo[curBusNum];
+
+ /*
+ * Fill in bus_info for pdev. The bridge field will either
+ * be pdev[idx] or a device on the parent bus.
+ */
+ get_bridge_info(bus_info, pdev[idx]);
+ prevBusNum = curBusNum;
+ }
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/altixPCI.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/altixPCI.h
new file mode 100644
index 000000000..2a738f362
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/altixPCI.h
@@ -0,0 +1,20 @@
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef PCI_ALTIX_H
+#define PCI_ALTIX_H 1
+
+#include <X11/Xdefs.h>
+#include <Pci.h>
+
+Bool xorgProbeAltix(scanpciWrapperOpt flags);
+void xf86PreScanAltix(void);
+void xf86PostScanAltix(void);
+
+/* Some defines for PCI */
+#define VENDOR_SGI 0x10A9
+#define CHIP_TIO_CA 0x1010
+#define CHIP_PIC_PCI 0x1011
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/axpPci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/axpPci.c
new file mode 100644
index 000000000..08c7fbd39
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/axpPci.c
@@ -0,0 +1,478 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/axpPci.c,v 1.14 2002/12/11 02:44:28 dawes Exp $ */
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include "compiler.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "Pci.h"
+
+#include <asm/unistd.h>
+#include "../linux/lnx.h" /* for _iobase */
+
+/*
+ * Alpha/Linux platform specific PCI access functions
+ */
+static CARD32 axpPciCfgRead(PCITAG tag, int off);
+static void axpPciCfgWrite(PCITAG, int off, CARD32 val);
+static void axpPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits);
+
+static pciBusFuncs_t axpFuncs0 = {
+/* pciReadLong */ axpPciCfgRead,
+/* pciWriteLong */ axpPciCfgWrite,
+/* pciSetBitsLong */ axpPciCfgSetBits,
+/* pciAddrHostToBus */ pciAddrNOOP,
+/* pciAddrBusToHost */ pciAddrNOOP
+};
+
+typedef struct _axpDomainRec {
+ int domain, hose;
+ int root_bus;
+ unsigned long dense_io, sparse_io;
+ unsigned long dense_mem, sparse_mem;
+ IOADDRESS mapped_io;
+} axpDomainRec, *axpDomainPtr;
+
+#define MAX_DOMAINS (MAX_PCI_BUSES / 256)
+static axpDomainPtr xf86DomainInfo[MAX_DOMAINS] = { NULL, };
+static int pciNumDomains = 0;
+
+/*
+ * For debug, domain assignment can start downward from a fixed base
+ * (instead of up from 0) by defining FORCE_HIGH_DOMAINS. This allows
+ * debug of large domain numbers and sparse domain numbering on systems
+ * which don't have as many hoses.
+ */
+#if 0
+# define FORCE_HIGH_DOMAINS MAX_DOMAINS /* assign domains downward from here */
+#endif
+
+/*
+ * If FORCE_HIGH_DOMAINS is set, make sure it's not larger than the
+ * max domain
+ */
+#if defined(FORCE_HIGH_DOMAINS) && (FORCE_HIGH_DOMAINS > MAX_DOMAINS)
+# undef FORCE_HIGH_DOMAINS
+# define FORCE_HIGH_DOMAINS MAX_DOMAINS
+#endif
+
+static int
+axpSetupDomains(void)
+{
+ axpDomainRec axpDomain;
+ int numDomains = 0;
+ int hose;
+
+#ifndef INCLUDE_XF86_NO_DOMAIN
+
+#ifdef FORCE_HIGH_DOMAINS
+ xf86Msg(X_WARNING,
+ "DEBUG OPTION FORCE_HIGH_DOMAINS in use - DRI will *NOT* work\n");
+ numDomains = FORCE_HIGH_DOMAINS;
+#endif
+
+ /*
+ * Since each hose has a different address space, hoses are a perfect
+ * overlay for domains, so set up one domain for each hose present
+ * in the system. We have to loop through all possible hoses because
+ * some systems allow sparse I/O controllers.
+ */
+ for(hose = 0; hose < MAX_DOMAINS; hose++) {
+ axpDomain.root_bus = _iobase(IOBASE_ROOT_BUS, hose, -1, -1);
+ if (axpDomain.root_bus < 0) continue;
+
+ axpDomain.hose = hose;
+
+#ifndef FORCE_HIGH_DOMAINS
+
+ axpDomain.domain = axpDomain.hose = hose;
+ numDomains = axpDomain.domain + 1;
+
+#else /* FORCE_HIGH_DOMAINS */
+
+ axpDomain.domain = numDomains - hose - 1;
+
+ xf86Msg(X_WARNING,
+ "FORCE_HIGH_DOMAINS - assigned hose %d to domain %d\n",
+ axpDomain.hose, axpDomain.domain);
+
+#endif /* FORCE_HIGH_DOMAINS */
+
+ axpDomain.dense_io = _iobase(IOBASE_DENSE_IO, hose, -1, -1);
+ axpDomain.sparse_io = _iobase(IOBASE_SPARSE_IO, hose, -1, -1);
+ axpDomain.mapped_io = 0;
+ axpDomain.dense_mem = _iobase(IOBASE_DENSE_MEM, hose, -1, -1);
+ axpDomain.sparse_mem = _iobase(IOBASE_SPARSE_MEM, hose, -1, -1);
+
+ xf86DomainInfo[axpDomain.domain] = xnfalloc(sizeof(axpDomainRec));
+ *(xf86DomainInfo[axpDomain.domain]) = axpDomain;
+
+ /*
+ * For now, only allow a single domain (hose) on sparse i/o systems.
+ *
+ * Allowing multiple domains on sparse systems would require:
+ * 1) either
+ * a) revamping the sparse video mapping code to allow
+ * for multiple unrelated address regions
+ * -- OR --
+ * b) implementing sparse mapping directly in
+ * xf86MapDomainMemory
+ * 2) revaming read/write sparse routines to correctly handle
+ * the solution to 1)
+ * 3) implementing a sparse I/O system (mapping, inX/outX)
+ * independent of glibc, since the glibc version only
+ * supports hose 0
+ */
+ if (axpDomain.sparse_io) {
+ if (_iobase(IOBASE_ROOT_BUS, hose + 1, -1, -1) >= 0) {
+ /*
+ * It's a sparse i/o system with (at least) one more hose,
+ * show a message indicating that video is constrained to
+ * hose 0
+ */
+ xf86Msg(X_INFO,
+ "Sparse I/O system - constraining video to hose 0\n");
+ }
+ break;
+ }
+ }
+
+#else /* INCLUDE_XF86_NO_DOMAIN */
+
+ /*
+ * domain support is not included, so just set up a single domain (0)
+ * to represent the first hose so that axpPciInit will still have
+ * be able to set up the root bus
+ */
+ xf86DomainInfo[0] = xnfalloc(sizeof(axpDomainRec));
+ *(xf86DomainInfo[0]) = axpDomain;
+ numDomains = 1;
+
+#endif /* INCLUDE_XF86_NO_DOMAIN */
+
+ return numDomains;
+}
+
+void
+axpPciInit()
+{
+ axpDomainPtr pDomain;
+ int domain, bus;
+
+ pciNumDomains = axpSetupDomains();
+
+ for(domain = 0; domain < pciNumDomains; domain++) {
+ if (!(pDomain = xf86DomainInfo[domain])) continue;
+
+ /*
+ * Since any bridged buses will be behind a probed pci-pci bridge,
+ * only set up the root bus for each domain (hose) and the bridged
+ * buses will be set up as they are found.
+ */
+ bus = PCI_MAKE_BUS(domain, 0);
+ pciBusInfo[bus] = xnfalloc(sizeof(pciBusInfo_t));
+ (void)memset(pciBusInfo[bus], 0, sizeof(pciBusInfo_t));
+
+ pciBusInfo[bus]->configMech = PCI_CFG_MECH_OTHER;
+ pciBusInfo[bus]->numDevices = 32;
+ pciBusInfo[bus]->funcs = &axpFuncs0;
+ pciBusInfo[bus]->pciBusPriv = pDomain;
+
+ pciNumBuses = bus + 1;
+ }
+
+ pciFindFirstFP = pciGenFindFirst;
+ pciFindNextFP = pciGenFindNext;
+}
+
+/*
+ * Alpha/Linux PCI configuration space access routines
+ */
+static int
+axpPciBusFromTag(PCITAG tag)
+{
+ pciBusInfo_t *pBusInfo;
+ axpDomainPtr pDomain;
+ int bus, dfn;
+
+ bus = PCI_BUS_FROM_TAG(tag);
+ if ((bus >= pciNumBuses)
+ || !(pBusInfo = pciBusInfo[bus])
+ || !(pDomain = pBusInfo->pciBusPriv)
+ || (pDomain->domain != PCI_DOM_FROM_TAG(tag))) return -1;
+
+ bus = PCI_BUS_NO_DOMAIN(bus) + pDomain->root_bus;
+ dfn = PCI_DFN_FROM_TAG(tag);
+ if (_iobase(IOBASE_HOSE, -1, bus, dfn) != pDomain->hose) return -1;
+
+ return bus;
+}
+
+static CARD32
+axpPciCfgRead(PCITAG tag, int off)
+{
+ int bus, dfn;
+ CARD32 val = 0xffffffff;
+
+ if ((bus = axpPciBusFromTag(tag)) >= 0) {
+ dfn = PCI_DFN_FROM_TAG(tag);
+
+ syscall(__NR_pciconfig_read, bus, dfn, off, 4, &val);
+ }
+ return(val);
+}
+
+static void
+axpPciCfgWrite(PCITAG tag, int off, CARD32 val)
+{
+ int bus, dfn;
+
+ if ((bus = axpPciBusFromTag(tag)) >= 0) {
+ dfn = PCI_DFN_FROM_TAG(tag);
+ syscall(__NR_pciconfig_write, bus, dfn, off, 4, &val);
+ }
+}
+
+static void
+axpPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits)
+{
+ int bus, dfn;
+ CARD32 val = 0xffffffff;
+
+ if ((bus = axpPciBusFromTag(tag)) >= 0) {
+ dfn = PCI_DFN_FROM_TAG(tag);
+
+ syscall(__NR_pciconfig_read, bus, dfn, off, 4, &val);
+ val = (val & ~mask) | (bits & mask);
+ syscall(__NR_pciconfig_write, bus, dfn, off, 4, &val);
+ }
+}
+
+#ifndef INCLUDE_XF86_NO_DOMAIN
+
+/*
+ * Alpha/Linux addressing domain support
+ */
+
+int
+xf86GetPciDomain(PCITAG Tag)
+{
+ return PCI_DOM_FROM_TAG(Tag);
+}
+
+pointer
+xf86MapDomainMemory(int ScreenNum, int Flags, PCITAG Tag,
+ ADDRESS Base, unsigned long Size)
+{
+ axpDomainPtr pDomain;
+ int domain = PCI_DOM_FROM_TAG(Tag);
+
+ if ((domain < 0) || (domain >= pciNumDomains) ||
+ !(pDomain = xf86DomainInfo[domain]))
+ FatalError("%s called with invalid parameters\n", __FUNCTION__);
+
+ /*
+ * xf86MapVidMem already does what we need, but remember to subtract
+ * _bus_base() (the physical dense memory root of hose 0) since
+ * xf86MapVidMem is expecting an offset relative to _bus_base() rather
+ * than an actual physical address.
+ */
+ return xf86MapVidMem(ScreenNum, Flags,
+ pDomain->dense_mem + Base - _bus_base(), Size);
+}
+
+IOADDRESS
+xf86MapDomainIO(int ScreenNum, int Flags, PCITAG Tag,
+ IOADDRESS Base, unsigned long Size)
+{
+ axpDomainPtr pDomain;
+ int domain = PCI_DOM_FROM_TAG(Tag);
+
+ if ((domain < 0) || (domain >= pciNumDomains) ||
+ !(pDomain = xf86DomainInfo[domain]))
+ FatalError("%s called with invalid parameters\n", __FUNCTION__);
+
+ /*
+ * Use glibc inx/outx routines for sparse I/O, so just return the
+ * base [this is ok since we also constrain sparse I/O systems to
+ * a single domain in axpSetupDomains()]
+ */
+ if (pDomain->sparse_io) return Base;
+
+ /*
+ * I/O addresses on Alpha are really just different physical memory
+ * addresses that the system corelogic turns into I/O commands on the
+ * bus, so just use xf86MapVidMem to map I/O as well, but remember
+ * to subtract _bus_base() (the physical dense memory root of hose 0)
+ * since xf86MapVidMem is expecting an offset relative to _bus_base()
+ * rather than an actual physical address.
+ *
+ * Map the entire I/O space (64kB) at once and only once.
+ */
+ if (!pDomain->mapped_io)
+ pDomain->mapped_io = (IOADDRESS)xf86MapVidMem(ScreenNum, Flags,
+ pDomain->dense_io - _bus_base(),
+ 0x10000);
+
+ return pDomain->mapped_io + Base;
+}
+
+int
+xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
+{
+ static unsigned long pagemask = 0;
+ unsigned char *MappedAddr;
+ unsigned long MapSize;
+ ADDRESS MapBase;
+ int i;
+
+ if (!pagemask) pagemask = xf86getpagesize() - 1;
+
+ /* Ensure page boundaries */
+ MapBase = Base & ~pagemask;
+ MapSize = ((Base + Len + pagemask) & ~pagemask) - MapBase;
+
+ /*
+ * VIDMEM_MMIO in order to get sparse mapping on sparse memory systems
+ * so we can use mmio functions to read (that way we can really get byte
+ * at a time reads on dense memory systems with byte/word instructions.
+ */
+ MappedAddr = xf86MapDomainMemory(-1, VIDMEM_READONLY | VIDMEM_MMIO,
+ Tag, MapBase, MapSize);
+
+ for (i = 0; i < Len; i++) {
+ *Buf++ = xf86ReadMmio8(MappedAddr, Base - MapBase + i);
+ }
+
+ xf86UnMapVidMem(-1, MappedAddr, MapSize);
+ return Len;
+}
+
+resPtr
+xf86PciBusAccWindowsFromOS(void)
+{
+ resPtr pRes = NULL;
+ resRange range;
+ int domain;
+
+ for(domain = 0; domain < pciNumDomains; domain++) {
+ if (!xf86DomainInfo[domain]) continue;
+
+ RANGE(range, 0, 0xffffffffUL,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ RANGE(range, 0, 0x0000ffffUL,
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ }
+
+ return pRes;
+}
+
+resPtr
+xf86BusAccWindowsFromOS(void)
+{
+ return xf86PciBusAccWindowsFromOS();
+}
+
+resPtr
+xf86AccResFromOS(resPtr pRes)
+{
+ resRange range;
+ int domain;
+
+ for(domain = 0; domain < pciNumDomains; domain++) {
+ if (!xf86DomainInfo[domain]) continue;
+
+ /*
+ * Fallback is to claim the following areas:
+ *
+ * 0x000c0000 - 0x000effff location of VGA and other extensions ROMS
+ */
+
+ RANGE(range, 0x000c0000, 0x000effff,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ /*
+ * Fallback would be to claim well known ports in the 0x0 - 0x3ff
+ * range along with their sparse I/O aliases, but that's too
+ * imprecise. Instead claim a bare minimum here.
+ */
+ RANGE(range, 0x00000000, 0x000000ff,
+ RANGE_TYPE(ResExcIoBlock, domain)); /* For mainboard */
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ /*
+ * At minimum, the top and bottom resources must be claimed, so that
+ * resources that are (or appear to be) unallocated can be relocated.
+ */
+ RANGE(range, 0x00000000, 0x00000000,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ RANGE(range, 0xffffffff, 0xffffffff,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+/* RANGE(range, 0x00000000, 0x00000000,
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1); */
+ RANGE(range, 0xffffffff, 0xffffffff,
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ }
+
+ return pRes;
+}
+
+#endif /* !INCLUDE_XF86_NO_DOMAIN */
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.c
new file mode 100644
index 000000000..65b0c0474
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.c
@@ -0,0 +1,64 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.c,v 1.2 2003/07/17 15:08:22 tsi Exp $ */
+/*
+ * Copyright (C) 2002-2003 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, 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
+ * XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+
+/*
+ * This file contains the glue necessary for support of Intel's E8870 chipset.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "e8870PCI.h"
+#include "xf86.h"
+#include "Pci.h"
+
+Bool
+xorgProbeE8870(scanpciWrapperOpt flags)
+{
+ PCITAG tag;
+
+ /* Look for an E8870's Hub interface */
+ tag = PCI_MAKE_TAG(0, 0x1E, 0);
+ if (pciReadLong(tag, PCI_ID_REG) == DEVID(VENDOR_INTEL, CHIP_82801_P2P))
+ return TRUE;
+
+ return FALSE;
+}
+
+void
+xf86PreScanE8870(void)
+{
+ /* XXX Fill me in... */
+ return;
+}
+
+void
+xf86PostScanE8870(void)
+{
+ /* XXX Fill me in... */
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.h
new file mode 100644
index 000000000..9efa0ed6d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.h
@@ -0,0 +1,42 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/e8870PCI.h,v 1.1 2003/02/23 20:26:49 tsi Exp $ */
+/*
+ * Copyright (C) 2002-2003 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, 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
+ * XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef PCI_E8870_H
+#define PCI_E8870_H 1
+
+#include <X11/Xdefs.h>
+#include <Pci.h>
+
+Bool xorgProbeE8870(scanpciWrapperOpt flags);
+void xf86PreScanE8870(void);
+void xf86PostScanE8870(void);
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/freebsdPci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/freebsdPci.c
new file mode 100644
index 000000000..f6d6f8a6d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/freebsdPci.c
@@ -0,0 +1,171 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/freebsdPci.c,v 1.4 2002/07/24 19:06:52 tsi Exp $ */
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include "compiler.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "Pci.h"
+
+#include <sys/pciio.h>
+
+/*
+ * freebsd platform specific PCI access functions -- using /dev/pci
+ * needs kernel version 2.2.x
+ */
+static CARD32 freebsdPciCfgRead(PCITAG tag, int off);
+static void freebsdPciCfgWrite(PCITAG, int off, CARD32 val);
+static void freebsdPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits);
+
+static pciBusFuncs_t freebsdFuncs0 = {
+/* pciReadLong */ freebsdPciCfgRead,
+/* pciWriteLong */ freebsdPciCfgWrite,
+/* pciSetBitsLong */ freebsdPciCfgSetBits,
+/* pciAddrHostToBus */ pciAddrNOOP,
+/* pciAddrBusToHost */ pciAddrNOOP
+};
+
+static pciBusInfo_t freebsdPci0 = {
+/* configMech */ PCI_CFG_MECH_OTHER,
+/* numDevices */ 32,
+/* secondary */ FALSE,
+/* primary_bus */ 0,
+#ifdef PowerMAX_OS
+/* ppc_io_base */ 0,
+/* ppc_io_size */ 0,
+#endif
+/* funcs */ &freebsdFuncs0,
+/* pciBusPriv */ NULL,
+/* bridge */ NULL
+};
+
+#if !defined(__OpenBSD__) && !defined(__FreeBSD__)
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+#ifdef __sparc__
+#ifndef ASI_PL
+#define ASI_PL 0x88
+#endif
+#define PCI_CPU(val) ({ \
+int __ret; \
+__asm__ __volatile__("lduwa [%1] %2, %0" : "=r" (__ret) : "r" (&val), "i" (ASI_PL)); \
+__ret; \
+})
+#else
+#define PCI_CPU(val) (((val >> 24) & 0x000000ff) | \
+ ((val >> 8) & 0x0000ff00) | \
+ ((val << 8) & 0x00ff0000) | \
+ ((val << 24) & 0xff000000))
+#endif
+#else
+#define PCI_CPU(val) (val)
+#endif
+#else /* ! OpenBSD */
+/* OpenBSD has already the bytes in the right order
+ for all architectures */
+#define PCI_CPU(val) (val)
+#endif
+
+
+#define BUS(tag) (((tag)>>16)&0xff)
+#define DFN(tag) (((tag)>>8)&0xff)
+
+static int pciFd = -1;
+
+void
+freebsdPciInit()
+{
+ pciFd = open("/dev/pci", O_RDWR);
+ if (pciFd < 0)
+ return;
+
+ pciNumBuses = 1;
+ pciBusInfo[0] = &freebsdPci0;
+ pciFindFirstFP = pciGenFindFirst;
+ pciFindNextFP = pciGenFindNext;
+}
+
+static CARD32
+freebsdPciCfgRead(PCITAG tag, int off)
+{
+ struct pci_io io;
+ int error;
+ io.pi_sel.pc_bus = BUS(tag);
+ io.pi_sel.pc_dev = DFN(tag) >> 3;
+ io.pi_sel.pc_func = DFN(tag) & 7;
+ io.pi_reg = off;
+ io.pi_width = 4;
+ error = ioctl(pciFd, PCIOCREAD, &io);
+ if (error)
+ return ~0;
+ return PCI_CPU(io.pi_data);
+}
+
+static void
+freebsdPciCfgWrite(PCITAG tag, int off, CARD32 val)
+{
+ struct pci_io io;
+ io.pi_sel.pc_bus = BUS(tag);
+ io.pi_sel.pc_dev = DFN(tag) >> 3;
+ io.pi_sel.pc_func = DFN(tag) & 7;
+ io.pi_reg = off;
+ io.pi_width = 4;
+ io.pi_data = PCI_CPU(val);
+ ioctl(pciFd, PCIOCWRITE, &io);
+}
+
+static void
+freebsdPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits)
+{
+ CARD32 val = freebsdPciCfgRead(tag, off);
+ val = (val & ~mask) | (bits & mask);
+ freebsdPciCfgWrite(tag, off, val);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/ix86Pci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/ix86Pci.c
new file mode 100644
index 000000000..6e2b650d1
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/ix86Pci.c
@@ -0,0 +1,704 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/ix86Pci.c,v 1.25 2003/09/24 02:43:34 dawes Exp $ */
+/*
+ * ix86Pci.c - x86 PCI driver
+ *
+ * The XFree86 server PCI access functions have been reimplemented as a
+ * framework that allows each supported platform/OS to have their own
+ * platform/OS specific PCI driver.
+ *
+ * Most of the code of these functions was simply lifted from the
+ * Intel architecture specifric portion of the original Xfree86
+ * PCI code in hw/xfree86/common_hw/xf86_PCI.C...
+ *
+ * Gary Barton
+ * Concurrent Computer Corporation
+ * garyb@gate.net
+ */
+
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * This software is derived from the original XFree86 PCI code
+ * which includes the following copyright notices as well:
+ *
+ * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of the above listed copyright holder(s)
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. The above listed
+ * copyright holder(s) make(s) no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * This code is also based heavily on the code in FreeBSD-current, which was
+ * written by Wolfgang Stanglmeier, and contains the following copyright:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/*
+ * Copyright (c) 1999-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
+
+#include <stdio.h>
+#include "compiler.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "Pci.h"
+
+#ifdef PC98
+#define outb(port,data) _outb(port,data)
+#define outl(port,data) _outl(port,data)
+#define inb(port) _inb(port)
+#define inl(port) _inl(port)
+#endif
+
+#define PCI_CFGMECH2_ENABLE_REG 0xCF8
+#ifdef PC98
+#define PCI_CFGMECH2_FORWARD_REG 0xCF9
+#else
+#define PCI_CFGMECH2_FORWARD_REG 0xCFA
+#endif
+
+#define PCI_CFGMECH2_MAXDEV 16
+
+#define PCI_ADDR_FROM_TAG_CFG1(tag,reg) (PCI_EN | tag | (reg & 0xfc))
+#define PCI_FORWARD_FROM_TAG(tag) PCI_BUS_FROM_TAG(tag)
+#define PCI_ENABLE_FROM_TAG(tag) (0xf0 | (((tag) & 0x00000700) >> 7))
+#define PCI_ADDR_FROM_TAG_CFG2(tag,reg) (0xc000 | (((tag) & 0x0000f800) >> 3) \
+ | (reg & 0xfc))
+
+/*
+ * Intel x86 platform specific PCI access functions
+ */
+static CARD32 ix86PciReadLongSetup(PCITAG tag, int off);
+static void ix86PciWriteLongSetup(PCITAG, int off, CARD32 val);
+static void ix86PciSetBitsLongSetup(PCITAG, int off, CARD32 mask, CARD32 val);
+static CARD32 ix86PciReadLongCFG1(PCITAG tag, int off);
+static void ix86PciWriteLongCFG1(PCITAG, int off, CARD32 val);
+static void ix86PciSetBitsLongCFG1(PCITAG, int off, CARD32 mask, CARD32 val);
+static CARD32 ix86PciReadLongCFG2(PCITAG tag, int off);
+static void ix86PciWriteLongCFG2(PCITAG, int off, CARD32 val);
+static void ix86PciSetBitsLongCFG2(PCITAG, int off, CARD32 mask, CARD32 val);
+
+static pciBusFuncs_t ix86Funcs0 = {
+/* pciReadLong */ ix86PciReadLongSetup,
+/* pciWriteLong */ ix86PciWriteLongSetup,
+/* pciSetBitsLong */ ix86PciSetBitsLongSetup,
+/* pciAddrHostToBus */ pciAddrNOOP,
+/* pciAddrBusToHost */ pciAddrNOOP
+};
+
+static pciBusFuncs_t ix86Funcs1 = {
+/* pciReadLong */ ix86PciReadLongCFG1,
+/* pciWriteLong */ ix86PciWriteLongCFG1,
+/* pciSetBitsLong */ ix86PciSetBitsLongCFG1,
+/* pciAddrHostToBus */ pciAddrNOOP,
+/* pciAddrBusToHost */ pciAddrNOOP
+};
+
+static pciBusFuncs_t ix86Funcs2 = {
+/* pciReadLong */ ix86PciReadLongCFG2,
+/* pciWriteLong */ ix86PciWriteLongCFG2,
+/* pciSetBitsLong */ ix86PciSetBitsLongCFG2,
+/* pciAddrHostToBus */ pciAddrNOOP,
+/* pciAddrBusToHost */ pciAddrNOOP
+};
+
+static pciBusInfo_t ix86Pci0 = {
+/* configMech */ PCI_CFG_MECH_UNKNOWN, /* Set by ix86PciInit() */
+/* numDevices */ 0, /* Set by ix86PciInit() */
+/* secondary */ FALSE,
+/* primary_bus */ 0,
+#ifdef PowerMAX_OS
+/* ppc_io_base */ 0,
+/* ppc_io_size */ 0,
+#endif
+/* funcs */ &ix86Funcs0, /* Set by ix86PciInit() */
+/* pciBusPriv */ NULL,
+/* bridge */ NULL
+};
+
+static Bool
+ix86PciBusCheck(void)
+{
+ PCITAG tag;
+ CARD32 id, class;
+ CARD8 device;
+
+ for (device = 0; device < ix86Pci0.numDevices; device++) {
+ tag = PCI_MAKE_TAG(0, device, 0);
+ id = (*ix86Pci0.funcs->pciReadLong)(tag, PCI_ID_REG);
+
+ if ((CARD16)(id + 1U) <= (CARD16)1UL)
+ continue;
+
+ /* The rest of this is inspired by the Linux kernel */
+ class = (*ix86Pci0.funcs->pciReadLong)(tag, PCI_CLASS_REG);
+
+ /* Ignore revision id and programming interface */
+ switch (class >> 16) {
+ case (PCI_CLASS_PREHISTORIC << 8) | PCI_SUBCLASS_PREHISTORIC_MISC:
+ /* Check for vendors of known buggy chipsets */
+ id &= 0x0000ffff;
+ if ((id == PCI_VENDOR_INTEL) || (id == PCI_VENDOR_COMPAQ))
+ return TRUE;
+ continue;
+
+ case (PCI_CLASS_PREHISTORIC << 8) | PCI_SUBCLASS_PREHISTORIC_VGA:
+ case (PCI_CLASS_DISPLAY << 8) | PCI_SUBCLASS_DISPLAY_VGA:
+ case (PCI_CLASS_BRIDGE << 8) | PCI_SUBCLASS_BRIDGE_HOST:
+ return TRUE;
+
+ default:
+ break;
+ }
+ }
+ return FALSE;
+}
+
+static
+void ix86PciSelectCfgmech(void)
+{
+ static Bool beenhere = FALSE;
+ CARD32 mode1Res1 = 0, mode1Res2 = 0, oldVal1 = 0;
+ CARD8 mode2Res1 = 0, mode2Res2 = 0, oldVal2 = 0;
+ int stages = 0;
+
+ if (beenhere)
+ return; /* Been there, done that */
+
+ beenhere = TRUE;
+
+ /*
+ * Determine if motherboard chipset supports PCI Config Mech 1 or 2
+ * We rely on xf86Info.pciFlags to tell which mechanisms to try....
+ */
+ switch (xf86Info.pciFlags) {
+
+ case PCIOsConfig:
+#ifdef ARCH_PCI_OS_INIT
+ return;
+#endif
+
+ case PCIProbe1:
+ if (!xf86EnableIO())
+ return;
+
+ xf86MsgVerb(X_INFO, 2,
+ "PCI: Probing config type using method 1\n");
+ oldVal1 = inl(PCI_CFGMECH1_ADDRESS_REG);
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2) {
+ ErrorF("Checking config type 1:\n"
+ "\tinitial value of MODE1_ADDR_REG is 0x%08x\n", oldVal1);
+ ErrorF("\tChecking that all bits in mask 0x7f000000 are clear\n");
+ }
+#endif
+
+ /* Assuming config type 1 to start with */
+ if ((oldVal1 & 0x7f000000) == 0) {
+
+ stages |= 0x01;
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2) {
+ ErrorF("\tValue indicates possibly config type 1\n");
+ ErrorF("\tWriting 32-bit value 0x%08x to MODE1_ADDR_REG\n", PCI_EN);
+#if 0
+ ErrorF("\tWriting 8-bit value 0x00 to MODE1_ADDR_REG + 3\n");
+#endif
+ }
+#endif
+
+ ix86Pci0.configMech = PCI_CFG_MECH_1;
+ ix86Pci0.numDevices = PCI_CFGMECH1_MAXDEV;
+ ix86Pci0.funcs = &ix86Funcs1;
+
+ outl(PCI_CFGMECH1_ADDRESS_REG, PCI_EN);
+
+#if 0
+ /*
+ * This seems to cause some Neptune-based PCI machines to switch
+ * from config type 1 to config type 2
+ */
+ outb(PCI_CFGMECH1_ADDRESS_REG + 3, 0);
+#endif
+ mode1Res1 = inl(PCI_CFGMECH1_ADDRESS_REG);
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2) {
+ ErrorF("\tValue read back from MODE1_ADDR_REG is 0x%08x\n",
+ mode1Res1);
+ ErrorF("\tRestoring original contents of MODE1_ADDR_REG\n");
+ }
+#endif
+
+ outl(PCI_CFGMECH1_ADDRESS_REG, oldVal1);
+
+ if (mode1Res1) {
+
+ stages |= 0x02;
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2) {
+ ErrorF("\tValue read back is non-zero, and indicates possible"
+ " config type 1\n");
+ }
+#endif
+
+ if (ix86PciBusCheck()) {
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2)
+ ErrorF("\tBus check Confirms this: ");
+#endif
+
+ xf86MsgVerb(X_INFO, 2, "PCI: Config type is 1\n");
+ xf86MsgVerb(X_INFO, 3,
+ "PCI: stages = 0x%02x, oldVal1 = 0x%08lx, mode1Res1"
+ " = 0x%08lx\n", stages, (unsigned long)oldVal1,
+ (unsigned long)mode1Res1);
+ return;
+ }
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2) {
+ ErrorF("\tBus check fails to confirm this, continuing type 1"
+ " check ...\n");
+ }
+#endif
+
+ }
+
+ stages |= 0x04;
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2) {
+ ErrorF("\tWriting 0xff000001 to MODE1_ADDR_REG\n");
+ }
+#endif
+ outl(PCI_CFGMECH1_ADDRESS_REG, 0xff000001);
+ mode1Res2 = inl(PCI_CFGMECH1_ADDRESS_REG);
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2) {
+ ErrorF("\tValue read back from MODE1_ADDR_REG is 0x%08x\n",
+ mode1Res2);
+ ErrorF("\tRestoring original contents of MODE1_ADDR_REG\n");
+ }
+#endif
+
+ outl(PCI_CFGMECH1_ADDRESS_REG, oldVal1);
+
+ if ((mode1Res2 & 0x80000001) == 0x80000000) {
+
+ stages |= 0x08;
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2) {
+ ErrorF("\tValue read back has only the msb set\n"
+ "\tThis indicates possible config type 1\n");
+ }
+#endif
+
+ if (ix86PciBusCheck()) {
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2)
+ ErrorF("\tBus check Confirms this: ");
+#endif
+
+ xf86MsgVerb(X_INFO, 2, "PCI: Config type is 1\n");
+ xf86MsgVerb(X_INFO, 3,
+ "PCI: stages = 0x%02x, oldVal1 = 0x%08lx,\n"
+ "\tmode1Res1 = 0x%08lx, mode1Res2 = 0x%08lx\n",
+ stages, (unsigned long)oldVal1,
+ (unsigned long)mode1Res1, (unsigned long)mode1Res2);
+ return;
+ }
+
+#ifdef DEBUGPCI
+ if (xf86Verbose > 2) {
+ ErrorF("\tBus check fails to confirm this.\n");
+ }
+#endif
+
+ }
+ }
+
+ xf86MsgVerb(X_INFO, 3, "PCI: Standard check for type 1 failed.\n");
+ xf86MsgVerb(X_INFO, 3, "PCI: stages = 0x%02x, oldVal1 = 0x%08lx,\n"
+ "\tmode1Res1 = 0x%08lx, mode1Res2 = 0x%08lx\n",
+ stages, (unsigned long)oldVal1, (unsigned long)mode1Res1,
+ (unsigned long)mode1Res2);
+
+ /* Try config type 2 */
+ oldVal2 = inb(PCI_CFGMECH2_ENABLE_REG);
+ if ((oldVal2 & 0xf0) == 0) {
+ ix86Pci0.configMech = PCI_CFG_MECH_2;
+ ix86Pci0.numDevices = PCI_CFGMECH2_MAXDEV;
+ ix86Pci0.funcs = &ix86Funcs2;
+
+ outb(PCI_CFGMECH2_ENABLE_REG, 0x0e);
+ mode2Res1 = inb(PCI_CFGMECH2_ENABLE_REG);
+ outb(PCI_CFGMECH2_ENABLE_REG, oldVal2);
+
+ if (mode2Res1 == 0x0e) {
+ if (ix86PciBusCheck()) {
+ xf86MsgVerb(X_INFO, 2, "PCI: Config type is 2\n");
+ return;
+ }
+ }
+ }
+ break; /* } */
+
+ case PCIProbe2: /* { */
+ if (!xf86EnableIO())
+ return;
+
+ /* The scanpci-style detection method */
+
+ xf86MsgVerb(X_INFO, 2, "PCI: Probing config type using method 2\n");
+
+ outb(PCI_CFGMECH2_ENABLE_REG, 0x00);
+ outb(PCI_CFGMECH2_FORWARD_REG, 0x00);
+ mode2Res1 = inb(PCI_CFGMECH2_ENABLE_REG);
+ mode2Res2 = inb(PCI_CFGMECH2_FORWARD_REG);
+
+ if (mode2Res1 == 0 && mode2Res2 == 0) {
+ xf86MsgVerb(X_INFO, 2, "PCI: Config type is 2\n");
+ ix86Pci0.configMech = PCI_CFG_MECH_2;
+ ix86Pci0.numDevices = PCI_CFGMECH2_MAXDEV;
+ ix86Pci0.funcs = &ix86Funcs2;
+ return;
+ }
+
+ oldVal1 = inl(PCI_CFGMECH1_ADDRESS_REG);
+ outl(PCI_CFGMECH1_ADDRESS_REG, PCI_EN);
+ mode1Res1 = inl(PCI_CFGMECH1_ADDRESS_REG);
+ outl(PCI_CFGMECH1_ADDRESS_REG, oldVal1);
+ if (mode1Res1 == PCI_EN) {
+ xf86MsgVerb(X_INFO, 2, "PCI: Config type is 1\n");
+ ix86Pci0.configMech = PCI_CFG_MECH_1;
+ ix86Pci0.numDevices = PCI_CFGMECH1_MAXDEV;
+ ix86Pci0.funcs = &ix86Funcs1;
+ return;
+ }
+ break; /* } */
+
+ case PCIForceConfig1:
+ if (!xf86EnableIO())
+ return;
+
+ xf86MsgVerb(X_INFO, 2, "PCI: Forcing config type 1\n");
+
+ ix86Pci0.configMech = PCI_CFG_MECH_1;
+ ix86Pci0.numDevices = PCI_CFGMECH1_MAXDEV;
+ ix86Pci0.funcs = &ix86Funcs1;
+ return;
+
+ case PCIForceConfig2:
+ if (!xf86EnableIO())
+ return;
+
+ xf86MsgVerb(X_INFO, 2, "PCI: Forcing config type 2\n");
+
+ ix86Pci0.configMech = PCI_CFG_MECH_2;
+ ix86Pci0.numDevices = PCI_CFGMECH2_MAXDEV;
+ ix86Pci0.funcs = &ix86Funcs2;
+ return;
+
+ case PCIForceNone:
+ break;
+ }
+
+ /* No PCI found */
+ ix86Pci0.configMech = PCI_CFG_MECH_UNKNOWN;
+ xf86MsgVerb(X_INFO, 2, "PCI: No PCI bus found or probed for\n");
+}
+
+#if 0
+static pciTagRec
+ix86PcibusTag(CARD8 bus, CARD8 cardnum, CARD8 func)
+{
+ pciTagRec tag;
+
+ tag.cfg1 = 0;
+
+ if (func > 7 || cardnum >= pciBusInfo[bus]->numDevices)
+ return tag;
+
+ switch (ix86Pci0.configMech) {
+ case PCI_CFG_MECH_1:
+ tag.cfg1 = PCI_EN | ((CARD32)bus << 16) |
+ ((CARD32)cardnum << 11) |
+ ((CARD32)func << 8);
+ break;
+
+ case PCI_CFG_MECH_2:
+ tag.cfg2.port = 0xc000 | ((CARD16)cardnum << 8);
+ tag.cfg2.enable = 0xf0 | (func << 1);
+ tag.cfg2.forward = bus;
+ break;
+ }
+
+ return tag;
+}
+#endif
+
+static CARD32
+ix86PciReadLongSetup(PCITAG Tag, int reg)
+{
+ ix86PciSelectCfgmech();
+ return (*ix86Pci0.funcs->pciReadLong)(Tag,reg);
+}
+
+static CARD32
+ix86PciReadLongCFG1(PCITAG Tag, int reg)
+{
+ CARD32 addr, data = 0;
+
+#ifdef DEBUGPCI
+ ErrorF("ix86PciReadLong 0x%lx, %d\n", Tag, reg);
+#endif
+
+ addr = PCI_ADDR_FROM_TAG_CFG1(Tag,reg);
+ outl(PCI_CFGMECH1_ADDRESS_REG, addr);
+ data = inl(PCI_CFGMECH1_DATA_REG);
+ outl(PCI_CFGMECH1_ADDRESS_REG, 0);
+
+#ifdef DEBUGPCI
+ ErrorF("ix86PciReadLong 0x%lx\n", data);
+#endif
+
+ return data;
+}
+
+static CARD32
+ix86PciReadLongCFG2(PCITAG Tag, int reg)
+{
+ CARD32 addr, data = 0;
+ CARD8 forward, enable;
+
+#ifdef DEBUGPCI
+ ErrorF("ix86PciReadLong 0x%lx, %d\n", Tag, reg);
+#endif
+
+ forward = PCI_FORWARD_FROM_TAG(Tag);
+ enable = PCI_ENABLE_FROM_TAG(Tag);
+ addr = PCI_ADDR_FROM_TAG_CFG2(Tag,reg);
+
+ outb(PCI_CFGMECH2_ENABLE_REG, enable);
+ outb(PCI_CFGMECH2_FORWARD_REG, forward);
+ data = inl((CARD16)addr);
+ outb(PCI_CFGMECH2_ENABLE_REG, 0);
+ outb(PCI_CFGMECH2_FORWARD_REG, 0);
+
+#ifdef DEBUGPCI
+ ErrorF("ix86PciReadLong 0x%lx\n", data);
+#endif
+
+ return data;
+}
+
+static void
+ix86PciWriteLongSetup(PCITAG Tag, int reg, CARD32 data)
+{
+ ix86PciSelectCfgmech();
+ (*ix86Pci0.funcs->pciWriteLong)(Tag,reg,data);
+}
+
+static void
+ix86PciWriteLongCFG1(PCITAG Tag, int reg, CARD32 data)
+{
+ CARD32 addr;
+
+ addr = PCI_ADDR_FROM_TAG_CFG1(Tag,reg);
+ outl(PCI_CFGMECH1_ADDRESS_REG, addr);
+ outl(PCI_CFGMECH1_DATA_REG, data);
+ outl(PCI_CFGMECH1_ADDRESS_REG, 0);
+}
+
+static void
+ix86PciWriteLongCFG2(PCITAG Tag, int reg, CARD32 data)
+{
+ CARD32 addr;
+ CARD8 forward, enable;
+
+ forward = PCI_FORWARD_FROM_TAG(Tag);
+ enable = PCI_ENABLE_FROM_TAG(Tag);
+ addr = PCI_ADDR_FROM_TAG_CFG2(Tag,reg);
+
+ outb(PCI_CFGMECH2_ENABLE_REG, enable);
+ outb(PCI_CFGMECH2_FORWARD_REG, forward);
+ outl((CARD16)addr, data);
+ outb(PCI_CFGMECH2_ENABLE_REG, 0);
+ outb(PCI_CFGMECH2_FORWARD_REG, 0);
+}
+
+static void
+ix86PciSetBitsLongSetup(PCITAG Tag, int reg, CARD32 mask, CARD32 val)
+{
+ ix86PciSelectCfgmech();
+ (*ix86Pci0.funcs->pciSetBitsLong)(Tag,reg,mask,val);
+}
+
+static void
+ix86PciSetBitsLongCFG1(PCITAG Tag, int reg, CARD32 mask, CARD32 val)
+{
+ CARD32 addr, data = 0;
+
+#ifdef DEBUGPCI
+ ErrorF("ix86PciSetBitsLong 0x%lx, %d\n", Tag, reg);
+#endif
+
+ addr = PCI_ADDR_FROM_TAG_CFG1(Tag,reg);
+ outl(PCI_CFGMECH1_ADDRESS_REG, addr);
+ data = inl(PCI_CFGMECH1_DATA_REG);
+ data = (data & ~mask) | (val & mask);
+ outl(PCI_CFGMECH1_DATA_REG, data);
+ outl(PCI_CFGMECH1_ADDRESS_REG, 0);
+}
+
+static void
+ix86PciSetBitsLongCFG2(PCITAG Tag, int reg, CARD32 mask, CARD32 val)
+{
+ CARD32 addr, data = 0;
+ CARD8 enable, forward;
+
+#ifdef DEBUGPCI
+ ErrorF("ix86PciSetBitsLong 0x%lx, %d\n", Tag, reg);
+#endif
+
+ forward = PCI_FORWARD_FROM_TAG(Tag);
+ enable = PCI_ENABLE_FROM_TAG(Tag);
+ addr = PCI_ADDR_FROM_TAG_CFG2(Tag,reg);
+
+ outb(PCI_CFGMECH2_ENABLE_REG, enable);
+ outb(PCI_CFGMECH2_FORWARD_REG, forward);
+ data = inl((CARD16)addr);
+ data = (data & ~mask) | (val & mask);
+ outl((CARD16)addr, data);
+ outb(PCI_CFGMECH2_ENABLE_REG, 0);
+ outb(PCI_CFGMECH2_FORWARD_REG, 0);
+}
+
+void
+ix86PciInit()
+{
+ /* Initialize pciBusInfo[] array and function pointers */
+ pciNumBuses = 1;
+ pciBusInfo[0] = &ix86Pci0;
+ pciFindFirstFP = pciGenFindFirst;
+ pciFindNextFP = pciGenFindNext;
+
+ /* Make sure that there is a PCI bus present. */
+ ix86PciSelectCfgmech();
+ if (ix86Pci0.configMech == PCI_CFG_MECH_UNKNOWN) {
+ pciNumBuses = 0;
+ pciBusInfo[0] = NULL;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c
new file mode 100644
index 000000000..40fb4604b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c
@@ -0,0 +1,894 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c,v 1.9 2002/09/24 16:14:16 tsi Exp $ */
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include "compiler.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "Pci.h"
+
+/*
+ * linux platform specific PCI access functions -- using /proc/bus/pci
+ * needs kernel version 2.2.x
+ */
+static CARD32 linuxPciCfgRead(PCITAG tag, int off);
+static void linuxPciCfgWrite(PCITAG, int off, CARD32 val);
+static void linuxPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits);
+static ADDRESS linuxTransAddrBusToHost(PCITAG tag, PciAddrType type, ADDRESS addr);
+#if defined(__powerpc__)
+static ADDRESS linuxPpcBusAddrToHostAddr(PCITAG, PciAddrType, ADDRESS);
+static ADDRESS linuxPpcHostAddrToBusAddr(PCITAG, PciAddrType, ADDRESS);
+#endif
+
+static CARD8 linuxPciCfgReadByte(PCITAG tag, int off);
+static void linuxPciCfgWriteByte(PCITAG tag, int off, CARD8 val);
+static CARD16 linuxPciCfgReadWord(PCITAG tag, int off);
+static void linuxPciCfgWriteWord(PCITAG tag, int off, CARD16 val);
+
+static pciBusFuncs_t linuxFuncs0 = {
+/* pciReadLong */ linuxPciCfgRead,
+/* pciWriteLong */ linuxPciCfgWrite,
+/* pciSetBitsLong */ linuxPciCfgSetBits,
+#if defined(__powerpc__)
+/* pciAddrHostToBus */ linuxPpcHostAddrToBusAddr,
+/* pciAddrBusToHost */ linuxPpcBusAddrToHostAddr,
+#else
+/* pciAddrHostToBus */ pciAddrNOOP,
+/* pciAddrBusToHost */ linuxTransAddrBusToHost,
+#endif
+
+/* pciControlBridge */ NULL,
+/* pciGetBridgeBuses */ NULL,
+/* pciGetBridgeResources */ NULL,
+
+/* pciReadByte */ linuxPciCfgReadByte,
+/* pciWriteByte */ linuxPciCfgWriteByte,
+
+/* pciReadWord */ linuxPciCfgReadWord,
+/* pciWriteWord */ linuxPciCfgWriteWord,
+};
+
+static pciBusInfo_t linuxPci0 = {
+/* configMech */ PCI_CFG_MECH_OTHER,
+/* numDevices */ 32,
+/* secondary */ FALSE,
+/* primary_bus */ 0,
+#ifdef PowerMAX_OS
+/* ppc_io_base */ 0,
+/* ppc_io_size */ 0,
+#endif
+/* funcs */ &linuxFuncs0,
+/* pciBusPriv */ NULL,
+/* bridge */ NULL
+};
+
+void
+linuxPciInit()
+{
+ struct stat st;
+ if ((xf86Info.pciFlags == PCIForceNone) ||
+ (-1 == stat("/proc/bus/pci", &st))) {
+ /* when using this as default for all linux architectures,
+ we'll need a fallback for 2.0 kernels here */
+ return;
+ }
+ pciNumBuses = 1;
+ pciBusInfo[0] = &linuxPci0;
+ pciFindFirstFP = pciGenFindFirst;
+ pciFindNextFP = pciGenFindNext;
+}
+
+static int
+linuxPciOpenFile(PCITAG tag, Bool write)
+{
+ static int lbus,ldev,lfunc,fd = -1,is_write = 0;
+ int bus, dev, func;
+ char file[32];
+ struct stat ignored;
+
+ bus = PCI_BUS_FROM_TAG(tag);
+ dev = PCI_DEV_FROM_TAG(tag);
+ func = PCI_FUNC_FROM_TAG(tag);
+ if (fd == -1 || (write && (!is_write))
+ || bus != lbus || dev != ldev || func != lfunc) {
+ if (fd != -1)
+ close(fd);
+ if (bus < 256) {
+ sprintf(file,"/proc/bus/pci/%02x",bus);
+ if (stat(file, &ignored) < 0)
+ sprintf(file, "/proc/bus/pci/0000:%02x/%02x.%1x",
+ bus, dev, func);
+ else
+ sprintf(file, "/proc/bus/pci/%02x/%02x.%1x",
+ bus, dev, func);
+ } else {
+ sprintf(file,"/proc/bus/pci/%04x",bus);
+ if (stat(file, &ignored) < 0)
+ sprintf(file, "/proc/bus/pci/0000:%04x/%02x.%1x",
+ bus, dev, func);
+ else
+ sprintf(file, "/proc/bus/pci/%04x/%02x.%1x",
+ bus, dev, func);
+ }
+ if (write) {
+ fd = open(file,O_RDWR);
+ if (fd != -1) is_write = TRUE;
+ } else switch (is_write) {
+ case TRUE:
+ fd = open(file,O_RDWR);
+ if (fd > -1)
+ break;
+ default:
+ fd = open(file,O_RDONLY);
+ is_write = FALSE;
+ }
+
+ lbus = bus;
+ ldev = dev;
+ lfunc = func;
+ }
+ return fd;
+}
+
+static CARD32
+linuxPciCfgRead(PCITAG tag, int off)
+{
+ int fd;
+ CARD32 val = 0xffffffff;
+
+ if (-1 != (fd = linuxPciOpenFile(tag,FALSE))) {
+ lseek(fd,off,SEEK_SET);
+ read(fd,&val,4);
+ }
+ return PCI_CPU(val);
+}
+
+static void
+linuxPciCfgWrite(PCITAG tag, int off, CARD32 val)
+{
+ int fd;
+
+ if (-1 != (fd = linuxPciOpenFile(tag,TRUE))) {
+ lseek(fd,off,SEEK_SET);
+ val = PCI_CPU(val);
+ write(fd,&val,4);
+ }
+}
+
+static void
+linuxPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits)
+{
+ int fd;
+ CARD32 val = 0xffffffff;
+
+ if (-1 != (fd = linuxPciOpenFile(tag,TRUE))) {
+ lseek(fd,off,SEEK_SET);
+ read(fd,&val,4);
+ val = PCI_CPU(val);
+ val = (val & ~mask) | (bits & mask);
+ val = PCI_CPU(val);
+ lseek(fd,off,SEEK_SET);
+ write(fd,&val,4);
+ }
+}
+
+/*
+ * This function will convert a BAR address into a host address
+ * suitable for passing into the mmap function of a /proc/bus
+ * device.
+ */
+ADDRESS linuxTransAddrBusToHost(PCITAG tag, PciAddrType type, ADDRESS addr)
+{
+ ADDRESS ret = xf86GetOSOffsetFromPCI(tag, PCI_MEM|PCI_IO, addr);
+
+ if (ret)
+ return ret;
+
+ /*
+ * if it is not a BAR address, it must be legacy, (or wrong)
+ * return it as is..
+ */
+ return addr;
+}
+
+
+#if defined(__powerpc__)
+
+#ifndef __NR_pciconfig_iobase
+#define __NR_pciconfig_iobase 200
+#endif
+
+static ADDRESS
+linuxPpcBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr)
+{
+ if (type == PCI_MEM)
+ {
+ ADDRESS membase = syscall(__NR_pciconfig_iobase, 1,
+ PCI_BUS_FROM_TAG(tag), PCI_DFN_FROM_TAG(tag));
+ return (addr + membase);
+ }
+ else if (type == PCI_IO)
+ {
+ ADDRESS iobase = syscall(__NR_pciconfig_iobase, 2,
+ PCI_BUS_FROM_TAG(tag), PCI_DFN_FROM_TAG(tag));
+ return (addr + iobase);
+ }
+ else return addr;
+}
+
+static ADDRESS
+linuxPpcHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr)
+{
+ if (type == PCI_MEM)
+ {
+ ADDRESS membase = syscall(__NR_pciconfig_iobase, 1,
+ PCI_BUS_FROM_TAG(tag), PCI_DFN_FROM_TAG(tag));
+ return (addr - membase);
+ }
+ else if (type == PCI_IO)
+ {
+ ADDRESS iobase = syscall(__NR_pciconfig_iobase, 2,
+ PCI_BUS_FROM_TAG(tag), PCI_DFN_FROM_TAG(tag));
+ return (addr - iobase);
+ }
+ else return addr;
+}
+
+#endif /* __powerpc__ */
+
+static CARD8
+linuxPciCfgReadByte(PCITAG tag, int off)
+{
+ int fd;
+ CARD8 val = 0xff;
+
+ if (-1 != (fd = linuxPciOpenFile(tag,FALSE))) {
+ lseek(fd,off,SEEK_SET);
+ read(fd,&val,1);
+ }
+
+ return val;
+}
+
+static void
+linuxPciCfgWriteByte(PCITAG tag, int off, CARD8 val)
+{
+ int fd;
+
+ if (-1 != (fd = linuxPciOpenFile(tag,TRUE))) {
+ lseek(fd,off,SEEK_SET);
+ write(fd, &val, 1);
+ }
+}
+
+static CARD16
+linuxPciCfgReadWord(PCITAG tag, int off)
+{
+ int fd;
+ CARD16 val = 0xff;
+
+ if (-1 != (fd = linuxPciOpenFile(tag,FALSE))) {
+ lseek(fd, off, SEEK_SET);
+ read(fd, &val, 2);
+ }
+
+ return PCI_CPU16(val);
+}
+
+static void
+linuxPciCfgWriteWord(PCITAG tag, int off, CARD16 val)
+{
+ int fd;
+
+ if (-1 != (fd = linuxPciOpenFile(tag,TRUE))) {
+ lseek(fd, off, SEEK_SET);
+ val = PCI_CPU16(val);
+ write(fd, &val, 2);
+ }
+}
+
+#ifndef INCLUDE_XF86_NO_DOMAIN
+
+/*
+ * Compiling the following simply requires the presence of <linux/pci.c>.
+ * Actually running this is another matter altogether...
+ *
+ * This scheme requires that the kernel allow mmap()'ing of a host bridge's I/O
+ * and memory spaces through its /proc/bus/pci/BUS/DFN entry. Which one is
+ * determined by a prior ioctl().
+ *
+ * For the sparc64 port, this means 2.4.12 or later. For ppc, this
+ * functionality is almost, but not quite there yet. Alpha and other kernel
+ * ports to multi-domain architectures still need to implement this.
+ *
+ * This scheme is also predicated on the use of an IOADDRESS compatible type to
+ * designate I/O addresses. Although IOADDRESS is defined as an unsigned
+ * integral type, it is actually the virtual address of, i.e. a pointer to, the
+ * I/O port to access. And so, the inX/outX macros in "compiler.h" need to be
+ * #define'd appropriately (as is done on SPARC's).
+ *
+ * Another requirement to port this scheme to another multi-domain architecture
+ * is to add the appropriate entries in the pciControllerSizes array below.
+ *
+ * TO DO: Address the deleterious reaction some host bridges have to master
+ * aborts. This is already done for secondary PCI buses, but not yet
+ * for accesses to primary buses (except for the SPARC port, where
+ * master aborts are avoided during PCI scans).
+ */
+
+#include <linux/pci.h>
+
+#ifndef PCIIOC_BASE /* Ioctls for /proc/bus/pci/X/Y nodes. */
+#define PCIIOC_BASE ('P' << 24 | 'C' << 16 | 'I' << 8)
+
+/* Get controller for PCI device. */
+#define PCIIOC_CONTROLLER (PCIIOC_BASE | 0x00)
+/* Set mmap state to I/O space. */
+#define PCIIOC_MMAP_IS_IO (PCIIOC_BASE | 0x01)
+/* Set mmap state to MEM space. */
+#define PCIIOC_MMAP_IS_MEM (PCIIOC_BASE | 0x02)
+/* Enable/disable write-combining. */
+#define PCIIOC_WRITE_COMBINE (PCIIOC_BASE | 0x03)
+
+#endif
+
+/* This probably shouldn't be Linux-specific */
+static pciConfigPtr
+xf86GetPciHostConfigFromTag(PCITAG Tag)
+{
+ int bus = PCI_BUS_FROM_TAG(Tag);
+ pciBusInfo_t *pBusInfo;
+
+ while ((bus < pciNumBuses) && (pBusInfo = pciBusInfo[bus])) {
+ if (bus == pBusInfo->primary_bus)
+ return pBusInfo->bridge;
+ bus = pBusInfo->primary_bus;
+ }
+
+ return NULL; /* Bad data */
+}
+
+/*
+ * This is ugly, but until I can extract this information from the kernel,
+ * it'll have to do. The default I/O space size is 64K, and 4G for memory.
+ * Anything else needs to go in this table. (PowerPC folk take note.)
+ *
+ * Note that Linux/SPARC userland is 32-bit, so 4G overflows to zero here.
+ *
+ * Please keep this table in ascending vendor/device order.
+ */
+static struct pciSizes {
+ unsigned short vendor, device;
+ unsigned long io_size, mem_size;
+} pciControllerSizes[] = {
+ {
+ PCI_VENDOR_SUN, PCI_CHIP_PSYCHO,
+ 1U << 16, 1U << 31
+ },
+ {
+ PCI_VENDOR_SUN, PCI_CHIP_SCHIZO,
+ 1U << 24, 1U << 31 /* ??? */
+ },
+ {
+ PCI_VENDOR_SUN, PCI_CHIP_SABRE,
+ 1U << 24, (unsigned long)(1ULL << 32)
+ },
+ {
+ PCI_VENDOR_SUN, PCI_CHIP_HUMMINGBIRD,
+ 1U << 24, (unsigned long)(1ULL << 32)
+ }
+};
+#define NUM_SIZES (sizeof(pciControllerSizes) / sizeof(pciControllerSizes[0]))
+
+static unsigned long
+linuxGetIOSize(PCITAG Tag)
+{
+ pciConfigPtr pPCI;
+ int i;
+
+ /* Find host bridge */
+ if ((pPCI = xf86GetPciHostConfigFromTag(Tag))) {
+ /* Look up vendor/device */
+ for (i = 0; i < NUM_SIZES; i++) {
+ if (pPCI->pci_vendor > pciControllerSizes[i].vendor)
+ continue;
+ if (pPCI->pci_vendor < pciControllerSizes[i].vendor)
+ break;
+ if (pPCI->pci_device > pciControllerSizes[i].device)
+ continue;
+ if (pPCI->pci_device < pciControllerSizes[i].device)
+ break;
+ return pciControllerSizes[i].io_size;
+ }
+ }
+
+ return 1U << 16; /* Default to 64K */
+}
+
+static void
+linuxGetSizes(PCITAG Tag, unsigned long *io_size, unsigned long *mem_size)
+{
+ pciConfigPtr pPCI;
+ int i;
+
+ *io_size = (1U << 16); /* Default to 64K */
+ *mem_size = (unsigned long)(1ULL << 32); /* Default to 4G */
+
+ /* Find host bridge */
+ if ((pPCI = xf86GetPciHostConfigFromTag(Tag))) {
+ /* Look up vendor/device */
+ for (i = 0; i < NUM_SIZES; i++) {
+ if (pPCI->pci_vendor > pciControllerSizes[i].vendor)
+ continue;
+ if (pPCI->pci_vendor < pciControllerSizes[i].vendor)
+ break;
+ if (pPCI->pci_device > pciControllerSizes[i].device)
+ continue;
+ if (pPCI->pci_device < pciControllerSizes[i].device)
+ break;
+ *io_size = pciControllerSizes[i].io_size;
+ *mem_size = pciControllerSizes[i].mem_size;
+ break;
+ }
+ }
+}
+
+int
+xf86GetPciDomain(PCITAG Tag)
+{
+ pciConfigPtr pPCI;
+ int fd, result;
+
+ pPCI = xf86GetPciHostConfigFromTag(Tag);
+
+ if (pPCI && (result = PCI_DOM_FROM_BUS(pPCI->busnum)))
+ return result;
+
+ if (!pPCI || pPCI->fakeDevice)
+ return 1; /* Domain 0 is reserved */
+
+ if ((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0)
+ return 0;
+
+ if ((result = ioctl(fd, PCIIOC_CONTROLLER, 0)) < 0)
+ return 0;
+
+ return result + 1; /* Domain 0 is reserved */
+}
+
+static pointer
+linuxMapPci(int ScreenNum, int Flags, PCITAG Tag,
+ ADDRESS Base, unsigned long Size, int mmap_ioctl)
+{
+ do {
+ pciConfigPtr pPCI;
+ unsigned char *result;
+ ADDRESS realBase, Offset;
+ int fd, mmapflags, prot;
+
+ xf86InitVidMem();
+
+ pPCI = xf86GetPciHostConfigFromTag(Tag);
+
+ if (((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0) ||
+ (ioctl(fd, mmap_ioctl, 0) < 0))
+ break;
+
+/* Note: IA-64 doesn't compile this and doesn't need to */
+#ifdef __ia64__
+
+# ifndef MAP_WRITECOMBINED
+# define MAP_WRITECOMBINED 0x00010000
+# endif
+# ifndef MAP_NONCACHED
+# define MAP_NONCACHED 0x00020000
+# endif
+
+ if (Flags & VIDMEM_FRAMEBUFFER)
+ mmapflags = MAP_SHARED | MAP_WRITECOMBINED;
+ else
+ mmapflags = MAP_SHARED | MAP_NONCACHED;
+
+#else /* !__ia64__ */
+
+ mmapflags = (Flags & VIDMEM_FRAMEBUFFER) / VIDMEM_FRAMEBUFFER;
+
+ if (ioctl(fd, PCIIOC_WRITE_COMBINE, mmapflags) < 0)
+ break;
+
+ mmapflags = MAP_SHARED;
+
+#endif /* ?__ia64__ */
+
+ /* Align to page boundary */
+ realBase = Base & ~(getpagesize() - 1);
+ Offset = Base - realBase;
+
+ if (Flags & VIDMEM_READONLY)
+ prot = PROT_READ;
+ else
+ prot = PROT_READ | PROT_WRITE;
+
+ result = mmap(NULL, Size + Offset, prot, mmapflags, fd, realBase);
+
+ if (!result || ((pointer)result == MAP_FAILED))
+ return NULL;
+
+ xf86MakeNewMapping(ScreenNum, Flags, realBase, Size + Offset, result);
+
+ return result + Offset;
+ } while (0);
+
+ if (mmap_ioctl == PCIIOC_MMAP_IS_MEM)
+ return xf86MapVidMem(ScreenNum, Flags, Base, Size);
+
+ return NULL;
+}
+
+#define MAX_DOMAINS 257
+static pointer DomainMmappedIO[MAX_DOMAINS];
+static pointer DomainMmappedMem[MAX_DOMAINS];
+
+static int
+linuxOpenLegacy(PCITAG Tag, char *name)
+{
+#define PREFIX "/sys/class/pci_bus/%04x:%02x/%s"
+ char *path;
+ int domain, bus;
+ pciBusInfo_t *pBusInfo;
+ pciConfigPtr bridge = NULL;
+ int fd;
+
+ path = xalloc(strlen(PREFIX) + strlen(name));
+ if (!path)
+ return -1;
+
+ for (;;) {
+ domain = xf86GetPciDomain(Tag);
+ bus = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
+
+ /* Domain 0 is reserved -- see xf86GetPciDomain() */
+ if ((domain <= 0) || (domain >= MAX_DOMAINS))
+ FatalError("linuxOpenLegacy(): domain out of range\n");
+
+ sprintf(path, PREFIX, domain - 1, bus, name);
+ fd = open(path, O_RDWR);
+ if (fd >= 0) {
+ xfree(path);
+ return fd;
+ }
+
+ pBusInfo = pciBusInfo[bus];
+ if (!pBusInfo || (bridge == pBusInfo->bridge) ||
+ !(bridge = pBusInfo->bridge)) {
+ xfree(path);
+ return -1;
+ }
+
+ Tag = bridge->tag;
+ }
+
+ xfree(path);
+ return fd;
+}
+
+/*
+ * xf86MapDomainMemory - memory map PCI domain memory
+ *
+ * This routine maps the memory region in the domain specified by Tag and
+ * returns a pointer to it. The pointer is saved for future use if it's in
+ * the legacy ISA memory space (memory in a domain between 0 and 1MB).
+ */
+pointer
+xf86MapDomainMemory(int ScreenNum, int Flags, PCITAG Tag,
+ ADDRESS Base, unsigned long Size)
+{
+ int domain = xf86GetPciDomain(Tag);
+ int fd;
+
+ /*
+ * We use /proc/bus/pci on non-legacy addresses or if the Linux sysfs
+ * legacy_mem interface is unavailable.
+ */
+ if (Base > 1024*1024)
+ return linuxMapPci(ScreenNum, Flags, Tag, Base, Size,
+ PCIIOC_MMAP_IS_MEM);
+
+ if ((fd = linuxOpenLegacy(Tag, "legacy_mem")) < 0)
+ return linuxMapPci(ScreenNum, Flags, Tag, Base, Size,
+ PCIIOC_MMAP_IS_MEM);
+
+
+ /* If we haven't already mapped this legacy space, try to. */
+ if (!DomainMmappedMem[domain]) {
+ DomainMmappedMem[domain] = mmap(NULL, 1024*1024, PROT_READ|PROT_WRITE,
+ MAP_SHARED, fd, 0);
+ if (DomainMmappedMem[domain] == MAP_FAILED) {
+ close(fd);
+ perror("mmap failure");
+ FatalError("xf86MapDomainMem(): mmap() failure\n");
+ }
+ }
+
+ close(fd);
+ return (pointer)((char *)DomainMmappedMem[domain] + Base);
+}
+
+/*
+ * xf86MapDomainIO - map I/O space in this domain
+ *
+ * Each domain has a legacy ISA I/O space. This routine will try to
+ * map it using the Linux sysfs legacy_io interface. If that fails,
+ * it'll fall back to using /proc/bus/pci.
+ *
+ * If the legacy_io interface *does* exist, the file descriptor (fd below)
+ * will be saved in the DomainMmappedIO array in the upper bits of the
+ * pointer. Callers will do I/O with small port numbers (<64k values), so
+ * the platform I/O code can extract the port number and the fd, lseek to
+ * the port number in the legacy_io file, and issue the read or write.
+ *
+ * This has no means of returning failure, so all errors are fatal
+ */
+IOADDRESS
+xf86MapDomainIO(int ScreenNum, int Flags, PCITAG Tag,
+ IOADDRESS Base, unsigned long Size)
+{
+ int domain = xf86GetPciDomain(Tag);
+ int fd;
+
+ if ((domain <= 0) || (domain >= MAX_DOMAINS))
+ FatalError("xf86MapDomainIO(): domain out of range\n");
+
+ if (DomainMmappedIO[domain])
+ return (IOADDRESS)DomainMmappedIO[domain] + Base;
+
+ /* Permanently map all of I/O space */
+ if ((fd = linuxOpenLegacy(Tag, "legacy_io")) < 0) {
+ DomainMmappedIO[domain] = linuxMapPci(ScreenNum, Flags, Tag,
+ 0, linuxGetIOSize(Tag),
+ PCIIOC_MMAP_IS_IO);
+ /* ia64 can't mmap legacy IO port space */
+ if (!DomainMmappedIO[domain])
+ return Base;
+ }
+ else { /* legacy_io file exists, encode fd */
+ DomainMmappedIO[domain] = (pointer)(fd << 24);
+ }
+
+ return (IOADDRESS)DomainMmappedIO[domain] + Base;
+}
+
+/*
+ * xf86ReadDomainMemory - copy from domain memory into a caller supplied buffer
+ */
+int
+xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
+{
+ unsigned char *ptr, *src;
+ ADDRESS offset;
+ unsigned long size;
+ int len, pagemask = getpagesize() - 1;
+
+ unsigned int i, dom, bus, dev, func;
+ unsigned int fd;
+ char file[256];
+ struct stat st;
+
+ dom = PCI_DOM_FROM_TAG(Tag);
+ bus = PCI_BUS_FROM_TAG(Tag);
+ dev = PCI_DEV_FROM_TAG(Tag);
+ func = PCI_FUNC_FROM_TAG(Tag);
+ sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
+ dom, bus, dom, bus, dev, func);
+
+ /*
+ * If the caller wants the ROM and the sysfs rom interface exists,
+ * try to use it instead of reading it from /proc/bus/pci.
+ */
+ if (((Base & 0xfffff) == 0xC0000) && (stat(file, &st) == 0)) {
+ if ((fd = open(file, O_RDWR)))
+ Base = 0x0;
+
+ /* enable the ROM first */
+ write(fd, "1", 2);
+ lseek(fd, 0, SEEK_SET);
+
+ /* copy the ROM until we hit Len, EOF or read error */
+ for (i = 0; i < Len && read(fd, Buf, 1) > 0; Buf++, i++)
+ ;
+
+ write(fd, "0", 2);
+ close(fd);
+
+ return Len;
+ }
+
+ /* Ensure page boundaries */
+ offset = Base & ~pagemask;
+ size = ((Base + Len + pagemask) & ~pagemask) - offset;
+
+ ptr = xf86MapDomainMemory(-1, VIDMEM_READONLY, Tag, offset, size);
+
+ if (!ptr)
+ return -1;
+
+ /* Using memcpy() here can hang the system */
+ src = ptr + (Base - offset);
+ for (len = Len; len-- > 0;)
+ *Buf++ = *src++;
+
+ xf86UnMapVidMem(-1, ptr, size);
+
+ return Len;
+}
+
+resPtr
+xf86BusAccWindowsFromOS(void)
+{
+ pciConfigPtr *ppPCI, pPCI;
+ resPtr pRes = NULL;
+ resRange range;
+ unsigned long io_size, mem_size;
+ int domain;
+
+ if ((ppPCI = xf86scanpci(0))) {
+ for (; (pPCI = *ppPCI); ppPCI++) {
+ if ((pPCI->pci_base_class != PCI_CLASS_BRIDGE) ||
+ (pPCI->pci_sub_class != PCI_SUBCLASS_BRIDGE_HOST))
+ continue;
+
+ domain = xf86GetPciDomain(pPCI->tag);
+ linuxGetSizes(pPCI->tag, &io_size, &mem_size);
+
+ RANGE(range, 0, (ADDRESS)(mem_size - 1),
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ RANGE(range, 0, (IOADDRESS)(io_size - 1),
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ if (domain <= 0)
+ break;
+ }
+ }
+
+ return pRes;
+}
+
+resPtr
+xf86PciBusAccWindowsFromOS(void)
+{
+ pciConfigPtr *ppPCI, pPCI;
+ resPtr pRes = NULL;
+ resRange range;
+ unsigned long io_size, mem_size;
+ int domain;
+
+ if ((ppPCI = xf86scanpci(0))) {
+ for (; (pPCI = *ppPCI); ppPCI++) {
+ if ((pPCI->pci_base_class != PCI_CLASS_BRIDGE) ||
+ (pPCI->pci_sub_class != PCI_SUBCLASS_BRIDGE_HOST))
+ continue;
+
+ domain = xf86GetPciDomain(pPCI->tag);
+ linuxGetSizes(pPCI->tag, &io_size, &mem_size);
+
+ RANGE(range, 0, (ADDRESS)(mem_size - 1),
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ RANGE(range, 0, (IOADDRESS)(io_size - 1),
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ if (domain <= 0)
+ break;
+ }
+ }
+
+ return pRes;
+}
+
+
+resPtr
+xf86AccResFromOS(resPtr pRes)
+{
+ pciConfigPtr *ppPCI, pPCI;
+ resRange range;
+ unsigned long io_size, mem_size;
+ int domain;
+
+ if ((ppPCI = xf86scanpci(0))) {
+ for (; (pPCI = *ppPCI); ppPCI++) {
+ if ((pPCI->pci_base_class != PCI_CLASS_BRIDGE) ||
+ (pPCI->pci_sub_class != PCI_SUBCLASS_BRIDGE_HOST))
+ continue;
+
+ domain = xf86GetPciDomain(pPCI->tag);
+ linuxGetSizes(pPCI->tag, &io_size, &mem_size);
+
+ /*
+ * At minimum, the top and bottom resources must be claimed, so
+ * that resources that are (or appear to be) unallocated can be
+ * relocated.
+ */
+ RANGE(range, 0x00000000u, 0x0009ffffu,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ RANGE(range, 0x000c0000u, 0x000effffu,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ RANGE(range, 0x000f0000u, 0x000fffffu,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ RANGE(range, (ADDRESS)(mem_size - 1), (ADDRESS)(mem_size - 1),
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ RANGE(range, 0x00000000u, 0x00000000u,
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ RANGE(range, (IOADDRESS)(io_size - 1), (IOADDRESS)(io_size - 1),
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ if (domain <= 0)
+ break;
+ }
+ }
+
+ return pRes;
+}
+
+#endif /* !INCLUDE_XF86_NO_DOMAIN */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/netbsdPci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/netbsdPci.c
new file mode 100644
index 000000000..7dbbfdec7
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/netbsdPci.c
@@ -0,0 +1,132 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/netbsdPci.c,v 1.4 2003/08/24 17:37:04 dawes Exp $ */
+/*
+ * Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, 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 XFREE86 PROJECT 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 XFree86 Project
+ * 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 XFree86 Project.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <dev/pci/pciio.h>
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86OSpriv.h"
+
+#include "Pci.h"
+
+static CARD32 netbsdPciConfRead(PCITAG, int);
+static void netbsdPciConfWrite(PCITAG, int, CARD32);
+static void netbsdPciSetBits(PCITAG, int, CARD32, CARD32);
+
+static int devpci = -1;
+
+static pciBusFuncs_t netbsdFuncs0 = {
+/* pciReadLong */ netbsdPciConfRead,
+/* pciWriteLong */ netbsdPciConfWrite,
+/* pciSetBitsLong */ netbsdPciSetBits,
+/* pciAddrHostToBus */ pciAddrNOOP,
+/* pciAddrBusToHost */ pciAddrNOOP
+};
+
+static pciBusInfo_t netbsdPci0 = {
+/* configMech */ PCI_CFG_MECH_OTHER,
+/* numDevices */ 32,
+/* secondary */ FALSE,
+/* primary_bus */ 0,
+/* funcs */ &netbsdFuncs0,
+/* pciBusPriv */ NULL,
+/* bridge */ NULL
+};
+
+void
+netbsdPciInit()
+{
+ struct pciio_businfo pci_businfo;
+
+ devpci = open("/dev/pci0", O_RDWR);
+ if (devpci == -1)
+ FatalError("netbsdPciInit: can't open /dev/pci0\n");
+
+ pciNumBuses = 1;
+ pciBusInfo[0] = &netbsdPci0;
+ pciFindFirstFP = pciGenFindFirst;
+ pciFindNextFP = pciGenFindNext;
+ /* use businfo to get the number of devs */
+ if (ioctl(devpci, PCI_IOC_BUSINFO, &pci_businfo) != 0)
+ FatalError("netbsdPciInit: not a PCI bus device");
+ netbsdPci0.numDevices = pci_businfo.maxdevs;
+}
+
+static CARD32
+netbsdPciConfRead(PCITAG tag, int reg)
+{
+ struct pciio_bdf_cfgreg bdfr;
+
+ bdfr.bus = PCI_BUS_FROM_TAG(tag);
+ bdfr.device = PCI_DEV_FROM_TAG(tag);
+ bdfr.function = PCI_FUNC_FROM_TAG(tag);
+ bdfr.cfgreg.reg = reg;
+
+ if (ioctl(devpci, PCI_IOC_BDF_CFGREAD, &bdfr) == -1)
+ FatalError("netbsdPciConfRead: failed on %d/%d/%d\n",
+ bdfr.bus, bdfr.device, bdfr.function);
+
+ return (bdfr.cfgreg.val);
+}
+
+static void
+netbsdPciConfWrite(PCITAG tag, int reg, CARD32 val)
+{
+ struct pciio_bdf_cfgreg bdfr;
+
+ bdfr.bus = PCI_BUS_FROM_TAG(tag);
+ bdfr.device = PCI_DEV_FROM_TAG(tag);
+ bdfr.function = PCI_FUNC_FROM_TAG(tag);
+ bdfr.cfgreg.reg = reg;
+ bdfr.cfgreg.val = val;
+
+ if (ioctl(devpci, PCI_IOC_BDF_CFGWRITE, &bdfr) == -1)
+ FatalError("netbsdPciConfWrite: failed on %d/%d/%d\n",
+ bdfr.bus, bdfr.device, bdfr.function);
+}
+
+static void
+netbsdPciSetBits(PCITAG tag, int reg, CARD32 mask, CARD32 bits)
+{
+ CARD32 val;
+
+ val = netbsdPciConfRead(tag, reg);
+ val = (val & ~mask) | (bits & mask);
+ netbsdPciConfWrite(tag, reg, val);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c
new file mode 100644
index 000000000..7a438af67
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c
@@ -0,0 +1,311 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c,v 1.8 2002/07/24 19:06:52 tsi Exp $ */
+/*
+ * ppcPci.c - PowerPC PCI access functions
+ *
+ * PCI driver functions supporting Motorola PowerPC platforms
+ * including Powerstack(RiscPC/RiscPC+), PowerStackII, MTX, and
+ * MVME 160x/260x/360x/460x VME boards
+ *
+ * Gary Barton
+ * Concurrent Computer Corporation
+ * garyb@gate.net
+ *
+ */
+
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include "compiler.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "Pci.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED (pointer)(-1)
+#endif
+
+void
+ppcPciInit()
+{
+#if defined(PowerMAX_OS)
+ extern void pmaxPciInit(void);
+
+ pmaxPciInit();
+
+#else
+
+ static void motoppcPciInit(void);
+ motoppcPciInit();
+
+#endif
+}
+
+#if defined(PowerMAX_OS)
+
+/*
+ * Motorola PowerPC platform support
+ *
+ * The following code should support the MVME 1600 & 2600 VME boards
+ * as well as the various PowerStack and RiscPC models. All of these
+ * machines support PCI config mechanism #1 and use the std config
+ * address and data regs locations:
+ * cfg address reg = 0xcf8 (PCI I/O)
+ * cfg data reg = 0xcfc (PCI I/O)
+ *
+ * The moto machines do have different address maps on either side
+ * of the PCI-host bridge though.
+ */
+static ADDRESS motoppcBusAddrToHostAddr(PCITAG, PciAddrType, ADDRESS);
+static ADDRESS motoppcHostAddrToBusAddr(PCITAG, PciAddrType, ADDRESS);
+static CARD32 pciCfgMech1Read(PCITAG tag, int offset);
+static void pciCfgMech1Write(PCITAG tag, int offset, CARD32 val);
+static void pciCfgMech1SetBits(PCITAG tag, int offset,
+ CARD32 mask, CARD32 val);
+
+
+static pciBusFuncs_t motoppcFuncs0 = {
+/* pciReadLong */ pciCfgMech1Read,
+/* pciWriteLong */ pciCfgMech1Write,
+/* pciSetBitsLong */ pciCfgMech1SetBits,
+/* pciAddrHostToBus */ motoppcHostAddrToBusAddr,
+/* pciAddrBusToHost */ motoppcBusAddrToHostAddr
+};
+
+static pciBusInfo_t motoppcPci0 = {
+/* configMech */ PCI_CFG_MECH_1,
+/* numDevices */ 32,
+/* secondary */ FALSE,
+/* primary_bus */ 0,
+#ifdef PowerMAX_OS
+/* ppc_io_base */ 0x80000000,
+/* ppc_io_size */ 64 * 1024,
+#endif
+/* funcs */ &motoppcFuncs0,
+/* pciBusPriv */ NULL,
+/* bridge */ NULL
+};
+
+extern volatile unsigned char *ioBase;
+
+static void
+motoppcPciInit()
+{
+ pciNumBuses = 1;
+ pciBusInfo[0] = &motoppcPci0;
+ pciFindFirstFP = pciGenFindFirst;
+ pciFindNextFP = pciGenFindNext;
+
+ if (!xf86EnableIO())
+ FatalError("motoppcPciInit: EnableIO failed\n");
+
+ if (ioBase == MAP_FAILED) {
+ ppcPciIoMap(0); /* Make inb/outb et al work for pci0 and its secondaries */
+
+ if (ioBase == MAP_FAILED) {
+ FatalError("motoppcPciInit: Cannot map pci0 I/O segment!!!\n");
+ /*NOTREACHED*/
+ }
+ }
+}
+
+extern unsigned long motoPciMemBase = 0;
+
+#if defined(Lynx) && defined(__powerpc__)
+extern unsigned long motoPciMemLen = 0x40000000;
+#else
+extern unsigned long motoPciMemLen = 0x3f000000;
+#endif
+
+extern unsigned long motoPciMemBaseCPU = 0xc0000000;
+
+static ADDRESS
+motoppcBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr)
+{
+ unsigned long addr_l = (unsigned long)addr;
+
+ if (type == PCI_MEM) {
+ if (addr_l >= motoPciMemBase && addr_l < motoPciMemLen)
+ /*
+ * PCI memory space addresses [0-0x3effffff] are
+ * are seen at [0xc0000000,0xfeffffff] on moto host
+ */
+ return((ADDRESS)((motoPciMemBaseCPU - motoPciMemBase) + addr_l));
+
+ else if (addr_l >= 0x80000000)
+ /*
+ * Moto host memory [0,0x7fffffff] is seen at
+ * [0x80000000,0xffffffff] on PCI bus
+ */
+ return((ADDRESS)(addr_l & 0x7fffffff));
+ else
+ FatalError("motoppcBusAddrToHostAddr: PCI addr 0x%x is not accessible to host!!!\n",
+ addr_l);
+ } else
+ return addr;
+
+ /*NOTREACHED*/
+}
+
+static ADDRESS
+motoppcHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr)
+{
+ unsigned long addr_l = (unsigned long)addr;
+
+ if (type == PCI_MEM) {
+ if (addr_l < 0x80000000)
+ /*
+ * Moto host memory [0,0x7fffffff] is seen at
+ * [0x80000000,0xffffffff] on PCI bus
+ */
+ return((ADDRESS)(0x80000000 | addr_l));
+
+ else if (addr_l >= motoPciMemBaseCPU && addr_l < motoPciMemBaseCPU + motoPciMemLen)
+ /*
+ * PCI memory space addresses [0-0x3effffff] are
+ * are seen at [0xc0000000,0xfeffffff] on moto host
+ */
+ return((ADDRESS)(addr_l - (motoPciMemBaseCPU - motoPciMemBase)));
+
+ else
+ FatalError("motoppcHostAddrToBusAddr: Host addr 0x%x is not accessible to PCI!!!\n",
+ addr_l);
+ } else
+ return addr;
+
+ /*NOTREACHED*/
+}
+
+#if defined (__powerpc__)
+static int buserr_detected;
+
+static
+void buserr(int sig)
+{
+ buserr_detected = 1;
+}
+#endif
+
+static CARD32
+pciCfgMech1Read(PCITAG tag, int offset)
+{
+ unsigned long rv = 0xffffffff;
+#ifdef DEBUGPCI
+ ErrorF("pciCfgMech1Read(tag=%08x,offset=%08x)\n", tag, offset);
+#endif
+
+#if defined(__powerpc__)
+ signal(SIGBUS, buserr);
+ buserr_detected = 0;
+#endif
+
+ outl(0xCF8, PCI_EN | tag | (offset & 0xfc));
+ rv = inl(0xCFC);
+
+#if defined(__powerpc__)
+ signal(SIGBUS, SIG_DFL);
+ if (buserr_detected)
+ {
+#ifdef DEBUGPCI
+ ErrorF("pciCfgMech1Read() BUS ERROR\n");
+#endif
+ return(0xffffffff);
+ }
+ else
+#endif
+ return(rv);
+}
+
+static void
+pciCfgMech1Write(PCITAG tag, int offset, CARD32 val)
+{
+#ifdef DEBUGPCI
+ ErrorF("pciCfgMech1Write(tag=%08x,offset=%08x,val=%08x)\n",
+ tag, offset,val);
+#endif
+
+#if defined(__powerpc__)
+ signal(SIGBUS, SIG_IGN);
+#endif
+
+ outl(0xCF8, PCI_EN | tag | (offset & 0xfc));
+#if defined(Lynx) && defined(__powerpc__)
+ outb(0x80, 0x00); /* without this the next access fails
+ * on my Powerstack system when we use
+ * assembler inlines for outl */
+#endif
+ outl(0xCFC, val);
+
+#if defined(__powerpc__)
+ signal(SIGBUS, SIG_DFL);
+#endif
+}
+
+static void
+pciCfgMech1SetBits(PCITAG tag, int offset, CARD32 mask, CARD32 val)
+{
+ unsigned long rv = 0xffffffff;
+
+#if defined(__powerpc__)
+ signal(SIGBUS, buserr);
+#endif
+
+ outl(0xCF8, PCI_EN | tag | (offset & 0xfc));
+ rv = inl(0xCFC);
+ rv = (rv & ~mask) | val;
+ outl(0xCFC, rv);
+
+#if defined(__powerpc__)
+ signal(SIGBUS, SIG_DFL);
+#endif
+}
+
+#endif /* PowerMAX_OS */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/sparcPci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/sparcPci.c
new file mode 100644
index 000000000..48e10ede4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/sparcPci.c
@@ -0,0 +1,1052 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/sparcPci.c,v 1.14 2003/08/24 17:37:04 dawes Exp $ */
+/*
+ * Copyright (C) 2001-2003 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, 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
+ * XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "Pci.h"
+#include "xf86sbusBus.h"
+
+#if defined(sun)
+
+extern char *apertureDevName;
+static int apertureFd = -1;
+
+/*
+ * A version of xf86MapVidMem() that allows for 64-bit displacements (but not
+ * sizes). Areas thus mapped can be unmapped by xf86UnMapVidMem().
+ */
+static pointer
+sparcMapAperture(int iScreen, int Flags,
+ unsigned long long Base, unsigned long Size)
+{
+ pointer result;
+ static int lastFlags = 0;
+
+ /* Assume both Base & Size are multiples of the page size */
+
+ if ((apertureFd < 0) || (Flags != lastFlags)) {
+ if (apertureFd >= 0)
+ close(apertureFd);
+ lastFlags = Flags;
+ apertureFd = open(apertureDevName,
+ (Flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
+ if (apertureFd < 0)
+ FatalError("sparcMapAperture: open failure: %s\n",
+ strerror(errno));
+ }
+
+ result = mmap(NULL, Size,
+ (Flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, apertureFd, (off_t)Base);
+
+ if (result == MAP_FAILED)
+ FatalError("sparcMapAperture: mmap failure: %s\n", strerror(errno));
+
+ return result;
+}
+
+/*
+ * Platform-specific bus privates.
+ */
+typedef struct _sparcDomainRec {
+ unsigned long long io_addr, io_size;
+ unsigned long long mem_addr, mem_size;
+ pointer pci, io;
+ int bus_min, bus_max;
+ unsigned char dfn_mask[256 / 8];
+} sparcDomainRec, *sparcDomainPtr;
+
+#define SetBitInMap(bit, map) \
+ do { \
+ int _bit = (bit); \
+ (map)[_bit >> 3] |= 1 << (_bit & 7); \
+ } while (0)
+
+#define IsBitSetInMap(bit, map) \
+ ((map)[(bit) >> 3] & (1 << ((bit) & 7)))
+
+/*
+ * Domain 0 is reserved for the one that represents the system as a whole, i.e.
+ * the one without any resource relocations.
+ */
+#define MAX_DOMAINS (MAX_PCI_BUSES / 256)
+static sparcDomainPtr xf86DomainInfo[MAX_DOMAINS];
+static int pciNumDomains = 1;
+
+/* Variables that are assigned this must be declared volatile */
+#define PciReg(base, tag, off, type) \
+ *(volatile type *)(pointer)((char *)(base) + \
+ (PCI_TAG_NO_DOMAIN(tag) | (off)))
+
+/* Generic SPARC PCI access functions */
+static CARD32
+sparcPciCfgRead32(PCITAG tag, int off)
+{
+ pciBusInfo_t *pBusInfo;
+ sparcDomainPtr pDomain;
+ volatile CARD32 result = (CARD32)(-1); /* Must be volatile */
+ int bus;
+
+ if ((off >= 0) && (off <= 252) && !(off & 3) &&
+ ((bus = PCI_BUS_FROM_TAG(tag)) < pciNumBuses) &&
+ (pBusInfo = pciBusInfo[bus]) && (pDomain = pBusInfo->pciBusPriv) &&
+ (bus >= pDomain->bus_min) && (bus < pDomain->bus_max) &&
+ ((bus > pDomain->bus_min) ||
+ IsBitSetInMap(PCI_DFN_FROM_TAG(tag), pDomain->dfn_mask))) {
+ result = PciReg(pDomain->pci, tag, off, CARD32);
+
+ result = PCI_CPU(result);
+ }
+
+ return result;
+}
+
+static void
+sparcPciCfgWrite32(PCITAG tag, int off, CARD32 val)
+{
+ pciBusInfo_t *pBusInfo;
+ sparcDomainPtr pDomain;
+ int bus;
+
+ if ((off < 0) || (off > 252) || (off & 3) ||
+ ((bus = PCI_BUS_FROM_TAG(tag)) >= pciNumBuses) ||
+ !(pBusInfo = pciBusInfo[bus]) || !(pDomain = pBusInfo->pciBusPriv) ||
+ (bus < pDomain->bus_min) || (bus >= pDomain->bus_max) ||
+ ((bus == pDomain->bus_min) &&
+ !IsBitSetInMap(PCI_DFN_FROM_TAG(tag), pDomain->dfn_mask)))
+ return;
+
+ val = PCI_CPU(val);
+ PciReg(pDomain->pci, tag, off, CARD32) = val;
+}
+
+static void
+sparcPciCfgSetBits32(PCITAG tag, int off, CARD32 mask, CARD32 bits)
+{
+ CARD32 PciVal;
+
+ PciVal = sparcPciCfgRead32(tag, off);
+ PciVal &= ~mask;
+ PciVal |= bits;
+ sparcPciCfgWrite32(tag, off, PciVal);
+}
+
+static pciBusFuncs_t sparcPCIFunctions =
+{
+ sparcPciCfgRead32,
+ sparcPciCfgWrite32,
+ sparcPciCfgSetBits32,
+ pciAddrNOOP,
+ pciAddrNOOP
+};
+
+/*
+ * Sabre-specific versions of the above because of its peculiar access size
+ * requirements.
+ */
+static CARD32
+sabrePciCfgRead32(PCITAG tag, int off)
+{
+ pciBusInfo_t *pBusInfo;
+ sparcDomainPtr pDomain;
+ volatile CARD32 result; /* Must be volatile */
+ int bus;
+
+ if (PCI_BDEV_FROM_TAG(tag))
+ return sparcPciCfgRead32(tag, off);
+
+ if (PCI_FUNC_FROM_TAG(tag) || (off < 0) || (off > 252) || (off & 3) ||
+ ((bus = PCI_BUS_FROM_TAG(tag)) >= pciNumBuses) ||
+ !(pBusInfo = pciBusInfo[bus]) || !(pDomain = pBusInfo->pciBusPriv) ||
+ (bus != pDomain->bus_min))
+ return (CARD32)(-1);
+
+ if (off < 8) {
+ result = (PciReg(pDomain->pci, tag, off, CARD16) << 16) |
+ PciReg(pDomain->pci, tag, off + 2, CARD16);
+ return PCI_CPU(result);
+ }
+
+ result = (PciReg(pDomain->pci, tag, off + 3, CARD8) << 24) |
+ (PciReg(pDomain->pci, tag, off + 2, CARD8) << 16) |
+ (PciReg(pDomain->pci, tag, off + 1, CARD8) << 8) |
+ (PciReg(pDomain->pci, tag, off , CARD8) );
+ return result;
+}
+
+static void
+sabrePciCfgWrite32(PCITAG tag, int off, CARD32 val)
+{
+ pciBusInfo_t *pBusInfo;
+ sparcDomainPtr pDomain;
+ int bus;
+
+ if (PCI_BDEV_FROM_TAG(tag))
+ sparcPciCfgWrite32(tag, off, val);
+ else if (!PCI_FUNC_FROM_TAG(tag) &&
+ (off >= 0) && (off <= 252) && !(off & 3) &&
+ ((bus = PCI_BUS_FROM_TAG(tag)) < pciNumBuses) &&
+ (pBusInfo = pciBusInfo[bus]) &&
+ (pDomain = pBusInfo->pciBusPriv) &&
+ (bus == pDomain->bus_min)) {
+ if (off < 8) {
+ val = PCI_CPU(val);
+ PciReg(pDomain->pci, tag, off , CARD16) = val >> 16;
+ PciReg(pDomain->pci, tag, off + 2, CARD16) = val;
+ } else {
+ PciReg(pDomain->pci, tag, off , CARD8) = val;
+ PciReg(pDomain->pci, tag, off + 1, CARD8) = val >> 8;
+ PciReg(pDomain->pci, tag, off + 2, CARD8) = val >> 16;
+ PciReg(pDomain->pci, tag, off + 3, CARD8) = val >> 24;
+ }
+ }
+}
+
+static void
+sabrePciCfgSetBits32(PCITAG tag, int off, CARD32 mask, CARD32 bits)
+{
+ CARD32 PciVal;
+
+ PciVal = sabrePciCfgRead32(tag, off);
+ PciVal &= ~mask;
+ PciVal |= bits;
+ sabrePciCfgWrite32(tag, off, PciVal);
+}
+
+static pciBusFuncs_t sabrePCIFunctions =
+{
+ sabrePciCfgRead32,
+ sabrePciCfgWrite32,
+ sabrePciCfgSetBits32,
+ pciAddrNOOP,
+ pciAddrNOOP
+};
+
+static int pagemask;
+
+/* Scan PROM for all PCI host bridges in the system */
+void
+sparcPciInit(void)
+{
+ int node, node2;
+
+ if (!xf86LinearVidMem())
+ return;
+
+ apertureFd = open(apertureDevName, O_RDWR);
+ if (apertureFd < 0) {
+ xf86Msg(X_ERROR,
+ "sparcPciInit: open failure: %s\n", strerror(errno));
+ return;
+ }
+
+ sparcPromInit();
+ pagemask = xf86getpagesize() - 1;
+
+ for (node = promGetChild(promRootNode);
+ node;
+ node = promGetSibling(node)) {
+ unsigned long long pci_addr;
+ sparcDomainRec domain;
+ sparcDomainPtr pDomain;
+ pciBusFuncs_p pFunctions;
+ char *prop_val;
+ int prop_len, bus;
+
+ prop_val = promGetProperty("name", &prop_len);
+ /* Some PROMs include the trailing null; some don't */
+ if (!prop_val || (prop_len < 3) || (prop_len > 4) ||
+ strcmp(prop_val, "pci"))
+ continue;
+
+ prop_val = promGetProperty("model", &prop_len);
+ if (!prop_val || (prop_len <= 0)) {
+ prop_val = promGetProperty("compatible", &prop_len);
+ if (!prop_val || (prop_len <= 0))
+ continue;
+ }
+
+ pFunctions = &sparcPCIFunctions;
+ (void)memset(&domain, 0, sizeof(domain));
+
+ if (!strncmp("SUNW,sabre", prop_val, prop_len) ||
+ !strncmp("pci108e,a000", prop_val, prop_len) ||
+ !strncmp("pci108e,a001", prop_val, prop_len)) {
+ /*
+ * There can only be one "Sabre" bridge in a system. It provides
+ * PCI configuration space, a 24-bit I/O space and a 32-bit memory
+ * space, all three of which are at fixed physical CPU addresses.
+ */
+ static Bool sabre_seen = FALSE;
+
+ xf86Msg(X_INFO,
+ "Sabre or Hummingbird PCI host bridge found (\"%s\")\n",
+ prop_val);
+
+ /* There can only be one Sabre */
+ if (sabre_seen)
+ continue;
+ sabre_seen = TRUE;
+
+ /* Get "bus-range" property */
+ prop_val = promGetProperty("bus-range", &prop_len);
+ if (!prop_val || (prop_len != 8) ||
+ (((unsigned int *)prop_val)[0]) ||
+ (((unsigned int *)prop_val)[1] >= 256))
+ continue;
+
+ pci_addr = 0x01fe01000000ull;
+ domain.io_addr = 0x01fe02000000ull;
+ domain.io_size = 0x000001000000ull;
+ domain.mem_addr = 0x01ff00000000ull;
+ domain.mem_size = 0x000100000000ull;
+ domain.bus_min = 0; /* Always */
+ domain.bus_max = ((int *)prop_val)[1];
+
+ pFunctions = &sabrePCIFunctions;
+ } else
+ if (!strncmp("SUNW,psycho", prop_val, prop_len) ||
+ !strncmp("pci108e,8000", prop_val, prop_len)) {
+ /*
+ * A "Psycho" host bridge provides two PCI interfaces, each with
+ * its own 16-bit I/O and 31-bit memory spaces. Both share the
+ * same PCI configuration space. Here, they are assigned separate
+ * domain numbers to prevent unintentional I/O and/or memory
+ * resource conflicts.
+ */
+ xf86Msg(X_INFO,
+ "Psycho PCI host bridge found (\"%s\")\n", prop_val);
+
+ /* Get "bus-range" property */
+ prop_val = promGetProperty("bus-range", &prop_len);
+ if (!prop_val || (prop_len != 8) ||
+ (((unsigned int *)prop_val)[1] >= 256) ||
+ (((unsigned int *)prop_val)[0] > ((unsigned int *)prop_val)[1]))
+ continue;
+
+ domain.bus_min = ((int *)prop_val)[0];
+ domain.bus_max = ((int *)prop_val)[1];
+
+ /* Get "ranges" property */
+ prop_val = promGetProperty("ranges", &prop_len);
+ if (!prop_val || (prop_len != 112) ||
+ prop_val[0] || (prop_val[28] != 0x01u) ||
+ (prop_val[56] != 0x02u) || (prop_val[84] != 0x03u) ||
+ (((unsigned int *)prop_val)[4] != 0x01000000u) ||
+ ((unsigned int *)prop_val)[5] ||
+ ((unsigned int *)prop_val)[12] ||
+ (((unsigned int *)prop_val)[13] != 0x00010000u) ||
+ ((unsigned int *)prop_val)[19] ||
+ (((unsigned int *)prop_val)[20] != 0x80000000u) ||
+ ((((unsigned int *)prop_val)[11] & ~0x00010000u) !=
+ 0x02000000u) ||
+ (((unsigned int *)prop_val)[18] & ~0x80000000u) ||
+ (((unsigned int *)prop_val)[3] !=
+ ((unsigned int *)prop_val)[10]) ||
+ (((unsigned int *)prop_val)[17] !=
+ ((unsigned int *)prop_val)[24]) ||
+ (((unsigned int *)prop_val)[18] !=
+ ((unsigned int *)prop_val)[25]) ||
+ (((unsigned int *)prop_val)[19] !=
+ ((unsigned int *)prop_val)[26]) ||
+ (((unsigned int *)prop_val)[20] !=
+ ((unsigned int *)prop_val)[27]))
+ continue;
+
+ /* Use memcpy() to avoid alignment issues */
+ (void)memcpy(&pci_addr, prop_val + 12,
+ sizeof(pci_addr));
+ (void)memcpy(&domain.io_addr, prop_val + 40,
+ sizeof(domain.io_addr));
+ (void)memcpy(&domain.mem_addr, prop_val + 68,
+ sizeof(domain.mem_addr));
+
+ domain.io_size = 0x000000010000ull;
+ domain.mem_size = 0x000080000000ull;
+ } else
+ if (!strncmp("SUNW,schizo", prop_val, prop_len) ||
+ !strncmp("pci108e,8001", prop_val, prop_len)) {
+ /*
+ * I have no docs on the "Schizo", but judging from the Linux
+ * kernel, it also provides two PCI domains. Each PCI
+ * configuration space is the usual 16M in size, followed by a
+ * variable-length I/O space. Each domain also provides a
+ * variable-length memory space. The kernel seems to think the I/O
+ * spaces are 16M long, and the memory spaces, 2G, but these
+ * assumptions are actually only present in source code comments.
+ * Sun has, however, confirmed to me the validity of these
+ * assumptions.
+ */
+ volatile unsigned long long mem_match, mem_mask, io_match, io_mask;
+ unsigned long Offset;
+ pointer pSchizo;
+
+ xf86Msg(X_INFO,
+ "Schizo PCI host bridge found (\"%s\")\n", prop_val);
+
+ /* Get "bus-range" property */
+ prop_val = promGetProperty("bus-range", &prop_len);
+ if (!prop_val || (prop_len != 8) ||
+ (((unsigned int *)prop_val)[1] >= 256) ||
+ (((unsigned int *)prop_val)[0] > ((unsigned int *)prop_val)[1]))
+ continue;
+
+ domain.bus_min = ((int *)prop_val)[0];
+ domain.bus_max = ((int *)prop_val)[1];
+
+ /* Get "reg" property */
+ prop_val = promGetProperty("reg", &prop_len);
+ if (!prop_val || (prop_len != 48))
+ continue;
+
+ /* Temporarily map some of Schizo's registers */
+ pSchizo = sparcMapAperture(-1, VIDMEM_MMIO,
+ ((unsigned long long *)prop_val)[2] - 0x000000010000ull,
+ 0x00010000ul);
+
+ /* Determine where PCI config, I/O and memory spaces reside */
+ if ((((unsigned long long *)prop_val)[0] & 0x000000700000ull) ==
+ 0x000000600000ull)
+ Offset = 0x0040;
+ else
+ Offset = 0x0060;
+
+ mem_match = PciReg(pSchizo, 0, Offset, unsigned long long);
+ mem_mask = PciReg(pSchizo, 0, Offset + 8, unsigned long long);
+ io_match = PciReg(pSchizo, 0, Offset + 16, unsigned long long);
+ io_mask = PciReg(pSchizo, 0, Offset + 24, unsigned long long);
+
+ /* Unmap Schizo registers */
+ xf86UnMapVidMem(-1, pSchizo, 0x00010000ul);
+
+ /* Calculate sizes */
+ mem_mask = (((mem_mask - 1) ^ mem_mask) >> 1) + 1;
+ io_mask = (((io_mask - 1) ^ io_mask ) >> 1) + 1;
+
+ if (io_mask <= 0x000001000000ull) /* Nothing left for I/O */
+ continue;
+
+ domain.mem_addr = mem_match & ~0x8000000000000000ull;
+ domain.mem_size = mem_mask;
+ pci_addr = io_match & ~0x8000000000000000ull;
+ domain.io_addr = pci_addr + 0x0000000001000000ull;
+ domain.io_size = io_mask - 0x0000000001000000ull;
+ } else {
+ xf86Msg(X_WARNING, "Unknown PCI host bridge: \"%s\"\n", prop_val);
+ continue;
+ }
+
+ /* Only map as much PCI configuration as we need */
+ domain.pci = (char *)sparcMapAperture(-1, VIDMEM_MMIO,
+ pci_addr + PCI_MAKE_TAG(domain.bus_min, 0, 0),
+ PCI_MAKE_TAG(domain.bus_max - domain.bus_min + 1, 0, 0)) -
+ PCI_MAKE_TAG(domain.bus_min, 0, 0);
+
+ /* Allocate a domain record */
+ pDomain = xnfalloc(sizeof(sparcDomainRec));
+ *pDomain = domain;
+
+ /*
+ * Allocate and prime pciBusInfo records. These are allocated one at a
+ * time because those for empty buses are eventually released.
+ */
+ bus = pDomain->bus_min =
+ PCI_MAKE_BUS(pciNumDomains, domain.bus_min);
+ pciNumBuses = pDomain->bus_max =
+ PCI_MAKE_BUS(pciNumDomains, domain.bus_max) + 1;
+
+ pciBusInfo[bus] = xnfcalloc(1, sizeof(pciBusInfo_t));
+ pciBusInfo[bus]->configMech = PCI_CFG_MECH_OTHER;
+ pciBusInfo[bus]->numDevices = 32;
+ pciBusInfo[bus]->funcs = pFunctions;
+ pciBusInfo[bus]->pciBusPriv = pDomain;
+ while (++bus < pciNumBuses) {
+ pciBusInfo[bus] = xnfalloc(sizeof(pciBusInfo_t));
+ *(pciBusInfo[bus]) = *(pciBusInfo[bus - 1]);
+ pciBusInfo[bus]->funcs = &sparcPCIFunctions;
+ }
+
+ /* Next domain, please... */
+ xf86DomainInfo[pciNumDomains++] = pDomain;
+
+ /*
+ * OK, enough of the straight-forward stuff. Time to deal with some
+ * brokenness...
+ *
+ * The PCI specs require that when a bus transaction remains unclaimed
+ * for too long, the master entity on that bus is to cancel the
+ * transaction it issued or passed on with a master abort. Two
+ * outcomes are possible:
+ *
+ * - the master abort can be treated as an error that is propogated
+ * back through the bus tree to the entity that ultimately originated
+ * the transaction; or
+ * - the transaction can be allowed to complete normally, which means
+ * that writes are ignored and reads return all ones.
+ *
+ * In the first case, if the CPU happens to be at the tail end of the
+ * tree path through one of its host bridges, it will be told there is
+ * a hardware mal-function, despite being generated by software.
+ *
+ * For a software function (be it firmware, OS or userland application)
+ * to determine how a PCI bus tree is populated, it must be able to
+ * detect when master aborts occur. Obviously, PCI discovery is much
+ * simpler when master aborts are allowed to complete normally.
+ *
+ * Unfortunately, a number of non-Intel PCI implementations have chosen
+ * to treat master aborts as severe errors. The net effect is to
+ * cripple PCI discovery algorithms in userland.
+ *
+ * On SPARCs, master aborts cause a number of different behaviours,
+ * including delivering a signal to the userland application, rebooting
+ * the system, "dropping down" to firmware, or, worst of all, bus
+ * lockouts. Even in the first case, the SIGBUS signal that is
+ * eventually generated isn't delivered in a timely enough fashion to
+ * allow an application to reliably detect the master abort that
+ * ultimately caused it.
+ *
+ * This can be somewhat mitigated. On all architectures, master aborts
+ * that occur on secondary buses can be forced to complete normally
+ * because the PCI-to-PCI bridges that serve them are governed by an
+ * industry-wide specification. (This is just another way of saying
+ * that whatever justification there might be for erroring out master
+ * aborts is deemed by the industry as insufficient to generate more
+ * PCI non-compliance than there already is...)
+ *
+ * This leaves us with master aborts that occur on primary buses.
+ * There is no specification for host-to-PCI bridges. Bridges used in
+ * SPARCs can be told to ignore all PCI errors, but not specifically
+ * master aborts. Not only is this too coarse-grained, but
+ * master-aborted read transactions on the primary bus end up returning
+ * garbage rather than all ones.
+ *
+ * I have elected to work around this the only way I can think of doing
+ * so right now. The following scans an additional PROM level and
+ * builds a device/function map for the primary bus. I can only hope
+ * this PROM information represents all devices on the primary bus,
+ * rather than only a subset of them.
+ *
+ * Master aborts are useful in other ways too, that are not addressed
+ * here. These include determining whether or not a domain provides
+ * VGA, or if a PCI device actually implements PCI disablement.
+ *
+ * --- TSI @ UQV 2001.09.19
+ */
+ for (node2 = promGetChild(node);
+ node2;
+ node2 = promGetSibling(node2)) {
+ /* Get "reg" property */
+ prop_val = promGetProperty("reg", &prop_len);
+ if (!prop_val || (prop_len % 20))
+ continue;
+
+ /*
+ * It's unnecessary to scan the entire "reg" property, but I'll do
+ * so anyway.
+ */
+ prop_len /= 20;
+ for (; prop_len--; prop_val += 20)
+ SetBitInMap(PCI_DFN_FROM_TAG(*(PCITAG *)prop_val),
+ pDomain->dfn_mask);
+ }
+
+ /* Assume the host bridge is device 0, function 0 on its bus */
+ SetBitInMap(0, pDomain->dfn_mask);
+ }
+
+ sparcPromClose();
+
+ close(apertureFd);
+ apertureFd = -1;
+}
+
+#ifndef INCLUDE_XF86_NO_DOMAIN
+
+int
+xf86GetPciDomain(PCITAG Tag)
+{
+ return PCI_DOM_FROM_TAG(Tag);
+}
+
+pointer
+xf86MapDomainMemory(int ScreenNum, int Flags, PCITAG Tag,
+ ADDRESS Base, unsigned long Size)
+{
+ sparcDomainPtr pDomain;
+ pointer result;
+ int domain = PCI_DOM_FROM_TAG(Tag);
+
+ if ((domain <= 0) || (domain >= pciNumDomains) ||
+ !(pDomain = xf86DomainInfo[domain]) ||
+ (((unsigned long long)Base + (unsigned long long)Size) >
+ pDomain->mem_size))
+ FatalError("xf86MapDomainMemory() called with invalid parameters.\n");
+
+ result = sparcMapAperture(ScreenNum, Flags, pDomain->mem_addr + Base, Size);
+
+ if (apertureFd >= 0) {
+ close(apertureFd);
+ apertureFd = -1;
+ }
+
+ return result;
+}
+
+IOADDRESS
+xf86MapDomainIO(int ScreenNum, int Flags, PCITAG Tag,
+ IOADDRESS Base, unsigned long Size)
+{
+ sparcDomainPtr pDomain;
+ int domain = PCI_DOM_FROM_TAG(Tag);
+
+ if ((domain <= 0) || (domain >= pciNumDomains) ||
+ !(pDomain = xf86DomainInfo[domain]) ||
+ (((unsigned long long)Base + (unsigned long long)Size) >
+ pDomain->io_size))
+ FatalError("xf86MapDomainIO() called with invalid parameters.\n");
+
+ /* Permanently map all of I/O space */
+ if (!pDomain->io) {
+ pDomain->io = sparcMapAperture(ScreenNum, Flags,
+ pDomain->io_addr, pDomain->io_size);
+
+ if (apertureFd >= 0) {
+ close(apertureFd);
+ apertureFd = -1;
+ }
+ }
+
+ return (IOADDRESS)pDomain->io + Base;
+}
+
+int
+xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len, unsigned char *Buf)
+{
+ unsigned char *ptr, *src;
+ ADDRESS offset;
+ unsigned long size;
+ int len;
+
+ /* Ensure page boundaries */
+ offset = Base & ~pagemask;
+ size = ((Base + Len + pagemask) & ~pagemask) - offset;
+
+ ptr = xf86MapDomainMemory(-1, VIDMEM_READONLY, Tag, offset, size);
+
+ /* Using memcpy() here hangs the system */
+ src = ptr + (Base - offset);
+ for (len = Len; len-- > 0;)
+ *Buf++ = *src++;
+
+ xf86UnMapVidMem(-1, ptr, size);
+
+ return Len;
+}
+
+resPtr
+xf86BusAccWindowsFromOS(void)
+{
+ sparcDomainPtr pDomain;
+ resPtr pRes = NULL;
+ resRange range;
+ int domain;
+
+ for (domain = 1; domain < pciNumDomains; domain++) {
+ if (!(pDomain = xf86DomainInfo[domain]))
+ continue;
+
+ RANGE(range, 0, pDomain->mem_size - 1,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ RANGE(range, 0, pDomain->io_size - 1,
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ }
+
+ return pRes;
+}
+
+resPtr
+xf86PciBusAccWindowsFromOS(void)
+{
+ sparcDomainPtr pDomain;
+ resPtr pRes = NULL;
+ resRange range;
+ int domain;
+
+ for (domain = 1; domain < pciNumDomains; domain++) {
+ if (!(pDomain = xf86DomainInfo[domain]))
+ continue;
+
+ RANGE(range, 0, pDomain->mem_size - 1,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ RANGE(range, 0, pDomain->io_size - 1,
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ }
+
+ return pRes;
+}
+
+resPtr
+xf86AccResFromOS(resPtr pRes)
+{
+ sparcDomainPtr pDomain;
+ resRange range;
+ int domain;
+
+ for (domain = 1; domain < pciNumDomains; domain++) {
+ if (!(pDomain = xf86DomainInfo[domain]))
+ continue;
+
+ /*
+ * At minimum, the top and bottom resources must be claimed, so that
+ * resources that are (or appear to be) unallocated can be relocated.
+ */
+ RANGE(range, 0x00000000u, 0x0009ffffu,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ RANGE(range, 0x000c0000u, 0x000effffu,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ RANGE(range, 0x000f0000u, 0x000fffffu,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ RANGE(range, pDomain->mem_size - 1, pDomain->mem_size - 1,
+ RANGE_TYPE(ResExcMemBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+
+ RANGE(range, 0x00000000u, 0x00000000u,
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ RANGE(range, pDomain->io_size - 1, pDomain->io_size - 1,
+ RANGE_TYPE(ResExcIoBlock, domain));
+ pRes = xf86AddResToList(pRes, &range, -1);
+ }
+
+ return pRes;
+}
+
+#endif /* !INCLUDE_XF86_NO_DOMAIN */
+
+#endif /* defined(sun) */
+
+#if defined(ARCH_PCI_PCI_BRIDGE)
+
+/* Definitions specific to Sun's APB P2P bridge (a.k.a. Simba) */
+#define APB_IO_ADDRESS_MAP 0xDE
+#define APB_MEM_ADDRESS_MAP 0xDF
+
+/*
+ * Simba's can only occur on bus 0. Furthermore, Simba's must have a non-zero
+ * device/function number because the Sabre interface they must connect to
+ * occupies the 0:0:0 slot. Also, there can be only one Sabre interface in the
+ * system, and therefore, only one Simba function can route any particular
+ * resource. Thus, it is appropriate to use a single set of static variables
+ * to hold the tag of the Simba function routing a VGA resource range at any
+ * one time, and to test these variables for non-zero to determine whether or
+ * not the Sabre would master-abort a VGA access (and kill the system).
+ *
+ * The trick is to determine when it is safe to re-route VGA, because doing so
+ * re-routes much more.
+ */
+static PCITAG simbavgaIOTag = 0, simbavgaMemTag = 0;
+static Bool simbavgaRoutingAllow = TRUE;
+
+/*
+ * Scan the bus subtree rooted at 'bus' for a non-display device that might be
+ * decoding the bottom 2 MB of I/O space and/or the bottom 512 MB of memory
+ * space. Reset simbavgaRoutingAllow if such a device is found.
+ *
+ * XXX For now, this is very conservative and should be made less so as the
+ * need arises.
+ */
+static void
+simbaCheckBus(CARD16 pcicommand, int bus)
+{
+ pciConfigPtr pPCI, *ppPCI = xf86scanpci(0);
+
+ while ((pPCI = *ppPCI++)) {
+ if (pPCI->busnum < bus)
+ continue;
+ if (pPCI->busnum > bus)
+ break;
+
+ /* XXX Assume all devices respect PCI disablement */
+ if (!(pcicommand & pPCI->pci_command))
+ continue;
+
+ /* XXX This doesn't deal with mis-advertised classes */
+ switch (pPCI->pci_base_class) {
+ case PCI_CLASS_PREHISTORIC:
+ if (pPCI->pci_sub_class == PCI_SUBCLASS_PREHISTORIC_VGA)
+ continue; /* Ignore VGA */
+ break;
+
+ case PCI_CLASS_DISPLAY:
+ continue;
+
+ case PCI_CLASS_BRIDGE:
+ switch (pPCI->pci_sub_class) {
+ case PCI_SUBCLASS_BRIDGE_PCI:
+ case PCI_SUBCLASS_BRIDGE_CARDBUS:
+ /* Scan secondary bus */
+ /* XXX First check bridge routing? */
+ simbaCheckBus(pcicommand & pPCI->pci_command,
+ PCI_SECONDARY_BUS_EXTRACT(pPCI->pci_pp_bus_register,
+ pPCI->tag));
+ if (!simbavgaRoutingAllow)
+ return;
+
+ default:
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ /*
+ * XXX We could check the device's bases here, but PCI doesn't limit
+ * the device's decoding to them.
+ */
+
+ simbavgaRoutingAllow = FALSE;
+ break;
+ }
+}
+
+static pciConfigPtr
+simbaVerifyBus(int bus)
+{
+ pciConfigPtr pPCI;
+ if ((bus < 0) || (bus >= pciNumBuses) ||
+ !pciBusInfo[bus] || !(pPCI = pciBusInfo[bus]->bridge) ||
+ (pPCI->pci_device_vendor != DEVID(VENDOR_SUN, CHIP_SIMBA)))
+ return NULL;
+
+ return pPCI;
+}
+
+static CARD16
+simbaControlBridge(int bus, CARD16 mask, CARD16 value)
+{
+ pciConfigPtr pPCI;
+ CARD16 current = 0, tmp;
+ CARD8 iomap, memmap;
+
+ if ((pPCI = simbaVerifyBus(bus))) {
+ /*
+ * The Simba does not implement VGA enablement as described in the P2P
+ * spec. It does however route I/O and memory in large enough chunks
+ * so that we can determine were VGA resources would be routed
+ * (including ISA VGA I/O aliases). We can allow changes to that
+ * routing only under certain circumstances.
+ */
+ iomap = pciReadByte(pPCI->tag, APB_IO_ADDRESS_MAP);
+ memmap = pciReadByte(pPCI->tag, APB_MEM_ADDRESS_MAP);
+ if (iomap & memmap & 0x01) {
+ current |= PCI_PCI_BRIDGE_VGA_EN;
+ if ((mask & PCI_PCI_BRIDGE_VGA_EN) &&
+ !(value & PCI_PCI_BRIDGE_VGA_EN)) {
+ if (!simbavgaRoutingAllow) {
+ xf86MsgVerb(X_WARNING, 3, "Attempt to disable VGA routing"
+ " through Simba at %x:%x:%x disallowed.\n",
+ pPCI->busnum, pPCI->devnum, pPCI->funcnum);
+ value |= PCI_PCI_BRIDGE_VGA_EN;
+ } else {
+ pciWriteByte(pPCI->tag, APB_IO_ADDRESS_MAP,
+ iomap & ~0x01);
+ pciWriteByte(pPCI->tag, APB_MEM_ADDRESS_MAP,
+ memmap & ~0x01);
+ simbavgaIOTag = simbavgaMemTag = 0;
+ }
+ }
+ } else {
+ if (mask & value & PCI_PCI_BRIDGE_VGA_EN) {
+ if (!simbavgaRoutingAllow) {
+ xf86MsgVerb(X_WARNING, 3, "Attempt to enable VGA routing"
+ " through Simba at %x:%x:%x disallowed.\n",
+ pPCI->busnum, pPCI->devnum, pPCI->funcnum);
+ value &= ~PCI_PCI_BRIDGE_VGA_EN;
+ } else {
+ if (pPCI->tag != simbavgaIOTag) {
+ if (simbavgaIOTag) {
+ tmp = pciReadByte(simbavgaIOTag,
+ APB_IO_ADDRESS_MAP);
+ pciWriteByte(simbavgaIOTag, APB_IO_ADDRESS_MAP,
+ tmp & ~0x01);
+ }
+
+ pciWriteByte(pPCI->tag, APB_IO_ADDRESS_MAP,
+ iomap | 0x01);
+ simbavgaIOTag = pPCI->tag;
+ }
+
+ if (pPCI->tag != simbavgaMemTag) {
+ if (simbavgaMemTag) {
+ tmp = pciReadByte(simbavgaMemTag,
+ APB_MEM_ADDRESS_MAP);
+ pciWriteByte(simbavgaMemTag, APB_MEM_ADDRESS_MAP,
+ tmp & ~0x01);
+ }
+
+ pciWriteByte(pPCI->tag, APB_MEM_ADDRESS_MAP,
+ memmap | 0x01);
+ simbavgaMemTag = pPCI->tag;
+ }
+ }
+ }
+ }
+
+ /* Move on to master abort failure enablement (as per P2P spec) */
+ tmp = pciReadWord(pPCI->tag, PCI_PCI_BRIDGE_CONTROL_REG);
+ current |= tmp;
+ if (tmp & PCI_PCI_BRIDGE_MASTER_ABORT_EN) {
+ if ((mask & PCI_PCI_BRIDGE_MASTER_ABORT_EN) &&
+ !(value & PCI_PCI_BRIDGE_MASTER_ABORT_EN))
+ pciWriteWord(pPCI->tag, PCI_PCI_BRIDGE_CONTROL_REG,
+ tmp & ~PCI_PCI_BRIDGE_MASTER_ABORT_EN);
+ } else {
+ if (mask & value & PCI_PCI_BRIDGE_MASTER_ABORT_EN)
+ pciWriteWord(pPCI->tag, PCI_PCI_BRIDGE_CONTROL_REG,
+ tmp | PCI_PCI_BRIDGE_MASTER_ABORT_EN);
+ }
+
+ /* Insert emulation of other P2P controls here */
+ }
+
+ return (current & ~mask) | (value & mask);
+}
+
+static void
+simbaGetBridgeResources(int bus,
+ pointer *ppIoRes,
+ pointer *ppMemRes,
+ pointer *ppPmemRes)
+{
+ pciConfigPtr pPCI = simbaVerifyBus(bus);
+ resRange range;
+ int i;
+
+ if (!pPCI)
+ return;
+
+ if (ppIoRes) {
+ xf86FreeResList(*ppIoRes);
+ *ppIoRes = NULL;
+
+ if (pPCI->pci_command & PCI_CMD_IO_ENABLE) {
+ unsigned char iomap = pciReadByte(pPCI->tag, APB_IO_ADDRESS_MAP);
+ if (simbavgaRoutingAllow)
+ iomap |= 0x01;
+ for (i = 0; i < 8; i++) {
+ if (iomap & (1 << i)) {
+ RANGE(range, i << 21, ((i + 1) << 21) - 1,
+ RANGE_TYPE(ResExcIoBlock,
+ xf86GetPciDomain(pPCI->tag)));
+ *ppIoRes = xf86AddResToList(*ppIoRes, &range, -1);
+ }
+ }
+ }
+ }
+
+ if (ppMemRes) {
+ xf86FreeResList(*ppMemRes);
+ *ppMemRes = NULL;
+
+ if (pPCI->pci_command & PCI_CMD_MEM_ENABLE) {
+ unsigned char memmap = pciReadByte(pPCI->tag, APB_MEM_ADDRESS_MAP);
+ if (simbavgaRoutingAllow)
+ memmap |= 0x01;
+ for (i = 0; i < 8; i++) {
+ if (memmap & (1 << i)) {
+ RANGE(range, i << 29, ((i + 1) << 29) - 1,
+ RANGE_TYPE(ResExcMemBlock,
+ xf86GetPciDomain(pPCI->tag)));
+ *ppMemRes = xf86AddResToList(*ppMemRes, &range, -1);
+ }
+ }
+ }
+ }
+
+ if (ppPmemRes) {
+ xf86FreeResList(*ppPmemRes);
+ *ppPmemRes = NULL;
+ }
+}
+
+void ARCH_PCI_PCI_BRIDGE(pciConfigPtr pPCI)
+{
+ static pciBusFuncs_t simbaBusFuncs;
+ pciBusInfo_t *pBusInfo;
+ CARD16 pcicommand;
+
+ if (pPCI->pci_device_vendor != DEVID(VENDOR_SUN, CHIP_SIMBA))
+ return;
+
+ pBusInfo = pPCI->businfo;
+
+ simbaBusFuncs = *(pBusInfo->funcs);
+ simbaBusFuncs.pciControlBridge = simbaControlBridge;
+ simbaBusFuncs.pciGetBridgeResources = simbaGetBridgeResources;
+
+ pBusInfo->funcs = &simbaBusFuncs;
+
+ if (!simbavgaRoutingAllow)
+ return;
+
+ pcicommand = 0;
+
+ if (pciReadByte(pPCI->tag, APB_IO_ADDRESS_MAP) & 0x01) {
+ pcicommand |= PCI_CMD_IO_ENABLE;
+ simbavgaIOTag = pPCI->tag;
+ }
+
+ if (pciReadByte(pPCI->tag, APB_MEM_ADDRESS_MAP) & 0x01) {
+ pcicommand |= PCI_CMD_MEM_ENABLE;
+ simbavgaMemTag = pPCI->tag;
+ }
+
+ if (!pcicommand)
+ return;
+
+ simbaCheckBus(pcicommand,
+ PCI_SECONDARY_BUS_EXTRACT(pPCI->pci_pp_bus_register, pPCI->tag));
+}
+
+#endif /* defined(ARCH_PCI_PCI_BRIDGE) */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/xf86Pci.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/xf86Pci.h
new file mode 100644
index 000000000..a8b7ef492
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/xf86Pci.h
@@ -0,0 +1,807 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/xf86Pci.h,v 1.39 2003/08/24 17:37:05 dawes Exp $ */
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * This file is derived in part from the original xf86_PCI.h that included
+ * following copyright message:
+ *
+ * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of the above listed copyright holder(s)
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. The above listed
+ * copyright holder(s) make(s) no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
+ * Copyright (c) 1999-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 just the public interface to the PCI code.
+ * Drivers should use this file rather than Pci.h.
+ */
+
+#ifndef _XF86PCI_H
+#define _XF86PCI_H 1
+#include <X11/Xarch.h>
+#include <X11/Xfuncproto.h>
+#include "misc.h"
+
+#define PCI_NOT_FOUND 0xFFFFFFFFU
+
+/*
+ * PCI cfg space definitions (e.g. stuff right out of the PCI spec)
+ */
+
+/* Device identification register */
+#define PCI_ID_REG 0x00
+
+/* Command and status register */
+#define PCI_CMD_STAT_REG 0x04
+#define PCI_CMD_BASE_REG 0x10
+#define PCI_CMD_BIOS_REG 0x30
+#define PCI_CMD_MASK 0xffff
+#define PCI_CMD_IO_ENABLE 0x01
+#define PCI_CMD_MEM_ENABLE 0x02
+#define PCI_CMD_MASTER_ENABLE 0x04
+#define PCI_CMD_SPECIAL_ENABLE 0x08
+#define PCI_CMD_INVALIDATE_ENABLE 0x10
+#define PCI_CMD_PALETTE_ENABLE 0x20
+#define PCI_CMD_PARITY_ENABLE 0x40
+#define PCI_CMD_STEPPING_ENABLE 0x80
+#define PCI_CMD_SERR_ENABLE 0x100
+#define PCI_CMD_BACKTOBACK_ENABLE 0x200
+#define PCI_CMD_BIOS_ENABLE 0x01
+
+/* base class */
+#define PCI_CLASS_REG 0x08
+#define PCI_CLASS_MASK 0xff000000
+#define PCI_CLASS_SHIFT 24
+#define PCI_CLASS_EXTRACT(x) \
+ (((x) & PCI_CLASS_MASK) >> PCI_CLASS_SHIFT)
+
+/* base class values */
+#define PCI_CLASS_PREHISTORIC 0x00
+#define PCI_CLASS_MASS_STORAGE 0x01
+#define PCI_CLASS_NETWORK 0x02
+#define PCI_CLASS_DISPLAY 0x03
+#define PCI_CLASS_MULTIMEDIA 0x04
+#define PCI_CLASS_MEMORY 0x05
+#define PCI_CLASS_BRIDGE 0x06
+#define PCI_CLASS_COMMUNICATIONS 0x07
+#define PCI_CLASS_SYSPERIPH 0x08
+#define PCI_CLASS_INPUT 0x09
+#define PCI_CLASS_DOCKING 0x0a
+#define PCI_CLASS_PROCESSOR 0x0b
+#define PCI_CLASS_SERIALBUS 0x0c
+#define PCI_CLASS_WIRELESS 0x0d
+#define PCI_CLASS_I2O 0x0e
+#define PCI_CLASS_SATELLITE 0x0f
+#define PCI_CLASS_CRYPT 0x10
+#define PCI_CLASS_DATA_ACQUISTION 0x11
+#define PCI_CLASS_UNDEFINED 0xff
+
+/* sub class */
+#define PCI_SUBCLASS_MASK 0x00ff0000
+#define PCI_SUBCLASS_SHIFT 16
+#define PCI_SUBCLASS_EXTRACT(x) \
+ (((x) & PCI_SUBCLASS_MASK) >> PCI_SUBCLASS_SHIFT)
+
+/* Sub class values */
+/* 0x00 prehistoric subclasses */
+#define PCI_SUBCLASS_PREHISTORIC_MISC 0x00
+#define PCI_SUBCLASS_PREHISTORIC_VGA 0x01
+
+/* 0x01 mass storage subclasses */
+#define PCI_SUBCLASS_MASS_STORAGE_SCSI 0x00
+#define PCI_SUBCLASS_MASS_STORAGE_IDE 0x01
+#define PCI_SUBCLASS_MASS_STORAGE_FLOPPY 0x02
+#define PCI_SUBCLASS_MASS_STORAGE_IPI 0x03
+#define PCI_SUBCLASS_MASS_STORAGE_MISC 0x80
+
+/* 0x02 network subclasses */
+#define PCI_SUBCLASS_NETWORK_ETHERNET 0x00
+#define PCI_SUBCLASS_NETWORK_TOKENRING 0x01
+#define PCI_SUBCLASS_NETWORK_FDDI 0x02
+#define PCI_SUBCLASS_NETWORK_MISC 0x80
+
+/* 0x03 display subclasses */
+#define PCI_SUBCLASS_DISPLAY_VGA 0x00
+#define PCI_SUBCLASS_DISPLAY_XGA 0x01
+#define PCI_SUBCLASS_DISPLAY_MISC 0x80
+
+/* 0x04 multimedia subclasses */
+#define PCI_SUBCLASS_MULTIMEDIA_VIDEO 0x00
+#define PCI_SUBCLASS_MULTIMEDIA_AUDIO 0x01
+#define PCI_SUBCLASS_MULTIMEDIA_MISC 0x80
+
+/* 0x05 memory subclasses */
+#define PCI_SUBCLASS_MEMORY_RAM 0x00
+#define PCI_SUBCLASS_MEMORY_FLASH 0x01
+#define PCI_SUBCLASS_MEMORY_MISC 0x80
+
+/* 0x06 bridge subclasses */
+#define PCI_SUBCLASS_BRIDGE_HOST 0x00
+#define PCI_SUBCLASS_BRIDGE_ISA 0x01
+#define PCI_SUBCLASS_BRIDGE_EISA 0x02
+#define PCI_SUBCLASS_BRIDGE_MC 0x03
+#define PCI_SUBCLASS_BRIDGE_PCI 0x04
+#define PCI_SUBCLASS_BRIDGE_PCMCIA 0x05
+#define PCI_SUBCLASS_BRIDGE_NUBUS 0x06
+#define PCI_SUBCLASS_BRIDGE_CARDBUS 0x07
+#define PCI_SUBCLASS_BRIDGE_RACEWAY 0x08
+#define PCI_SUBCLASS_BRIDGE_MISC 0x80
+#define PCI_IF_BRIDGE_PCI_SUBTRACTIVE 0x01
+
+/* 0x07 communications controller subclasses */
+#define PCI_SUBCLASS_COMMUNICATIONS_SERIAL 0x00
+#define PCI_SUBCLASS_COMMUNICATIONS_PARALLEL 0x01
+#define PCI_SUBCLASS_COMMUNICATIONS_MULTISERIAL 0x02
+#define PCI_SUBCLASS_COMMUNICATIONS_MODEM 0x03
+#define PCI_SUBCLASS_COMMUNICATIONS_MISC 0x80
+
+/* 0x08 generic system peripherals subclasses */
+#define PCI_SUBCLASS_SYSPERIPH_PIC 0x00
+#define PCI_SUBCLASS_SYSPERIPH_DMA 0x01
+#define PCI_SUBCLASS_SYSPERIPH_TIMER 0x02
+#define PCI_SUBCLASS_SYSPERIPH_RTC 0x03
+#define PCI_SUBCLASS_SYSPERIPH_HOTPCI 0x04
+#define PCI_SUBCLASS_SYSPERIPH_MISC 0x80
+
+/* 0x09 input device subclasses */
+#define PCI_SUBCLASS_INPUT_KEYBOARD 0x00
+#define PCI_SUBCLASS_INPUT_DIGITIZER 0x01
+#define PCI_SUBCLASS_INPUT_MOUSE 0x02
+#define PCI_SUBCLASS_INPUT_SCANNER 0x03
+#define PCI_SUBCLASS_INPUT_GAMEPORT 0x04
+#define PCI_SUBCLASS_INPUT_MISC 0x80
+
+/* 0x0a docking station subclasses */
+#define PCI_SUBCLASS_DOCKING_GENERIC 0x00
+#define PCI_SUBCLASS_DOCKING_MISC 0x80
+
+/* 0x0b processor subclasses */
+#define PCI_SUBCLASS_PROCESSOR_386 0x00
+#define PCI_SUBCLASS_PROCESSOR_486 0x01
+#define PCI_SUBCLASS_PROCESSOR_PENTIUM 0x02
+#define PCI_SUBCLASS_PROCESSOR_ALPHA 0x10
+#define PCI_SUBCLASS_PROCESSOR_POWERPC 0x20
+#define PCI_SUBCLASS_PROCESSOR_MIPS 0x30
+#define PCI_SUBCLASS_PROCESSOR_COPROC 0x40
+
+/* 0x0c serial bus controller subclasses */
+#define PCI_SUBCLASS_SERIAL_FIREWIRE 0x00
+#define PCI_SUBCLASS_SERIAL_ACCESS 0x01
+#define PCI_SUBCLASS_SERIAL_SSA 0x02
+#define PCI_SUBCLASS_SERIAL_USB 0x03
+#define PCI_SUBCLASS_SERIAL_FIBRECHANNEL 0x04
+#define PCI_SUBCLASS_SERIAL_SMBUS 0x05
+
+/* 0x0d wireless controller subclasses */
+#define PCI_SUBCLASS_WIRELESS_IRDA 0x00
+#define PCI_SUBCLASS_WIRELESS_CONSUMER_IR 0x01
+#define PCI_SUBCLASS_WIRELESS_RF 0x02
+#define PCI_SUBCLASS_WIRELESS_MISC 0x80
+
+/* 0x0e intelligent I/O controller subclasses */
+#define PCI_SUBCLASS_I2O_I2O 0x00
+
+/* 0x0f satellite communications controller subclasses */
+#define PCI_SUBCLASS_SATELLITE_TV 0x01
+#define PCI_SUBCLASS_SATELLITE_AUDIO 0x02
+#define PCI_SUBCLASS_SATELLITE_VOICE 0x03
+#define PCI_SUBCLASS_SATELLITE_DATA 0x04
+
+/* 0x10 encryption/decryption controller subclasses */
+#define PCI_SUBCLASS_CRYPT_NET_COMPUTING 0x00
+#define PCI_SUBCLASS_CRYPT_ENTERTAINMENT 0x10
+#define PCI_SUBCLASS_CRYPT_MISC 0x80
+
+/* 0x11 data acquisition and signal processing controller subclasses */
+#define PCI_SUBCLASS_DATAACQ_DPIO 0x00
+#define PCI_SUBCLASS_DATAACQ_MISC 0x80
+
+
+/* Header */
+#define PCI_HEADER_MISC 0x0c
+#define PCI_HEADER_MULTIFUNCTION 0x00800000
+
+/* Interrupt configration register */
+#define PCI_INTERRUPT_REG 0x3c
+#define PCI_INTERRUPT_PIN_MASK 0x0000ff00
+#define PCI_INTERRUPT_PIN_EXTRACT(x) \
+ ((((x) & PCI_INTERRUPT_PIN_MASK) >> 8) & 0xff)
+#define PCI_INTERRUPT_PIN_NONE 0x00
+#define PCI_INTERRUPT_PIN_A 0x01
+#define PCI_INTERRUPT_PIN_B 0x02
+#define PCI_INTERRUPT_PIN_C 0x03
+#define PCI_INTERRUPT_PIN_D 0x04
+
+#define PCI_INTERRUPT_LINE_MASK 0x000000ff
+#define PCI_INTERRUPT_LINE_EXTRACT(x) \
+ ((((x) & PCI_INTERRUPT_LINE_MASK) >> 0) & 0xff)
+#define PCI_INTERRUPT_LINE_INSERT(x,v) \
+ (((x) & ~PCI_INTERRUPT_LINE_MASK) | ((v) << 0))
+
+/* Base registers */
+#define PCI_MAP_REG_START 0x10
+#define PCI_MAP_REG_END 0x28
+#define PCI_MAP_ROM_REG 0x30
+
+#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_IS_MEM(b) (!PCI_MAP_IS_IO(b))
+
+#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 PCIGETMEMORY64HIGH(b) (*((CARD32*)&(b) + 1))
+#define PCIGETMEMORY64(b) \
+ (PCIGETMEMORY(b) | ((CARD64)PCIGETMEMORY64HIGH(b) << 32))
+
+#define PCI_MAP_IO_ADDRESS_MASK 0xfffffffc
+
+#define PCIGETIO(b) ((b) & PCI_MAP_IO_ADDRESS_MASK)
+
+#define PCI_MAP_ROM_DECODE_ENABLE 0x00000001
+#define PCI_MAP_ROM_ADDRESS_MASK 0xfffff800
+
+#define PCIGETROM(b) ((b) & PCI_MAP_ROM_ADDRESS_MASK)
+
+/* PCI-PCI bridge mapping registers */
+#define PCI_PCI_BRIDGE_BUS_REG 0x18
+#define PCI_SUBORDINATE_BUS_MASK 0x00ff0000
+#define PCI_SECONDARY_BUS_MASK 0x0000ff00
+#define PCI_PRIMARY_BUS_MASK 0x000000ff
+
+#define PCI_PCI_BRIDGE_IO_REG 0x1c
+#define PCI_PCI_BRIDGE_MEM_REG 0x20
+#define PCI_PCI_BRIDGE_PMEM_REG 0x24
+
+#define PCI_PPB_IOBASE_EXTRACT(x) (((x) << 8) & 0xFF00)
+#define PCI_PPB_IOLIMIT_EXTRACT(x) (((x) << 0) & 0xFF00)
+
+#define PCI_PPB_MEMBASE_EXTRACT(x) (((x) << 16) & 0xFFFF0000)
+#define PCI_PPB_MEMLIMIT_EXTRACT(x) (((x) << 0) & 0xFFFF0000)
+
+#define PCI_PCI_BRIDGE_CONTROL_REG 0x3E
+#define PCI_PCI_BRIDGE_PARITY_EN 0x01
+#define PCI_PCI_BRIDGE_SERR_EN 0x02
+#define PCI_PCI_BRIDGE_ISA_EN 0x04
+#define PCI_PCI_BRIDGE_VGA_EN 0x08
+#define PCI_PCI_BRIDGE_MASTER_ABORT_EN 0x20
+#define PCI_PCI_BRIDGE_SECONDARY_RESET 0x40
+#define PCI_PCI_BRIDGE_FAST_B2B_EN 0x80
+/* header type 2 extensions */
+#define PCI_CB_BRIDGE_CTL_CB_RESET 0x40 /* CardBus reset */
+#define PCI_CB_BRIDGE_CTL_16BIT_INT 0x80 /* Enable interrupt for 16-bit cards */
+#define PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 0x100
+#define PCI_CB_BRIDGE_CTL_PREFETCH_MEM1 0x200
+#define PCI_CB_BRIDGE_CTL_POST_WRITES 0x400
+
+#define PCI_CB_SEC_STATUS_REG 0x16 /* Secondary status */
+#define PCI_CB_PRIMARY_BUS_REG 0x18 /* PCI bus number */
+#define PCI_CB_CARD_BUS_REG 0x19 /* CardBus bus number */
+#define PCI_CB_SUBORDINATE_BUS_REG 0x1a /* Subordinate bus number */
+#define PCI_CB_LATENCY_TIMER_REG 0x1b /* CardBus latency timer */
+#define PCI_CB_MEM_BASE_0_REG 0x1c
+#define PCI_CB_MEM_LIMIT_0_REG 0x20
+#define PCI_CB_MEM_BASE_1_REG 0x24
+#define PCI_CB_MEM_LIMIT_1_REG 0x28
+#define PCI_CB_IO_BASE_0_REG 0x2c
+#define PCI_CB_IO_LIMIT_0_REG 0x30
+#define PCI_CB_IO_BASE_1_REG 0x34
+#define PCI_CB_IO_LIMIT_1_REG 0x38
+#define PCI_CB_BRIDGE_CONTROL_REG 0x3E
+
+#define PCI_CB_IO_RANGE_MASK ~0x03
+#define PCI_CB_IOBASE(x) (x & PCI_CB_IO_RANGE_MASK)
+#define PCI_CB_IOLIMIT(x) ((x & PCI_CB_IO_RANGE_MASK) + 3)
+
+/* Subsystem identification register */
+#define PCI_SUBSYSTEM_ID_REG 0x2c
+
+/* User defined cfg space regs */
+#define PCI_REG_USERCONFIG 0x40
+#define PCI_OPTION_REG 0x40
+
+/*
+ * Typedefs, etc...
+ */
+
+/* Primitive Types */
+typedef unsigned long ADDRESS; /* Memory/PCI address */
+typedef unsigned long IOADDRESS; /* Must be large enough for a pointer */
+typedef unsigned long PCITAG;
+
+/*
+ * PCI configuration space
+ */
+typedef struct pci_cfg_regs {
+ /* start of official PCI config space header */
+ union { /* Offset 0x0 - 0x3 */
+ CARD32 device_vendor;
+ struct {
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ CARD16 device;
+ CARD16 vendor;
+#else
+ CARD16 vendor;
+ CARD16 device;
+#endif
+ } dv;
+ } dv_id;
+
+ union { /* Offset 0x4 - 0x8 */
+ CARD32 status_command;
+ struct {
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ CARD16 status;
+ CARD16 command;
+#else
+ CARD16 command;
+ CARD16 status;
+#endif
+ } sc;
+ } stat_cmd;
+
+ union { /* Offset 0x8 - 0xb */
+ CARD32 class_revision;
+ struct {
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ CARD8 base_class;
+ CARD8 sub_class;
+ CARD8 prog_if;
+ CARD8 rev_id;
+#else
+ CARD8 rev_id;
+ CARD8 prog_if;
+ CARD8 sub_class;
+ CARD8 base_class;
+#endif
+ } cr;
+ } class_rev;
+
+ union { /* Offset 0xc - 0xf */
+ CARD32 bist_header_latency_cache;
+ struct {
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ CARD8 bist;
+ CARD8 header_type;
+ CARD8 latency_timer;
+ CARD8 cache_line_size;
+#else
+ CARD8 cache_line_size;
+ CARD8 latency_timer;
+ CARD8 header_type;
+ CARD8 bist;
+#endif
+ } bhlc;
+ } bhlc;
+ union { /* Offset 0x10 - 0x3b */
+ struct { /* header type 2 */
+ CARD32 cg_rsrvd1; /* 0x10 */
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ CARD16 secondary_status; /* 0x16 */
+ CARD16 cg_rsrvd2; /* 0x14 */
+
+ union {
+ CARD32 cg_bus_reg;
+ struct {
+ CARD8 latency_timer; /* 0x1b */
+ CARD8 subordinate_bus_number; /* 0x1a */
+ CARD8 cardbus_bus_number; /* 0x19 */
+ CARD8 primary_bus_number; /* 0x18 */
+ } cgbr;
+ } cgbr;
+#else
+ CARD16 cg_rsrvd2; /* 0x14 */
+ CARD16 secondary_status; /* 0x16 */
+
+ union {
+ CARD32 cg_bus_reg;
+ struct {
+ CARD8 primary_bus_number; /* 0x18 */
+ CARD8 cardbus_bus_number; /* 0x19 */
+ CARD8 subordinate_bus_number; /* 0x1a */
+ CARD8 latency_timer; /* 0x1b */
+ } cgbr;
+ } cgbr;
+#endif
+ CARD32 mem_base0; /* 0x1c */
+ CARD32 mem_limit0; /* 0x20 */
+ CARD32 mem_base1; /* 0x24 */
+ CARD32 mem_limit1; /* 0x28 */
+ CARD32 io_base0; /* 0x2c */
+ CARD32 io_limit0; /* 0x30 */
+ CARD32 io_base1; /* 0x34 */
+ CARD32 io_limit1; /* 0x38 */
+ } cg;
+ struct {
+ union { /* Offset 0x10 - 0x27 */
+ struct { /* header type 0 */
+ CARD32 dv_base0;
+ CARD32 dv_base1;
+ CARD32 dv_base2;
+ CARD32 dv_base3;
+ CARD32 dv_base4;
+ CARD32 dv_base5;
+ } dv;
+ struct { /* header type 1 */
+ CARD32 bg_rsrvd[2];
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ union {
+ CARD32 pp_bus_reg;
+ struct {
+ CARD8 secondary_latency_timer;
+ CARD8 subordinate_bus_number;
+ CARD8 secondary_bus_number;
+ CARD8 primary_bus_number;
+ } ppbr;
+ } ppbr;
+
+ CARD16 secondary_status;
+ CARD8 io_limit;
+ CARD8 io_base;
+
+ CARD16 mem_limit;
+ CARD16 mem_base;
+
+ CARD16 prefetch_mem_limit;
+ CARD16 prefetch_mem_base;
+#else
+ union {
+ CARD32 pp_bus_reg;
+ struct {
+ CARD8 primary_bus_number;
+ CARD8 secondary_bus_number;
+ CARD8 subordinate_bus_number;
+ CARD8 secondary_latency_timer;
+ } ppbr;
+ } ppbr;
+
+ CARD8 io_base;
+ CARD8 io_limit;
+ CARD16 secondary_status;
+
+ CARD16 mem_base;
+ CARD16 mem_limit;
+
+ CARD16 prefetch_mem_base;
+ CARD16 prefetch_mem_limit;
+#endif
+ } bg;
+ } bc;
+ union { /* Offset 0x28 - 0x2b */
+ CARD32 rsvd1;
+ CARD32 pftch_umem_base;
+ CARD32 cardbus_cis_ptr;
+ } um_c_cis;
+ union { /* Offset 0x2c - 0x2f */
+ CARD32 subsys_card_vendor;
+ CARD32 pftch_umem_limit;
+ CARD32 rsvd2;
+ struct {
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ CARD16 subsys_card;
+ CARD16 subsys_vendor;
+#else
+ CARD16 subsys_vendor;
+ CARD16 subsys_card;
+#endif
+ } ssys;
+ } um_ssys_id;
+ union { /* Offset 0x30 - 0x33 */
+ CARD32 baserom;
+ struct {
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ CARD16 io_ulimit;
+ CARD16 io_ubase;
+#else
+ CARD16 io_ubase;
+ CARD16 io_ulimit;
+#endif
+ } b_u_io;
+ } uio_rom;
+ struct {
+ CARD32 rsvd3; /* Offset 0x34 - 0x37 */
+ CARD32 rsvd4; /* Offset 0x38 - 0x3b */
+ } rsvd;
+ } cd;
+ } cx;
+ union { /* Offset 0x3c - 0x3f */
+ union { /* header type 0 */
+ CARD32 max_min_ipin_iline;
+ struct {
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ CARD8 max_lat;
+ CARD8 min_gnt;
+ CARD8 int_pin;
+ CARD8 int_line;
+#else
+ CARD8 int_line;
+ CARD8 int_pin;
+ CARD8 min_gnt;
+ CARD8 max_lat;
+#endif
+ } mmii;
+ } mmii;
+ struct { /* header type 1 */
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ CARD16 bridge_control; /* upper 8 bits reserved */
+ CARD8 rsvd2;
+ CARD8 rsvd1;
+#else
+ CARD8 rsvd1;
+ CARD8 rsvd2;
+ CARD16 bridge_control; /* upper 8 bits reserved */
+#endif
+ } bctrl;
+ } bm;
+ union { /* Offset 0x40 - 0xff */
+ CARD32 dwords[48];
+ CARD8 bytes[192];
+ } devspf;
+} pciCfgRegs;
+
+typedef union pci_cfg_spc {
+ pciCfgRegs regs;
+ CARD32 dwords[256/sizeof(CARD32)];
+ CARD8 bytes[256/sizeof(CARD8)];
+} pciCfgSpc;
+
+/*
+ * Data structure returned by xf86scanpci including contents of
+ * PCI config space header
+ */
+typedef struct pci_device {
+ PCITAG tag;
+ int busnum;
+ int devnum;
+ int funcnum;
+ pciCfgSpc cfgspc;
+ int basesize[7]; /* number of bits in base addr allocations */
+ Bool minBasesize;
+ CARD32 listed_class;
+ pointer businfo; /* pointer to secondary's bus info structure */
+ Bool fakeDevice; /* Device added by system chipset support */
+} pciDevice, *pciConfigPtr;
+
+typedef enum {
+ PCI_MEM,
+ PCI_MEM_SIZE,
+ PCI_MEM_SPARSE_BASE,
+ PCI_MEM_SPARSE_MASK,
+ PCI_IO,
+ PCI_IO_SIZE,
+ PCI_IO_SPARSE_BASE,
+ PCI_IO_SPARSE_MASK
+} PciAddrType;
+
+#define pci_device_vendor cfgspc.regs.dv_id.device_vendor
+#define pci_vendor cfgspc.regs.dv_id.dv.vendor
+#define pci_device cfgspc.regs.dv_id.dv.device
+#define pci_status_command cfgspc.regs.stat_cmd.status_command
+#define pci_command cfgspc.regs.stat_cmd.sc.command
+#define pci_status cfgspc.regs.stat_cmd.sc.status
+#define pci_class_revision cfgspc.regs.class_rev.class_revision
+#define pci_rev_id cfgspc.regs.class_rev.cr.rev_id
+#define pci_prog_if cfgspc.regs.class_rev.cr.prog_if
+#define pci_sub_class cfgspc.regs.class_rev.cr.sub_class
+#define pci_base_class cfgspc.regs.class_rev.cr.base_class
+#define pci_bist_header_latency_cache cfgspc.regs.bhlc.bist_header_latency_cache
+#define pci_cache_line_size cfgspc.regs.bhlc.bhlc.cache_line_size
+#define pci_latency_timer cfgspc.regs.bhlc.bhlc.latency_timer
+#define pci_header_type cfgspc.regs.bhlc.bhlc.header_type
+#define pci_bist cfgspc.regs.bhlc.bhlc.bist
+#define pci_cb_secondary_status cfgspc.regs.cx.cg.secondary_status
+#define pci_cb_bus_register cfgspc.regs.cx.cg.cgbr.cg_bus_reg
+#define pci_cb_primary_bus_number cfgspc.regs.cx.cg.cgbr.cgbr.primary_bus_number
+#define pci_cb_cardbus_bus_number cfgspc.regs.cx.cg.cgbr.cgbr.cardbus_bus_number
+#define pci_cb_subordinate_bus_number cfgspc.regs.cx.cg.cgbr.cgbr.subordinate_bus_number
+#define pci_cb_latency_timer cfgspc.regs.cx.cg.cgbr.cgbr.latency_timer
+#define pci_cb_membase0 cfgspc.regs.cx.cg.mem_base0
+#define pci_cb_memlimit0 cfgspc.regs.cx.cg.mem_limit0
+#define pci_cb_membase1 cfgspc.regs.cx.cg.mem_base1
+#define pci_cb_memlimit1 cfgspc.regs.cx.cg.mem_limit1
+#define pci_cb_iobase0 cfgspc.regs.cx.cg.io_base0
+#define pci_cb_iolimit0 cfgspc.regs.cx.cg.io_limit0
+#define pci_cb_iobase1 cfgspc.regs.cx.cg.io_base1
+#define pci_cb_iolimit1 cfgspc.regs.cx.cg.io_limit1
+#define pci_base0 cfgspc.regs.cx.cd.bc.dv.dv_base0
+#define pci_base1 cfgspc.regs.cx.cd.bc.dv.dv_base1
+#define pci_base2 cfgspc.regs.cx.cd.bc.dv.dv_base2
+#define pci_base3 cfgspc.regs.cx.cd.bc.dv.dv_base3
+#define pci_base4 cfgspc.regs.cx.cd.bc.dv.dv_base4
+#define pci_base5 cfgspc.regs.cx.cd.bc.dv.dv_base5
+#define pci_cardbus_cis_ptr cfgspc.regs.cx.cd.umem_c_cis.cardbus_cis_ptr
+#define pci_subsys_card_vendor cfgspc.regs.cx.cd.um_ssys_id.subsys_card_vendor
+#define pci_subsys_vendor cfgspc.regs.cx.cd.um_ssys_id.ssys.subsys_vendor
+#define pci_subsys_card cfgspc.regs.cx.cd.um_ssys_id.ssys.subsys_card
+#define pci_baserom cfgspc.regs.cx.cd.uio_rom.baserom
+#define pci_pp_bus_register cfgspc.regs.cx.cd.bc.bg.ppbr.pp_bus_reg
+#define pci_primary_bus_number cfgspc.regs.cx.cd.bc.bg.ppbr.ppbr.primary_bus_number
+#define pci_secondary_bus_number cfgspc.regs.cx.cd.bc.bg.ppbr.ppbr.secondary_bus_number
+#define pci_subordinate_bus_number cfgspc.regs.cx.cd.bc.bg.ppbr.ppbr.subordinate_bus_number
+#define pci_secondary_latency_timer cfgspc.regs.cx.cd.bc.bg.ppbr.ppbr.secondary_latency_timer
+#define pci_io_base cfgspc.regs.cx.cd.bc.bg.io_base
+#define pci_io_limit cfgspc.regs.cx.cd.bc.bg.io_limit
+#define pci_secondary_status cfgspc.regs.cx.cd.bc.bg.secondary_status
+#define pci_mem_base cfgspc.regs.cx.cd.bc.bg.mem_base
+#define pci_mem_limit cfgspc.regs.cx.cd.bc.bg.mem_limit
+#define pci_prefetch_mem_base cfgspc.regs.cx.cd.bc.bg.prefetch_mem_base
+#define pci_prefetch_mem_limit cfgspc.regs.cx.cd.bc.bg.prefetch_mem_limit
+#define pci_rsvd1 cfgspc.regs.cx.cd.um_c_cis.rsvd1
+#define pci_rsvd2 cfgspc.regs.cx.cd.um_ssys_id.rsvd2
+#define pci_prefetch_upper_mem_base cfgspc.regs.cx.cd.um_c_cis.pftch_umem_base
+#define pci_prefetch_upper_mem_limit cfgspc.regs.cx.cd.um_ssys_id.pftch_umem_limit
+#define pci_upper_io_base cfgspc.regs.cx.cd.uio_rom.b_u_io.io_ubase
+#define pci_upper_io_limit cfgspc.regs.cx.cd.uio_rom.b_u_io.io_ulimit
+#define pci_int_line cfgspc.regs.bm.mmii.mmii.int_line
+#define pci_int_pin cfgspc.regs.bm.mmii.mmii.int_pin
+#define pci_min_gnt cfgspc.regs.bm.mmii.mmii.min_gnt
+#define pci_max_lat cfgspc.regs.bm.mmii.mmii.max_lat
+#define pci_max_min_ipin_iline cfgspc.regs.bm.mmii.max_min_ipin_iline
+#define pci_bridge_control cfgspc.regs.bm.bctrl.bridge_control
+#define pci_user_config cfgspc.regs.devspf.dwords[0]
+#define pci_user_config_0 cfgspc.regs.devspf.bytes[0]
+#define pci_user_config_1 cfgspc.regs.devspf.bytes[1]
+#define pci_user_config_2 cfgspc.regs.devspf.bytes[2]
+#define pci_user_config_3 cfgspc.regs.devspf.bytes[3]
+
+typedef enum {
+ PCI_BIOS_PC = 0,
+ PCI_BIOS_OPEN_FIRMARE,
+ PCI_BIOS_HP_PA_RISC,
+ PCI_BIOS_OTHER
+} PciBiosType;
+
+/* Public PCI access functions */
+void pciInit(void);
+PCITAG pciFindFirst(CARD32 id, CARD32 mask);
+PCITAG pciFindNext(void);
+CARD32 pciReadLong(PCITAG tag, int offset);
+CARD16 pciReadWord(PCITAG tag, int offset);
+CARD8 pciReadByte(PCITAG tag, int offset);
+void pciWriteLong(PCITAG tag, int offset, CARD32 val);
+void pciWriteWord(PCITAG tag, int offset, CARD16 val);
+void pciWriteByte(PCITAG tag, int offset, CARD8 val);
+void pciSetBitsLong(PCITAG tag, int offset, CARD32 mask, CARD32 val);
+void pciSetBitsByte(PCITAG tag, int offset, CARD8 mask, CARD8 val);
+ADDRESS pciBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
+ADDRESS pciHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
+PCITAG pciTag(int busnum, int devnum, int funcnum);
+int pciGetBaseSize(PCITAG tag, int indx, Bool destructive, Bool *min);
+CARD32 pciCheckForBrokenBase(PCITAG tag,int basereg);
+pointer xf86MapPciMem(int ScreenNum, int Flags, PCITAG Tag,
+ ADDRESS Base, unsigned long Size);
+int xf86ReadPciBIOS(unsigned long Offset, PCITAG Tag, int basereg,
+ unsigned char *Buf, int Len);
+int xf86ReadPciBIOSByType(unsigned long Offset, PCITAG Tag,
+ int basereg, unsigned char *Buf,
+ int Len, PciBiosType Type);
+int xf86GetAvailablePciBIOSTypes(PCITAG Tag, int basereg,
+ PciBiosType *Buf);
+pciConfigPtr *xf86scanpci(int flags);
+
+extern int pciNumBuses;
+
+/* Domain access functions. Some of these probably shouldn't be public */
+int xf86GetPciDomain(PCITAG tag);
+pointer xf86MapDomainMemory(int ScreenNum, int Flags, PCITAG Tag,
+ ADDRESS Base, unsigned long Size);
+IOADDRESS xf86MapDomainIO(int ScreenNum, int Flags, PCITAG Tag,
+ IOADDRESS Base, unsigned long Size);
+int xf86ReadDomainMemory(PCITAG Tag, ADDRESS Base, int Len,
+ unsigned char *Buf);
+
+typedef enum {
+ ROM_BASE_PRESET = -2,
+ ROM_BASE_BIOS,
+ ROM_BASE_MEM0 = 0,
+ ROM_BASE_MEM1,
+ ROM_BASE_MEM2,
+ ROM_BASE_MEM3,
+ ROM_BASE_MEM4,
+ ROM_BASE_MEM5,
+ ROM_BASE_FIND
+} romBaseSource;
+
+#endif /* _XF86PCI_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/xf86Sbus.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/xf86Sbus.h
new file mode 100644
index 000000000..21b05cba4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/xf86Sbus.h
@@ -0,0 +1,70 @@
+/*
+ * Platform specific SBUS and OpenPROM access declarations.
+ *
+ * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
+ *
+ * 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
+ * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/xf86Sbus.h,v 1.3 2001/04/20 17:02:43 tsi Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _XF86_SBUS_H
+#define _XF86_SBUS_H
+
+#if defined(linux)
+#include <asm/types.h>
+#include <linux/fb.h>
+#include <asm/fbio.h>
+#include <asm/openpromio.h>
+#elif defined(SVR4)
+#include <sys/fbio.h>
+#include <sys/openpromio.h>
+#elif defined(__OpenBSD__) && defined(__sparc64__)
+/* XXX */
+#elif defined(CSRG_BASED)
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/fbio.h>
+#include <dev/ofw/openpromio.h>
+#else
+#include <machine/fbio.h>
+#endif
+#else
+#include <sun/fbio.h>
+#endif
+
+#ifndef FBTYPE_SUNGP3
+#define FBTYPE_SUNGP3 -1
+#endif
+#ifndef FBTYPE_MDICOLOR
+#define FBTYPE_MDICOLOR -1
+#endif
+#ifndef FBTYPE_SUNLEO
+#define FBTYPE_SUNLEO -1
+#endif
+#ifndef FBTYPE_TCXCOLOR
+#define FBTYPE_TCXCOLOR -1
+#endif
+#ifndef FBTYPE_CREATOR
+#define FBTYPE_CREATOR -1
+#endif
+
+#endif /* _XF86_SBUS_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.c
new file mode 100644
index 000000000..3d219c86f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.c
@@ -0,0 +1,1133 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.c,v 1.8 2004/01/16 15:39:38 tsi Exp $ */
+/*
+ * Copyright (C) 2002-2003 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, 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
+ * XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+
+/*
+ * This file contains the glue necessary for support of HP's ZX1 chipset.
+ * Keep in mind that this chipset is used in both Itanium2 and PA-RISC
+ * architectures.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "zx1PCI.h"
+#include "xf86.h"
+#include "xf86_OSlib.h"
+#include "Pci.h"
+
+#define MIO_BASE 0xFED00000UL /* mio register base */
+#define MIO_SIZE 0x00002000UL /* 8k, minimum */
+
+/* ZX1 mio register definitions */
+#define MIO_FUNCTION0 0x0000U
+
+#define MODULE_INFO 0x0100U
+#define STATUS_CONTROL 0x0108U
+#define DILLON_PRESENT 0x02UL
+
+#define LMMIO_DIR_BASE0 0x0300U
+#define LMMIO_DIR_MASK0 0x0308U
+#define LMMIO_DIR_ROUTE0 0x0310U
+#define LMMIO_DIR_BASE1 0x0318U
+#define LMMIO_DIR_MASK1 0x0320U
+#define LMMIO_DIR_ROUTE1 0x0328U
+#define LMMIO_DIR_BASE2 0x0330U
+#define LMMIO_DIR_MASK2 0x0338U
+#define LMMIO_DIR_ROUTE2 0x0340U
+#define LMMIO_DIR_BASE3 0x0348U
+#define LMMIO_DIR_MASK3 0x0350U
+#define LMMIO_DIR_ROUTE3 0x0358U
+#define LMMIO_DIST_BASE 0x0360U
+#define LMMIO_DIST_MASK 0x0368U
+#define LMMIO_DIST_ROUTE 0x0370U
+#define GMMIO_DIST_BASE 0x0378U
+#define PORT_DISABLE 0x02UL
+#define MAP_TO_LMMIO 0x04UL
+#define GMMIO_DIST_MASK 0x0380U
+#define GMMIO_DIST_ROUTE 0x0388U
+#define IOS_DIST_BASE 0x0390U
+#define IOS_DIST_MASK 0x0398U
+#define IOS_DIST_ROUTE 0x03A0U
+#define ROPE_CONFIG_BASE 0x03A8U
+#define VGA_ROUTE 0x03B0U
+#define VGA_ENABLE 0x8000000000000000UL
+#define VGA_LIGHT 0x4000000000000000UL
+
+#define IOS_DIR_BASE 0x03C0U
+#define IOS_DIR_MASK 0x03C8U
+#define IOS_DIR_ROUTE 0x03D0U
+#define IOS_BASE 0x03D8U
+
+#define MIO_FUNCTION1 0x1000U
+
+#define ROPE_CONFIG 0x1040U
+#define ROPE_D0 0x0100UL
+#define ROPE_D2 0x0200UL
+#define ROPE_D4 0x0400UL
+#define ROPE_D6 0x0800UL
+#define ROPE_Q0 0x1000UL
+#define ROPE_Q4 0x2000UL
+
+#define LBA_PORT0_CNTRL 0x1200U
+#define LBA_PORT1_CNTRL 0x1208U
+#define LBA_PORT2_CNTRL 0x1210U
+#define LBA_PORT3_CNTRL 0x1218U
+#define LBA_PORT4_CNTRL 0x1220U
+#define LBA_PORT5_CNTRL 0x1228U
+#define LBA_PORT6_CNTRL 0x1230U
+#define LBA_PORT7_CNTRL 0x1238U
+#define LBA_RESET_FUNCTION 0x0000000001UL
+#define LBA_CLEAR_ERROR 0x0000000010UL
+#define LBA_HARD_FAIL 0x0000000040UL
+#define LBA_RESET_COMPLETE 0x0100000000UL
+
+#define ROPE_PAGE_CONTROL 0x1418U
+
+/*
+ * Total ioa configuration space size is actually 128k, but we only need the
+ * first 64k.
+ */
+#define IOA_SIZE 0x00010000UL
+
+/* ZX1 ioa register definitions */
+#define IOA_CONFIG_ADDR 0x0040U
+#define IOA_CONFIG_DATA 0x0048U
+
+#define IOA_SECONDARY_BUS 0x0058U
+#define IOA_SUBORDINATE_BUS 0x0059U
+
+#define IOA_CONTROL 0x0108U
+#define IOA_RESET_FUNCTION 0x0000000001UL
+#define IOA_FORWARD_VGA 0x0000000008UL
+#define IOA_CLEAR_ERROR 0x0000000010UL
+#define IOA_HARD_FAIL 0x0000000040UL
+#define IOA_RESET_COMPLETE 0x0100000000UL
+
+#define IOA_LMMIO_BASE 0x0200U
+#define IOA_LMMIO_MASK 0x0208U
+#define IOA_GMMIO_BASE 0x0210U
+#define IOA_GMMIO_MASK 0x0218U
+#define IOA_WLMMIO_BASE 0x0220U
+#define IOA_WLMMIO_MASK 0x0228U
+#define IOA_WGMMIO_BASE 0x0230U
+#define IOA_WGMMIO_MASK 0x0238U
+#define IOA_IOS_BASE 0x0240U
+#define IOA_IOS_MASK 0x0248U
+#define IOA_ELMMIO_BASE 0x0250U
+#define IOA_ELMMIO_MASK 0x0258U
+#define IOA_EIOS_BASE 0x0260U
+#define IOA_EIOS_MASK 0x0268U
+#define IOA_GLOBAL_MASK 0x0270U
+#define IOA_SLAVE_CONTROL 0x0278U
+#define IOA_VGA_PEER_ENABLE 0x2000UL
+#define IOA_MSI_BASE 0x0280U
+#define IOA_MSI_MASK 0x0288U
+
+#define IOA_DMA_BASE 0x02B0U
+#define IOA_DMA_MASK 0x02B8U
+
+#define IOA_ERROR_CONFIG 0x0680U
+#define IOA_ERROR_PIOWRITE 0x0001UL
+#define IOA_ERROR_PIOREAD 0x0002UL
+#define IOA_ERROR_DMAWRITE 0x0004UL
+#define IOA_ERROR_DMAREAD 0x0008UL
+#define IOA_ERROR_CONFIG_MASTER 0x0010UL
+#define IOA_ERROR_SMART 0x0020UL
+#define IOA_ERROR_FATAL_SERR 0x0040UL
+#define IOA_ERROR_ASSERT_SERR 0x0080UL
+/* ? 0x0100UL */
+#define IOA_ERROR_LOOPBACK 0x0200UL
+#define IOA_ERROR_CONFIG_TARGET 0x0400UL
+#define IOA_ERROR_IO_MASTER 0x0800UL
+#define IOA_ERROR_IO_TARGET 0x1000UL
+#define IOA_ERROR_MEM_MASTER 0x2000UL
+#define IOA_ERROR_MEM_TARGET 0x4000UL
+#define IOA_ERROR_HF_IO_FATAL 0x8000UL
+
+#define RANGE_ENABLE 0x01UL /* In various base registers */
+
+#define IO_MASK ((1UL << 16) - 1UL)
+#define LMMIO_MASK ((1UL << 32) - 1UL)
+#ifdef __ia64__
+#define GMMIO_MASK ((1UL << 44) - 1UL)
+#else /* PA-RISC */
+#define GMMIO_MASK ((1UL << 40) - 1UL)
+#endif
+
+#define PDH_START 0xFF000000UL
+#define PDH_LAST 0xFFFFFFFFUL
+
+static CARD8 *pZX1mio = NULL,
+ *pZX1ioa = NULL;
+
+/* Per-rope data */
+static INT8 zx1_ropemap[8];
+static CARD32 zx1_pciids[8];
+static CARD64 zx1_lbacntl[8];
+static int zx1_busno[8], zx1_subno[8];
+
+/* Array of Booleans for non-empty buses */
+static INT8 zx1_busnmpt[MAX_PCI_BUSES];
+
+static pciBusFuncs_t zx1BusFuncs;
+static int zx1_fakebus = -1;
+static Bool zx1_hasvga = FALSE;
+
+static pointer pZX1IoRes[8], pZX1MemRes[8]; /* Rope resources */
+
+/* Non-PCI configuration space access macros */
+#define MIO_BYTE(offset) \
+ (*(volatile CARD8 *)(pointer)(pZX1mio + (offset)))
+#define MIO_WORD(offset) \
+ (*(volatile CARD16 *)(pointer)(pZX1mio + (offset)))
+#define MIO_LONG(offset) \
+ (*(volatile CARD32 *)(pointer)(pZX1mio + (offset)))
+#define MIO_QUAD(offset) \
+ (*(volatile CARD64 *)(pointer)(pZX1mio + (offset)))
+#define IOA_BYTE(ioa, offset) \
+ (*(volatile CARD8 *)(pointer)(pZX1ioa + ((offset) + ((ioa) << 13))))
+#define IOA_WORD(ioa, offset) \
+ (*(volatile CARD16 *)(pointer)(pZX1ioa + ((offset) + ((ioa) << 13))))
+#define IOA_LONG(ioa, offset) \
+ (*(volatile CARD32 *)(pointer)(pZX1ioa + ((offset) + ((ioa) << 13))))
+#define IOA_QUAD(ioa, offset) \
+ (*(volatile CARD64 *)(pointer)(pZX1ioa + ((offset) + ((ioa) << 13))))
+
+/* Range definitions */
+#define MAX_RANGE 16
+static CARD64 bot[MAX_RANGE], top[MAX_RANGE], msk[MAX_RANGE], siz[MAX_RANGE];
+static INT8 *pDecode[MAX_RANGE];
+static int nRange = 0;
+
+/* Track a resource range and assign a granularity to it */
+static void
+SetRange(CARD64 base, CARD64 last, CARD8 width)
+{
+ int i;
+
+ bot[nRange] = base;
+ top[nRange] = last;
+ msk[nRange] = (CARD64)(-1L);
+ if (base)
+ msk[nRange] &= (base ^ (base - 1UL)) >> 1;
+ if (last + 1UL)
+ msk[nRange] &= (last ^ (last + 1UL)) >> 1;
+ if (width < 64)
+ msk[nRange] &= (1UL << width) - 1UL;
+
+ /* Look for overlapping ranges */
+ for (i = 0; i < nRange; i++) {
+ if ((bot[i] > top[i]) ||
+ (top[nRange] < bot[i]) ||
+ (top[i] < bot[nRange]))
+ continue;
+
+ /* Merge in overlapping range */
+ if (bot[nRange] > bot[i])
+ bot[nRange] = bot[i];
+ if (top[nRange] < top[i])
+ top[nRange] = top[i];
+
+ /* Assign finer granularity */
+ msk[nRange] &= msk[i];
+ bot[i] = 1UL;
+ top[i] = 0;
+ }
+
+ nRange++;
+}
+
+/* Lookup granularity associated with the range containing 'base' */
+static int
+GetRange(CARD64 base)
+{
+ int i;
+
+ for (i = 0; i < nRange; i++) {
+ if ((bot[i] > top[i]) ||
+ (base < bot[i]) ||
+ (base > top[i]))
+ continue;
+
+ if (pDecode[i])
+ break;
+
+ /* Allocate decoding array */
+ msk[i]++;
+ siz[i] = ((top[i] - bot[i] + 1UL) / msk[i]) + 1UL;
+ pDecode[i] = xnfalloc(siz[i]);
+ (void)memset(pDecode[i], -1, siz[i]);
+ break;
+ }
+
+ return i;
+}
+
+/*
+ * Verify that 'bus' is a rope's secondary bus and return the pciConfigPtr of
+ * the associated fake PCI-to-PCI bridge.
+ */
+static pciConfigPtr
+VerifyZX1Bus(int bus)
+{
+ pciConfigPtr pPCI;
+
+ if ((bus < 0) || (bus >= pciNumBuses) ||
+ !pciBusInfo[bus] || !(pPCI = pciBusInfo[bus]->bridge) ||
+ (pPCI->busnum != zx1_fakebus) || (pPCI->funcnum != 0) ||
+ (pPCI->devnum < 0x10) || (pPCI->devnum > 0x17))
+ return NULL;
+
+ return pPCI;
+}
+
+/*
+ * This function is called to emulate the various settings in a P2P or CardBus
+ * bridge's control register on a ZX1-based system.
+ */
+static CARD16
+ControlZX1Bridge(int bus, CARD16 mask, CARD16 value)
+{
+ pciConfigPtr pPCI;
+ CARD64 tmp1, tmp2, tmp3, ropenum;
+ CARD16 current = 0;
+
+ if ((pPCI = VerifyZX1Bus(bus))) {
+ ropenum = pPCI->devnum & 0x07;
+
+ /*
+ * Start with VGA enablement. This preserves the "VGA-lite" bit
+ * in mio's VGA_ROUTE register, and the VPE bit in each ioa's
+ * SLAVE_CONTROL register.
+ */
+ tmp1 = MIO_QUAD(VGA_ROUTE);
+ tmp2 = IOA_QUAD(ropenum, IOA_CONTROL) &
+ ~(IOA_RESET_FUNCTION | IOA_CLEAR_ERROR);
+ if ((tmp1 & VGA_ENABLE) && ((tmp1 & 0x07UL) == ropenum)) {
+ current |= PCI_PCI_BRIDGE_VGA_EN;
+ if ((mask & PCI_PCI_BRIDGE_VGA_EN) &&
+ !(value & PCI_PCI_BRIDGE_VGA_EN)) {
+ MIO_QUAD(VGA_ROUTE) = tmp1 & ~VGA_ENABLE;
+ tmp2 &= ~IOA_FORWARD_VGA;
+ IOA_QUAD(ropenum, IOA_CONTROL) = tmp2;
+ }
+ } else if (mask & value & PCI_PCI_BRIDGE_VGA_EN) {
+ if (!zx1_hasvga) {
+ xf86MsgVerb(X_WARNING, 3,
+ "HP ZX1: Attempt to enable VGA routing to bus %d"
+ " through rope %ld disallowed\n", bus, ropenum);
+ value &= ~PCI_PCI_BRIDGE_VGA_EN;
+ } else {
+ if (tmp1 & VGA_ENABLE) {
+ /*
+ * VGA is routed somewhere else. Disable it.
+ */
+ MIO_QUAD(VGA_ROUTE) = 0UL;
+ tmp3 = IOA_QUAD(tmp1 & 0x07UL, IOA_CONTROL);
+ if (tmp3 & IOA_FORWARD_VGA)
+ IOA_QUAD(tmp1 & 0x07UL, IOA_CONTROL) = tmp3 &
+ ~(IOA_RESET_FUNCTION | IOA_FORWARD_VGA |
+ IOA_CLEAR_ERROR);
+ }
+ if (!(tmp2 & IOA_FORWARD_VGA)) {
+ tmp2 |= IOA_FORWARD_VGA;
+ IOA_QUAD(ropenum, IOA_CONTROL) = tmp2;
+ }
+ tmp1 = (tmp1 & ~0x07UL) | ropenum | VGA_ENABLE;
+ MIO_QUAD(VGA_ROUTE) = tmp1;
+ }
+ }
+
+ /* Move on to master abort failure enablement */
+ tmp1 = MIO_QUAD((ropenum << 3) + LBA_PORT0_CNTRL) &
+ ~(LBA_RESET_FUNCTION | LBA_CLEAR_ERROR);
+ if ((tmp1 & LBA_HARD_FAIL) || (tmp2 & IOA_HARD_FAIL)) {
+ current |= PCI_PCI_BRIDGE_MASTER_ABORT_EN;
+ if ((mask & PCI_PCI_BRIDGE_MASTER_ABORT_EN) &&
+ !(value & PCI_PCI_BRIDGE_MASTER_ABORT_EN)) {
+ if (tmp1 & LBA_HARD_FAIL)
+ MIO_QUAD((ropenum << 3) + LBA_PORT0_CNTRL) =
+ tmp1 & ~LBA_HARD_FAIL;
+ if (tmp2 & IOA_HARD_FAIL) {
+ tmp2 &= ~IOA_HARD_FAIL;
+ IOA_QUAD(ropenum, IOA_CONTROL) = tmp2;
+ }
+ }
+ } else {
+ if (mask & value & PCI_PCI_BRIDGE_MASTER_ABORT_EN) {
+ if (!(tmp1 & LBA_HARD_FAIL))
+ MIO_QUAD((ropenum << 3) + LBA_PORT0_CNTRL) =
+ tmp1 | LBA_HARD_FAIL;
+ if (!(tmp2 & IOA_HARD_FAIL)) {
+ tmp2 |= IOA_HARD_FAIL;
+ IOA_QUAD(ropenum, IOA_CONTROL) = tmp2;
+ }
+ }
+ }
+
+ /* Put emulation of any other P2P bridge control here */
+ }
+
+ return (current & ~mask) | (value & mask);
+}
+
+/* Retrieves a list of the resources routed to a rope's secondary bus */
+static void
+GetZX1BridgeResources(int bus,
+ pointer *ppIoRes,
+ pointer *ppMemRes,
+ pointer *ppPmemRes)
+{
+ pciConfigPtr pPCI = VerifyZX1Bus(bus);
+
+ if (ppIoRes) {
+ xf86FreeResList(*ppIoRes);
+ *ppIoRes =
+ pPCI ? xf86DupResList(pZX1IoRes[pPCI->devnum & 0x07]) : NULL;
+ }
+
+ if (ppMemRes) {
+ xf86FreeResList(*ppMemRes);
+ *ppMemRes =
+ pPCI ? xf86DupResList(pZX1MemRes[pPCI->devnum & 0x07]) : NULL;
+ }
+
+ if (ppPmemRes) {
+ xf86FreeResList(*ppPmemRes);
+ *ppPmemRes = NULL;
+ }
+}
+
+/* The fake bus */
+static CARD32
+zx1FakeReadLong(PCITAG tag, int offset)
+{
+ FatalError("zx1FakeReadLong(0x%lX, 0x%X) called\n",
+ (unsigned long)tag, offset);
+}
+
+static void
+zx1FakeWriteLong(PCITAG tag, int offset, CARD32 val)
+{
+ FatalError("zx1FakeWriteLong(0x%lX, 0x%X, 0x%08X) called\n",
+ (unsigned long)tag, offset, val);
+}
+
+static void
+zx1FakeSetBits(PCITAG tag, int offset, CARD32 mask, CARD32 bits)
+{
+ CARD32 val;
+
+ val = zx1FakeReadLong(tag, offset);
+ val &= ~mask;
+ val |= bits;
+ zx1FakeWriteLong(tag, offset, val);
+}
+
+static pciBusFuncs_t zx1FakeBusFuncs = {
+ zx1FakeReadLong,
+ zx1FakeWriteLong,
+ zx1FakeSetBits
+};
+
+static pciBusInfo_t zx1FakeBus = {
+ 0, /* configMech -- copied from bus 0 */
+ 0, /* numDevices -- copied from bus 0 */
+ FALSE, /* secondary */
+ 0, /* primary_bus -- dynamically set */
+#ifdef PowerMAX_OS
+ 0, /* ppc_io_base -- ignored */
+ 0, /* ppc_io_size -- ignored */
+#endif
+ &zx1FakeBusFuncs, /* funcs */
+ NULL, /* pciBusPriv -- none */
+ NULL, /* bridge -- dynamically set */
+};
+
+void
+xf86PreScanZX1(void)
+{
+ resRange range;
+ unsigned long mapSize = xf86getpagesize();
+ unsigned long tmp, base, ioaaddr;
+ unsigned long flagsd, based, lastd, maskd, routed;
+ unsigned long flags0, base0, last0, mask0, route0;
+ unsigned long flags1, base1, last1, mask1, route1;
+ unsigned long flags2, base2, last2, mask2, route2;
+ unsigned long flags3, base3, last3, mask3, route3;
+ unsigned long flagsg, baseg, lastg, maskg, routeg;
+ unsigned long flagsl, basel, lastl;
+ int i, rope;
+
+ /* Map mio registers (minimum 8k) */
+ if (mapSize < MIO_SIZE)
+ mapSize = MIO_SIZE;
+
+ if (!(pZX1mio = xf86MapVidMem(-1, VIDMEM_MMIO, MIO_BASE, mapSize)))
+ return;
+
+ /* Look for ZX1's SBA and IOC */
+ if (((MIO_LONG(MIO_FUNCTION0 + PCI_ID_REG) !=
+ DEVID(VENDOR_HP, CHIP_ZX1_SBA)) ||
+ (MIO_LONG(MIO_FUNCTION1 + PCI_ID_REG) !=
+ DEVID(VENDOR_HP, CHIP_ZX1_IOC))) &&
+ ((MIO_LONG(MIO_FUNCTION0 + PCI_ID_REG) !=
+ DEVID(VENDOR_HP, CHIP_ZX2_SBA)) ||
+ (MIO_LONG(MIO_FUNCTION1 + PCI_ID_REG) !=
+ DEVID(VENDOR_HP, CHIP_ZX2_IOC)))) {
+ xf86UnMapVidMem(-1, pZX1mio, mapSize);
+ pZX1mio = NULL;
+ return;
+ }
+
+ /* Map rope configuration space */
+ ioaaddr = MIO_QUAD(ROPE_CONFIG_BASE);
+ if (!(ioaaddr & RANGE_ENABLE) || /* No ropes */
+ ((ioaaddr = ioaaddr & ~RANGE_ENABLE) & 0x01FFFFUL) || /* Not aligned */
+ !(pZX1ioa = xf86MapVidMem(-1, VIDMEM_MMIO, ioaaddr, IOA_SIZE))) {
+ xf86UnMapVidMem(-1, pZX1mio, mapSize);
+ pZX1mio = NULL;
+ return;
+ }
+
+ for (i = 0; i < 8; i++) {
+ zx1_ropemap[i] = i;
+ zx1_lbacntl[i] = 0;
+ xf86FreeResList(pZX1IoRes[i]);
+ xf86FreeResList(pZX1MemRes[i]);
+ pZX1IoRes[i] = pZX1MemRes[i] = NULL;
+ }
+
+ /*
+ * Determine which of 8 possible ropes exist in the system. This is done
+ * by looking at their "coupling" to generate a list of candidates,
+ * whittling this list down by factoring in ROPE_PAGE_CONTROL register
+ * contents, then poking each candidate's configuration space to determine
+ * its existence.
+ */
+ tmp = MIO_QUAD(ROPE_CONFIG);
+ if (tmp & ROPE_D0)
+ zx1_ropemap[1] = 0;
+ if (tmp & ROPE_D2)
+ zx1_ropemap[3] = 2;
+ if (tmp & ROPE_D4)
+ zx1_ropemap[5] = 4;
+ if (tmp & ROPE_D6)
+ zx1_ropemap[7] = 6;
+ if (tmp & ROPE_Q0)
+ zx1_ropemap[1] = zx1_ropemap[2] = zx1_ropemap[3] = 0;
+ if (tmp & ROPE_Q4)
+ zx1_ropemap[5] = zx1_ropemap[6] = zx1_ropemap[7] = 4;
+
+ /*
+ * zx2 should allow better probing support via hard-fails, so no need to
+ * use the ROPE_PAGE_CONTROL register. Also, zx2 always has ropes 3 & 7
+ * active regardless of bundling.
+ */
+ if (MIO_LONG(MIO_FUNCTION0 + PCI_ID_REG) !=
+ DEVID(VENDOR_HP, CHIP_ZX2_SBA)) {
+
+ tmp = MIO_QUAD(ROPE_PAGE_CONTROL);
+ for (i = 0; i < 8; i++, tmp >>= 8)
+ if (!(CARD8)tmp)
+ zx1_ropemap[i] = -1;
+ } else {
+ zx1_ropemap[3] = 3;
+ zx1_ropemap[7] = 7;
+ }
+
+ for (i = 0; i < 8; ) {
+ if (zx1_ropemap[i] == i) {
+
+ /* Prevent hard-fails */
+ zx1_lbacntl[i] = MIO_QUAD((i << 3) + LBA_PORT0_CNTRL) &
+ ~(LBA_RESET_FUNCTION | LBA_CLEAR_ERROR);
+ if (zx1_lbacntl[i] & LBA_HARD_FAIL)
+ MIO_QUAD((i << 3) + LBA_PORT0_CNTRL) =
+ zx1_lbacntl[i] & ~LBA_HARD_FAIL;
+
+ /* Poke for an ioa */
+ zx1_pciids[i] = IOA_LONG(i, PCI_ID_REG);
+ switch (zx1_pciids[i]) {
+ case DEVID(VENDOR_HP, CHIP_ELROY):
+ case DEVID(VENDOR_HP, CHIP_ZX1_LBA): /* Mercury */
+ case DEVID(VENDOR_HP, CHIP_ZX1_AGP8): /* QuickSilver */
+ case DEVID(VENDOR_HP, CHIP_ZX2_LBA):
+ /* Expected vendor/device IDs */
+ zx1_busno[i] =
+ (unsigned int)IOA_BYTE(i, IOA_SECONDARY_BUS);
+ zx1_subno[i] =
+ (unsigned int)IOA_BYTE(i, IOA_SUBORDINATE_BUS);
+ break;
+
+ default:
+ if ((CARD16)(zx1_pciids[i] + 1U) > (CARD16)1U)
+ xf86MsgVerb(X_NOTICE, 0,
+ "HP ZX1: Unexpected vendor/device id 0x%08X"
+ " on rope %d\n", zx1_pciids[i], i);
+ /* Nobody home, or not the "right" kind of rope guest */
+
+ /*
+ * Restore hard-fail setting. For "active" ropes, this is done
+ * later.
+ */
+ if (zx1_lbacntl[i] & LBA_HARD_FAIL) {
+ MIO_QUAD((i << 3) + LBA_PORT0_CNTRL) = zx1_lbacntl[i];
+ zx1_lbacntl[i] = 0;
+ }
+
+ /* Ignore this rope and its couplings */
+ do {
+ zx1_ropemap[i++] = -1;
+ } while ((i < 8) && (zx1_ropemap[i] < i));
+ continue; /* Avoid over-incrementing 'i' */
+ }
+ }
+ i++;
+ }
+
+ /* Determine if VGA is currently routed */
+ tmp = MIO_QUAD(VGA_ROUTE);
+ if (tmp & VGA_ENABLE)
+ zx1_hasvga = TRUE;
+
+ /*
+ * Decode mio resource "coarse" routing (i.e. ignoring VGA). Due to the
+ * rather unusual flexibility of this chipset, this is done in a number of
+ * stages. For each of I/O and memory, first decode the relevant registers
+ * to generate ranges with an associated granularity. Overlapping ranges
+ * are merged into a larger range with the finer granularity. Each
+ * original range is then more thoroughly decoded using the granularity
+ * associated with the merged range that contains it. The result is then
+ * converted into resource lists for the common layer.
+ *
+ * Note that this doesn't care whether or not read-only bits are actually
+ * set as documented, nor that mask bits are contiguous. This does,
+ * however, factor in upper limits on I/O, LMMIO anf GMMIO addresses, and
+ * thus assumes high-order address bits are ignored rather than decoded.
+ * For example, an I/O address of 0x76543210 will be treated as 0x3210
+ * rather than considered out-of-range. In part, this handling is a
+ * consequence of the fact that high-order mask bits are zeroes instead of
+ * ones.
+ */
+
+ flagsd = 0; based = 0; lastd = 0; maskd = 0; routed = 0;
+ flags0 = 0; base0 = 0; last0 = 0; mask0 = 0; route0 = 0;
+ flags1 = 0; base1 = 0; last1 = 0; mask1 = 0; route1 = 0;
+ flags2 = 0; base2 = 0; last2 = 0; mask2 = 0; route2 = 0;
+ flags3 = 0; base3 = 0; last3 = 0; mask3 = 0; route3 = 0;
+ flagsg = 0; baseg = 0; lastg = 0; maskg = 0; routeg = 0;
+ flagsl = 0; basel = 0; lastl = 0;
+
+ if ((tmp = MIO_QUAD(IOS_DIST_BASE)) & RANGE_ENABLE) {
+ flagsd = RANGE_ENABLE;
+ maskd = MIO_QUAD(IOS_DIST_MASK);
+ based = tmp & maskd & (~RANGE_ENABLE & IO_MASK);
+ lastd = based | (~maskd & IO_MASK);
+ routed = MIO_QUAD(IOS_DIST_ROUTE) >> 58;
+ SetRange(based, lastd, routed);
+ }
+
+ if ((tmp = MIO_QUAD(IOS_DIR_BASE)) & RANGE_ENABLE) {
+ flags0 = RANGE_ENABLE;
+ mask0 = MIO_QUAD(IOS_DIR_MASK);
+ base0 = tmp & mask0 & (~RANGE_ENABLE & IO_MASK);
+ last0 = base0 | (~mask0 & IO_MASK);
+ route0 = MIO_QUAD(IOS_DIR_ROUTE) & 0x07U;
+ SetRange(base0, last0, 64);
+ }
+
+ if (flagsd) {
+ i = GetRange(based);
+ for (tmp = based; tmp <= lastd; tmp += msk[i]) {
+ if ((tmp & maskd) == based) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = zx1_ropemap[(tmp >> routed) & 0x07U];
+ }
+ }
+
+ flagsd = 0;
+ }
+
+ if (flags0) {
+ i = GetRange(base0);
+ for (tmp = base0; tmp <= last0; tmp += msk[i]) {
+ if ((tmp & mask0) == base0) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = zx1_ropemap[route0];
+ }
+ }
+
+ flags0 = 0;
+ }
+
+ for (i = 0; i < nRange; i++) {
+ if (!pDecode[i])
+ continue;
+
+ rope = pDecode[i][0];
+ for (base = tmp = 0; ++tmp < siz[i]; ) {
+ if (rope == pDecode[i][tmp])
+ continue;
+
+ if (rope >= 0) {
+ RANGE(range, (base * msk[i]) + bot[i],
+ (tmp * msk[i]) + bot[i] - 1UL,
+ RANGE_TYPE(ResExcIoBlock, 0));
+ pZX1IoRes[rope] =
+ xf86AddResToList(pZX1IoRes[rope], &range, -1);
+ }
+
+ base = tmp;
+ rope = pDecode[i][base];
+ }
+
+ xfree(pDecode[i]);
+ pDecode[i] = NULL;
+ }
+
+ nRange = 0;
+
+ /*
+ * Move on to CPU memory access decoding. For now, don't tell the common
+ * layer about CPU memory ranges that are either relocated to 0 or
+ * translated into PCI I/O.
+ */
+
+ SetRange(MIO_BASE, MIO_BASE + MIO_SIZE - 1UL, 64); /* mio */
+ SetRange(ioaaddr, ioaaddr + ((IOA_SIZE << 1) - 1UL), 64); /* ioa */
+ SetRange(PDH_START, PDH_LAST, 64); /* PDH */
+
+ SetRange(MIO_BASE, LMMIO_MASK, 64); /* Completeness */
+
+ if ((tmp = MIO_QUAD(LMMIO_DIST_BASE)) & RANGE_ENABLE) {
+ flagsd = RANGE_ENABLE;
+ maskd = MIO_QUAD(LMMIO_DIST_MASK);
+ based = tmp & maskd & (~RANGE_ENABLE & LMMIO_MASK);
+ lastd = based | (~maskd & LMMIO_MASK);
+ routed = MIO_QUAD(LMMIO_DIST_ROUTE) >> 58;
+ SetRange(based, lastd, routed);
+ }
+
+ if ((tmp = MIO_QUAD(LMMIO_DIR_BASE0)) & RANGE_ENABLE) {
+ flags0 = RANGE_ENABLE;
+ mask0 = MIO_QUAD(LMMIO_DIR_MASK0);
+ base0 = tmp & mask0 & (~RANGE_ENABLE & LMMIO_MASK);
+ last0 = base0 | (~mask0 & LMMIO_MASK);
+ route0 = MIO_QUAD(LMMIO_DIR_ROUTE0) & 0x07U;
+ SetRange(base0, last0, 64);
+ }
+
+ if ((tmp = MIO_QUAD(LMMIO_DIR_BASE1)) & RANGE_ENABLE) {
+ flags1 = RANGE_ENABLE;
+ mask1 = MIO_QUAD(LMMIO_DIR_MASK1);
+ base1 = tmp & mask1 & (~RANGE_ENABLE & LMMIO_MASK);
+ last1 = base1 | (~mask1 & LMMIO_MASK);
+ route1 = MIO_QUAD(LMMIO_DIR_ROUTE1) & 0x07U;
+ SetRange(base1, last1, 64);
+ }
+
+ if ((tmp = MIO_QUAD(LMMIO_DIR_BASE2)) & RANGE_ENABLE) {
+ flags2 = RANGE_ENABLE;
+ mask2 = MIO_QUAD(LMMIO_DIR_MASK2);
+ base2 = tmp & mask2 & (~RANGE_ENABLE & LMMIO_MASK);
+ last2 = base2 | (~mask2 & LMMIO_MASK);
+ route2 = MIO_QUAD(LMMIO_DIR_ROUTE2) & 0x07U;
+ SetRange(base2, last2, 64);
+ }
+
+ if ((tmp = MIO_QUAD(LMMIO_DIR_BASE3)) & RANGE_ENABLE) {
+ flags3 = RANGE_ENABLE;
+ mask3 = MIO_QUAD(LMMIO_DIR_MASK3);
+ base3 = tmp & mask3 & (~RANGE_ENABLE & LMMIO_MASK);
+ last3 = base3 | (~mask3 & LMMIO_MASK);
+ route3 = MIO_QUAD(LMMIO_DIR_ROUTE3) & 0x07U;
+ SetRange(base3, last3, 64);
+ }
+
+ if ((tmp = MIO_QUAD(GMMIO_DIST_BASE)) & RANGE_ENABLE) {
+ flagsg = tmp & (RANGE_ENABLE | PORT_DISABLE | MAP_TO_LMMIO);
+ maskg = MIO_QUAD(GMMIO_DIST_MASK);
+ baseg = tmp & maskg &
+ (~(RANGE_ENABLE | PORT_DISABLE | MAP_TO_LMMIO) & GMMIO_MASK);
+ lastg = baseg | (~maskg & GMMIO_MASK);
+ tmp = routeg = MIO_QUAD(GMMIO_DIST_ROUTE) >> 58;
+ if (!(flagsg & (PORT_DISABLE & MAP_TO_LMMIO)) && (tmp > 26))
+ tmp = 26;
+ SetRange(baseg, lastg, tmp);
+ }
+
+ if ((tmp = MIO_QUAD(IOS_BASE)) & RANGE_ENABLE) {
+ flagsl = RANGE_ENABLE;
+ basel = tmp & (~RANGE_ENABLE & GMMIO_MASK);
+ lastl = basel | 0x001FFFFFUL;
+ SetRange(basel, lastl, 64);
+ }
+
+ if (flagsd) {
+ i = GetRange(based);
+ for (tmp = based; tmp <= lastd; tmp += msk[i]) {
+ if ((tmp & maskd) == based) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = zx1_ropemap[(tmp >> routed) & 0x07U];
+ }
+ }
+
+ flagsd = 0;
+ }
+
+ /* LMMIO distributed range does not address anything beyond 0xFED00000 */
+ i = GetRange(MIO_BASE);
+ for (tmp = MIO_BASE; tmp <= LMMIO_MASK; tmp += msk[i]) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = -1;
+ }
+
+ /* Dillon space can sometimes be redirected to rope 0 */
+ tmp = MIO_QUAD(STATUS_CONTROL);
+ if (!(tmp & DILLON_PRESENT)) {
+ i = GetRange(PDH_START);
+ for (tmp = PDH_START; tmp <= PDH_LAST; tmp += msk[i]) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = zx1_ropemap[0];
+ }
+ }
+
+ if (flagsg) {
+ unsigned long mask = (0x07UL << routeg) | maskg;
+
+ i = GetRange(baseg);
+ for (tmp = baseg; tmp <= lastg; tmp += msk[i]) {
+ if ((tmp & maskg) == baseg) {
+ base = (tmp - bot[i]) / msk[i];
+
+ if ((flagsg & MAP_TO_LMMIO) ||
+ (!(flagsg & PORT_DISABLE) &&
+ (tmp <= ((tmp & mask) | 0x03FFFFFFUL)))) {
+ pDecode[i][base] = -1;
+ } else {
+ pDecode[i][base] = zx1_ropemap[(tmp >> routeg) & 0x07U];
+ }
+ }
+ }
+
+ flagsg = 0;
+ }
+
+ if (flagsl) {
+ i = GetRange(basel);
+ for (tmp = basel; tmp <= lastl; tmp += msk[i]) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = -1;
+ }
+
+ flagsl = 0;
+ }
+
+ /* For now, assume directed LMMIO ranges don't overlap with each other */
+ if (flags0) {
+ i = GetRange(base0);
+ for (tmp = base0; tmp <= last0; tmp += msk[i]) {
+ if ((tmp & mask0) == base0) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = zx1_ropemap[route0];
+ }
+ }
+
+ flags0 = 0;
+ }
+
+ if (flags1) {
+ i = GetRange(base1);
+ for (tmp = base1; tmp <= last1; tmp += msk[i]) {
+ if ((tmp & mask1) == base1) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = zx1_ropemap[route1];
+ }
+ }
+
+ flags1 = 0;
+ }
+
+ if (flags2) {
+ i = GetRange(base2);
+ for (tmp = base2; tmp <= last2; tmp += msk[i]) {
+ if ((tmp & mask2) == base2) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = zx1_ropemap[route2];
+ }
+ }
+
+ flags2 = 0;
+ }
+
+ if (flags3) {
+ i = GetRange(base3);
+ for (tmp = base3; tmp <= last3; tmp += msk[i]) {
+ if ((tmp & mask3) == base3) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = zx1_ropemap[route3];
+ }
+ }
+
+ flags3 = 0;
+ }
+
+ /* Claim iao config area */
+ i = GetRange(ioaaddr);
+ for (tmp = ioaaddr; tmp < ioaaddr + (IOA_SIZE << 1); tmp += msk[i]) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = -1;
+ }
+
+ /* Claim mio config area */
+ i = GetRange(MIO_BASE);
+ for (tmp = MIO_BASE; tmp < (MIO_BASE + MIO_SIZE); tmp += msk[i]) {
+ base = (tmp - bot[i]) / msk[i];
+ pDecode[i][base] = -1;
+ }
+
+ for (i = 0; i < nRange; i++) {
+ if (!pDecode[i])
+ continue;
+
+ rope = pDecode[i][0];
+ for (base = tmp = 0; ++tmp < siz[i]; ) {
+ if (rope == pDecode[i][tmp])
+ continue;
+
+ if (rope >= 0) {
+ RANGE(range, (base * msk[i]) + bot[i],
+ (tmp * msk[i]) + bot[i] - 1UL,
+ RANGE_TYPE(ResExcMemBlock, 0));
+ pZX1MemRes[rope] =
+ xf86AddResToList(pZX1MemRes[rope], &range, -1);
+ }
+
+ base = tmp;
+ rope = pDecode[i][base];
+ }
+
+ xfree(pDecode[i]);
+ pDecode[i] = NULL;
+ }
+
+ nRange = 0;
+
+ return;
+}
+
+/* This is called to finalise the results of a PCI bus scan */
+void
+xf86PostScanZX1(void)
+{
+ pciConfigPtr pPCI, *ppPCI, *ppPCI2;
+ pciBusInfo_t *pBusInfo;
+ int i, idx;
+
+ if (!pZX1mio)
+ return;
+
+ (void)memset(zx1_busnmpt, FALSE, sizeof(zx1_busnmpt));
+ pBusInfo = pciBusInfo[0];
+
+ /*
+ * Certain 2.4 & 2.5 Linux kernels add fake PCI devices. Remove them to
+ * prevent any possible interference with our PCI validation.
+ *
+ * Also, if VGA isn't routed on server entry, determine if VGA routing
+ * needs to be enabled while the server is running.
+ */
+ idx = 0;
+ ppPCI = ppPCI2 = xf86scanpci(0); /* Recursion is only apparent */
+ while ((pPCI = *ppPCI2++)) {
+ switch (pPCI->pci_device_vendor) {
+ case DEVID(VENDOR_HP, CHIP_ELROY):
+ case DEVID(VENDOR_HP, CHIP_ZX1_SBA): /* Pluto function 0 */
+ case DEVID(VENDOR_HP, CHIP_ZX1_IOC): /* Pluto function 1 */
+ case DEVID(VENDOR_HP, CHIP_ZX1_LBA): /* Mercury */
+ case DEVID(VENDOR_HP, CHIP_ZX1_AGP8): /* QuickSilver */
+ case DEVID(VENDOR_HP, CHIP_ZX2_SBA):
+ case DEVID(VENDOR_HP, CHIP_ZX2_IOC):
+ case DEVID(VENDOR_HP, CHIP_ZX2_LBA):
+ xfree(pPCI); /* Remove it */
+ continue;
+
+ default:
+ *ppPCI++ = pPCI;
+ idx++;
+
+ zx1_busnmpt[pPCI->busnum] = TRUE;
+
+ if (zx1_hasvga)
+ continue;
+
+ switch (pPCI->pci_base_class) {
+ case PCI_CLASS_PREHISTORIC:
+ if (pPCI->pci_sub_class == PCI_SUBCLASS_PREHISTORIC_VGA)
+ break;
+ continue;
+
+ case PCI_CLASS_DISPLAY:
+ if (pPCI->pci_sub_class == PCI_SUBCLASS_DISPLAY_VGA)
+ break;
+ continue;
+
+ default:
+ continue;
+ }
+
+ zx1_hasvga = TRUE;
+ continue;
+ }
+ }
+
+ /*
+ * Restore hard-fail settings and figure out the actual secondary and
+ * subordinate bus numbers.
+ */
+ for (i = 0; i < 8; i++) {
+ if (zx1_ropemap[i] != i)
+ continue;
+
+ if (zx1_lbacntl[i] & LBA_HARD_FAIL)
+ MIO_QUAD((i << 3) + LBA_PORT0_CNTRL) = zx1_lbacntl[i];
+
+ while ((zx1_busno[i] < zx1_subno[i]) && !pciBusInfo[zx1_subno[i]])
+ zx1_subno[i]--;
+
+ if (zx1_fakebus <= zx1_subno[i])
+ zx1_fakebus = zx1_subno[i] + 1;
+
+ while (!zx1_busnmpt[zx1_busno[i]]) {
+ if (zx1_busno[i]) /* Info for bus zero is in static storage */
+ xfree(pciBusInfo[zx1_busno[i]]);
+ pciBusInfo[zx1_busno[i]++] = NULL;
+ if (zx1_busno[i] > zx1_subno[i])
+ break;
+ }
+ }
+
+ if (zx1_fakebus >= pciNumBuses) {
+ if (zx1_fakebus >= pciMaxBusNum)
+ FatalError("HP ZX1: No room for fake PCI bus\n");
+ pciNumBuses = zx1_fakebus + 1;
+ }
+
+ /* Set up our extra bus functions */
+ zx1BusFuncs = *(pBusInfo->funcs);
+ zx1BusFuncs.pciControlBridge = ControlZX1Bridge;
+ zx1BusFuncs.pciGetBridgeResources = GetZX1BridgeResources;
+
+ /* Set up our own fake bus to act as the root segment */
+ zx1FakeBus.configMech = pBusInfo->configMech;
+ zx1FakeBus.numDevices = pBusInfo->numDevices;
+ zx1FakeBus.primary_bus = zx1_fakebus;
+ pciBusInfo[zx1_fakebus] = &zx1FakeBus;
+
+ /* Add the fake bus' host bridge */
+ if (++idx >= MAX_PCI_DEVICES)
+ FatalError("HP ZX1: No room for fake Host-to-PCI bridge\n");
+ *ppPCI++ = zx1FakeBus.bridge = pPCI = xnfcalloc(1, sizeof(pciDevice));
+ pPCI->tag = PCI_MAKE_TAG(zx1_fakebus, 0, 0);
+ pPCI->busnum = zx1_fakebus;
+ /* pPCI->devnum = pPCI->funcnum = 0; */
+ pPCI->pci_device_vendor = DEVID(VENDOR_HP, CHIP_ZX1_SBA);
+ pPCI->pci_base_class = PCI_CLASS_BRIDGE;
+ /* pPCI->pci_sub_class = PCI_SUBCLASS_BRIDGE_HOST; */
+ pPCI->fakeDevice = TRUE;
+
+#ifdef OLD_FORMAT
+ xf86MsgVerb(X_INFO, 2, "PCI: BusID 0x%.2x,0x%02x,0x%1x "
+ "ID 0x%04x,0x%04x Rev 0x%02x Class 0x%02x,0x%02x\n",
+ pPCI->busnum, pPCI->devnum, pPCI->funcnum,
+ pPCI->pci_vendor, pPCI->pci_device, pPCI->pci_rev_id,
+ pPCI->pci_base_class, pPCI->pci_sub_class);
+#else
+ xf86MsgVerb(X_INFO, 2, "PCI: %.2x:%02x:%1x: chip %04x,%04x"
+ " card %04x,%04x rev %02x class %02x,%02x,%02x hdr %02x\n",
+ pPCI->busnum, pPCI->devnum, pPCI->funcnum,
+ pPCI->pci_vendor, pPCI->pci_device,
+ pPCI->pci_subsys_vendor, pPCI->pci_subsys_card,
+ pPCI->pci_rev_id, pPCI->pci_base_class,
+ pPCI->pci_sub_class, pPCI->pci_prog_if,
+ pPCI->pci_header_type);
+#endif
+
+ /* Add a fake PCI-to-PCI bridge to represent each active rope */
+ for (i = 0; i < 8; i++) {
+ if ((zx1_ropemap[i] != i) || (zx1_busno[i] > zx1_subno[i]) ||
+ !(pBusInfo = pciBusInfo[zx1_busno[i]]))
+ continue;
+
+ if (++idx >= MAX_PCI_DEVICES)
+ FatalError("HP ZX1: No room for fake PCI-to-PCI bridge\n");
+ *ppPCI++ = pPCI = xnfcalloc(1, sizeof(pciDevice));
+ pPCI->busnum = zx1_fakebus;
+ pPCI->devnum = i | 0x10;
+ /* pPCI->funcnum = 0; */
+ pPCI->tag = PCI_MAKE_TAG(zx1_fakebus, pPCI->devnum, 0);
+ pPCI->pci_device_vendor = zx1_pciids[i];
+ pPCI->pci_base_class = PCI_CLASS_BRIDGE;
+ pPCI->pci_sub_class = PCI_SUBCLASS_BRIDGE_PCI;
+ pPCI->pci_header_type = 1;
+ pPCI->pci_primary_bus_number = zx1_fakebus;
+ pPCI->pci_secondary_bus_number = zx1_busno[i];
+ pPCI->pci_subordinate_bus_number = zx1_subno[i];
+ pPCI->fakeDevice = TRUE;
+
+ pBusInfo->bridge = pPCI;
+ pBusInfo->secondary = TRUE;
+ pBusInfo->primary_bus = zx1_fakebus;
+
+ /* Plug in chipset routines */
+ pBusInfo->funcs = &zx1BusFuncs;
+
+ /* Set bridge control register for scanpci utility */
+ pPCI->pci_bridge_control = ControlZX1Bridge(zx1_busno[i], 0, 0);
+
+#ifdef OLD_FORMAT
+ xf86MsgVerb(X_INFO, 2, "PCI: BusID 0x%.2x,0x%02x,0x%1x "
+ "ID 0x%04x,0x%04x Rev 0x%02x Class 0x%02x,0x%02x\n",
+ pPCI->busnum, pPCI->devnum, pPCI->funcnum,
+ pPCI->pci_vendor, pPCI->pci_device, pPCI->pci_rev_id,
+ pPCI->pci_base_class, pPCI->pci_sub_class);
+#else
+ xf86MsgVerb(X_INFO, 2, "PCI: %.2x:%02x:%1x: chip %04x,%04x"
+ " card %04x,%04x rev %02x class %02x,%02x,%02x hdr %02x\n",
+ pPCI->busnum, pPCI->devnum, pPCI->funcnum,
+ pPCI->pci_vendor, pPCI->pci_device,
+ pPCI->pci_subsys_vendor, pPCI->pci_subsys_card,
+ pPCI->pci_rev_id, pPCI->pci_base_class,
+ pPCI->pci_sub_class, pPCI->pci_prog_if,
+ pPCI->pci_header_type);
+#endif
+ }
+
+ *ppPCI = NULL; /* Terminate array */
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.h
new file mode 100644
index 000000000..2795b4459
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.h
@@ -0,0 +1,40 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/zx1PCI.h,v 1.1 2003/02/23 20:26:49 tsi Exp $ */
+/*
+ * Copyright (C) 2002-2003 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, 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
+ * XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef PCI_ZX1_H
+#define PCI_ZX1_H 1
+
+#include <X11/Xdefs.h>
+
+void xf86PreScanZX1(void);
+void xf86PostScanZX1(void);
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/Imakefile
new file mode 100644
index 000000000..261bd6bab
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/Imakefile
@@ -0,0 +1,35 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/dgux/Imakefile,v 1.8 2002/10/11 01:46:59 dawes Exp $
+#include <Server.tmpl>
+
+BIOS_MOD = bios_DGmmap
+
+SRCS = dgux_init.c dgux_video.c IO_utils.c dgux_io.c $(BIOS_MOD).c VTsw_noop.c \
+ dgux_kbd.c dgux_kbdEv.c dgux_tty.c std_mouse.c std_mseEv.c \
+ stdResource.c stdPci.c sigiostubs.c pm_noop.c kmod_noop.c agp_noop.c
+
+OBJS = dgux_init.o dgux_video.o IO_utils.o dgux_io.o $(BIOS_MOD).o VTsw_noop.o \
+ dgux_kbd.o dgux_kbdEv.o dgux_tty.o std_mouse.o std_mseEv.o \
+ stdResource.o stdPci.o sigiostubs.o pm_noop.o kmod_noop.o agp_noop.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC)
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+LinkSourceFile(VTsw_noop,../shared)
+LinkSourceFile(IO_utils,../shared)
+LinkSourceFile(std_mouse,../shared)
+LinkSourceFile(std_mseEv,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/bios_DGmmap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/bios_DGmmap.c
new file mode 100644
index 000000000..95aad7a12
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/bios_DGmmap.c
@@ -0,0 +1,70 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/dgux/bios_DGmmap.c,v 1.3 2000/02/11 22:36:02 dawes Exp $ */
+/*
+ * INTEL DG/UX RELEASE 4.20 MU03
+ * Copyright 1997 Takis Psarogiannakopoulos Cambridge,UK
+ * <takis@dpmms.cam.ac.uk>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ * XCONSORTIUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FITNESS, IN NO EVENT SHALL XCONSORTIUM BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * Read the BIOS via mmap() to the device /dev/mem.
+ */
+int xf86ReadBIOS(Base, Offset, Buf, Len)
+unsigned long Base;
+unsigned long Offset;
+unsigned char *Buf;
+int Len;
+{
+ int fd;
+ unsigned char *ptr;
+ int psize;
+ int mlen;
+
+ if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
+ {
+ ErrorF("xf86ReadBios: Failed to open %s (%s)\n", DEV_MEM,
+ strerror(errno));
+ return(-1);
+ }
+ psize = xf86getpagesize();
+ Offset += Base & (psize - 1);
+ Base &= ~(psize - 1);
+ mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+ ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ, MAP_SHARED,
+ fd, (off_t)Base);
+ if ((int)ptr == -1)
+ {
+ ErrorF("xf86ReadBios: %s mmap failed\n", DEV_MEM);
+ close(fd);
+ return(-1);
+ }
+ (void)memcpy(Buf, (void *)(ptr + Offset), Len);
+ (void)munmap((caddr_t)ptr, mlen);
+ (void)close(fd);
+ return(Len);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_init.c
new file mode 100644
index 000000000..b7282a004
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_init.c
@@ -0,0 +1,182 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/dgux/dgux_init.c,v 1.1 1998/12/13 07:37:46 dawes Exp $ */
+/*
+ * INTEL DG/UX RELEASE 4.20 MU03
+ * Copyright 1997 Takis Psarogiannakopoulos Cambridge,UK
+ * <takis@dpmms.cam.ac.uk>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ * XCONSORTIUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FITNESS, IN NO EVENT SHALL XCONSORTIUM BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+
+static Bool KeepTty = FALSE;
+static Bool Protect0 = FALSE;
+static int VTnum = -1;
+
+extern void xf86VTRequest(
+ int
+);
+
+void xf86OpenConsole()
+{
+ int i;
+ int fd;
+ char vtname[14];
+
+ if (serverGeneration == 1)
+ {
+ /* check if we're run with euid==0 */
+ if (geteuid() != 0)
+ {
+ FatalError("xf86OpenConsole: Server must be suid root\n");
+ }
+ if (Protect0)
+ {
+ int fd = -1;
+
+ if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0)
+ {
+ ErrorF("xf86OpenConsole: cannot open /dev/zero (%s)\n",
+ strerror(errno));
+ }
+ else
+ {
+ if ((int)mmap(0, 0x1000, PROT_NONE,
+ MAP_FIXED | MAP_SHARED, fd, 0) == -1)
+ {
+ ErrorF("xf86OpenConsole: failed to protect page 0 (%s)\n",
+ strerror(errno));
+ }
+ close(fd);
+ }
+ }
+ if (VTnum != -1)
+ {
+ xf86Info.vtno = VTnum;
+ }
+ else
+ {
+ if ((fd = open("/dev/console",O_WRONLY,0)) < 0)
+ {
+ FatalError(
+ "xf86OpenConsole: Cannot open system tty (/dev/console), (%s)\n",
+ strerror(errno));
+ }
+ close(fd);
+ }
+ xf86Info.vtno=0;
+ ErrorF(" (Intel DG/ux: using VT number: systty%d)\n\n", xf86Info.vtno);
+
+ sprintf(vtname,"/dev/console");
+
+ xf86Config(FALSE); /* Read XF86Config */
+
+ if (!KeepTty)
+ {
+ setpgrp();
+ }
+
+ if ((xf86Info.consoleFd = open("/dev/console", O_RDWR|O_NDELAY, 0)) < 0)
+ {
+ FatalError("xf86OpenConsole: Cannot open %s (%s)\n",
+ vtname, strerror(errno));
+ }
+
+
+
+ if ((xf86Info.kbdFd = open("/dev/keybd", O_RDONLY|O_NDELAY, 0)) < 0)
+ {
+ FatalError("xf86OpenConsole: Cannot open keyboard (/dev/keybd), (%s)\n", strerror(errno));
+ }
+ /* change ownerships and Grab all other system consoles */
+ chown(vtname, getuid(), getgid());
+ chown("/dev/syscon", getuid(), getgid());
+ chown("/dev/systty", getuid(), getgid());
+ if (!KeepTty)
+ {
+ /*
+ * Detach from the controlling tty to avoid char loss
+ */
+ if ((i = open("/dev/tty",O_RDWR)) >= 0)
+ {
+ ioctl(i, TIOCNOTTY, 0);
+ close(i);
+ }
+ }
+ }
+ else
+ {
+ /* serverGeneration != 1 */
+ if (!xf86VTSema)
+ sleep(5);
+ }
+ return;
+}
+
+void xf86CloseConsole()
+{
+ close(xf86Info.kbdFd); /* Close the keyboard */
+ close(xf86Info.consoleFd); /* Close the system console */
+ return;
+}
+
+int xf86ProcessArgument(argc, argv, i)
+int argc;
+char *argv[];
+int i;
+{
+ if (!strcmp(argv[i], "-keeptty"))
+ {
+ KeepTty = TRUE;
+ return(1);
+ }
+ if (!strcmp(argv[i], "-protect0"))
+ {
+ Protect0 = TRUE;
+ return(1);
+ }
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+ {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ return(1);
+ }
+ return(0);
+}
+
+void xf86UseMsg()
+{
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_io.c
new file mode 100644
index 000000000..b66051f63
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_io.c
@@ -0,0 +1,96 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/dgux/dgux_io.c,v 1.3 2002/10/11 01:40:34 dawes Exp $ */
+/*
+ * INTEL DG/UX RELEASE 4.20 MU03
+ * Copyright 1997 Takis Psarogiannakopoulos Cambridge,UK
+ * <takis@dpmms.cam.ac.uk>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ * XCONSORTIUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FITNESS, IN NO EVENT SHALL XCONSORTIUM BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+
+
+
+void xf86SoundKbdBell(loudness, pitch, duration)
+int loudness;
+int pitch;
+int duration;
+{
+ if (loudness && pitch)
+ {
+
+ /*
+ * We use KBD_TONE_HIGH to avoid putting the server
+ * to sleep
+ */
+ ioctl(xf86Info.kbdFd, KBD_TONE_HIGH,
+ ((1193190 / pitch) & 0xffff) |
+ (((unsigned long)duration *
+ loudness / 50) << 16));
+
+ }
+}
+
+
+
+void xf86MouseInit(mouse)
+MouseDevPtr mouse;
+{
+ return;
+}
+
+
+
+/* Added for DG/ux: only RDONLY will not crash the Xserver */
+int xf86MouseOn(mouse)
+MouseDevPtr mouse;
+{
+ if ((mouse->mseFd = open(mouse->mseDevice, O_RDONLY|O_NDELAY)) < 0)
+ {
+ if (xf86Info.allowMouseOpenFail) {
+ ErrorF("Cannot open mouse (%s) - Continuing...\n",
+ strerror(errno));
+ return(-2);
+ }
+ FatalError("Cannot open mouse (%s)\n", strerror(errno));
+ }
+
+ xf86SetupMouse(mouse);
+
+ /* Flush any pending input */
+ ioctl(mouse->mseFd, TCFLSH, 0);
+ return(mouse->mseFd);
+}
+
+#include "xf86OSKbd.h"
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_kbd.c
new file mode 100644
index 000000000..7c25fb390
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_kbd.c
@@ -0,0 +1,120 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/dgux/dgux_kbd.c,v 1.1 1998/12/13 07:37:46 dawes Exp $ */
+/*
+ * INTEL DG/UX RELEASE 4.20 MU03
+ * Copyright 1997 Takis Psarogiannakopoulos Cambridge,UK
+ * <takis@dpmms.cam.ac.uk>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ * XCONSORTIUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FITNESS, IN NO EVENT SHALL XCONSORTIUM BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* *Contents*
+
+ 1 xf86KbdSetLeds
+ 2 xf86KbdGetLeds
+ 3 xf86SetKbdRepeat
+ 4 xf86KbdInit()
+ 5 xf86KbdOn()
+ 6 xf86KbdOff()
+
+*/
+
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+
+
+static struct termios kbdtty;
+
+
+/* ADDED FOR INTEL DGUX */
+void xf86SetKbdLeds(leds)
+int leds;
+{
+ ioctl(xf86Info.kbdFd, KBD_SET_LED, leds);
+}
+
+
+
+/* ADDED FOR INTEL DGUX */
+int xf86GetKbdLeds()
+{
+ int leds;
+
+ ioctl(xf86Info.kbdFd, KBD_GET_STATE, &leds);
+ return(leds);
+}
+
+/* ADDED FOR INTEL DGUX */
+void xf86SetKbdRepeat(char rad)
+{
+ return;
+}
+
+
+
+
+/* ADDED FOR INTEL DGUX */
+
+void xf86KbdInit()
+{
+ tcgetattr(xf86Info.kbdFd, &kbdtty);
+}
+
+
+
+
+
+/* ADDED FOR INTEL DGUX */
+
+int xf86KbdOn()
+{
+ struct termios nTty;
+
+ nTty = kbdtty;
+ nTty.c_iflag = IGNPAR | IGNBRK;
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME] = 0;
+ nTty.c_cc[VMIN] = 1;
+ cfsetispeed(&nTty, 9600);
+ cfsetospeed(&nTty, 9600);
+ tcsetattr(xf86Info.kbdFd, TCSANOW, &nTty);
+ return(xf86Info.kbdFd);
+}
+
+
+
+
+
+/* Intel DG/ux */
+int xf86KbdOff()
+{
+ tcsetattr(xf86Info.kbdFd, TCSANOW, &kbdtty);
+ return(xf86Info.kbdFd);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_kbdEv.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_kbdEv.c
new file mode 100644
index 000000000..1651f20d8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_kbdEv.c
@@ -0,0 +1,47 @@
+/* $XFree86$ */
+/*
+ * INTEL DG/UX RELEASE 4.20 MU02
+ * Copyright 1997 Takis Psarogiannakopoulos Cambridge,UK
+ * <takis@dpmms.cam.ac.uk>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ * XCONSORTIUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FITNESS, IN NO EVENT SHALL XCONSORTIUM BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+
+void xf86KbdEvents()
+{
+ unsigned char rBuf[64];
+ int nBytes, i;
+
+ if ((nBytes = read( xf86Info.kbdFd, (char *)rBuf, sizeof(rBuf))) > 0)
+ {
+ for (i = 0; i < nBytes; i++)
+ xf86PostKbdEvent(rBuf[i]);
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_tty.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_tty.c
new file mode 100644
index 000000000..b6dee0421
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_tty.c
@@ -0,0 +1,175 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/dgux/dgux_tty.c,v 1.1 1998/12/13 07:37:47 dawes Exp $ */
+/*
+ * INTEL DG/UX RELEASE 4.20 MU03
+ * Copyright 1997 Takis Psarogiannakopoulos Cambridge,UK
+ * <takis@dpmms.cam.ac.uk>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ * XCONSORTIUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FITNESS, IN NO EVENT SHALL XCONSORTIUM BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* BSD (POSIX) Flavor tty for ix86 DG/ux R4.20MU03 */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+#include "xf86_Config.h"
+
+static Bool not_a_tty = FALSE;
+
+void xf86SetMouseSpeed(mouse, old, new, cflag)
+MouseDevPtr mouse;
+int old;
+int new;
+unsigned cflag;
+{
+ struct termios tty;
+ char *c;
+
+ if (not_a_tty)
+ return;
+
+ if (tcgetattr(mouse->mseFd, &tty) < 0)
+ {
+ not_a_tty = TRUE;
+ ErrorF("Warning: %s unable to get status of mouse fd (%s)\n",
+ mouse->mseDevice, strerror(errno));
+ return;
+ }
+
+ /* this will query the initial baudrate only once */
+ if (mouse->oldBaudRate < 0) {
+ switch (cfgetispeed(&tty))
+ {
+ case B9600:
+ mouse->oldBaudRate = 9600;
+ break;
+ case B4800:
+ mouse->oldBaudRate = 4800;
+ break;
+ case B2400:
+ mouse->oldBaudRate = 2400;
+ break;
+ case B1200:
+ default:
+ mouse->oldBaudRate = 1200;
+ break;
+ }
+ }
+
+ tty.c_iflag = IGNBRK | IGNPAR;
+ tty.c_oflag = 0;
+ tty.c_lflag = 0;
+ tty.c_cflag = (tcflag_t)cflag;
+ tty.c_cc[VTIME] = 0;
+ tty.c_cc[VMIN] = 1;
+
+ switch (old)
+ {
+ case 9600:
+ cfsetispeed(&tty, B9600);
+ cfsetospeed(&tty, B9600);
+ break;
+ case 4800:
+ cfsetispeed(&tty, B4800);
+ cfsetospeed(&tty, B4800);
+ break;
+ case 2400:
+ cfsetispeed(&tty, B2400);
+ cfsetospeed(&tty, B2400);
+ break;
+ case 1200:
+ default:
+ cfsetispeed(&tty, B1200);
+ cfsetospeed(&tty, B1200);
+ }
+
+ if (tcsetattr(mouse->mseFd, TCSADRAIN, &tty) < 0)
+ {
+ if (xf86Info.allowMouseOpenFail) {
+ ErrorF("Unable to set status of mouse fd (%s) - Continuing...\n",
+ strerror(errno));
+ return;
+ }
+ xf86FatalError("Unable to set status of mouse fd (%s)\n",
+ strerror(errno));
+ }
+
+ switch (new)
+ {
+ case 9600:
+ c = "*q";
+ cfsetispeed(&tty, B9600);
+ cfsetospeed(&tty, B9600);
+ break;
+ case 4800:
+ c = "*p";
+ cfsetispeed(&tty, B4800);
+ cfsetospeed(&tty, B4800);
+ break;
+ case 2400:
+ c = "*o";
+ cfsetispeed(&tty, B2400);
+ cfsetospeed(&tty, B2400);
+ break;
+ case 1200:
+ default:
+ c = "*n";
+ cfsetispeed(&tty, B1200);
+ cfsetospeed(&tty, B1200);
+ }
+
+ if (mouse->mseType == P_LOGIMAN || mouse->mseType == P_LOGI)
+ {
+ if (write(mouse->mseFd, c, 2) != 2)
+ {
+ if (xf86AllowMouseOpenFail) {
+ ErrorF("Unable to write to mouse fd (%s) - Continuing...\n",
+ strerror(errno));
+ return;
+ }
+ xf86FatalError("Unable to write to mouse fd (%s)\n",
+ strerror(errno));
+ }
+ }
+ usleep(100000);
+
+ if (tcsetattr(mouse->mseFd, TCSADRAIN, &tty) < 0)
+ {
+ if (xf86AllowMouseOpenFail) {
+ ErrorF("Unable to set status of mouse fd (%s) - Continuing...\n",
+ strerror(errno));
+ return;
+ }
+ xf86FatalError("Unable to set status of mouse fd (%s)\n",
+ strerror(errno));
+ }
+}
+
+/* ADDED FOR X 3.3.2.3 */
+int
+xf86FlushInput(fd)
+int fd;
+{
+ return tcflush(fd, TCIFLUSH);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_video.c
new file mode 100644
index 000000000..25336d68a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/dgux/dgux_video.c
@@ -0,0 +1,441 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/dgux/dgux_video.c,v 1.6tsi Exp $ */
+/*
+ * INTEL DG/UX RELEASE 4.20 MU03
+ * Copyright 1997 Takis Psarogiannakopoulos Cambridge,UK
+ * <takis@dpmms.cam.ac.uk>
+ *
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.
+ * XFREE86 PROJECT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FITNESS, IN NO EVENT SHALL XCONSORTIUM BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+/* Stuff for the SET_IOPL() ,RESET_IOPL() */
+/* #include <fcntl.h> */
+static int io_takis;
+int set_takis;
+
+
+/***************************************************************************/
+/* SET_IOPL() and RESET_IOPL() section for ix86 DG/ux 4.20MU03 */
+/***************************************************************************/
+
+
+int SET_IOPL()
+{
+ io_takis=open("/dev/console", O_RDWR,0);
+ if ((io_takis) < 0)
+ {
+ return(-1);
+ }
+ set_takis = ioctl(io_takis,KDENABIO,0);
+
+ if (set_takis < 0)
+ {
+ return(-1);
+ }
+ return(1);
+}
+
+
+
+
+void RESET_IOPL()
+{
+
+ ioctl(io_takis,KDDISABIO,0);
+ close(io_takis);
+ return;
+
+}
+
+/***************************************************************************/
+/* DG/ux Video Memory Mapping part */
+/***************************************************************************/
+
+#undef HAS_SVR3_MMAPDRV /* ix86 DG/ux is a typical SVR4 without SVR3_MMAPDRV */
+
+Bool xf86LinearVidMem()
+{
+ return(TRUE);
+}
+
+pointer
+xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
+{
+ pointer base;
+ int fd;
+
+ fd = open(DEV_MEM, (Flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
+ if (fd < 0)
+ {
+ FatalError("xf86MapVidMem: failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ base = mmap((caddr_t)0, Size,
+ (Flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, fd, (off_t)Base);
+ close(fd);
+ if (base == MAP_FAILED)
+ {
+ FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
+ "xf86MapVidMem", Size, Base, strerror(errno));
+ }
+
+ return(base);
+}
+
+void xf86UnMapVidMem(ScreenNum, Region, Base, Size)
+int ScreenNum;
+int Region;
+pointer Base;
+unsigned long Size;
+{
+ munmap(Base, Size);
+}
+
+/***************************************************************************/
+/* I/O Permissions section */
+/***************************************************************************/
+
+#define ALWAYS_USE_EXTENDED
+#ifdef ALWAYS_USE_EXTENDED
+
+static Bool ScreenEnabled[MAXSCREENS];
+static Bool ExtendedEnabled = FALSE;
+static Bool InitDone = FALSE;
+
+void
+xf86ClearIOPortList(ScreenNum)
+int ScreenNum;
+{
+ if (!InitDone)
+ {
+ int i;
+ for (i = 0; i < MAXSCREENS; i++)
+ ScreenEnabled[i] = FALSE;
+ InitDone = TRUE;
+ }
+ return;
+}
+
+void
+xf86AddIOPorts(ScreenNum, NumPorts, Ports)
+int ScreenNum;
+int NumPorts;
+unsigned *Ports;
+{
+ return;
+}
+
+void
+xf86EnableIOPorts(ScreenNum)
+int ScreenNum;
+{
+ int i;
+
+ ScreenEnabled[ScreenNum] = TRUE;
+
+ if (ExtendedEnabled)
+ return;
+
+ if (SET_IOPL() < 0)
+ {
+ FatalError("%s: Failed to set IOPL for extended I/O\n",
+ "xf86EnableIOPorts");
+ }
+ ExtendedEnabled = TRUE;
+
+ return;
+}
+
+void
+xf86DisableIOPorts(ScreenNum)
+int ScreenNum;
+{
+ int i;
+
+ ScreenEnabled[ScreenNum] = FALSE;
+
+ if (!ExtendedEnabled)
+ return;
+
+ for (i = 0; i < MAXSCREENS; i++)
+ if (ScreenEnabled[i])
+ return;
+
+ RESET_IOPL();
+ ExtendedEnabled = FALSE;
+
+ return;
+}
+
+#else /* !ALWAYS_USE_EXTENDED */
+
+#define DISABLED 0
+#define NON_EXTENDED 1
+#define EXTENDED 2
+
+static unsigned *EnabledPorts[MAXSCREENS];
+static int NumEnabledPorts[MAXSCREENS];
+static Bool ScreenEnabled[MAXSCREENS];
+static Bool ExtendedPorts[MAXSCREENS];
+static Bool ExtendedEnabled = FALSE;
+static Bool InitDone = FALSE;
+static struct kd_disparam OrigParams;
+
+void xf86ClearIOPortList(ScreenNum)
+int ScreenNum;
+{
+ if (!InitDone)
+ {
+ xf86InitPortLists(EnabledPorts, NumEnabledPorts, ScreenEnabled,
+ ExtendedPorts, MAXSCREENS);
+ if (ioctl(xf86Info.consoleFd, KDDISPTYPE, &OrigParams) < 0)
+ {
+ FatalError("%s: Could not get display parameters\n",
+ "xf86ClearIOPortList");
+ }
+ InitDone = TRUE;
+ return;
+ }
+ ExtendedPorts[ScreenNum] = FALSE;
+ if (EnabledPorts[ScreenNum] != (unsigned *)NULL)
+ xfree(EnabledPorts[ScreenNum]);
+ EnabledPorts[ScreenNum] = (unsigned *)NULL;
+ NumEnabledPorts[ScreenNum] = 0;
+}
+
+void xf86AddIOPorts(ScreenNum, NumPorts, Ports)
+int ScreenNum;
+int NumPorts;
+unsigned *Ports;
+{
+ int i;
+
+ if (!InitDone)
+ {
+ FatalError("xf86AddIOPorts: I/O control lists not initialised\n");
+ }
+ EnabledPorts[ScreenNum] = xrealloc(EnabledPorts[ScreenNum],
+ (NumEnabledPorts[ScreenNum]+NumPorts)*sizeof(unsigned));
+ for (i = 0; i < NumPorts; i++)
+ {
+ EnabledPorts[ScreenNum][NumEnabledPorts[ScreenNum] + i] =
+ Ports[i];
+ if (Ports[i] > 0x3FF)
+ ExtendedPorts[ScreenNum] = TRUE;
+ }
+ NumEnabledPorts[ScreenNum] += NumPorts;
+}
+
+void xf86EnableIOPorts(ScreenNum)
+int ScreenNum;
+{
+ struct kd_disparam param;
+ int i, j;
+
+ if (ScreenEnabled[ScreenNum])
+ return;
+
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ if (ExtendedPorts[i] && (ScreenEnabled[i] || i == ScreenNum))
+ {
+ if (SET_IOPL() < 0)
+ {
+ FatalError("%s: Failed to set IOPL for extended I/O\n",
+ "xf86EnableIOPorts");
+ }
+ ExtendedEnabled = TRUE;
+ break;
+ }
+ }
+ if (ExtendedEnabled && i == MAXSCREENS)
+ {
+ RESET_IOPL();
+ ExtendedEnabled = FALSE;
+ }
+ if (ioctl(xf86Info.consoleFd, KDDISPTYPE, &param) < 0)
+ {
+ FatalError("%s: Could not get display parameters\n",
+ "xf86EnableIOPorts");
+ }
+ for (i = 0; i < NumEnabledPorts[ScreenNum]; i++)
+ {
+ unsigned port = EnabledPorts[ScreenNum][i];
+
+ if (port > 0x3FF)
+ continue;
+
+ if (!xf86CheckPorts(port, EnabledPorts, NumEnabledPorts,
+ ScreenEnabled, MAXSCREENS))
+ {
+ continue;
+ }
+ for (j=0; j < MKDIOADDR; j++)
+ {
+ if (param.ioaddr[j] == port)
+ {
+ break;
+ }
+ }
+ if (j == MKDIOADDR)
+ {
+ if (ioctl(xf86Info.consoleFd, KDADDIO, port) < 0)
+ {
+ FatalError("%s: Failed to enable port 0x%x\n",
+ "xf86EnableIOPorts", port);
+ }
+ }
+ }
+ if (ioctl(xf86Info.consoleFd, KDENABIO, 0) < 0)
+ {
+ FatalError("xf86EnableIOPorts: I/O port enable failed (%s)\n",
+ strerror(errno));
+ }
+ ScreenEnabled[ScreenNum] = TRUE;
+ return;
+}
+
+void xf86DisableIOPorts(ScreenNum)
+int ScreenNum;
+{
+ struct kd_disparam param;
+ int i, j;
+
+ if (!ScreenEnabled[ScreenNum])
+ return;
+
+ ScreenEnabled[ScreenNum] = FALSE;
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ if (ScreenEnabled[i] && ExtendedPorts[i])
+ break;
+ }
+ if (ExtendedEnabled && i == MAXSCREENS)
+ {
+ RESET_IOPL();
+ ExtendedEnabled = FALSE;
+ }
+ /* Turn off I/O before changing the access list */
+ ioctl(xf86Info.consoleFd, KDDISABIO, 0);
+ if (ioctl(xf86Info.consoleFd, KDDISPTYPE, &param) < 0)
+ {
+ ErrorF("%s: Could not get display parameters\n",
+ "xf86DisableIOPorts");
+ return;
+ }
+
+ for (i=0; i < MKDIOADDR; i++)
+ {
+ if (param.ioaddr[i] == 0)
+ {
+ break;
+ }
+ if (!xf86CheckPorts(param.ioaddr[i], EnabledPorts,
+ NumEnabledPorts, ScreenEnabled, MAXSCREENS))
+ {
+ continue;
+ }
+ for (j=0; j < MKDIOADDR; j++)
+ {
+ if (param.ioaddr[i] == OrigParams.ioaddr[j])
+ {
+ /*
+ * Port was one of the original ones; don't
+ * touch it.
+ */
+ break;
+ }
+ }
+ if (j == MKDIOADDR)
+ {
+ /*
+ * We added this port, so remove it.
+ */
+ ioctl(xf86Info.consoleFd, KDDELIO, param.ioaddr[i]);
+ }
+ }
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ if (ScreenEnabled[i])
+ {
+ ioctl(xf86Info.consoleFd, KDENABIO, 0);
+ break;
+ }
+ }
+ return;
+}
+#endif
+
+void xf86DisableIOPrivs()
+{
+ if (ExtendedEnabled)
+ RESET_IOPL();
+ return;
+}
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+
+Bool xf86DisableInterrupts()
+{
+
+#ifdef __GNUC__
+ __asm__ __volatile__("cli");
+#else
+ asm("cli");
+#endif /* __GNUC__ */
+
+ return(TRUE);
+}
+
+void xf86EnableInterrupts()
+{
+
+#ifdef __GNUC__
+ __asm__ __volatile__("sti");
+#else
+ asm("sti");
+#endif /* __GNUC__ */
+
+ return;
+}
+
+
+void
+xf86MapReadSideEffects(int ScreenNum, int Flags, pointer Base,
+ unsigned long Size)
+{
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/Imakefile
new file mode 100644
index 000000000..7716ed348
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/Imakefile
@@ -0,0 +1,40 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/hurd/Imakefile,v 1.14 2002/10/11 01:46:59 dawes Exp $
+
+#include <Server.tmpl>
+
+BIOS_MOD = bios_mmap
+
+MOUSESRC = hurd_mouse.c
+MOUSEOBJ = hurd_mouse.o
+
+SRCS = hurd_init.c hurd_video.c hurd_io.c libc_wrapper.c $(BIOS_MOD).c \
+ VTsw_noop.c posix_tty.c $(MOUSESRC) \
+ stdResource.c stdPci.c sigiostubs.c pm_noop.c kmod_noop.c agp_noop.c
+
+OBJS = hurd_init.o hurd_video.o hurd_io.o libc_wrapper.o $(BIOS_MOD).o \
+ VTsw_noop.o posix_tty.o $(MOUSEOBJ) \
+ stdResource.o stdPci.o sigiostubs.o pm_noop.o kmod_noop.o agp_noop.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(SERVERSRC)/mi
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+
+LinkSourceFile(VTsw_noop.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+
+DependTarget()
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/bios_mmap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/bios_mmap.c
new file mode 100644
index 000000000..132e755e2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/bios_mmap.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright 1997 by UCHIYAMA Yasushi
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of UCHIYAMA Yasushi not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. UCHIYAMA Yasushi makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XFree86$ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include<mach.h>
+#include<device/device.h>
+
+#include <X11/X.h>
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#define BIOS_SIZE 0x20000
+
+int
+xf86ReadBIOS(unsigned long Base,unsigned long Offset,unsigned char *Buf,int Len)
+{
+ mach_port_t device,iopl_dev;
+ memory_object_t iopl_mem;
+ vm_address_t addr = (vm_address_t)0; /* serach starting address */
+ kern_return_t err;
+
+
+ err = get_privileged_ports (NULL, &device);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86ReadBIOS() can't get_privileged_ports. (%s)\n",strerror(errno));
+ }
+ err = device_open(device,D_READ|D_WRITE,"iopl",&iopl_dev);
+ mach_port_deallocate (mach_task_self (), device);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86ReadBIOS() can't device_open. (%s)\n",strerror(errno));
+ }
+ err = device_map(iopl_dev,VM_PROT_READ|VM_PROT_WRITE, Base , BIOS_SIZE ,&iopl_mem,0);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86ReadBIOS() can't device_map. (%s)\n",strerror(errno));
+ }
+ err = vm_map(mach_task_self(),
+ &addr,
+ BIOS_SIZE,
+ 0,
+ TRUE,
+ iopl_mem,
+ Base,
+ FALSE,
+ VM_PROT_READ|VM_PROT_WRITE,
+ VM_PROT_READ|VM_PROT_WRITE,
+ VM_INHERIT_SHARE);
+ mach_port_deallocate(mach_task_self(),iopl_mem);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86ReadBIOS() can't vm_map. (%s)\n",strerror(errno));
+ }
+
+ memcpy(Buf,(void*)((int)addr + Offset), Len);
+
+ err = vm_deallocate(mach_task_self(), addr, BIOS_SIZE);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86ReadBIOS() can't vm_deallocate. (%s)\n",strerror(errno));
+ }
+
+ return Len;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_init.c
new file mode 100644
index 000000000..aec5b3d46
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_init.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright 1997,1998 by UCHIYAMA Yasushi
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of UCHIYAMA Yasushi not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. UCHIYAMA Yasushi makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/hurd/hurd_init.c,v 1.1 1998/08/16 10:25:48 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include <stdio.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#include <assert.h>
+#include <mach.h>
+
+int
+xf86ProcessArgument( int argc,char **argv, int i )
+{
+ return 0;
+}
+void
+xf86UseMsg()
+{
+ return;
+}
+
+
+void
+xf86OpenConsole()
+{
+ if( serverGeneration == 1 )
+ {
+ kern_return_t err;
+ mach_port_t device;
+ int fd;
+ err = get_privileged_ports( NULL, &device );
+ if( err )
+ {
+ errno = err;
+ FatalError( "xf86KbdInit can't get_privileged_ports. (%s)\n" , strerror(errno) );
+ }
+ mach_port_deallocate (mach_task_self (), device);
+
+ if( ( fd = open( "/dev/kbd" , O_RDONLY|O_NONBLOCK ) ) < 0 )
+ {
+ fprintf( stderr , "Cannot open keyboard (%s)\n",strerror(errno) );
+ exit(1);
+ }
+ xf86Info.consoleFd = fd;
+ }
+ return;
+}
+
+void
+xf86CloseConsole()
+{
+ close( xf86Info.consoleFd );
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_io.c
new file mode 100644
index 000000000..32b4bc71d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_io.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright 1997,1998 by UCHIYAMA Yasushi
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of UCHIYAMA Yasushi not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. UCHIYAMA Yasushi makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/hurd/hurd_io.c,v 1.8 2002/10/11 01:40:35 dawes Exp $ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include "mipointer.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include <stdio.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#include <assert.h>
+#include <mach.h>
+#include <sys/ioctl.h>
+
+typedef unsigned short kev_type; /* kd event type */
+typedef unsigned char Scancode;
+
+struct mouse_motion {
+ short mm_deltaX; /* units? */
+ short mm_deltaY;
+};
+
+typedef struct {
+ kev_type type; /* see below */
+ struct timeval time; /* timestamp */
+ union { /* value associated with event */
+ boolean_t up; /* MOUSE_LEFT .. MOUSE_RIGHT */
+ Scancode sc; /* KEYBD_EVENT */
+ struct mouse_motion mmotion; /* MOUSE_MOTION */
+ } value;
+} kd_event;
+
+/*
+ * kd_event ID's.
+ */
+#define MOUSE_LEFT 1 /* mouse left button up/down */
+#define MOUSE_MIDDLE 2
+#define MOUSE_RIGHT 3
+#define MOUSE_MOTION 4 /* mouse motion */
+#define KEYBD_EVENT 5 /* key up/down */
+
+/***********************************************************************
+ * Keyboard
+ **********************************************************************/
+void
+xf86SoundKbdBell(int loudness,int pitch,int duration)
+{
+ return;
+}
+
+void
+xf86SetKbdLeds(int leds)
+{
+ return;
+}
+
+int
+xf86GetKbdLeds()
+{
+ return 0;
+}
+
+void
+xf86SetKbdRepeat(char rad)
+{
+ return;
+}
+
+void
+xf86KbdInit()
+{
+ return;
+}
+int
+xf86KbdOn()
+{
+ int data = 1;
+ if( ioctl( xf86Info.consoleFd, _IOW('k', 1, int),&data) < 0)
+ FatalError("Cannot set event mode on keyboard (%s)\n",strerror(errno));
+ return xf86Info.consoleFd;
+}
+int
+xf86KbdOff()
+{
+ int data = 2;
+ if( ioctl( xf86Info.consoleFd, _IOW('k', 1, int),&data) < 0)
+ FatalError("can't reset keyboard mode (%s)\n",strerror(errno));
+}
+
+void
+xf86KbdEvents()
+{
+ kd_event ke;
+ while( read(xf86Info.consoleFd, &ke, sizeof(ke)) == sizeof(ke) )
+ xf86PostKbdEvent(ke.value.sc);
+}
+
+#include "xf86OSKbd.h"
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_mouse.c
new file mode 100644
index 000000000..84a5c46da
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_mouse.c
@@ -0,0 +1,300 @@
+/*
+ * Copyright 1997,1998 by UCHIYAMA Yasushi
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of UCHIYAMA Yasushi not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. UCHIYAMA Yasushi makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/hurd/hurd_mouse.c,v 1.7 2000/02/10 22:33:44 dawes Exp $ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include "mipointer.h"
+
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "xf86_OSlib.h"
+
+#include <stdio.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#include <assert.h>
+#include <mach.h>
+#include <sys/ioctl.h>
+
+typedef unsigned short kev_type; /* kd event type */
+typedef unsigned char Scancode;
+
+struct mouse_motion {
+ short mm_deltaX; /* units? */
+ short mm_deltaY;
+};
+
+typedef struct {
+ kev_type type; /* see below */
+ struct timeval time; /* timestamp */
+ union { /* value associated with event */
+ boolean_t up; /* MOUSE_LEFT .. MOUSE_RIGHT */
+ Scancode sc; /* KEYBD_EVENT */
+ struct mouse_motion mmotion; /* MOUSE_MOTION */
+ } value;
+} kd_event;
+
+/*
+ * kd_event ID's.
+ */
+#define MOUSE_LEFT 1 /* mouse left button up/down */
+#define MOUSE_MIDDLE 2
+#define MOUSE_RIGHT 3
+#define MOUSE_MOTION 4 /* mouse motion */
+#define KEYBD_EVENT 5 /* key up/down */
+
+#define NUMEVENTS 64
+
+/*
+ * OsMouseProc --
+ * Handle the initialization, etc. of a mouse
+ */
+static int
+OsMouseProc(DeviceIntPtr pPointer, int what)
+{
+ InputInfoPtr pInfo;
+ MouseDevPtr pMse;
+ unsigned char map[MSE_MAXBUTTONS + 1];
+ int nbuttons;
+
+ pInfo = pPointer->public.devicePrivate;
+ pMse = pInfo->private;
+ pMse->device = pPointer;
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+
+ for (nbuttons = 0; nbuttons < MSE_MAXBUTTONS; ++nbuttons)
+ map[nbuttons + 1] = nbuttons + 1;
+
+ InitPointerDeviceStruct((DevicePtr)pPointer,
+ map,
+ min(pMse->buttons, MSE_MAXBUTTONS),
+ miPointerGetMotionEvents,
+ pMse->Ctrl,
+ miPointerGetMotionBufferSize());
+
+ /* X valuator */
+ xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 0);
+ /* Y valuator */
+ xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 1);
+ xf86MotionHistoryAllocate(pInfo);
+ break;
+
+ case DEVICE_ON:
+ pInfo->fd = xf86OpenSerial(pInfo->options);
+ if (pInfo->fd == -1)
+ xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
+ else {
+ pMse->buffer = XisbNew(pInfo->fd,
+ NUMEVENTS * sizeof(kd_event));
+ if (!pMse->buffer) {
+ xfree(pMse);
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+ } else {
+ xf86FlushInput(pInfo->fd);
+ AddEnabledDevice(pInfo->fd);
+ }
+ }
+ pMse->lastButtons = 0;
+ pMse->lastMappedButtons = 0;
+ pMse->emulateState = 0;
+ pPointer->public.on = TRUE;
+ break;
+
+ case DEVICE_OFF:
+ case DEVICE_CLOSE:
+ if (pInfo->fd != -1) {
+ RemoveEnabledDevice(pInfo->fd);
+ if (pMse->buffer) {
+ XisbFree(pMse->buffer);
+ pMse->buffer = NULL;
+ }
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+ }
+ pPointer->public.on = FALSE;
+ usleep(300000);
+ break;
+ }
+ return Success;
+}
+
+/*
+ * OsMouseReadInput --
+ * Get some events from our queue. Process all outstanding events now.
+ */
+static void
+OsMouseReadInput(InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse;
+ static kd_event eventList[NUMEVENTS];
+ int n, c;
+ kd_event *event = eventList;
+ unsigned char *pBuf;
+
+ pMse = pInfo->private;
+
+ XisbBlockDuration(pMse->buffer, -1);
+ pBuf = (unsigned char *)eventList;
+ n = 0;
+ while ((c = XisbRead(pMse->buffer)) >= 0 && n < sizeof(eventList))
+ pBuf[n++] = (unsigned char)c;
+
+ if (n == 0)
+ return;
+
+ n /= sizeof(kd_event);
+ while( n-- ) {
+ int buttons = pMse->lastButtons;
+ int dx = 0, dy = 0;
+ switch (event->type) {
+ case MOUSE_RIGHT:
+ buttons = buttons & 6 |(event->value.up ? 0 : 1);
+ break;
+ case MOUSE_MIDDLE:
+ buttons = buttons & 5 |(event->value.up ? 0 : 2);
+ break;
+ case MOUSE_LEFT:
+ buttons = buttons & 3 |(event->value.up ? 0 : 4) ;
+ break;
+ case MOUSE_MOTION:
+ dx = event->value.mmotion.mm_deltaX;
+ dy = - event->value.mmotion.mm_deltaY;
+ break;
+ default:
+ ErrorF("Bad mouse event (%d)\n",event->type);
+ continue;
+ }
+ pMse->PostEvent(pInfo, buttons, dx, dy, 0, 0);
+ ++event;
+ }
+ return;
+}
+
+static Bool
+OsMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ MouseDevPtr pMse;
+
+ /* This is called when the protocol is "OSMouse". */
+
+ pMse = pInfo->private;
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ /* Check if the device can be opened. */
+ pInfo->fd = xf86OpenSerial(pInfo->options);
+ if (pInfo->fd == -1) {
+ if (xf86GetAllowMouseOpenFail())
+ xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
+ else {
+ xf86Msg(X_ERROR, "%s: cannot open input device\n", pInfo->name);
+ xfree(pMse);
+ return FALSE;
+ }
+ }
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local procs. */
+ pInfo->device_control = OsMouseProc;
+ pInfo->read_input = OsMouseReadInput;
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+
+static int
+SupportedInterfaces(void)
+{
+ /* XXX Need to check this. */
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO;
+}
+
+static const char *internalNames[] = {
+ "OSMouse",
+ NULL
+};
+
+static const char **
+BuiltinNames(void)
+{
+ return internalNames;
+}
+
+static Bool
+CheckProtocol(const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++)
+ if (xf86NameCmp(protocol, internalNames[i]) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+/* XXX Is this appropriate? If not, this function should be removed. */
+static const char *
+DefaultProtocol(void)
+{
+ return "OSMouse";
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+ p->BuiltinNames = BuiltinNames;
+ p->DefaultProtocol = DefaultProtocol;
+ p->CheckProtocol = CheckProtocol;
+ p->PreInit = OsMousePreInit;
+ return p;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_video.c
new file mode 100644
index 000000000..ecb8df1db
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/hurd/hurd_video.c
@@ -0,0 +1,181 @@
+/*
+ * Copyright 1997, 1998 by UCHIYAMA Yasushi
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of UCHIYAMA Yasushi not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. UCHIYAMA Yasushi makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/hurd/hurd_video.c,v 1.3 1999/04/29 12:24:52 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <mach.h>
+#include <device/device.h>
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/**************************************************************************
+ * Video Memory Mapping section
+ ***************************************************************************/
+pointer
+xf86MapVidMem(int ScreenNum,int Flags, unsigned long Base, unsigned long Size)
+{
+ mach_port_t device,iopl_dev;
+ memory_object_t iopl_mem;
+ kern_return_t err;
+ vm_address_t addr=(vm_address_t)0;
+
+ err = get_privileged_ports (NULL, &device);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86MapVidMem() can't get_privileged_ports. (%s)\n",strerror(errno));
+ }
+ err = device_open(device,D_READ|D_WRITE,"iopl",&iopl_dev);
+ mach_port_deallocate (mach_task_self(), device);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86MapVidMem() can't device_open. (%s)\n",strerror(errno));
+ }
+
+ err = device_map(iopl_dev,VM_PROT_READ|VM_PROT_WRITE, Base , Size ,&iopl_mem,0);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86MapVidMem() can't device_map. (%s)\n",strerror(errno));
+ }
+ err = vm_map(mach_task_self(),
+ &addr,
+ Size,
+ 0, /* mask */
+ TRUE, /* anywhere */
+ iopl_mem,
+ (vm_offset_t)Base,
+ FALSE, /* copy on write */
+ VM_PROT_READ|VM_PROT_WRITE,
+ VM_PROT_READ|VM_PROT_WRITE,
+ VM_INHERIT_SHARE);
+ mach_port_deallocate(mach_task_self(),iopl_mem);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86MapVidMem() can't vm_map.(iopl_mem) (%s)\n",strerror(errno));
+ }
+ mach_port_deallocate(mach_task_self(),iopl_dev);
+ if( err )
+ {
+ errno = err;
+ FatalError("xf86MapVidMem() can't mach_port_deallocate.(iopl_dev) (%s)\n",strerror(errno));
+ }
+ return (pointer)addr;
+}
+
+void
+xf86UnMapVidMem(int ScreenNum,pointer Base,unsigned long Size)
+{
+ kern_return_t err = vm_deallocate(mach_task_self(), (int)Base, Size);
+ if( err )
+ {
+ errno = err;
+ ErrorF("xf86UnMapVidMem: can't dealloc framebuffer space (%s)\n",strerror(errno));
+ }
+ return;
+}
+
+Bool
+xf86LinearVidMem()
+{
+ return(TRUE);
+}
+
+/**************************************************************************
+ * I/O Permissions section
+ ***************************************************************************/
+Bool
+xf86EnableIO()
+{
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ return;
+}
+
+void
+xf86ClearIOPortList(int ScreenNum)
+{
+ return;
+}
+void
+xf86AddIOPorts(int ScreenNum,int NumPorts,unsigned int *Ports)
+{
+ return;
+}
+void
+xf86EnableIOPorts(int ScreenNum)
+{
+ return;
+}
+
+void
+xf86DisableIOPorts(int ScreenNum)
+{
+ return;
+}
+void
+xf86DisableIOPrivs()
+{
+ return;
+}
+/**************************************************************************
+ * Interrupt Handling section
+ **************************************************************************/
+Bool
+xf86DisableInterrupts()
+{
+ return TRUE;
+}
+void
+xf86EnableInterrupts()
+{
+ return;
+}
+
+void
+xf86MapReadSideEffects(int ScreenNum, int Flags, pointer Base,
+ unsigned long Size)
+{
+}
+
+Bool
+xf86CheckMTRR(int s)
+{
+ return FALSE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/int10Defines.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/int10Defines.h
new file mode 100644
index 000000000..56e10cf67
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/int10Defines.h
@@ -0,0 +1,90 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/int10Defines.h,v 1.4 2003/08/24 17:37:03 dawes Exp $ */
+/*
+ * Copyright (c) 2000-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).
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _INT10DEFINES_H_
+#define _INT10DEFINES_H_ 1
+
+#ifdef _VM86_LINUX
+
+#include <asm/vm86.h>
+
+#define CPU_R(type,name,num) \
+ (((type *)&(((struct vm86_struct *)REG->cpuRegs)->regs.name))[num])
+#define CPU_RD(name,num) CPU_R(CARD32,name,num)
+#define CPU_RW(name,num) CPU_R(CARD16,name,num)
+#define CPU_RB(name,num) CPU_R(CARD8,name,num)
+
+#define X86_EAX CPU_RD(eax,0)
+#define X86_EBX CPU_RD(ebx,0)
+#define X86_ECX CPU_RD(ecx,0)
+#define X86_EDX CPU_RD(edx,0)
+#define X86_ESI CPU_RD(esi,0)
+#define X86_EDI CPU_RD(edi,0)
+#define X86_EBP CPU_RD(ebp,0)
+#define X86_EIP CPU_RD(eip,0)
+#define X86_ESP CPU_RD(esp,0)
+#define X86_EFLAGS CPU_RD(eflags,0)
+
+#define X86_FLAGS CPU_RW(eflags,0)
+#define X86_AX CPU_RW(eax,0)
+#define X86_BX CPU_RW(ebx,0)
+#define X86_CX CPU_RW(ecx,0)
+#define X86_DX CPU_RW(edx,0)
+#define X86_SI CPU_RW(esi,0)
+#define X86_DI CPU_RW(edi,0)
+#define X86_BP CPU_RW(ebp,0)
+#define X86_IP CPU_RW(eip,0)
+#define X86_SP CPU_RW(esp,0)
+#define X86_CS CPU_RW(cs,0)
+#define X86_DS CPU_RW(ds,0)
+#define X86_ES CPU_RW(es,0)
+#define X86_SS CPU_RW(ss,0)
+#define X86_FS CPU_RW(fs,0)
+#define X86_GS CPU_RW(gs,0)
+
+#define X86_AL CPU_RB(eax,0)
+#define X86_BL CPU_RB(ebx,0)
+#define X86_CL CPU_RB(ecx,0)
+#define X86_DL CPU_RB(edx,0)
+
+#define X86_AH CPU_RB(eax,1)
+#define X86_BH CPU_RB(ebx,1)
+#define X86_CH CPU_RB(ecx,1)
+#define X86_DH CPU_RB(edx,1)
+
+#elif defined(_X86EMU)
+
+#include "xf86x86emu.h"
+
+#endif
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/Imakefile
new file mode 100644
index 000000000..8ef246842
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/Imakefile
@@ -0,0 +1,142 @@
+XCOMM $XConsortium: Imakefile /main/10 1996/10/19 18:06:19 kaleb $
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile,v 3.45 2002/09/16 18:06:13 eich Exp $
+
+#include <Server.tmpl>
+
+#if BuildXInputExt
+# if JoystickSupport
+ JOYSTICK_SRC = lnx_jstk.c
+# endif
+# if DoLoadableServer
+SHARED_CFLAGS = PositionIndependentCFlags
+# else
+# if JoystickSupport
+ JOYSTICK_OBJ = lnx_jstk.o
+# endif
+# endif
+#endif
+
+#if HasMTRRSupport
+MTRRDEFINES = -DHAS_MTRR_SUPPORT
+#endif
+
+DRI_SRC = sigio.c
+DRI_OBJ = sigio.o
+
+MOUSESRC = lnx_mouse.c
+MOUSEOBJ = lnx_mouse.o
+
+KBDSRC = lnx_kbd.c lnx_KbdMap.c at_scancode.c
+KBDOBJ = lnx_kbd.o lnx_KbdMap.o at_scancode.o
+
+#if defined(i386Architecture) || defined(ia64Architecture) || defined(AMD64Architecture)
+RES_SRCS=stdResource.c
+RES_OBJS=stdResource.o
+#else
+RES_SRCS=lnxResource.c
+RES_OBJS=lnxResource.o
+#endif
+
+#if defined(AlphaArchitecture)
+PLATFORM_SRC=lnx_ev56.c xf86Axp.c lnx_axp.c
+PLATFORM_OBJ=lnx_ev56.o xf86Axp.o lnx_axp.o
+#endif
+#if defined (ia64Architecture)
+PLATFORM_SRC=ia64Pci.c lnx_ia64.c
+PLATFORM_OBJ=ia64Pci.o lnx_ia64.o
+PLATFORM_DEFINES=-DOS_PROBE_PCI_CHIPSET=lnxProbePciChipset
+#endif
+
+#if DoOSFontRestore
+FONTSRC=lnx_font.c
+FONTOBJ=lnx_font.o
+# ifndef FontRestoreCheckOsVersion
+# define FontRestoreCheckOsVersion YES
+# endif
+FONT_DEFINES=-DDO_OS_FONTRESTORE -DCHECK_OS_VERSION=FontRestoreCheckOsVersion
+#endif
+
+SRCS = lnx_init.c lnx_video.c lnx_io.c libc_wrapper.c bios_mmap.c \
+ VTsw_usl.c std_kbdEv.c posix_tty.c lnx_acpi.c $(MOUSESRC) \
+ lnx_pci.c vidmem.c lnx_apm.c $(JOYSTICK_SRC) $(DRI_SRC) $(RES_SRCS) \
+ $(PLATFORM_SRC) lnx_kmod.c lnx_agp.c $(FONTSRC) $(KBDSRC) /*wcHelper.c*/
+
+OBJS = lnx_init.o lnx_video.o lnx_io.o libc_wrapper.o bios_mmap.o \
+ VTsw_usl.o std_kbdEv.o posix_tty.o lnx_acpi.o $(MOUSEOBJ) \
+ lnx_pci.o vidmem.o lnx_apm.o $(JOYSTICK_OBJ) $(DRI_OBJ) $(RES_OBJS) \
+ $(PLATFORM_OBJ) lnx_kmod.o lnx_agp.o $(FONTOBJ) $(KBDOBJ) /*wcHelper.o*/
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(XF86OSSRC)/shared \
+ -I$(XF86OSSRC)/bus -I$(DRMSRCDIR)/shared-core
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(MTRRDEFINES) $(RESDEFINES) $(PLATFORM_DEFINES) $(FONT_DEFINES) -DHAVE_SYSV_IPC
+
+#if defined(AlphaArchitecture)
+SpecialObjectRule(lnx_ev56.o, lnx_ev56.c, -mcpu=ev56)
+#endif
+
+#if DoOSFontRestore
+SpecialObjectRule(VTsw_usl.o, VTsw_usl.c, -DOSHEADER=\"lnx.h\" -DOSSWITCHAWAY="lnx_switchaway()")
+#endif
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+#if BuildXF86DRI
+DRISUBDIR = drm
+#endif
+TESTVAR = XF86INT10_BUILD
+
+#if XF86INT10_BUILD > X86EMU_GENERIC
+INT10SUBDIR = int10
+#endif
+
+#if BuildXF86DRI || (XF86INT10_BUILD > X86EMU_GENERIC)
+#define IHaveSubdirs
+SUBDIRS = $(DRISUBDIR) $(INT10SUBDIR)
+#endif
+
+#ifdef IHaveSubdirs
+MakeSubdirs($(SUBDIRS))
+DependSubdirs($(SUBDIRS))
+#endif
+
+#if BuildXInputExt
+# if DoLoadableServer
+# if JoystickSupport
+AllTarget(lnx_jstk.o)
+#if 0
+InstallDynamicModule(lnx_jstk.o,$(MODULEDIR),input)
+#endif
+# endif
+# endif
+#endif
+
+LinkSourceFile(bios_mmap.c,../shared)
+LinkSourceFile(std_kbdEv.c,../shared)
+LinkSourceFile(at_scancode.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(vidmem.c,../shared)
+LinkSourceFile(VTsw_usl.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+
+LinkSourceFile($(DRI_SRC),../shared)
+
+#if defined(i386Architecture) || defined(ia64Architecture) || defined (AMD64Architecture)
+LinkSourceFile(stdResource.c,../shared)
+#endif
+#if defined(AlphaArchitecture)
+LinkSourceFile(xf86Axp.c,../shared)
+#endif
+#if defined(ia64Architecture)
+LinkSourceFile(ia64Pci.c,../shared)
+#endif
+DependTarget()
+
+#if 0
+InstallDriverSDKDynamicModule(lnx_jstk.o,$(DRIVERSDKMODULEDIR))
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/Imakefile
new file mode 100644
index 000000000..54511fbe0
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/Imakefile
@@ -0,0 +1,64 @@
+XCOMM $XFree86: Imakefile,v 1.13 2002/10/30 12:52:32 alanh Exp $
+
+#define IHaveModules
+#include <Server.tmpl>
+
+#if DoLoadableServer
+MSRC = drmmodule.c
+MOBJ = drmmodule.o
+#endif
+
+#if BuildXF86DRI
+#if HasMTRRSupport
+MTRR_DEFINES = -DHAS_MTRR_SUPPORT
+#endif
+
+ SRCS = xf86drm.c \
+ xf86drmHash.c \
+ xf86drmRandom.c \
+ xf86drmSL.c \
+ $(MSRC)
+
+ OBJS = xf86drm.o \
+ xf86drmHash.o \
+ xf86drmRandom.o \
+ xf86drmSL.o \
+ $(MOBJ)
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC) -I../.. -I$(DRMSRCDIR)/linux-core \
+ -I$(DRMSRCDIR)/shared-core
+
+DEFINES = $(MTRR_DEFINES) $(GLX_DEFINES)
+
+LIBDRM_DIR = ../../../../../../../extras/drm/libdrm
+
+LinkSourceFile(xf86drm.c,$(LIBDRM_DIR))
+LinkSourceFile(xf86drmHash.c,$(LIBDRM_DIR))
+LinkSourceFile(xf86drmRandom.c,$(LIBDRM_DIR))
+LinkSourceFile(xf86drmSL.c,$(LIBDRM_DIR))
+
+#if DoLoadableServer
+
+ModuleObjectRule()
+LibraryModuleTarget(drm,$(OBJS))
+NormalLintTarget($(SRCS))
+
+#ifdef LinuxArchitecture
+InstallLibraryModule(drm,$(MODULEDIR),linux)
+#endif
+
+#else
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+#endif
+
+
+DependTarget()
+#endif
+
+
+
+InstallDriverSDKLibraryModule(drm,$(DRIVERSDKMODULEDIR),linux)
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c
new file mode 100644
index 000000000..fd751e756
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c
@@ -0,0 +1,60 @@
+/* drmmodule.c -- Module initialization
+ * Created: Fri Jun 4 09:05:48 1999 by faith@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c,v 1.2 2000/02/23 04:47:22 martin Exp $
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Module.h"
+
+static MODULESETUPPROTO(drmSetup);
+
+static XF86ModuleVersionInfo VersRec =
+{
+ "drm",
+ MODULEVENDORSTRING,
+ MODINFOSTRING1,
+ MODINFOSTRING2,
+ XORG_VERSION_CURRENT,
+ 1, 0, 0,
+ ABI_CLASS_EXTENSION,
+ ABI_EXTENSION_VERSION,
+ MOD_CLASS_NONE,
+ {0,0,0,0}
+};
+
+XF86ModuleData drmModuleData = { &VersRec, drmSetup, NULL };
+
+static pointer
+drmSetup(pointer module, pointer opts, int *errmaj, int *errmin)
+{
+ return (void *)1;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile
new file mode 100644
index 000000000..6a23e75e5
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile
@@ -0,0 +1,77 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile,v 1.15 2003/06/12 14:12:36 eich Exp $
+
+#define IHaveModules
+
+#include <Server.tmpl>
+
+#define IHaveSubdirs
+
+
+#if defined(XF86INT10_BUILD) && \
+ ( !defined(DoLoadableServer) || !defined(Int10SubLibs))
+#define DoSingleLib
+# if XF86INT10_BUILD == X86VM
+EXPOBJS = vm86/helper_exec.o vm86/linux_vm86.o vm86/xf86int10.o
+SUBDIRS = vm86
+# elif XF86INT10_BUILD == X86EMU_OS
+EXPOBJS = x86emu/x86emu.o x86emu/xf86int10.o x86emu/helper_exec.o \
+ x86emu/xf86x86emu.o
+SUBDIRS = x86emu
+# endif
+#else
+SUBDIRS = vm86 x86emu
+LNXDEF = -DDoSubModules
+#endif
+
+
+#ifdef IHaveSubdirs
+MakeSubdirs($(SUBDIRS))
+DependSubdirs($(SUBDIRS))
+#endif
+
+SRCS = pci.c xf86int10module.c helper_mem.c linux.c
+OBJS = pci.o xf86int10module.o helper_mem.o linux.o
+
+
+LinkSourceFile(helper_mem.c,$(XF86SRC)/int10)
+LinkSourceFile(pci.c,$(XF86SRC)/int10)
+LinkSourceFile(xf86int10module.c,$(XF86SRC)/int10)
+
+
+INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86SRC)/int10 \
+ -I$(XF86OSSRC) \
+ -I$(SERVERSRC)/include -I$(XINCLUDESRC) -I$(X86EMUINCLUDES)
+
+DEFINES=-DHAVE_SYSV_IPC $(X86EMUDEFINES) $(EXTRADEFINES)
+
+#if defined(i386Architecture) || defined (AMD64Architecture)
+EXTRADEFINES=-D_PC
+#endif
+
+
+SpecialObjectRule(linux.o, linux.c, -DHAVE_SYSV_IPC $(LNXDEF))
+
+
+#if defined(XF86INT10_BUILD) && XF86INT10_BUILD > X86EMU_GENERIC
+
+ModuleObjectRule()
+
+#if HasParallelMake && defined (DoSingleLib)
+MakeMutex($(SUBDIRS) $(EXPOBJS) $(DONES))
+#endif
+
+LibraryModuleTarget(int10, $(OBJS) $(EXPOBJS))
+
+InstallLibraryModule(int10,$(MODULEDIR),linux)
+
+all::
+ @(set -x; cd ../..; \
+ RemoveFile(LibraryTargetName(int10)); \
+ $(LN) linux/int10/LibraryTargetName(int10) . )
+
+InstallDriverSDKLibraryModule(int10,$(DRIVERSDKMODULEDIR),.)
+
+#endif
+
+DependTarget()
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c
new file mode 100644
index 000000000..b8e821cd1
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c
@@ -0,0 +1,649 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c,v 1.32 2004/02/05 18:24:59 eich Exp $ */
+/*
+ * linux specific part of the int10 module
+ * Copyright 1999, 2000, 2001, 2002, 2003, 2004 Egbert Eich
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+#include "xf86_ansic.h"
+#include "xf86Pci.h"
+#include "compiler.h"
+#define _INT10_PRIVATE
+#include "xf86int10.h"
+#ifdef __sparc__
+#define DEV_MEM "/dev/fb"
+#else
+#define DEV_MEM "/dev/mem"
+#endif
+#ifndef XFree86LOADER
+#include <sys/mman.h>
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+#endif
+#define ALLOC_ENTRIES(x) ((V_RAM / x) - 1)
+#define SHMERRORPTR (pointer)(-1)
+
+static int counter = 0;
+static unsigned long int10Generation = 0;
+
+static CARD8 read_b(xf86Int10InfoPtr pInt, int addr);
+static CARD16 read_w(xf86Int10InfoPtr pInt, int addr);
+static CARD32 read_l(xf86Int10InfoPtr pInt, int addr);
+static void write_b(xf86Int10InfoPtr pInt, int addr, CARD8 val);
+static void write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val);
+static void write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val);
+
+int10MemRec linuxMem = {
+ read_b,
+ read_w,
+ read_l,
+ write_b,
+ write_w,
+ write_l
+};
+
+typedef struct {
+ int lowMem;
+ int highMem;
+ char* base;
+ char* base_high;
+ int screen;
+ char* alloc;
+} linuxInt10Priv;
+
+#if defined DoSubModules
+
+typedef enum {
+ INT10_NOT_LOADED,
+ INT10_LOADED_VM86,
+ INT10_LOADED_X86EMU,
+ INT10_LOAD_FAILED
+} Int10LinuxSubModuleState;
+
+static Int10LinuxSubModuleState loadedSubModule = INT10_NOT_LOADED;
+
+static Int10LinuxSubModuleState int10LinuxLoadSubModule(ScrnInfoPtr pScrn);
+
+#endif /* DoSubModules */
+
+xf86Int10InfoPtr
+xf86InitInt10(int entityIndex)
+{
+ return xf86ExtendedInitInt10(entityIndex, 0);
+}
+
+xf86Int10InfoPtr
+xf86ExtendedInitInt10(int entityIndex, int Flags)
+{
+ xf86Int10InfoPtr pInt = NULL;
+ CARD8 *bios_base;
+ int screen;
+ int fd;
+ static void* vidMem = NULL;
+ static void* sysMem = NULL;
+ void* vMem = NULL;
+ void *options = NULL;
+ int low_mem;
+ int high_mem = -1;
+ char *base = SHMERRORPTR;
+ char *base_high = SHMERRORPTR;
+ int pagesize;
+ memType cs;
+ legacyVGARec vga;
+ xf86int10BiosLocation bios;
+ Bool videoBiosMapped = FALSE;
+
+ if (int10Generation != serverGeneration) {
+ counter = 0;
+ int10Generation = serverGeneration;
+ }
+
+ screen = (xf86FindScreenForEntity(entityIndex))->scrnIndex;
+
+ options = xf86HandleInt10Options(xf86Screens[screen],entityIndex);
+
+ if (int10skip(options)) {
+ xfree(options);
+ return NULL;
+ }
+
+#if defined DoSubModules
+ if (loadedSubModule == INT10_NOT_LOADED)
+ loadedSubModule = int10LinuxLoadSubModule(xf86Screens[screen]);
+
+ if (loadedSubModule == INT10_LOAD_FAILED)
+ return NULL;
+#endif
+
+ if ((!vidMem) || (!sysMem)) {
+ if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) {
+ if (!sysMem) {
+#ifdef DEBUG
+ ErrorF("Mapping sys bios area\n");
+#endif
+ if ((sysMem = mmap((void *)(SYS_BIOS), BIOS_SIZE,
+ PROT_READ | PROT_EXEC,
+ MAP_SHARED | MAP_FIXED, fd, SYS_BIOS))
+ == MAP_FAILED) {
+ xf86DrvMsg(screen, X_ERROR, "Cannot map SYS BIOS\n");
+ close(fd);
+ goto error0;
+ }
+ }
+ if (!vidMem) {
+#ifdef DEBUG
+ ErrorF("Mapping VRAM area\n");
+#endif
+ if ((vidMem = mmap((void *)(V_RAM), VRAM_SIZE,
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_SHARED | MAP_FIXED, fd, V_RAM))
+ == MAP_FAILED) {
+ xf86DrvMsg(screen, X_ERROR, "Cannot map V_RAM\n");
+ close(fd);
+ goto error0;
+ }
+ }
+ close(fd);
+ } else {
+ xf86DrvMsg(screen, X_ERROR, "Cannot open %s\n", DEV_MEM);
+ goto error0;
+ }
+ }
+
+ pInt = (xf86Int10InfoPtr)xnfcalloc(1, sizeof(xf86Int10InfoRec));
+ pInt->scrnIndex = screen;
+ pInt->entityIndex = entityIndex;
+ if (!xf86Int10ExecSetup(pInt))
+ goto error0;
+ pInt->mem = &linuxMem;
+ pagesize = getpagesize();
+ pInt->private = (pointer)xnfcalloc(1, sizeof(linuxInt10Priv));
+ ((linuxInt10Priv*)pInt->private)->screen = screen;
+ ((linuxInt10Priv*)pInt->private)->alloc =
+ (pointer)xnfcalloc(1, ALLOC_ENTRIES(pagesize));
+
+ if (!xf86IsEntityPrimary(entityIndex)) {
+#ifdef DEBUG
+ ErrorF("Mapping high memory area\n");
+#endif
+ if ((high_mem = shmget(counter++, HIGH_MEM_SIZE,
+ IPC_CREAT | SHM_R | SHM_W)) == -1) {
+ if (errno == ENOSYS)
+ xf86DrvMsg(screen, X_ERROR, "shmget error\n Please reconfigure"
+ " your kernel to include System V IPC support\n");
+ else
+ xf86DrvMsg(screen, X_ERROR,
+ "shmget(highmem) error: %s\n",strerror(errno));
+ goto error1;
+ }
+ } else {
+#ifdef DEBUG
+ ErrorF("Mapping Video BIOS\n");
+#endif
+ videoBiosMapped = TRUE;
+ if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) {
+ if ((vMem = mmap((void *)(V_BIOS), SYS_BIOS - V_BIOS,
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_SHARED | MAP_FIXED, fd, V_BIOS))
+ == MAP_FAILED) {
+ xf86DrvMsg(screen, X_ERROR, "Cannot map V_BIOS\n");
+ close(fd);
+ goto error1;
+ }
+ close (fd);
+ } else
+ goto error1;
+ }
+ ((linuxInt10Priv*)pInt->private)->highMem = high_mem;
+
+#ifdef DEBUG
+ ErrorF("Mapping 640kB area\n");
+#endif
+ if ((low_mem = shmget(counter++, V_RAM,
+ IPC_CREAT | SHM_R | SHM_W)) == -1) {
+ xf86DrvMsg(screen, X_ERROR,
+ "shmget(lowmem) error: %s\n",strerror(errno));
+ goto error2;
+ }
+
+ ((linuxInt10Priv*)pInt->private)->lowMem = low_mem;
+ base = shmat(low_mem, 0, 0);
+ if (base == SHMERRORPTR) {
+ xf86DrvMsg(screen, X_ERROR,
+ "shmat(low_mem) error: %s\n",strerror(errno));
+ goto error3;
+ }
+ ((linuxInt10Priv *)pInt->private)->base = base;
+ if (high_mem > -1) {
+ base_high = shmat(high_mem, 0, 0);
+ if (base_high == SHMERRORPTR) {
+ xf86DrvMsg(screen, X_ERROR,
+ "shmat(high_mem) error: %s\n",strerror(errno));
+ goto error3;
+ }
+ ((linuxInt10Priv*)pInt->private)->base_high = base_high;
+ } else
+ ((linuxInt10Priv*)pInt->private)->base_high = NULL;
+
+ if (!MapCurrentInt10(pInt))
+ goto error3;
+
+ Int10Current = pInt;
+
+#ifdef DEBUG
+ ErrorF("Mapping int area\n");
+#endif
+ if (xf86ReadBIOS(0, 0, (unsigned char *)0, LOW_PAGE_SIZE) < 0) {
+ xf86DrvMsg(screen, X_ERROR, "Cannot read int vect\n");
+ goto error3;
+ }
+#ifdef DEBUG
+ ErrorF("done\n");
+#endif
+ /*
+ * Read in everything between V_BIOS and SYS_BIOS as some system BIOSes
+ * have executable code there. Note that xf86ReadBIOS() can only bring in
+ * 64K bytes at a time.
+ */
+ if (!videoBiosMapped) {
+ (void)memset((pointer)V_BIOS, 0, SYS_BIOS - V_BIOS);
+#ifdef DEBUG
+ ErrorF("Reading BIOS\n");
+#endif
+ for (cs = V_BIOS; cs < SYS_BIOS; cs += V_BIOS_SIZE)
+ if (xf86ReadBIOS(cs, 0, (pointer)cs, V_BIOS_SIZE) < V_BIOS_SIZE)
+ xf86DrvMsg(screen, X_WARNING,
+ "Unable to retrieve all of segment 0x%06lX.\n", cs);
+#ifdef DEBUG
+ ErrorF("done\n");
+#endif
+ }
+
+ xf86int10ParseBiosLocation(options,&bios);
+
+ if (xf86IsEntityPrimary(entityIndex)
+ && !(initPrimary(options))) {
+ if (bios.bus == BUS_ISA && bios.location.legacy) {
+ xf86DrvMsg(screen, X_CONFIG,
+ "Overriding BIOS location: 0x%x\n",
+ bios.location.legacy);
+ cs = bios.location.legacy >> 4;
+ bios_base = (unsigned char *)(cs << 4);
+ if (!int10_check_bios(screen, cs, bios_base)) {
+ xf86DrvMsg(screen, X_ERROR,
+ "No V_BIOS at specified address 0x%lx\n",cs << 4);
+ goto error3;
+ }
+ } else {
+ if (bios.bus == BUS_PCI) {
+ xf86DrvMsg(screen, X_WARNING,
+ "Option BiosLocation for primary device ignored: "
+ "It points to PCI.\n");
+ xf86DrvMsg(screen, X_WARNING,
+ "You must set Option InitPrimary also\n");
+ }
+
+ cs = ((CARD16*)0)[(0x10<<1) + 1];
+
+ bios_base = (unsigned char *)(cs << 4);
+
+ if (!int10_check_bios(screen, cs, bios_base)) {
+ cs = ((CARD16*)0)[(0x42 << 1) + 1];
+ bios_base = (unsigned char *)(cs << 4);
+ if (!int10_check_bios(screen, cs, bios_base)) {
+ cs = V_BIOS >> 4;
+ bios_base = (unsigned char *)(cs << 4);
+ if (!int10_check_bios(screen, cs, bios_base)) {
+ xf86DrvMsg(screen, X_ERROR, "No V_BIOS found\n");
+ goto error3;
+ }
+ }
+ }
+ }
+
+ xf86DrvMsg(screen, X_INFO, "Primary V_BIOS segment is: 0x%lx\n", cs);
+
+ pInt->BIOSseg = cs;
+ set_return_trap(pInt);
+#ifdef _PC
+ pInt->Flags = Flags & (SET_BIOS_SCRATCH | RESTORE_BIOS_SCRATCH);
+ if (! (pInt->Flags & SET_BIOS_SCRATCH))
+ pInt->Flags &= ~RESTORE_BIOS_SCRATCH;
+ xf86Int10SaveRestoreBIOSVars(pInt, TRUE);
+#endif
+ } else {
+ EntityInfoPtr pEnt = xf86GetEntityInfo(pInt->entityIndex);
+ BusType location_type;
+
+ if (bios.bus != BUS_NONE) {
+ switch (location_type = bios.bus) {
+ case BUS_PCI:
+ xf86DrvMsg(screen,X_CONFIG,"Overriding bios location: "
+ "PCI:%i:%i%i\n",bios.location.pci.bus,
+ bios.location.pci.dev,bios.location.pci.func);
+ break;
+ case BUS_ISA:
+ if (bios.location.legacy)
+ xf86DrvMsg(screen,X_CONFIG,"Overriding bios location: "
+ "Legacy:0x%x\n",bios.location.legacy);
+ else
+ xf86DrvMsg(screen,X_CONFIG,"Overriding bios location: "
+ "Legacy\n");
+ break;
+ default:
+ break;
+ }
+ } else
+ location_type = pEnt->location.type;
+
+ switch (location_type) {
+ case BUS_PCI:
+ {
+ int pci_entity;
+
+ if (bios.bus == BUS_PCI)
+ pci_entity = xf86GetPciEntity(bios.location.pci.bus,
+ bios.location.pci.dev,
+ bios.location.pci.func);
+ else
+ pci_entity = pInt->entityIndex;
+ if (!mapPciRom(pci_entity, (unsigned char *)(V_BIOS))) {
+ xf86DrvMsg(screen, X_ERROR, "Cannot read V_BIOS\n");
+ goto error3;
+ }
+ pInt->BIOSseg = V_BIOS >> 4;
+ break;
+ }
+ case BUS_ISA:
+ if (bios.bus == BUS_ISA && bios.location.legacy) {
+ cs = bios.location.legacy >> 4;
+ bios_base = (unsigned char *)(cs << 4);
+ if (!int10_check_bios(screen, cs, bios_base)) {
+ xf86DrvMsg(screen,X_ERROR,"No V_BIOS found "
+ "on override address %p\n",bios_base);
+ goto error3;
+ }
+ } else {
+ cs = ((CARD16*)0)[(0x10<<1)+1];
+ bios_base = (unsigned char *)(cs << 4);
+
+ if (!int10_check_bios(screen, cs, bios_base)) {
+ cs = ((CARD16*)0)[(0x42<<1)+1];
+ bios_base = (unsigned char *)(cs << 4);
+ if (!int10_check_bios(screen, cs, bios_base)) {
+ cs = V_BIOS >> 4;
+ bios_base = (unsigned char *)(cs << 4);
+ if (!int10_check_bios(screen, cs, bios_base)) {
+ xf86DrvMsg(screen,X_ERROR,"No V_BIOS found\n");
+ goto error3;
+ }
+ }
+ }
+ }
+ xf86DrvMsg(screen,X_INFO,"Primary V_BIOS segment is: 0x%lx\n",cs);
+ pInt->BIOSseg = cs;
+ break;
+ default:
+ goto error3;
+ }
+ xfree(pEnt);
+ pInt->num = 0xe6;
+ reset_int_vect(pInt);
+ set_return_trap(pInt);
+ LockLegacyVGA(pInt, &vga);
+ xf86ExecX86int10(pInt);
+ UnlockLegacyVGA(pInt, &vga);
+ }
+#ifdef DEBUG
+ dprint(0xc0000, 0x20);
+#endif
+
+ xfree(options);
+ return pInt;
+
+error3:
+ if (base_high)
+ shmdt(base_high);
+ shmdt(base);
+ shmdt(0);
+ if (base_high)
+ shmdt((char*)HIGH_MEM);
+ shmctl(low_mem, IPC_RMID, NULL);
+ Int10Current = NULL;
+error2:
+ if (high_mem > -1)
+ shmctl(high_mem, IPC_RMID,NULL);
+error1:
+ if (vMem)
+ munmap(vMem, SYS_BIOS - V_BIOS);
+ xfree(((linuxInt10Priv*)pInt->private)->alloc);
+ xfree(pInt->private);
+error0:
+ xfree(options);
+ xfree(pInt);
+ return NULL;
+}
+
+Bool
+MapCurrentInt10(xf86Int10InfoPtr pInt)
+{
+ pointer addr;
+ int fd = -1;
+
+ if (Int10Current) {
+ shmdt(0);
+ if (((linuxInt10Priv*)Int10Current->private)->highMem >= 0)
+ shmdt((char*)HIGH_MEM);
+ else
+ munmap((pointer)V_BIOS, (SYS_BIOS - V_BIOS));
+ }
+ addr = shmat(((linuxInt10Priv*)pInt->private)->lowMem, (char*)1, SHM_RND);
+ if (addr == SHMERRORPTR) {
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot shmat() low memory\n");
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+ "shmat(low_mem) error: %s\n",strerror(errno));
+ return FALSE;
+ }
+
+ if (((linuxInt10Priv*)pInt->private)->highMem >= 0) {
+ addr = shmat(((linuxInt10Priv*)pInt->private)->highMem,
+ (char*)HIGH_MEM, 0);
+ if (addr == SHMERRORPTR) {
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+ "Cannot shmat() high memory\n");
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+ "shmget error: %s\n",strerror(errno));
+ return FALSE;
+ }
+ } else {
+ if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) {
+ if (mmap((void *)(V_BIOS), SYS_BIOS - V_BIOS,
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_SHARED | MAP_FIXED, fd, V_BIOS)
+ == MAP_FAILED) {
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot map V_BIOS\n");
+ close (fd);
+ return FALSE;
+ }
+ } else {
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot open %s\n",DEV_MEM);
+ return FALSE;
+ }
+ close (fd);
+ }
+
+ return TRUE;
+}
+
+void
+xf86FreeInt10(xf86Int10InfoPtr pInt)
+{
+ if (!pInt)
+ return;
+
+#ifdef _PC
+ xf86Int10SaveRestoreBIOSVars(pInt, FALSE);
+#endif
+ if (Int10Current == pInt) {
+ shmdt(0);
+ if (((linuxInt10Priv*)pInt->private)->highMem >= 0)
+ shmdt((char*)HIGH_MEM);
+ else
+ munmap((pointer)V_BIOS, (SYS_BIOS - V_BIOS));
+ Int10Current = NULL;
+ }
+
+ if (((linuxInt10Priv*)pInt->private)->base_high)
+ shmdt(((linuxInt10Priv*)pInt->private)->base_high);
+ shmdt(((linuxInt10Priv*)pInt->private)->base);
+ shmctl(((linuxInt10Priv*)pInt->private)->lowMem, IPC_RMID, NULL);
+ if (((linuxInt10Priv*)pInt->private)->highMem >= 0)
+ shmctl(((linuxInt10Priv*)pInt->private)->highMem, IPC_RMID, NULL);
+ xfree(((linuxInt10Priv*)pInt->private)->alloc);
+ xfree(pInt->private);
+ xfree(pInt);
+}
+
+void *
+xf86Int10AllocPages(xf86Int10InfoPtr pInt, int num, int *off)
+{
+ int pagesize = getpagesize();
+ int num_pages = ALLOC_ENTRIES(pagesize);
+ int i, j;
+
+ for (i = 0; i < (num_pages - num); i++) {
+ if (((linuxInt10Priv*)pInt->private)->alloc[i] == 0) {
+ for (j = i; j < (num + i); j++)
+ if ((((linuxInt10Priv*)pInt->private)->alloc[j] != 0))
+ break;
+ if (j == (num + i))
+ break;
+ else
+ i = i + num;
+ }
+ }
+ if (i == (num_pages - num))
+ return NULL;
+
+ for (j = i; j < (i + num); j++)
+ ((linuxInt10Priv*)pInt->private)->alloc[j] = 1;
+
+ *off = (i + 1) * pagesize;
+
+ return ((linuxInt10Priv*)pInt->private)->base + ((i + 1) * pagesize);
+}
+
+void
+xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num)
+{
+ int pagesize = getpagesize();
+ int first = (((unsigned long)pbase
+ - (unsigned long)((linuxInt10Priv*)pInt->private)->base)
+ / pagesize) - 1;
+ int i;
+
+ for (i = first; i < (first + num); i++)
+ ((linuxInt10Priv*)pInt->private)->alloc[i] = 0;
+}
+
+static CARD8
+read_b(xf86Int10InfoPtr pInt, int addr)
+{
+ return *((CARD8 *)(memType)addr);
+}
+
+static CARD16
+read_w(xf86Int10InfoPtr pInt, int addr)
+{
+ return *((CARD16 *)(memType)addr);
+}
+
+static CARD32
+read_l(xf86Int10InfoPtr pInt, int addr)
+{
+ return *((CARD32 *)(memType)addr);
+}
+
+static void
+write_b(xf86Int10InfoPtr pInt, int addr, CARD8 val)
+{
+ *((CARD8 *)(memType)addr) = val;
+}
+
+static void
+write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val)
+{
+ *((CARD16 *)(memType)addr) = val;
+}
+
+static
+void write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val)
+{
+ *((CARD32 *)(memType) addr) = val;
+}
+
+pointer
+xf86int10Addr(xf86Int10InfoPtr pInt, CARD32 addr)
+{
+ if (addr < V_RAM)
+ return ((linuxInt10Priv*)pInt->private)->base + addr;
+ else if (addr < V_BIOS)
+ return (pointer)(memType)addr;
+ else if (addr < SYS_BIOS) {
+ if (((linuxInt10Priv*)pInt->private)->base_high)
+ return (pointer)(((linuxInt10Priv*)pInt->private)->base_high
+ - V_BIOS + addr);
+ else
+ return (pointer) (memType)addr;
+ } else
+ return (pointer) (memType)addr;
+}
+
+#if defined DoSubModules
+
+static Bool
+vm86_tst(void)
+{
+ int __res;
+
+#ifdef __PIC__
+ /* When compiling with -fPIC, we can't use asm constraint "b" because
+ %ebx is already taken by gcc. */
+ __asm__ __volatile__("pushl %%ebx\n\t"
+ "movl %2,%%ebx\n\t"
+ "movl %1,%%eax\n\t"
+ "int $0x80\n\t"
+ "popl %%ebx"
+ :"=a" (__res)
+ :"n" ((int)113), "r" (NULL));
+#else
+ __asm__ __volatile__("int $0x80\n\t"
+ :"=a" (__res):"a" ((int)113),
+ "b" ((struct vm86_struct *)NULL));
+#endif
+
+ if (__res < 0 && __res == -ENOSYS)
+ return FALSE;
+
+ return TRUE;
+}
+
+static Int10LinuxSubModuleState
+int10LinuxLoadSubModule(ScrnInfoPtr pScrn)
+{
+ if (vm86_tst()) {
+ if (xf86LoadSubModule(pScrn,"vm86"))
+ return INT10_LOADED_VM86;
+ }
+ if (xf86LoadSubModule(pScrn,"x86emu"))
+ return INT10_LOADED_X86EMU;
+
+ return INT10_LOAD_FAILED;
+}
+
+#endif /* DoSubModules */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile
new file mode 100644
index 000000000..522369894
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile
@@ -0,0 +1,55 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile,v 1.2 2003/06/12 14:12:37 eich Exp $
+
+#define IHaveModules
+
+#include <Server.tmpl>
+
+SRCS1 = linux_vm86.c helper_exec.c xf86int10.c
+OBJS1 = linux_vm86.o helper_exec.o xf86int10.o
+
+#if defined(DoLoadableServer) && defined(Int10SubLibs)
+SUBMODSRCS = xf86vm86module.c
+SUBMODOBJS = xf86vm86module.o
+#endif
+
+OBJS = $(SUBMODOBJS) $(OBJS1)
+SRCS = $(SUBMODSRCS) $(SRCS1)
+
+LinkSourceFile(helper_exec.c,$(XF86SRC)/int10)
+LinkSourceFile(xf86int10.c,$(XF86SRC)/int10)
+LinkFile(xf86vm86module.c,$(XF86SRC)/int10/xf86int10module.c)
+
+
+INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86SRC)/int10 \
+ -I$(XF86OSSRC) \
+ -I$(SERVERSRC)/include -I$(XINCLUDESRC) -I$(X86EMUINCLUDES)
+
+DEFINES=-DHAVE_SYSV_IPC $(X86EMUDEFINES) $(EXTRADEFINES)
+
+#if defined(i386Architecture) || defined (AMD64Architecture)
+EXTRADEFINES=-D_PC
+#endif
+
+SpecialObjectRule(xf86vm86module.o, xf86vm86module.c, -DMOD_NAME=vm86)
+SpecialObjectRule(helper_exec.o, helper_exec.c, -D_VM86_LINUX)
+SpecialObjectRule(xf86int10.o, xf86int10.c, -D_VM86_LINUX -DSHOW_ALL_DEVICES)
+SpecialObjectRule(linux_vm86.o, linux_vm86.c, -D_VM86_LINUX)
+
+ModuleObjectRule()
+
+#if defined(DoLoadableServer) && defined(Int10SubLibs)
+LibraryModuleTarget(vm86, $(OBJS))
+InstallLibraryModule(vm86,$(MODULEDIR),linux)
+
+all::
+ @(set -x; cd ../..; \
+ RemoveFile(LibraryTargetName(vm86)); \
+ $(LN) linux/int10/vm86/LibraryTargetName(vm86) . )
+
+InstallDriverSDKLibraryModule(vm86,$(DRIVERSDKMODULEDIR),.)
+#else
+SubdirLibraryRule($(OBJS))
+#endif
+
+DependTarget()
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c
new file mode 100644
index 000000000..e99cde8da
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c
@@ -0,0 +1,302 @@
+/* $XFree86$ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+#include "xf86_ansic.h"
+#include "xf86Pci.h"
+#include "compiler.h"
+#define _INT10_PRIVATE
+#include "xf86int10.h"
+
+#define REG pInt
+
+#ifdef _VM86_LINUX
+#include "int10Defines.h"
+
+static int vm86_rep(struct vm86_struct *ptr);
+static struct vm86_struct vm86_s;
+
+Bool
+xf86Int10ExecSetup(xf86Int10InfoPtr pInt)
+{
+#define VM86S ((struct vm86_struct *)pInt->cpuRegs)
+
+ pInt->cpuRegs = &vm86_s;
+ VM86S->flags = 0;
+ VM86S->screen_bitmap = 0;
+ VM86S->cpu_type = CPU_586;
+ memset(&VM86S->int_revectored, 0xff, sizeof(VM86S->int_revectored));
+ memset(&VM86S->int21_revectored, 0xff, sizeof(VM86S->int21_revectored));
+ return TRUE;
+}
+
+/* get the linear address */
+#define LIN_PREF_SI ((pref_seg << 4) + X86_SI)
+#define LWECX ((prefix66 ^ prefix67) ? X86_ECX : X86_CX)
+#define LWECX_ZERO {if (prefix66 ^ prefix67) X86_ECX = 0; else X86_CX = 0;}
+#define DF (1 << 10)
+
+/* vm86 fault handling */
+static Bool
+vm86_GP_fault(xf86Int10InfoPtr pInt)
+{
+ unsigned char *csp, *lina;
+ CARD32 org_eip;
+ int pref_seg;
+ int done, is_rep, prefix66, prefix67;
+
+ csp = lina = SEG_ADR((unsigned char *), X86_CS, IP);
+
+ is_rep = 0;
+ prefix66 = prefix67 = 0;
+ pref_seg = -1;
+
+ /* eat up prefixes */
+ done = 0;
+ do {
+ switch (MEM_RB(pInt, (int)csp++)) {
+ case 0x66: /* operand prefix */ prefix66=1; break;
+ case 0x67: /* address prefix */ prefix67=1; break;
+ case 0x2e: /* CS */ pref_seg=X86_CS; break;
+ case 0x3e: /* DS */ pref_seg=X86_DS; break;
+ case 0x26: /* ES */ pref_seg=X86_ES; break;
+ case 0x36: /* SS */ pref_seg=X86_SS; break;
+ case 0x65: /* GS */ pref_seg=X86_GS; break;
+ case 0x64: /* FS */ pref_seg=X86_FS; break;
+ case 0xf0: /* lock */ break;
+ case 0xf2: /* repnz */
+ case 0xf3: /* rep */ is_rep=1; break;
+ default: done=1;
+ }
+ } while (!done);
+ csp--; /* oops one too many */
+ org_eip = X86_EIP;
+ X86_IP += (csp - lina);
+
+ switch (MEM_RB(pInt, (int)csp)) {
+ case 0x6c: /* insb */
+ /* NOTE: ES can't be overwritten; prefixes 66,67 should use esi,edi,ecx
+ * but is anyone using extended regs in real mode? */
+ /* WARNING: no test for DI wrapping! */
+ X86_EDI += port_rep_inb(pInt, X86_DX, SEG_EADR((CARD32), X86_ES, DI),
+ X86_FLAGS & DF, is_rep ? LWECX : 1);
+ if (is_rep) LWECX_ZERO;
+ X86_IP++;
+ break;
+
+ case 0x6d: /* (rep) insw / insd */
+ /* NOTE: ES can't be overwritten */
+ /* WARNING: no test for _DI wrapping! */
+ if (prefix66) {
+ X86_DI += port_rep_inl(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI),
+ X86_EFLAGS & DF, is_rep ? LWECX : 1);
+ }
+ else {
+ X86_DI += port_rep_inw(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI),
+ X86_FLAGS & DF, is_rep ? LWECX : 1);
+ }
+ if (is_rep) LWECX_ZERO;
+ X86_IP++;
+ break;
+
+ case 0x6e: /* (rep) outsb */
+ if (pref_seg < 0) pref_seg = X86_DS;
+ /* WARNING: no test for _SI wrapping! */
+ X86_SI += port_rep_outb(pInt, X86_DX, (CARD32)LIN_PREF_SI,
+ X86_FLAGS & DF, is_rep ? LWECX : 1);
+ if (is_rep) LWECX_ZERO;
+ X86_IP++;
+ break;
+
+ case 0x6f: /* (rep) outsw / outsd */
+ if (pref_seg < 0) pref_seg = X86_DS;
+ /* WARNING: no test for _SI wrapping! */
+ if (prefix66) {
+ X86_SI += port_rep_outl(pInt, X86_DX, (CARD32)LIN_PREF_SI,
+ X86_EFLAGS & DF, is_rep ? LWECX : 1);
+ }
+ else {
+ X86_SI += port_rep_outw(pInt, X86_DX, (CARD32)LIN_PREF_SI,
+ X86_FLAGS & DF, is_rep ? LWECX : 1);
+ }
+ if (is_rep) LWECX_ZERO;
+ X86_IP++;
+ break;
+
+ case 0xe5: /* inw xx, inl xx */
+ if (prefix66) X86_EAX = x_inl(csp[1]);
+ else X86_AX = x_inw(csp[1]);
+ X86_IP += 2;
+ break;
+
+ case 0xe4: /* inb xx */
+ X86_AL = x_inb(csp[1]);
+ X86_IP += 2;
+ break;
+
+ case 0xed: /* inw dx, inl dx */
+ if (prefix66) X86_EAX = x_inl(X86_DX);
+ else X86_AX = x_inw(X86_DX);
+ X86_IP += 1;
+ break;
+
+ case 0xec: /* inb dx */
+ X86_AL = x_inb(X86_DX);
+ X86_IP += 1;
+ break;
+
+ case 0xe7: /* outw xx */
+ if (prefix66) x_outl(csp[1], X86_EAX);
+ else x_outw(csp[1], X86_AX);
+ X86_IP += 2;
+ break;
+
+ case 0xe6: /* outb xx */
+ x_outb(csp[1], X86_AL);
+ X86_IP += 2;
+ break;
+
+ case 0xef: /* outw dx */
+ if (prefix66) x_outl(X86_DX, X86_EAX);
+ else x_outw(X86_DX, X86_AX);
+ X86_IP += 1;
+ break;
+
+ case 0xee: /* outb dx */
+ x_outb(X86_DX, X86_AL);
+ X86_IP += 1;
+ break;
+
+ case 0xf4:
+#ifdef DEBUG
+ ErrorF("hlt at %p\n", lina);
+#endif
+ return FALSE;
+
+ case 0x0f:
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+ "CPU 0x0f Trap at CS:EIP=0x%4.4x:0x%8.8lx\n", X86_CS, X86_EIP);
+ goto op0ferr;
+
+ default:
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown reason for exception\n");
+
+ op0ferr:
+ dump_registers(pInt);
+ stack_trace(pInt);
+ dump_code(pInt);
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR, "cannot continue\n");
+ return FALSE;
+ } /* end of switch() */
+ return TRUE;
+}
+
+static int
+do_vm86(xf86Int10InfoPtr pInt)
+{
+ int retval, signo;
+
+ xf86InterceptSignals(&signo);
+ retval = vm86_rep(VM86S);
+ xf86InterceptSignals(NULL);
+
+ if (signo >= 0) {
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+ "vm86() syscall generated signal %d.\n", signo);
+ dump_registers(pInt);
+ dump_code(pInt);
+ stack_trace(pInt);
+ return 0;
+ }
+
+ switch (VM86_TYPE(retval)) {
+ case VM86_UNKNOWN:
+ if (!vm86_GP_fault(pInt)) return 0;
+ break;
+ case VM86_STI:
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR, "vm86_sti :-((\n");
+ dump_registers(pInt);
+ dump_code(pInt);
+ stack_trace(pInt);
+ return 0;
+ case VM86_INTx:
+ pInt->num = VM86_ARG(retval);
+ if (!int_handler(pInt)) {
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+ "Unknown vm86_int: 0x%X\n\n", VM86_ARG(retval));
+ dump_registers(pInt);
+ dump_code(pInt);
+ stack_trace(pInt);
+ return 0;
+ }
+ /* I'm not sure yet what to do if we can handle ints */
+ break;
+ case VM86_SIGNAL:
+ return 1;
+ /*
+ * we used to warn here and bail out - but now the sigio stuff
+ * always fires signals at us. So we just ignore them for now.
+ */
+ xf86DrvMsg(pInt->scrnIndex, X_WARNING, "received signal\n");
+ return 0;
+ default:
+ xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown type(0x%x)=0x%x\n",
+ VM86_ARG(retval), VM86_TYPE(retval));
+ dump_registers(pInt);
+ dump_code(pInt);
+ stack_trace(pInt);
+ return 0;
+ }
+
+ return 1;
+}
+
+void
+xf86ExecX86int10(xf86Int10InfoPtr pInt)
+{
+ int sig = setup_int(pInt);
+
+ if (int_handler(pInt))
+ while(do_vm86(pInt)) {};
+
+ finish_int(pInt, sig);
+}
+
+static int
+vm86_rep(struct vm86_struct *ptr)
+{
+ int __res;
+
+#ifdef __PIC__
+ /* When compiling with -fPIC, we can't use asm constraint "b" because
+ %ebx is already taken by gcc. */
+ __asm__ __volatile__("pushl %%ebx\n\t"
+ "push %%gs\n\t"
+ "movl %2,%%ebx\n\t"
+ "movl %1,%%eax\n\t"
+ "int $0x80\n\t"
+ "pop %%gs\n\t"
+ "popl %%ebx"
+ :"=a" (__res)
+ :"n" ((int)113), "r" ((struct vm86_struct *)ptr));
+#else
+ __asm__ __volatile__("push %%gs\n\t"
+ "int $0x80\n\t"
+ "pop %%gs"
+ :"=a" (__res):"a" ((int)113),
+ "b" ((struct vm86_struct *)ptr));
+#endif
+
+ if (__res < 0) {
+ errno = -__res;
+ __res = -1;
+ }
+ else errno = 0;
+ return __res;
+}
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile
new file mode 100644
index 000000000..8a0dc4463
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile
@@ -0,0 +1,86 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile,v 1.2 2003/06/12 14:12:37 eich Exp $
+
+#define IHaveModules
+
+#include <Server.tmpl>
+
+SRCS1 = xf86x86emu.c helper_exec.c xf86int10.c
+OBJS1 = xf86x86emu.o helper_exec.o xf86int10.o
+
+#if defined(DoLoadableServer) && defined(Int10SubLibs)
+SUBMODSRCS = xf86x86emumodule.c
+SUBMODOBJS = xf86x86emumodule.o
+#endif
+
+SRCS2 = $(SUBMODSRCS) $(SRCS1)
+OBJS2 = $(SUBMODOBJS) $(OBJS1)
+
+LinkSourceFile(helper_exec.c,$(XF86SRC)/int10)
+LinkSourceFile(xf86int10.c,$(XF86SRC)/int10)
+LinkSourceFile(xf86x86emu.c,$(XF86SRC)/int10)
+LinkFile(xf86x86emumodule.c,$(XF86SRC)/int10/xf86int10module.c)
+
+
+INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86SRC)/int10 \
+ -I$(XF86OSSRC) \
+ -I$(SERVERSRC)/include -I$(XINCLUDESRC) -I$(X86EMUINCLUDES)
+
+DEFINES=-DHAVE_SYSV_IPC $(X86EMUDEFINES) $(EXTRADEFINES)
+
+#if defined(i386Architecture) || defined (AMD64Architecture)
+EXTRADEFINES=-D_PC
+#endif
+
+SpecialObjectRule(xf86x86emumodule.o, xf86x86emumodule.c, -DMOD_NAME=x86emu)
+SpecialObjectRule(helper_exec.o, helper_exec.c, -D_X86EMU)
+SpecialObjectRule(xf86int10.o, xf86int10.c, -D_X86EMU -DSHOW_ALL_DEVICES)
+SpecialObjectRule(linux.o, linux.c, -D_X86EMU -DHAVE_SYSV_IPC)
+
+X86TOPDIR = $(TOP)/extras/x86emu
+X86SRCDIR = $(X86TOPDIR)/src/x86emu
+X86EMUINCLUDES = $(X86TOPDIR)/include -I$(X86SRCDIR)
+# if DoLoadableServer
+X86EMUMODDEFS = -DNO_SYS_HEADERS
+# endif
+
+X86EMUDEFINES = -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG $(X86EMUMODDEFS)
+
+#if !defined(X86EMU_LIBPATH)
+X86EMUSRCS = x86emu.c
+X86EMUOBJS = x86emu.o
+
+LinkSourceFile(x86emu.c,$(XF86SRC)/int10)
+LinkSourceFile(debug.c,$(X86SRCDIR))
+LinkSourceFile(decode.c,$(X86SRCDIR))
+LinkSourceFile(fpu.c,$(X86SRCDIR))
+LinkSourceFile(ops.c,$(X86SRCDIR))
+LinkSourceFile(ops2.c,$(X86SRCDIR))
+LinkSourceFile(prim_ops.c,$(X86SRCDIR))
+LinkSourceFile(sys.c,$(X86SRCDIR))
+#else
+BuildObjectFromLibraryWithPath(X86EMU_LIBPATH,x86emu,x86emu)
+X86EMUOBJS = x86emu.o
+#endif
+
+SRCS = $(SRCS2) $(X86EMUSRCS)
+OBJS = $(OBJS2) $(X86EMUOBJS)
+
+ModuleObjectRule()
+
+#if defined(DoLoadableServer) && defined(Int10SubLibs)
+LibraryModuleTarget(x86emu, $(OBJS))
+
+InstallLibraryModule(x86emu,$(MODULEDIR),linux)
+
+all::
+ @(set -x; cd ../..; \
+ RemoveFile(LibraryTargetName(x86emu)); \
+ $(LN) linux/int10/x86emu/LibraryTargetName(x86emu) . )
+
+InstallDriverSDKLibraryModule(x86emu,$(DRIVERSDKMODULEDIR),.)
+#else
+SubdirLibraryRule($(OBJS))
+#endif
+
+DependTarget()
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx.h
new file mode 100644
index 000000000..68ad34011
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx.h
@@ -0,0 +1,55 @@
+/* $XFree86: Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef LNX_H_
+# ifdef __alpha__
+extern unsigned long _bus_base __P ((void)) __attribute__ ((const));
+extern unsigned long _bus_base_sparse __P ((void)) __attribute__ ((const));
+extern int iopl __P ((int __level));
+
+/* new pciconfig_iobase syscall added in 2.2.15 and 2.3.99 */
+# include <linux/unistd.h>
+# include <asm/pci.h>
+extern long (*_iobase)(unsigned, int, int, int);
+
+/*
+ * _iobase deals with the case the __NR_pciconfig_iobase is either undefined
+ * or unsupported by the kernel, but we need to make sure that the `which'
+ * argument symbols are defined.
+ */
+# ifndef IOBASE_HOSE
+# define IOBASE_HOSE 0
+# endif
+# ifndef IOBASE_SPARSE_MEM
+# define IOBASE_SPARSE_MEM 1
+# endif
+# ifndef IOBASE_DENSE_MEM
+# define IOBASE_DENSE_MEM 2
+# endif
+# ifndef IOBASE_SPARSE_IO
+# define IOBASE_SPARSE_IO 3
+# endif
+# ifndef IOBASE_DENSE_IO
+# define IOBASE_DENSE_IO 4
+# endif
+# ifndef IOBASE_ROOT_BUS
+# define IOBASE_ROOT_BUS 5
+# endif
+# ifndef IOBASE_FROM_HOSE
+# define IOBASE_FROM_HOSE 0x10000
+# endif
+# endif /* __alpha__ */
+
+# if defined(DO_OS_FONTRESTORE)
+Bool lnx_savefont(void);
+Bool lnx_restorefont(void);
+Bool lnx_switchaway(void);
+void lnx_freefontdata(void);
+# endif
+
+#define LNX_H_
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c
new file mode 100644
index 000000000..690d3bc8f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c
@@ -0,0 +1,291 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c,v 3.18 2002/01/25 21:56:19 tsi Exp $ */
+
+/* Resource information code */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Privstr.h"
+#include "xf86Pci.h"
+#include "xf86Resources.h"
+#define NEED_OS_RAC_PROTOS
+#include "xf86_OSlib.h"
+#include "lnx.h"
+
+/* Avoid Imakefile changes */
+#include "bus/Pci.h"
+
+resRange PciAvoid[] =
+{
+#if !defined(__sparc__) || !defined(INCLUDE_XF86_NO_DOMAIN)
+ _PCI_AVOID_PC_STYLE,
+#endif
+ _END
+};
+
+#ifdef INCLUDE_XF86_NO_DOMAIN
+
+#ifdef __alpha__
+
+resPtr
+xf86BusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+resPtr
+xf86PciBusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+ /*
+ * On the Alpha the first 16MB of every 128 Mb segment in
+ * sparse address space are an image of the ISA bus range
+ */
+ if (_bus_base_sparse()) {
+ RANGE(range, 0x00000000, 0x07ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x09000000, 0x0fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x11000000, 0x17ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x19000000, 0x1fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x21000000, 0x27ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x29000000, 0x2fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x31000000, 0x37ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x39000000, 0x3fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x41000000, 0x47ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x49000000, 0x4fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x51000000, 0x57ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x59000000, 0x5fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x61000000, 0x67ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x69000000, 0x6fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x71000000, 0x77ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x79000000, 0x7fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x81000000, 0x87ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x89000000, 0x8fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x91000000, 0x97ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x99000000, 0x9fffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xa1000000, 0xa7ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xa9000000, 0xafffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xb1000000, 0xb7ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xb9000000, 0xbfffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xc1000000, 0xc7ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xc9000000, 0xcfffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xd1000000, 0xd7ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xd9000000, 0xdfffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xe1000000, 0xe7ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xe9000000, 0xefffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xf1000000, 0xf7ffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xf9000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ } else {
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ }
+ RANGE(range, 0x00000000, 0xffffffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#ifdef INCLUDE_UNUSED
+
+resPtr
+xf86IsaBusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#endif /* INCLUDE_UNUSED */
+
+resPtr
+xf86AccResFromOS(resPtr ret)
+{
+ resRange range;
+
+ /*
+ * Fallback is to claim the following areas:
+ *
+ * 0x000c0000 - 0x000effff location of VGA and other extensions ROMS
+ */
+
+ RANGE(range, 0x000c0000, 0x000effff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /*
+ * Fallback would be to claim well known ports in the 0x0 - 0x3ff range
+ * along with their sparse I/O aliases, but that's too imprecise. Instead
+ * claim a bare minimum here.
+ */
+ RANGE(range, 0x00000000, 0x000000ff, ResExcIoBlock); /* For mainboard */
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /*
+ * At minimum, the top and bottom resources must be claimed, so that
+ * resources that are (or appear to be) unallocated can be relocated.
+ */
+ RANGE(range, 0x00000000, 0x00000000, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xffffffff, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+/* RANGE(range, 0x00000000, 0x00000000, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1); */
+ RANGE(range, 0xffffffff, 0xffffffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /* XXX add others */
+ return ret;
+}
+
+#elif defined(__powerpc__) || \
+ defined(__sparc__) || \
+ defined(__mips__) || \
+ defined(__sh__) || \
+ defined(__mc68000__) || \
+ defined(__arm__) || \
+ defined(__s390__) || \
+ defined(__hppa__)
+
+ /*
+ * XXX this isn't exactly correct but it will get the server working
+ * for now until we get something better.
+ */
+
+resPtr
+xf86BusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+#if defined(__sparc__) || defined(__powerpc__)
+ RANGE(range, 0x00000000, 0x00ffffff, ResExcIoBlock);
+#else
+ RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock);
+#endif
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+resPtr
+xf86PciBusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+#if defined(__sparc__) || defined(__powerpc__)
+ RANGE(range, 0x00000000, 0x00ffffff, ResExcIoBlock);
+#else
+ RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock);
+#endif
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#ifdef INCLUDE_UNUSED
+
+resPtr
+xf86IsaBusAccWindowsFromOS(void)
+{
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+#if defined(__sparc__) || defined(__powerpc__)
+ RANGE(range, 0x00000000, 0x00ffffff, ResExcIoBlock);
+#else
+ RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock);
+#endif
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#endif /* INCLUDE_UNUSED */
+
+resPtr
+xf86AccResFromOS(resPtr ret)
+{
+ resRange range;
+
+ /*
+ * At minimum, the top and bottom resources must be claimed, so that
+ * resources that are (or appear to be) unallocated can be relocated.
+ */
+ RANGE(range, 0x00000000, 0x00000000, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xffffffff, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x00000000, 0x00000000, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+#if defined(__sparc__) || defined(__powerpc__)
+ RANGE(range, 0x00ffffff, 0x00ffffff, ResExcIoBlock);
+#else
+ RANGE(range, 0x0000ffff, 0x0000ffff, ResExcIoBlock);
+#endif
+ ret = xf86AddResToList(ret, &range, -1);
+
+ return ret;
+}
+
+#else
+
+#error : Put your platform dependent code here!!
+
+#endif
+
+#endif /* INCLUDE_XF86_NO_DOMAIN */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_KbdMap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_KbdMap.c
new file mode 100644
index 000000000..3a5a57b8c
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_KbdMap.c
@@ -0,0 +1,606 @@
+/* $XFree86$ */
+
+/*
+ * Slightly modified xf86KbdLnx.c which is
+ *
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+#include "atKeynames.h"
+
+#include "xf86Keymap.h"
+
+#include "lnx_kbd.h"
+
+/*ARGSUSED*/
+
+/*
+ * KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+static void readKernelMapping(InputInfoPtr pInfo,
+ KeySymsPtr pKeySyms, CARD8 *pModMap);
+void
+KbdGetMapping (InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ KeySym *k;
+ char type;
+ int i;
+
+ readKernelMapping(pInfo, pKeySyms, pModMap);
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+ pKbd->kbdType = ioctl(pInfo->fd, KDGKBTYPE, &type) != -1 ? type : KB_101;
+
+ pKeySyms->map = map;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+}
+
+#include <linux/keyboard.h>
+
+static KeySym linux_to_x[256] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_BackSpace,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_nobreakspace,XK_exclamdown, XK_cent, XK_sterling,
+ XK_currency, XK_yen, XK_brokenbar, XK_section,
+ XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft,
+ XK_notsign, XK_hyphen, XK_registered, XK_macron,
+ XK_degree, XK_plusminus, XK_twosuperior, XK_threesuperior,
+ XK_acute, XK_mu, XK_paragraph, XK_periodcentered,
+ XK_cedilla, XK_onesuperior, XK_masculine, XK_guillemotright,
+ XK_onequarter, XK_onehalf, XK_threequarters,XK_questiondown,
+ XK_Agrave, XK_Aacute, XK_Acircumflex, XK_Atilde,
+ XK_Adiaeresis, XK_Aring, XK_AE, XK_Ccedilla,
+ XK_Egrave, XK_Eacute, XK_Ecircumflex, XK_Ediaeresis,
+ XK_Igrave, XK_Iacute, XK_Icircumflex, XK_Idiaeresis,
+ XK_ETH, XK_Ntilde, XK_Ograve, XK_Oacute,
+ XK_Ocircumflex, XK_Otilde, XK_Odiaeresis, XK_multiply,
+ XK_Ooblique, XK_Ugrave, XK_Uacute, XK_Ucircumflex,
+ XK_Udiaeresis, XK_Yacute, XK_THORN, XK_ssharp,
+ XK_agrave, XK_aacute, XK_acircumflex, XK_atilde,
+ XK_adiaeresis, XK_aring, XK_ae, XK_ccedilla,
+ XK_egrave, XK_eacute, XK_ecircumflex, XK_ediaeresis,
+ XK_igrave, XK_iacute, XK_icircumflex, XK_idiaeresis,
+ XK_eth, XK_ntilde, XK_ograve, XK_oacute,
+ XK_ocircumflex, XK_otilde, XK_odiaeresis, XK_division,
+ XK_oslash, XK_ugrave, XK_uacute, XK_ucircumflex,
+ XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis
+};
+
+/*
+ * Maps the AT keycodes to Linux keycodes
+ */
+static unsigned char at2lnx[NUM_KEYCODES] =
+{
+ 0x01, /* KEY_Escape */ 0x02, /* KEY_1 */
+ 0x03, /* KEY_2 */ 0x04, /* KEY_3 */
+ 0x05, /* KEY_4 */ 0x06, /* KEY_5 */
+ 0x07, /* KEY_6 */ 0x08, /* KEY_7 */
+ 0x09, /* KEY_8 */ 0x0a, /* KEY_9 */
+ 0x0b, /* KEY_0 */ 0x0c, /* KEY_Minus */
+ 0x0d, /* KEY_Equal */ 0x0e, /* KEY_BackSpace */
+ 0x0f, /* KEY_Tab */ 0x10, /* KEY_Q */
+ 0x11, /* KEY_W */ 0x12, /* KEY_E */
+ 0x13, /* KEY_R */ 0x14, /* KEY_T */
+ 0x15, /* KEY_Y */ 0x16, /* KEY_U */
+ 0x17, /* KEY_I */ 0x18, /* KEY_O */
+ 0x19, /* KEY_P */ 0x1a, /* KEY_LBrace */
+ 0x1b, /* KEY_RBrace */ 0x1c, /* KEY_Enter */
+ 0x1d, /* KEY_LCtrl */ 0x1e, /* KEY_A */
+ 0x1f, /* KEY_S */ 0x20, /* KEY_D */
+ 0x21, /* KEY_F */ 0x22, /* KEY_G */
+ 0x23, /* KEY_H */ 0x24, /* KEY_J */
+ 0x25, /* KEY_K */ 0x26, /* KEY_L */
+ 0x27, /* KEY_SemiColon */ 0x28, /* KEY_Quote */
+ 0x29, /* KEY_Tilde */ 0x2a, /* KEY_ShiftL */
+ 0x2b, /* KEY_BSlash */ 0x2c, /* KEY_Z */
+ 0x2d, /* KEY_X */ 0x2e, /* KEY_C */
+ 0x2f, /* KEY_V */ 0x30, /* KEY_B */
+ 0x31, /* KEY_N */ 0x32, /* KEY_M */
+ 0x33, /* KEY_Comma */ 0x34, /* KEY_Period */
+ 0x35, /* KEY_Slash */ 0x36, /* KEY_ShiftR */
+ 0x37, /* KEY_KP_Multiply */ 0x38, /* KEY_Alt */
+ 0x39, /* KEY_Space */ 0x3a, /* KEY_CapsLock */
+ 0x3b, /* KEY_F1 */ 0x3c, /* KEY_F2 */
+ 0x3d, /* KEY_F3 */ 0x3e, /* KEY_F4 */
+ 0x3f, /* KEY_F5 */ 0x40, /* KEY_F6 */
+ 0x41, /* KEY_F7 */ 0x42, /* KEY_F8 */
+ 0x43, /* KEY_F9 */ 0x44, /* KEY_F10 */
+ 0x45, /* KEY_NumLock */ 0x46, /* KEY_ScrollLock */
+ 0x47, /* KEY_KP_7 */ 0x48, /* KEY_KP_8 */
+ 0x49, /* KEY_KP_9 */ 0x4a, /* KEY_KP_Minus */
+ 0x4b, /* KEY_KP_4 */ 0x4c, /* KEY_KP_5 */
+ 0x4d, /* KEY_KP_6 */ 0x4e, /* KEY_KP_Plus */
+ 0x4f, /* KEY_KP_1 */ 0x50, /* KEY_KP_2 */
+ 0x51, /* KEY_KP_3 */ 0x52, /* KEY_KP_0 */
+ 0x53, /* KEY_KP_Decimal */ 0x54, /* KEY_SysReqest */
+ 0x00, /* 0x55 */ 0x56, /* KEY_Less */
+ 0x57, /* KEY_F11 */ 0x58, /* KEY_F12 */
+ 0x66, /* KEY_Home */ 0x67, /* KEY_Up */
+ 0x68, /* KEY_PgUp */ 0x69, /* KEY_Left */
+ 0x5d, /* KEY_Begin */ 0x6a, /* KEY_Right */
+ 0x6b, /* KEY_End */ 0x6c, /* KEY_Down */
+ 0x6d, /* KEY_PgDown */ 0x6e, /* KEY_Insert */
+ 0x6f, /* KEY_Delete */ 0x60, /* KEY_KP_Enter */
+ 0x61, /* KEY_RCtrl */ 0x77, /* KEY_Pause */
+ 0x63, /* KEY_Print */ 0x62, /* KEY_KP_Divide */
+ 0x64, /* KEY_AltLang */ 0x65, /* KEY_Break */
+ 0x00, /* KEY_LMeta */ 0x00, /* KEY_RMeta */
+ 0x7A, /* KEY_Menu/FOCUS_PF11*/0x00, /* 0x6e */
+ 0x7B, /* FOCUS_PF12 */ 0x00, /* 0x70 */
+ 0x00, /* 0x71 */ 0x00, /* 0x72 */
+ 0x59, /* FOCUS_PF2 */ 0x78, /* FOCUS_PF9 */
+ 0x00, /* 0x75 */ 0x00, /* 0x76 */
+ 0x5A, /* FOCUS_PF3 */ 0x5B, /* FOCUS_PF4 */
+ 0x5C, /* FOCUS_PF5 */ 0x5D, /* FOCUS_PF6 */
+ 0x5E, /* FOCUS_PF7 */ 0x5F, /* FOCUS_PF8 */
+ 0x7C, /* JAP_86 */ 0x79, /* FOCUS_PF10 */
+ 0x00, /* 0x7f */
+};
+#define NUM_AT2LNX (sizeof(at2lnx) / sizeof(at2lnx[0]))
+
+#define NUM_CUSTOMKEYS NR_KEYS
+
+static void
+readKernelMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ KeySym *k;
+ int i;
+ int maxkey;
+ static unsigned char tbl[GLYPHS_PER_KEY] =
+ {
+ 0, /* unshifted */
+ 1, /* shifted */
+ 0, /* modeswitch unshifted */
+ 0 /* modeswitch shifted */
+ };
+
+ /*
+ * Read the mapping from the kernel.
+ * Since we're still using the XFree86 scancode->AT keycode mapping
+ * routines, we need to convert the AT keycodes to Linux keycodes,
+ * then translate the Linux keysyms into X keysyms.
+ *
+ * First, figure out which tables to use for the modeswitch columns
+ * above, from the XF86Config fields.
+ */
+ tbl[2] = 8; /* alt */
+ tbl[3] = tbl[2] | 1;
+
+ if (pKbd->CustomKeycodes) {
+ k = map;
+ maxkey = NUM_CUSTOMKEYS;
+ }
+ else {
+ k = map+GLYPHS_PER_KEY;
+ maxkey = NUM_AT2LNX;
+ }
+
+ for (i = 0; i < maxkey; ++i)
+ {
+ struct kbentry kbe;
+ int j;
+
+ if (pKbd->CustomKeycodes)
+ kbe.kb_index = i;
+ else
+ kbe.kb_index = at2lnx[i];
+
+ for (j = 0; j < GLYPHS_PER_KEY; ++j, ++k)
+ {
+ unsigned short kval;
+
+ *k = NoSymbol;
+
+ kbe.kb_table = tbl[j];
+ if (
+ (!pKbd->CustomKeycodes && kbe.kb_index == 0) ||
+ ioctl(pInfo->fd, KDGKBENT, &kbe))
+ continue;
+
+ kval = KVAL(kbe.kb_value);
+ switch (KTYP(kbe.kb_value))
+ {
+ case KT_LATIN:
+ case KT_LETTER:
+ *k = linux_to_x[kval];
+ break;
+
+ case KT_FN:
+ if (kval <= 19)
+ *k = XK_F1 + kval;
+ else switch (kbe.kb_value)
+ {
+ case K_FIND:
+ *k = XK_Home; /* or XK_Find */
+ break;
+ case K_INSERT:
+ *k = XK_Insert;
+ break;
+ case K_REMOVE:
+ *k = XK_Delete;
+ break;
+ case K_SELECT:
+ *k = XK_End; /* or XK_Select */
+ break;
+ case K_PGUP:
+ *k = XK_Prior;
+ break;
+ case K_PGDN:
+ *k = XK_Next;
+ break;
+ case K_HELP:
+ *k = XK_Help;
+ break;
+ case K_DO:
+ *k = XK_Execute;
+ break;
+ case K_PAUSE:
+ *k = XK_Pause;
+ break;
+ case K_MACRO:
+ *k = XK_Menu;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case KT_SPEC:
+ switch (kbe.kb_value)
+ {
+ case K_ENTER:
+ *k = XK_Return;
+ break;
+ case K_BREAK:
+ *k = XK_Break;
+ break;
+ case K_CAPS:
+ *k = XK_Caps_Lock;
+ break;
+ case K_NUM:
+ *k = XK_Num_Lock;
+ break;
+ case K_HOLD:
+ *k = XK_Scroll_Lock;
+ break;
+ case K_COMPOSE:
+ *k = XK_Multi_key;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case KT_PAD:
+ switch (kbe.kb_value)
+ {
+ case K_PPLUS:
+ *k = XK_KP_Add;
+ break;
+ case K_PMINUS:
+ *k = XK_KP_Subtract;
+ break;
+ case K_PSTAR:
+ *k = XK_KP_Multiply;
+ break;
+ case K_PSLASH:
+ *k = XK_KP_Divide;
+ break;
+ case K_PENTER:
+ *k = XK_KP_Enter;
+ break;
+ case K_PCOMMA:
+ *k = XK_KP_Separator;
+ break;
+ case K_PDOT:
+ *k = XK_KP_Decimal;
+ break;
+ case K_PPLUSMINUS:
+ *k = XK_KP_Subtract;
+ break;
+ default:
+ if (kval <= 9)
+ *k = XK_KP_0 + kval;
+ break;
+ }
+ break;
+
+ /*
+ * KT_DEAD keys are for accelerated diacritical creation.
+ */
+ case KT_DEAD:
+ switch (kbe.kb_value)
+ {
+ case K_DGRAVE:
+ *k = XK_dead_grave;
+ break;
+ case K_DACUTE:
+ *k = XK_dead_acute;
+ break;
+ case K_DCIRCM:
+ *k = XK_dead_circumflex;
+ break;
+ case K_DTILDE:
+ *k = XK_dead_tilde;
+ break;
+ case K_DDIERE:
+ *k = XK_dead_diaeresis;
+ break;
+ }
+ break;
+
+ case KT_CUR:
+ switch (kbe.kb_value)
+ {
+ case K_DOWN:
+ *k = XK_Down;
+ break;
+ case K_LEFT:
+ *k = XK_Left;
+ break;
+ case K_RIGHT:
+ *k = XK_Right;
+ break;
+ case K_UP:
+ *k = XK_Up;
+ break;
+ }
+ break;
+
+ case KT_SHIFT:
+ switch (kbe.kb_value)
+ {
+ case K_ALTGR:
+ *k = XK_Alt_R;
+ break;
+ case K_ALT:
+ *k = (kbe.kb_index == 0x64 ?
+ XK_Alt_R : XK_Alt_L);
+ break;
+ case K_CTRL:
+ *k = (kbe.kb_index == 0x61 ?
+ XK_Control_R : XK_Control_L);
+ break;
+ case K_CTRLL:
+ *k = XK_Control_L;
+ break;
+ case K_CTRLR:
+ *k = XK_Control_R;
+ break;
+ case K_SHIFT:
+ *k = (kbe.kb_index == 0x36 ?
+ XK_Shift_R : XK_Shift_L);
+ break;
+ case K_SHIFTL:
+ *k = XK_Shift_L;
+ break;
+ case K_SHIFTR:
+ *k = XK_Shift_R;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ /*
+ * KT_ASCII keys accumulate a 3 digit decimal number that gets
+ * emitted when the shift state changes. We can't emulate that.
+ */
+ case KT_ASCII:
+ break;
+
+ case KT_LOCK:
+ if (kbe.kb_value == K_SHIFTLOCK)
+ *k = XK_Shift_Lock;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (k[-1] == k[-2]) k[-1] = NoSymbol;
+ if (k[-2] == k[-3]) k[-2] = NoSymbol;
+ if (k[-3] == k[-4]) k[-3] = NoSymbol;
+ if (k[-4] == k[-2] && k[-3] == k[-1]) k[-2] = k[-1] = NoSymbol;
+ if (k[-1] == k[-4] && k[-2] == k[-3] && k[-2] == NoSymbol) k[-1] =NoSymbol;
+ }
+
+ if (!pKbd->CustomKeycodes)
+ return;
+
+ /*
+ * Find the Mapping for the special server functions
+ */
+ pKbd->specialMap = (TransMapPtr) xcalloc(NUM_CUSTOMKEYS, 1);
+ if (pKbd->specialMap != NULL) {
+ pKbd->specialMap->end = NUM_CUSTOMKEYS;
+ pKbd->specialMap->map = (unsigned char*) xcalloc(NUM_CUSTOMKEYS, 1);
+ if (pKbd->specialMap == NULL) {
+ xfree(pKbd->specialMap);
+ pKbd->specialMap = NULL;
+ }
+ }
+ if (pKbd->specialMap == NULL) {
+ xf86Msg(X_ERROR, "%s can't allocate \"special map\"\n", pInfo->name);
+ return;
+ }
+
+ for (i = 0; i < NUM_CUSTOMKEYS; ++i) {
+ struct kbentry kbe;
+ int special = 0;
+
+ kbe.kb_index = i;
+ kbe.kb_table = 0; /* Plain map */
+ if (!ioctl(pInfo->fd, KDGKBENT, &kbe))
+ switch (kbe.kb_value) {
+ case K(KT_LATIN,0x7f): /* This catches DEL too... But who cares? */
+ special = KEY_BackSpace;
+ break;
+ case K_PMINUS:
+ special = KEY_KP_Minus;
+ break;
+ case K_PPLUS:
+ special = KEY_KP_Plus;
+ break;
+ case K_F1:
+ special = KEY_F1;
+ break;
+ case K_F2:
+ special = KEY_F2;
+ break;
+ case K_F3:
+ special = KEY_F3;
+ break;
+ case K_F4:
+ special = KEY_F4;
+ break;
+ case K_F5:
+ special = KEY_F5;
+ break;
+ case K_F6:
+ special = KEY_F6;
+ break;
+ case K_F7:
+ special = KEY_F7;
+ break;
+ case K_F8:
+ special = KEY_F8;
+ break;
+ case K_F9:
+ special = KEY_F9;
+ break;
+ case K_F10:
+ special = KEY_F10;
+ break;
+ case K_F11:
+ special = KEY_F11;
+ break;
+ case K_F12:
+ special = KEY_F12;
+ break;
+ case K_ALT:
+ special = KEY_Alt;
+ break;
+ case K_ALTGR:
+ special = KEY_AltLang;
+ break;
+ case K_CONS:
+ special = KEY_SysReqest;
+ break;
+ }
+ pKbd->specialMap->map[i] = special;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c
new file mode 100644
index 000000000..9d1dea77d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c
@@ -0,0 +1,170 @@
+#include "X.h"
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSproc.h"
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#define ACPI_SOCKET "/var/run/acpid.socket"
+#define ACPI_EVENTS "/proc/acpi/event"
+
+#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
+#define ACPI_VIDEO_NOTIFY_PROBE 0x81
+#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
+#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
+#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
+
+#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x82
+#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x83
+#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x84
+#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x85
+#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x86
+
+#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
+#define ACPI_VIDEO_HEAD_END (~0u)
+
+static void lnxCloseACPI(void);
+static pointer ACPIihPtr = NULL;
+PMClose lnxACPIOpen(void);
+
+#define LINE_LENGTH 80
+
+static int
+lnxACPIGetEventFromOs(int fd, pmEvent *events, int num)
+{
+ char ev[LINE_LENGTH];
+ int n;
+
+ memset(ev, 0, LINE_LENGTH);
+
+ n = read( fd, ev, LINE_LENGTH );
+
+ /* Check that we have a video event */
+ if (strstr(ev, "video") == ev) {
+ char *video = NULL;
+ char *GFX = NULL;
+ char *notify = NULL;
+ char *data = NULL; /* doesn't appear to be used in the kernel */
+ unsigned long int notify_l, data_l;
+
+ video = strtok(ev, "video");
+
+ GFX = strtok(NULL, " ");
+#if 0
+ ErrorF("GFX: %s\n",GFX);
+#endif
+
+ notify = strtok(NULL, " ");
+ notify_l = strtoul(notify, NULL, 16);
+#if 0
+ ErrorF("notify: 0x%lx\n",notify_l);
+#endif
+
+ data = strtok(NULL, " ");
+ data_l = strtoul(data, NULL, 16);
+#if 0
+ ErrorF("data: 0x%lx\n",data_l);
+#endif
+
+ /* We currently don't differentiate between any event */
+ switch (notify_l) {
+ case ACPI_VIDEO_NOTIFY_SWITCH:
+ break;
+ case ACPI_VIDEO_NOTIFY_PROBE:
+ break;
+ case ACPI_VIDEO_NOTIFY_CYCLE:
+ break;
+ case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
+ break;
+ case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
+ break;
+ default:
+ break;
+ }
+
+ /* Deal with all ACPI events as a capability change */
+ events[0] = XF86_APM_CAPABILITY_CHANGED;
+
+ return 1;
+ }
+
+ return 0;
+}
+
+static pmWait
+lnxACPIConfirmEventToOs(int fd, pmEvent event)
+{
+ /* No ability to send back to the kernel in ACPI */
+ switch (event) {
+ default:
+ return PM_NONE;
+ }
+}
+
+PMClose
+lnxACPIOpen(void)
+{
+ int fd;
+ struct sockaddr_un addr;
+ int r = -1;
+
+#ifdef DEBUG
+ ErrorF("ACPI: OSPMOpen called\n");
+#endif
+ if (ACPIihPtr || !xf86Info.pmFlag)
+ return NULL;
+
+#ifdef DEBUG
+ ErrorF("ACPI: Opening device\n");
+#endif
+ if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) > -1) {
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_UNIX;
+ strcpy(addr.sun_path, ACPI_SOCKET);
+ if ((r = connect(fd, (struct sockaddr*)&addr, sizeof(addr))) == -1) {
+ shutdown(fd, 2);
+ close(fd);
+ fd = -1;
+ }
+ }
+
+ /* acpid's socket isn't available, so try going direct */
+ if (fd == -1) {
+ if ((fd = open(ACPI_EVENTS, O_RDONLY)) < 0) {
+ xf86MsgVerb(X_WARNING,3,"Open ACPI failed (%s) (%s)\n", ACPI_EVENTS,
+ strerror(errno));
+ return NULL;
+ }
+ }
+
+ xf86PMGetEventFromOs = lnxACPIGetEventFromOs;
+ xf86PMConfirmEventToOs = lnxACPIConfirmEventToOs;
+ ACPIihPtr = xf86AddInputHandler(fd,xf86HandlePMEvents,NULL);
+ xf86MsgVerb(X_INFO,3,"Open ACPI successful (%s)\n", (r != -1) ? ACPI_SOCKET : ACPI_EVENTS);
+
+ return lnxCloseACPI;
+}
+
+static void
+lnxCloseACPI(void)
+{
+ int fd;
+
+#ifdef DEBUG
+ ErrorF("ACPI: Closing device\n");
+#endif
+ if (ACPIihPtr) {
+ fd = xf86RemoveInputHandler(ACPIihPtr);
+ shutdown(fd, 2);
+ close(fd);
+ ACPIihPtr = NULL;
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c
new file mode 100644
index 000000000..6a5c83db2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c
@@ -0,0 +1,371 @@
+/*
+ * Abstraction of the AGP GART interface.
+ *
+ * This version is for both Linux and FreeBSD.
+ *
+ * Copyright © 2000 VA Linux Systems, Inc.
+ * Copyright © 2001 The XFree86 Project, Inc.
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c,v 3.11 2003/04/03 22:47:42 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#if defined(linux)
+#include <asm/ioctl.h>
+#include <linux/agpgart.h>
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#include <sys/ioctl.h>
+#include <sys/agpio.h>
+#endif
+
+#ifndef AGP_DEVICE
+#define AGP_DEVICE "/dev/agpgart"
+#endif
+/* AGP page size is independent of the host page size. */
+#ifndef AGP_PAGE_SIZE
+#define AGP_PAGE_SIZE 4096
+#endif
+#define AGPGART_MAJOR_VERSION 0
+#define AGPGART_MINOR_VERSION 99
+
+static int gartFd = -1;
+static int acquiredScreen = -1;
+static Bool initDone = FALSE;
+/*
+ * Close /dev/agpgart. This frees all associated memory allocated during
+ * this server generation.
+ */
+Bool
+xf86GARTCloseScreen(int screenNum)
+{
+ if(gartFd != -1) {
+ close(gartFd);
+ acquiredScreen = -1;
+ gartFd = -1;
+ initDone = FALSE;
+ }
+ return TRUE;
+}
+
+/*
+ * Open /dev/agpgart. Keep it open until xf86GARTCloseScreen is called.
+ */
+static Bool
+GARTInit(int screenNum)
+{
+ struct _agp_info agpinf;
+
+ if (initDone)
+ return (gartFd != -1);
+
+ initDone = TRUE;
+
+ if (gartFd == -1)
+ gartFd = open(AGP_DEVICE, O_RDWR, 0);
+ else
+ return FALSE;
+
+ if (gartFd == -1) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "GARTInit: Unable to open " AGP_DEVICE " (%s)\n",
+ strerror(errno));
+ return FALSE;
+ }
+
+ xf86AcquireGART(-1);
+ /* Check the kernel driver version. */
+ if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "GARTInit: AGPIOC_INFO failed (%s)\n", strerror(errno));
+ close(gartFd);
+ gartFd = -1;
+ return FALSE;
+ }
+ xf86ReleaseGART(-1);
+
+#if defined(linux)
+ /* Per Dave Jones, every effort will be made to keep the
+ * agpgart interface backwards compatible, so allow all
+ * future versions.
+ */
+ if (
+#if (AGPGART_MAJOR_VERSION > 0) /* quiet compiler */
+ agpinf.version.major < AGPGART_MAJOR_VERSION ||
+#endif
+ (agpinf.version.major == AGPGART_MAJOR_VERSION &&
+ agpinf.version.minor < AGPGART_MINOR_VERSION)) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "GARTInit: Kernel agpgart driver version is not current"
+ " (%d.%d vs %d.%d)\n",
+ agpinf.version.major, agpinf.version.minor,
+ AGPGART_MAJOR_VERSION, AGPGART_MINOR_VERSION);
+ close(gartFd);
+ gartFd = -1;
+ return FALSE;
+ }
+#endif
+
+ return TRUE;
+}
+
+Bool
+xf86AgpGARTSupported()
+{
+ return GARTInit(-1);
+}
+
+AgpInfoPtr
+xf86GetAGPInfo(int screenNum)
+{
+ struct _agp_info agpinf;
+ AgpInfoPtr info;
+
+ if (!GARTInit(screenNum))
+ return NULL;
+
+
+ if ((info = xcalloc(sizeof(AgpInfo), 1)) == NULL) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "xf86GetAGPInfo: Failed to allocate AgpInfo\n");
+ return NULL;
+ }
+
+ memset((char*)&agpinf, 0, sizeof(agpinf));
+
+ if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n",
+ strerror(errno));
+ return NULL;
+ }
+
+ info->bridgeId = agpinf.bridge_id;
+ info->agpMode = agpinf.agp_mode;
+ info->base = agpinf.aper_base;
+ info->size = agpinf.aper_size;
+ info->totalPages = agpinf.pg_total;
+ info->systemPages = agpinf.pg_system;
+ info->usedPages = agpinf.pg_used;
+
+ xf86DrvMsg(screenNum, X_INFO, "Kernel reported %d total, %d used\n", agpinf.pg_total, agpinf.pg_used);
+
+ return info;
+}
+
+/*
+ * XXX If multiple screens can acquire the GART, should we have a reference
+ * count instead of using acquiredScreen?
+ */
+
+Bool
+xf86AcquireGART(int screenNum)
+{
+ if (screenNum != -1 && !GARTInit(screenNum))
+ return FALSE;
+
+ if (screenNum == -1 || acquiredScreen != screenNum) {
+ if (ioctl(gartFd, AGPIOC_ACQUIRE, 0) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "xf86AcquireGART: AGPIOC_ACQUIRE failed (%s)\n",
+ strerror(errno));
+ return FALSE;
+ }
+ acquiredScreen = screenNum;
+ }
+ return TRUE;
+}
+
+Bool
+xf86ReleaseGART(int screenNum)
+{
+ if (screenNum != -1 && !GARTInit(screenNum))
+ return FALSE;
+
+ if (acquiredScreen == screenNum) {
+ /*
+ * The FreeBSD agp driver removes allocations on release.
+ * The Linux driver doesn't. xf86ReleaseGART() is expected
+ * to give up access to the GART, but not to remove any
+ * allocations.
+ */
+#if !defined(linux)
+ if (screenNum == -1)
+#endif
+ {
+ if (ioctl(gartFd, AGPIOC_RELEASE, 0) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "xf86ReleaseGART: AGPIOC_RELEASE failed (%s)\n",
+ strerror(errno));
+ return FALSE;
+ }
+ acquiredScreen = -1;
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+int
+xf86AllocateGARTMemory(int screenNum, unsigned long size, int type,
+ unsigned long *physical)
+{
+ struct _agp_allocate alloc;
+ int pages;
+
+ /*
+ * Allocates "size" bytes of GART memory (rounds up to the next
+ * page multiple) or type "type". A handle (key) for the allocated
+ * memory is returned. On error, the return value is -1.
+ */
+
+ if (!GARTInit(screenNum) || acquiredScreen != screenNum)
+ return -1;
+
+ pages = (size / AGP_PAGE_SIZE);
+ if (size % AGP_PAGE_SIZE != 0)
+ pages++;
+
+ /* XXX check for pages == 0? */
+
+ alloc.pg_count = pages;
+ alloc.type = type;
+
+ if (ioctl(gartFd, AGPIOC_ALLOCATE, &alloc) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86AllocateGARTMemory: "
+ "allocation of %d pages failed\n\t(%s)\n", pages,
+ strerror(errno));
+ return -1;
+ }
+
+ if (physical)
+ *physical = alloc.physical;
+
+ return alloc.key;
+}
+
+Bool
+xf86DeallocateGARTMemory(int screenNum, int key)
+{
+ if (!GARTInit(screenNum) || acquiredScreen != screenNum)
+ return FALSE;
+
+ if (acquiredScreen != screenNum) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "xf86UnbindGARTMemory: AGP not acquired by this screen\n");
+ return FALSE;
+ }
+
+ if (ioctl(gartFd, AGPIOC_DEALLOCATE, (int *)key) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING,"xf86DeAllocateGARTMemory: "
+ "deallocation gart memory with key %d failed\n\t(%s)\n",
+ key, strerror(errno));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Bind GART memory with "key" at "offset" */
+Bool
+xf86BindGARTMemory(int screenNum, int key, unsigned long offset)
+{
+ struct _agp_bind bind;
+ int pageOffset;
+
+ if (!GARTInit(screenNum) || acquiredScreen != screenNum)
+ return FALSE;
+
+ if (acquiredScreen != screenNum) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "xf86BindGARTMemory: AGP not acquired by this screen\n");
+ return FALSE;
+ }
+
+ if (offset % AGP_PAGE_SIZE != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: "
+ "offset (0x%lx) is not page-aligned (%d)\n",
+ offset, AGP_PAGE_SIZE);
+ return FALSE;
+ }
+ pageOffset = offset / AGP_PAGE_SIZE;
+
+ xf86DrvMsgVerb(screenNum, X_INFO, 3,
+ "xf86BindGARTMemory: bind key %d at 0x%08lx "
+ "(pgoffset %d)\n", key, offset, pageOffset);
+
+ bind.pg_start = pageOffset;
+ bind.key = key;
+
+ if (ioctl(gartFd, AGPIOC_BIND, &bind) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: "
+ "binding of gart memory with key %d\n"
+ "\tat offset 0x%lx failed (%s)\n",
+ key, offset, strerror(errno));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/* Unbind GART memory with "key" */
+Bool
+xf86UnbindGARTMemory(int screenNum, int key)
+{
+ struct _agp_unbind unbind;
+
+ if (!GARTInit(screenNum) || acquiredScreen != screenNum)
+ return FALSE;
+
+ if (acquiredScreen != screenNum) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "xf86UnbindGARTMemory: AGP not acquired by this screen\n");
+ return FALSE;
+ }
+
+ unbind.priority = 0;
+ unbind.key = key;
+
+ if (ioctl(gartFd, AGPIOC_UNBIND, &unbind) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86UnbindGARTMemory: "
+ "unbinding of gart memory with key %d "
+ "failed (%s)\n", key, strerror(errno));
+ return FALSE;
+ }
+
+ xf86DrvMsgVerb(screenNum, X_INFO, 3,
+ "xf86UnbindGARTMemory: unbind key %d\n", key);
+
+ return TRUE;
+}
+
+
+/* XXX Interface may change. */
+Bool
+xf86EnableAGP(int screenNum, CARD32 mode)
+{
+ agp_setup setup;
+
+ if (!GARTInit(screenNum) || acquiredScreen != screenNum)
+ return FALSE;
+
+ setup.agp_mode = mode;
+ if (ioctl(gartFd, AGPIOC_SETUP, &setup) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86EnableAGP: "
+ "AGPIOC_SETUP with mode %ld failed (%s)\n",
+ (unsigned long)mode, strerror(errno));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c
new file mode 100644
index 000000000..bd78d877f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c
@@ -0,0 +1,192 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c,v 3.12 2001/12/24 22:54:31 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSproc.h"
+#include "lnx.h"
+#include <linux/apm_bios.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#define APM_PROC "/proc/apm"
+#define APM_DEVICE "/dev/apm_bios"
+
+#ifndef APM_STANDBY_FAILED
+# define APM_STANDBY_FAILED 0xf000
+#endif
+#ifndef APM_SUSPEND_FAILED
+# define APM_SUSPEND_FAILED 0xf001
+#endif
+
+static PMClose lnxAPMOpen(void);
+extern PMClose lnxACPIOpen(void);
+static void lnxCloseAPM(void);
+static pointer APMihPtr = NULL;
+
+static struct {
+ apm_event_t apmLinux;
+ pmEvent xf86;
+} LinuxToXF86[] = {
+ { APM_SYS_STANDBY, XF86_APM_SYS_STANDBY },
+ { APM_SYS_SUSPEND, XF86_APM_SYS_SUSPEND },
+ { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME },
+ { APM_CRITICAL_RESUME, XF86_APM_CRITICAL_RESUME },
+ { APM_LOW_BATTERY, XF86_APM_LOW_BATTERY },
+ { APM_POWER_STATUS_CHANGE, XF86_APM_POWER_STATUS_CHANGE },
+ { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME },
+ { APM_CRITICAL_SUSPEND, XF86_APM_CRITICAL_SUSPEND },
+ { APM_USER_STANDBY, XF86_APM_USER_STANDBY },
+ { APM_USER_SUSPEND, XF86_APM_USER_SUSPEND },
+ { APM_STANDBY_RESUME, XF86_APM_STANDBY_RESUME },
+#if defined(APM_CAPABILITY_CHANGED)
+ { APM_CAPABILITY_CHANGED, XF86_CAPABILITY_CHANGED },
+#endif
+#if 0
+ { APM_STANDBY_FAILED, XF86_APM_STANDBY_FAILED },
+ { APM_SUSPEND_FAILED, XF86_APM_SUSPEND_FAILED }
+#endif
+};
+
+#define numApmEvents (sizeof(LinuxToXF86) / sizeof(LinuxToXF86[0]))
+
+/*
+ * APM is still under construction.
+ * I'm not sure if the places where I initialize/deinitialize
+ * apm is correct. Also I don't know what to do in SETUP state.
+ * This depends if wakeup gets called in this situation, too.
+ * Also we need to check if the action that is taken on an
+ * event is reasonable.
+ */
+static int
+lnxPMGetEventFromOs(int fd, pmEvent *events, int num)
+{
+ int i,j,n;
+ apm_event_t linuxEvents[8];
+
+ if ((n = read( fd, linuxEvents, num * sizeof(apm_event_t) )) == -1)
+ return 0;
+ n /= sizeof(apm_event_t);
+ if (n > num)
+ n = num;
+ for (i = 0; i < n; i++) {
+ for (j = 0; j < numApmEvents; j++)
+ if (LinuxToXF86[j].apmLinux == linuxEvents[i]) {
+ events[i] = LinuxToXF86[j].xf86;
+ break;
+ }
+ if (j == numApmEvents)
+ events[i] = XF86_APM_UNKNOWN;
+ }
+ return n;
+}
+
+static pmWait
+lnxPMConfirmEventToOs(int fd, pmEvent event)
+{
+ switch (event) {
+ case XF86_APM_SYS_STANDBY:
+ case XF86_APM_USER_STANDBY:
+ if (ioctl( fd, APM_IOC_STANDBY, NULL ))
+ return PM_FAILED;
+ return PM_CONTINUE;
+ case XF86_APM_SYS_SUSPEND:
+ case XF86_APM_CRITICAL_SUSPEND:
+ case XF86_APM_USER_SUSPEND:
+ if (ioctl( fd, APM_IOC_SUSPEND, NULL )) {
+ /* I believe this is wrong (EE)
+ EBUSY is sent when a device refuses to be suspended.
+ In this case we still need to undo everything we have
+ done to suspend ourselves or we will stay in suspended
+ state forever. */
+ if (errno == EBUSY)
+ return PM_CONTINUE;
+ else
+ return PM_FAILED;
+ }
+ return PM_CONTINUE;
+ case XF86_APM_STANDBY_RESUME:
+ case XF86_APM_NORMAL_RESUME:
+ case XF86_APM_CRITICAL_RESUME:
+ case XF86_APM_STANDBY_FAILED:
+ case XF86_APM_SUSPEND_FAILED:
+ return PM_CONTINUE;
+ default:
+ return PM_NONE;
+ }
+}
+
+PMClose
+xf86OSPMOpen(void)
+{
+ PMClose ret = NULL;
+
+ /* Favour ACPI over APM, but only when enabled */
+
+ if (!xf86acpiDisableFlag)
+ ret = lnxACPIOpen();
+
+ if (!ret)
+ ret = lnxAPMOpen();
+
+ return ret;
+}
+
+static PMClose
+lnxAPMOpen(void)
+{
+ int fd, pfd;
+
+#ifdef DEBUG
+ ErrorF("APM: OSPMOpen called\n");
+#endif
+ if (APMihPtr || !xf86Info.pmFlag)
+ return NULL;
+
+#ifdef DEBUG
+ ErrorF("APM: Opening device\n");
+#endif
+ if ((fd = open( APM_DEVICE, O_RDWR )) > -1) {
+ if (access( APM_PROC, R_OK ) ||
+ ((pfd = open( APM_PROC, O_RDONLY)) == -1)) {
+ xf86MsgVerb(X_WARNING,3,"Cannot open APM (%s) (%s)\n",
+ APM_PROC, strerror(errno));
+ close(fd);
+ return NULL;
+ } else
+ close(pfd);
+ xf86PMGetEventFromOs = lnxPMGetEventFromOs;
+ xf86PMConfirmEventToOs = lnxPMConfirmEventToOs;
+ APMihPtr = xf86AddInputHandler(fd,xf86HandlePMEvents,NULL);
+ xf86MsgVerb(X_INFO,3,"Open APM successful\n");
+ return lnxCloseAPM;
+ }
+ xf86MsgVerb(X_INFO,3,"No APM support in BIOS or kernel\n");
+ return NULL;
+}
+
+static void
+lnxCloseAPM(void)
+{
+ int fd;
+
+#ifdef DEBUG
+ ErrorF("APM: Closing device\n");
+#endif
+ if (APMihPtr) {
+ fd = xf86RemoveInputHandler(APMihPtr);
+ close(fd);
+ APMihPtr = NULL;
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c
new file mode 100644
index 000000000..fd47a5559
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c
@@ -0,0 +1,200 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c,v 1.3 2001/02/15 11:03:56 alanh Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "shared/xf86Axp.h"
+
+axpDevice lnxGetAXP(void);
+
+typedef struct
+ { char* sysName;
+ char* sysVari;
+ char* cpu;
+ axpDevice sys; }
+AXP;
+
+static AXP axpList[] = {
+ { "Tsunami", NULL, NULL, TSUNAMI },
+ { "Eiger", NULL, NULL, TSUNAMI },
+ {"Noname", NULL, NULL, LCA },
+ { "AlphaBook1", NULL, NULL, LCA },
+ {"EB66", NULL, NULL, LCA},
+ {"EB64+",NULL,NULL, APECS},
+ {"Noritake",NULL,"EV5",CIA},
+ {"Noritake",NULL,"EV56",CIA},
+ {"Noritake",NULL,NULL,APECS},
+ {"XL",NULL,NULL,APECS},
+ {"Avanti",NULL,NULL,APECS},
+ {"Mikasa",NULL,"EV5",CIA},
+ {"Mikasa",NULL,"EV56",CIA},
+ {"Mikasa",NULL,NULL,APECS},
+ {"EB164","EB164",NULL,CIA},
+ {"EB164","PC164", NULL,CIA},
+ {"EB164","LX164",NULL, PYXIS},
+ {"EB164","SX164",NULL, PYXIS},
+ {"EB164","RX164",NULL, POLARIS},
+ {"Alcor",NULL,NULL,CIA},
+ {"Takara",NULL,NULL,CIA},
+ {"Sable",NULL, "EV5",T2_GAMMA},
+ {"Sable",NULL,"EV56",T2_GAMMA},
+ {"Sable",NULL,NULL,T2},
+ {"Rawhide",NULL,NULL,MCPCIA},
+ {"Jensen",NULL,NULL,JENSEN},
+ {"Miata",NULL,NULL,PYXIS_CIA},
+ {"Ruffian",NULL,NULL,PYXIS_CIA},
+ {"Nautilus",NULL,NULL,IRONGATE},
+ {NULL,NULL,NULL,NONE}
+};
+
+
+axpDevice
+lnxGetAXP(void)
+{
+ FILE *file;
+ int count = 0;
+ char res[256];
+ char cpu[255];
+ char systype[255];
+ char sysvari[255];
+ if (!(file = fopen("/proc/cpuinfo","r")))
+ return SYS_NONE;
+ do {
+ if (!fgets(res,0xff,file)) return SYS_NONE;
+ switch (count) {
+ case 1:
+ sscanf(res, "cpu model : %s",cpu);
+#ifdef DEBUG
+ ErrorF("CPU %s\n",cpu);
+#endif
+ break;
+ case 5:
+ sscanf(res, "system type : %s",systype);
+#ifdef DEBUG
+ ErrorF("system type : %s\n",systype);
+#endif
+ break;
+ case 6:
+ sscanf(res, "system variation : %s",sysvari);
+#ifdef DEBUG
+ ErrorF("system variation: %s\n",sysvari);
+#endif
+ break;
+ }
+ count++;
+ } while (count < 8);
+
+ fclose(file);
+
+ count = 0;
+
+ do {
+ if (!axpList[count].sysName || !strcmp(axpList[count].sysName,systype)) {
+ if (axpList[count].sysVari && strcmp(axpList[count].sysVari,sysvari)) {
+ count++;
+ continue;
+ };
+ if (axpList[count].cpu && strcmp(axpList[count].cpu,cpu)) {
+ count++;
+ continue;
+ }
+ return axpList[count].sys;
+ }
+ count++;
+ } while (1);
+}
+
+/*
+ * pciconfig_iobase wrappers and dynamic i/o selection
+ */
+#include <linux/unistd.h>
+#include <asm/pci.h>
+#include <errno.h>
+
+/* glibc versions (single hose only) */
+extern void _outb(char val, unsigned long port);
+extern void _outw(short val, unsigned long port);
+extern void _outl(int val, unsigned long port);
+extern unsigned int _inb(unsigned long port);
+extern unsigned int _inw(unsigned long port);
+extern unsigned int _inl(unsigned long port);
+
+extern void _dense_outb(char, unsigned long);
+extern void _dense_outw(short, unsigned long);
+extern void _dense_outl(int, unsigned long);
+extern unsigned int _dense_inb(unsigned long);
+extern unsigned int _dense_inw(unsigned long);
+extern unsigned int _dense_inl(unsigned long);
+
+void (*_alpha_outb)(char, unsigned long) = _outb;
+void (*_alpha_outw)(short, unsigned long) = _outw;
+void (*_alpha_outl)(int, unsigned long) = _outl;
+unsigned int (*_alpha_inb)(unsigned long) = _inb;
+unsigned int (*_alpha_inw)(unsigned long) = _inw;
+unsigned int (*_alpha_inl)(unsigned long) = _inl;
+
+static long _alpha_iobase_query(unsigned, int, int, int);
+long (*_iobase)(unsigned, int, int, int) = _alpha_iobase_query;
+
+static long
+_alpha_iobase(unsigned flags, int hose, int bus, int devfn)
+{
+#ifdef __NR_pciconfig_iobase
+ if (bus < 0) {
+ bus = hose;
+ flags |= IOBASE_FROM_HOSE;
+ }
+
+ return syscall(__NR_pciconfig_iobase, flags, bus, devfn);
+#else
+ return -ENOSYS
+#endif
+}
+
+static long
+_alpha_iobase_legacy(unsigned flags, int hose, int bus, int devfn)
+{
+ if (hose > 0) return -ENODEV;
+ if (flags & IOBASE_DENSE_MEM) return _bus_base();
+ if (flags & IOBASE_SPARSE_MEM) return _bus_base_sparse();
+ return 0;
+}
+
+static long
+_alpha_iobase_query(unsigned flags, int hose, int bus, int devfn)
+{
+ /*
+ * Only use iobase if the syscall is supported *and* it's
+ * a dense io system
+ */
+ if (_alpha_iobase(IOBASE_DENSE_IO, 0, 0, 0) > 0) {
+ /*
+ * The syscall worked and it's a dense io system - take over the
+ * io subsystem
+ */
+ _iobase = _alpha_iobase;
+
+#ifndef INCLUDE_XF86_NO_DOMAIN
+ /*
+ * Only take over the inx/outx functions if this is a dense I/O
+ * system *and* addressing domains are being used. The dense I/O
+ * routines expect I/O to be mapped (as done in xf86MapDomainIO)
+ */
+ _alpha_outb = _dense_outb;
+ _alpha_outw = _dense_outw;
+ _alpha_outl = _dense_outl;
+ _alpha_inb = _dense_inb;
+ _alpha_inw = _dense_inw;
+ _alpha_inl = _dense_inl;
+#endif /* !INCLUDE_XF86_NO_DOMAIN */
+ } else _iobase = _alpha_iobase_legacy;
+
+ return _iobase(flags, hose, bus, devfn);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c
new file mode 100644
index 000000000..63077e907
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c
@@ -0,0 +1,151 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c,v 3.5 2000/02/17 13:45:49 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+int readDense8(pointer Base, register unsigned long Offset);
+int readDense16(pointer Base, register unsigned long Offset);
+int readDense32(pointer Base, register unsigned long Offset);
+void
+writeDenseNB8(int Value, pointer Base, register unsigned long Offset);
+void
+writeDenseNB16(int Value, pointer Base, register unsigned long Offset);
+void
+writeDenseNB32(int Value, pointer Base, register unsigned long Offset);
+void
+writeDense8(int Value, pointer Base, register unsigned long Offset);
+void
+writeDense16(int Value, pointer Base, register unsigned long Offset);
+void
+writeDense32(int Value, pointer Base, register unsigned long Offset);
+
+int
+readDense8(pointer Base, register unsigned long Offset)
+{
+ mem_barrier();
+ return *(volatile CARD8*) ((unsigned long)Base+(Offset));
+}
+
+int
+readDense16(pointer Base, register unsigned long Offset)
+{
+ mem_barrier();
+ return *(volatile CARD16*) ((unsigned long)Base+(Offset));
+}
+
+int
+readDense32(pointer Base, register unsigned long Offset)
+{
+ mem_barrier();
+ return *(volatile CARD32*)((unsigned long)Base+(Offset));
+}
+
+void
+writeDenseNB8(int Value, pointer Base, register unsigned long Offset)
+{
+ *(volatile CARD8*)((unsigned long)Base+(Offset)) = Value;
+}
+
+void
+writeDenseNB16(int Value, pointer Base, register unsigned long Offset)
+{
+ *(volatile CARD16*)((unsigned long)Base + (Offset)) = Value;
+}
+
+void
+writeDenseNB32(int Value, pointer Base, register unsigned long Offset)
+{
+ *(volatile CARD32*)((unsigned long)Base+(Offset)) = Value;
+}
+
+void
+writeDense8(int Value, pointer Base, register unsigned long Offset)
+{
+ write_mem_barrier();
+ *(volatile CARD8 *)((unsigned long)Base+(Offset)) = Value;
+}
+
+void
+writeDense16(int Value, pointer Base, register unsigned long Offset)
+{
+ write_mem_barrier();
+ *(volatile CARD16 *)((unsigned long)Base+(Offset)) = Value;
+}
+
+void
+writeDense32(int Value, pointer Base, register unsigned long Offset)
+{
+ write_mem_barrier();
+ *(volatile CARD32 *)((unsigned long)Base+(Offset)) = Value;
+}
+
+
+#ifndef INCLUDE_XF86_NO_DOMAIN
+
+void
+_dense_outb(char val, unsigned long port)
+{
+ if ((port & ~0xffff) == 0) return _outb(val, port);
+
+ write_mem_barrier();
+ *(volatile CARD8 *)port = val;
+}
+
+void
+_dense_outw(short val, unsigned long port)
+{
+ if ((port & ~0xffff) == 0) return _outw(val, port);
+
+ write_mem_barrier();
+ *(volatile CARD16 *)port = val;
+}
+
+void
+_dense_outl(int val, unsigned long port)
+{
+ if ((port & ~0xffff) == 0) return _outl(val, port);
+
+ write_mem_barrier();
+ *(volatile CARD32 *)port = val;
+}
+
+unsigned int
+_dense_inb(unsigned long port)
+{
+ if ((port & ~0xffff) == 0) return _inb(port);
+
+ mem_barrier();
+ return *(volatile CARD8 *)port;
+}
+
+unsigned int
+_dense_inw(unsigned long port)
+{
+ if ((port & ~0xffff) == 0) return _inw(port);
+
+ mem_barrier();
+ return *(volatile CARD16 *)port;
+}
+
+unsigned int
+_dense_inl(unsigned long port)
+{
+ if ((port & ~0xffff) == 0) return _inl(port);
+
+ mem_barrier();
+ return *(volatile CARD32 *)port;
+}
+
+#endif /* !INCLUDE_XF86_NO_DOMAIN */
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c
new file mode 100644
index 000000000..e9a5b6aef
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c
@@ -0,0 +1,291 @@
+/*
+ * Copyright 2004, Egbert Eich
+ *
+ * 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
+ * EGBERT EICH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+ * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Egbert Eich shall not
+ * be used in advertising or otherwise to promote the sale, use or other deal-
+ *ings in this Software without prior written authorization from Egbert Eich.
+ *
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "lnx.h"
+
+#include <sys/stat.h>
+#include <string.h>
+#include <errno.h>
+
+struct {
+ int width;
+ int height;
+ int charcount;
+ unsigned char *data;
+} lnxfont = { 0, 0, 0, NULL };
+
+
+static Bool
+getfont(int *width, int *height,
+ int *charcount, unsigned char *data)
+{
+ struct console_font_op op;
+ struct consolefontdesc ds;
+ int result;
+
+ op.op = KD_FONT_OP_GET;
+ op.width = *width;
+ op.height = *height;
+ op.charcount = *charcount;
+ op.data = data;
+ op.flags = 0;
+
+ SYSCALL(result = ioctl(xf86Info.consoleFd, KDFONTOP, &op));
+#ifdef DEBUG
+ ErrorF("Console font read: h: %i count: %i\n",op.height,op.charcount);
+#endif
+
+ if (!result) {
+
+ *width = op.width;
+ *height = op.height;
+ *charcount = op.charcount;
+
+ return TRUE;
+ }
+
+ if (errno != ENOSYS && errno != EINVAL)
+ return FALSE;
+
+ /* GIO_FONTX fallback */
+ ds.charcount = *charcount;
+ ds.charheight = *height;
+ ds.chardata = (char *)data;
+ *width = 8;
+
+ SYSCALL(result = ioctl(xf86Info.consoleFd, GIO_FONTX, &ds));
+
+ if (!result) {
+
+ *charcount = ds.charcount;
+ *height = ds.charheight;
+
+ return TRUE;
+ }
+
+ if (errno != ENOSYS && errno != EINVAL)
+ return FALSE;
+
+ /* GIO_FONT fallback */
+ if (*charcount < 256)
+ return FALSE;
+
+ SYSCALL(result = ioctl(xf86Info.consoleFd, GIO_FONT, data));
+
+ if (!result) {
+ *height = 0;
+ *charcount = 512;
+ return TRUE;
+ }
+
+ return FALSE;
+
+}
+
+#define VERSION_LEN 31
+
+Bool
+lnx_savefont(void)
+{
+ unsigned char *fontdata;
+#if CHECK_OS_VERSION
+ char kernel_version[VERSION_LEN + 1];
+ int k_major, k_minor, k_release;
+#endif
+ int size;
+ int fd;
+ int width = 32, height = 32, charcount = 2048;
+
+#ifdef DEBUG
+ ErrorF("SAVE font\n");
+#endif
+
+#if CHECK_OS_VERSION
+ /* Check if the kernel has full support for this */
+ if ((fd = open ("/proc/sys/kernel/osrelease",O_RDONLY)) == -1) {
+ close (fd);
+ return TRUE;
+ }
+ size = read(fd, kernel_version, VERSION_LEN);
+ close (fd);
+
+ if (size < 0)
+ return TRUE;
+
+ size = sscanf(kernel_version, "%d.%d.%d",&k_major,&k_minor,&k_release);
+ if (size < 3
+ || (k_major < 2)
+ || ((k_major == 2)
+ && ((k_minor < 6)
+ || ( k_minor == 6
+ && k_release < 11))))
+ return TRUE;
+#endif
+
+ /* if we are in fbdev mode we don't bother saving fonts */
+ if ((fd = open ("/dev/fb0",O_RDWR)) != -1) {
+ close (fd);
+ return TRUE;
+ }
+
+ if (!getfont(&width, &height, &charcount, NULL)) {
+ xf86Msg(X_WARNING,
+ "lnx_savefont: cannot obtain font info\n");
+ goto error;
+ } else if (charcount == 2048) {
+ xf86Msg(X_WARNING, "lnx_savefont: "
+ "kernel bug: kernel doesn't report font info\n");
+ return FALSE;
+ }
+
+ size = (width + 7)/8 * 32 * charcount;
+ fontdata = (unsigned char *)xnfalloc(size);
+ if (!fontdata) {
+ xf86Msg(X_WARNING,
+ "lnx_savefont: cannot allocate memory to save font\n");
+ goto error;
+ }
+
+ if (!getfont(&width, &height, &charcount, fontdata)) {
+ xf86Msg(X_WARNING,"lnx_savefont: cannot read font data\n");
+ goto error;
+ }
+ lnxfont.width = width;
+ lnxfont.height = height;
+ lnxfont.charcount = charcount;
+ lnxfont.data = fontdata;
+
+ return TRUE;
+
+ error:
+ return FALSE;
+}
+
+static Bool
+setfont(int width, int height,
+ int charcount, unsigned char *data)
+{
+ struct console_font_op op;
+ struct consolefontdesc ds;
+ int result;
+
+ op.op = KD_FONT_OP_SET;
+ op.flags = 0;
+ op.charcount = charcount;
+ op.width = width;
+ op.height = height;
+ op.data = data;
+
+ SYSCALL(result = ioctl(xf86Info.consoleFd, KDFONTOP, &op));
+
+ if (!result)
+ return TRUE;
+
+ if (errno != ENOSYS && errno != EINVAL)
+ return FALSE;
+
+ /* PIO_FONTX fallback */
+ if (width != 8)
+ return FALSE;
+
+ ds.charcount = charcount;
+ ds.chardata = (char *)data;
+ ds.charheight = height;
+ SYSCALL(result = ioctl(xf86Info.consoleFd, PIO_FONTX, &ds));
+
+ if (!result)
+ return TRUE;
+
+ if (errno != ENOSYS && errno != EINVAL)
+ return FALSE;
+
+ /* PIO_FONT fallback */
+ SYSCALL(result = ioctl(xf86Info.consoleFd, PIO_FONT, data));
+
+ if (!result)
+ return TRUE;
+
+ return FALSE;
+}
+
+Bool
+lnx_restorefont(void)
+{
+ if (lnxfont.data == NULL)
+ return FALSE;
+#ifdef DEBUG
+ ErrorF("RESTORE font\n");
+#endif
+#if 0
+ /* must wack the height to make the kernel reprogram the VGA registers */
+ if (!setfont(lnxfont.width, lnxfont.height + 1, lnxfont.charcount,
+ lnxfont.data)) {
+ xf86Msg(X_WARNING,"lnx_fontretore: cannot write font data\n");
+ return FALSE;
+ }
+#endif
+ if (!setfont(lnxfont.width, lnxfont.height, lnxfont.charcount,
+ lnxfont.data)) {
+ xf86Msg(X_WARNING,"lnx_restorefont: cannot write font data\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+Bool
+lnx_switchaway(void)
+{
+ Bool ret;
+
+ /* temporarily switch to text mode */
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT);
+ ret = lnx_restorefont();
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS);
+ return ret;
+}
+
+void
+lnx_freefontdata(void)
+{
+ if (lnxfont.data == NULL)
+ return;
+
+ xfree(lnxfont.data);
+ lnxfont.data = NULL;
+ lnxfont.width = lnxfont.height = lnxfont.charcount = 0;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ia64.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ia64.c
new file mode 100644
index 000000000..5f742d01f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ia64.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2004, Egbert Eich
+ *
+ * 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
+ * EGBERT EICH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+ * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Egbert Eich shall not
+ * be used in advertising or otherwise to promote the sale, use or other deal-
+ *ings in this Software without prior written authorization from Egbert Eich.
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/utsname.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "ia64Pci.h"
+#include "Pci.h"
+
+#if defined OS_PROBE_PCI_CHIPSET
+IA64Chipset OS_PROBE_PCI_CHIPSET(scanpciWrapperOpt flags)
+{
+ struct stat unused;
+ struct utsname utsName;
+
+ if (!stat("/proc/bus/mckinley/zx1",&unused)
+ || !stat("/proc/bus/mckinley/zx2",&unused))
+ return ZX1_CHIPSET;
+
+ if (!stat("/proc/sgi_sn/licenseID", &unused)) {
+ int major, minor, patch;
+ char *c;
+
+ /* We need a 2.6.11 or better kernel for Altix support */
+ uname(&utsName);
+ c = utsName.release;
+
+ major = atoi(c);
+ c = strstr(c, ".") + 1;
+ minor = atoi(c);
+ c = strstr(c, ".") + 1;
+ patch = atoi(c);
+
+ if (major < 2 || (major == 2 && minor < 6) ||
+ (major == 2 && minor == 6 && patch < 11)) {
+ ErrorF("Kernel 2.6.11 or better needed for Altix support\n");
+ return NONE_CHIPSET;
+ }
+ return ALTIX_CHIPSET;
+ }
+
+ return NONE_CHIPSET;
+}
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c
new file mode 100644
index 000000000..1eb0f33fe
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c
@@ -0,0 +1,415 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 1.9 2005/08/26 07:35:55 daniels Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 3.14 2001/10/31 22:50:30 tsi Exp $ */
+/*
+ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Orest Zborowski and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Orest Zborowski
+ * and David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: lnx_init.c /main/7 1996/10/23 18:46:30 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "lnx.h"
+
+#include <sys/stat.h>
+
+#ifdef USE_DEV_FB
+extern char *getenv(const char *);
+#include <linux/fb.h>
+char *fb_dev_name;
+#endif
+
+static Bool KeepTty = FALSE;
+static int VTnum = -1;
+static Bool VTSwitch = TRUE;
+static Bool ShareVTs = FALSE;
+static int activeVT = -1;
+
+static int vtPermSave[4];
+static char vtname[11];
+
+static int
+saveVtPerms(void)
+{
+ /* We need to use stat to get permissions. */
+ struct stat svtp;
+
+ /* Do them numerically ordered, hard coded tty0 first. */
+ if (stat("/dev/tty0", &svtp) != 0)
+ return 0;
+ vtPermSave[0] = (int)svtp.st_uid;
+ vtPermSave[1] = (int)svtp.st_gid;
+
+ /* Now check the console we are dealing with. */
+ if (stat(vtname, &svtp) != 0)
+ return 0;
+ vtPermSave[2] = (int)svtp.st_uid;
+ vtPermSave[3] = (int)svtp.st_gid;
+
+ return 1;
+}
+
+static void
+restoreVtPerms(void)
+{
+ /* Set the terminal permissions back to before we started. */
+ chown("/dev/tty0", vtPermSave[0], vtPermSave[1]);
+ chown(vtname, vtPermSave[2], vtPermSave[3]);
+}
+
+void
+xf86OpenConsole(void)
+{
+ int i, fd = -1;
+ struct vt_mode VT;
+ struct vt_stat vts;
+ MessageType from = X_PROBED;
+#ifdef USE_DEV_FB
+ struct fb_var_screeninfo var;
+ int fbfd;
+#endif
+ char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
+ char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
+
+ if (serverGeneration == 1) {
+
+ /* when KeepTty check if we're run with euid==0 */
+ if (KeepTty && geteuid() != 0)
+ FatalError("xf86OpenConsole:"
+ " Server must be suid root for option \"KeepTTY\"\n");
+
+ /*
+ * setup the virtual terminal manager
+ */
+ if (VTnum != -1) {
+ xf86Info.vtno = VTnum;
+ from = X_CMDLINE;
+ } else {
+
+ i=0;
+ while (tty0[i] != NULL) {
+ if ((fd = open(tty0[i],O_WRONLY,0)) >= 0)
+ break;
+ i++;
+ }
+
+ if (fd < 0)
+ FatalError(
+ "xf86OpenConsole: Cannot open /dev/tty0 (%s)\n",
+ strerror(errno));
+
+ if (ShareVTs)
+ {
+ if (ioctl(fd, VT_GETSTATE, &vts) == 0)
+ xf86Info.vtno = vts.v_active;
+ else
+ FatalError("xf86OpenConsole: Cannot find the current"
+ " VT (%s)\n", strerror(errno));
+ } else {
+ if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
+ (xf86Info.vtno == -1))
+ FatalError("xf86OpenConsole: Cannot find a free VT: %s\n",
+ strerror(errno));
+ }
+ close(fd);
+ }
+
+#ifdef USE_DEV_FB
+ if (!ShareVTs)
+ {
+ fb_dev_name=getenv("FRAMEBUFFER");
+ if (!fb_dev_name)
+ fb_dev_name="/dev/fb0current";
+
+ if ((fbfd = open(fb_dev_name, O_RDONLY)) < 0)
+ FatalError("xf86OpenConsole: Cannot open %s (%s)\n",
+ fb_dev_name, strerror(errno));
+
+ if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var) < 0)
+ FatalError("xf86OpenConsole: Unable to get screen info %s\n",
+ strerror(errno));
+ }
+#endif
+ xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno);
+
+ if (!KeepTty) {
+ pid_t ppid = getppid();
+ pid_t ppgid;
+ ppgid = getpgid(ppid);
+
+ /*
+ * change to parent process group that pgid != pid so
+ * that setsid() doesn't fail and we become process
+ * group leader
+ */
+ if (setpgid(0,ppgid) < 0)
+ xf86Msg(X_WARNING, "xf86OpenConsole: setpgid failed: %s\n",
+ strerror(errno));
+
+ /* become process group leader */
+ if ((setsid() < 0))
+ xf86Msg(X_WARNING, "xf86OpenConsole: setsid failed: %s\n",
+ strerror(errno));
+ }
+
+ i=0;
+ while (vcs[i] != NULL) {
+ sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */
+ if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) >= 0)
+ break;
+ i++;
+ }
+
+ if (xf86Info.consoleFd < 0)
+ FatalError("xf86OpenConsole: Cannot open virtual console"
+ " %d (%s)\n", xf86Info.vtno, strerror(errno));
+
+ if (!ShareVTs)
+ {
+ /*
+ * Grab the vt ownership before we overwrite it.
+ * Hard coded /dev/tty0 into this function as well for below.
+ */
+ if (!saveVtPerms())
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: Could not save ownership of VT\n");
+
+ /* change ownership of the vt */
+ if (chown(vtname, getuid(), getgid()) < 0)
+ xf86Msg(X_WARNING,"xf86OpenConsole: chown %s failed: %s\n",
+ vtname, strerror(errno));
+
+ /*
+ * the current VT device we're running on is not "console", we want
+ * to grab all consoles too
+ *
+ * Why is this needed??
+ */
+ if (chown("/dev/tty0", getuid(), getgid()) < 0)
+ xf86Msg(X_WARNING,"xf86OpenConsole: chown /dev/tty0 failed: %s\n",
+ strerror(errno));
+ }
+
+ /*
+ * Linux doesn't switch to an active vt after the last close of a vt,
+ * so we do this ourselves by remembering which is active now.
+ */
+ if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) < 0)
+ xf86Msg(X_WARNING,"xf86OpenConsole: VT_GETSTATE failed: %s\n",
+ strerror(errno));
+ else
+ activeVT = vts.v_active;
+
+#if 0
+ if (!KeepTty) {
+ /*
+ * Detach from the controlling tty to avoid char loss
+ */
+ if ((i = open("/dev/tty",O_RDWR)) >= 0) {
+ ioctl(i, TIOCNOTTY, 0);
+ close(i);
+ }
+ }
+#endif
+
+ if (!ShareVTs)
+ {
+#if defined(DO_OS_FONTRESTORE)
+ lnx_savefont();
+#endif
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed: %s\n",
+ strerror(errno));
+
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed: %s\n",
+ strerror(errno));
+
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
+ FatalError("xf86OpenConsole: VT_GETMODE failed %s\n",
+ strerror(errno));
+
+ signal(SIGUSR1, xf86VTRequest);
+
+ VT.mode = VT_PROCESS;
+ VT.relsig = SIGUSR1;
+ VT.acqsig = SIGUSR1;
+
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
+ FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed: %s\n",
+ strerror(errno));
+
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
+ FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed %s\n",
+ strerror(errno));
+
+ /* we really should have a InitOSInputDevices() function instead
+ * of Init?$#*&Device(). So I just place it here */
+
+#ifdef USE_DEV_FB
+ /* copy info to new console */
+ var.yoffset=0;
+ var.xoffset=0;
+ if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &var))
+ FatalError("Unable to set screen info\n");
+ close(fbfd);
+#endif
+ } else { /* ShareVTs */
+ close(xf86Info.consoleFd);
+ }
+ signal(SIGUSR2, xf86ReloadInputDevs);
+ } else { /* serverGeneration != 1 */
+ if (!ShareVTs && VTSwitch)
+ {
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed %s\n",
+ strerror(errno));
+ }
+
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed %s\n",
+ strerror(errno));
+ }
+ return;
+}
+
+void
+xf86CloseConsole()
+{
+ struct vt_mode VT;
+#if defined(DO_OS_FONTRESTORE)
+ struct vt_stat vts;
+ int vtno = -1;
+#endif
+
+ if (ShareVTs) return;
+
+#if defined(DO_OS_FONTRESTORE)
+ if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) < 0)
+ xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETSTATE failed: %s\n",
+ strerror(errno));
+ else
+ vtno = vts.v_active;
+#endif
+
+ /* Back to text mode ... */
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT) < 0)
+ xf86Msg(X_WARNING, "xf86CloseConsole: KDSETMODE failed: %s\n",
+ strerror(errno));
+
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
+ xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETMODE failed: %s\n",
+ strerror(errno));
+ else {
+ /* set dflt vt handling */
+ VT.mode = VT_AUTO;
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
+ xf86Msg(X_WARNING, "xf86CloseConsole: VT_SETMODE failed: %s\n",
+ strerror(errno));
+ }
+
+ if (VTSwitch)
+ {
+ /*
+ * Perform a switch back to the active VT when we were started
+ */
+ if (activeVT >= 0) {
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT) < 0)
+ xf86Msg(X_WARNING, "xf86CloseConsole: VT_ACTIVATE failed: %s\n",
+ strerror(errno));
+ activeVT = -1;
+ }
+
+#if defined(DO_OS_FONTRESTORE)
+ if (xf86Info.vtno == vtno) /* check if we are active */
+ lnx_restorefont();
+ lnx_freefontdata();
+#endif
+ }
+ close(xf86Info.consoleFd); /* make the vt-manager happy */
+
+ restoreVtPerms(); /* restore the permissions */
+
+ return;
+}
+
+int
+xf86ProcessArgument(int argc, char *argv[], int i)
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful
+ * when debugging (so the server can receive keyboard signals.
+ */
+ if (!strcmp(argv[i], "-keeptty"))
+ {
+ KeepTty = TRUE;
+ return(1);
+ }
+ if (!strcmp(argv[i], "-novtswitch"))
+ {
+ VTSwitch = FALSE;
+ return(1);
+ }
+ if (!strcmp(argv[i], "-sharevts"))
+ {
+ ShareVTs = TRUE;
+ return(1);
+ }
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+ {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ return(1);
+ }
+ return(0);
+}
+
+void
+xf86UseMsg()
+{
+ ErrorF("vtXX use the specified VT number\n");
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ ErrorF("-novtswitch don't immediately switch to new VT\n");
+ ErrorF("-sharevts share VTs with another X server\n");
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c
new file mode 100644
index 000000000..47df0dfb6
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c
@@ -0,0 +1,275 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c,v 3.25 2003/08/19 17:32:34 tsi Exp $ */
+/*
+ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Orest Zborowski and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Orest Zborowski
+ * and David Dawes make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * OREST ZBOROWSKI AND DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID DAWES BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: lnx_io.c /main/8 1996/10/19 18:06:28 kaleb $ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#define KBC_TIMEOUT 250 /* Timeout in ms for sending to keyboard controller */
+
+void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ if (loudness && pitch)
+ {
+ ioctl(xf86Info.consoleFd, KDMKTONE,
+ ((1193190 / pitch) & 0xffff) |
+ (((unsigned long)duration *
+ loudness / 50) << 16));
+ }
+}
+
+void
+xf86SetKbdLeds(int leds)
+{
+ ioctl(xf86Info.consoleFd, KDSETLED, leds);
+}
+
+int
+xf86GetKbdLeds()
+{
+ int leds = 0;
+
+ ioctl(xf86Info.consoleFd, KDGETLED, &leds);
+ return(leds);
+}
+
+/* kbd rate stuff based on kbdrate.c from Rik Faith <faith@cs.unc.edu> et.al.
+ * from util-linux-2.9t package */
+
+#include <linux/kd.h>
+#include <linux/version.h>
+#ifdef __sparc__
+#include <asm/param.h>
+#include <asm/kbio.h>
+#endif
+
+/* Deal with spurious kernel header change in struct kbd_repeat.
+ We undo this define after the routine using that struct is over,
+ so as not to interfere with other 'rate' elements. */
+#if defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION)
+# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,42)
+# define rate period
+# endif
+#endif
+
+static int
+KDKBDREP_ioctl_ok(int rate, int delay) {
+#if defined(KDKBDREP) && !defined(__sparc__)
+ /* This ioctl is defined in <linux/kd.h> but is not
+ implemented anywhere - must be in some m68k patches. */
+ struct kbd_repeat kbdrep_s;
+
+ /* don't change, just test */
+ kbdrep_s.rate = -1;
+ kbdrep_s.delay = -1;
+ if (ioctl( xf86Info.consoleFd, KDKBDREP, &kbdrep_s )) {
+ return 0;
+ }
+ /* do the change */
+ if (rate == 0) /* switch repeat off */
+ kbdrep_s.rate = 0;
+ else
+ kbdrep_s.rate = 10000 / rate; /* convert cps to msec */
+ if (kbdrep_s.rate < 1)
+ kbdrep_s.rate = 1;
+ kbdrep_s.delay = delay;
+ if (kbdrep_s.delay < 1)
+ kbdrep_s.delay = 1;
+
+ if (ioctl( xf86Info.consoleFd, KDKBDREP, &kbdrep_s )) {
+ return 0;
+ }
+
+ return 1; /* success! */
+#else /* no KDKBDREP */
+ return 0;
+#endif /* KDKBDREP */
+}
+
+#undef rate
+
+/* Undo the earlier define for the struct kbd_repeat problem. */
+#if defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION)
+# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,42)
+# undef rate
+# endif
+#endif
+
+static int
+KIOCSRATE_ioctl_ok(int rate, int delay) {
+#ifdef KIOCSRATE
+ struct kbd_rate kbdrate_s;
+ int fd;
+
+ fd = open("/dev/kbd", O_RDONLY);
+ if (fd == -1)
+ return 0;
+
+ kbdrate_s.rate = (rate + 5) / 10; /* must be integer, so round up */
+ kbdrate_s.delay = delay * HZ / 1000; /* convert ms to Hz */
+ if (kbdrate_s.rate > 50)
+ kbdrate_s.rate = 50;
+
+ if (ioctl( fd, KIOCSRATE, &kbdrate_s )) {
+ return 0;
+ }
+
+ close( fd );
+
+ return 1;
+#else /* no KIOCSRATE */
+ return 0;
+#endif /* KIOCSRATE */
+}
+
+void xf86SetKbdRepeat(char rad)
+{
+#ifdef __sparc__
+ int rate = 500; /* Default rate */
+ int delay = 200; /* Default delay */
+#else
+ int rate = 300; /* Default rate */
+ int delay = 250; /* Default delay */
+#endif
+
+#if defined(__alpha__) || defined (__i386__) || defined(__ia64__)
+ int i;
+ int timeout;
+ int value = 0x7f; /* Maximum delay with slowest rate */
+
+ static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150,
+ 133, 120, 109, 100, 92, 86, 80, 75, 67,
+ 60, 55, 50, 46, 43, 40, 37, 33, 30, 27,
+ 25, 23, 21, 20 };
+#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int ))
+
+ static int valid_delays[] = { 250, 500, 750, 1000 };
+#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int ))
+#endif
+
+ if (xf86Info.kbdRate >= 0)
+ rate = xf86Info.kbdRate * 10;
+ if (xf86Info.kbdDelay >= 0)
+ delay = xf86Info.kbdDelay;
+
+ if(KDKBDREP_ioctl_ok(rate, delay)) /* m68k? */
+ return;
+
+ if(KIOCSRATE_ioctl_ok(rate, delay)) /* sparc? */
+ return;
+
+ if (xf86IsPc98())
+ return;
+
+#if defined(__alpha__) || defined (__i386__) || defined(__ia64__)
+
+ /* The ioport way */
+
+ for (i = 0; i < RATE_COUNT; i++)
+ if (rate >= valid_rates[i]) {
+ value &= 0x60;
+ value |= i;
+ break;
+ }
+
+ for (i = 0; i < DELAY_COUNT; i++)
+ if (delay <= valid_delays[i]) {
+ value &= 0x1f;
+ value |= i << 5;
+ break;
+ }
+
+ timeout = KBC_TIMEOUT;
+ while (((inb(0x64) & 2) == 2) && --timeout)
+ usleep(1000); /* wait */
+
+ if (timeout == 0)
+ return;
+
+ outb(0x60, 0xf3); /* set typematic rate */
+ while (((inb(0x64) & 2) == 2) && --timeout)
+ usleep(1000); /* wait */
+
+ usleep(10000);
+ outb(0x60, value);
+
+#endif /* __alpha__ || __i386__ || __ia64__ */
+}
+
+static int kbdtrans;
+static struct termios kbdtty;
+
+void
+xf86KbdInit()
+{
+ ioctl (xf86Info.consoleFd, KDGKBMODE, &kbdtrans);
+ tcgetattr (xf86Info.consoleFd, &kbdtty);
+}
+
+int
+xf86KbdOn()
+{
+ struct termios nTty;
+
+#ifdef __powerpc__
+ if (xf86Info.kbdCustomKeycodes)
+ ioctl(xf86Info.consoleFd, KDSKBMODE, K_MEDIUMRAW);
+ else
+#endif
+ ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW);
+
+ nTty = kbdtty;
+ nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME]=0;
+ nTty.c_cc[VMIN]=1;
+ cfsetispeed(&nTty, 9600);
+ cfsetospeed(&nTty, 9600);
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty);
+ return(xf86Info.consoleFd);
+}
+
+int
+xf86KbdOff()
+{
+ ioctl(xf86Info.consoleFd, KDSKBMODE, kbdtrans);
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &kbdtty);
+ return(xf86Info.consoleFd);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c
new file mode 100644
index 000000000..dafdc0594
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c
@@ -0,0 +1,188 @@
+/* $XConsortium: lnx_jstk.c /main/7 1996/02/21 17:51:36 kaleb $ */
+/* Id: lnx_jstk.c,v 1.1 1995/12/20 14:06:09 lepied Exp */
+/*
+ * Copyright 1995 by Frederic Lepied, France. <fred@sugix.frmug.fr.net>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Frederic Lepied not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Frederic Lepied makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c,v 3.8.2.1 1998/06/05 16:23:12 dawes Exp $ */
+
+static const char rcs_id[] = "Id: lnx_jstk.c,v 1.1 1995/12/20 14:06:09 lepied Exp";
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#define inline __inline__
+#include <linux/joystick.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#ifdef XFree86LOADER
+#include "xf86.h"
+#include "xf86_ansic.h"
+#endif
+
+#if !defined(JSIOCGTIMELIMIT)
+/* make 2.1.x joystick.h backward compatable */
+#define JSIOCGTIMELIMIT JS_GET_TIMELIMIT
+#define JSIOCSTIMELIMIT JS_SET_TIMELIMIT
+#define js_status JS_DATA_TYPE
+#endif
+
+
+/***********************************************************************
+ *
+ * xf86JoystickOn --
+ *
+ * open the device and init timeout according to the device value.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickOn(char *name, int *timeout, int *centerX, int *centerY)
+{
+ int fd;
+ struct js_status js;
+
+#ifdef DEBUG
+ ErrorF("xf86JoystickOn %s\n", name);
+#endif
+
+ if ((fd = open(name, O_RDWR | O_NDELAY, 0)) < 0)
+ {
+ xf86Msg(X_WARNING, "Cannot open joystick '%s' (%s)\n", name,
+ strerror(errno));
+ return -1;
+ }
+
+ if (*timeout == 0) {
+ if (ioctl (fd, JSIOCGTIMELIMIT, timeout) == -1) {
+ Error("joystick JSIOCGTIMELIMIT ioctl");
+ }
+ else {
+ xf86Msg(X_CONFIG, "Joystick: timeout value = %d\n", *timeout);
+ }
+ }
+ else {
+ if (ioctl(fd, JSIOCSTIMELIMIT, timeout) == -1) {
+ Error("joystick JSIOCSTIMELIMIT ioctl");
+ }
+ }
+
+ /* Assume the joystick is centred when this is called */
+ read(fd, &js, JS_RETURN);
+ if (*centerX < 0) {
+ *centerX = js.x;
+ xf86Msg(X_CONFIG, "Joystick: CenterX set to %d\n", *centerX);
+ }
+ if (*centerY < 0) {
+ *centerY = js.y;
+ xf86Msg(X_CONFIG, "Joystick: CenterY set to %d\n", *centerY);
+ }
+
+ return fd;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickInit --
+ *
+ * called when X device is initialized.
+ *
+ ***********************************************************************
+ */
+
+void
+xf86JoystickInit()
+{
+ return;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickOff --
+ *
+ * close the handle.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickOff(int *fd, int doclose)
+{
+ int oldfd;
+
+ if (((oldfd = *fd) >= 0) && doclose) {
+ close(*fd);
+ *fd = -1;
+ }
+ return oldfd;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickGetState --
+ *
+ * return the state of buttons and the position of the joystick.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickGetState(int fd, int *x, int *y, int *buttons)
+{
+ struct js_status js;
+ int status;
+
+ status = read(fd, &js, JS_RETURN);
+
+ if (status != JS_RETURN)
+ {
+ Error("Joystick read");
+ return 0;
+ }
+
+ *x = js.x;
+ *y = js.y;
+ *buttons = js.buttons;
+
+ return 1;
+}
+
+#ifdef XFree86LOADER
+/*
+ * Entry point for XFree86 Loader
+ */
+void
+linux_jstkModuleInit(pointer *data, INT32 *magic)
+{
+ *magic = MAGIC_DONE;
+ *data = NULL;
+}
+#endif
+
+/* end of lnx_jstk.c */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c
new file mode 100644
index 000000000..b1fc95b56
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c
@@ -0,0 +1,559 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c,v 1.4 2003/11/03 05:11:52 tsi Exp $ */
+
+/*
+ * Copyright (c) 2002 by The XFree86 Project, Inc.
+ * Author: Ivan Pascal.
+ *
+ * Based on the code from lnx_io.c which is
+ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+#include "atKeynames.h"
+#if defined(DO_OS_FONTRESTORE)
+#include "lnx.h"
+#endif
+#include "lnx_kbd.h"
+
+#define KBC_TIMEOUT 250 /* Timeout in ms for sending to keyboard controller */
+
+static KbdProtocolRec protocols[] = {
+ {"standard", PROT_STD },
+ { NULL, PROT_UNKNOWN_KBD }
+};
+
+extern Bool VTSwitchEnabled;
+#ifdef USE_VT_SYSREQ
+extern Bool VTSysreqToggle;
+#endif
+
+static void
+SoundBell(InputInfoPtr pInfo, int loudness, int pitch, int duration)
+{
+ if (loudness && pitch)
+ {
+ ioctl(pInfo->fd, KDMKTONE,
+ ((1193190 / pitch) & 0xffff) |
+ (((unsigned long)duration *
+ loudness / 50) << 16));
+ }
+}
+
+static void
+SetKbdLeds(InputInfoPtr pInfo, int leds)
+{
+ int real_leds = 0;
+
+#if defined (__sparc__)
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ if (pKbd->sunKbd) {
+ if (leds & 0x08) real_leds |= XLED1;
+ if (leds & 0x04) real_leds |= XLED3;
+ if (leds & 0x02) real_leds |= XLED4;
+ if (leds & 0x01) real_leds |= XLED2;
+ leds = real_leds;
+ real_leds = 0;
+ }
+#endif /* defined (__sparc__) */
+#ifdef LED_CAP
+ if (leds & XLED1) real_leds |= LED_CAP;
+ if (leds & XLED2) real_leds |= LED_NUM;
+ if (leds & XLED3) real_leds |= LED_SCR;
+#ifdef LED_COMP
+ if (leds & XLED4) real_leds |= LED_COMP;
+#else
+ if (leds & XLED4) real_leds |= LED_SCR;
+#endif
+#endif
+ ioctl(pInfo->fd, KDSETLED, real_leds);
+}
+
+static int
+GetKbdLeds(InputInfoPtr pInfo)
+{
+ int real_leds, leds = 0;
+
+ ioctl(pInfo->fd, KDGETLED, &real_leds);
+
+ if (real_leds & LED_CAP) leds |= XLED1;
+ if (real_leds & LED_NUM) leds |= XLED2;
+ if (real_leds & LED_SCR) leds |= XLED3;
+
+ return(leds);
+}
+
+/* kbd rate stuff based on kbdrate.c from Rik Faith <faith@cs.unc.edu> et.al.
+ * from util-linux-2.9t package */
+
+#include <linux/kd.h>
+#include <linux/version.h>
+#ifdef __sparc__
+#include <asm/param.h>
+#include <asm/kbio.h>
+#endif
+
+/* Deal with spurious kernel header change in struct kbd_repeat.
+ We undo this define after the routine using that struct is over,
+ so as not to interfere with other 'rate' elements. */
+#if defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION)
+# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,42)
+# define rate period
+# endif
+#endif
+
+static int
+KDKBDREP_ioctl_ok(int rate, int delay) {
+#if defined(KDKBDREP) && !defined(__sparc__)
+ /* This ioctl is defined in <linux/kd.h> but is not
+ implemented anywhere - must be in some m68k patches. */
+ struct kbd_repeat kbdrep_s;
+
+ /* don't change, just test */
+ kbdrep_s.rate = -1;
+ kbdrep_s.delay = -1;
+ if (ioctl( xf86Info.consoleFd, KDKBDREP, &kbdrep_s )) {
+ return 0;
+ }
+
+ /* do the change */
+ if (rate == 0) /* switch repeat off */
+ kbdrep_s.rate = 0;
+ else
+ kbdrep_s.rate = 10000 / rate; /* convert cps to msec */
+ if (kbdrep_s.rate < 1)
+ kbdrep_s.rate = 1;
+ kbdrep_s.delay = delay;
+ if (kbdrep_s.delay < 1)
+ kbdrep_s.delay = 1;
+
+ if (ioctl( xf86Info.consoleFd, KDKBDREP, &kbdrep_s )) {
+ return 0;
+ }
+
+ return 1; /* success! */
+#else /* no KDKBDREP */
+ return 0;
+#endif /* KDKBDREP */
+}
+
+#undef rate
+
+/* Undo the earlier define for the struct kbd_repeat problem. */
+#if defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION)
+# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,42)
+# undef rate
+# endif
+#endif
+
+static int
+KIOCSRATE_ioctl_ok(int rate, int delay) {
+#ifdef KIOCSRATE
+ struct kbd_rate kbdrate_s;
+ int fd;
+
+ fd = open("/dev/kbd", O_RDONLY);
+ if (fd == -1)
+ return 0;
+
+ kbdrate_s.rate = (rate + 5) / 10; /* must be integer, so round up */
+ kbdrate_s.delay = delay * HZ / 1000; /* convert ms to Hz */
+ if (kbdrate_s.rate > 50)
+ kbdrate_s.rate = 50;
+
+ if (ioctl( fd, KIOCSRATE, &kbdrate_s )) {
+ return 0;
+ }
+
+ close( fd );
+
+ return 1;
+#else /* no KIOCSRATE */
+ return 0;
+#endif /* KIOCSRATE */
+}
+
+#undef rate
+
+static void
+SetKbdRepeat(InputInfoPtr pInfo, char rad)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int i;
+ int timeout;
+ int value = 0x7f; /* Maximum delay with slowest rate */
+
+#ifdef __sparc__
+ int rate = 500; /* Default rate */
+ int delay = 200; /* Default delay */
+#else
+ int rate = 300; /* Default rate */
+ int delay = 250; /* Default delay */
+#endif
+
+ static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150,
+ 133, 120, 109, 100, 92, 86, 80, 75, 67,
+ 60, 55, 50, 46, 43, 40, 37, 33, 30, 27,
+ 25, 23, 21, 20 };
+#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int ))
+
+ static int valid_delays[] = { 250, 500, 750, 1000 };
+#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int ))
+
+ if (pKbd->rate >= 0)
+ rate = pKbd->rate * 10;
+ if (pKbd->delay >= 0)
+ delay = pKbd->delay;
+
+ if(KDKBDREP_ioctl_ok(rate, delay)) /* m68k? */
+ return;
+
+ if(KIOCSRATE_ioctl_ok(rate, delay)) /* sparc? */
+ return;
+
+ if (xf86IsPc98())
+ return;
+
+#if defined(__alpha__) || defined (__i386__) || defined(__ia64__)
+
+ if (!xorgHWAccess) {
+ if (xf86EnableIO())
+ xorgHWAccess = TRUE;
+ else
+ return;
+ }
+
+ /* The ioport way */
+
+ for (i = 0; i < RATE_COUNT; i++)
+ if (rate >= valid_rates[i]) {
+ value &= 0x60;
+ value |= i;
+ break;
+ }
+
+ for (i = 0; i < DELAY_COUNT; i++)
+ if (delay <= valid_delays[i]) {
+ value &= 0x1f;
+ value |= i << 5;
+ break;
+ }
+
+ timeout = KBC_TIMEOUT;
+ while (((inb(0x64) & 2) == 2) && --timeout)
+ usleep(1000); /* wait */
+
+ if (timeout == 0)
+ return;
+
+ outb(0x60, 0xf3); /* set typematic rate */
+ while (((inb(0x64) & 2) == 2) && --timeout)
+ usleep(1000); /* wait */
+
+ usleep(10000);
+ outb(0x60, value);
+
+#endif /* __alpha__ || __i386__ || __ia64__ */
+}
+
+typedef struct {
+ int kbdtrans;
+ struct termios kbdtty;
+} LnxKbdPrivRec, *LnxKbdPrivPtr;
+
+static int
+KbdInit(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ LnxKbdPrivPtr priv = (LnxKbdPrivPtr) pKbd->private;
+
+ if (pKbd->isConsole) {
+ ioctl (pInfo->fd, KDGKBMODE, &(priv->kbdtrans));
+ tcgetattr (pInfo->fd, &(priv->kbdtty));
+ }
+ if (!pKbd->CustomKeycodes) {
+ pKbd->RemapScanCode = ATScancode;
+ }
+
+ return Success;
+}
+
+static int
+KbdOn(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ LnxKbdPrivPtr priv = (LnxKbdPrivPtr) pKbd->private;
+ struct termios nTty;
+
+ if (pKbd->isConsole) {
+ if (pKbd->CustomKeycodes)
+ ioctl(pInfo->fd, KDSKBMODE, K_MEDIUMRAW);
+ else
+ ioctl(pInfo->fd, KDSKBMODE, K_RAW);
+
+ nTty = priv->kbdtty;
+ nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME]=0;
+ nTty.c_cc[VMIN]=1;
+ cfsetispeed(&nTty, 9600);
+ cfsetospeed(&nTty, 9600);
+ tcsetattr(pInfo->fd, TCSANOW, &nTty);
+ }
+ return Success;
+}
+
+static int
+KbdOff(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ LnxKbdPrivPtr priv = (LnxKbdPrivPtr) pKbd->private;
+
+ if (pKbd->isConsole) {
+ ioctl(pInfo->fd, KDSKBMODE, priv->kbdtrans);
+ tcsetattr(pInfo->fd, TCSANOW, &(priv->kbdtty));
+ }
+ return Success;
+}
+
+static int
+GetSpecialKey(InputInfoPtr pInfo, int scanCode)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int specialkey = scanCode;
+
+#if defined (__sparc__)
+ if (pKbd->sunKbd) {
+ switch (scanCode) {
+ case 0x2b: specialkey = KEY_BackSpace; break;
+ case 0x47: specialkey = KEY_KP_Minus; break;
+ case 0x7d: specialkey = KEY_KP_Plus; break;
+ /* XXX needs cases for KEY_KP_Divide and KEY_KP_Multiply */
+ case 0x05: specialkey = KEY_F1; break;
+ case 0x06: specialkey = KEY_F2; break;
+ case 0x08: specialkey = KEY_F3; break;
+ case 0x0a: specialkey = KEY_F4; break;
+ case 0x0c: specialkey = KEY_F5; break;
+ case 0x0e: specialkey = KEY_F6; break;
+ case 0x10: specialkey = KEY_F7; break;
+ case 0x11: specialkey = KEY_F8; break;
+ case 0x12: specialkey = KEY_F9; break;
+ case 0x07: specialkey = KEY_F10; break;
+ case 0x09: specialkey = KEY_F11; break;
+ case 0x0b: specialkey = KEY_F12; break;
+ default: specialkey = 0; break;
+ }
+ return specialkey;
+ }
+#endif
+
+ if (pKbd->CustomKeycodes) {
+ specialkey = pKbd->specialMap->map[scanCode];
+ }
+ return specialkey;
+}
+
+#define ModifierSet(k) ((modifiers & (k)) == (k))
+
+static
+Bool SpecialKey(InputInfoPtr pInfo, int key, Bool down, int modifiers)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+
+ if(!pKbd->vtSwitchSupported)
+ return FALSE;
+
+ if ((ModifierSet(ControlMask | AltMask)) ||
+ (ModifierSet(ControlMask | AltLangMask))) {
+ if (VTSwitchEnabled && !xf86Info.vtSysreq && !xf86Info.dontVTSwitch) {
+ switch (key) {
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ if (down) {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F1 + 1);
+ return TRUE;
+ }
+ case KEY_F11:
+ case KEY_F12:
+ if (down) {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F11 + 11);
+ return TRUE;
+ }
+ }
+ }
+ }
+#ifdef USE_VT_SYSREQ
+ if (VTSwitchEnabled && xf86Info.vtSysreq && !xf86Info.dontVTSwitch) {
+ switch (key) {
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ if (VTSysreqToggle && down) {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F1 + 1);
+ VTSysreqToggle = FALSE;
+ return TRUE;
+ }
+ break;
+ case KEY_F11:
+ case KEY_F12:
+ if (VTSysreqToggle && down) {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F11 + 11);
+ VTSysreqToggle = FALSE;
+ return TRUE;
+ }
+ break;
+ /* Ignore these keys -- ie don't let them cancel an alt-sysreq */
+ case KEY_Alt:
+ case KEY_AltLang:
+ break;
+ case KEY_SysReqest:
+ if ((ModifierSet(AltMask) || ModifierSet(AltLangMask)) && down)
+ VTSysreqToggle = TRUE;
+ break;
+ default:
+ /*
+ * We only land here when Alt-SysReq is followed by a
+ * non-switching key.
+ */
+ if (VTSysreqToggle)
+ VTSysreqToggle = FALSE;
+ }
+ }
+#endif /* USE_VT_SYSREQ */
+ return FALSE;
+}
+
+static void
+stdReadInput(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ unsigned char rBuf[64];
+ int nBytes, i;
+ if ((nBytes = read( pInfo->fd, (char *)rBuf, sizeof(rBuf))) > 0) {
+ for (i = 0; i < nBytes; i++)
+ pKbd->PostEvent(pInfo, rBuf[i] & 0x7f,
+ rBuf[i] & 0x80 ? FALSE : TRUE);
+ }
+}
+
+static Bool
+OpenKeyboard(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int i;
+ KbdProtocolId prot = PROT_UNKNOWN_KBD;
+ char *s;
+
+ s = xf86SetStrOption(pInfo->options, "Protocol", NULL);
+ for (i = 0; protocols[i].name; i++) {
+ if (xf86NameCmp(s, protocols[i].name) == 0) {
+ prot = protocols[i].id;
+ break;
+ }
+ }
+
+ switch (prot) {
+ case PROT_STD:
+ pInfo->read_input = stdReadInput;
+ break;
+ default:
+ xf86Msg(X_ERROR,"\"%s\" is not a valid keyboard protocol name\n", s);
+ xfree(s);
+ return FALSE;
+ }
+
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, s);
+ xfree(s);
+
+ s = xf86SetStrOption(pInfo->options, "Device", NULL);
+ if (s == NULL) {
+ pInfo->fd = xf86Info.consoleFd;
+ pKbd->isConsole = TRUE;
+ } else {
+ pInfo->fd = open(s, O_RDONLY | O_NONBLOCK | O_EXCL);
+ if (pInfo->fd == -1) {
+ xf86Msg(X_ERROR, "%s: cannot open \"%s\"\n", pInfo->name, s);
+ xfree(s);
+ return FALSE;
+ }
+ pKbd->isConsole = FALSE;
+ xfree(s);
+ }
+
+ if (pKbd->isConsole)
+ pKbd->vtSwitchSupported = TRUE;
+
+ return TRUE;
+}
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = pInfo->private;
+
+ pKbd->KbdInit = KbdInit;
+ pKbd->KbdOn = KbdOn;
+ pKbd->KbdOff = KbdOff;
+ pKbd->Bell = SoundBell;
+ pKbd->SetLeds = SetKbdLeds;
+ pKbd->GetLeds = GetKbdLeds;
+ pKbd->SetKbdRepeat = SetKbdRepeat;
+ pKbd->KbdGetMapping = KbdGetMapping;
+ pKbd->SpecialKey = SpecialKey;
+
+ pKbd->RemapScanCode = NULL;
+ pKbd->GetSpecialKey = GetSpecialKey;
+
+ pKbd->OpenKeyboard = OpenKeyboard;
+ pKbd->vtSwitchSupported = FALSE;
+
+ pKbd->private = xcalloc(sizeof(LnxKbdPrivRec), 1);
+ if (pKbd->private == NULL) {
+ xf86Msg(X_ERROR,"can't allocate keyboard OS private data\n");
+ return FALSE;
+ }
+
+#if defined(__powerpc__)
+ {
+ FILE *f;
+ f = fopen("/proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes","r");
+ if (f) {
+ if (fgetc(f) == '0')
+ pKbd->CustomKeycodes = TRUE;
+ fclose(f);
+ }
+ }
+#endif
+ return TRUE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.h
new file mode 100644
index 000000000..7b9cd434e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.h
@@ -0,0 +1,5 @@
+/* $XFree86$ */
+
+extern void KbdGetMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms,
+ CARD8 *pModMap);
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c
new file mode 100644
index 000000000..c211d115a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c
@@ -0,0 +1,113 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c,v 3.5 2001/10/01 13:44:14 eich Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include "xf86_OSlib.h"
+#include "xf86.h"
+
+
+#define MODPROBE_PATH_FILE "/proc/sys/kernel/modprobe"
+#define MAX_PATH 1024
+
+
+#if 0
+/* XFree86 #defines execl to be the xf86execl() function which does
+ * a fork AND exec. We don't want that. We want the regular,
+ * standard execl().
+ */
+#ifdef execl
+#undef execl
+#endif
+#endif
+
+
+/*
+ * Load a Linux kernel module.
+ * This is used by the DRI/DRM to load a DRM kernel module when
+ * the X server starts. It could be used for other purposes in the future.
+ * Input:
+ * modName - name of the kernel module (Ex: "tdfx")
+ * Return:
+ * 0 for failure, 1 for success
+ */
+int
+xf86LoadKernelModule(const char *modName)
+{
+ char mpPath[MAX_PATH] = "";
+ int fd = -1, status, n;
+ pid_t pid;
+
+ /* get the path to the modprobe program */
+ fd = open(MODPROBE_PATH_FILE, O_RDONLY);
+ if (fd >= 0) {
+ int count = read(fd, mpPath, MAX_PATH - 1);
+ if (count <= 0) {
+ mpPath[0] = 0;
+ }
+ else if (mpPath[count - 1] == '\n') {
+ mpPath[count - 1] = 0; /* replaces \n with \0 */
+ }
+ close(fd);
+ /* if this worked, mpPath will be "/sbin/modprobe" or similar. */
+ }
+
+ if (mpPath[0] == 0) {
+ /* we failed to get the path from the system, use a default */
+ strcpy(mpPath, "/sbin/modprobe");
+ }
+
+ /* now fork/exec the modprobe command */
+ /*
+ * It would be good to capture stdout/stderr so that it can be directed
+ * to the log file. modprobe errors currently are missing from the log
+ * file.
+ */
+ switch (pid = fork()) {
+ case 0: /* child */
+ /* change real/effective user ID to 0/0 as we need to
+ * preinstall agpgart module for some DRM modules
+ */
+ if (setreuid(0,0)) {
+ xf86Msg(X_WARNING,"LoadKernelModule: "
+ "Setting of real/effective user Id to 0/0 failed");
+ }
+ setenv("PATH","/sbin",1);
+ n = execl(mpPath, "modprobe", modName, NULL);
+ xf86Msg(X_WARNING,"LoadKernelModule %s\n",strerror(errno));
+ exit(EXIT_FAILURE); /* if we get here the child's exec failed */
+ break;
+ case -1: /* fork failed */
+ return 0;
+ default: /* fork worked */
+ {
+ /* XXX we loop over waitpid() because it sometimes fails on
+ * the first attempt. Don't know why!
+ */
+ int count = 0, p;
+ do {
+ p = waitpid(pid, &status, 0);
+ } while (p == -1 && count++ < 4);
+
+ if (p == -1) {
+ return 0;
+ }
+
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+ return 1; /* success! */
+ }
+ else {
+ return 0;
+ }
+ }
+ }
+
+ /* never get here */
+ return 0;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c
new file mode 100644
index 000000000..d73c69853
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c
@@ -0,0 +1,206 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c,v 1.2 2003/10/08 14:58:30 dawes Exp $ */
+
+/*
+ * Copyright 1999 by The XFree86 Project, Inc.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "xf86_OSlib.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static int
+SupportedInterfaces(void)
+{
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO;
+}
+
+static const char *
+DefaultProtocol(void)
+{
+ return "Auto";
+}
+
+#define DEFAULT_MOUSE_DEV "/dev/mouse"
+#define DEFAULT_PS2_DEV "/dev/psaux"
+#define DEFAULT_GPM_DATA_DEV "/dev/gpmdata"
+#define DEFAULT_GPM_CTL_DEV "/dev/gpmdata"
+
+static const char *mouseDevs[] = {
+ DEFAULT_MOUSE_DEV,
+ DEFAULT_PS2_DEV,
+ DEFAULT_GPM_DATA_DEV,
+ NULL
+};
+
+typedef enum {
+ MOUSE_PROTO_UNKNOWN = 0,
+ MOUSE_PROTO_SERIAL,
+ MOUSE_PROTO_PS2,
+ MOUSE_PROTO_MSC,
+ MOUSE_PROTO_GPM
+} protocolTypes;
+
+static struct {
+ protocolTypes proto;
+ const char *name;
+} devproto[] = {
+ { MOUSE_PROTO_UNKNOWN, NULL },
+ { MOUSE_PROTO_PS2, "PS/2" },
+ { MOUSE_PROTO_MSC, "MouseSystems" },
+ { MOUSE_PROTO_GPM, "GPM" }
+};
+
+static const char *
+FindDevice(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ int fd = -1;
+ const char **pdev;
+
+ for (pdev = mouseDevs; *pdev; pdev++) {
+ SYSCALL (fd = open(*pdev, O_RDWR | O_NONBLOCK | O_EXCL));
+ if (fd == -1) {
+#ifdef DEBUG
+ ErrorF("Cannot open %s (%s)\n", *pdev, strerror(errno));
+#endif
+ } else
+ break;
+ }
+
+ if (*pdev) {
+ close(fd);
+ /* Set the Device option. */
+ pInfo->conf_idev->commonOptions =
+ xf86AddNewOption(pInfo->conf_idev->commonOptions, "Device", *pdev);
+ xf86Msg(X_INFO, "%s: Setting Device option to \"%s\"\n",
+ pInfo->name, *pdev);
+ }
+
+ return *pdev;
+}
+
+static const char *
+GuessProtocol(InputInfoPtr pInfo, int flags)
+{
+ int fd = -1;
+ const char *dev;
+ char *realdev;
+ struct stat sbuf;
+ int i;
+ int proto = MOUSE_PROTO_UNKNOWN;
+
+ dev = xf86SetStrOption(pInfo->conf_idev->commonOptions, "Device", NULL);
+ if (!dev) {
+#ifdef DEBUG
+ ErrorF("xf86SetStrOption failed to return the device name\n");
+#endif
+ return NULL;
+ }
+ /* Look at the device name to guess the protocol. */
+ realdev = NULL;
+ if (strcmp(dev, DEFAULT_MOUSE_DEV) == 0) {
+ if (lstat(dev, &sbuf) != 0) {
+#ifdef DEBUG
+ ErrorF("lstat failed for %s (%s)\n", dev, strerror(errno));
+#endif
+ return NULL;
+ }
+ if (S_ISLNK(sbuf.st_mode)) {
+ realdev = xnfalloc(PATH_MAX + 1);
+ i = readlink(dev, realdev, PATH_MAX);
+ if (i <= 0) {
+#ifdef DEBUG
+ ErrorF("readlink failed for %s (%s)\n", dev, strerror(errno));
+#endif
+ xfree(realdev);
+ return NULL;
+ }
+ realdev[i] = '\0';
+ }
+ }
+ if (!realdev)
+ realdev = xnfstrdup(dev);
+ else {
+ /* If realdev doesn't contain a '/' then prepend "/dev/" */
+ if (!strchr(realdev, '/')) {
+ char *tmp = xnfalloc(strlen(realdev) + 5 + 1);
+ sprintf(tmp, "/dev/%s", realdev);
+ xfree(realdev);
+ realdev = tmp;
+ }
+ }
+
+ if (strcmp(realdev, DEFAULT_PS2_DEV) == 0)
+ proto = MOUSE_PROTO_PS2;
+ else if (strcmp(realdev, DEFAULT_GPM_DATA_DEV) == 0)
+ proto = MOUSE_PROTO_MSC;
+ else if (strcmp(realdev, DEFAULT_GPM_CTL_DEV) == 0)
+ proto = MOUSE_PROTO_GPM;
+ xfree(realdev);
+ /*
+ * If the protocol can't be guessed from the device name,
+ * try to characterise it.
+ */
+ if (proto == MOUSE_PROTO_UNKNOWN) {
+ SYSCALL (fd = open(dev, O_RDWR | O_NONBLOCK | O_EXCL));
+ if (isatty(fd)) {
+ /* Serial PnP has already failed, so give up. */
+ } else {
+ if (fstat(fd, &sbuf) != 0) {
+#ifdef DEBUG
+ ErrorF("fstat failed for %s (%s)\n", dev, strerror(errno));
+#endif
+ close(fd);
+ return NULL;
+ }
+ if (S_ISFIFO(sbuf.st_mode)) {
+ /* Assume GPM data in MSC format. */
+ proto = MOUSE_PROTO_MSC;
+ } else {
+ /* Default to PS/2 */
+ proto = MOUSE_PROTO_PS2;
+ }
+ }
+ close(fd);
+ }
+ if (proto == MOUSE_PROTO_UNKNOWN) {
+ xf86Msg(X_ERROR, "%s: GuessProtocol: Cannot find mouse protocol.\n",
+ pInfo->name);
+ return NULL;
+ } else {
+ for (i = 0; i < sizeof(devproto)/sizeof(devproto[0]); i++) {
+ if (devproto[i].proto == proto) {
+ xf86Msg(X_INFO,
+ "%s: GuessProtocol: "
+ "setting mouse protocol to \"%s\"\n",
+ pInfo->name, devproto[i].name);
+ return devproto[i].name;
+ }
+ }
+ }
+ return NULL;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+ p->DefaultProtocol = DefaultProtocol;
+ p->FindDevice = FindDevice;
+ p->GuessProtocol = GuessProtocol;
+ return p;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c
new file mode 100644
index 000000000..cec9226c8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c
@@ -0,0 +1,230 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c,v 3.8 2002/04/09 15:59:37 tsi Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSproc.h"
+#include "xf86Pci.h"
+
+#ifdef __sparc__
+#define PCIADDR_TYPE long long
+#define PCIADDR_IGNORE_FMT "%*x"
+#define PCIADDR_FMT "%llx"
+#else
+#define PCIADDR_TYPE long
+#define PCIADDR_IGNORE_FMT "%*x"
+#define PCIADDR_FMT "%lx"
+#endif
+
+FILE *xf86OSLinuxPCIFile = NULL;
+
+Bool
+xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits)
+{
+ char c[0x200];
+ char *res;
+ unsigned int bus, devfn, dev, fn;
+ unsigned PCIADDR_TYPE size[7];
+ unsigned int num;
+ signed PCIADDR_TYPE Size;
+
+ if (index > 7)
+ return FALSE;
+
+ if (!xf86OSLinuxPCIFile && \
+ !(xf86OSLinuxPCIFile = fopen("/proc/bus/pci/devices","r")))
+ return FALSE;
+ do {
+ res = fgets(c,0x1ff,xf86OSLinuxPCIFile);
+ if (res) {
+ num = sscanf(res,
+ /*bus+dev vendorid deviceid irq */
+ "%02x%02x\t%*04x%*04x\t%*x"
+ /* 7 PCI resource base addresses */
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ /* 7 PCI resource sizes, and then optionally a driver name */
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT,
+ &bus,&devfn,&size[0],&size[1],&size[2],&size[3],
+ &size[4],&size[5],&size[6]);
+ if (num != 9) { /* apparantly not 2.3 style */
+ fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET);
+ return FALSE;
+ }
+ dev = devfn >> 3;
+ fn = devfn & 0x7;
+ if (tag == pciTag(bus,dev,fn)) {
+ *bits = 0;
+ if (size[index] != 0) {
+ Size = size[index] - ((PCIADDR_TYPE) 1);
+ while (Size & ((PCIADDR_TYPE) 0x01)) {
+ Size = Size >> ((PCIADDR_TYPE) 1);
+ (*bits)++;
+ }
+ }
+ fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET);
+ return TRUE;
+ }
+ }
+ } while (res);
+
+ fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET);
+ return FALSE;
+}
+
+
+
+/* Query the kvirt address (64bit) of a BAR range from TAG */
+Bool
+xf86GetPciOffsetFromOS(PCITAG tag, int index, unsigned long* bases)
+{
+ FILE *file;
+ char c[0x200];
+ char *res;
+ unsigned int bus, devfn, dev, fn;
+ unsigned PCIADDR_TYPE offset[7];
+ unsigned int num;
+
+ if (index > 7)
+ return FALSE;
+
+ if (!(file = fopen("/proc/bus/pci/devices","r")))
+ return FALSE;
+ do {
+ res = fgets(c,0x1ff,file);
+ if (res) {
+ num = sscanf(res,
+ /*bus+dev vendorid deviceid irq */
+ "%02x%02x\t%*04x%*04x\t%*x"
+ /* 7 PCI resource base addresses */
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ /* 7 PCI resource sizes, and then optionally a driver name */
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT
+ "\t" PCIADDR_IGNORE_FMT,
+ &bus,&devfn,&offset[0],&offset[1],&offset[2],&offset[3],
+ &offset[4],&offset[5],&offset[6]);
+ if (num != 9) { /* apparantly not 2.3 style */
+ fclose(file);
+ return FALSE;
+ }
+
+ dev = devfn >> 3;
+ fn = devfn & 0x7;
+ if (tag == pciTag(bus,dev,fn)) {
+ /* return the offset for the index requested */
+ *bases = offset[index];
+ fclose(file);
+ return TRUE;
+ }
+ }
+ } while (res);
+
+ fclose(file);
+ return FALSE;
+}
+
+/* Query the kvirt address (64bit) of a BAR range from size for a given TAG */
+unsigned long
+xf86GetOSOffsetFromPCI(PCITAG tag, int space, unsigned long base)
+{
+ FILE *file;
+ char c[0x200];
+ char *res;
+ unsigned int bus, devfn, dev, fn;
+ unsigned PCIADDR_TYPE offset[7];
+ unsigned PCIADDR_TYPE size[7];
+ unsigned int num;
+ unsigned int ndx;
+
+ if (!(file = fopen("/proc/bus/pci/devices","r")))
+ return 0;
+ do {
+ res = fgets(c,0x1ff,file);
+ if (res) {
+ num = sscanf(res,
+ /*bus+dev vendorid deviceid irq */
+ "%02x%02x\t%*04x%*04x\t%*x"
+ /* 7 PCI resource base addresses */
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ /* 7 PCI resource sizes, and then optionally a driver name */
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT
+ "\t" PCIADDR_FMT,
+ &bus,&devfn,&offset[0],&offset[1],&offset[2],&offset[3],
+ &offset[4],&offset[5],&offset[6], &size[0], &size[1], &size[2],
+ &size[3], &size[4], &size[5], &size[6]);
+ if (num != 16) { /* apparantly not 2.3 style */
+ fclose(file);
+ return 0;
+ }
+
+ dev = devfn >> 3;
+ fn = devfn & 0x7;
+ if (tag == pciTag(bus,dev,fn)) {
+ /* ok now look through all the BAR values of this device */
+ for (ndx=0; ndx<7; ndx++) {
+ unsigned long savePtr;
+ /*
+ * remember to lop of the last 4bits of the BAR values as they are
+ * memory attributes
+ */
+ if (ndx == 6)
+ savePtr = (0xFFFFFFF0) &
+ pciReadLong(tag, PCI_CMD_BIOS_REG);
+ else /* this the ROM bar */
+ savePtr = (0xFFFFFFF0) &
+ pciReadLong(tag, PCI_CMD_BASE_REG + (0x4 * ndx));
+
+ /* find the index of the incoming base */
+ if (base >= savePtr && base <= (savePtr + size[ndx])) {
+ fclose(file);
+ return (offset[ndx] & ~(0xFUL)) + (base - savePtr);
+ }
+ }
+ }
+ }
+ } while (res);
+
+ fclose(file);
+ return 0;
+
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c
new file mode 100644
index 000000000..577439c54
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c
@@ -0,0 +1,1169 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c,v 1.10 2005/09/19 18:38:26 alanc Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c,v 3.67 2003/06/25 18:27:07 eich Exp $ */
+/*
+ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Orest Zborowski and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Orest Zborowski
+ * and David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: lnx_video.c /main/9 1996/10/19 18:06:34 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+#include "lnx.h"
+#ifdef __alpha__
+#include "shared/xf86Axp.h"
+#endif
+
+#ifdef HAS_MTRR_SUPPORT
+#include <asm/mtrr.h>
+#endif
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+static Bool ExtendedEnabled = FALSE;
+
+#ifdef __ia64__
+
+#include "compiler.h"
+#include <sys/io.h>
+
+#elif !defined(__powerpc__) && \
+ !defined(__mc68000__) && \
+ !defined(__sparc__) && \
+ !defined(__mips__)
+
+/*
+ * Due to conflicts with "compiler.h", don't rely on <sys/io.h> to declare
+ * these.
+ */
+extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on);
+extern int iopl(int __level);
+
+#endif
+
+#ifdef __alpha__
+
+# ifdef LIBC_IS_FIXED
+extern void sethae(unsigned long hae);
+# else
+# include <unistd.h>
+# define sethae(x) syscall(301,x);
+# endif
+
+/* define to test the Sparse addressing on a non-Jensen */
+# ifdef TEST_JENSEN_CODE
+# define isJensen (1)
+# else
+# define isJensen (axpSystem == JENSEN)
+# endif
+
+# define BUS_BASE bus_base
+
+#else
+
+#define BUS_BASE (0)
+
+#endif /* __alpha__ */
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+static pointer mapVidMem(int, unsigned long, unsigned long, int);
+static void unmapVidMem(int, pointer, unsigned long);
+#if defined (__alpha__)
+static pointer mapVidMemSparse(int, unsigned long, unsigned long, int);
+extern axpDevice lnxGetAXP(void);
+static void unmapVidMemSparse(int, pointer, unsigned long);
+# if defined(JENSEN_SUPPORT)
+static pointer mapVidMemJensen(int, unsigned long, unsigned long, int);
+static void unmapVidMemJensen(int, pointer, unsigned long);
+# endif
+static axpDevice axpSystem = -1;
+static Bool needSparse;
+static unsigned long hae_thresh;
+static unsigned long hae_mask;
+static unsigned long bus_base;
+static unsigned long sparse_size;
+#endif
+
+#ifdef HAS_MTRR_SUPPORT
+
+#define SPLIT_WC_REGIONS 1
+
+static pointer setWC(int, unsigned long, unsigned long, Bool, MessageType);
+static void undoWC(int, pointer);
+
+/* The file desc for /proc/mtrr. Once opened, left opened, and the mtrr
+ driver will clean up when we exit. */
+#define MTRR_FD_UNOPENED (-1) /* We have yet to open /proc/mtrr */
+#define MTRR_FD_PROBLEM (-2) /* We tried to open /proc/mtrr, but had
+ a problem. */
+static int mtrr_fd = MTRR_FD_UNOPENED;
+
+/* Open /proc/mtrr. FALSE on failure. Will always fail on Linux 2.0,
+ and will fail on Linux 2.2 with MTRR support configured out,
+ so verbosity should be chosen appropriately. */
+static Bool
+mtrr_open(int verbosity)
+{
+ /* Only report absence of /proc/mtrr once. */
+ static Bool warned = FALSE;
+
+ char **fn;
+ static char *mtrr_files[] = {
+ "/dev/cpu/mtrr", /* Possible future name */
+ "/proc/mtrr", /* Current name */
+ NULL
+ };
+
+ if (mtrr_fd == MTRR_FD_UNOPENED) {
+ /* So open it. */
+ for (fn = mtrr_files; mtrr_fd < 0 && *fn; fn++)
+ mtrr_fd = open(*fn, O_WRONLY);
+
+ if (mtrr_fd < 0)
+ mtrr_fd = MTRR_FD_PROBLEM;
+ }
+
+ if (mtrr_fd == MTRR_FD_PROBLEM) {
+ /* To make sure we only ever warn once, need to check
+ verbosity outside xf86MsgVerb */
+ if (!warned && verbosity <= xf86GetVerbosity()) {
+ xf86MsgVerb(X_WARNING, verbosity,
+ "System lacks support for changing MTRRs\n");
+ warned = TRUE;
+ }
+
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+/*
+ * We maintain a list of WC regions for each physical mapping so they can
+ * be undone when unmapping.
+ */
+
+struct mtrr_wc_region {
+ struct mtrr_sentry sentry;
+ Bool added; /* added WC or removed it */
+ struct mtrr_wc_region * next;
+};
+
+
+static struct mtrr_wc_region *
+mtrr_cull_wc_region(int screenNum, unsigned long base, unsigned long size,
+ MessageType from)
+{
+ /* Some BIOS writers thought that setting wc over the mmio
+ region of a graphics devices was a good idea. Try to fix
+ it. */
+
+ struct mtrr_gentry gent;
+ struct mtrr_wc_region *wcreturn = NULL, *wcr;
+ int count, ret=0;
+
+ /* Linux 2.0 users should not get a warning without -verbose */
+ if (!mtrr_open(2))
+ return NULL;
+
+ for (gent.regnum = 0;
+ ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0;
+ gent.regnum++) {
+ if (gent.type != MTRR_TYPE_WRCOMB
+ || gent.base + gent.size <= base
+ || base + size <= gent.base)
+ continue;
+
+ /* Found an overlapping region. Delete it. */
+
+ wcr = xalloc(sizeof(*wcr));
+ if (!wcr)
+ return NULL;
+ wcr->sentry.base = gent.base;
+ wcr->sentry.size = gent.size;
+ wcr->sentry.type = MTRR_TYPE_WRCOMB;
+ wcr->added = FALSE;
+
+ count = 3;
+ while (count-- &&
+ (ret = ioctl(mtrr_fd, MTRRIOC_KILL_ENTRY, &(wcr->sentry))) < 0);
+
+ if (ret >= 0) {
+ xf86DrvMsg(screenNum, from,
+ "Removed MMIO write-combining range "
+ "(0x%lx,0x%lx)\n",
+ (unsigned long) gent.base, (unsigned long) gent.size);
+ wcr->next = wcreturn;
+ wcreturn = wcr;
+ gent.regnum--;
+ } else {
+ xfree(wcr);
+ xf86DrvMsgVerb(screenNum, X_WARNING, 0,
+ "Failed to remove MMIO "
+ "write-combining range (0x%lx,0x%lx)\n",
+ gent.base, (unsigned long) gent.size);
+ }
+ }
+ return wcreturn;
+}
+
+
+static struct mtrr_wc_region *
+mtrr_remove_offending(int screenNum, unsigned long base, unsigned long size,
+ MessageType from)
+{
+ struct mtrr_gentry gent;
+ struct mtrr_wc_region *wcreturn = NULL, **wcr;
+
+ if (!mtrr_open(2))
+ return NULL;
+
+ wcr = &wcreturn;
+ for (gent.regnum = 0;
+ ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; gent.regnum++ ) {
+ if (gent.type == MTRR_TYPE_WRCOMB
+ && ((gent.base >= base && gent.base + gent.size < base + size) ||
+ (gent.base > base && gent.base + gent.size <= base + size))) {
+ *wcr = mtrr_cull_wc_region(screenNum, gent.base, gent.size, from);
+ if (*wcr) gent.regnum--;
+ while(*wcr) {
+ wcr = &((*wcr)->next);
+ }
+ }
+ }
+ return wcreturn;
+}
+
+
+static struct mtrr_wc_region *
+mtrr_add_wc_region(int screenNum, unsigned long base, unsigned long size,
+ MessageType from)
+{
+ struct mtrr_wc_region **wcr, *wcreturn, *curwcr;
+
+ /*
+ * There can be only one....
+ */
+
+ wcreturn = mtrr_remove_offending(screenNum, base, size, from);
+ wcr = &wcreturn;
+ while (*wcr) {
+ wcr = &((*wcr)->next);
+ }
+
+ /* Linux 2.0 should not warn, unless the user explicitly asks for
+ WC. */
+
+ if (!mtrr_open(from == X_CONFIG ? 0 : 2))
+ return wcreturn;
+
+ *wcr = curwcr = xalloc(sizeof(**wcr));
+ if (!curwcr)
+ return wcreturn;
+
+ curwcr->sentry.base = base;
+ curwcr->sentry.size = size;
+ curwcr->sentry.type = MTRR_TYPE_WRCOMB;
+ curwcr->added = TRUE;
+ curwcr->next = NULL;
+
+#if SPLIT_WC_REGIONS
+ /*
+ * Splits up the write-combining region if it is not aligned on a
+ * size boundary.
+ */
+
+ {
+ unsigned long lbase, d_size = 1;
+ unsigned long n_size = size;
+ unsigned long n_base = base;
+
+ for (lbase = n_base, d_size = 1; !(lbase & 1);
+ lbase = lbase >> 1, d_size <<= 1);
+ while (d_size > n_size)
+ d_size = d_size >> 1;
+#ifdef DEBUG
+ ErrorF("WC_BASE: 0x%lx WC_END: 0x%lx\n",base,base+d_size-1);
+#endif
+ n_base += d_size;
+ n_size -= d_size;
+ if (n_size) {
+ xf86DrvMsgVerb(screenNum,X_INFO,3,"Splitting WC range: "
+ "base: 0x%lx, size: 0x%lx\n",base,size);
+ curwcr->next = mtrr_add_wc_region(screenNum, n_base, n_size,from);
+ }
+ curwcr->sentry.size = d_size;
+ }
+
+ /*****************************************************************/
+#endif /* SPLIT_WC_REGIONS */
+
+ if (ioctl(mtrr_fd, MTRRIOC_ADD_ENTRY, &curwcr->sentry) >= 0) {
+ /* Avoid printing on every VT switch */
+ if (xf86ServerIsInitialising()) {
+ xf86DrvMsg(screenNum, from,
+ "Write-combining range (0x%lx,0x%lx)\n",
+ base, size);
+ }
+ return wcreturn;
+ }
+ else {
+ *wcr = curwcr->next;
+ xfree(curwcr);
+
+ /* Don't complain about the VGA region: MTRR fixed
+ regions aren't currently supported, but might be in
+ the future. */
+ if ((unsigned long)base >= 0x100000) {
+ xf86DrvMsgVerb(screenNum, X_WARNING, 0,
+ "Failed to set up write-combining range "
+ "(0x%lx,0x%lx)\n", base, size);
+ }
+ return wcreturn;
+ }
+}
+
+static void
+mtrr_undo_wc_region(int screenNum, struct mtrr_wc_region *wcr)
+{
+ struct mtrr_wc_region *p, *prev;
+
+ if (mtrr_fd > 0) {
+ p = wcr;
+ while (p) {
+ if (p->added)
+ ioctl(mtrr_fd, MTRRIOC_DEL_ENTRY, &p->sentry);
+ prev = p;
+ p = p->next;
+ xfree(prev);
+ }
+ }
+}
+
+static pointer
+setWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
+ MessageType from)
+{
+ if (enable)
+ return mtrr_add_wc_region(screenNum, base, size, from);
+ else
+ return mtrr_cull_wc_region(screenNum, base, size, from);
+}
+
+static void
+undoWC(int screenNum, pointer regioninfo)
+{
+ mtrr_undo_wc_region(screenNum, regioninfo);
+}
+
+#endif /* HAS_MTRR_SUPPORT */
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ pVidMem->linearSupported = TRUE;
+#ifdef __alpha__
+ if (axpSystem == -1) {
+ axpSystem = lnxGetAXP();
+ if ((needSparse = (_bus_base_sparse() > 0))) {
+ hae_thresh = xf86AXPParams[axpSystem].hae_thresh;
+ hae_mask = xf86AXPParams[axpSystem].hae_mask;
+ sparse_size = xf86AXPParams[axpSystem].size;
+ }
+ bus_base = _bus_base();
+ }
+ if (isJensen) {
+# ifndef JENSEN_SUPPORT
+ FatalError("Jensen is not supported any more\n"
+ "If you are intereseted in fixing Jensen support\n"
+ "please contact xfree86@xfree86.org\n");
+# else
+ xf86Msg(X_INFO,"Machine type is Jensen\n");
+ pVidMem->mapMem = mapVidMemJensen;
+ pVidMem->unmapMem = unmapVidMemJensen;
+# endif /* JENSEN_SUPPORT */
+ } else if (needSparse) {
+ xf86Msg(X_INFO,"Machine needs sparse mapping\n");
+ pVidMem->mapMem = mapVidMemSparse;
+ pVidMem->unmapMem = unmapVidMemSparse;
+ } else {
+ xf86Msg(X_INFO,"Machine type has 8/16 bit access\n");
+ pVidMem->mapMem = mapVidMem;
+ pVidMem->unmapMem = unmapVidMem;
+ }
+#else
+ pVidMem->mapMem = mapVidMem;
+ pVidMem->unmapMem = unmapVidMem;
+#endif /* __alpha__ */
+
+
+#ifdef HAS_MTRR_SUPPORT
+ pVidMem->setWC = setWC;
+ pVidMem->undoWC = undoWC;
+#endif
+ pVidMem->initialised = TRUE;
+}
+
+#ifdef __sparc__
+/* Basically, you simply cannot do this on Sparc. You have to do something portable
+ * like use /dev/fb* or mmap() on /proc/bus/pci/X/Y nodes. -DaveM
+ */
+static pointer mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ return NULL;
+}
+#else
+static pointer
+mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ pointer base;
+ int fd;
+ int mapflags = MAP_SHARED;
+ int prot;
+ memType realBase, alignOff;
+
+ realBase = Base & ~(getpagesize() - 1);
+ alignOff = Base - realBase;
+#ifdef DEBUG
+ ErrorF("base: %lx, realBase: %lx, alignOff: %lx \n",
+ Base,realBase,alignOff);
+#endif
+
+#if defined(__ia64__)
+#ifndef MAP_WRITECOMBINED
+#define MAP_WRITECOMBINED 0x00010000
+#endif
+#ifndef MAP_NONCACHED
+#define MAP_NONCACHED 0x00020000
+#endif
+ if(flags & VIDMEM_FRAMEBUFFER)
+ mapflags |= MAP_WRITECOMBINED;
+ else
+ mapflags |= MAP_NONCACHED;
+#endif
+
+#if 0
+ /* this will disappear when people upgrade their kernels */
+ fd = open(DEV_MEM,
+ ((flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR) | O_SYNC);
+#else
+ fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
+#endif
+ if (fd < 0)
+ {
+ FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n",
+ strerror(errno));
+ }
+
+ if (flags & VIDMEM_READONLY)
+ prot = PROT_READ;
+ else
+ prot = PROT_READ | PROT_WRITE;
+
+ /* This requires linux-0.99.pl10 or above */
+ base = mmap((caddr_t)0, Size + alignOff, prot, mapflags, fd,
+ (off_t)realBase + BUS_BASE);
+ close(fd);
+ if (base == MAP_FAILED) {
+ FatalError("xf86MapVidMem: Could not mmap framebuffer"
+ " (0x%08lx,0x%lx) (%s)\n", Base, Size,
+ strerror(errno));
+ }
+#ifdef DEBUG
+ ErrorF("base: %lx aligned base: %lx\n",base, base + alignOff);
+#endif
+ return (char *)base + alignOff;
+}
+#endif /* !(__sparc__) */
+
+static void
+unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ memType alignOff = (memType)Base
+ - ((memType)Base & ~(getpagesize() - 1));
+
+#ifdef DEBUG
+ ErrorF("alignment offset: %lx\n",alignOff);
+#endif
+ munmap((caddr_t)((memType)Base - alignOff), (Size + alignOff));
+}
+
+
+/***************************************************************************/
+/* I/O Permissions section */
+/***************************************************************************/
+
+#if defined(__powerpc__)
+volatile unsigned char *ioBase = NULL;
+
+#ifndef __NR_pciconfig_iobase
+#define __NR_pciconfig_iobase 200
+#endif
+
+#endif
+
+Bool
+xf86EnableIO(void)
+{
+#if defined(__powerpc__)
+ int fd;
+ unsigned int ioBase_phys;
+#endif
+
+ if (ExtendedEnabled)
+ return TRUE;
+
+#if defined(__powerpc__)
+ ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0);
+
+ fd = open("/dev/mem", O_RDWR);
+ if (ioBase == NULL) {
+ ioBase = (volatile unsigned char *)mmap(0, 0x20000,
+ PROT_READ | PROT_WRITE, MAP_SHARED, fd,
+ ioBase_phys);
+/* Should this be fatal or just a warning? */
+#if 0
+ if (ioBase == MAP_FAILED) {
+ xf86Msg(X_WARNING,
+ "xf86EnableIOPorts: Failed to map iobase (%s)\n",
+ strerror(errno));
+ return FALSE;
+ }
+#endif
+ }
+ close(fd);
+#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__)
+ if (ioperm(0, 1024, 1) || iopl(3)) {
+ if (errno == ENODEV)
+ ErrorF("xf86EnableIOPorts: no I/O ports found\n");
+ else
+ FatalError("xf86EnableIOPorts: failed to set IOPL"
+ " for I/O (%s)\n", strerror(errno));
+ return FALSE;
+ }
+# if !defined(__alpha__)
+ ioperm(0x40,4,0); /* trap access to the timer chip */
+ ioperm(0x60,4,0); /* trap access to the keyboard controller */
+# endif
+#endif
+ ExtendedEnabled = TRUE;
+
+ return TRUE;
+}
+
+void
+xf86DisableIO(void)
+{
+ if (!ExtendedEnabled)
+ return;
+#if defined(__powerpc__)
+ munmap(ioBase, 0x20000);
+ ioBase = NULL;
+#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__)
+ iopl(0);
+ ioperm(0, 1024, 0);
+#endif
+ ExtendedEnabled = FALSE;
+
+ return;
+}
+
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+/* XXX The #ifdefs should be made simpler. */
+
+Bool
+xf86DisableInterrupts()
+{
+#if !defined(__mc68000__) && !defined(__powerpc__) && !defined(__sparc__) && !defined(__mips__) && !defined(__ia64__) && !defined(__sh__) && !defined(__hppa__)
+ if (!ExtendedEnabled)
+ if (iopl(3) || ioperm(0, 1024, 1))
+ return (FALSE);
+#endif
+#if defined(__alpha__) || defined(__mc68000__) || defined(__powerpc__) || defined(__sparc__) || defined(__mips__) || defined(__arm__) || defined(__sh__) || defined(__ia64__) || defined(__hppa__)
+#else
+# ifdef __GNUC__
+# if defined(__ia64__)
+# if 0
+ __asm__ __volatile__ (";; rsm psr.i;; srlz.d" ::: "memory");
+# endif
+# else
+ __asm__ __volatile__("cli");
+# endif
+# else
+ asm("cli");
+# endif
+#endif
+#if !defined(__mc68000__) && !defined(__powerpc__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__ia64__) && !defined(__hppa__)
+ if (!ExtendedEnabled) {
+ iopl(0);
+ ioperm(0, 1024, 0);
+ }
+
+#endif
+ return (TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+#if !defined(__mc68000__) && !defined(__powerpc__) && !defined(__sparc__) && !defined(__mips__) && !defined(__ia64__) && !defined(__sh__) && !defined(__hppa__)
+ if (!ExtendedEnabled)
+ if (iopl(3) || ioperm(0, 1024, 1))
+ return;
+#endif
+#if defined(__alpha__) || defined(__mc68000__) || defined(__powerpc__) || defined(__sparc__) || defined(__mips__) || defined(__arm__) || defined(__sh__) || defined(__ia64__) || defined(__hppa__)
+#else
+# ifdef __GNUC__
+# if defined(__ia64__)
+# if 0
+ __asm__ __volatile__ (";; ssm psr.i;; srlz.d" ::: "memory");
+# endif
+# else
+ __asm__ __volatile__("sti");
+# endif
+# else
+ asm("sti");
+# endif
+#endif
+#if !defined(__mc68000__) && !defined(__powerpc__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__ia64__) && !defined(__hppa__)
+ if (!ExtendedEnabled) {
+ iopl(0);
+ ioperm(0, 1024, 0);
+ }
+#endif
+ return;
+}
+
+#if defined (__alpha__)
+
+#define vuip volatile unsigned int *
+
+extern int readDense8(pointer Base, register unsigned long Offset);
+extern int readDense16(pointer Base, register unsigned long Offset);
+extern int readDense32(pointer Base, register unsigned long Offset);
+extern void
+writeDenseNB8(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDenseNB16(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDenseNB32(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDense8(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDense16(int Value, pointer Base, register unsigned long Offset);
+extern void
+writeDense32(int Value, pointer Base, register unsigned long Offset);
+
+static int readSparse8(pointer Base, register unsigned long Offset);
+static int readSparse16(pointer Base, register unsigned long Offset);
+static int readSparse32(pointer Base, register unsigned long Offset);
+static void
+writeSparseNB8(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparseNB16(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparseNB32(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparse8(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparse16(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparse32(int Value, pointer Base, register unsigned long Offset);
+
+#define DENSE_BASE 0x2ff00000000UL
+#define SPARSE_BASE 0x30000000000UL
+
+static unsigned long msb_set = 0;
+
+static pointer
+mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ int fd, prot;
+ unsigned long ret, rets = 0;
+
+ static Bool was_here = FALSE;
+
+ if (!was_here) {
+ was_here = TRUE;
+
+ xf86WriteMmio8 = writeSparse8;
+ xf86WriteMmio16 = writeSparse16;
+ xf86WriteMmio32 = writeSparse32;
+ xf86WriteMmioNB8 = writeSparseNB8;
+ xf86WriteMmioNB16 = writeSparseNB16;
+ xf86WriteMmioNB32 = writeSparseNB32;
+ xf86ReadMmio8 = readSparse8;
+ xf86ReadMmio16 = readSparse16;
+ xf86ReadMmio32 = readSparse32;
+ }
+
+ fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
+ if (fd < 0) {
+ FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n",
+ strerror(errno));
+ }
+
+#if 0
+ xf86Msg(X_INFO,"mapVidMemSparse: try Base 0x%lx size 0x%lx flags 0x%x\n",
+ Base, Size, flags);
+#endif
+
+ if (flags & VIDMEM_READONLY)
+ prot = PROT_READ;
+ else
+ prot = PROT_READ | PROT_WRITE;
+
+ /* This requirers linux-0.99.pl10 or above */
+
+ /*
+ * Always do DENSE mmap, since read32/write32 currently require it.
+ */
+ ret = (unsigned long)mmap((caddr_t)(DENSE_BASE + Base), Size,
+ prot, MAP_SHARED, fd,
+ (off_t) (bus_base + Base));
+
+ /*
+ * Do SPARSE mmap only when MMIO and not MMIO_32BIT, or FRAMEBUFFER
+ * and SPARSE (which should require the use of read/write macros).
+ *
+ * By not SPARSE mmapping an 8MB framebuffer, we can save approx. 256K
+ * bytes worth of pagetable (32 pages).
+ */
+ if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) ||
+ ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE)))
+ {
+ rets = (unsigned long)mmap((caddr_t)(SPARSE_BASE + (Base << 5)),
+ Size << 5, prot, MAP_SHARED, fd,
+ (off_t) _bus_base_sparse() + (Base << 5));
+ }
+
+ close(fd);
+
+ if (ret == (unsigned long)MAP_FAILED) {
+ FatalError("xf86MapVidMemSparse: Could not (dense) mmap fb (%s)\n",
+ strerror(errno));
+ }
+
+ if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) ||
+ ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE)))
+ {
+ if (rets == (unsigned long)MAP_FAILED ||
+ rets != (SPARSE_BASE + (Base << 5)))
+ {
+ FatalError("mapVidMemSparse: Could not (sparse) mmap fb (%s)\n",
+ strerror(errno));
+ }
+ }
+
+#if 1
+ if (rets)
+ xf86Msg(X_INFO,"mapVidMemSparse: mapped Base 0x%lx size 0x%lx"
+ " to DENSE at 0x%lx and SPARSE at 0x%lx\n",
+ Base, Size, ret, rets);
+ else
+ xf86Msg(X_INFO,"mapVidMemSparse: mapped Base 0x%lx size 0x%lx"
+ " to DENSE only at 0x%lx\n",
+ Base, Size, ret);
+
+#endif
+ return (pointer) ret;
+}
+
+static void
+unmapVidMemSparse(int ScreenNum, pointer Base, unsigned long Size)
+{
+ unsigned long Offset = (unsigned long)Base - DENSE_BASE;
+#if 1
+ xf86Msg(X_INFO,"unmapVidMemSparse: unmapping Base 0x%lx Size 0x%lx\n",
+ Base, Size);
+#endif
+ /* Unmap DENSE always. */
+ munmap((caddr_t)Base, Size);
+
+ /* Unmap SPARSE always, and ignore error in case we did not map it. */
+ munmap((caddr_t)(SPARSE_BASE + (Offset << 5)), Size << 5);
+}
+
+static int
+readSparse8(pointer Base, register unsigned long Offset)
+{
+ register unsigned long result, shift;
+ register unsigned long msb;
+
+ mem_barrier();
+ Offset += (unsigned long)Base - DENSE_BASE;
+ shift = (Offset & 0x3) << 3;
+ if (Offset >= (hae_thresh)) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+ sethae(msb);
+ msb_set = msb;
+ }
+ }
+
+ mem_barrier();
+ result = *(vuip) (SPARSE_BASE + (Offset << 5));
+ result >>= shift;
+ return 0xffUL & result;
+}
+
+static int
+readSparse16(pointer Base, register unsigned long Offset)
+{
+ register unsigned long result, shift;
+ register unsigned long msb;
+
+ mem_barrier();
+ Offset += (unsigned long)Base - DENSE_BASE;
+ shift = (Offset & 0x2) << 3;
+ if (Offset >= hae_thresh) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+ sethae(msb);
+ msb_set = msb;
+ }
+ }
+
+ mem_barrier();
+ result = *(vuip)(SPARSE_BASE + (Offset<<5) + (1<<(5-2)));
+ result >>= shift;
+ return 0xffffUL & result;
+}
+
+static int
+readSparse32(pointer Base, register unsigned long Offset)
+{
+ /* NOTE: this is really using DENSE. */
+ mem_barrier();
+ return *(vuip)((unsigned long)Base+(Offset));
+}
+
+static void
+writeSparse8(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned long msb;
+ register unsigned int b = Value & 0xffU;
+
+ write_mem_barrier();
+ Offset += (unsigned long)Base - DENSE_BASE;
+ if (Offset >= hae_thresh) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+ sethae(msb);
+ msb_set = msb;
+ }
+ }
+
+ write_mem_barrier();
+ *(vuip) (SPARSE_BASE + (Offset << 5)) = b * 0x01010101;
+}
+
+static void
+writeSparse16(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned long msb;
+ register unsigned int w = Value & 0xffffU;
+
+ write_mem_barrier();
+ Offset += (unsigned long)Base - DENSE_BASE;
+ if (Offset >= hae_thresh) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+ sethae(msb);
+ msb_set = msb;
+ }
+ }
+
+ write_mem_barrier();
+ *(vuip)(SPARSE_BASE + (Offset<<5) + (1<<(5-2))) = w * 0x00010001;
+}
+
+static void
+writeSparse32(int Value, pointer Base, register unsigned long Offset)
+{
+ /* NOTE: this is really using DENSE. */
+ write_mem_barrier();
+ *(vuip)((unsigned long)Base + (Offset)) = Value;
+ return;
+}
+
+static void
+writeSparseNB8(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned long msb;
+ register unsigned int b = Value & 0xffU;
+
+ Offset += (unsigned long)Base - DENSE_BASE;
+ if (Offset >= hae_thresh) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+ sethae(msb);
+ msb_set = msb;
+ }
+ }
+ *(vuip) (SPARSE_BASE + (Offset << 5)) = b * 0x01010101;
+}
+
+static void
+writeSparseNB16(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned long msb;
+ register unsigned int w = Value & 0xffffU;
+
+ Offset += (unsigned long)Base - DENSE_BASE;
+ if (Offset >= hae_thresh) {
+ msb = Offset & hae_mask;
+ Offset -= msb;
+ if (msb_set != msb) {
+ sethae(msb);
+ msb_set = msb;
+ }
+ }
+ *(vuip)(SPARSE_BASE+(Offset<<5)+(1<<(5-2))) = w * 0x00010001;
+}
+
+static void
+writeSparseNB32(int Value, pointer Base, register unsigned long Offset)
+{
+ /* NOTE: this is really using DENSE. */
+ *(vuip)((unsigned long)Base + (Offset)) = Value;
+ return;
+}
+
+void (*xf86WriteMmio8)(int Value, pointer Base, unsigned long Offset)
+ = writeDense8;
+void (*xf86WriteMmio16)(int Value, pointer Base, unsigned long Offset)
+ = writeDense16;
+void (*xf86WriteMmio32)(int Value, pointer Base, unsigned long Offset)
+ = writeDense32;
+void (*xf86WriteMmioNB8)(int Value, pointer Base, unsigned long Offset)
+ = writeDenseNB8;
+void (*xf86WriteMmioNB16)(int Value, pointer Base, unsigned long Offset)
+ = writeDenseNB16;
+void (*xf86WriteMmioNB32)(int Value, pointer Base, unsigned long Offset)
+ = writeDenseNB32;
+int (*xf86ReadMmio8)(pointer Base, unsigned long Offset)
+ = readDense8;
+int (*xf86ReadMmio16)(pointer Base, unsigned long Offset)
+ = readDense16;
+int (*xf86ReadMmio32)(pointer Base, unsigned long Offset)
+ = readDense32;
+
+#ifdef JENSEN_SUPPORT
+
+static int
+readSparseJensen8(pointer Base, register unsigned long Offset);
+static int
+readSparseJensen16(pointer Base, register unsigned long Offset);
+static int
+readSparseJensen32(pointer Base, register unsigned long Offset);
+static void
+writeSparseJensen8(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparseJensen16(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparseJensen32(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparseJensenNB8(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparseJensenNB16(int Value, pointer Base, register unsigned long Offset);
+static void
+writeSparseJensenNB32(int Value, pointer Base, register unsigned long Offset);
+
+/*
+ * The Jensen lacks dense memory, thus we have to address the bus via
+ * the sparse addressing scheme.
+ *
+ * Martin Ostermann (ost@comnets.rwth-aachen.de) - Apr.-Sep. 1996
+ */
+
+#ifdef TEST_JENSEN_CODE
+#define SPARSE (5)
+#else
+#define SPARSE (7)
+#endif
+
+#define JENSEN_SHIFT(x) ((long)x<<SPARSE)
+
+static pointer
+mapVidMemJensen(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ pointer base;
+ int fd, prot;
+
+ xf86WriteMmio8 = writeSparseJensen8;
+ xf86WriteMmio16 = writeSparseJensen16;
+ xf86WriteMmio32 = writeSparseJensen32;
+ xf86WriteMmioNB8 = writeSparseJensenNB8;
+ xf86WriteMmioNB16 = writeSparseJensenNB16;
+ xf86WriteMmioNB32 = writeSparseJensenNB32;
+ xf86ReadMmio8 = readSparseJensen8;
+ xf86ReadMmio16 = readSparseJensen16;
+ xf86ReadMmio32 = readSparseJensen32;
+
+ fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
+ if (fd < 0) {
+ FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n",
+ strerror(errno));
+ }
+
+ if (flags & VIDMEM_READONLY)
+ prot = PROT_READ;
+ else
+ prot = PROT_READ | PROT_WRITE;
+
+ /* This requires linux-0.99.pl10 or above */
+ base = mmap((caddr_t)0, JENSEN_SHIFT(Size),
+ prot, MAP_SHARED, fd,
+ (off_t)(JENSEN_SHIFT((off_t)Base) + _bus_base_sparse()));
+ close(fd);
+ if (base == MAP_FAILED) {
+ FatalError("xf86MapVidMem: Could not mmap framebuffer"
+ " (0x%08x,0x%x) (%s)\n", Base, Size,
+ strerror(errno));
+ }
+ return base;
+}
+
+static void
+unmapVidMemJensen(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap((caddr_t)Base, JENSEN_SHIFT(Size));
+}
+
+static int
+readSparseJensen8(pointer Base, register unsigned long Offset)
+{
+ register unsigned long result, shift;
+
+ mem_barrier();
+ shift = (Offset & 0x3) << 3;
+
+ result = *(vuip) ((unsigned long)Base + (Offset << SPARSE));
+
+ result >>= shift;
+ return 0xffUL & result;
+}
+
+static int
+readSparseJensen16(pointer Base, register unsigned long Offset)
+{
+ register unsigned long result, shift;
+
+ mem_barrier();
+ shift = (Offset & 0x2) << 3;
+
+ result = *(vuip)((unsigned long)Base+(Offset<<SPARSE)+(1<<(SPARSE-2)));
+
+ result >>= shift;
+ return 0xffffUL & result;
+}
+
+static int
+readSparseJensen32(pointer Base, register unsigned long Offset)
+{
+ register unsigned long result;
+
+ mem_barrier();
+ result = *(vuip)((unsigned long)Base+(Offset<<SPARSE)+(3<<(SPARSE-2)));
+
+ return result;
+}
+
+static void
+writeSparseJensen8(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned int b = Value & 0xffU;
+
+ write_mem_barrier();
+ *(vuip) ((unsigned long)Base + (Offset << SPARSE)) = b * 0x01010101;
+}
+
+static void
+writeSparseJensen16(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned int w = Value & 0xffffU;
+
+ write_mem_barrier();
+ *(vuip)((unsigned long)Base+(Offset<<SPARSE)+(1<<(SPARSE-2))) =
+ w * 0x00010001;
+}
+
+static void
+writeSparseJensen32(int Value, pointer Base, register unsigned long Offset)
+{
+ write_mem_barrier();
+ *(vuip)((unsigned long)Base+(Offset<<SPARSE)+(3<<(SPARSE-2))) = Value;
+}
+
+static void
+writeSparseJensenNB8(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned int b = Value & 0xffU;
+
+ *(vuip) ((unsigned long)Base + (Offset << SPARSE)) = b * 0x01010101;
+}
+
+static void
+writeSparseJensenNB16(int Value, pointer Base, register unsigned long Offset)
+{
+ register unsigned int w = Value & 0xffffU;
+
+ *(vuip)((unsigned long)Base+(Offset<<SPARSE)+(1<<(SPARSE-2))) =
+ w * 0x00010001;
+}
+
+static void
+writeSparseJensenNB32(int Value, pointer Base, register unsigned long Offset)
+{
+ *(vuip)((unsigned long)Base+(Offset<<SPARSE)+(3<<(SPARSE-2))) = Value;
+}
+#endif /* JENSEN_SUPPORT */
+
+#endif /* __alpha__ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/Imakefile
new file mode 100644
index 000000000..350856905
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/Imakefile
@@ -0,0 +1,62 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/Imakefile,v 3.23 2002/10/17 02:22:46 dawes Exp $
+#include <Server.tmpl>
+
+#if AllowSIGIO
+SIGIO=sigio
+#else
+SIGIO=sigiostubs
+#endif
+
+#if !defined(PpcArchitecture)
+#if HasMTRRSupport
+MTRRDEFINES = -DHAS_MTRR_SUPPORT
+#endif
+IOPERM_SRCS=ioperm_noop.c
+IOPERM_OBJS=ioperm_noop.o
+#endif
+
+#if defined(PpcArchitecture)
+PPC_SRCS=lynx_noinline.c lynx_ppc.c
+PPC_OBJS=lynx_noinline.o lynx_ppc.o
+#endif
+
+MOUSESRC = lynx_mouse.c
+MOUSEOBJ = lynx_mouse.o
+
+SRCS = lynx_init.c lynx_video.c lynx_io.c lynx_mmap.c \
+ VTsw_usl.c std_kbdEv.c posix_tty.c $(MOUSESRC) \
+ $(IOPERM_SRCS) $(PPC_SRCS) libc_wrapper.c stdResource.c stdPci.c \
+ vidmem.c $(SIGIO).c pm_noop.c kmod_noop.c agp_noop.c
+
+OBJS = lynx_init.o lynx_video.o lynx_io.o lynx_mmap.o \
+ VTsw_usl.o std_kbdEv.o posix_tty.o $(MOUSEOBJ) \
+ $(IOPERM_OBJS) $(PPC_OBJS) libc_wrapper.o stdResource.o stdPci.o \
+ vidmem.o $(SIGIO).o pm_noop.o kmod_noop.o agp_noop.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC) \
+ -I$(ENV_PREFIX)/sys/lynx.os -I$(DRMSRCDIR)/shared-core
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES) $(MTRRDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+#if !defined(PpcArchitecture)
+LinkSourceFile(ioperm_noop.c,../shared)
+#endif
+LinkSourceFile(VTsw_usl.c,../shared)
+LinkSourceFile(std_kbdEv.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(vidmem.c,../shared)
+LinkSourceFile($(SIGIO).c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_init.c
new file mode 100644
index 000000000..84db50127
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_init.c
@@ -0,0 +1,193 @@
+/*
+ * Copyright 1993 by Thomas Mueller
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Mueller not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Mueller makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS MUELLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS MUELLER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_init.c,v 3.2 1998/07/25 16:56:45 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+static int VTnum = -1;
+
+void
+xf86OpenConsole()
+{
+ struct vt_mode VT;
+ char vtname1[11];
+ int fd, pgrp;
+ MessageType from = X_PROBED;
+
+ if (serverGeneration == 1)
+ {
+ /* check if we're run with euid==0 */
+ if (geteuid() != 0)
+ {
+ FatalError("xf86OpenConsole: Server must be suid root\n");
+ }
+
+ /*
+ * setup the virtual terminal manager
+ * NOTE:
+ * We use the out-of-the-box atc terminal driver,
+ * not the GE contributed vdt driver.
+ * Also, we do setup signals for VT switching which
+ * is not really necessary because we don't feed the
+ * VT switch keystrokes to the kernel in xf86Events.c
+ * (it bombs occasionally...)
+ */
+ if (VTnum != -1)
+ {
+ xf86Info.vtno = VTnum;
+ from = X_CMDLINE;
+ }
+ else
+ {
+ /* We could use /dev/con which is usually a symlink
+ * to /dev/atc0 but one could configure the system
+ * to use a serial line as console device, so to
+ * be sure we take /dev/atc0.
+ */
+ if ((fd = open("/dev/atc0",O_WRONLY,0)) < 0)
+ {
+ FatalError(
+ "xf86OpenConsole: Cannot open /dev/atc0 (%s)\n",
+ strerror(errno));
+ }
+ if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
+ (xf86Info.vtno == -1))
+ {
+ FatalError("xf86OpenConsole: Cannot find a free VT\n");
+ }
+ close(fd);
+ }
+ xf86Msg(from, "using VT number %d\n", xf86Info.vtno);
+
+ sprintf(vtname1,"/dev/atc%d",xf86Info.vtno);
+
+ pgrp = getpgrp(); /* POSIX version ! */
+ ioctl(xf86Info.consoleFd, TIOCSPGRP, &pgrp);
+
+ if ((xf86Info.consoleFd = open(vtname1,O_RDWR|O_NDELAY,0)) < 0)
+ {
+ FatalError(
+ "xf86OpenConsole: Cannot open %s (%s)\n",
+ vtname1, strerror(errno));
+ }
+ /* change ownership of the vt */
+ chown(vtname1, getuid(), getgid());
+
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
+ {
+ FatalError("xf86OpenConsole: VT_GETMODE failed\n");
+ }
+
+ /* for future use... */
+ signal(SIGUSR1, xf86VTRequest);
+
+ VT.mode = VT_PROCESS;
+ VT.relsig = SIGUSR1;
+ VT.acqsig = SIGUSR1;
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
+ {
+ FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
+ }
+ }
+ else
+ {
+ /* serverGeneration != 1 */
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ /*
+ * If the server doesn't have the VT when the reset occurs,
+ * this is to make sure we don't continue until the activate
+ * signal is received.
+ */
+ if (!xf86Screens[0]->vtSema)
+ sleep(5);
+ }
+ return;
+}
+
+void
+xf86CloseConsole()
+{
+ struct vt_mode VT;
+
+#if 0
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno);
+ ioctl(xf86Info.consoleFd, VT_WAITACTIVE, 0);
+#endif
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
+ {
+ VT.mode = VT_AUTO;
+ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */
+ }
+ close(xf86Info.consoleFd); /* make the vt-manager happy */
+ return;
+}
+
+int
+xf86ProcessArgument(int argc, char *argv[], int i)
+{
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+ {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ return(1);
+ }
+ return(0);
+}
+
+void
+xf86UseMsg()
+{
+ ErrorF("vtXX use the specified VT number\n");
+ return;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_io.c
new file mode 100644
index 000000000..afd3f8962
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_io.c
@@ -0,0 +1,166 @@
+/*
+ * Copyright 1993 by Thomas Mueller
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Mueller not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Mueller makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS MUELLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS MUELLER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_io.c,v 3.9 2002/10/11 01:40:35 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#if defined(KDMKTONE) || defined(KIOCSOUND)
+/* Lynx 2.2.1 has sophisticated atc stuff.... */
+void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ if (loudness && pitch)
+ {
+#ifdef KDMKTONE
+ /*
+ * If we have KDMKTONE use it to avoid putting the server
+ * to sleep
+ */
+ ioctl(xf86Info.consoleFd, KDMKTONE,
+ (pitch & 0xffff) |
+ (((unsigned long)duration *
+ loudness / 50) << 16));
+#else
+ ioctl(xf86Info.consoleFd, KIOCSOUND, pitch);
+ usleep(xf86Info.bell_duration * loudness * 20);
+ ioctl(xf86Info.consoleFd, KIOCSOUND, 0);
+#endif
+ }
+}
+
+#else
+
+/* this is pulled from /sys/drivers/vt100/atbeep.c */
+
+#define SPEAKER_CONTROL 0x61
+#define TIMER_CONTROL 0x43
+#define TIMER_DATA 0x42
+#define TIMER_LOAD_CMD 0xb6
+
+#define TIMER_CONSTANT 1193280
+#define FREQ_LO(f) ((TIMER_CONSTANT / (f)) % 256)
+#define FREQ_HI(f) ((TIMER_CONSTANT / (f)) / 256)
+
+void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ int flo = FREQ_LO(pitch);
+ int fhi = FREQ_HI(pitch);
+
+ outb(TIMER_CONTROL, TIMER_LOAD_CMD);
+ outb(TIMER_DATA, flo);
+ outb(TIMER_DATA, fhi);
+
+ /* speaker on */
+ outb(SPEAKER_CONTROL, inb(SPEAKER_CONTROL) | 3);
+ usleep(xf86Info.bell_duration * loudness * 20);
+ /* speaker off */
+ outb(SPEAKER_CONTROL, inb(SPEAKER_CONTROL) & ~3);
+}
+#endif
+
+void
+xf86SetKbdLeds(int leds)
+{
+#ifdef KBD_SET_LEDS
+ ioctl(xf86Info.consoleFd, KBD_SET_LEDS, &leds);
+#endif
+}
+
+int
+xf86GetKbdLeds()
+{
+#ifdef KBD_SET_LEDS
+ int leds;
+
+ if (ioctl(xf86Info.consoleFd, KBD_SET_LEDS, &leds) < 0)
+ return 0;
+
+ return leds;
+#endif
+ return 0;
+}
+
+void
+xf86SetKbdRepeat(char rad)
+{
+}
+
+static struct termio kbdtty;
+
+void
+xf86KbdInit()
+{
+ ioctl(xf86Info.consoleFd, TCGETA, &kbdtty);
+}
+
+int
+xf86KbdOn()
+{
+ struct termio nTty;
+
+ /* set CAPS_LOCK to behave as CAPS_LOCK not as CTRL */
+ write(xf86Info.consoleFd, "\033<", 2);
+
+ /* enable scan mode */
+ ioctl(xf86Info.consoleFd, TIO_ENSCANMODE, NULL);
+
+ nTty = kbdtty;
+ nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME]=0;
+ nTty.c_cc[VMIN]=1;
+ ioctl(xf86Info.consoleFd, TCSETA, &nTty);
+
+ return(xf86Info.consoleFd);
+}
+
+int
+xf86KbdOff()
+{
+ /* disable scan mode */
+ ioctl(xf86Info.consoleFd, TIO_DISSCANMODE, NULL);
+ ioctl(xf86Info.consoleFd, TCSETA, &kbdtty);
+ return(xf86Info.consoleFd);
+}
+
+#include "xf86OSKbd.h"
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mmap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mmap.c
new file mode 100644
index 000000000..c00b6700f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mmap.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright 1993 by Thomas Mueller
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Mueller not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Mueller makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS MUELLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS MUELLER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mmap.c,v 3.5 1998/08/29 05:43:58 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * Read BIOS using smem_create facility
+ */
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+#if defined(__powerpc__)
+ xf86Msg(X_WARNING, "xf86ReadBios: no BIOS-probe on PowerPC\n");
+ return(-1);
+#else
+ char *p;
+ int mlen;
+
+ mlen = (Offset + Len + 4095) & ~4095;
+ p = smem_create("BIOS-probe", (char *)Base, mlen, SM_READ);
+ if (p == NULL)
+ {
+ /* check if there is a stale segment around */
+ if (smem_remove("BIOS-probe") == 0) {
+ xf86Msg(X_INFO,
+ "xf86ReadBios: removed stale smem_ segment\n");
+ p = smem_create("BIOS-probe", (char *)Base, mlen, SM_READ);
+ }
+ if (p == NULL) {
+ xf86Msg(X_WARNING, "xf86ReadBios: Failed to smem_create "
+ "Base %x len %x %s \n",
+ Base, mlen, strerror(errno));
+ return(-1);
+ }
+ }
+ memcpy(Buf, p + Offset, Len);
+ smem_create(NULL, p, 0, SM_DETACH);
+ smem_remove("BIOS-probe");
+ return(Len);
+#endif
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mouse.c
new file mode 100644
index 000000000..68aca5d38
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mouse.c
@@ -0,0 +1,34 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mouse.c,v 1.1 1999/05/22 08:40:14 dawes Exp $ */
+
+/*
+ * Copyright 1999 by The XFree86 Project, Inc.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+
+static int
+SupportedInterfaces(void)
+{
+ /* XXX Need to check this. */
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_AUTO;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+ return p;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_noinline.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_noinline.c
new file mode 100644
index 000000000..1c12f62f9
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_noinline.c
@@ -0,0 +1,178 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_noinline.c,v 3.5 2000/07/31 23:25:18 tsi Exp $ */
+/*
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#if /* NO_INLINE && */ defined(__powerpc__)
+
+#include "xf86Pci.h"
+
+extern volatile unsigned char *ioBase;
+
+void
+eieio()
+{
+ __asm__ __volatile__ ("eieio");
+}
+
+unsigned long
+ldl_brx(volatile unsigned char *base, int ndx)
+{
+ register unsigned long tmp = *(volatile unsigned long *)(base+ndx);
+ return( ((tmp & 0x000000ff) << 24) |
+ ((tmp & 0x0000ff00) << 8) |
+ ((tmp & 0x00ff0000) >> 8) |
+ ((tmp & 0xff000000) >> 24) );
+}
+
+unsigned short
+ldw_brx(volatile unsigned char *base, int ndx)
+{
+ register unsigned short tmp = *(volatile unsigned short *)(base+ndx);
+ return((tmp << 8) | (tmp >> 8));
+}
+
+void
+stl_brx(unsigned long val, volatile unsigned char *base, int ndx)
+{
+ unsigned char *p = (unsigned char *)&val;
+ unsigned long tmp = (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0);
+ *(volatile unsigned long *)(base+ndx) = tmp;
+}
+
+void
+stw_brx(unsigned short val, volatile unsigned char *base, int ndx)
+{
+ unsigned char *p = (unsigned char *)&val;
+ unsigned short tmp = (p[1] << 8) | p[0];
+ *(volatile unsigned short *)(base+ndx) = tmp;
+}
+
+void
+outb(IOADDRESS port, unsigned char value)
+{
+ *((volatile unsigned char *)(ioBase + port)) = value; eieio();
+}
+
+void
+outw(IOADDRESS port, unsigned short value)
+{
+ stw_brx(value, ioBase, port); eieio();
+}
+
+void
+outl(IOADDRESS port, unsigned int value)
+{
+ stl_brx(value, ioBase, port); eieio();
+}
+
+unsigned char
+inb(IOADDRESS port)
+{
+ unsigned char val;
+
+ val = *((volatile unsigned char *)(ioBase + port)); eieio();
+ return(val);
+}
+
+unsigned short
+inw(IOADDRESS port)
+{
+ unsigned short val;
+
+ val = ldw_brx(ioBase, port); eieio();
+ return(val);
+}
+
+unsigned int
+inl(IOADDRESS port)
+{
+ unsigned int val;
+
+ val = ldl_brx(ioBase, port); eieio();
+ return(val);
+}
+
+unsigned long
+ldl_u(void *p)
+{
+ return (((*(unsigned char *)(p)) |
+ (*((unsigned char *)(p)+1)<<8) |
+ (*((unsigned char *)(p)+2)<<16) |
+ (*((unsigned char *)(p)+3)<<24)));
+}
+
+unsigned long
+ldq_u(void *p)
+{
+ return ldl_u(p);
+}
+
+unsigned short
+ldw_u(void *p)
+{
+ return(((*(unsigned char *)(p)) |
+ (*((unsigned char *)(p)+1)<<8)));
+}
+
+void
+stl_u(unsigned long v, void *p)
+{
+
+ (*(unsigned char *)(p)) = (v);
+ (*((unsigned char *)(p)+1)) = ((v) >> 8);
+ (*((unsigned char *)(p)+2)) = ((v) >> 16);
+ (*((unsigned char *)(p)+3)) = ((v) >> 24);
+}
+
+void
+stq_u(unsigned long v, void *p)
+{
+ stl_u(v,p);
+}
+
+void
+stw_u(unsigned short v, void *p)
+{
+ (*(unsigned char *)(p)) = (v);
+ (*((unsigned char *)(p)+1)) = ((v) >> 8);
+}
+
+
+void
+mem_barrier(void)
+{
+ __asm__ __volatile__("eieio");
+}
+
+void
+write_mem_barrier(void)
+{
+ __asm__ __volatile__("eieio");
+}
+
+#endif /* NO_INLINE && __powerpc__ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.S b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.S
new file mode 100644
index 000000000..3865850d1
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.S
@@ -0,0 +1,70 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.S,v 1.1 1999/07/10 07:24:49 dawes Exp $ */
+/*
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+ .file "ppc.s"
+.toc
+ .csect .text[PR]
+ .balign 4
+ .globl ppc_flush_icache
+ .globl .ppc_flush_icache
+.csect ppc_flush_icache[DS]
+ppc_flush_icache:
+ .long .ppc_flush_icache, TOC[tc0], 0
+.csect .text[PR]
+.ppc_flush_icache:
+ mflr 0
+ stw 31,-4(1)
+ stw 0,8(1)
+ stwu 1,-64(1)
+ mr 31,1
+ stw 3,88(31)
+ li 6, 0 /* __inst_dcbf (addr, 0); */
+ dcbf 3, 6
+ li 5, 32 /* __inst_dcbf (addr, LINESIZE); */
+ dcbf 3, 5
+ sync /* __inst_sync (); */
+ li 4,0 /* __inst_icbi (addr, 0); */
+ icbi 3,4
+ li 7,32 /* __inst_icbi (addr, LINESIZE); */
+ icbi 3,7
+ sync /* __inst_sync (); */
+ isync /* __inst_isync (); */
+L..1:
+ lwz 1,0(1)
+ lwz 0,8(1)
+ mtlr 0
+ lwz 31,-4(1)
+ blr
+LT..ppc_flush_icache:
+ .long 0
+ .byte 0,0,32,97,128,1,1,1
+ .long 0
+ .long LT..ppc_flush_icache-.ppc_flush_icache
+ .short 16
+ .byte "ppc_flush_icache"
+ .byte 31
+_section_.text:
+ .csect .data[RW]
+ .long _section_.text
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.c
new file mode 100644
index 000000000..12fa3bcae
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.c
@@ -0,0 +1,52 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_ppc.S,v 1.1 1999/07/10 07:24:49 dawes Exp $ */
+/*
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+void ppc_flush_icache()
+{
+__asm__ __volatile__ (" \
+ mflr 0 ;\
+ stw 31,-4(1) ;\
+ stw 0,8(1) ;\
+ stwu 1,-64(1) ;\
+ mr 31,1 ;\
+ stw 3,88(31) ;\
+ li 6, 0 ;\
+ dcbf 3, 6 ;\
+ li 5, 32 ;\
+ dcbf 3, 5 ;\
+ sync ;\
+ li 4,0 ;\
+ icbi 3,4 ;\
+ li 7,32 ;\
+ icbi 3,7 ;\
+ sync ;\
+ isync ;\
+ lwz 1,0(1) ;\
+ lwz 0,8(1) ;\
+ mtlr 0 ;\
+ lwz 31,-4(1) ;\
+ blr ;\
+");
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c
new file mode 100644
index 000000000..5d0949091
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c
@@ -0,0 +1,711 @@
+/*
+ * Copyright 1993 by Thomas Mueller
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Mueller not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Mueller makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS MUELLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS MUELLER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_video.c,v 3.17 2000/10/28 01:42:27 mvojkovi Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#if defined(__powerpc__)
+
+# if defined(USE_MACHINE_ABSOLUTE)
+# include <machine/absolute.h>
+# else
+# define __USER_SPACE_INCLUDE
+# include <hw_absolute.h>
+# endif
+
+void ppcPciIoMap(int bus);
+#endif
+
+#if 0
+#define DEBUG
+#endif
+
+#ifdef HAS_MTRR_SUPPORT
+#include <sys/memrange.h>
+#define X_MTRR_ID "XFree86"
+
+static pointer setWC(int, unsigned long, unsigned long, Bool, MessageType);
+static void undoWC(int, pointer);
+static Bool cleanMTRR(void);
+static int devMemFd = -1;
+#define MTRR_DEVICE "/dev/mtrr"
+#endif
+
+
+#if !defined(NO_MMAP)
+#include <sys/mman.h>
+
+int smem_remove(char *name)
+{
+ return(0);
+}
+
+char *smem_create(char *name, char *arg_addr, long size, int mode)
+{
+ int fd;
+ void *addr = 0;
+ char *retval;
+ size_t len = size;
+ int prot = PROT_READ|PROT_WRITE|PROT_UNCACHE;
+ int flags = MAP_SHARED;
+ off_t off = (off_t)arg_addr;
+
+ if ((fd = open("/dev/mem" , O_RDWR)) < 0)
+ {
+ retval = (char *)-1;
+ }
+ else
+ {
+ if (mode == SM_DETACH)
+ {
+ munmap(arg_addr, len);
+ retval = 0;
+ }
+ else
+ {
+ if ((retval = mmap (addr, len, prot, flags, fd, off) ) == MAP_FAILED)
+ {
+ retval = (char *)-1;
+ }
+ }
+
+ close(fd);
+ }
+
+ return(retval);
+}
+
+#endif
+
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+typedef struct
+{
+ char name[16];
+ unsigned long Base;
+ unsigned long Size;
+ char *ptr;
+ int RefCnt;
+}
+_SMEMS;
+
+#define MAX_SMEMS 16
+
+static _SMEMS smems[MAX_SMEMS];
+
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+static void
+smemCleanup(void)
+{
+ int i;
+
+ for (i = 0; i < MAX_SMEMS; i++) {
+ if (*smems[i].name && smems[i].ptr) {
+ (void)smem_create(NULL, smems[i].ptr, 0, SM_DETACH);
+ (void)smem_remove(smems[i].name);
+ *smems[i].name = '\0';
+ smems[i].ptr = NULL;
+ smems[i].Base = 0;
+ smems[i].Size = 0;
+ smems[i].RefCnt = 0;
+ }
+ }
+}
+
+static pointer
+MapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ static int once;
+ int free_slot = -1;
+ int i;
+
+ if (!once)
+ {
+ atexit(smemCleanup);
+ once = 1;
+ }
+ for (i = 0; i < MAX_SMEMS; i++)
+ {
+ if (!*smems[i].name && free_slot == -1)
+ free_slot = i;
+ if (smems[i].Base == Base && smems[i].Size == Size
+ && *smems[i].name) {
+ smems[i].RefCnt++;
+ return smems[i].ptr;
+ }
+ }
+ if (i == MAX_SMEMS && free_slot == -1)
+ {
+ FatalError("MapVidMem: failed to smem_create Base %x Size %x (out of SMEMS entries)\n",
+ Base, Size);
+ }
+
+ i = free_slot;
+ sprintf(smems[i].name, "Video-%d", i);
+ smems[i].Base = Base;
+ smems[i].Size = Size;
+
+ xf86MsgVerb(X_INFO, 3, "MapVidMem: Base=0x%x Size=0x%x\n",
+ Base, Size);
+
+#if defined(__powerpc__)
+ if (((unsigned long)Base & PHYS_IO_MEM_START) != PHYS_IO_MEM_START) {
+ Base = Base | PHYS_IO_MEM_START;
+ }
+#endif
+
+ smems[i].ptr = smem_create(smems[i].name, (char *)Base, Size, SM_READ|SM_WRITE);
+ smems[i].RefCnt = 1;
+ if (smems[i].ptr == NULL)
+ {
+ /* check if there is a stale segment around */
+ if (smem_remove(smems[i].name) == 0) {
+ xf86Msg(X_INFO,
+ "MapVidMem: removed stale smem_ segment %s\n",
+ smems[i].name);
+ smems[i].ptr = smem_create(smems[i].name,
+ (char *)Base, Size, SM_READ|SM_WRITE);
+ }
+ if (smems[i].ptr == NULL) {
+ *smems[i].name = '\0';
+ FatalError("MapVidMem: failed to smem_create Base %x Size %x (%s)\n",
+ Base, Size, strerror(errno));
+ }
+ }
+ xf86MsgVerb(X_INFO, 3, "MapVidMem: Base=0x%x Size=0x%x Ptr=0x%x\n",
+ Base, Size, smems[i].ptr);
+ return smems[i].ptr;
+}
+
+static void
+UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ int i;
+
+ xf86MsgVerb(X_INFO, 3, "UnMapVidMem: Base/Ptr=0x%x Size=0x%x\n",
+ Base, Size);
+ for (i = 0; i < MAX_SMEMS; i++)
+ {
+ if (*smems[i].name && smems[i].ptr == Base
+ && smems[i].Size == Size)
+ {
+ if (--smems[i].RefCnt > 0)
+ return;
+
+ (void)smem_create(NULL, smems[i].ptr, 0, SM_DETACH);
+ xf86MsgVerb(X_INFO, 3,
+ "UnMapVidMem: smem_create(%s, 0x%08x, ... "
+ "SM_DETACH)\n", smems[i].name, smems[i].ptr);
+ (void)smem_remove(smems[i].name);
+ *smems[i].name = '\0';
+ smems[i].RefCnt = 0;
+ return;
+ }
+ }
+ xf86MsgVerb(X_WARNING, 2,
+ "UnMapVidMem: no SMEM found for Base = %lx Size = %lx\n",
+ Base, Size);
+}
+
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ pVidMem->linearSupported = TRUE;
+ pVidMem->mapMem = MapVidMem;
+ pVidMem->unmapMem = UnMapVidMem;
+ pVidMem->setWC = 0;
+ pVidMem->undoWC = 0;
+#ifdef HAS_MTRR_SUPPORT
+ if (cleanMTRR()) {
+ pVidMem->setWC = setWC;
+ pVidMem->undoWC = undoWC;
+ }
+#endif
+ pVidMem->initialised = TRUE;
+}
+
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts()
+{
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+ return;
+}
+
+/***************************************************************************/
+/* I/O Permissions section for PowerPC */
+/***************************************************************************/
+
+#if defined(__powerpc__)
+
+volatile unsigned char *ioBase = MAP_FAILED;
+volatile unsigned char *pciConfBase = MAP_FAILED;
+
+static int IOEnabled;
+
+
+static void
+removeIOSmem(void)
+{
+ smem_create(NULL, (char *) ioBase, 0, SM_DETACH);
+ smem_remove("IOBASE");
+ ioBase = MAP_FAILED;
+}
+
+Bool
+xf86EnableIO()
+{
+ if (IOEnabled++ == 0) {
+ ioBase = (unsigned char *) smem_create("IOBASE",
+ (char *)PHYS_ISA_IO_SPACE, 64*1024, SM_READ|SM_WRITE);
+ if (ioBase == MAP_FAILED) {
+ --IOEnabled;
+ xf86Msg(X_WARNING,"xf86EnableIO: Failed to map I/O\n");
+ return FALSE;
+ } else {
+#ifdef DEBUG
+ ErrorF("xf86EnableIO: mapped I/O at vaddr 0x%08x\n",
+ ioBase);
+#endif
+ atexit(removeIOSmem);
+ }
+ }
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ if (!IOEnabled)
+ return;
+
+ if (--IOEnabled == 0)
+ removeIOSmem();
+ return;
+}
+
+#if 0
+void
+xf86DisableIOPrivs(void)
+{
+ return;
+}
+#endif
+void
+ppcPciIoMap(int bus)
+{
+ xf86EnableIO();
+}
+
+#endif
+
+
+#ifdef HAS_MTRR_SUPPORT
+/* memory range (MTRR) support for LynxOS (taken from BSD MTRR support) */
+
+/*
+ * This code is experimental. Some parts may be overkill, and other parts
+ * may be incomplete.
+ */
+
+/*
+ * getAllRanges returns the full list of memory ranges with attributes set.
+ */
+
+static struct mem_range_desc *
+getAllRanges(int *nmr)
+{
+ struct mem_range_desc *mrd;
+ struct mem_range_op mro;
+
+ /*
+ * Find how many ranges there are. If this fails, then the kernel
+ * probably doesn't have MTRR support.
+ */
+ mro.mo_arg[0] = 0;
+ if (ioctl(devMemFd, MEMRANGE_GET, &mro))
+ return NULL;
+ *nmr = mro.mo_arg[0];
+ mrd = xnfalloc(*nmr * sizeof(struct mem_range_desc));
+ mro.mo_arg[0] = *nmr;
+ mro.mo_desc = mrd;
+ if (ioctl(devMemFd, MEMRANGE_GET, &mro)) {
+ xfree(mrd);
+ return NULL;
+ }
+ return mrd;
+}
+
+/*
+ * cleanMTRR removes any memory attribute that may be left by a previous
+ * X server. Normally there won't be any, but this takes care of the
+ * case where a server crashed without being able finish cleaning up.
+ */
+
+static Bool
+cleanMTRR()
+{
+ struct mem_range_desc *mrd;
+ struct mem_range_op mro;
+ int nmr, i;
+
+ /* This shouldn't happen */
+ if (devMemFd < 0) {
+ if ((devMemFd = open(MTRR_DEVICE, O_RDONLY)) < 0) {
+perror("open MTRR");
+ return FALSE;
+ }
+ }
+
+ if (!(mrd = getAllRanges(&nmr)))
+ return FALSE;
+
+ for (i = 0; i < nmr; i++) {
+ if (strcmp(mrd[i].mr_owner, X_MTRR_ID) == 0 &&
+ (mrd[i].mr_flags & MDF_ACTIVE)) {
+#ifdef DEBUG
+ ErrorF("Clean for (0x%lx,0x%lx)\n",
+ (unsigned long)mrd[i].mr_base,
+ (unsigned long)mrd[i].mr_len);
+#endif
+ if (mrd[i].mr_flags & MDF_FIXACTIVE) {
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ mrd[i].mr_flags = MDF_UNCACHEABLE;
+ } else {
+ mro.mo_arg[0] = MEMRANGE_SET_REMOVE;
+ }
+ mro.mo_desc = mrd + i;
+ ioctl(devMemFd, MEMRANGE_SET, &mro);
+ }
+ }
+#ifdef DEBUG
+ sleep(10);
+#endif
+ xfree(mrd);
+ return TRUE;
+}
+
+typedef struct x_RangeRec {
+ struct mem_range_desc mrd;
+ Bool wasWC;
+ struct x_RangeRec * next;
+} RangeRec, *RangePtr;
+
+static void
+freeRangeList(RangePtr range)
+{
+ RangePtr rp;
+
+ while (range) {
+ rp = range;
+ range = rp->next;
+ xfree(rp);
+ }
+}
+
+static RangePtr
+dupRangeList(RangePtr list)
+{
+ RangePtr new = NULL, rp, p;
+
+ rp = list;
+ while (rp) {
+ p = xnfalloc(sizeof(RangeRec));
+ *p = *rp;
+ p->next = new;
+ new = p;
+ rp = rp->next;
+ }
+ return new;
+}
+
+static RangePtr
+sortRangeList(RangePtr list)
+{
+ RangePtr rp1, rp2, copy, sorted = NULL, minp, prev, minprev;
+ unsigned long minBase;
+
+ /* Sort by base address */
+ rp1 = copy = dupRangeList(list);
+ while (rp1) {
+ minBase = rp1->mrd.mr_base;
+ minp = rp1;
+ minprev = NULL;
+ prev = rp1;
+ rp2 = rp1->next;
+ while (rp2) {
+ if (rp2->mrd.mr_base < minBase) {
+ minBase = rp2->mrd.mr_base;
+ minp = rp2;
+ minprev = prev;
+ }
+ prev = rp2;
+ rp2 = rp2->next;
+ }
+ if (minprev) {
+ minprev->next = minp->next;
+ rp1 = copy;
+ } else {
+ rp1 = minp->next;
+ }
+ minp->next = sorted;
+ sorted = minp;
+ }
+ return sorted;
+}
+
+/*
+ * findRanges returns a list of ranges that overlap the specified range.
+ */
+
+static void
+findRanges(unsigned long base, unsigned long size, RangePtr *ucp, RangePtr *wcp)
+{
+ struct mem_range_desc *mrd;
+ int nmr, i;
+ RangePtr rp, *p;
+
+ if (!(mrd = getAllRanges(&nmr)))
+ return;
+
+ for (i = 0; i < nmr; i++) {
+ if ((mrd[i].mr_flags & MDF_ACTIVE) &&
+ mrd[i].mr_base < base + size &&
+ mrd[i].mr_base + mrd[i].mr_len > base) {
+ if (mrd[i].mr_flags & MDF_WRITECOMBINE)
+ p = wcp;
+ else if (mrd[i].mr_flags & MDF_UNCACHEABLE)
+ p = ucp;
+ else
+ continue;
+ rp = xnfalloc(sizeof(RangeRec));
+ rp->mrd = mrd[i];
+ rp->next = *p;
+ *p = rp;
+ }
+ }
+ xfree(mrd);
+}
+
+/*
+ * This checks if the existing overlapping ranges fully cover the requested
+ * range. Is this overkill?
+ */
+
+static Bool
+fullCoverage(unsigned long base, unsigned long size, RangePtr overlap)
+{
+ RangePtr rp1, sorted = NULL;
+ unsigned long end;
+
+ sorted = sortRangeList(overlap);
+ /* Look for gaps */
+ rp1 = sorted;
+ end = base + size;
+ while (rp1) {
+ if (rp1->mrd.mr_base > base) {
+ freeRangeList(sorted);
+ return FALSE;
+ } else {
+ base = rp1->mrd.mr_base + rp1->mrd.mr_len;
+ }
+ if (base >= end) {
+ freeRangeList(sorted);
+ return TRUE;
+ }
+ rp1 = rp1->next;
+ }
+ freeRangeList(sorted);
+ return FALSE;
+}
+
+static pointer
+addWC(int screenNum, unsigned long base, unsigned long size, MessageType from)
+{
+ RangePtr uc = NULL, wc = NULL, retlist = NULL;
+ struct mem_range_desc mrd;
+ struct mem_range_op mro;
+
+ findRanges(base, size, &uc, &wc);
+
+ /* See of the full range is already WC */
+ if (!uc && fullCoverage(base, size, wc)) {
+ xf86DrvMsg(screenNum, from,
+ "Write-combining range (0x%lx,0x%lx) was already set\n",
+ base, size);
+ return NULL;
+ }
+
+ /* Otherwise, try to add the new range */
+ mrd.mr_base = base;
+ mrd.mr_len = size;
+ strcpy(mrd.mr_owner, X_MTRR_ID);
+ mrd.mr_flags = MDF_WRITECOMBINE;
+ mro.mo_desc = &mrd;
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "Failed to set write-combining range "
+ "(0x%lx,0x%lx)\n", base, size);
+ return NULL;
+ } else {
+ xf86DrvMsg(screenNum, from,
+ "Write-combining range (0x%lx,0x%lx)\n", base, size);
+ retlist = xnfalloc(sizeof(RangeRec));
+ retlist->mrd = mrd;
+ retlist->wasWC = FALSE;
+ retlist->next = NULL;
+ return retlist;
+ }
+}
+
+static pointer
+delWC(int screenNum, unsigned long base, unsigned long size, MessageType from)
+{
+ RangePtr uc = NULL, wc = NULL, retlist = NULL;
+ struct mem_range_desc mrd;
+ struct mem_range_op mro;
+
+ findRanges(base, size, &uc, &wc);
+
+ /*
+ * See of the full range is already not WC, or if there is full
+ * coverage from UC ranges.
+ */
+ if (!wc || fullCoverage(base, size, uc)) {
+ xf86DrvMsg(screenNum, from,
+ "Write-combining range (0x%lx,0x%lx) was already clear\n",
+ base, size);
+ return NULL;
+ }
+
+ /* Otherwise, try to add the new range */
+ mrd.mr_base = base;
+ mrd.mr_len = size;
+ strcpy(mrd.mr_owner, X_MTRR_ID);
+ mrd.mr_flags = MDF_UNCACHEABLE;
+ mro.mo_desc = &mrd;
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "Failed to remove write-combining range "
+ "(0x%lx,0x%lx)\n", base, size);
+ /* XXX Should then remove all of the overlapping WC ranges */
+ return NULL;
+ } else {
+ xf86DrvMsg(screenNum, from,
+ "Removed Write-combining range (0x%lx,0x%lx)\n",
+ base, size);
+ retlist = xnfalloc(sizeof(RangeRec));
+ retlist->mrd = mrd;
+ retlist->wasWC = TRUE;
+ retlist->next = NULL;
+ return retlist;
+ }
+}
+
+static pointer
+setWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
+ MessageType from)
+{
+ if (enable)
+ return addWC(screenNum, base, size, from);
+ else
+ return delWC(screenNum, base, size, from);
+}
+
+static void
+undoWC(int screenNum, pointer list)
+{
+ RangePtr rp;
+ struct mem_range_op mro;
+ Bool failed;
+
+ rp = list;
+ while (rp) {
+#ifdef DEBUG
+ ErrorF("Undo for (0x%lx,0x%lx), %d\n",
+ (unsigned long)rp->mrd.mr_base,
+ (unsigned long)rp->mrd.mr_len, rp->wasWC);
+#endif
+ failed = FALSE;
+ if (rp->wasWC) {
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ rp->mrd.mr_flags = MDF_WRITECOMBINE;
+ strcpy(rp->mrd.mr_owner, "unknown");
+ } else {
+ mro.mo_arg[0] = MEMRANGE_SET_REMOVE;
+ }
+ mro.mo_desc = &rp->mrd;
+
+ if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
+ if (!rp->wasWC) {
+ mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+ rp->mrd.mr_flags = MDF_UNCACHEABLE;
+ strcpy(rp->mrd.mr_owner, "unknown");
+ if (ioctl(devMemFd, MEMRANGE_SET, &mro))
+ failed = TRUE;
+ } else
+ failed = TRUE;
+ }
+ if (failed) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "Failed to restore MTRR range (0x%lx,0x%lx)\n",
+ (unsigned long)rp->mrd.mr_base,
+ (unsigned long)rp->mrd.mr_len);
+ }
+ rp = rp->next;
+ }
+}
+
+#endif /* HAS_MTRR_SUPPORT */
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.S b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.S
new file mode 100644
index 000000000..373723c7d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.S
@@ -0,0 +1,153 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.s,v 1.2 1998/07/25 16:56:49 dawes Exp $ */
+/******************************************************************************
+ Copyright 1993 by Glenn G. Lai
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Glenn G. Lai not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+Glenn G. Lai DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+Glenn G. Lai
+P.O. Box 4314
+Austin, Tx 78765
+(glenn@cs.utexas.edu)
+8/9/93
+******************************************************************************/
+/* $XConsortium: BUSmemcpy.s /main/4 1996/02/21 17:39:34 kaleb $ */
+
+/*
+ * Modified to use long-alignment of video memory rather than word-alignment
+ * to improve performance for LocalBus video cards. Function names changed
+ * from ISAToMem and MemToISA to BusToMem and MemToBus.
+ *
+ * David Dawes <dawes@XFree86.org>, 25 August 1993.
+ */
+
+
+#include "assyntax.h"
+
+ FILE("BUSmemcpy.s")
+
+ AS_BEGIN
+
+/* BusToMem copies from video memory to main memory
+ MemToBus copies from main memory to video memory
+
+ void xf86BusToMem(unsigned char *dst, unsigned char *src, int len);
+ void xf86MemToBus(unsigned char *dst, unsigned char *src, int len);
+*/
+
+#define dst REGOFF(4,ESP)
+#define src REGOFF(8,ESP)
+#define len REGOFF(12,ESP)
+
+ GLOBL GLNAME(xf86BusToMem)
+ GLOBL GLNAME(xf86MemToBus)
+
+ SEG_DATA
+copyright:
+ STRING("Copyright 8/9/1993 by Glenn G. Lai")
+
+ SEG_TEXT
+ ALIGNTEXT4
+GLNAME(xf86BusToMem):
+ CLD
+ PUSH_L (ESI)
+ MOV_L (EDI, EDX)
+
+ MOV_L (src, ESI)
+ MOV_L (dst, EDI)
+ MOV_L (len, ECX)
+
+ CMP_L (CONST(7), ECX)
+ JC (quickBM)
+
+ TEST_L (CONST(1), ESI)
+ JZ (BwM)
+
+ MOVS_B
+ DEC_L (ECX)
+
+BwM:
+ TEST_L (CONST(2), ESI)
+ JZ (BlM)
+
+ MOVS_W
+ DEC_L (ECX)
+ DEC_L (ECX)
+
+BlM:
+ MOV_L (ECX, EAX)
+ AND_L (CONST(3), EAX)
+ SHR_L (CONST(2), ECX)
+ REP
+ MOVS_L
+ MOV_L (EAX, ECX)
+quickBM:
+ OR_L (ECX, ECX)
+ JZ (return)
+ REP
+ MOVS_B
+return:
+ POP_L (ESI)
+ MOV_L (EDX, EDI)
+ RET
+/************************/
+
+ ALIGNTEXT4
+GLNAME(xf86MemToBus):
+ CLD
+ PUSH_L (ESI)
+ MOV_L (EDI, EDX)
+
+ MOV_L (src, ESI)
+ MOV_L (dst, EDI)
+ MOV_L (len, ECX)
+
+ CMP_L (CONST(7), ECX)
+ JC (quickMB)
+
+ TEST_L (CONST(1), EDI)
+ JZ (MwB)
+
+ MOVS_B
+ DEC_L (ECX)
+
+MwB:
+ TEST_L (CONST(2), EDI)
+ JZ (MlB)
+
+ MOVS_W
+ DEC_L (ECX)
+ DEC_L (ECX)
+
+MlB:
+ MOV_L (ECX, EAX)
+ AND_L (CONST(3), EAX)
+ SHR_L (CONST(2), ECX)
+ REP
+ MOVS_L
+ MOV_L (EAX, ECX)
+quickMB:
+ OR_L (ECX, ECX)
+ JZ (return)
+ REP
+ MOVS_B
+
+ POP_L (ESI)
+ MOV_L (EDX, EDI)
+ RET
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.c
new file mode 100644
index 000000000..9ff14396c
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.c
@@ -0,0 +1,413 @@
+
+/****************************************************************************
+
+ For Alpha Linux, BusToMem() and MemToBus() can be simply memcpy(), BUT:
+ we need to prevent unaligned operations when accessing DENSE space on the BUS,
+ as the video memory is mmap'd that way. The below code does this.
+
+NOTE: we could simply use the "memcpy()" from LIBC here, but that, currently, is
+ not as fast.
+
+Thanks to Linus Torvalds for contributing this code.
+
+****************************************************************************/
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/BUSmemcpy.c,v 1.3 1999/12/03 19:17:44 eich Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#ifdef __alpha__
+
+#include "compiler.h"
+
+/*
+ * The Jensen lacks dense memory, thus we have to address the bus via
+ * the sparse addressing scheme. These routines are only used in s3im.c
+ * Non time critical code uses SlowBCopy_{from/to} bus.
+ *
+ * Martin Ostermann (ost@comnets.rwth-aachen.de) - Apr.-Sep. 1996
+ */
+
+#ifdef TEST_JENSEN_CODE /* define to test the Sparse addressing on a non-Jensen */
+#define LWORD_CODING (0x18)
+#define SPARSE (5)
+#else
+#define LWORD_CODING (0x60)
+#define SPARSE (7)
+#endif
+
+void
+xf86JensenMemToBus(char *Base, long dst, long src, int count)
+{
+ if( ((long)src^((long)dst)) & 3) {
+ /* src & dst are NOT aligned to each other */
+ unsigned long addr;
+ unsigned long low_word, high_word,last_read;
+ long rm,loop;
+ unsigned long tmp,org,org2,mask,src_org,count_org;
+
+ src_org=src;
+ count_org=count;
+
+ /* add EISA longword coding and round off*/
+ addr = (long)(Base+(dst<<SPARSE) + LWORD_CODING) & ~(3<<SPARSE);
+ rm = (long)dst & 3;
+ count += rm;
+
+ count = count_org + rm;
+ org = *(volatile unsigned int *)addr;
+ __asm__("ldq_u %0,%1"
+ :"=r" (low_word):"m" (*(unsigned long *)(src_org)));
+ src = src_org - rm;
+ if( count > 4 ) {
+ last_read = src_org+count_org - 1;
+ __asm__("ldq_u %0,%1"
+ :"=r" (high_word):"m" (*(unsigned long *)(src+4)));
+ __asm__("extll %1,%2,%0"
+ :"=r" (low_word)
+ :"r" (low_word), "r" ((unsigned long)(src)));
+ __asm__("extlh %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (high_word), "r" ((unsigned long)(src)));
+ tmp |= low_word;
+ src += 4;
+ __asm__("mskqh %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (tmp), "r" (rm));
+ __asm__("mskql %1,%2,%0"
+ :"=r" (org2)
+ :"r" (org), "r" (rm));
+ tmp |= org2;
+
+ loop = (count-4) >> 2; /* loop eqv. count>=4 ; count -= 4 */
+ while (loop) {
+ /* tmp to be stored completly -- need to read next word*/
+ low_word = high_word;
+ *(volatile unsigned int *) (addr) = tmp;
+ __asm__("ldq_u %0,%1"
+ :"=r" (high_word):"m" (*(unsigned long*)(src+4)));
+ loop --;
+ __asm__("extll %1,%2,%0"
+ :"=r" (low_word)
+ :"r" (low_word), "r" ((unsigned long)src));
+ __asm__("extlh %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (high_word), "r" ((unsigned long)src));
+ src += 4;
+ tmp |= low_word;
+ addr += 4<<SPARSE;
+ }
+ if ( count & 3 ) {
+ /* Store tmp completly, and possibly read one more word.*/
+ *(volatile unsigned int *) (addr) = tmp;
+ __asm__("ldq_u %0,%1"
+ :"=r" (tmp):"m" (*((unsigned long *)(last_read)) ));
+ addr += 4<<SPARSE;
+ __asm__("extll %1,%2,%0"
+ :"=r" (low_word)
+ :"r" (high_word), "r" ((unsigned long)src));
+ __asm__("extlh %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (tmp), "r" ((unsigned long)src));
+ tmp |= low_word;
+ org = *(volatile unsigned int *)addr;
+
+ __asm__("mskql %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (tmp), "r" (count&3));
+ __asm__("mskqh %1,%2,%0"
+ :"=r" (org)
+ :"r" (org), "r" (count&3));
+
+ tmp |= org;
+ }
+ *(volatile unsigned int *) (addr) = tmp;
+ return;
+ } else { /* count > 4 */
+ __asm__("ldq_u %0,%1"
+ :"=r" (high_word):"m" (*(unsigned long *)(src+4)));
+ __asm__("extll %1,%2,%0"
+ :"=r" (low_word)
+ :"r" (low_word), "r" ((unsigned long)(src)));
+ __asm__("extlh %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (high_word), "r" ((unsigned long)(src)));
+ tmp |= low_word;
+ if( count < 4 ) {
+
+ mask = -1;
+ __asm__("mskqh %1,%2,%0"
+ :"=r" (mask)
+ :"r" (mask), "r" (rm));
+ __asm__("mskql %1,%2,%0"
+ :"=r" (mask)
+ :"r" (mask), "r" (count));
+ tmp = (tmp & mask) | (org & ~mask);
+ *(volatile unsigned int *) (addr) = tmp;
+ return;
+ } else {
+ __asm__("mskqh %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (tmp), "r" (rm));
+ __asm__("mskql %1,%2,%0"
+ :"=r" (org2)
+ :"r" (org), "r" (rm));
+
+ tmp |= org2;
+ *(volatile unsigned int *) (addr) = tmp;
+ return;
+ }
+ }
+ } else { /* src & dst are aligned to each other */
+ unsigned long addr;
+ unsigned int tmp,org,rm;
+ unsigned int *src_r;
+
+ /* add EISA longword coding and round off*/
+ addr = (long)(Base+(dst<<SPARSE) + LWORD_CODING) & ~(3<<SPARSE);
+
+ src_r = (unsigned int*)((long)src & ~3L);
+ rm=(long)src & 3;
+ count += rm;
+
+ tmp = *src_r;
+ org = *(volatile unsigned int *)addr;
+
+ __asm__("mskqh %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (tmp), "r" (rm));
+ __asm__("mskql %1,%2,%0"
+ :"=r" (org)
+ :"r" (org), "r" (rm));
+
+ tmp |= org;
+
+ while (count > 4) {
+ *(volatile unsigned int *) addr = tmp;
+ addr += 4<<SPARSE;
+ src_r += 1;
+ tmp = *src_r;
+ count -= 4;
+ }
+
+ org = *(volatile unsigned int *)addr;
+ __asm__("mskql %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (tmp), "r" (count));
+ __asm__("mskqh %1,%2,%0"
+ :"=r" (org)
+ :"r" (org), "r" (count));
+ tmp |= org;
+ *(volatile unsigned int *) (addr) = tmp;
+ }
+}
+
+void
+xf86JensenBusToMem(char *Base, char *dst, unsigned long src, int count)
+{
+#if 0
+ /* Optimization of BusToMem() is left as an exercise to the reader ;-)
+ * Consider that ldq_u/extlh/extll won't work because of the bus being
+ * only 4 bytes wide!
+ */
+#else
+ unsigned long addr;
+ long result;
+
+ addr = (unsigned long)(Base+(src<<SPARSE)) ;
+ while( addr & (3<<SPARSE) ){
+ if(count <= 0) return;
+ result = *(volatile int *) addr;
+ result >>= ((addr>>SPARSE) & 3) * 8;
+ *dst++ = (char) result;
+ addr += 1<<SPARSE;
+ count--;
+ }
+ count -=4;
+ while(count >= 0){
+ int i;
+
+ result = *(volatile int *) (addr+LWORD_CODING);
+ for(i=4;i--;) {
+ *dst++ = (char) result;
+ result >>= 8;
+ }
+ addr += 4<<SPARSE;
+ count -= 4;
+ }
+ count +=4;
+
+ while( count ){
+ result = *(volatile int *) addr;
+ result >>= ((addr>>SPARSE) & 3) * 8;
+ *dst++ = (char) result;
+ addr += 1<<SPARSE;
+ count--;
+ }
+#endif
+}
+
+
+static unsigned long __memcpy(unsigned long dest, unsigned long src, int n);
+
+void
+xf86BusToMem(unsigned char *dst, unsigned char *src, int len)
+{
+ __memcpy((unsigned long)dst, (unsigned long)src, len);
+}
+void
+xf86MemToBus(unsigned char *dst, unsigned char *src, int len)
+{
+ if (len == sizeof(int))
+ if (!(((long)src | (long)dst) & 3))
+ *((unsigned int*)dst) = *((unsigned int*)(src));
+ else {
+ int i;
+ if (((long)src) & 3)
+ i = ldl_u((unsigned int*)src);
+ else
+ i = *(unsigned int*)src;
+ if (((long)dst) & 3)
+ stl_u(i,(unsigned int*)dst);
+ else
+ *(unsigned int*)dst = i;
+ }
+ else
+ __memcpy((unsigned long)dst, (unsigned long)src, len);
+}
+
+/*
+ * linux/arch/alpha/lib/memcpy.c
+ *
+ * Copyright (C) 1995 Linus Torvalds, used with his permission.
+ */
+
+/*
+ * This is a reasonably optimized memcpy() routine.
+ */
+
+/*
+ * Note that the C code is written to be optimized into good assembly. However,
+ * at this point gcc is unable to sanely compile "if (n >= 0)", resulting in a
+ * explicit compare against 0 (instead of just using the proper "blt reg, xx" or
+ * "bge reg, xx"). I hope alpha-gcc will be fixed to notice this eventually..
+ */
+
+/*
+ * This should be done in one go with ldq_u*2/mask/stq_u. Do it
+ * with a macro so that we can fix it up later..
+ */
+#define ALIGN_DEST_TO8(d,s,n) \
+ while (d & 7) { \
+ if (n <= 0) return; \
+ n--; \
+ *(char *) d = *(char *) s; \
+ d++; s++; \
+ }
+
+/*
+ * This should similarly be done with ldq_u*2/mask/stq. The destination
+ * is aligned, but we don't fill in a full quad-word
+ */
+#define DO_REST(d,s,n) \
+ while (n > 0) { \
+ n--; \
+ *(char *) d = *(char *) s; \
+ d++; s++; \
+ }
+
+/*
+ * This should be done with ldq/mask/stq. The source and destination are
+ * aligned, but we don't fill in a full quad-word
+ */
+#define DO_REST_ALIGNED(d,s,n) DO_REST(d,s,n)
+
+/*
+ * This does unaligned memory copies. We want to avoid storing to
+ * an unaligned address, as that would do a read-modify-write cycle.
+ * We also want to avoid double-reading the unaligned reads.
+ *
+ * Note the ordering to try to avoid load (and address generation) latencies.
+ */
+static __inline__ void __memcpy_unaligned(unsigned long d, unsigned long s, long n)
+{
+ ALIGN_DEST_TO8(d,s,n);
+ n -= 8; /* to avoid compare against 8 in the loop */
+ if (n >= 0) {
+ unsigned long low_word, high_word;
+ __asm__("ldq_u %0,%1":"=r" (low_word):"m" (*(unsigned long *) s));
+ do {
+ unsigned long tmp;
+ __asm__("ldq_u %0,%1":"=r" (high_word):"m" (*(unsigned long *)(s+8)));
+ n -= 8;
+ __asm__("extql %1,%2,%0"
+ :"=r" (low_word)
+ :"r" (low_word), "r" (s));
+ __asm__("extqh %1,%2,%0"
+ :"=r" (tmp)
+ :"r" (high_word), "r" (s));
+ s += 8;
+ *(unsigned long *) d = low_word | tmp;
+ d += 8;
+ low_word = high_word;
+ } while (n >= 0);
+ }
+ n += 8;
+ DO_REST(d,s,n);
+}
+
+/*
+ * Hmm.. Strange. The __asm__ here is there to make gcc use a integer register
+ * for the load-store. I don't know why, but it would seem that using a floating
+ * point register for the move seems to slow things down (very small difference,
+ * though).
+ *
+ * Note the ordering to try to avoid load (and address generation) latencies.
+ */
+static __inline__ void __memcpy_aligned(unsigned long d, unsigned long s, long n)
+{
+ ALIGN_DEST_TO8(d,s,n);
+ n -= 8;
+ while (n >= 0) {
+ unsigned long tmp;
+ __asm__("ldq %0,%1":"=r" (tmp):"m" (*(unsigned long *) s));
+ n -= 8;
+ s += 8;
+ *(unsigned long *) d = tmp;
+ d += 8;
+ }
+ n += 8;
+ DO_REST_ALIGNED(d,s,n);
+}
+
+static unsigned long __memcpy(unsigned long dest, unsigned long src, int n)
+{
+ if (!((dest ^ src) & 7)) {
+ __memcpy_aligned(dest, src, n);
+ return dest;
+ }
+ __memcpy_unaligned(dest, src, n);
+ return dest;
+}
+
+#else /* __alpha__ */
+
+void
+xf86BusToMem(unsigned char *dst, unsigned char *src, int len)
+{
+ memcpy(dst, src, len);
+}
+void
+xf86MemToBus(unsigned char *dst, unsigned char *src, int len)
+{
+ memcpy(dst, src, len);
+}
+
+#endif /* __alpha__ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/Delay.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/Delay.c
new file mode 100644
index 000000000..33d0789fd
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/Delay.c
@@ -0,0 +1,44 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/Delay.c,v 3.3 2000/12/08 20:13:38 eich Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include <time.h>
+
+void
+xf86UDelay(long usec)
+{
+#if 0
+ struct timeval start, interrupt;
+#else
+ int sigio;
+
+ sigio = xf86BlockSIGIO();
+ xf86usleep(usec);
+ xf86UnblockSIGIO(sigio);
+#endif
+
+#if 0
+ gettimeofday(&start,NULL);
+
+ do {
+ usleep(usec);
+ gettimeofday(&interrupt,NULL);
+
+ if ((usec = usec - (interrupt.tv_sec - start.tv_sec) * 1000000
+ - (interrupt.tv_usec - start.tv_usec)) < 0)
+ break;
+ start = interrupt;
+ } while (1);
+#endif
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/IODelay.S b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/IODelay.S
new file mode 100644
index 000000000..685584653
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/IODelay.S
@@ -0,0 +1,53 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/IODelay.s,v 1.2 1998/07/25 16:56:49 dawes Exp $ */
+/*******************************************************************************
+ Copyright 1994 by Glenn G. Lai
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyr notice appear in all copies and that
+both that copyr notice and this permission notice appear in
+supporting documentation, and that the name of Glenn G. Lai not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+Glenn G. Lai DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+Glenn G. Lai
+P.O. Box 4314
+Austin, Tx 78765
+glenn@cs.utexas.edu)
+7/21/94
+*******************************************************************************/
+/* $XConsortium: IODelay.s /main/4 1996/02/21 17:40:21 kaleb $ */
+
+/*
+ * All we really need is a delay of about 40ns for I/O recovery for just
+ * about any occasion, but we'll be more conservative here: On a
+ * 100-MHz CPU, produce at least a delay of 1,000ns.
+ */
+
+#include "assyntax.h"
+
+ FILE("DACDelay.s")
+
+ AS_BEGIN
+
+ GLOBL GLNAME(xf86IODelay)
+
+ SEG_TEXT
+ ALIGNTEXT4
+GLNAME(xf86IODelay):
+ MOV_L (CONST(100), EAX)
+delay_it:
+ DEC_L (EAX)
+ JNE (delay_it)
+ RET
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/IODelay.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/IODelay.c
new file mode 100644
index 000000000..697c07f61
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/IODelay.c
@@ -0,0 +1,28 @@
+
+/* $XConsortium: IODelay.c /main/1 1996/05/07 17:13:43 kaleb $ */
+/*******************************************************************************
+ Stub for Alpha Linux
+*******************************************************************************/
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/IODelay.c,v 1.1.2.1 1998/06/04 17:35:59 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * All we really need is a delay of about 40ns for I/O recovery for just
+ * about any occasion, but we'll be more conservative here: On a
+ * 100-MHz CPU, produce at least a delay of 1,000ns.
+ */
+void
+xf86IODelay()
+{
+ xf86UDelay(1);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/Imakefile
new file mode 100644
index 000000000..d6122f52a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/Imakefile
@@ -0,0 +1,54 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/Imakefile,v 3.13 2003/12/30 15:21:06 herrb Exp $
+XCOMM $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/misc/Imakefile,v 1.2 2004/04/23 19:54:11 eich Exp $
+
+
+
+XCOMM $XConsortium: Imakefile /main/4 1996/09/28 17:24:12 rws $
+
+#include <Server.tmpl>
+
+
+#if defined(i386Architecture) && !defined(cygwinArchitecture) \
+ && !defined(OS2Architecture)
+XSRCS = BUSmemcpy.S IODelay.S SlowBcopy.S
+XOBJS = BUSmemcpy.o IODelay.o SlowBcopy.o
+#else
+XSRCS = BUSmemcpy.c IODelay.c SlowBcopy.c
+XOBJS = BUSmemcpy.o IODelay.o SlowBcopy.o
+#if defined(NetBSDArchitecture)
+BUSmemcpy.o: BUSmemcpy.c
+IODelay.o: IODelay.c
+SlowBcopy.o: SlowBcopy.c
+#endif
+#endif
+
+#if HasGcc || HasGcc2
+ILHACKSRCS = xf86_IlHack.c
+ILHACKOBJS = xf86_IlHack.o
+#elif NeedPortIO
+ILHACKOBJS = PortIO.o
+#endif
+
+SRCS = xf86_Util.c Delay.c $(ILHACKSRCS) $(XSRCS)
+
+OBJS = xf86_Util.o Delay.o $(ILHACKOBJS) $(XOBJS)
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+#if defined(i386Architecture) && !defined(cygwinArchitecture) \
+ && !defined(OS2Architecture)
+ObjectFromAsmSource(BUSmemcpy,NullParameter)
+ObjectFromAsmSource(IODelay,NullParameter)
+ObjectFromAsmSource(SlowBcopy,NullParameter)
+#endif
+
+#ifdef NeedPortIO
+ObjectFromAsmSource(PortIO,NullParameter)
+#endif
+
+DependTarget()
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/PortIO.S b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/PortIO.S
new file mode 100644
index 000000000..75db31156
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/PortIO.S
@@ -0,0 +1,57 @@
+/* $XFree86$ */
+
+/* Port I/O functions for platforms with no inlining. */
+
+#include "assyntax.h"
+
+ FILE("PortIO.s")
+
+ AS_BEGIN
+
+ GLOBL GLNAME(outb)
+ GLOBL GLNAME(outw)
+ GLOBL GLNAME(outl)
+ GLOBL GLNAME(inb)
+ GLOBL GLNAME(inw)
+ GLOBL GLNAME(inl)
+
+ SEG_TEXT
+ ALIGNTEXT4
+GLNAME(outb):
+ MOV_L (REGOFF(4,ESP), EDX)
+ MOV_L (REGOFF(8,ESP), EAX)
+ OUT_B
+ RET
+
+ ALIGNTEXT4
+GLNAME(outw):
+ MOV_L (REGOFF(4,ESP), EDX)
+ MOV_L (REGOFF(8,ESP), EAX)
+ OUT_W
+ RET
+
+ ALIGNTEXT4
+GLNAME(outl):
+ MOV_L (REGOFF(4,ESP), EDX)
+ MOV_L (REGOFF(8,ESP), EAX)
+ OUT_L
+ RET
+
+ ALIGNTEXT4
+GLNAME(inb):
+ MOV_L (REGOFF(4,ESP), EDX)
+ IN_B
+ RET
+
+ ALIGNTEXT4
+GLNAME(inw):
+ MOV_L (REGOFF(4,ESP), EDX)
+ IN_L
+ RET
+
+ ALIGNTEXT4
+GLNAME(inl):
+ MOV_L (REGOFF(4,ESP), EDX)
+ IN_L
+ RET
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.S b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.S
new file mode 100644
index 000000000..9fd73a0f9
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.S
@@ -0,0 +1,108 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.s,v 1.2 1998/07/25 16:56:50 dawes Exp $ */
+/*******************************************************************************
+ Copyright 1994 by Glenn G. Lai
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyr notice appear in all copies and that
+both that copyr notice and this permission notice appear in
+supporting documentation, and that the name of Glenn G. Lai not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+Glenn G. Lai DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+Glenn G. Lai
+P.O. Box 4314
+Austin, Tx 78765
+glenn@cs.utexas.edu)
+7/21/94
+*******************************************************************************/
+/* $XConsortium: SlowBcopy.s /main/4 1996/02/21 17:40:52 kaleb $ */
+
+/*
+ * Modified from the output generated by GCC
+ *
+ * Create a dependency that should be immune from the effect of register
+ * renaming as is commonly seen in superscalar processors. This should
+ * insert a minimum of 100-ns delays between reads/writes at clock rates
+ * up to 100 MHz---GGL
+ *
+ * Slowbcopy(char *src, char *dst, int count)
+ *
+ */
+
+#include "assyntax.h"
+
+ FILE("SlowBcopy.s")
+
+ AS_BEGIN
+
+gcc2_compiled.:
+___gnu_compiled_c:
+
+ GLOBL GLNAME(xf86SlowBcopy)
+
+ SEG_TEXT
+ ALIGNTEXT4
+GLNAME(xf86SlowBcopy):
+ PUSH_L (EBP)
+ MOV_L (ESP,EBP)
+ PUSH_L (ESI)
+ PUSH_L (EBX)
+ MOV_L (REGOFF(8,EBP),ECX)
+ MOV_L (REGOFF(12,EBP),EDX)
+ MOV_L (REGOFF(16,EBP),ESI)
+ XOR_L (EAX,EAX)
+ CMP_L (ESI,EAX)
+ JGE (L3)
+
+ ALIGNTEXT4
+L5:
+ MOV_B (REGIND(ECX),BL)
+
+ MOV_B (BL, BH)
+ MOV_B (BH, BL)
+ MOV_B (BL, BH)
+ MOV_B (BH, BL)
+ MOV_B (BL, BH)
+ MOV_B (BH, BL)
+ MOV_B (BL, BH)
+ MOV_B (BH, BL)
+ MOV_B (BL, BH)
+ MOV_B (BH, BL)
+
+ MOV_B (BL,REGIND(EDX))
+
+ INC_L (ECX)
+ DEC_L (ECX)
+ INC_L (ECX)
+ DEC_L (ECX)
+ INC_L (ECX)
+ DEC_L (ECX)
+ INC_L (ECX)
+ DEC_L (ECX)
+ INC_L (ECX)
+ DEC_L (ECX)
+
+ INC_L (ECX)
+ INC_L (EDX)
+ INC_L (EAX)
+ CMP_L (ESI,EAX)
+ JL (L5)
+L3:
+ LEA_L (REGOFF(-8,EBP),ESP)
+ POP_L (EBX)
+ POP_L (ESI)
+ MOV_L (EBP,ESP)
+ POP_L (EBP)
+ RET
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.c
new file mode 100644
index 000000000..ec2c67ffa
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.c
@@ -0,0 +1,114 @@
+
+/* $XConsortium: SlowBcopy.c /main/1 1996/05/07 17:14:10 kaleb $ */
+/*******************************************************************************
+ for Alpha Linux
+*******************************************************************************/
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/SlowBcopy.c,v 1.6tsi Exp $ */
+
+/*
+ * Create a dependency that should be immune from the effect of register
+ * renaming as is commonly seen in superscalar processors. This should
+ * insert a minimum of 100-ns delays between reads/writes at clock rates
+ * up to 100 MHz---GGL
+ *
+ * Slowbcopy(char *src, char *dst, int count)
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "compiler.h"
+
+/* The outb() isn't needed on my machine, but who knows ... -- ost */
+void
+xf86SlowBcopy(unsigned char *src, unsigned char *dst, int len)
+{
+ while(len--)
+ {
+ *dst++ = *src++;
+#if !defined(__sparc__) && \
+ !defined(__powerpc__) && \
+ !defined(__mips__) && \
+ !defined(__ia64__)
+ outb(0x80, 0x00);
+#endif
+ }
+}
+
+#ifdef __alpha__
+/*
+ * The Jensen lacks dense memory, thus we have to address the bus via
+ * the sparse addressing scheme. Time critical code uses routines from
+ * BUSmemcpy.c
+ *
+ * Martin Ostermann (ost@comnets.rwth-aachen.de) - Apr.-Sep. 1996
+ */
+
+#ifdef linux
+
+unsigned long _bus_base(void);
+
+#ifdef TEST_JENSEN_CODE /* define to test the Sparse addressing on a non-Jensen */
+#define SPARSE (5)
+#else
+#define SPARSE (7)
+#endif
+
+#define isJensen() (!_bus_base())
+
+#else
+
+#define isJensen() 0
+#define SPARSE 0
+
+#endif
+
+void
+xf86SlowBCopyFromBus(unsigned char *src, unsigned char *dst, int count)
+{
+ if (isJensen())
+ {
+ unsigned long addr;
+ long result;
+
+ addr = (unsigned long) src;
+ while( count ){
+ result = *(volatile int *) addr;
+ result >>= ((addr>>SPARSE) & 3) * 8;
+ *dst++ = (unsigned char) (0xffUL & result);
+ addr += 1<<SPARSE;
+ count--;
+ outb(0x80, 0x00);
+ }
+ }
+ else
+ xf86SlowBcopy(src,dst,count);
+}
+
+void
+xf86SlowBCopyToBus(unsigned char *src, unsigned char *dst, int count)
+{
+ if (isJensen())
+ {
+ unsigned long addr;
+
+ addr = (unsigned long) dst;
+ while(count) {
+ *(volatile unsigned int *) addr = (unsigned short)(*src) * 0x01010101;
+ src++;
+ addr += 1<<SPARSE;
+ count--;
+ outb(0x80, 0x00);
+ }
+ }
+ else
+ xf86SlowBcopy(src,dst,count);
+}
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/xf86_IlHack.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/xf86_IlHack.c
new file mode 100644
index 000000000..d8053f7d2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/xf86_IlHack.c
@@ -0,0 +1,19 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/xf86_IlHack.c,v 3.4.4.1 1998/06/04 17:36:01 dawes Exp $ */
+/*
+ * This file is an incredible crock to get the normally-inline functions
+ * built into the server so that things can be debugged properly.
+ *
+ * Note: this doesn't work when using a compiler other than GCC.
+ */
+/* $XConsortium: xf86_IlHack.c /main/4 1996/02/21 17:52:26 kaleb $ */
+
+
+#define static /**/
+#define __inline__ /**/
+#undef NO_INLINE
+#define DO_PROTOTYPES
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "compiler.h"
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/xf86_Util.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/xf86_Util.c
new file mode 100644
index 000000000..afcdd5b69
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/misc/xf86_Util.c
@@ -0,0 +1,96 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/misc/xf86_Util.c,v 3.7 1999/01/14 13:05:05 dawes Exp $ */
+/*
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: xf86_Util.c /main/5 1996/10/23 13:13:10 kaleb $ */
+
+/*
+ * This file is for utility functions that will be shared by other pieces
+ * of the system. Putting things here ensure that all the linking order
+ * dependencies are dealt with, as this library will be linked in last.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <ctype.h>
+
+/* To prevent empty source file warnings */
+int _xf86misc;
+
+#if 0
+/* For use only with gcc */
+#ifdef __GNUC__
+
+#include "os.h"
+
+char *
+debug_alloca(char *file, int line, int size)
+{
+ char *ptr;
+
+ ptr = Xalloc(size);
+ ErrorF("Alloc: %s line %d; ptr = 0x%x, length = %d\n", file, line,
+ ptr, size);
+ return ptr;
+}
+
+void
+debug_dealloca(char *file, int line, char *ptr)
+{
+ ErrorF("Dealloc: %s line %d; ptr = 0x%x\n", file, line, ptr);
+ Xfree(ptr);
+}
+#endif
+#endif
+
+#if defined(ISC) || defined(Lynx)
+
+#include <math.h>
+
+/* Needed for apm_driver.c */
+/* These functions are modeled after the functions inside gnu's libc */
+
+static double
+copysign(double x, double y)
+{
+ x = fabs(x);
+ return y < 0 ? - x : x;
+}
+
+double
+RInt(double x)
+{
+ double s,t;
+ const double one = 1.0;
+ const static double L = 4503599627370496.0E0;
+
+ if (x!=x)
+ return(x);
+ if (copysign(x,one) >= L)
+ return(x);
+ s = copysign(L,x);
+ t = x + s;
+ return (t - s);
+}
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/Imakefile
new file mode 100644
index 000000000..fb7132182
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/Imakefile
@@ -0,0 +1,37 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/nto/Imakefile,v 1.7 2002/10/11 01:46:59 dawes Exp $
+XCOMM
+
+#include <Server.tmpl>
+
+
+SRCS = nto_io.c nto_init.c nto_kbdEv.c nto_ioperm.c nto_video.c \
+ VTsw_noop.c posix_tty.c kmod_noop.c agp_noop.c stdResource.c \
+ stdPci.c libc_wrapper.c sigiostubs.c pm_noop.c nto_mouse.c
+
+OBJS = nto_io.o nto_init.o nto_kbdEv.o nto_ioperm.o nto_video.o \
+ VTsw_noop.o posix_tty.o kmod_noop.o agp_noop.o stdResource.o \
+ stdPci.o libc_wrapper.o sigiostubs.o pm_noop.o nto_mouse.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC)
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+
+LinkSourceFile(VTsw_noop.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/README b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/README
new file mode 100644
index 000000000..8d262fe08
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/README
@@ -0,0 +1,29 @@
+XFree86 on NTO
+
+Status:
+Everything builds, and appears to work. Libraries are built as shared.
+
+Building:
+Buiding is done as cross-development from QNX4. What you'll need:
+
+QNX4 4.24+
+Neutrino 2.0 x86 runtime and development packages for QNX4 host.
+Various QNX4 utilities, such as pdksh, cpp etc.
+
+To build:
+
+type (from the xc/ directory)
+BOOTSTRAPCFLAGS="-D__QNXNTO__ -Di386 -D__GNUC__" make World 2>&1 | tee make.log
+
+you can also make PPC or MIPS clients (-DPPC or -DMIPS):
+BOOTSTRAPCFLAGS="-D__QNXNTO__ -DPPC -D__GNUC__" make World 2>&1 | tee make.log
+
+Let the build run, and then examine make.log for any errors.
+
+
+Note that we'll very soon be able to build X natively on NTO...
+
+Sebastien Marineau
+sebastien@qnx.com
+
+$XFree86: xc/programs/Xserver/hw/xfree86/os-support/nto/README,v 1.1.2.1 1999/07/29 09:40:14 hohndel Exp $
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_init.c
new file mode 100644
index 000000000..726a8a5ac
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_init.c
@@ -0,0 +1,104 @@
+/*
+ * (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * SEBASTIEN MARINEAU 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/nto/nto_init.c,v 1.2 1999/12/27 00:45:45 robin Exp $
+ */
+
+/* This module contains the NTO-specific functions used at server init.
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/neutrino.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/dcmd_chr.h>
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+extern int NTO_con_fd;
+
+void
+xf86UseMsg()
+{
+ ErrorF("No NTO-specific usage options available at this time\n");
+ return;
+}
+
+int
+xf86ProcessArgument(argc, argv, i)
+int argc;
+char **argv;
+int i;
+{
+
+ return 0;
+
+}
+
+
+/* Right now, OpenConsole() does not do much; later, we may want to handle
+ * console switching and so on....
+ */
+
+void
+xf86OpenConsole()
+{
+ unsigned flags;
+
+
+ ThreadCtl(_NTO_TCTL_IO, 0);
+
+ if((NTO_con_fd = open("/dev/con1", O_RDWR)) == -1) {
+ ErrorF("Unable to open console\n");
+ return;
+ }
+
+ /* Make the console invisible to prevent devc-con from touching hardware */
+ flags = _CONCTL_INVISIBLE | _CONCTL_INVISIBLE_CHG;
+ devctl(NTO_con_fd, DCMD_CHR_SERCTL, &flags, sizeof flags, 0);
+
+ return;
+}
+
+void
+xf86CloseConsole()
+{
+ unsigned flags;
+
+ /* Make console visible again */
+ flags = _CONCTL_INVISIBLE_CHG;
+ devctl(NTO_con_fd, DCMD_CHR_SERCTL, &flags, sizeof flags, 0);
+ close(NTO_con_fd);
+
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_io.c
new file mode 100644
index 000000000..9c32afd35
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_io.c
@@ -0,0 +1,118 @@
+/*
+ * (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * SEBASTIEN MARINEAU 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/nto/nto_io.c,v 1.4 2002/10/11 01:40:35 dawes Exp $
+ */
+
+/* This module contains the NTO-specific functions to access the keyboard
+ * and the console.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+int NTO_kbd_fd = -1;
+int NTO_con_fd = -1;
+
+void
+xf86SoundKbdBell(loudness, pitch, duration)
+int loudness, pitch, duration;
+{
+
+/* Come back and fix! */
+ErrorF("xf86SoundKbdBell: to implement\n");
+}
+
+void
+xf86SetKbdLeds(leds)
+int leds;
+{
+
+ErrorF("xf86SetKbdLeds: to implement\n");
+}
+
+int
+xf86GetKbdLeds()
+{
+ int leds;
+
+ leds = 0;
+ ErrorF("xf86GetKbdLeds: to implement\n");
+ return(leds);
+}
+
+/* This is a no-op for now */
+void
+xf86SetKbdRepeat(rad)
+char rad;
+{
+ return;
+}
+
+
+/* Need to open keyboard here ? */
+void
+xf86KbdInit()
+{
+
+ ErrorF("xf86KbdInit: to implement\n");
+ return;
+}
+
+
+int xf86KbdOn()
+{
+ /* Here, we need to open /dev/kbd */
+ NTO_kbd_fd = open("/dev/kbd", O_RDWR | O_NONBLOCK);
+ ErrorF("Opened keyboard device, handle %d\n",NTO_kbd_fd);
+ return(NTO_kbd_fd);
+}
+
+int xf86KbdOff()
+{
+ close(NTO_kbd_fd);
+ NTO_kbd_fd = -1;
+ return (-1);
+}
+
+#include "xf86OSKbd.h"
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_ioperm.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_ioperm.c
new file mode 100644
index 000000000..67a771ff6
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_ioperm.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright 1998 by Sebastien Marineau <sebastien@qnx.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Sebastien Marineau makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * SEBASTIEN MARINEAU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/nto/nto_ioperm.c,v 1.2 1999/12/27 00:45:45 robin Exp $
+ */
+
+/* I/O functions to enable access to I/O ports under Neutrino */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/neutrino.h>
+#include <errno.h>
+
+
+Bool xf86EnableIO()
+{
+ ErrorF("xf86EnableIO: enabling I/O access\n");
+ if(ThreadCtl(_NTO_TCTL_IO, 0)) {
+ ErrorF("xf86EnableIO: could not set I/O privilege, errno %d\n",errno);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+void xf86DisableIO()
+{
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_kbdEv.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_kbdEv.c
new file mode 100644
index 000000000..a028de6b6
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_kbdEv.c
@@ -0,0 +1,53 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/nto/nto_kbdEv.c,v 1.2 1999/12/27 00:45:46 robin Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Dawes <dawes@physics.su.oz.au>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Dawes makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID DAWES BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: std_kbdEv.c /main/4 1996/03/11 10:47:33 kaleb $ */
+
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "xf86_OSlib.h"
+
+extern int NTO_kbd_fd;
+
+void xf86KbdEvents()
+{
+ unsigned char rBuf[64];
+ int nBytes, i;
+
+ if ((nBytes = read( NTO_kbd_fd, (char *)rBuf, sizeof(rBuf))) > 0) {
+ for (i = 0; i < nBytes; i++) {
+ xf86PostKbdEvent(rBuf[i]);
+ }
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_mouse.c
new file mode 100644
index 000000000..2dda8aa32
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_mouse.c
@@ -0,0 +1,210 @@
+/*
+ * Written by Frank Liu Oct 10, 2001
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/nto/nto_mouse.c,v 1.1 2001/11/16 16:47:56 dawes Exp $ */
+
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+
+/* copied from mipointer.h */
+extern int miPointerGetMotionEvents(
+ DeviceIntPtr /*pPtr*/,
+ xTimecoord * /*coords*/,
+ unsigned long /*start*/,
+ unsigned long /*stop*/,
+ ScreenPtr /*pScreen*/
+);
+
+#include <sys/dcmd_input.h>
+#define NUMEVENTS 64 /* don't want to stuck in the mouse read loop */
+
+/*
+ * OsMouseReadInput --
+ * Get some events from our queue. Process outstanding events now.
+ */
+static void
+OsMouseReadInput(InputInfoPtr pInfo)
+{
+ int n = 0;
+ int buttons, col, row;
+ struct _mouse_packet mp;
+ MouseDevPtr pMse;
+
+ pMse = pInfo->private;
+
+ while ( (read(pInfo->fd, &mp, sizeof(struct _mouse_packet)) > 0 )
+ && (n < NUMEVENTS ) )
+ {
+ col = mp.dx;
+ row = -mp.dy;
+ buttons = mp.hdr.buttons;
+ pMse->PostEvent(pInfo, buttons, col, row, 0, 0);
+ n++;
+ }
+}
+
+/*
+ * OsMouseProc --
+ * Handle the initialization, etc. of a mouse
+ */
+static int
+OsMouseProc(pPointer, what)
+DeviceIntPtr pPointer;
+int what;
+{
+ int nbuttons;
+ unsigned char map[MSE_MAXBUTTONS + 1];
+ MouseDevPtr pMse;
+ InputInfoPtr pInfo;
+
+ pInfo = pPointer->public.devicePrivate;
+ pMse = pInfo->private;
+ pMse->device = pPointer;
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+
+ for (nbuttons = 0; nbuttons < MSE_MAXBUTTONS; ++nbuttons)
+ map[nbuttons + 1] = nbuttons + 1;
+
+ InitPointerDeviceStruct((DevicePtr)pPointer,
+ map,
+ min(pMse->buttons, MSE_MAXBUTTONS),
+ miPointerGetMotionEvents,
+ pMse->Ctrl,
+ miPointerGetMotionBufferSize());
+
+ /* X valuator */
+ xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 0);
+ /* Y valuator */
+ xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 1);
+ xf86MotionHistoryAllocate(pInfo);
+ break;
+
+ case DEVICE_ON:
+ pInfo->fd = xf86OpenSerial(pInfo->options);
+ if (pInfo->fd == -1)
+ xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
+ else {
+ AddEnabledDevice(pInfo->fd);
+ }
+ pMse->lastButtons = 0;
+ pMse->lastMappedButtons = 0;
+ pMse->emulateState = 0;
+ pPointer->public.on = TRUE;
+ break;
+
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ if (pInfo->fd != -1) {
+ RemoveEnabledDevice(pInfo->fd);
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+ }
+ pPointer->public.on = FALSE;
+ break;
+ }
+ return (Success);
+}
+
+static int
+SupportedInterfaces(void)
+{
+ /* FIXME: Is this correct? Should we just return MSE_MISC? */
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_MISC | MSE_AUTO;
+}
+
+static const char *internalNames[] = {
+ "OSMouse",
+ NULL
+};
+
+static const char **
+BuiltinNames(void)
+{
+ return internalNames;
+}
+
+static Bool
+CheckProtocol(const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++)
+ if (xf86NameCmp(protocol, internalNames[i]) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+/* XXX Is this appropriate? If not, this function should be removed. */
+static const char *
+DefaultProtocol(void)
+{
+ return "OSMouse";
+}
+
+static Bool
+OsMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ MouseDevPtr pMse;
+
+ /* This is called when the protocol is "OSMouse". */
+
+ pMse = pInfo->private;
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ /* Check if the device can be opened. */
+ pInfo->fd = xf86OpenSerial(pInfo->options);
+ if (pInfo->fd == -1) {
+ if (xf86GetAllowMouseOpenFail())
+ xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
+ else {
+ xf86Msg(X_ERROR, "%s: cannot open input device\n", pInfo->name);
+ xfree(pMse);
+ return FALSE;
+ }
+ }
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local procs. */
+ pInfo->device_control = OsMouseProc;
+ pInfo->read_input = OsMouseReadInput;
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+ p->BuiltinNames = BuiltinNames;
+ p->DefaultProtocol = DefaultProtocol;
+ p->CheckProtocol = CheckProtocol;
+ p->PreInit = OsMousePreInit;
+ return p;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_video.c
new file mode 100644
index 000000000..f78f6864a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/nto/nto_video.c
@@ -0,0 +1,170 @@
+/* (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * SEBASTIEN MARINEAU 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/nto/nto_video.c,v 1.3tsi Exp $
+ */
+
+/* This module contains the NTO-specific functions to deal with video
+ * framebuffer access and interrupts.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/neutrino.h>
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+
+/* These are the interrupt enabling/disabling functions.
+ */
+
+void xf86EnableInterrupts()
+{
+ InterruptEnable();
+}
+
+Bool xf86DisableInterrupts()
+{
+ InterruptDisable();
+ return 0;
+}
+
+/* These are the routines to map/unmap video memory... */
+
+Bool xf86LinearVidMem()
+{
+ /* Yes we can... */
+ return(TRUE);
+}
+
+/* This is our shmem "Physical" handle */
+int NTO_PhMem_fd = -1;
+
+
+/* Map a chunk of physical video memory, using mmap */
+pointer
+xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
+{
+ int fd;
+ pointer base;
+
+ if(NTO_PhMem_fd < 0) {
+ if ((fd = open("/dev/mem", O_RDWR, 0777)) < 0) {
+ FatalError("xf86MapVidMem: Failed to open /dev/mem\n");
+ }
+ NTO_PhMem_fd = fd;
+ }
+
+ base = mmap((caddr_t)0, Size,
+ (Flags & VIDMEM_READONLY) ? PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, NTO_PhMem_fd, (off_t)Base);
+
+ ErrorF("MapVidMem: addr %08x size %08x addr %08x\n", Base, Size, base);
+ if ((long)base == -1) {
+ FatalError("xf86MapVidMem: Failed to mmap video memory\n");
+ }
+
+ return base;
+}
+
+/* ARGSUSED */
+void
+xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+
+ ErrorF("xf86UnmapVidMem: base %x size %x\n", Base, Size);
+ munmap((caddr_t) Base, Size);
+
+}
+
+/* Finally, this function allows us to read the video BIOS content */
+
+int
+xf86ReadBIOS(Base, Offset, Buf, Len)
+unsigned long Base, Offset;
+unsigned char *Buf;
+int Len;
+{
+ unsigned char * VirtBase;
+
+ ErrorF("xf86ReadBIOS: base %x offset %x len %x\n", Base, Offset, Len);
+
+ if (NTO_PhMem_fd == -1) {
+ if ((NTO_PhMem_fd = open("/dev/mem", O_RDWR, 0777)) < 0) {
+ FatalError("xf86ReadBIOS: cannot open Physical memory\n");
+ }
+ }
+
+ /* Use mmap to map BIOS region. Note the restrictions on
+ * mmap alignement of offset variable (which must be on a page
+ * boundary).
+ */
+ VirtBase = (unsigned char *) mmap(0, (size_t)((Offset & 0x7fff) + Len), PROT_READ,
+ MAP_SHARED, NTO_PhMem_fd, (off_t) (Base + (Offset & 0xffff8000)));
+ if((long)VirtBase == -1) {
+ FatalError( "xf86ReadBIOS: Could not mmap BIOS memory space, errno=%i\n", errno);
+ }
+
+ /* So now we have our mapping to the BIOS region */
+
+ /* Do a sanity check on what we have just mapped */
+ if (((off_t)((off_t)Offset & 0x7FFF) != (off_t)0) &&
+ (VirtBase[0] != 0x55) &&
+ (VirtBase[1] != 0xaa)) {
+ ErrorF( "xf86ReadBIOS: BIOS sanity check failed, addr=%x\n",
+ (int)Base + Offset);
+ munmap(VirtBase, (Offset & 0x7fff) + Len);
+ return -1;
+ }
+
+ /* Things look good: copy BIOS data */
+ memcpy(Buf, VirtBase + (Offset & 0x7fff), Len);
+ munmap(VirtBase, (Offset & 0x7fff) + Len);
+
+ return Len;
+}
+
+void
+xf86MapReadSideEffects(int ScreenNum, int Flags, pointer base,
+ unsigned long Size)
+{
+ return;
+}
+
+Bool
+xf86CheckMTRR(int s)
+{
+ return FALSE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/Imakefile
new file mode 100644
index 000000000..6659da9be
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/Imakefile
@@ -0,0 +1,45 @@
+XCOMM $XConsortium: Imakefile /main/7 1996/09/28 17:24:18 rws $
+
+
+
+
+
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/Imakefile,v 3.20 2002/10/17 02:22:48 dawes Exp $
+#include <Server.tmpl>
+
+BIOS_MOD = os2_bios
+
+SRCS = os2_init.c os2_video.c os2_io.c $(BIOS_MOD).c \
+ os2_ioperm.c os2_VTsw.c os2_mouse.c os2_KbdEv.c os2_stubs.c \
+ os2_select.c os2_diag.c libc_wrapper.c stdResource.c stdPci.c \
+ vidmem.c sigiostubs.c pm_noop.c kmod_noop.c agp_noop.c os2_serial.c \
+ os2_kbd.c
+
+OBJS = os2_init.o os2_video.o os2_io.o $(BIOS_MOD).o \
+ os2_ioperm.o os2_VTsw.o os2_mouse.o os2_kbdEv.o os2_stubs.o \
+ os2_select.o os2_diag.o libc_wrapper.o stdResource.o stdPci.o \
+ vidmem.o sigiostubs.o pm_noop.o kmod_noop.o agp_noop.o os2_serial.o \
+ os2_kbd.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(SERVERSRC)/mi -I$(XINCLUDESRC) -I$(EXTINCSRC)
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+NormalAsmObjectRule()
+
+LinkSourceFile(VTsw_noop.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(vidmem.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/README b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/README
new file mode 100644
index 000000000..d07059eed
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/README
@@ -0,0 +1,78 @@
+Information on files in this directory
+--------------------------------------
+\xc\programs\xserver\hw\xfree86\os-support\os2
+
+The files in this directory form the OS-dependent porting layer of
+XFree86 for OS/2. They are the work of:
+
+ Holger Veit <Holger.Veit@gmd.de>
+ Sebastien Marineau <marineau@genie.uottawa.ca>
+
+Some functions which were absent from OS/2,
+such as direct access to IO ports and the mapping of physical memory,
+are implemented in a device-driver written for this purpose by Holger Veit
+<Holger.Veit@gmd.de>. The driver also implements several functions
+necessary for xterm.
+The driver should be installed in the config.sys with a line:
+
+DEVICE=path\XF86SUP.SYS
+
+The following gives a brief overview of the implementation of the
+porting layer, and lists some of the "gotchas" when modifying the source.
+
+BIOS and physical memory mapping: This is handled by the functions in XF86SUP.SYS driver.
+
+IO permission: Handled by a function in the XF86SUP.SYS driver. Essentially, IO permissions
+are granted for the whole Xserver at server initialisation. The device-driver sets the IOPL
+level to ring 3 for the Xserver, which in essence gives it the same IO privileges that a
+device-driver has. Note the danger here: the Xserver can write to any IO port it wishes,
+and can disable interrupts (something which it does), thus can potentially hang the system.
+
+VT switching (switching back and forth to the WPS): This is handled by the keyboard driver,
+i.e. the stardard keyboard sequences (CTRL-ESC etc.) trigger the switch back to PM. The
+Xserver is notified of switches by the VIO function VIOSavRedrawWait(), which is run in
+a separate thread. When a switch to/from PM is requested, this function call unblocks, and
+the Xserver either saves or restores the video buffer and video mode. Note that semaphores
+are used to communicate with the main Xserver thread, and handle cases such as server
+reset while the server has lost focus etc.
+A similar mechanism is used to handle hard-error popups. A thread is run which blocks
+on the VIOModeWait() function. When a hard-error notification occurs, the Xserver attempts
+to recover by resetting the screen. Note that, due to some (probable) bugs in the OS/2
+video drivers, this does not always work as expected. According to the specs, the OS/2
+video drivers are supposed to restore the palette when returning from a hard-error. This
+does not seem to be always the case..... so the palette in X may be screwed up after the
+hard-error.
+
+Keyboard input: because X needs all keyboard event to function (both keypresses, key
+releases, for all keys), the keyboard input was implemented by registering a keyboard
+monitor for the Xserver. The keyboard monitor is run in a separate thread, and sends
+the keystrokes back to the Xserver main thread through a queue. Another thread is
+also started, whose purpose is to "eat" the keystrokes returned by KbdCharIn(). Note that
+the monitor was necessary because the OS/2 keyboard driver does not pass all keystrokes
+to the application calling KbdCharIn().
+
+Mouse input: This was implemented similarly to the keyboard input: mouse events are
+read in a thread, which then passes them to the main Xserver thread through a queue.
+
+Select: this unix and emx function has been reimplemented and optimized for the xserver.
+Because of the need to handle input from pipes, sockets, the mouse and keyboard (which
+select() in unix does but the EMX select does not), it was decided to rewrite it in
+order to minimize CPU usage and maximize responsiveness. Essentially, select() blocks on
+a MuxWait semaphore, and unblocks when input is available from pipes, the mouse and the
+keyboard. The MuxWait semaphore times out every timeslice, so that sockets can be checked
+for activity (unfortunately, sockets are not well-handled in the OS/2 TCPIP and one cannot
+attach a semaphore to a socket). There is also the possibility of using the high-resolution
+timer (found in Merlin) to check sockets more often than every timeslice.
+*** Important: in order to maximize speed, certain shortcuts are utilized in this
+implementation of select(), which makes it unsuitable as a general-purpose function. Also,
+it is imperative that the EMX select() never be called from the Xserver! ***
+
+
+If you wish to modify the source, be aware that there may be very good reasons as
+to why certain things were done this way. Usually, if certain function implementations
+appear unnecessarily complicated, it is probably because there were subtle problems
+with the simpler solutions. Due to the complexity of the Xserver code, and the
+differences between OS/2 and unix, there are many potential pitfalls.
+
+$XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/README,v 3.1 1996/01/30 15:26:27 dawes Exp $
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/int10/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/int10/Imakefile
new file mode 100644
index 000000000..a323229bf
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/int10/Imakefile
@@ -0,0 +1,110 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/int10/Imakefile,v 1.1 2000/04/05 18:13:55 dawes Exp $
+
+#define IHaveModules
+
+#include <Server.tmpl>
+
+SRCS1 = pci.c xf86int10module.c helper_exec.c helper_mem.c xf86int10.c
+OBJS1 = pci.o xf86int10module.o helper_exec.o helper_mem.o xf86int10.o
+
+LinkSourceFile(helper_mem.c,$(XF86SRC)/int10)
+LinkSourceFile(helper_exec.c,$(XF86SRC)/int10)
+LinkSourceFile(xf86int10.c,$(XF86SRC)/int10)
+LinkSourceFile(pci.c,$(XF86SRC)/int10)
+LinkSourceFile(xf86int10module.c,$(XF86SRC)/int10)
+LinkSourceFile(xf86x86emu.c,$(XF86SRC)/int10)
+LinkSourceFile(generic.c,$(XF86SRC)/int10)
+
+INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86SRC)/int10 \
+ -I$(XF86OSSRC) \
+ -I$(SERVERSRC)/include -I$(XINCLUDESRC)
+
+DEFINES=-DHAVE_SYSV_IPC
+
+#if 0
+/* debugging stuff */
+#DEFINES =-D_PC
+#undef XF86INT10_BUILD
+#define XF86INT10_BUILD X86EMU_GENERIC
+#define X86EMU_LIBPATH /usr/local/lib
+#endif
+
+#if defined(i386Architecture)
+DEFINES =-D_PC
+#endif
+
+/* XXX keep this temporarily for reference */
+#if 0
+#if (XF86INT10_BUILD == X86EMU_GENERIC)
+
+SRCS = $(SRCS1) xf86x86emu.c generic.c
+OBJS = $(OBJS1) xf86x86emu.o generic.o x86emu.o
+SpecialObjectRule(pci.o, pci.c, -D_X86EMU)
+SpecialObjectRule(helper_exec.o, helper_exec.c, -D_X86EMU)
+SpecialObjectRule(xf86int10.o, xf86int10.c, -D_X86EMU -DSHOW_ALL_DEVICES)
+SpecialObjectRule(generic.o, generic.c, -D_X86EMU)
+SpecialObjectRule(xf86x86emu.o, xf86x86emu.c, -D_X86EMU)
+BuildObjectFromLibraryWithPath(X86EMU_LIBPATH,x86emu,x86emu)
+#endif
+#endif
+
+#if defined(XF86INT10_BUILD) && (XF86INT10_BUILD == X86VM)
+
+SRCS = $(SRCS1) linux.c
+OBJS = $(OBJS1) linux.o
+SpecialObjectRule(pci.o, pci.c, -D_VM86_LINUX)
+SpecialObjectRule(helper_exec.o, helper_exec.c, -D_VM86_LINUX)
+SpecialObjectRule(xf86int10.o, xf86int10.c, -D_VM86_LINUX -DSHOW_ALL_DEVICES)
+SpecialObjectRule(linux.o, linux.c, -D_VM86_LINUX -DHAVE_SYSV_IPC)
+
+#elif (XF86INT10_BUILD == X86EMU_OS)
+
+SpecialObjectRule(pci.o, pci.c, -D_X86EMU)
+SpecialObjectRule(helper_exec.o, helper_exec.c, -D_X86EMU)
+SpecialObjectRule(xf86int10.o, xf86int10.c, -D_X86EMU -DSHOW_ALL_DEVICES)
+SpecialObjectRule(linux.o, linux.c, -D_X86EMU -DHAVE_SYSV_IPC)
+
+X86TOPDIR = $(TOP)/extras/x86emu
+X86SRCDIR = $(X86TOPDIR)/src/x86emu
+X86EMUINCLUDES = -I$(X86TOPDIR)/include -I$(X86SRCDIR)
+
+# if !defined(X86EMU_LIBPATH)
+X86EMUSRCS = debug.c decode.c fpu.c ops.c ops2.c prim_ops.c sys.c
+X86EMUOBJS = debug.o decode.o fpu.o ops.o ops2.o prim_ops.o sys.o
+
+LinkSourceFile(debug.c,$(X86SRCDIR))
+LinkSourceFile(decode.c,$(X86SRCDIR))
+LinkSourceFile(fpu.c,$(X86SRCDIR))
+LinkSourceFile(ops.c,$(X86SRCDIR))
+LinkSourceFile(ops2.c,$(X86SRCDIR))
+LinkSourceFile(prim_ops.c,$(X86SRCDIR))
+LinkSourceFile(sys.c,$(X86SRCDIR))
+# else
+BuildObjectFromLibraryWithPath(X86EMU_LIBPATH,x86emu,x86emu)
+X86EMUOBJS = x86emu.o
+# endif
+
+SRCS = $(SRCS1) xf86x86emu.c linux.c $(X86EMUSRCS)
+OBJS = $(OBJS1) xf86x86emu.o linux.o $(X86EMUOBJS)
+
+#endif
+
+#if defined(XF86INT10_BUILD) && XF86INT10_BUILD > X86EMU_GENERIC
+
+LibraryModuleTarget(int10, $(OBJS))
+
+InstallLibraryModule(int10,$(MODULEDIR),linux)
+
+all::
+ @(set -x; cd ../..; \
+ RemoveFile(LibraryTargetName(int10)); \
+ $(LN) linux/int10/LibraryTargetName(int10) . )
+
+InstallDriverSDKLibraryModule(int10,$(DRIVERSDKMODULEDIR),.)
+
+InstallDriverSDKNonExecFile(../../int10/xf86int10.h,$(DRIVERSDKINCLUDEDIR))
+
+#endif
+
+DependTarget()
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/int10/os2.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/int10/os2.c
new file mode 100644
index 000000000..d01cfb373
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/int10/os2.c
@@ -0,0 +1,452 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/int10/os2.c,v 1.3 2001/04/30 14:34:58 tsi Exp $ */
+/*
+ * XFree86 int10 module
+ * execute BIOS int 10h calls in x86 real mode environment
+ * Copyright 1999 Egbert Eich
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86str.h"
+#include "xf86_OSproc.h"
+#include "xf86_ansic.h"
+#include "xf86Pci.h"
+#include "compiler.h"
+#define _INT10_PRIVATE
+#include "xf86int10.h"
+#include "int10Defines.h"
+
+static CARD8 read_b(xf86Int10InfoPtr pInt,int addr);
+static CARD16 read_w(xf86Int10InfoPtr pInt,int addr);
+static CARD32 read_l(xf86Int10InfoPtr pInt,int addr);
+static void write_b(xf86Int10InfoPtr pInt,int addr, CARD8 val);
+static void write_w(xf86Int10InfoPtr pInt,int addr, CARD16 val);
+static void write_l(xf86Int10InfoPtr pInt,int addr, CARD32 val);
+
+/*
+ * the emulator cannot pass a pointer to the current xf86Int10InfoRec
+ * to the memory access functions therefore store it here.
+ */
+
+typedef struct {
+ int shift;
+ int pagesize_1;
+ int entries;
+ void* vRam;
+ memType *alloc_rec;
+} genericInt10Priv;
+
+#define INTPriv(x) ((genericInt10Priv*)x->private)
+
+int10MemRec genericMem = {
+ read_b,
+ read_w,
+ read_l,
+ write_b,
+ write_w,
+ write_l
+};
+
+static void MapVRam(xf86Int10InfoPtr pInt);
+static void UnmapVRam(xf86Int10InfoPtr pInt);
+static void setupTable(xf86Int10InfoPtr pInt, memType address,
+ int loc,int size);
+
+static void *sysMem = NULL;
+
+xf86Int10InfoPtr
+xf86InitInt10(int entityIndex)
+{
+ xf86Int10InfoPtr pInt;
+ int screen;
+ void* intMem;
+ void* vbiosMem;
+ int pagesize;
+ int entries;
+ int shift;
+ legacyVGARec vga;
+
+ screen = (xf86FindScreenForEntity(entityIndex))->scrnIndex;
+
+ if (int10skip(xf86Screens[screen],entityIndex))
+ return NULL;
+
+ pInt = (xf86Int10InfoPtr)xnfcalloc(1,sizeof(xf86Int10InfoRec));
+ pInt->entityIndex = entityIndex;
+ if (!xf86Int10ExecSetup(pInt))
+ goto error0;
+ pInt->mem = &genericMem;
+ pagesize = xf86getpagesize();
+ pInt->private = (pointer)xnfcalloc(1,sizeof(genericInt10Priv));
+ entries = SYS_SIZE / pagesize;
+
+ pInt->scrnIndex = screen;
+ INTPriv(pInt)->pagesize_1 = pagesize - 1;
+ INTPriv(pInt)->entries = entries;
+ INTPriv(pInt)->alloc_rec =
+ xnfcalloc(1,sizeof(memType) * entries);
+ for (shift = 0 ; (pagesize >> shift) ; shift++) {};
+ shift -= 1;
+ INTPriv(pInt)->shift = shift;
+
+ /*
+ * we need to map video RAM MMIO as some chipsets map mmio
+ * registers into this range.
+ */
+
+ MapVRam(pInt);
+ intMem = xnfalloc(pagesize);
+ setupTable(pInt,(memType)intMem,0,pagesize);
+ vbiosMem = xnfalloc(V_BIOS_SIZE);
+
+#ifdef _PC
+ if (!sysMem)
+ sysMem = xf86MapVidMem(screen,VIDMEM_FRAMEBUFFER,SYS_BIOS,BIOS_SIZE);
+ setupTable(pInt,(memType)sysMem,SYS_BIOS,BIOS_SIZE);
+ if (xf86ReadBIOS(0,0,(unsigned char *)intMem,LOW_PAGE_SIZE) < 0) {
+ xf86DrvMsg(screen,X_ERROR,"Cannot read int vect\n");
+ goto error1;
+ }
+ if (xf86IsEntityPrimary(entityIndex)) {
+ int size;
+ int cs = MEM_RW(pInt,((0x10<<2)+2));
+
+int i,k,m;
+char buf[100], hx[10];
+for (i=0; i<0x100; i+=16) {
+sprintf(buf,"%04x: ",i);
+for (k=0; k<16; k++) {
+ m = MEM_RB(pInt,i+k);
+ sprintf(hx,"%02x ",((unsigned)m)&0xff);
+ strcat(buf,hx);
+}
+xf86DrvMsg(screen,X_INFO,"%s\n",buf);
+}
+
+
+
+ xf86DrvMsg(screen,X_INFO,"Primary V_BIOS segmant is: 0x%x\n",cs);
+ if (xf86ReadBIOS(cs << 4,0,(unsigned char *)vbiosMem,
+ 0x10) < 0) {
+ xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (1)\n");
+ goto error1;
+ }
+ if (!((*(CARD8*)vbiosMem == 0x55)
+ && (*((CARD8*)vbiosMem + 1) == 0xAA))) {
+ xf86DrvMsg(screen,X_ERROR,"No V_BIOS found\n");
+ goto error1;
+ }
+
+ size = *((CARD8*)vbiosMem + 2) * 512;
+ if (xf86ReadBIOS(cs << 4,0,vbiosMem, size) < 0) {
+ xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (2)\n");
+ goto error1;
+ }
+
+ setupTable(pInt,(memType)vbiosMem,cs<<4,size);
+ set_return_trap(pInt);
+ pInt->BIOSseg = cs;
+ } else {
+ reset_int_vect(pInt);
+ set_return_trap(pInt);
+ if (!mapPciRom(pInt,(unsigned char *)(vbiosMem))) {
+ xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (3)\n");
+ goto error1;
+ }
+ setupTable(pInt,(memType)vbiosMem,V_BIOS,V_BIOS_SIZE);
+ pInt->BIOSseg = V_BIOS >> 4;
+ pInt->num = 0xe6;
+ LockLegacyVGA(pInt, &vga);
+ xf86ExecX86int10(pInt);
+ UnlockLegacyVGA(pInt, &vga);
+ }
+#else
+ if (!sysMem) {
+ sysMem = xnfalloc(BIOS_SIZE);
+ setup_system_bios((memType)sysMem);
+ }
+ setupTable(pInt,(memType)sysMem,SYS_BIOS,BIOS_SIZE);
+ setup_int_vect(pInt);
+ set_return_trap(pInt);
+ if (!mapPciRom(pInt,(unsigned char *)(vbiosMem))) {
+ xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (4)\n");
+ goto error1;
+ }
+ setupTable(pInt,(memType)vbiosMem,V_BIOS,V_BIOS_SIZE);
+ pInt->BIOSseg = V_BIOS >> 4;
+ pInt->num = 0xe6;
+ LockLegacyVGA(pInt, &vga);
+ xf86ExecX86int10(pInt);
+ UnlockLegacyVGA(pInt, &vga);
+#endif
+ return pInt;
+
+ error1:
+ xfree(vbiosMem);
+ xfree(intMem);
+ UnmapVRam(pInt);
+ xfree(INTPriv(pInt)->alloc_rec);
+ xfree(pInt->private);
+ error0:
+ xfree(pInt);
+
+ return NULL;
+}
+
+static void
+MapVRam(xf86Int10InfoPtr pInt)
+{
+ int screen = pInt->scrnIndex;
+ int pagesize = INTPriv(pInt)->pagesize_1 + 1;
+ int size = ((VRAM_SIZE + pagesize - 1)/pagesize) * pagesize;
+ INTPriv(pInt)->vRam = xf86MapVidMem(screen,VIDMEM_MMIO,V_RAM,size);
+}
+
+static void
+UnmapVRam(xf86Int10InfoPtr pInt)
+{
+ int screen = pInt->scrnIndex;
+ int pagesize = INTPriv(pInt)->pagesize_1 + 1;
+ int size = ((VRAM_SIZE + pagesize - 1)/pagesize) * pagesize;
+
+ xf86UnMapVidMem(screen,INTPriv(pInt)->vRam,size);
+}
+
+Bool
+MapCurrentInt10(xf86Int10InfoPtr pInt)
+{
+ /* nothing to do here */
+ return TRUE;
+}
+
+void
+xf86FreeInt10(xf86Int10InfoPtr pInt)
+{
+ int pagesize;
+
+ if (!pInt)
+ return;
+ pagesize = INTPriv(pInt)->pagesize_1 + 1;
+ if (Int10Current == pInt)
+ Int10Current = NULL;
+ xfree(INTPriv(pInt)->alloc_rec[V_BIOS/pagesize]);
+ xfree(INTPriv(pInt)->alloc_rec[0]);
+ UnmapVRam(pInt);
+ xfree(INTPriv(pInt)->alloc_rec);
+ xfree(pInt->private);
+ xfree(pInt);
+}
+
+void *
+xf86Int10AllocPages(xf86Int10InfoPtr pInt,int num, int *off)
+{
+ void* addr;
+ int pagesize = INTPriv(pInt)->pagesize_1 + 1;
+ int num_pages = INTPriv(pInt)->entries;
+ int i,j;
+
+ for (i=0;i<num_pages - num;i++) {
+ if (INTPriv(pInt)->alloc_rec[i] == 0) {
+ for (j=i;j < num + i;j++)
+ if ((INTPriv(pInt)->alloc_rec[j] != 0))
+ break;
+ if (j == num + i)
+ break;
+ else
+ i = i + num;
+ }
+ }
+ if (i == num_pages - num)
+ return NULL;
+
+ *off = i * pagesize;
+ addr = xnfalloc(pagesize * num);
+ setupTable(pInt,(memType)addr,*off,pagesize * num);
+
+ return addr;
+}
+
+void
+xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num)
+{
+ int num_pages = INTPriv(pInt)->entries;
+ int i,j;
+ for (i = 0;i<num_pages - num; i++)
+ if (INTPriv(pInt)->alloc_rec[i]==(memType)pbase) {
+ for (j = 0; j < num; j++)
+ INTPriv(pInt)->alloc_rec[i] = 0;
+ break;
+ }
+ xfree(pbase);
+ return;
+}
+
+static void
+setupTable(xf86Int10InfoPtr pInt, memType address,int loc,int size)
+{
+ int pagesize = INTPriv(pInt)->pagesize_1 + 1;
+ int i,j,num;
+
+ i = loc / pagesize;
+ num = (size + pagesize - 1)/ pagesize; /* round up to the nearest page */
+ /* boudary if size is not */
+ /* multiple of pagesize */
+ for (j = 0; j<num; j++) {
+ INTPriv(pInt)->alloc_rec[i+j] = address;
+ address += pagesize;
+ }
+}
+
+#define OFF(addr) \
+ ((addr) & (INTPriv(pInt)->pagesize_1))
+#define SHIFT \
+ (INTPriv(pInt)->shift)
+#define BASE(addr,shift) \
+ (INTPriv(pInt)->alloc_rec[addr >> shift])
+#define V_ADDR(addr,shift,off) \
+ (BASE(addr,shift) + (off))
+#define VRAM_ADDR(addr) (addr - 0xA0000)
+#define VRAM_BASE (INTPriv(pInt)->vRam)
+
+#define VRAM(addr) ((addr >= 0xA0000) && (addr <= 0xBFFFF))
+#define V_ADDR_RB(addr,shift,off) \
+ (VRAM(addr)) ? MMIO_IN8((CARD8*)VRAM_BASE,VRAM_ADDR(addr)) \
+ : *(CARD8*) V_ADDR(addr,shift,off)
+#define V_ADDR_RW(addr,shift,off) \
+ (VRAM(addr)) ? MMIO_IN16((CARD16*)VRAM_BASE,VRAM_ADDR(addr)) \
+ : ldw_u((pointer)V_ADDR(addr,shift,off))
+#define V_ADDR_RL(addr,shift,off) \
+ (VRAM(addr)) ? MMIO_IN32((CARD32*)VRAM_BASE,VRAM_ADDR(addr)) \
+ : ldl_u((pointer)V_ADDR(addr,shift,off))
+
+#define V_ADDR_WB(addr,shift,off,val) \
+ if(VRAM(addr)) \
+ MMIO_OUT8((CARD8*)VRAM_BASE,VRAM_ADDR(addr),val); \
+ else \
+ *(CARD8*) V_ADDR(addr,shift,off) = val;
+#define V_ADDR_WW(addr,shift,off,val) \
+ if(VRAM(addr)) \
+ MMIO_OUT16((CARD16*)VRAM_BASE,VRAM_ADDR(addr),val); \
+ else \
+ stw_u((val),(pointer)(V_ADDR(addr,shift,off)));
+
+#define V_ADDR_WL(addr,shift,off,val) \
+ if (VRAM(addr)) \
+ MMIO_OUT32((CARD32*)VRAM_BASE,VRAM_ADDR(addr),val); \
+ else \
+ stl_u(val,(pointer)(V_ADDR(addr,shift,off)));
+
+static CARD8
+read_b(xf86Int10InfoPtr pInt, int addr)
+{
+ if (!BASE(addr,SHIFT)) return 0xff;
+
+ return V_ADDR_RB(addr,SHIFT,OFF(addr));
+}
+
+static CARD16
+read_w(xf86Int10InfoPtr pInt, int addr)
+{
+ int shift = SHIFT;
+ int off = OFF(addr);
+
+ if (!BASE(addr,shift)) return 0xffff;
+
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ return ((V_ADDR_RB(addr,shift,off))
+ || ((V_ADDR_RB(addr,shift,off + 1)) << 8));
+#else
+ if (OFF(addr + 1) > 0) {
+ return V_ADDR_RW(addr,SHIFT,OFF(addr));
+ } else {
+ return ((V_ADDR_RB(addr,shift,off + 1))
+ || ((V_ADDR_RB(addr,shift,off)) << 8));
+ }
+#endif
+}
+
+static CARD32
+read_l(xf86Int10InfoPtr pInt, int addr)
+{
+ int shift = SHIFT;
+ int off = OFF(addr);
+
+ if (!BASE(addr,shift)) return 0xffffffff;
+
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ return ((V_ADDR_RB(addr,shift,off))
+ || ((V_ADDR_RB(addr,shift,off + 1)) << 8)
+ || ((V_ADDR_RB(addr,shift,off + 2)) << 16)
+ || ((V_ADDR_RB(addr,shift,off + 3)) << 24));
+#else
+ if (OFF(addr + 3) > 2) {
+ return V_ADDR_RL(addr,SHIFT,OFF(addr));
+ } else {
+ return ((V_ADDR_RB(addr,shift,off + 3))
+ || ((V_ADDR_RB(addr,shift,off + 2)) << 8)
+ || ((V_ADDR_RB(addr,shift,off + 1)) << 16)
+ || ((V_ADDR_RB(addr,shift,off)) << 24));
+ }
+#endif
+}
+
+static void
+write_b(xf86Int10InfoPtr pInt, int addr, CARD8 val)
+{
+ if (!BASE(addr,SHIFT)) return;
+
+ V_ADDR_WB(addr,SHIFT,OFF(addr),val);
+}
+
+static void
+write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val)
+{
+ int shift = SHIFT;
+ int off = OFF(addr);
+
+ if (!BASE(addr,shift)) return;
+
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ V_ADDR_WB(addr,shift,off,val);
+ V_ADDR_WB(addr,shift,off + 1,val >> 8);
+#else
+ if (OFF(addr + 1) > 0) {
+ V_ADDR_WW(addr,shift,OFF(addr),val);
+ } else {
+ V_ADDR_WB(addr,shift,off + 1,val);
+ V_ADDR_WB(addr,shift,off,val >> 8);
+ }
+#endif
+}
+
+static void
+write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val)
+{
+ int shift = SHIFT;
+ int off = OFF(addr);
+ if (!BASE(addr,shift)) return;
+
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+ V_ADDR_WB(addr,shift,off,val);
+ V_ADDR_WB(addr,shift,off + 1, val >> 8);
+ V_ADDR_WB(addr,shift,off + 2, val >> 16);
+ V_ADDR_WB(addr,shift,off + 3, val >> 24);
+#else
+ if (OFF(addr + 3) > 2) {
+ V_ADDR_WL(addr,shift,OFF(addr),val);
+ } else {
+ V_ADDR_WB(addr,shift,off + 3, val);
+ V_ADDR_WB(addr,shift,off + 2, val >> 8);
+ V_ADDR_WB(addr,shift,off + 1, val >> 16);
+ V_ADDR_WB(addr,shift,off, val >> 24);
+ }
+#endif
+}
+
+pointer
+xf86int10Addr(xf86Int10InfoPtr pInt, CARD32 addr)
+{
+ return (pointer) V_ADDR(addr,SHIFT,OFF(addr));
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_VTsw.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_VTsw.c
new file mode 100644
index 000000000..e050a62cb
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_VTsw.c
@@ -0,0 +1,340 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_VTsw.c,v 3.13 2003/06/10 17:03:54 dawes Exp $ */
+/*
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ * Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: os2_VTsw.c /main/7 1996/05/13 16:37:55 kaleb $ */
+
+#define I_NEED_OS2_H
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#define INCL_WINSWITCHLIST
+#define INCL_VIO
+#define INCL_KBD
+#define INCL_DOSPROCESS
+#define INCL_DOSSEMAPHORES
+#define INCL_DOSERRORS
+#undef RT_FONT
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+
+BOOL SwitchedToWPS=FALSE;
+BOOL WaitingForAccess=FALSE;
+void os2PostKbdEvent();
+HEV hevServerHasFocus;
+HEV hevSwitchRequested;
+HEV hevErrorPopupDetected;
+extern HEV hevPopupPending;
+extern HEV hSwitchToSem;
+BOOL os2PopupErrorPending=FALSE;
+
+/*
+ * Added OS/2 code to handle switching back to WPS
+ */
+
+
+Bool xf86VTSwitchPending()
+{
+ return(xf86Info.vtRequestsPending ? TRUE : FALSE);
+}
+
+Bool xf86VTSwitchAway()
+{
+ APIRET rc;
+ ULONG drive;
+
+ xf86Info.vtRequestsPending=FALSE;
+ SwitchedToWPS=TRUE;
+
+ rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
+ rc = DosSuppressPopUps(0x0000L,drive+96); /* Disable popups */
+ DosPostEventSem(hevSwitchRequested);
+ usleep(30000);
+ return(TRUE);
+}
+
+Bool xf86VTSwitchTo()
+{
+ APIRET rc;
+ ULONG drive,postCount;
+
+ xf86Info.vtRequestsPending=FALSE;
+ SwitchedToWPS=FALSE;
+ rc = DosResetEventSem(hSwitchToSem,&postCount);
+ DosPostEventSem(hevSwitchRequested);
+ rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
+ rc = DosSuppressPopUps(0x0001L,drive+96); /* Disable popups */
+
+ /* We reset the state of the control key */
+ os2PostKbdEvent(KEY_LCtrl,1);
+ os2PostKbdEvent(KEY_LCtrl,0);
+ os2PostKbdEvent(KEY_RCtrl,1);
+ os2PostKbdEvent(KEY_RCtrl,0);
+ os2PostKbdEvent(KEY_Alt,1);
+ os2PostKbdEvent(KEY_Alt,0);
+ return(TRUE);
+}
+
+
+/* This function is run as a thread and will notify of switch-to/switch-away events */
+void os2VideoNotify(arg)
+void * arg;
+{
+ USHORT Indic;
+ USHORT NotifyType;
+ APIRET rc;
+ ULONG postCount;
+ Bool FirstTime=TRUE;
+ int timeout_count;
+
+ rc=DosCreateEventSem(NULL,&hevServerHasFocus,0L,FALSE);
+ rc=DosPostEventSem(hevServerHasFocus);
+ rc=DosCreateEventSem(NULL,&hevSwitchRequested,0L,FALSE);
+ rc=DosPostEventSem(hevSwitchRequested);
+
+
+ while(1) {
+ Indic=0;
+ rc=VioSavRedrawWait(Indic,&NotifyType,(HVIO)0);
+
+/* Here we handle the semaphore used to indicate wether we have screen access */
+ if(NotifyType==0) rc=DosResetEventSem(hevServerHasFocus,&postCount);
+ if(FirstTime){
+ FirstTime=FALSE;
+ if(NotifyType==1) NotifyType=65535; /* In case a redraw is requested on first call */
+ }
+
+ if(NotifyType==1){
+/* Notify os2PseudoSelect() that we are back */
+ rc=DosPostEventSem(hSwitchToSem);
+ if (rc) xf86Msg(X_ERROR,"Post SwitchToSem returned %d\n");
+/* Sanity check */
+ if (!SwitchedToWPS) {
+ xf86Msg(X_ERROR,
+ "Abnormal switching back to server detected\n");
+ }
+ }
+
+/* Here we set the semaphore used to indicate switching request */
+
+ if((NotifyType!=65535)&&(!WaitingForAccess)) {
+ rc=DosResetEventSem(hevSwitchRequested,&postCount);
+ xf86Info.vtRequestsPending=TRUE;
+/* Then wait for semaphore to be posted once switch is complete. Wait 20 secs, then kill server */
+ timeout_count=0;
+ rc=DosSetPriority(2,3,0,1);
+ do {
+ rc=DosWaitEventSem(hevSwitchRequested,1000L);
+ if(rc==ERROR_TIMEOUT){
+ timeout_count++;
+ if(timeout_count>25){
+ xf86Msg(X_ERROR,
+ "Server timeout on VT switch request. Server was killed\n");
+ DosExit(1L,0);
+ }
+ if(WaitingForAccess) { /* The server is resetting */
+ DosPostEventSem(hevSwitchRequested);
+ xf86Info.vtRequestsPending=FALSE;
+ }
+ }
+ } while (rc==ERROR_TIMEOUT);
+ rc=DosSetPriority(2,2,0,1);
+ }
+ if(NotifyType==1) rc=DosPostEventSem(hevServerHasFocus);
+ if((NotifyType==0)&&(!SwitchedToWPS))
+ xf86Msg(X_ERROR,
+ "Abnormal switching away from server!\n");
+ } /* endwhile */
+
+/* End of thread */
+}
+
+/* This function is run as a thread and will notify of hard-error events */
+void os2HardErrorNotify(arg)
+void * arg;
+{
+ USHORT Indic;
+ USHORT NotifyType;
+ APIRET rc;
+ ULONG postCount;
+
+ rc=DosCreateEventSem(NULL,&hevErrorPopupDetected,0L,FALSE);
+ rc=DosPostEventSem(hevErrorPopupDetected);
+ os2PopupErrorPending=FALSE;
+
+ while(1) {
+ Indic=0;
+ rc=VioModeWait(Indic,&NotifyType,(HVIO)0);
+ if(NotifyType==0){
+ os2PopupErrorPending=TRUE;
+ rc=DosPostEventSem(hSwitchToSem);
+ rc=DosResetEventSem(hevErrorPopupDetected,&postCount);
+ rc=DosWaitEventSem(hevErrorPopupDetected,20000L);
+ if(rc==ERROR_TIMEOUT) GiveUp(0); /* Shutdown on timeout of semaphore */
+ }
+ } /* endwhile */
+
+/* End of thread */
+}
+
+static BOOL is_redirected = FALSE;
+
+static void
+redirect_output(void)
+{
+ /* hv300996 create redirect file on boot drive, instead
+ * anywhere you are just standing
+ */
+ char buf[20],dr[3];
+ ULONG drive;
+ APIRET rc;
+
+ if (is_redirected) return;
+
+ if ((rc = DosQuerySysInfo(5,5,&drive,sizeof(drive))) != 0)
+ dr[0] = 0;
+ else {
+ dr[0] = drive+96;
+ dr[1] = ':';
+ dr[2] = 0;
+ }
+ sprintf(buf,"%s\\xf86log.os2",dr);
+
+ ErrorF("\nThis is the XFree86/OS2-4.0 server\n");
+ ErrorF("\nAll output from now on will be redirected to %s\n",buf);
+ freopen(buf,"w",stderr);
+
+ is_redirected = TRUE;
+}
+
+void
+os2ServerVideoAccess()
+{
+ APIRET rc;
+ ULONG fgSession;
+ ULONG length=4;
+ CHAR Status;
+
+ /* Redirect output as early as possible */
+ /* redirect_output(); */
+ /* too many logfiles, server will log to /usr/adm */
+
+/* Wait for screen access. This is called at server reset or at server startup */
+/* Here we do some waiting until this session comes in the foreground before *
+ * going any further. This is because we may have been started in the bg */
+
+ if(serverGeneration==1){
+ rc=VioScrLock(0, &Status, (HVIO)0);
+ while(Status != 0){
+ rc=VioScrLock(0, &Status, (HVIO)0);
+ DosSleep(1000);
+ }
+ VioScrUnLock((HVIO)0);
+ return;
+ }
+ WaitingForAccess=TRUE;
+ rc=DosWaitEventSem(hevServerHasFocus,SEM_INDEFINITE_WAIT);
+ WaitingForAccess=FALSE;
+ SwitchedToWPS=FALSE; /* In case server has reset while we were switched to WPS */
+}
+
+/* This next function will attempt to recover from a hard error popup
+ * with an EnterLeave call
+ */
+
+void os2RecoverFromPopup()
+{
+ int j;
+ ULONG postCount;
+
+ if (os2PopupErrorPending) {
+#if 0
+ for (j = 0; j < screenInfo.numScreens; j++)
+ (XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(LEAVE, j);
+ for (j = 0; j < screenInfo.numScreens; j++)
+ (XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(ENTER, j);
+#endif
+ DosResetEventSem(hSwitchToSem,&postCount);
+
+ for (j = 0; j < xf86NumScreens; j++) {
+ if (xf86Screens[j]->EnableDisableFBAccess)
+ (*xf86Screens[j]->EnableDisableFBAccess)(j, FALSE);
+ }
+ xf86EnterServerState(SETUP);
+ for (j = 0; j < xf86NumScreens; j++)
+ xf86Screens[j]->LeaveVT(j, 0);
+ for (j = 0; j < xf86NumScreens; j++) {
+ xf86Screens[j]->EnterVT(j, 0);
+ }
+ xf86EnterServerState(OPERATING);
+ for (j = 0; j < xf86NumScreens; j++) {
+ if (xf86Screens[j]->EnableDisableFBAccess)
+ (*xf86Screens[j]->EnableDisableFBAccess)(j, TRUE);
+ }
+
+ /* We reset the state of the control key */
+ os2PostKbdEvent(KEY_LCtrl,1);
+ os2PostKbdEvent(KEY_LCtrl,0);
+ os2PostKbdEvent(KEY_RCtrl,1);
+ os2PostKbdEvent(KEY_RCtrl,0);
+ os2PostKbdEvent(KEY_Alt,1);
+ os2PostKbdEvent(KEY_Alt,0);
+
+ /* Turn screen saver off when switching back */
+ SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset);
+ os2PopupErrorPending=FALSE;
+ DosPostEventSem(hevErrorPopupDetected);
+ }
+}
+
+/* This checks wether a popup event is waiting. The semaphore would be reset
+ * by the XF86VIO.DLL function
+ */
+
+void os2CheckPopupPending()
+{
+ int j;
+ ULONG postCount;
+
+ return; /* For now this is a no-op */
+
+#if 0
+ DosQueryEventSem(hevPopupPending,&postCount);
+ if (postCount==0) { /* We have a popup pending */
+#if 0
+ for (j = 0; j < screenInfo.numScreens; j++)
+ (XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(LEAVE, j);
+#endif
+ DosPostEventSem(hevPopupPending);
+ }
+#endif
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_bios.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_bios.c
new file mode 100644
index 000000000..4069ad745
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_bios.c
@@ -0,0 +1,143 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_bios.c,v 3.10 2000/04/05 18:13:52 dawes Exp $ */
+/*
+ * (c) Copyright 1994 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ * Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium: os2_bios.c /main/5 1996/10/27 11:48:45 kaleb $ */
+
+#define I_NEED_OS2_H
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#define INCL_32
+#define INCL_DOS
+#define INCL_DOSFILEMGR
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * Read BIOS via xf86sup.SYS device driver
+ */
+
+static APIRET doioctl(HFILE fd,ULONG addr,ULONG len,unsigned char* dbuf)
+{
+ UCHAR *dta;
+ ULONG plen,dlen;
+ APIRET rc;
+
+ struct {
+ ULONG command;
+ ULONG physaddr;
+ USHORT numbytes;
+ } par;
+
+ /* prepare parameter and data packets for ioctl */
+ par.command = 0;
+ par.physaddr = addr;
+ par.numbytes = dlen = len;
+ plen = sizeof(par);
+
+ /* issue call to get a readonly copy of BIOS ROM */
+ rc = DosDevIOCtl(fd, (ULONG)0x76, (ULONG)0x64,
+ (PVOID)&par, (ULONG)plen, (PULONG)&plen,
+ (PVOID)dbuf, (ULONG)dlen, (PULONG)&dlen);
+
+ return rc;
+}
+
+int xf86ReadBIOS(Base, Offset, Buf, Len)
+unsigned long Base;
+unsigned long Offset;
+unsigned char *Buf;
+int Len;
+{
+ HFILE fd;
+ int i;
+ ULONG action;
+ APIRET rc;
+ ULONG Phys_address;
+ UCHAR* dta;
+ int off, chunksz,lensave;
+
+ /* allocate dta */
+ dta = (UCHAR*)xalloc(Len);
+
+ Phys_address=Base+Offset;
+
+ /* open the special device pmap$ (default with OS/2) */
+ if (DosOpen((PSZ)"PMAP$", (PHFILE)&fd, (PULONG)&action,
+ (ULONG)0, FILE_SYSTEM, FILE_OPEN,
+ OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
+ (ULONG)0) != 0) {
+ FatalError("xf86ReadBIOS: install DEVICE=path\\xf86sup.SYS!");
+ return -1;
+ }
+
+ /* copy 32K at a time */
+ off = 0;
+ lensave = Len;
+ while (Len > 0) {
+ chunksz = (Len > 32768) ? 32768 : Len;
+ Len -= chunksz;
+ rc = doioctl(fd,(ULONG)Phys_address,chunksz,dta+off);
+ if (rc != 0) {
+ FatalError("xf86ReadBIOS: BIOS map failed, addr=%lx, rc=%d\n",
+ Phys_address,rc);
+ xfree(dta);
+ DosClose(fd);
+ return -1;
+ }
+ off += chunksz;
+ }
+
+ /*
+ * Sanity check... No longer fatal, as some PS/1 and PS/2 fail here but still work.
+ * S. Marineau, 10/10/96
+ */
+#if 0
+ if ((Phys_address & 0x7fff) != 0 &&
+ (dta[0] != 0x55 || dta[1] != 0xaa)) {
+ FatalError("BIOS sanity check failed, addr=%x\nPlease report if you encounter problems\n",
+ Phys_address);
+ }
+#endif
+
+ /* copy data to buffer */
+ memcpy(Buf, dta, lensave);
+ xfree(dta);
+
+ /* close device */
+ DosClose(fd);
+
+ return(lensave);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_diag.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_diag.c
new file mode 100644
index 000000000..f321df5c2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_diag.c
@@ -0,0 +1,263 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_diag.c,v 3.7 2000/04/05 18:13:52 dawes Exp $ */
+/*
+ * (c) Copyright 1997 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium$ */
+
+/* This file checks whether the user has installed the system correctly,
+ * to avoid the numerous questions why this or that does not work
+ */
+
+#define I_NEED_OS2_H
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#define INCL_DOSFILEMGR
+#define INCL_KBD
+#define INCL_VIO
+#define INCL_DOSMISC
+#define INCL_DOSPROCESS
+#define INCL_DOSSEMAPHORES
+#define INCL_DOSMODULEMGR
+#define INCL_DOSFILEMGR
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include <netdb.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+static BOOL diag_checks = FALSE;
+
+/* from Eberhard to check for the right EMX version */
+static void
+check_emx (void)
+{
+ ULONG rc;
+ HMODULE hmod;
+ char name[CCHMAXPATH];
+ char fail[9];
+
+ if (_emx_rev < 50) {
+ xf86Msg(X_ERROR,"This program requires emx.dll revision 50 (0.9c fix 2) "
+ "or later.\n");
+ rc = DosLoadModule (fail, sizeof (fail), "emx", &hmod);
+ if (rc == 0) {
+ rc = DosQueryModuleName (hmod, sizeof (name), name);
+ if (rc == 0)
+ xf86Msg(X_ERROR,"Please delete or update `%s'.\n", name);
+ DosFreeModule (hmod);
+ }
+ exit (2);
+ }
+}
+
+static void
+check_bsl(const char *var)
+{
+ char *t1 = strrchr(var,'\\');
+ if (strchr(var,'/')) {
+ xf86Msg(X_WARNING,
+ "\"%s\" must exclusively use backward slashes \"\\\"\n",
+ var);
+ }
+ if (t1 && *(t1+1)=='\0') {
+ xf86Msg(X_WARNING,
+ "\"%s\" mustn't end with \"\\\"\n",var);
+ *t1 = '\0';
+ }
+}
+
+
+static void
+check_fsl(const char *var)
+{
+ char *t1 = strrchr(var,'/');
+ if (strchr(var,'\\')) {
+ xf86Msg(X_WARNING,
+ "\"%s\" must exclusively use forward slashes \"/\"\n",
+ var);
+ }
+}
+
+
+static void
+check_long(const char* path)
+{
+ FILE *f;
+ char n[300];
+
+ sprintf(n,"%s\\xf86_test_for_very_long_filename",path);
+ f = fopen(n,"w");
+ if (f==NULL) {
+ xf86Msg(X_WARNING,
+ "\"%s\" does not accept long filenames\nmust reside on HPFS or similar\n",
+ path);
+ } else {
+ fclose(f);
+ unlink(n);
+ }
+}
+
+static char *
+check_env_present(const char *env)
+{
+ char *e = getenv(env);
+ if (!e) {
+ xf86Msg(X_WARNING,
+ "You have no \"%s\" environment variable, but need one\n",
+ env);
+ return 0;
+ }
+ return e;
+}
+
+void os2_checkinstallation(void)
+{
+ char *emxopt, *tmp, *home, *logname, *termcap;
+ char hostname[256], *display, *hostvar, *s, *h;
+ struct hostent *hent;
+ struct in_addr *in;
+ int i;
+
+ if (diag_checks) return;
+ diag_checks = TRUE;
+
+ /* test whether the EMX version is okay */
+ check_emx();
+
+ /* Check a number of environment variables */
+ emxopt = getenv("EMXOPT");
+ if (emxopt) {
+ for (i=0; i<strlen(emxopt); i++) {
+ if (emxopt[i]=='-') {
+ switch (emxopt[++i]) {
+ case 't':
+ xf86Msg(X_ERROR,
+ "Remove -t option from EMXOPT variable!\n");
+ break;
+ case 'r':
+ xf86Msg(X_ERROR,
+ "Remove -r option from EMXOPT variable!\n");
+ }
+ }
+ }
+ }
+
+ tmp = check_env_present("TMP");
+ if (tmp) {
+ check_bsl(tmp);
+ check_long(tmp);
+ }
+
+ home = check_env_present("HOME");
+ if (home) {
+ check_bsl(home);
+ check_long(home);
+ }
+
+ logname = check_env_present("LOGNAME");
+ termcap = check_env_present("TERMCAP");
+ if (termcap)
+ check_fsl(termcap);
+
+ if (gethostname(hostname,sizeof(hostname)) != 0) {
+ xf86Msg(X_ERROR,
+ "gethostname() failed: Check TCP/IP setup!\n");
+ } else {
+ xf86Msg(X_INFO,
+ "gethostname() returns: \"%s\"\n",hostname);
+ }
+
+ display = check_env_present("DISPLAY");
+ if (display)
+ xf86Msg(X_INFO,
+ "DISPLAY to listen is set to: \"%s\"\n",
+ display);
+
+ hostvar = check_env_present("HOSTNAME");
+
+ strcpy(hostname,display);
+ h = strchr(hostname,':');
+ if (!h)
+ xf86Msg(X_WARNING,
+ "Invalid DISPLAY name: expected something like XXX:0.0\n");
+ else
+ *h = 0;
+ h = strchr(hostname,'/');
+ if (h)
+ h++;
+ else
+ h = hostname;
+
+ if (stricmp(h,hostvar)) {
+ xf86Msg(X_WARNING,
+ "HOSTNAME does not match DISPLAY: Do you really mean this?\n");
+ xf86Msg(X_WARNING,
+ " This means that xinit/startx and client access may not work\n");
+ xf86Msg(X_WARNING,
+ " which is intentional usually only when connection to a XDM server\n");
+ }
+
+ hent = gethostbyname(h);
+ if (!hent)
+ xf86Msg(X_ERROR,
+ "gethostbyname() failed: Check TCP/IP setup\n");
+ else {
+ xf86Msg(X_INFO,
+ "gethostbyname() returns the following data:\n");
+ xf86Msg(X_INFO," official host name: \"%s\"\n",hent->h_name);
+ while ((s= *(hent->h_aliases)) != NULL) {
+ xf86Msg(X_INFO,
+ " alias: \"%s\"\n",s);
+ hent->h_aliases++;
+ }
+ xf86Msg(X_INFO,
+ " addr type = %d, addr length = %d\n",
+ hent->h_addrtype, hent->h_length);
+ if (hent->h_addrtype == AF_INET) {
+ while ((in= (struct in_addr*)*(hent->h_addr_list++)) != NULL) {
+ xf86Msg(X_INFO,
+ " IP address: \"%s\"\n",
+ inet_ntoa(*in));
+ }
+ } else {
+ xf86Msg(X_INFO,
+ "Addrtype should be %d: Check network setup and install TCP/IP support correctly\n",
+ AF_INET);
+ }
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_init.c
new file mode 100644
index 000000000..81b2689b8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_init.c
@@ -0,0 +1,244 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_init.c,v 3.18 2003/11/29 01:48:31 dawes Exp $ */
+/*
+ * (c) Copyright 1994 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ * Modified 1996 Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium: os2_init.c /main/9 1996/10/19 18:07:13 kaleb $ */
+
+#define I_NEED_OS2_H
+#define INCL_DOSFILEMGR
+#define INCL_KBD
+#define INCL_VIO
+#define INCL_DOSMISC
+#define INCL_DOSPROCESS
+#define INCL_DOSSEMAPHORES
+#define INCL_DOSMODULEMGR
+#define INCL_DOSFILEMGR
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <float.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+VIOMODEINFO OriginalVideoMode;
+void os2VideoNotify();
+void os2HardErrorNotify();
+void os2KbdMonitorThread();
+void os2KbdBitBucketThread();
+HEV hevPopupPending;
+extern HEV hKbdSem;
+extern BOOL os2HRTimerFlag;
+static unsigned short cw;
+extern void os2_checkinstallation(); /* os2_diag.c */
+
+void xf86OpenConsole()
+{
+ /* try to catch problems before they become obvious */
+ os2_checkinstallation();
+
+ if (serverGeneration == 1) {
+ HKBD fd;
+ ULONG drive;
+ ULONG dummy;
+ KBDHWID hwid;
+ APIRET rc;
+ int VioTid;
+ ULONG actual_handles;
+ LONG new_handles;
+
+ /* hv 250197 workaround for xkb-Problem: switch to X11ROOT drive */
+ char *x11r = getenv("X11ROOT");
+ /* Make sure X11ROOT is set before we go further sm280297 */
+ if (x11r == NULL){
+ xf86Msg(X_ERROR,
+ "Environment variable X11ROOT is not set! Aborting...\n");
+ exit(1);
+ }
+ if (_chdir2(x11r) < 0) {
+ xf86Msg(X_ERROR,"Cannot change to X11ROOT directory!\n");
+ }
+
+ xf86Msg(X_INFO,"Console opened\n");
+ OriginalVideoMode.cb=sizeof(VIOMODEINFO);
+ rc=VioGetMode(&OriginalVideoMode,(HVIO)0);
+ if(rc!=0)
+ xf86Msg(X_ERROR,
+ "Could not get original video mode. RC=%d\n",rc);
+ xf86Info.consoleFd = -1;
+
+ /* Set the number of handles to higher than the default 20. Set to 80 which should be plenty */
+ new_handles = 0;
+ rc = DosSetRelMaxFH(&new_handles,&actual_handles);
+ if (actual_handles < 80) {
+ new_handles = 80 - actual_handles;
+ rc = DosSetRelMaxFH(&new_handles,&actual_handles);
+ xf86Msg(X_INFO,"Increased number of available handles to %d\n",
+ actual_handles);
+ }
+
+ /* grab the keyboard */
+ rc = KbdGetFocus(0,0);
+ if (rc != 0)
+ FatalError("xf86OpenConsole: cannot grab kbd focus, rc=%d\n",rc);
+
+ /* open the keyboard */
+ rc = KbdOpen(&fd);
+ if (rc != 0)
+ FatalError("xf86OpenConsole: cannot open keyboard, rc=%d\n",rc);
+ xf86Info.consoleFd = fd;
+
+ xf86Msg(X_INFO,"Keyboard opened\n");
+
+ /* assign logical keyboard */
+ KbdFreeFocus(0);
+ rc = KbdGetFocus(0,fd);
+ if (rc != 0)
+ FatalError("xf86OpenConsole: cannot set local kbd focus, rc=%d\n",rc);
+
+/* Create kbd queue semaphore */
+
+ rc = DosCreateEventSem(NULL,&hKbdSem,DC_SEM_SHARED,TRUE);
+ if (rc != 0)
+ FatalError("xf86OpenConsole: cannot create keyboard queue semaphore, rc=%d\n",rc);
+
+/* Create popup semaphore */
+
+ rc = DosCreateEventSem("\\SEM32\\XF86PUP",&hevPopupPending,DC_SEM_SHARED,1);
+ if (rc)
+ xf86Msg(X_ERROR,
+ "Could not create popup semaphore! RC=%d\n",rc);
+#if 0
+ rc=VioRegister("xf86vio","XF86POPUP_SUBCLASS",0x20002004L,0L);
+ if (rc) {
+ FatalError("Could not register XF86VIO.DLL module. Please install in LIBPATH! RC=%d\n",
+ rc);
+ }
+#endif
+
+/* Start up the VIO monitor thread */
+ VioTid=_beginthread(os2VideoNotify,NULL,0x4000,(void *)NULL);
+ xf86Msg(X_INFO,"Started Vio thread, Tid=%d\n",VioTid);
+ rc=DosSetPriority(2,3,0,VioTid);
+
+/* Start up the hard-error VIO monitor thread */
+ VioTid=_beginthread(os2HardErrorNotify,NULL,0x4000,(void *)NULL);
+ xf86Msg(X_INFO,"Started hard error Vio mode monitor thread, Tid=%d\n",
+ VioTid);
+ rc=DosSetPriority(2,3,0,VioTid);
+
+/* We have to set the codepage before the keyboard monitor is registered */
+ rc = KbdSetCp(0,0,fd);
+ if(rc != 0)
+ FatalError("xf86OpenConsole: cannot set keyboard codepage, rc=%d\n",rc);
+
+/* Start up the kbd monitor thread */
+ VioTid=_beginthread(os2KbdMonitorThread,NULL,0x4000,(void *)NULL);
+ xf86Msg(X_INFO,"Started Kbd monitor thread, Tid=%d\n",VioTid);
+ rc=DosSetPriority(2,3,0,VioTid);
+
+/* Disable hard-errors through DosError */
+ rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
+ rc = DosSuppressPopUps(0x0001L,drive+96); /* Disable popups */
+
+ hwid.cb = sizeof(hwid); /* fix crash on P9000 */
+ rc = KbdGetHWID(&hwid, fd);
+ if (rc == 0) {
+ switch (hwid.idKbd) {
+ default:
+ case 0xab54: /* 88/89 key */
+ case 0: /*unknown*/
+ case 1: /*real AT 84 key*/
+ xf86Info.kbdType = KB_84; break;
+ case 0xab85: /* 122 key */
+ FatalError("Unsupported extended 122key keyboard found!\n",0);
+ case 0xab41: /* 101/102 key */
+ xf86Info.kbdType = KB_101; break;
+ }
+ } else
+ xf86Info.kbdType = KB_84; /*defensive*/
+
+/* Start up the Kbd bit-bucket thread. We don't want to leave the kbd events in the driver queue */
+ VioTid=_beginthread(os2KbdBitBucketThread,NULL,0x2000,(void *)NULL);
+ xf86Msg(X_INFO,"Started Kbd bit-bucket thread, Tid=%d\n",VioTid);
+
+/* fg271103: set control word of FPU to default value to prevent SIGFPE in GLX (and elsewhere?) */
+
+#define DEFAULT_X86_FPU 0x037f
+
+ cw = _control87(DEFAULT_X86_FPU, 0xFFFF);
+ xf86Msg(X_INFO,"Checking FPCW: %#x\n",cw);
+
+ if (cw != DEFAULT_X86_FPU) {
+ cw = _control87(0,0);
+ xf86Msg(X_INFO,"Set FPCW to %#x\n",cw);
+ }
+
+ }
+ return;
+}
+
+void xf86CloseConsole()
+{
+ APIRET rc;
+ ULONG drive;
+
+ if (xf86Info.consoleFd != -1) {
+ KbdClose(xf86Info.consoleFd);
+ }
+ VioSetMode(&OriginalVideoMode,(HVIO)0);
+ rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
+ rc = DosSuppressPopUps(0x0000L,drive+96); /* Reenable popups */
+ rc = DosCloseEventSem(hevPopupPending);
+ rc = VioDeRegister();
+ return;
+}
+
+/* ARGSUSED */
+
+int xf86ProcessArgument (argc, argv, i)
+int argc;
+char *argv[];
+int i;
+{
+ return 0;
+}
+
+void xf86UseMsg()
+{
+ return;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_io.c
new file mode 100644
index 000000000..e6570aeb9
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_io.c
@@ -0,0 +1,257 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_io.c,v 3.19 2003/11/17 22:20:41 dawes Exp $ */
+/*
+ * (c) Copyright 1994,1999 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ * Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium: os2_io.c /main/9 1996/05/13 16:38:07 kaleb $ */
+
+#define I_NEED_OS2_H
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xpoll.h>
+#include "compiler.h"
+#include <time.h>
+
+#define INCL_DOSPROCESS
+#define INCL_KBD
+#define INCL_MOU
+#define INCL_DOSDEVIOCTL
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+int os2MouseQueueQuery();
+int os2KbdQueueQuery();
+void os2RecoverFromPopup();
+void os2CheckPopupPending();
+extern BOOL os2PopupErrorPending;
+int _select2 (int, fd_set *, fd_set *,fd_set *, struct timeval *);
+
+
+/***************************************************************************/
+
+void xf86SoundKbdBell(loudness, pitch, duration)
+int loudness;
+int pitch;
+int duration;
+{
+ DosBeep((ULONG)pitch, (ULONG)duration);
+}
+
+void xf86SetKbdLeds(leds)
+int leds;
+{
+ KBDINFO kinfo;
+ APIRET rc;
+
+ rc = KbdGetStatus(&kinfo,(HKBD)xf86Info.consoleFd);
+ if (!rc) {
+ kinfo.fsMask = 0x10;
+ kinfo.fsState &= ~0x70;
+ kinfo.fsState |= (leds&0x70);
+ KbdSetStatus(&kinfo,(HKBD)xf86Info.consoleFd);
+ }
+}
+
+int xf86GetKbdLeds()
+{
+ KBDINFO kinfo;
+ APIRET rc;
+
+ rc = KbdGetStatus(&kinfo,(HKBD)xf86Info.consoleFd);
+ return rc ? 0 : kinfo.fsState & 0x70;
+}
+
+void xf86SetKbdRepeat(char rad)
+{
+ int rc;
+ int delay = 250; /* Default delay */
+ int rate = 30; /* Default repeat rate */
+
+ struct {
+ USHORT Delay;
+ USHORT Rate;
+ } rateDelay;
+
+ ULONG rateDelaySize = sizeof(rateDelay);
+
+ /*notyet*/
+ return;
+
+ if (xf86Info.kbdRate >= 0)
+ rate = xf86Info.kbdRate;
+ if (xf86Info.kbdDelay >= 0)
+ delay = xf86Info.kbdDelay;
+
+ rateDelay.Delay = delay;
+ rateDelay.Rate = rate;
+
+ xf86Msg(X_INFO,"Setting typematic rate: Delay=%d, Rate=%d\n",delay,rate);
+
+ rc = DosDevIOCtl( (HFILE) xf86Info.consoleFd,
+ IOCTL_KEYBOARD,
+ KBD_SETTYPAMATICRATE,
+ &rateDelay,
+ rateDelaySize,
+ &rateDelaySize,
+ NULL,
+ 0,
+ NULL);
+ if (rc!=0) {
+ xf86Msg(X_ERROR,"xf86SetKbdRepeat: DosDevIOCtl returned %d\n",rc);
+ }
+}
+
+void xf86KbdInit()
+{
+ /*none required*/
+}
+
+
+USHORT OrigKbdState;
+USHORT OrigKbdInterim;
+
+typedef struct {
+ USHORT state;
+ UCHAR makeCode;
+ UCHAR breakCode;
+ USHORT keyID;
+} HOTKEYPARAM;
+
+
+int xf86KbdOn()
+{
+ KBDINFO info;
+ APIRET rc;
+ int i,k;
+ ULONG len;
+
+
+ KbdGetStatus(&info,(HKBD)xf86Info.consoleFd);
+ OrigKbdState=info.fsMask;
+ OrigKbdInterim=info.fsInterim;
+ info.fsMask &= ~0x09;
+ info.fsMask |= 0x136;
+ info.fsInterim &= ~0x20;
+ KbdSetStatus(&info,(HKBD)xf86Info.consoleFd);
+ return -1;
+}
+
+int xf86KbdOff()
+{
+ ULONG len;
+ APIRET rc;
+ KBDINFO info;
+
+ info.fsMask=OrigKbdState;
+ info.fsInterim=OrigKbdInterim;
+ KbdSetStatus(&info,(HKBD)xf86Info.consoleFd);
+ return -1;
+}
+
+#if 0 /*OBSOLETE*/
+void xf86MouseInit(mouse)
+MouseDevPtr mouse;
+{
+ HMOU fd;
+ APIRET rc;
+ USHORT nbut;
+
+ if (serverGeneration == 1) {
+ rc = MouOpen((PSZ)NULL,(PHMOU)&fd);
+ if (rc != 0)
+ FatalError("Cannot open mouse, rc=%d\n", rc);
+ mouse->mseFd = fd;
+ }
+
+ /* flush mouse queue */
+ MouFlushQue(fd);
+
+ /* check buttons */
+ rc = MouGetNumButtons(&nbut,fd);
+ if (rc == 0)
+ xf86Msg(X_INFO,"OsMouse has %d button(s).\n",nbut);
+}
+#endif
+
+#if 0 /*OBSOLETE*/
+int xf86MouseOn(mouse)
+MouseDevPtr mouse;
+{
+#if 0
+ HMOU fd;
+ APIRET rc;
+ USHORT nbut;
+#endif
+ xf86Msg (X_ERROR,
+ "Calling MouseOn, a bad thing.... Must be some bug in the code!\n");
+
+#if 0
+ if (serverGeneration == 1) {
+ rc = MouOpen((PSZ)NULL,(PHMOU)&fd);
+ if (rc != 0)
+ FatalError("Cannot open mouse, rc=%d\n", rc);
+ mouse->mseFd = fd;
+ }
+
+ /* flush mouse queue */
+ MouFlushQue(fd);
+
+ /* check buttons */
+ rc = MouGetNumButtons(&nbut,fd);
+ if (rc == 0)
+ xf86Msg(X_INFO,"OsMouse has %d button(s).\n",nbut);
+
+ return (mouse->mseFd);
+#endif
+}
+#endif
+
+#if 0 /*OBSOLETE*/
+/* This table is a bit irritating, because these mouse types are infact
+ * defined in the OS/2 kernel, but I want to force the user to put
+ * "OsMouse" in the config file, and not worry about the particular mouse
+ * type that is connected.
+ */
+Bool xf86SupportedMouseTypes[] =
+{
+ FALSE, /* Microsoft */
+ FALSE, /* MouseSystems */
+ FALSE, /* MMSeries */
+ FALSE, /* Logitech */
+ FALSE, /* BusMouse */
+ FALSE, /* MouseMan */
+ FALSE, /* PS/2 */
+ FALSE, /* Hitachi Tablet */
+};
+
+int xf86NumMouseTypes = sizeof(xf86SupportedMouseTypes) /
+ sizeof(xf86SupportedMouseTypes[0]);
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c
new file mode 100644
index 000000000..c03bb96af
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c
@@ -0,0 +1,140 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c,v 3.5 1997/08/26 10:01:38 hohndel Exp $ */
+/*
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ * Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: os2_ioperm.c /main/4 1996/04/18 16:50:01 kaleb $ */
+
+
+
+#define I_NEED_OS2_H
+#define INCL_32
+#define INCL_DOS
+#define INCL_DOSFILEMGR
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * To access I/O ports under OS/2, we use the xf86sup.sys driver.
+ * For the moment, we use a function which basically grants IO priviledge
+ * to the whole server. NOTE: Once the server is running, we should
+ * change this to use inline IO functions through the callgate returned by
+ * the fastio$ driver.
+ */
+
+int ioEnabled=FALSE;
+ULONG action;
+char *ioDrvPath = "/dev/fastio$";
+USHORT callgate[3]={0,0,0};
+
+
+Bool xf86EnableIO()
+{
+
+HFILE hfd;
+ ULONG dlen;
+ APIRET rc;
+
+ /* no need to call multiple times */
+ if (ioEnabled) return TRUE;
+
+ if (DosOpen((PSZ)ioDrvPath, (PHFILE)&hfd, (PULONG)&action,
+ (ULONG)0, FILE_SYSTEM, FILE_OPEN,
+ OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
+ (ULONG)0) != 0) {
+ xf86Msg(X_ERROR,"Error opening fastio$ driver...\n");
+ xf86Msg(X_ERROR,"Please install xf86sup.sys in config.sys!\n");
+ return FALSE;
+ }
+ callgate[0] = callgate[1] = 0;
+
+/* Get callgate from driver for fast io to ports and other stuff */
+
+ rc = DosDevIOCtl(hfd, (ULONG)0x76, (ULONG)0x64,
+ NULL, 0, NULL,
+ (ULONG*)&callgate[2], sizeof(USHORT), &dlen);
+ if (rc) {
+ xf86Msg(X_ERROR,
+ "EnableIOPorts failed, rc=%d, dlen=%d; emergency exit\n",
+ rc,dlen);
+ DosClose(hfd);
+ return FALSE;
+ }
+
+/* Calling callgate with function 13 sets IOPL for the program */
+
+ asm volatile ("movl $13,%%ebx;.byte 0xff,0x1d;.long _callgate"
+ : /*no outputs */
+ : /*no inputs */
+ : "eax","ebx","ecx","edx","cc");
+
+ ioEnabled = TRUE;
+ DosClose(hfd);
+ return TRUE;
+}
+
+void xf86DisableIO()
+{
+HFILE hfd;
+ ULONG dlen;
+ APIRET rc;
+
+ /* no need to call multiple times */
+ if (!ioEnabled) return;
+
+ if (DosOpen((PSZ)ioDrvPath, (PHFILE)&hfd, (PULONG)&action,
+ (ULONG)0, FILE_SYSTEM, FILE_OPEN,
+ OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
+ (ULONG)0) != 0) {
+ xf86Msg(X_ERROR,"Error opening fastio$ driver...\n");
+ xf86Msg(X_ERROR,"Please install xf86sup.sys in config.sys!\n");
+ return;
+ }
+ callgate[0] = callgate[1] = 0;
+
+ rc = DosDevIOCtl(hfd, (ULONG)0x76, (ULONG)0x64,
+ NULL, 0, NULL,
+ (ULONG*)&callgate[2], sizeof(USHORT), &dlen);
+ if (rc) {
+ xf86Msg(X_ERROR,"DisableIOPorts failed, rc=%d, dlen=%d\n",
+ rc,dlen);
+ DosClose(hfd);
+ return;
+ }
+
+/* Function 14 of callgate brings program back to ring 3 */
+
+ asm volatile ("movl $14,%%ebx;.byte 0xff,0x1d;.long _callgate"
+ : /*no outputs */
+ : /*no inputs */
+ : "eax","ebx","ecx","edx","cc");
+ ioEnabled=FALSE;
+ DosClose(hfd);
+ return;
+
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_kbd.c
new file mode 100644
index 000000000..f99f12c0f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_kbd.c
@@ -0,0 +1,158 @@
+/*
+ * Copied from os2_io.c which is
+ *
+ * (c) Copyright 1994,1999 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ * Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XFree86$ */
+
+#define I_NEED_OS2_H
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xpoll.h>
+#include "compiler.h"
+#include <time.h>
+
+#define INCL_DOSPROCESS
+#define INCL_KBD
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+
+
+
+/***************************************************************************/
+
+static void SoundKbdBell(loudness, pitch, duration)
+int loudness;
+int pitch;
+int duration;
+{
+ DosBeep((ULONG)pitch, (ULONG)duration);
+}
+
+static void SetKbdLeds(pInfo, leds)
+InputInfoPtr pInfo;
+int leds;
+{
+ KBDINFO kinfo;
+ APIRET rc;
+
+ rc = KbdGetStatus(&kinfo,(HKBD)xf86Info.consoleFd);
+ if (!rc) {
+ kinfo.fsMask = 0x10;
+ kinfo.fsState &= ~0x70;
+ kinfo.fsState |= (leds&0x70);
+ KbdSetStatus(&kinfo,(HKBD)xf86Info.consoleFd);
+ }
+}
+
+static int GetKbdLeds(pInfo)
+InputInfoPtr pInfo;
+{
+ KBDINFO kinfo;
+ APIRET rc;
+
+ rc = KbdGetStatus(&kinfo,(HKBD)xf86Info.consoleFd);
+ return rc ? 0 : kinfo.fsState & 0x70;
+}
+
+static void SetKbdRepeat(pInfo, rad)
+InputInfoPtr pInfo;
+char rad;
+{
+ /*notyet*/
+}
+
+static void KbdInit(pInfo)
+InputInfoPtr pInfo;
+{
+ /*none required*/
+ xf86Msg(X_INFO,"XKB module: Keyboard initialized\n");
+}
+
+
+static USHORT OrigKbdState;
+static USHORT OrigKbdInterim;
+
+typedef struct {
+ USHORT state;
+ UCHAR makeCode;
+ UCHAR breakCode;
+ USHORT keyID;
+} HOTKEYPARAM;
+
+
+static int KbdOn(pInfo)
+InputInfoPtr pInfo;
+{
+ KBDINFO info;
+
+ KbdGetStatus(&info,(HKBD)xf86Info.consoleFd);
+ OrigKbdState=info.fsMask;
+ OrigKbdInterim=info.fsInterim;
+ info.fsMask &= ~0x09;
+ info.fsMask |= 0x136;
+ info.fsInterim &= ~0x20;
+ KbdSetStatus(&info,(HKBD)xf86Info.consoleFd);
+ return -1;
+}
+
+static int KbdOff(pInfo)
+InputInfoPtr pInfo;
+{
+ KBDINFO info;
+
+ info.fsMask=OrigKbdState;
+ info.fsInterim=OrigKbdInterim;
+ KbdSetStatus(&info,(HKBD)xf86Info.consoleFd);
+ return -1;
+}
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = pInfo->private;
+
+ pKbd->KbdInit = KbdInit;
+ pKbd->KbdOn = KbdOn;
+ pKbd->KbdOff = KbdOff;
+ pKbd->Bell = SoundKbdBell;
+ pKbd->SetLeds = SetKbdLeds;
+ pKbd->GetLeds = GetKbdLeds;
+ pKbd->SetKbdRepeat = SetKbdRepeat;
+
+ pKbd->vtSwitchSupported = FALSE;
+
+ /* not yet */
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_kbdEv.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_kbdEv.c
new file mode 100644
index 000000000..861fbf089
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_kbdEv.c
@@ -0,0 +1,511 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_kbdEv.c,v 3.16 2002/05/31 18:46:01 dawes Exp $ */
+/*
+ * (c) Copyright 1994,1996,1999 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ * Modified 1996 Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium: os2_kbdEv.c /main/10 1996/10/27 11:48:48 kaleb $ */
+
+#define I_NEED_OS2_H
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#define INCL_KBD
+#define INCL_DOSMONITORS
+#define INCL_WINSWITCHLIST
+#define INCL_DOSQUEUES
+#undef RT_FONT /* must discard this */
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+
+/* Attention! these lines copied from ../../common/xf86Events.c */
+#define XE_POINTER 1
+#define XE_KEYBOARD 2
+
+#ifdef XKB
+extern Bool noXkbExtension;
+#endif
+
+#ifdef XTESTEXT1
+
+#define XTestSERVER_SIDE
+#include <X11/extensions/xtestext1.h>
+extern short xtest_mousex;
+extern short xtest_mousey;
+extern int on_steal_input;
+extern Bool XTestStealKeyData();
+extern void XTestStealMotionData();
+
+#ifdef XINPUT
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ if (!on_steal_input || \
+ XTestStealKeyData((ev)->u.u.detail, (ev)->u.u.type, dev_type, \
+ xtest_mousex, xtest_mousey)) \
+ xf86eqEnqueue((ev))
+#else
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ if (!on_steal_input || \
+ XTestStealKeyData((ev)->u.u.detail, (ev)->u.u.type, dev_type, \
+ xtest_mousex, xtest_mousey)) \
+ mieqEnqueue((ev))
+#endif
+
+#define MOVEPOINTER(dx, dy, time) \
+ if (on_steal_input) \
+ XTestStealMotionData(dx, dy, XE_POINTER, xtest_mousex, xtest_mousey); \
+ miPointerDeltaCursor (dx, dy, time)
+
+#else /* ! XTESTEXT1 */
+
+#ifdef XINPUT
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ xf86eqEnqueue((ev))
+#else
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ mieqEnqueue((ev))
+#endif
+#define MOVEPOINTER(dx, dy, time) \
+ miPointerDeltaCursor (dx, dy, time)
+
+#endif
+/* end of include */
+
+HQUEUE hKbdQueue;
+HEV hKbdSem;
+int last_status;
+int lastStatus;
+int lastShiftState;
+extern BOOL SwitchedToWPS;
+
+void os2PostKbdEvent();
+
+int os2KbdQueueQuery()
+{
+ ULONG numElements,postCount;
+
+ (void)DosQueryQueue(hKbdQueue,&numElements);
+ if (numElements!=0) return 0; /* We have something in queue */
+
+ DosResetEventSem(hKbdSem,&postCount);
+ return 1;
+}
+
+
+void xf86KbdEvents()
+{
+ KBDKEYINFO keybuf;
+ ULONG numElements;
+ REQUESTDATA requestData;
+ ULONG dataLength, postCount;
+ PVOID dummy;
+ BYTE elemPriority;
+ int scan, down;
+ static int last;
+ USHORT ModState;
+ int i;
+
+ while(DosReadQueue(hKbdQueue,
+ &requestData,&dataLength,&dummy,
+ 0L,1L,&elemPriority,hKbdSem) == 0) {
+
+ /* xf86Msg(X_INFO,
+ "Got queue element. data=%d, scancode =%d,up=%d, ddflag %d\n",
+ requestData.ulData,
+ (requestData.ulData&0x7F00)>>8,
+ requestData.ulData&0x8000,
+ requestData.ulData>>16);*/
+
+ scan=(requestData.ulData&0x7F00)>>8;
+
+ /* the separate cursor keys return 0xe0/scan */
+ if ((requestData.ulData & 0x3F0000)==0x20000) scan=0;
+ if (requestData.ulData & 0x800000) {
+ switch (scan) {
+
+/* BUG ALERT: IBM has in its keyboard driver a 122 key keyboard, which
+ * uses the "server generated scancodes" from atKeynames.h as real scan codes.
+ * We wait until some poor guy with such a keyboard will break the whole
+ * card house though...
+ */
+ case KEY_KP_7: scan = KEY_Home; break;
+ case KEY_KP_8: scan = KEY_Up; break;
+ case KEY_KP_9: scan = KEY_PgUp; break;
+ case KEY_KP_4: scan = KEY_Left; break;
+ case KEY_KP_5: scan = KEY_Begin; break;
+ case KEY_KP_6: scan = KEY_Right; break;
+ case KEY_KP_1: scan = KEY_End; break;
+ case KEY_KP_2: scan = KEY_Down; break;
+ case KEY_KP_3: scan = KEY_PgDown; break;
+ case KEY_KP_0: scan = KEY_Insert; break;
+ case KEY_KP_Decimal: scan = KEY_Delete; break;
+ case KEY_Enter: scan = KEY_KP_Enter; break;
+ case KEY_LCtrl: scan = KEY_RCtrl; break;
+ case KEY_KP_Multiply: scan = KEY_Print; break;
+ case KEY_Slash: scan = KEY_KP_Divide; break;
+ case KEY_Alt: scan = KEY_AltLang; break;
+ case KEY_ScrollLock: scan = KEY_Break; break;
+ case 0x5b: scan = KEY_LMeta; break;
+ case 0x5c: scan = KEY_RMeta; break;
+ case 0x5d: scan = KEY_Menu; break;
+ default:
+ /* virtual shifts: ignore */
+ scan = 0; break;
+ }
+ }
+
+ down = (requestData.ulData&0x8000) ? FALSE : TRUE;
+ if (scan!=0) os2PostKbdEvent(scan, down);
+ }
+ (void)DosResetEventSem(hKbdSem,&postCount);
+}
+
+/*
+ * xf86PostKbdEvent --
+ * Translate the raw hardware KbdEvent into an XEvent, and tell DIX
+ * about it. Scancode preprocessing and so on is done ...
+ *
+ * OS/2 specific xf86PostKbdEvent(key) has been moved from common/xf86Events.c
+ * as some things differ, and I didn't want to scatter this routine with
+ * ifdefs further (hv).
+ */
+
+void os2PostKbdEvent(unsigned scanCode, Bool down)
+{
+ KeyClassRec *keyc = ((DeviceIntPtr)xf86Info.pKeyboard)->key;
+ Bool updateLeds = FALSE;
+ Bool UsePrefix = FALSE;
+ Bool Direction = FALSE;
+ xEvent kevent;
+ KeySym *keysym;
+ int keycode;
+ static int lockkeys = 0;
+
+ /*
+ * and now get some special keysequences
+ */
+ if ((ModifierDown(ControlMask | AltMask)) ||
+ (ModifierDown(ControlMask | AltLangMask))) {
+ switch (scanCode) {
+ case KEY_BackSpace:
+ if (!xf86Info.dontZap) GiveUp(0);
+ return;
+ case KEY_KP_Minus: /* Keypad - */
+ if (!xf86Info.dontZoom) {
+ if (down)
+ xf86ZoomViewport(xf86Info.currentScreen, -1);
+ return;
+ }
+ break;
+ case KEY_KP_Plus: /* Keypad + */
+ if (!xf86Info.dontZoom) {
+ if (down)
+ xf86ZoomViewport(xf86Info.currentScreen, 1);
+ return;
+ }
+ break;
+ }
+ }
+
+ /* CTRL-ESC is std OS/2 hotkey for going back to PM and popping up
+ * window list... handled by keyboard driverand PM if you tell it. This is
+ * what we have done, and thus should never detect this key combo */
+ if (ModifierDown(ControlMask) && scanCode==KEY_Escape) {
+ /* eat it */
+ return;
+ } else if (ModifierDown(AltLangMask|AltMask) && scanCode==KEY_Escape) {
+ /* same here */
+ return;
+ }
+
+ /*
+ * Now map the scancodes to real X-keycodes ...
+ */
+ keycode = scanCode + MIN_KEYCODE;
+ keysym = (keyc->curKeySyms.map +
+ keyc->curKeySyms.mapWidth *
+ (keycode - keyc->curKeySyms.minKeyCode));
+#ifdef XKB
+ if (noXkbExtension) {
+#endif
+ /* Filter autorepeated caps/num/scroll lock keycodes. */
+
+#define CAPSFLAG 0x01
+#define NUMFLAG 0x02
+#define SCROLLFLAG 0x04
+#define MODEFLAG 0x08
+ if (down) {
+ switch (keysym[0]) {
+ case XK_Caps_Lock:
+ if (lockkeys & CAPSFLAG)
+ return;
+ else
+ lockkeys |= CAPSFLAG;
+ break;
+ case XK_Num_Lock:
+ if (lockkeys & NUMFLAG)
+ return;
+ else
+ lockkeys |= NUMFLAG;
+ break;
+ case XK_Scroll_Lock:
+ if (lockkeys & SCROLLFLAG)
+ return;
+ else
+ lockkeys |= SCROLLFLAG;
+ break;
+ }
+
+ if (keysym[1] == XF86XK_ModeLock) {
+ if (lockkeys & MODEFLAG)
+ return;
+ else
+ lockkeys |= MODEFLAG;
+ }
+ } else {
+ switch (keysym[0]) {
+ case XK_Caps_Lock:
+ lockkeys &= ~CAPSFLAG;
+ break;
+ case XK_Num_Lock:
+ lockkeys &= ~NUMFLAG;
+ break;
+ case XK_Scroll_Lock:
+ lockkeys &= ~SCROLLFLAG;
+ break;
+ }
+
+ if (keysym[1] == XF86XK_ModeLock)
+ lockkeys &= ~MODEFLAG;
+ }
+
+ /*
+ * LockKey special handling:
+ * ignore releases, toggle on & off on presses.
+ * Don't deal with the Caps_Lock keysym directly,
+ * but check the lock modifier
+ */
+#ifndef PC98
+ if (keyc->modifierMap[keycode] & LockMask ||
+ keysym[0] == XK_Scroll_Lock ||
+ keysym[1] == XF86XK_ModeLock ||
+ keysym[0] == XK_Num_Lock) {
+ Bool flag;
+
+ if (!down) return;
+ flag = !KeyPressed(keycode);
+ if (!flag) down = !down;
+
+ if (keyc->modifierMap[keycode] & LockMask)
+ xf86Info.capsLock = flag;
+ if (keysym[0] == XK_Num_Lock)
+ xf86Info.numLock = flag;
+ if (keysym[0] == XK_Scroll_Lock)
+ xf86Info.scrollLock = flag;
+ if (keysym[1] == XF86XK_ModeLock)
+ xf86Info.modeSwitchLock = flag;
+ updateLeds = TRUE;
+ }
+#endif /* not PC98 */
+
+ /* normal, non-keypad keys */
+ if (scanCode < KEY_KP_7 || scanCode > KEY_KP_Decimal) {
+ /* magic ALT_L key on AT84 keyboards for multilingual support */
+ if (xf86Info.kbdType == KB_84 &&
+ ModifierDown(AltMask) &&
+ keysym[2] != NoSymbol) {
+ UsePrefix = TRUE;
+ Direction = TRUE;
+ }
+ }
+
+#ifdef XKB /* Warning: got position wrong first time */
+ }
+#endif
+
+ /* check for an autorepeat-event */
+ if ((down && KeyPressed(keycode)) &&
+ (xf86Info.autoRepeat != AutoRepeatModeOn || keyc->modifierMap[keycode]))
+ return;
+
+ xf86Info.lastEventTime =
+ kevent.u.keyButtonPointer.time =
+ GetTimeInMillis();
+
+ /*
+ * And now send these prefixes ...
+ * NOTE: There cannot be multiple Mode_Switch keys !!!!
+ */
+ if (UsePrefix) {
+ ENQUEUE(&kevent,
+ keyc->modifierKeyMap[keyc->maxKeysPerModifier*7],
+ Direction ? KeyPress : KeyRelease,
+ XE_KEYBOARD);
+ ENQUEUE(&kevent,
+ keycode,
+ down ? KeyPress : KeyRelease,
+ XE_KEYBOARD);
+ ENQUEUE(&kevent,
+ keyc->modifierKeyMap[keyc->maxKeysPerModifier*7],
+ Direction ? KeyRelease : KeyPress,
+ XE_KEYBOARD);
+ } else {
+#ifdef XFreeDGA
+ if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectKeyb) {
+ XF86DirectVideoKeyEvent(&kevent,
+ keycode,
+ down ? KeyPress : KeyRelease);
+ } else
+#endif
+ {
+ ENQUEUE(&kevent,
+ keycode,
+ down ? KeyPress : KeyRelease,
+ XE_KEYBOARD);
+ }
+ }
+
+ if (updateLeds) xf86KbdLeds();
+}
+
+#pragma pack(1)
+struct KeyPacket {
+ unsigned short mnflags;
+ KBDKEYINFO cp;
+ unsigned short ddflags;
+};
+#pragma pack()
+
+/* The next function runs as a thread. It registers a monitor on the kbd
+ * driver, and uses that to get keystrokes. This is because the standard
+ * OS/2 keyboard driver does not send keyboard release events. A queue
+ * is used to communicate with the main thread to send keystrokes */
+
+void os2KbdMonitorThread(void* arg)
+{
+ struct KeyPacket packet;
+ APIRET rc;
+ USHORT length,print_flag;
+ ULONG queueParam;
+ HMONITOR hKbdMonitor;
+ MONIN monInbuf;
+ MONOUT monOutbuf;
+ char queueName[128];
+
+#if 0
+ monInbuf=(MONIN *)_tmalloc(2*sizeof(MONIN));
+ if (monInbuf==NULL) {
+ xf86Msg(X_ERROR,
+ "Could not allocate memory in kbd monitor thread!\n");
+ exit(1);
+ }
+ monOutbuf=(MONOUT *) &monInbuf[1];
+#endif
+
+ monInbuf.cb=sizeof(MONIN);
+ monOutbuf.cb=sizeof(MONOUT);
+
+ rc = DosMonOpen("KBD$",&hKbdMonitor);
+ xf86Msg(X_INFO,"Opened kbd monitor, rc=%d\n",rc);
+ rc = DosMonReg(hKbdMonitor,
+ (PBYTE)&monInbuf,(PBYTE)&monOutbuf,(USHORT)2,(USHORT)-1);
+ xf86Msg(X_INFO,"Kbd monitor registered, rc=%d\n",rc);
+ if (rc) {
+ DosMonClose(hKbdMonitor);
+ exit(1);
+ }
+
+ /* create a queue */
+ sprintf(queueName,"\\QUEUES\\XF86KBD\\%d",getpid());
+ rc = DosCreateQueue(&hKbdQueue,0L,queueName);
+ xf86Msg(X_INFO,"Kbd Queue created, rc=%d\n",rc);
+ (void)DosPurgeQueue(hKbdQueue);
+
+ while (1) {
+ length = sizeof(packet);
+ rc = DosMonRead((PBYTE)&monInbuf,0,(PBYTE)&packet,&length);
+ if (rc) {
+ xf86Msg(X_ERROR,
+ "DosMonRead returned bad RC! rc=%d\n",rc);
+ DosMonClose(hKbdMonitor);
+ exit(1);
+ }
+ queueParam = packet.mnflags+(packet.ddflags<<16);
+ if (packet.mnflags&0x7F00)
+ DosWriteQueue(hKbdQueue,queueParam,0L,NULL,0L);
+ /*xf86Msg(X_INFO,"Wrote a char to queue, rc=%d\n",rc); */
+ print_flag = packet.ddflags & 0x1F;
+
+ /*xf86Msg(X_INFO,"Kbd Monitor: Key press %d, scan code %d, ddflags %d\n",
+ packet.mnflags&0x8000,(packet.mnflags&0x7F00)>>8,packet.ddflags);
+ */
+
+ /* This line will swallow print-screen keypresses */
+ if (print_flag == 0x13 || print_flag == 0x14 ||
+ print_flag == 0x15 || print_flag == 0x16)
+ rc = 0;
+ else
+ rc = DosMonWrite((PBYTE)&monOutbuf,(PBYTE)&packet,length);
+ if (rc) {
+ xf86Msg(X_ERROR,
+ "DosMonWrite returned bad RC! rc=%d\n",rc);
+ DosMonClose(hKbdMonitor);
+ exit(1);
+ }
+ }
+
+ DosCloseQueue(hKbdQueue);
+ DosMonClose(hKbdMonitor);
+}
+
+void os2KbdBitBucketThread(void* arg)
+{
+ KBDKEYINFO key;
+ while (1) {
+ if (xf86Info.consoleFd != -1) {
+ KbdCharIn(&key,1,xf86Info.consoleFd);
+ usleep(100000);
+ } else
+ usleep(500000);
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_mouse.c
new file mode 100644
index 000000000..e1fd52c2e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_mouse.c
@@ -0,0 +1,653 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_mouse.c,v 3.17 2002/05/31 18:46:02 dawes Exp $ */
+/*
+ * (c) Copyright 1994,1999,2000 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ * Modified (c) 1996 Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium: os2_mouse.c /main/10 1996/10/27 11:48:51 kaleb $ */
+
+#define I_NEED_OS2_H
+#define NEED_EVENTS
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#define INCL_DOSFILEMGR
+#define INCL_DOSQUEUES
+#define INCL_MOU
+#undef RT_FONT
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Config.h"
+
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "mipointer.h"
+
+/* The following support code was copied from mouse.c */
+
+/**********************************************************************
+ *
+ * Emulate3Button support code
+ *
+ **********************************************************************/
+
+
+/*
+ * Lets create a simple finite-state machine for 3 button emulation:
+ *
+ * We track buttons 1 and 3 (left and right). There are 11 states:
+ * 0 ground - initial state
+ * 1 delayed left - left pressed, waiting for right
+ * 2 delayed right - right pressed, waiting for left
+ * 3 pressed middle - right and left pressed, emulated middle sent
+ * 4 pressed left - left pressed and sent
+ * 5 pressed right - right pressed and sent
+ * 6 released left - left released after emulated middle
+ * 7 released right - right released after emulated middle
+ * 8 repressed left - left pressed after released left
+ * 9 repressed right - right pressed after released right
+ * 10 pressed both - both pressed, not emulating middle
+ *
+ * At each state, we need handlers for the following events
+ * 0: no buttons down
+ * 1: left button down
+ * 2: right button down
+ * 3: both buttons down
+ * 4: emulate3Timeout passed without a button change
+ * Note that button events are not deltas, they are the set of buttons being
+ * pressed now. It's possible (ie, mouse hardware does it) to go from (eg)
+ * left down to right down without anything in between, so all cases must be
+ * handled.
+ *
+ * a handler consists of three values:
+ * 0: action1
+ * 1: action2
+ * 2: new emulation state
+ *
+ * action > 0: ButtonPress
+ * action = 0: nothing
+ * action < 0: ButtonRelease
+ *
+ * The comment preceeding each section is the current emulation state.
+ * The comments to the right are of the form
+ * <button state> (<events>) -> <new emulation state>
+ * which should be read as
+ * If the buttons are in <button state>, generate <events> then go to
+ * <new emulation state>.
+ */
+static signed char stateTab[11][5][3] = {
+/* 0 ground */
+ {
+ { 0, 0, 0 }, /* nothing -> ground (no change) */
+ { 0, 0, 1 }, /* left -> delayed left */
+ { 0, 0, 2 }, /* right -> delayed right */
+ { 2, 0, 3 }, /* left & right (middle press) -> pressed middle */
+ { 0, 0, -1 } /* timeout N/A */
+ },
+/* 1 delayed left */
+ {
+ { 1, -1, 0 }, /* nothing (left event) -> ground */
+ { 0, 0, 1 }, /* left -> delayed left (no change) */
+ { 1, -1, 2 }, /* right (left event) -> delayed right */
+ { 2, 0, 3 }, /* left & right (middle press) -> pressed middle */
+ { 1, 0, 4 }, /* timeout (left press) -> pressed left */
+ },
+/* 2 delayed right */
+ {
+ { 3, -3, 0 }, /* nothing (right event) -> ground */
+ { 3, -3, 1 }, /* left (right event) -> delayed left (no change) */
+ { 0, 0, 2 }, /* right -> delayed right (no change) */
+ { 2, 0, 3 }, /* left & right (middle press) -> pressed middle */
+ { 3, 0, 5 }, /* timeout (right press) -> pressed right */
+ },
+/* 3 pressed middle */
+ {
+ { -2, 0, 0 }, /* nothing (middle release) -> ground */
+ { 0, 0, 7 }, /* left -> released right */
+ { 0, 0, 6 }, /* right -> released left */
+ { 0, 0, 3 }, /* left & right -> pressed middle (no change) */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 4 pressed left */
+ {
+ { -1, 0, 0 }, /* nothing (left release) -> ground */
+ { 0, 0, 4 }, /* left -> pressed left (no change) */
+ { -1, 0, 2 }, /* right (left release) -> delayed right */
+ { 3, 0, 10 }, /* left & right (right press) -> pressed both */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 5 pressed right */
+ {
+ { -3, 0, 0 }, /* nothing (right release) -> ground */
+ { -3, 0, 1 }, /* left (right release) -> delayed left */
+ { 0, 0, 5 }, /* right -> pressed right (no change) */
+ { 1, 0, 10 }, /* left & right (left press) -> pressed both */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 6 released left */
+ {
+ { -2, 0, 0 }, /* nothing (middle release) -> ground */
+ { -2, 0, 1 }, /* left (middle release) -> delayed left */
+ { 0, 0, 6 }, /* right -> released left (no change) */
+ { 1, 0, 8 }, /* left & right (left press) -> repressed left */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 7 released right */
+ {
+ { -2, 0, 0 }, /* nothing (middle release) -> ground */
+ { 0, 0, 7 }, /* left -> released right (no change) */
+ { -2, 0, 2 }, /* right (middle release) -> delayed right */
+ { 3, 0, 9 }, /* left & right (right press) -> repressed right */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 8 repressed left */
+ {
+ { -2, -1, 0 }, /* nothing (middle release, left release) -> ground */
+ { -2, 0, 4 }, /* left (middle release) -> pressed left */
+ { -1, 0, 6 }, /* right (left release) -> released left */
+ { 0, 0, 8 }, /* left & right -> repressed left (no change) */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 9 repressed right */
+ {
+ { -2, -3, 0 }, /* nothing (middle release, right release) -> ground */
+ { -3, 0, 7 }, /* left (right release) -> released right */
+ { -2, 0, 5 }, /* right (middle release) -> pressed right */
+ { 0, 0, 9 }, /* left & right -> repressed right (no change) */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 10 pressed both */
+ {
+ { -1, -3, 0 }, /* nothing (left release, right release) -> ground */
+ { -3, 0, 4 }, /* left (right release) -> pressed left */
+ { -1, 0, 5 }, /* right (left release) -> pressed right */
+ { 0, 0, 10 }, /* left & right -> pressed both (no change) */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+};
+
+/*
+ * Table to allow quick reversal of natural button mapping to correct mapping
+ */
+
+/*
+ * [JCH-96/01/21] The ALPS GlidePoint pad extends the MS protocol
+ * with a fourth button activated by tapping the PAD.
+ * The 2nd line corresponds to 4th button on; the drv sends
+ * the buttons in the following map (MSBit described first) :
+ * 0 | 4th | 1st | 2nd | 3rd
+ * And we remap them (MSBit described first) :
+ * 0 | 4th | 3rd | 2nd | 1st
+ */
+static char reverseMap[32] = { 0, 4, 2, 6, 1, 5, 3, 7,
+ 8, 12, 10, 14, 9, 13, 11, 15,
+ 16, 20, 18, 22, 17, 21, 19, 23,
+ 24, 28, 26, 30, 25, 29, 27, 31};
+
+
+static char hitachMap[16] = { 0, 2, 1, 3,
+ 8, 10, 9, 11,
+ 4, 6, 5, 7,
+ 12, 14, 13, 15 };
+
+#define reverseBits(map, b) (((b) & ~0x0f) | map[(b) & 0x0f])
+
+static CARD32
+buttonTimer(InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse;
+ int sigstate;
+ int id;
+
+ pMse = pInfo->private;
+
+ sigstate = xf86BlockSIGIO ();
+
+ pMse->emulate3Pending = FALSE;
+ if ((id = stateTab[pMse->emulateState][4][0]) != 0) {
+ xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
+ pMse->emulateState = stateTab[pMse->emulateState][4][2];
+ } else {
+ ErrorF("Got unexpected buttonTimer in state %d\n", pMse->emulateState);
+ }
+
+ xf86UnblockSIGIO (sigstate);
+ return 0;
+}
+
+static Bool
+Emulate3ButtonsSoft(InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse = pInfo->private;
+
+ if (!pMse->emulate3ButtonsSoft)
+ return TRUE;
+
+ pMse->emulate3Buttons = FALSE;
+
+ if (pMse->emulate3Pending)
+ buttonTimer(pInfo);
+
+ xf86Msg(X_INFO,"3rd Button detected: disabling emulate3Button\n");
+
+ return FALSE;
+}
+
+static void MouseBlockHandler(pointer data,
+ struct timeval **waitTime,
+ pointer LastSelectMask)
+{
+ InputInfoPtr pInfo = (InputInfoPtr) data;
+ MouseDevPtr pMse = (MouseDevPtr) pInfo->private;
+ int ms;
+
+ if (pMse->emulate3Pending)
+ {
+ ms = pMse->emulate3Expires - GetTimeInMillis ();
+ if (ms <= 0)
+ ms = 0;
+ AdjustWaitForDelay (waitTime, ms);
+ }
+}
+
+static void MouseWakeupHandler(pointer data,
+ int i,
+ pointer LastSelectMask)
+{
+ InputInfoPtr pInfo = (InputInfoPtr) data;
+ MouseDevPtr pMse = (MouseDevPtr) pInfo->private;
+ int ms;
+
+ if (pMse->emulate3Pending)
+ {
+ ms = pMse->emulate3Expires - GetTimeInMillis ();
+ if (ms <= 0)
+ buttonTimer (pInfo);
+ }
+}
+
+static int
+SupportedInterfaces(void)
+{
+ return MSE_MISC;
+}
+
+static const char* internalNames[] = {
+ "OS2Mouse",
+ NULL
+};
+
+static const char**
+BuiltinNames(void)
+{
+ return internalNames;
+}
+
+static Bool
+CheckProtocol(const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++)
+ if (xf86NameCmp(protocol, internalNames[i]) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+static const char *
+DefaultProtocol(void)
+{
+ return "OS2Mouse";
+}
+
+static const char *
+SetupAuto(InputInfoPtr pInfo, int *protoPara)
+{
+ return "OS2Mouse";
+}
+
+HMOU hMouse=65535;
+HEV hMouseSem;
+HQUEUE hMouseQueue;
+InputInfoPtr iinfoPtr;
+int MouseTid;
+BOOL HandleValid=FALSE;
+extern BOOL SwitchedToWPS;
+extern CARD32 LastSwitchTime;
+void os2MouseEventThread(void* arg);
+
+static void
+os2MouseReadInput(InputInfoPtr pInfo)
+{
+ APIRET rc;
+ ULONG postCount,dataLength;
+ PVOID dummy;
+ int buttons;
+ int state;
+ int i, dx,dy;
+ BYTE elemPriority;
+ REQUESTDATA requestData;
+
+ MouseDevPtr pMse = pInfo->private;
+
+ if (!HandleValid) return;
+ while((rc = DosReadQueue(hMouseQueue,
+ &requestData,&dataLength,&dummy,
+ 0L,1L,&elemPriority,hMouseSem)) == 0) {
+ dx = requestData.ulData;
+ (void)DosReadQueue(hMouseQueue,
+ &requestData,&dataLength,&dummy,
+ 0L,1L,&elemPriority,hMouseSem);
+ dy = requestData.ulData;
+ (void)DosReadQueue(hMouseQueue,
+ &requestData,&dataLength,&dummy,
+ 0L,1L,&elemPriority,hMouseSem);
+ state = requestData.ulData;
+ (void)DosReadQueue(hMouseQueue,
+ &requestData,&dataLength,&dummy,
+ 0L,1L,&elemPriority,hMouseSem);
+ if (requestData.ulData != 0xFFFFFFFF)
+ xf86Msg(X_ERROR,
+ "Unexpected mouse event tag, %d\n",
+ requestData.ulData);
+
+ /* Contrary to other systems, OS/2 has mouse buttons *
+ * in the proper order, so we reverse them before *
+ * sending the event. */
+
+ buttons = ((state & 0x06) ? 4 : 0) |
+ ((state & 0x18) ? 1 : 0) |
+ ((state & 0x60) ? 2 : 0);
+ pMse->PostEvent(pInfo, buttons, dx, dy, 0, 0);
+ }
+ DosResetEventSem(hMouseSem,&postCount);
+}
+
+int os2MouseProc(DeviceIntPtr pPointer, int what)
+{
+ APIRET rc = 0;
+ USHORT nbuttons, state;
+ unsigned char map[MSE_MAXBUTTONS + 1];
+ int i;
+
+ InputInfoPtr pInfo = pPointer->public.devicePrivate;
+ MouseDevPtr pMse = pInfo->private;
+ pMse->device = pPointer;
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+ if (hMouse == 65535)
+ rc = MouOpen((PSZ)0, &hMouse);
+ if (rc != 0)
+ xf86Msg(X_WARNING,"%s: cannot open mouse, rc=%d\n",
+ pInfo->name,rc);
+ else {
+ pInfo->fd = hMouse;
+
+ /* flush mouse queue */
+ MouFlushQue(hMouse);
+
+ /* check buttons */
+ rc = MouGetNumButtons(&nbuttons, hMouse);
+ if (rc == 0)
+ xf86Msg(X_INFO,"%s: Mouse has %d button(s).\n",
+ pInfo->name,nbuttons);
+ if (nbuttons==2) nbuttons++;
+
+ for (i = 1; i<=nbuttons; i++)
+ map[i] = i;
+
+ InitPointerDeviceStruct((DevicePtr)pPointer, map, nbuttons,
+ miPointerGetMotionEvents, pMse->Ctrl,
+ miPointerGetMotionBufferSize());
+
+ /* X valuator */
+ xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 0);
+ /* y Valuator */
+ InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 1);
+ xf86MotionHistoryAllocate(pInfo);
+
+ /* OK, we are ready to start up the mouse thread ! */
+ if (!HandleValid) {
+ rc = DosCreateEventSem(NULL,&hMouseSem,DC_SEM_SHARED,TRUE);
+ if (rc != 0)
+ xf86Msg(X_ERROR,"%s: could not create mouse queue semaphore, rc=%d\n",
+ pInfo->name,rc);
+ MouseTid = _beginthread(os2MouseEventThread,NULL,0x4000,(void *)pInfo);
+ xf86Msg(X_INFO,
+ "%s: Started Mouse event thread, Tid=%d\n",
+ pInfo->name, MouseTid);
+ DosSetPriority(2,3,0,MouseTid);
+ }
+ HandleValid=TRUE;
+ }
+ break;
+
+ case DEVICE_ON:
+ if (!HandleValid) return -1;
+ pMse->lastButtons = 0;
+ pMse->lastMappedButtons = 0;
+ pMse->emulateState = 0;
+ pPointer->public.on = TRUE;
+ state = 0x300;
+ rc = MouSetDevStatus(&state,hMouse);
+ state = 0x7f;
+ rc = MouSetEventMask(&state,hMouse);
+ MouFlushQue(hMouse);
+ if (pMse->emulate3Buttons || pMse->emulate3ButtonsSoft)
+ {
+ RegisterBlockAndWakeupHandlers (MouseBlockHandler, MouseWakeupHandler,
+ (pointer) pInfo);
+ }
+ break;
+
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ if (!HandleValid) return -1;
+ if (pMse->emulate3Buttons || pMse->emulate3ButtonsSoft)
+ {
+ RemoveBlockAndWakeupHandlers (MouseBlockHandler, MouseWakeupHandler,
+ (pointer) pInfo);
+ }
+ pPointer->public.on = FALSE;
+ state = 0x300;
+ MouSetDevStatus(&state,hMouse);
+ state = 0;
+ MouSetEventMask(&state,hMouse);
+ if (what == DEVICE_CLOSE) {
+/* Comment out for now as this seems to break server */
+#if 0
+ MouClose(hMouse);
+ hMouse = 65535;
+ pInfo->fd = -1;
+ HandleValid = FALSE;
+#endif
+ }
+ break;
+ }
+ return Success;
+}
+
+int os2MouseQueueQuery()
+{
+ /* Now we check for activity on mouse handles */
+ ULONG numElements,postCount;
+
+ if (!HandleValid) return(1);
+ DosResetEventSem(hMouseSem,&postCount);
+ (void)DosQueryQueue(hMouseQueue,&numElements);
+ if (numElements>0) { /* Something in mouse queue! */
+ return 0; /* Will this work? */
+ }
+ return 1;
+}
+
+void os2MouseEventThread(void *arg)
+{
+ APIRET rc;
+ MOUEVENTINFO mev;
+ ULONG queueParam;
+ USHORT waitflg;
+ char queueName[128];
+ MouseDevPtr pMse;
+
+ iinfoPtr = (InputInfoPtr)arg;
+ pMse = iinfoPtr->private;
+
+ sprintf(queueName,"\\QUEUES\\XF86MOU\\%d",getpid());
+ rc = DosCreateQueue(&hMouseQueue,0L,queueName);
+ xf86Msg(X_INFO,"Mouse Queue created, rc=%d\n",rc);
+ (void)DosPurgeQueue(hMouseQueue);
+
+ while(1) {
+ waitflg = 1;
+ rc = MouReadEventQue(&mev,&waitflg,hMouse);
+ if (rc) {
+ xf86Msg(X_ERROR,
+ "Bad return code from mouse driver, rc=%d\n",
+ rc);
+ xf86Msg(X_ERROR,"Mouse aborting!\n");
+ break;
+ }
+
+ queueParam = mev.col;
+ if ((rc = DosWriteQueue(hMouseQueue,queueParam,0L,NULL,0L)))
+ break;
+ queueParam = mev.row;
+ if ((rc = DosWriteQueue(hMouseQueue,queueParam,0L,NULL,0L)))
+ break;
+ queueParam = mev.fs;
+ if ((rc = DosWriteQueue(hMouseQueue,queueParam,0L,NULL,0L)))
+ break;
+ queueParam = 0xFFFFFFFF;
+ if ((rc = DosWriteQueue(hMouseQueue,queueParam,0L,NULL,0L)))
+ break;
+ }
+ xf86Msg(X_ERROR,
+ "An unrecoverable error in mouse queue has occured, rc=%d. Mouse is shutting down.\n",
+ rc);
+ DosCloseQueue(hMouseQueue);
+}
+
+
+static Bool
+os2MousePreInit(InputInfoPtr pInfo, const char* protocol, int flags)
+{
+ MouseDevPtr pMse = pInfo->private;
+
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local procs. */
+ pInfo->device_control = os2MouseProc;
+ pInfo->read_input = os2MouseReadInput;
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+ p->BuiltinNames = BuiltinNames;
+ p->DefaultProtocol = DefaultProtocol;
+ p->CheckProtocol = CheckProtocol;
+ p->PreInit = os2MousePreInit;
+ p->SetupAuto = SetupAuto;
+ return p;
+}
+
+void xf86OsMouseEvents()
+{
+ APIRET rc;
+ ULONG postCount,dataLength;
+ PVOID dummy;
+ int buttons;
+ int state;
+ int i, dx,dy;
+ BYTE elemPriority;
+ REQUESTDATA requestData;
+
+ MouseDevPtr pMse = iinfoPtr->private;
+
+ if (!HandleValid) return;
+ while((rc = DosReadQueue(hMouseQueue,
+ &requestData,&dataLength,&dummy,
+ 0L,1L,&elemPriority,hMouseSem)) == 0) {
+ dx = requestData.ulData;
+ (void)DosReadQueue(hMouseQueue,
+ &requestData,&dataLength,&dummy,
+ 0L,1L,&elemPriority,hMouseSem);
+ dy = requestData.ulData;
+ (void)DosReadQueue(hMouseQueue,
+ &requestData,&dataLength,&dummy,
+ 0L,1L,&elemPriority,hMouseSem);
+ state = requestData.ulData;
+ (void)DosReadQueue(hMouseQueue,
+ &requestData,&dataLength,&dummy,
+ 0L,1L,&elemPriority,hMouseSem);
+ if (requestData.ulData != 0xFFFFFFFF)
+ xf86Msg(X_ERROR,
+ "Unexpected mouse event tag, %d\n",
+ requestData.ulData);
+
+ /* Contrary to other systems, OS/2 has mouse buttons *
+ * in the proper order, so we reverse them before *
+ * sending the event. */
+
+ buttons = ((state & 0x06) ? 4 : 0) |
+ ((state & 0x18) ? 1 : 0) |
+ ((state & 0x60) ? 2 : 0);
+ pMse->PostEvent(iinfoPtr, buttons, dx, dy, 0, 0);
+ }
+ DosResetEventSem(hMouseSem,&postCount);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_select.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_select.c
new file mode 100644
index 000000000..395104242
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_select.c
@@ -0,0 +1,497 @@
+/* $XConsortium: os2_select.c /main/6 1996/10/27 11:48:55 kaleb $ */
+
+
+
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_select.c,v 3.9 2003/03/25 04:18:24 dawes Exp $ */
+
+/*
+ * (c) Copyright 1996 by Sebastien Marineau
+ * <marineau@genie.uottawa.ca>
+ * Modified 1999 by Holger.Veit@gmd.de
+ * Modified 2004 by Frank Giessler
+ * <giessler@biomag.uni-jena.de>
+ *
+ * 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
+ * HOLGER VEIT 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ */
+
+/* os2_select.c: reimplementation of the xserver select(), optimized for speed */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <memory.h>
+#include <io.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/errno.h>
+#include <emx/io.h>
+
+#define I_NEED_OS2_H
+#define INCL_DOSSEMAPHORES
+#define INCL_DOSPROFILE
+#define INCL_DOSPROCESS
+#define INCL_DOSFILEMGR
+#define INCL_DOSMISC
+#define INCL_DOSMODULEMGR
+
+
+#include <X11/Xpoll.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include "os2_select.h"
+
+int os2MouseQueueQuery();
+int os2KbdQueueQuery();
+void os2RecoverFromPopup();
+void os2CheckPopupPending();
+void os2SocketMonitorThread();
+extern BOOL os2PopupErrorPending;
+
+extern HEV hKbdSem;
+extern HEV hMouseSem;
+extern HEV hevServerHasFocus;
+HEV hPipeSem;
+HEV hSocketSem;
+HEV hActivateSocketSem;
+HEV hSwitchToSem;
+static HMUX hSelectWait;
+SEMRECORD SelectMuxRecord[5];
+HMODULE hmod_so32dll;
+static struct select_data sd;
+
+static int (*os2_tcp_select)(int *,int,int,int,long);
+static int (*os2_so_cancel)(int);
+static int (*os2_sock_errno)();
+int os2_set_error(ULONG);
+extern int _files[];
+
+
+
+/* This is a new implementation of select, for improved efficiency */
+/* This function performs select() on sockets */
+/* but uses OS/2 internal fncts to check mouse */
+/* and keyboard. S. Marineau, 27/4/96 */
+
+/* This is still VERY messy */
+
+/* A few note on optimizations: this select has been tuned for maximum
+* performance, and thus has a different approach than a general-purpose
+* select. It should not be used in another app without modifications. Further,
+* it may need modifications if the Xserver os code is modified
+* Assumptions: this is never called with anything in exceptfds. This is
+* silently ignored. Further, if any pipes are specified in the write mask, it is
+* because they have just been stuffed full by the xserver. There is not much
+* in immediately returning with those bits set. Instead, we block on the
+* semaphore for at least one tick, which will let the client at least start
+* to flush the pipe. */
+
+int os2PseudoSelect(nfds,readfds,writefds,exceptfds,timeout)
+ int nfds;
+ fd_set *readfds,*writefds,*exceptfds;
+ struct timeval *timeout;
+{
+
+ static BOOL FirstTime=TRUE;
+
+ int n,ns,np;
+ int ready_handles;
+ ULONG timeout_ms;
+ BOOL any_ready;
+ ULONG semKey,postCount;
+ APIRET rc;
+ char faildata[16];
+ static int Socket_Tid;
+
+ sd.have_read=FALSE; sd.have_write=FALSE;
+ sd.socket_nread=0; sd.socket_nwrite=0; sd.socket_ntotal=0;
+ sd.max_fds=31; ready_handles=0; any_ready=FALSE;
+ sd.pipe_ntotal=0; sd.pipe_have_write=FALSE;
+
+ /* Stuff we have to do the first time this is called to set up various parameters */
+
+ if (FirstTime) {
+ /* First load the so32dll.dll module and get a pointer to the SELECT fn */
+
+ if ((rc=DosLoadModule(faildata,sizeof(faildata),"SO32DLL",&hmod_so32dll))!=0) {
+ FatalError("Could not load module so32dll.dll, rc = %d. Error note %s\n",rc,faildata);
+ }
+ if ((rc = DosQueryProcAddr(hmod_so32dll, 0, "SELECT", (PPFN)&os2_tcp_select))!=0) {
+ FatalError("Could not query address of SELECT, rc = %d.\n",rc);
+ }
+ if ((rc = DosQueryProcAddr(hmod_so32dll, 0, "SO_CANCEL", (PPFN)&os2_so_cancel))!=0) {
+ FatalError("Could not query address of SO_CANCEL, rc = %d.\n",rc);
+ }
+ if ((rc = DosQueryProcAddr(hmod_so32dll, 0, "SOCK_ERRNO", (PPFN)&os2_sock_errno))!=0) {
+ FatalError("Could not query address of SOCK_ERRNO, rc = %d.\n",rc);
+ }
+
+ /* Call these a first time to set the semaphore */
+ xf86OsMouseEvents();
+ xf86KbdEvents();
+
+ DosCreateEventSem(NULL, &hSocketSem,DC_SEM_SHARED,FALSE);
+ DosResetEventSem(hSocketSem,&postCount);
+
+ DosCreateEventSem(NULL, &hActivateSocketSem, DC_SEM_SHARED, FALSE);
+ DosResetEventSem(hActivateSocketSem, &postCount);
+
+ DosCreateEventSem(NULL, &hSwitchToSem, DC_SEM_SHARED, FALSE);
+ DosResetEventSem(hSwitchToSem, &postCount);
+
+ Socket_Tid = _beginthread(os2SocketMonitorThread, NULL, 0x2000,(void *) NULL);
+ xf86Msg(X_INFO,
+ "Started Socket monitor thread, TID=%d\n",Socket_Tid);
+
+ SelectMuxRecord[0].hsemCur = (HSEM)hMouseSem;
+ SelectMuxRecord[0].ulUser = MOUSE_SEM_KEY;
+ SelectMuxRecord[1].hsemCur = (HSEM)hKbdSem;
+ SelectMuxRecord[1].ulUser = KBD_SEM_KEY;
+ SelectMuxRecord[2].hsemCur = (HSEM)hPipeSem;
+ SelectMuxRecord[2].ulUser = PIPE_SEM_KEY;
+ SelectMuxRecord[3].hsemCur = (HSEM)hSocketSem;
+ SelectMuxRecord[3].ulUser = SOCKET_SEM_KEY;
+ SelectMuxRecord[4].hsemCur = (HSEM)hSwitchToSem;
+ SelectMuxRecord[4].ulUser = SWITCHTO_SEM_KEY;
+
+ rc = DosCreateMuxWaitSem(NULL, &hSelectWait, 5, SelectMuxRecord,
+ DC_SEM_SHARED | DCMW_WAIT_ANY);
+ if (rc) {
+ xf86Msg(X_ERROR,"Could not create MuxWait semaphore, rc=%d\n",rc);
+ }
+ FirstTime = FALSE;
+ }
+
+ rc = DosResetEventSem(hActivateSocketSem, &postCount);
+ /* Set up the time delay structs */
+
+ if (timeout!=NULL) {
+ timeout_ms=timeout->tv_sec*1000+timeout->tv_usec/1000;
+ } else {
+ timeout_ms=1000000; /* This should be large enough... */
+ }
+
+ /* Zero our local fd_masks */
+ {FD_ZERO(&sd.read_copy);}
+ {FD_ZERO(&sd.write_copy);}
+
+ /* Copy the masks for later use */
+ if (readfds!=NULL) { XFD_COPYSET(readfds,&sd.read_copy); sd.have_read=TRUE; }
+ if (writefds!=NULL) {XFD_COPYSET(writefds,&sd.write_copy); sd.have_write=TRUE; }
+
+ /* And zero the original masks */
+ if (sd.have_read){ FD_ZERO(readfds); }
+ if (sd.have_write) {FD_ZERO(writefds); }
+ if (exceptfds != NULL) {FD_ZERO(exceptfds); }
+
+ /* Now we parse the fd_sets passed to select and separate pipe/sockets */
+ n = os2_parse_select(&sd,nfds);
+
+ /* Now check if we have sockets ready! */
+
+ if (sd.socket_ntotal > 0) {
+ ns = os2_poll_sockets(&sd,readfds,writefds);
+ if (ns>0) {
+ ready_handles+=ns;
+ any_ready = TRUE;
+ } else if (ns == -1) {
+ return(-1);
+ }
+ }
+
+ /* And pipes */
+
+ if (sd.pipe_ntotal > 0) {
+ np = os2_check_pipes(&sd,readfds,writefds);
+ if (np > 0) {
+ ready_handles+=np;
+ any_ready = TRUE;
+ } else if (np == -1) {
+ return(-1);
+ }
+ }
+
+ /* And finally poll input devices */
+ if(!os2MouseQueueQuery() || !os2KbdQueueQuery() ) any_ready = TRUE;
+
+ if (xf86Info.vtRequestsPending) any_ready=TRUE;
+
+ if (os2PopupErrorPending)
+ os2RecoverFromPopup();
+
+ if (!any_ready && timeout_ms) {
+ DosResetEventSem(hSocketSem,&postCount);
+
+ /* Activate the socket thread */
+ if (sd.socket_ntotal>0) {
+ rc = DosPostEventSem(hActivateSocketSem);
+ }
+
+ rc = DosWaitMuxWaitSem(hSelectWait, timeout_ms, &semKey);
+
+ /* If our socket monitor thread is still blocked in os2_tcp_select()
+ * we have to wake it up by calling os2_so_cancel().
+ * After that, call os2_tcp_select() once more to get rid of
+ * error SOCEINTR (10004)
+ */
+ if (sd.socket_ntotal>0) {
+ rc = DosQueryEventSem(hSocketSem, &postCount);
+
+ if (postCount == 0) { /* os2_select still blocked */
+ int i,f,g;
+ struct select_data *sd_ptr=&sd;
+
+ if (sd.socket_nread > 0) {
+ for (i=0; i<sd.socket_nread; i++) {
+ f = g = sd_ptr->tcp_select_mask[i];
+ os2_so_cancel(f);
+ os2_tcp_select(&g, 1, 0, 0, 0); /* get rid of error 10004 */
+ }
+ }
+ if (sd.socket_nwrite > 0) {
+ for (i=sd.socket_nread;
+ i<sd.socket_nread+sd.socket_nwrite;
+ i++) {
+ f = g = sd_ptr->tcp_select_mask[i];
+ os2_so_cancel(f);
+ os2_tcp_select(&g, 0, 1, 0, 0); /* get rid of error 10004 */
+ }
+ }
+ } else { /* not blocked, something must be ready -> get it */
+ ns = os2_poll_sockets(&sd,readfds,writefds);
+ if (ns>0) {
+ ready_handles+=ns;
+ } else if (ns == -1) {
+ return(-1);
+ }
+ }
+ }
+ if (sd.pipe_ntotal > 0) {
+ rc = DosQueryEventSem(hPipeSem,&postCount);
+ if (postCount > 0) {
+ np = os2_check_pipes(&sd,readfds,writefds);
+ if (np > 0) {
+ ready_handles+=np;
+ } else if (np == -1) {
+ return(-1);
+ }
+ }
+ }
+ }
+ /* The polling of sockets/pipe automatically set the proper bits */
+ return (ready_handles);
+}
+
+
+int os2_parse_select(sd,nfds)
+ struct select_data *sd;
+ int nfds;
+{
+ int i;
+ /* First we determine up to which descriptor we need to check. */
+ /* No need to check up to 256 if we don't have to (and usually we dont...)*/
+ /* Note: stuff here is hardcoded for fd_sets which are int[8] as in EMX!!! */
+
+ if (nfds > sd->max_fds) {
+ for (i=0;i<((FD_SETSIZE+31)/32);i++) {
+ if (sd->read_copy.fds_bits[i] ||
+ sd->write_copy.fds_bits[i])
+ sd->max_fds=(i*32) +32;
+ }
+ } else { sd->max_fds = nfds; }
+
+ /* Check if this is greater than specified in select() call */
+ if(sd->max_fds > nfds) sd->max_fds = nfds;
+
+ if (sd->have_read) {
+ for (i = 0; i < sd->max_fds; ++i) {
+ if (FD_ISSET (i, &sd->read_copy)) {
+ if(_files[i] & F_SOCKET) {
+ sd->tcp_select_mask[sd->socket_ntotal]=_getsockhandle(i);
+ sd->tcp_emx_handles[sd->socket_ntotal]=i;
+ sd->socket_ntotal++; sd->socket_nread++;
+ } else if (_files[i] & F_PIPE) {
+ sd -> pipe_ntotal++;
+ }
+ }
+ }
+ }
+ if (sd->have_write) {
+ for (i = 0; i < sd->max_fds; ++i) {
+ if (FD_ISSET (i, &sd->write_copy)) {
+ if (_files[i] & F_SOCKET) {
+ sd->tcp_select_mask[sd->socket_ntotal]=_getsockhandle(i);
+ sd->tcp_emx_handles[sd->socket_ntotal]=i;
+ sd->socket_ntotal++; sd->socket_nwrite++;
+ } else if (_files[i] & F_PIPE) {
+ sd -> pipe_ntotal++;
+ sd -> pipe_have_write=TRUE;
+ }
+ }
+ }
+ }
+ return(sd->socket_ntotal);
+}
+
+
+int os2_poll_sockets(sd,readfds,writefds)
+ struct select_data *sd;
+ fd_set *readfds,*writefds;
+{
+ int e,i;
+ int j,n;
+
+ memcpy(sd->tcp_select_copy,sd->tcp_select_mask,
+ sd->socket_ntotal*sizeof(int));
+
+ e = os2_tcp_select(sd->tcp_select_copy,sd->socket_nread,
+ sd->socket_nwrite, 0, 0);
+
+ if (e == 0) return(e);
+
+ /* We have something ready? */
+ if (e>0) {
+ j = 0; n = 0;
+ for (i = 0; i < sd->socket_nread; ++i, ++j)
+ if (sd->tcp_select_copy[j] != -1) {
+ FD_SET (sd->tcp_emx_handles[j], readfds);
+ n ++;
+ }
+ for (i = 0; i < sd->socket_nwrite; ++i, ++j)
+ if (sd->tcp_select_copy[j] != -1) {
+ FD_SET (sd->tcp_emx_handles[j], writefds);
+ n ++;
+ }
+ errno = 0;
+
+ return n;
+ }
+ if (e<0) {
+ /*Error -- TODO */
+ xf86Msg(X_ERROR,"Error in server select! sock_errno = %d\n",os2_sock_errno());
+ errno = EBADF;
+ return (-1);
+ }
+}
+
+/* Check to see if anything is ready on pipes */
+
+int os2_check_pipes(sd,readfds,writefds)
+ struct select_data *sd;
+ fd_set *readfds,*writefds;
+{
+ int i,e;
+ ULONG ulPostCount;
+ PIPESEMSTATE pipeSemState[128];
+ APIRET rc;
+
+ e = 0;
+ rc = DosResetEventSem(hPipeSem,&ulPostCount);
+ rc = DosQueryNPipeSemState((HSEM) hPipeSem, (PPIPESEMSTATE)&pipeSemState,
+ sizeof(pipeSemState));
+ if(rc) xf86Msg(X_ERROR,"SELECT: rc from QueryNPipeSem: %d\n",rc);
+ i=0;
+ while (pipeSemState[i].fStatus != 0) {
+/* xf86Msg(X_INFO,"SELECT: sem entry, stat=%d, flag=%d, key=%d,avail=%d\n",
+ pipeSemState[i].fStatus,pipeSemState[i].fFlag,pipeSemState[i].usKey,
+ pipeSemState[i].usAvail); */
+ if ((pipeSemState[i].fStatus == 1) &&
+ (FD_ISSET(pipeSemState[i].usKey,&sd->read_copy))) {
+ FD_SET(pipeSemState[i].usKey,readfds);
+ e++;
+ } else if ((pipeSemState[i].fStatus == 2) &&
+ (FD_ISSET(pipeSemState[i].usKey,&sd->write_copy))) {
+ FD_SET(pipeSemState[i].usKey,writefds);
+ e++;
+ } else if ((pipeSemState[i].fStatus == 3) &&
+ ((FD_ISSET(pipeSemState[i].usKey,&sd->read_copy)) ||
+ (FD_ISSET(pipeSemState[i].usKey,&sd->write_copy)) )) {
+ errno = EBADF;
+ /* xf86Msg(X_ERROR,"Pipe has closed down, fd=%d\n",pipeSemState[i].usKey); */
+ return (-1);
+ }
+ i++;
+ } /* endwhile */
+
+ errno = 0;
+ return(e);
+}
+
+
+void os2SocketMonitorThread(void *arg)
+{
+ struct select_data *sd_ptr = &sd;
+ ULONG ulPostCount;
+ int e,rc;
+
+ /* Make thread time critical */
+ DosSetPriority(2L,3L,0L,0L);
+
+ while (1) {
+ rc = DosWaitEventSem(hActivateSocketSem, SEM_INDEFINITE_WAIT);
+ if (rc != 0 )
+ xf86Msg(X_ERROR,"Socket monitor: DosWaitEventSem(hActivateSocketSem..) returned %d\n",rc);
+
+ rc = DosResetEventSem(hActivateSocketSem,&ulPostCount);
+ if (rc != 0 )
+ xf86Msg(X_ERROR,"Socket monitor: DosResetEventSem(&hActivateSocketSem..) returned %d\n",rc);
+
+ /* fg300104:
+ * The next line shouldn't be here, but the DosPostEventSem()
+ * below will return 299 from time to time under heavy load
+ */
+/* DosResetEventSem(hSocketSem,&ulPostCount);*/
+
+ memcpy(sd_ptr->tcp_select_monitor,sd_ptr->tcp_select_mask,
+ sd_ptr->socket_ntotal*sizeof(int));
+
+ /* call os2_select(), return only if either something is ready or
+ * os2_so_cancel() was called
+ */
+ e = os2_tcp_select(sd_ptr->tcp_select_monitor, sd_ptr->socket_nread,
+ sd_ptr->socket_nwrite, 0, -1);
+
+ if (e>0) {
+ rc = DosPostEventSem(hSocketSem);
+ if (rc != 0 )
+ xf86Msg(X_ERROR,"Socket monitor: DosPostEventSem(hSocketSem..) returned %d\n",rc);
+ } else if (e<0) {
+ rc = os2_sock_errno();
+ if (rc != 10004)
+ xf86Msg(X_ERROR,"Socket monitor: os2_select: sock_errno = %d\n",rc);
+ }
+
+ rc = DosQueryEventSem(hevServerHasFocus, &ulPostCount);
+
+ /* no need to rush while switched away */
+ if ((rc==0) && (ulPostCount==0))
+ rc == DosWaitEventSem(hevServerHasFocus,31L);
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_select.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_select.h
new file mode 100644
index 000000000..cb2291e09
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_select.h
@@ -0,0 +1,62 @@
+/* $XConsortium: os2_select.h /main/1 1996/05/13 16:38:30 kaleb $ */
+/*
+ * (c) Copyright 1996 by Sebastien Marineau
+ * <marineau@genie.uottawa.ca>
+ *
+ * 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
+ * HOLGER VEIT 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_select.h,v 3.1 1996/12/27 07:04:31 dawes Exp $ */
+
+/* Header file for os2_select.c */
+
+#define MAX_TCP 256
+
+#define MOUSE_SEM_KEY 0x0F01
+#define KBD_SEM_KEY 0x0F02
+#define PIPE_SEM_KEY 0x0F03
+#define SOCKET_SEM_KEY 0x0F04
+#define SWITCHTO_SEM_KEY 0x0F05
+
+
+struct select_data
+{
+ fd_set read_copy;
+ fd_set write_copy;
+ BOOL have_read;
+ BOOL have_write;
+ int tcp_select_mask[MAX_TCP];
+ int tcp_emx_handles[MAX_TCP];
+ int tcp_select_copy[MAX_TCP];
+ int tcp_select_monitor[MAX_TCP];
+ int socket_nread;
+ int socket_nwrite;
+ int socket_ntotal;
+ int pipe_ntotal;
+ int pipe_have_write;
+ int max_fds;
+};
+
+
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_serial.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_serial.c
new file mode 100644
index 000000000..6587b1bda
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_serial.c
@@ -0,0 +1,517 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_serial.c,v 1.3 2000/04/05 18:13:53 dawes Exp $ */
+/*
+ * (c) Copyright 1999 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium$ */
+
+#define I_NEED_OS2_H
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#define INCL_DOSDEVIOCTL
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+static int _set_baudrate(HFILE fd,int baud)
+{
+ USHORT br = baud;
+ ULONG plen;
+ return DosDevIOCtl(fd,IOCTL_ASYNC,ASYNC_SETBAUDRATE,
+ (PULONG)&br,sizeof(br),&plen,NULL,0,NULL);
+}
+
+#pragma pack(1)
+typedef struct _glinectl {
+ UCHAR databits;
+ UCHAR parity;
+ UCHAR stopbits;
+ UCHAR sendbrk;
+} GLINECTL;
+typedef struct _slinectl {
+ UCHAR databits;
+ UCHAR parity;
+ UCHAR stopbits;
+} SLINECTL;
+
+#pragma pack()
+
+static int _get_linectrl(HFILE fd,GLINECTL* linectrl)
+{
+ ULONG dlen;
+ return DosDevIOCtl(fd,IOCTL_ASYNC,ASYNC_GETLINECTRL,
+ NULL,0,NULL,linectrl,sizeof(GLINECTL),&dlen);
+}
+
+static int _set_linectl(HFILE fd,GLINECTL* linectl)
+{
+ ULONG plen;
+ return DosDevIOCtl(fd,IOCTL_ASYNC,ASYNC_SETLINECTRL,
+ (PULONG)&linectl,sizeof(SLINECTL),&plen,NULL,0,NULL);
+}
+
+static int _get_dcb(HFILE fd,DCBINFO* dcb) {
+
+ ULONG dlen;
+ return DosDevIOCtl(fd,IOCTL_ASYNC,ASYNC_GETDCBINFO,
+ NULL,0,NULL,(PULONG)dcb,sizeof(DCBINFO),&dlen);
+}
+
+static int _set_dcb(HFILE fd,DCBINFO* dcb)
+{
+ ULONG plen;
+ return DosDevIOCtl(fd,IOCTL_ASYNC, ASYNC_SETDCBINFO,
+ (PULONG)dcb,sizeof(DCBINFO),&plen,NULL,0,NULL);
+}
+
+#pragma pack(1)
+typedef struct comsize {
+ USHORT nqueued;
+ USHORT qsize;
+} COMSIZE;
+#pragma pack()
+
+static int _get_nread(HFILE fd,ULONG* nread)
+{
+ ULONG dlen;
+ COMSIZE sz;
+ APIRET rc = DosDevIOCtl(fd,IOCTL_ASYNC,ASYNC_GETINQUECOUNT,
+ NULL, 0, NULL, sz,sizeof(COMSIZE),&dlen);
+ *nread = sz.nqueued;
+ return rc ? -1 : 0;
+}
+
+int xf86OpenSerial (pointer options)
+{
+ APIRET rc;
+ HFILE fd, i;
+ ULONG action;
+ GLINECTL linectl;
+
+ char* dev = xf86FindOptionValue (options, "Device");
+ xf86MarkOptionUsedByName (options, "Device");
+ if (!dev) {
+ xf86Msg (X_ERROR, "xf86OpenSerial: No Device specified.\n");
+ return -1;
+ }
+
+ rc = DosOpen(dev, &fd, &action, 0, FILE_NORMAL, FILE_OPEN,
+ OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, NULL);
+ if (rc) {
+ xf86Msg (X_ERROR,
+ "xf86OpenSerial: Cannot open device %s, rc=%d.\n",
+ dev, rc);
+ return -1;
+ }
+
+ /* check whether it is an async device */
+ if (_get_linectrl(fd,&linectl)) {
+ xf86Msg (X_WARNING,
+ "xf86OpenSerial: Specified device %s is not a tty\n",
+ dev);
+ DosClose(fd);
+ return -1;
+ }
+
+ /* set up default port parameters */
+ _set_baudrate(fd, 9600);
+
+ linectl.databits = 8;
+ linectl.parity = 0;
+ linectl.stopbits = 0;
+ _set_linectl(fd, &linectl);
+
+ if (xf86SetSerial (fd, options) == -1) {
+ DosClose(fd);
+ return -1;
+ }
+
+ return fd;
+}
+
+int xf86SetSerial (int fd, pointer options)
+{
+ APIRET rc;
+ USHORT baud;
+ ULONG plen,dlen;
+ char *s;
+
+ GLINECTL linectl;
+ DCBINFO dcb;
+
+ if ((s = xf86FindOptionValue (options, "BaudRate"))) {
+ xf86MarkOptionUsedByName (options, "BaudRate");
+ if ((rc = _set_baudrate(fd, atoi(s)))) {
+ xf86Msg (X_ERROR,"Set Baudrate: %s, rc=%d\n", s, rc);
+ return -1;
+ }
+ }
+
+ /* get line parameters */
+ if (DosDevIOCtl((HFILE)fd,IOCTL_ASYNC, ASYNC_GETLINECTRL,
+ NULL,0,NULL,
+ (PULONG)&linectl,sizeof(GLINECTL),&dlen)) return -1;
+
+ if ((s = xf86FindOptionValue (options, "StopBits"))) {
+ xf86MarkOptionUsedByName (options, "StopBits");
+ switch (atoi (s)) {
+ case 1: linectl.stopbits = 0;
+ break;
+ case 2: linectl.stopbits = 2;
+ break;
+ default: xf86Msg (X_ERROR,
+ "Invalid Option StopBits value: %s\n", s);
+ return -1;
+ }
+ }
+
+ if ((s = xf86FindOptionValue (options, "DataBits"))) {
+ int db;
+ xf86MarkOptionUsedByName (options, "DataBits");
+ switch (db = atoi (s)) {
+ case 5: case 6: case 7: case 8:
+ linectl.databits = db;
+ break;
+ default: xf86Msg (X_ERROR,
+ "Invalid Option DataBits value: %s\n", s);
+ return -1;
+ }
+ }
+
+ if ((s = xf86FindOptionValue (options, "Parity"))) {
+ xf86MarkOptionUsedByName (options, "Parity");
+ if (xf86NameCmp (s, "Odd") == 0)
+ linectl.parity = 1; /* odd */
+ else if (xf86NameCmp (s, "Even") == 0)
+ linectl.parity = 2; /* even */
+ else if (xf86NameCmp (s, "None") == 0)
+ linectl.parity = 0; /* none */
+ else {
+ xf86Msg (X_ERROR,
+ "Invalid Option Parity value: %s\n", s);
+ return -1;
+ }
+ }
+
+ /* set line parameters */
+ if (_set_linectl(fd,&linectl)) return -1;
+
+ if (xf86FindOptionValue (options, "Vmin"))
+ xf86Msg (X_ERROR, "Vmin unsupported on this OS\n");
+
+ if (xf86FindOptionValue (options, "Vtime"))
+ xf86Msg (X_ERROR, "Vtime unsupported on this OS\n");
+
+ /* get device parameters */
+ if (_get_dcb(fd,&dcb)) return -1;
+
+ if ((s = xf86FindOptionValue (options, "FlowControl"))) {
+ xf86MarkOptionUsedByName (options, "FlowControl");
+ if (xf86NameCmp (s, "XonXoff") == 0)
+ dcb.fbFlowReplace |= 0x03;
+ else if (xf86NameCmp (s, "None") == 0)
+ dcb.fbFlowReplace &= ~0x03;
+ else {
+ xf86Msg (X_ERROR,
+ "Invalid Option FlowControl value: %s\n", s);
+ return -1;
+ }
+ }
+
+ if ((s = xf86FindOptionValue (options, "ClearDTR"))) {
+ dcb.fbCtlHndShake &= ~0x03; /* DTR=0 */
+ xf86MarkOptionUsedByName (options, "ClearDTR");
+ }
+
+ if ((s = xf86FindOptionValue (options, "ClearRTS"))) {
+ dcb.fbFlowReplace &= ~0xc0; /* RTS=0 */
+ xf86MarkOptionUsedByName (options, "ClearRTS");
+ }
+
+ /* set device parameters */
+ return _set_dcb(fd,&dcb) ? -1 : 0;
+}
+
+int xf86ReadSerial (int fd, void *buf, int count)
+{
+ ULONG nread,nq;
+ APIRET rc;
+
+ /* emulate non-blocking read */
+ if (_get_nread((HFILE)fd,&nq)) return -1;
+ if (nq==0) return 0;
+ if (nq < count) count = nq;
+
+ rc = DosRead((HFILE)fd,(PVOID)buf,(ULONG)count,&nread);
+ return rc ? -1 : (int)nread;
+}
+
+int xf86WriteSerial (int fd, const void *buf, int count)
+{
+ ULONG nwrite;
+ APIRET rc = DosWrite((HFILE)fd,(PVOID)buf,(ULONG)count,&nwrite);
+ return rc ? -1 : (int)nwrite;
+}
+
+int xf86CloseSerial (int fd)
+{
+ APIRET rc = DosClose((HFILE)fd);
+ return rc ? -1 : 0;
+}
+
+int xf86WaitForInput (int fd, int timeout)
+{
+ APIRET rc;
+ ULONG dlen,nq;
+
+ do {
+ if (_get_nread((HFILE)fd,&nq)) return -1;
+ if (nq) return 1;
+
+ DosSleep(10);
+ timeout -= 10000; /* 10000 usec */
+ } while (timeout > 0);
+
+ return 0;
+}
+
+int xf86SerialSendBreak (int fd, int duration)
+{
+ USHORT data;
+ ULONG dlen;
+ APIRET rc;
+ rc = DosDevIOCtl((HFILE)fd,IOCTL_ASYNC,ASYNC_SETBREAKON,
+ NULL, 0, NULL,
+ &data, sizeof(data), &dlen);
+ if (rc)
+ return -1;
+ DosSleep(500);
+
+ rc = DosDevIOCtl((HFILE)fd,IOCTL_ASYNC,ASYNC_SETBREAKOFF,
+ NULL, 0, NULL,
+ &data, sizeof(data), &dlen);
+ return rc ? -1 : 0;
+}
+
+int xf86FlushInput(int fd)
+{
+ APIRET rc;
+ UCHAR buf;
+ ULONG nread,nq;
+
+ if (_get_nread((HFILE)fd,&nq)) return -1;
+
+ /* eat all chars in queue */
+ while (nq) {
+ rc = DosRead((HFILE)fd,&buf,1,&nread);
+ if (rc) return -1;
+ nq--;
+ }
+ return 0;
+}
+
+static struct states {
+ int xf;
+ int os;
+} modemStates[] = {
+ { XF86_M_DTR, 0x01 },
+ { XF86_M_RTS, 0x02 },
+ { XF86_M_CTS, 0x10 },
+ { XF86_M_DSR, 0x20 },
+ { XF86_M_RNG, 0x40 },
+ { XF86_M_CAR, 0x80 },
+};
+
+static int numStates = sizeof(modemStates) / sizeof(modemStates[0]);
+
+static int
+xf2osState(int state)
+{
+ int i;
+ int ret = 0;
+
+ for (i = 0; i < numStates; i++)
+ if (state & modemStates[i].xf)
+ ret |= modemStates[i].os;
+ return ret;
+}
+
+static int
+os2xfState(int state)
+{
+ int i;
+ int ret = 0;
+
+ for (i = 0; i < numStates; i++)
+ if (state & modemStates[i].os)
+ ret |= modemStates[i].xf;
+ return ret;
+}
+
+static int
+getOsStateMask(void)
+{
+ int i;
+ int ret = 0;
+ for (i = 0; i < numStates; i++)
+ ret |= modemStates[i].os;
+ return ret;
+}
+
+static int osStateMask = 0;
+
+static
+int _get_modem_state(int fd,ULONG* state)
+{
+ ULONG state1,len;
+
+ if (DosDevIOCtl((HFILE)fd,IOCTL_ASYNC,ASYNC_GETMODEMOUTPUT,
+ NULL,0,NULL, state, sizeof(BYTE), &len) != 0 ||
+ DosDevIOCtl((HFILE)fd,IOCTL_ASYNC,ASYNC_GETMODEMINPUT,
+ NULL,0,NULL, &state1, sizeof(BYTE), &len) != 0)
+ return -1;
+ *state |= state1;
+ *state &= 0xff;
+ return 0;
+}
+
+static
+int _set_modem_state(int fd,ULONG state,ULONG mask)
+{
+ int len;
+ struct {
+ BYTE onmask;
+ BYTE offmask;
+ } modemctrl;
+ modemctrl.onmask = state;
+ modemctrl.offmask = mask;
+
+ if (DosDevIOCtl((HFILE)fd,IOCTL_ASYNC,ASYNC_SETMODEMCTRL,
+ NULL,0,NULL, (PULONG)&modemctrl, sizeof(modemctrl), &len) != 0)
+ return -1;
+ else
+ return 0;
+}
+
+int
+xf86SetSerialModemState(int fd, int state)
+{
+ ULONG s;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+ if (!osStateMask)
+ osStateMask = getOsStateMask();
+
+ state = xf2osState(state);
+
+ if (_get_modem_state(fd,&s) != 0)
+ return -1;
+
+ s &= ~osStateMask;
+ s |= state;
+
+ return _set_modem_state(fd,s,0x03);
+}
+
+int
+xf86GetSerialModemState(int fd)
+{
+ ULONG s;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+ if (_get_modem_state(fd,&s) != 0)
+ return -1;
+
+ return os2xfState(s);
+}
+
+int
+xf86SerialModemSetBits(int fd, int bits)
+{
+ int ret;
+ int s;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+ s = xf2osState(bits);
+ return _set_modem_state(fd,s,0x03);
+}
+
+int
+xf86SerialModemClearBits(int fd, int bits)
+{
+ int ret;
+ int s;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+ s = xf2osState(bits);
+ return _set_modem_state(fd, 0, ~s & 0xff);
+}
+
+int
+xf86SetSerialSpeed (int fd, int speed)
+{
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+ return _set_baudrate(fd,speed);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_stubs.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_stubs.c
new file mode 100644
index 000000000..727a605d1
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_stubs.c
@@ -0,0 +1,403 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_stubs.c,v 3.4 2002/05/31 18:46:02 dawes Exp $ */
+/*
+ * (c) Copyright 1996 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium: os2_stubs.c /main/3 1996/10/27 11:48:58 kaleb $ */
+
+#define I_NEED_OS2_H
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xpoll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+/* This is there to resolve a symbol in Xvfb
+ * this version is somewhat crippled compared to the one in os2_io.c
+ */
+#ifdef OS2NULLSELECT
+
+/* This below implements select() for calls in xnest. It has been */
+/* somewhat optimized for improved performance, but assumes a few */
+/* things so it cannot be used as a general select. */
+
+#include <sys/select.h>
+#include <sys/errno.h>
+#define INCL_DOSSEMAPHORES
+#define INCL_DOSNPIPES
+#define INCL_DOSMISC
+#define INCL_DOSMODULEMGR
+#undef BOOL
+#undef BYTE
+#include <os2.h>
+
+HEV hPipeSem;
+HMODULE hmod_so32dll;
+static int (*os2_tcp_select)(int*,int,int,int,long);
+ULONG os2_get_sys_millis();
+extern int _files[];
+
+#define MAX_TCP 256
+/* These lifted from sys/emx.h. Change if that changes there! */
+#define F_SOCKET 0x10000000
+#define F_PIPE 0x20000000
+
+struct select_data
+{
+ fd_set read_copy;
+ fd_set write_copy;
+ BOOL have_read;
+ BOOL have_write;
+ int tcp_select_mask[MAX_TCP];
+ int tcp_emx_handles[MAX_TCP];
+ int tcp_select_copy[MAX_TCP];
+ int socket_nread;
+ int socket_nwrite;
+ int socket_ntotal;
+ int pipe_ntotal;
+ int pipe_have_write;
+ int max_fds;
+};
+
+int os2PseudoSelect(int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval *timeout)
+{
+static BOOL FirstTime=TRUE;
+static haveTCPIP=TRUE;
+ULONG timeout_ms;
+ULONG postCount, start_millis,now_millis;
+char faildata[16];
+struct select_data sd;
+BOOL any_ready;
+int np,ns, i,ready_handles,n;
+APIRET rc;
+
+sd.have_read=FALSE; sd.have_write=FALSE;
+sd.socket_nread=0; sd.socket_nwrite=0; sd.socket_ntotal=0;
+sd.max_fds=31; ready_handles=0; any_ready=FALSE;
+sd.pipe_ntotal=0; sd.pipe_have_write=FALSE;
+
+if(FirstTime){
+ /* First load the so32dll.dll module and get a pointer to the SELECT function */
+
+ if((rc=DosLoadModule(faildata,sizeof(faildata),"SO32DLL",&hmod_so32dll))!=0){
+ fprintf(stderr, "Could not load module so32dll.dll, rc = %d. Error note %s\n",rc,faildata);
+ haveTCPIP=FALSE;
+ }
+ if((rc = DosQueryProcAddr(hmod_so32dll, 0, "SELECT", (PPFN)&os2_tcp_select))!=0){
+ fprintf(stderr, "Could not query address of SELECT, rc = %d.\n",rc);
+ haveTCPIP=FALSE;
+ }
+ /* Call these a first time to set the semaphore */
+ /* rc = DosCreateEventSem(NULL, &hPipeSem, DC_SEM_SHARED, FALSE);
+ if(rc) {
+ fprintf(stderr, "Could not create event semaphore, rc=%d\n",rc);
+ return(-1);
+ }
+ rc = DosResetEventSem(hPipeSem, &postCount); */ /* Done in xtrans code for servers*/
+
+ /*fprintf(stderr, "Client select() done first-time stuff, sem handle %d.\n",hPipeSem);*/
+
+ FirstTime = FALSE;
+}
+
+/* Set up the time delay structs */
+
+ if(timeout!=NULL) {
+ timeout_ms=timeout->tv_sec*1000+timeout->tv_usec/1000;
+ }
+ else { timeout_ms=1000000; } /* This should be large enough... */
+ if(timeout_ms>0) start_millis=os2_get_sys_millis();
+
+/* Copy the masks */
+ {FD_ZERO(&sd.read_copy);}
+ {FD_ZERO(&sd.write_copy);}
+ if(readfds!=NULL){ XFD_COPYSET(readfds,&sd.read_copy); sd.have_read=TRUE;}
+ if(writefds!=NULL) {XFD_COPYSET(writefds,&sd.write_copy);sd.have_write=TRUE;}
+
+/* And zero the original masks */
+ if(sd.have_read){ FD_ZERO(readfds);}
+ if(sd.have_write) {FD_ZERO(writefds);}
+ if(exceptfds != NULL) {FD_ZERO(exceptfds);}
+
+/* Now we parse the fd_sets passed to select and separate pipe/sockets */
+ n = os2_parse_select(&sd,nfds);
+ if(n == -1) {
+ errno = EBADF;
+ return (-1);
+ }
+
+/* Now we have three cases: either we have sockets, pipes, or both */
+/* We handle all three cases differently to optimize things */
+
+/* Case 1: only pipes! */
+ if((sd.pipe_ntotal >0) && (!sd.socket_ntotal)){
+ np = os2_check_pipes(&sd,readfds,writefds);
+ if(np > 0){
+ return (np);
+ }
+ else if (np == -1) { return(-1); }
+ while(!any_ready){
+ rc = DosWaitEventSem(hPipeSem, 1L);
+ /* if(rc) fprintf(stderr,"Sem-wait timeout, rc = %d\n",rc); */
+ if(rc == 640) {
+ return(0);
+ }
+ if((rc != 0) && (rc != 95)) {errno= EBADF; return(-1);}
+ np = os2_check_pipes(&sd,readfds,writefds);
+ if (np > 0){
+ return(np);
+ }
+ else if (np < 0){ return(-1); }
+ }
+ }
+
+/* Case 2: only sockets. Just let the os/2 tcp select do the work */
+ if((sd.socket_ntotal > 0) && (!sd.pipe_ntotal)){
+ ns = os2_check_sockets(&sd, readfds, writefds, timeout_ms);
+ return (ns);
+ }
+
+/* Case 3: combination of both */
+ if((sd.socket_ntotal > 0) && (sd.pipe_ntotal)){
+ np = os2_check_pipes(&sd,readfds,writefds);
+ if(np > 0){
+ any_ready=TRUE;
+ ready_handles += np;
+ }
+ else if (np == -1) { return(-1); }
+
+ ns = os2_check_sockets(&sd,readfds,writefds, 0);
+ if(ns>0){
+ ready_handles+=ns;
+ any_ready = TRUE;
+ }
+ else if (ns == -1) {return(-1);}
+
+ while (!any_ready && timeout_ms){
+
+ rc = DosWaitEventSem(hPipeSem, 1L);
+ if (rc=640) return(0);
+ if(rc == 0){
+ np = os2_check_pipes(&sd,readfds,writefds);
+ if(np > 0){
+ ready_handles+=np;
+ any_ready = TRUE;
+ }
+ else if (np == -1) {
+ return(-1); }
+ }
+
+ ns = os2_check_sockets(&sd,readfds,writefds,exceptfds, 0);
+ if(ns>0){
+ ready_handles+=ns;
+ any_ready = TRUE;
+ }
+ else if (ns == -1) {return(-1);}
+
+ if (i%8 == 0) {
+ now_millis = os2_get_sys_millis();
+ if((now_millis-start_millis) > timeout_ms) timeout_ms = 0;
+ }
+ i++;
+ }
+ }
+
+return(ready_handles);
+}
+
+
+ULONG os2_get_sys_millis()
+{
+ APIRET rc;
+ ULONG milli;
+
+ rc = DosQuerySysInfo(14, 14, &milli, sizeof(milli));
+ if(rc) {
+ fprintf(stderr,"Bad return code querying the millisecond counter! rc=%d\n",rc);
+ return(0);
+ }
+ return(milli);
+}
+
+int os2_parse_select(sd,nfds)
+struct select_data *sd;
+int nfds;
+{
+ int i;
+ APIRET rc;
+/* First we determine up to which descriptor we need to check. */
+/* No need to check up to 256 if we don't have to (and usually we dont...)*/
+/* Note: stuff here is hardcoded for fd_sets which are int[8] as in EMX! */
+
+ if(nfds > sd->max_fds){
+ for(i=0;i<((FD_SETSIZE+31)/32);i++){
+ if(sd->read_copy.fds_bits[i] ||
+ sd->write_copy.fds_bits[i])
+ sd->max_fds=(i*32) +32;
+ }
+ }
+ else { sd->max_fds = nfds; }
+/* Check if result is greater than specified in select() call */
+ if(sd->max_fds > nfds) sd->max_fds = nfds;
+
+ if (sd->have_read)
+ {
+ for (i = 0; i < sd->max_fds; ++i) {
+ if (FD_ISSET (i, &sd->read_copy)){
+ if(_files[i] & F_SOCKET)
+ {
+ sd->tcp_select_mask[sd->socket_ntotal]=_getsockhandle(i);
+ sd->tcp_emx_handles[sd->socket_ntotal]=i;
+ sd->socket_ntotal++; sd->socket_nread++;
+ }
+ else if (_files[i] & F_PIPE)
+ {
+ sd -> pipe_ntotal++;
+ /* rc = DosSetNPipeSem((HPIPE)i, (HSEM) hPipeSem, i);
+ if(rc) { fprintf(stderr,"Error SETNPIPE rc = %d\n",rc); return -1;} */
+ }
+ }
+ }
+ }
+
+ if (sd->have_write)
+ {
+ for (i = 0; i < sd->max_fds; ++i) {
+ if (FD_ISSET (i, &sd->write_copy)){
+ if(_files[i] & F_SOCKET)
+ {
+ sd->tcp_select_mask[sd->socket_ntotal]=_getsockhandle(i);
+ sd->tcp_emx_handles[sd->socket_ntotal]=i;
+ sd->socket_ntotal++; sd->socket_nwrite++;
+ }
+ else if (_files[i] & F_PIPE)
+ {
+ sd -> pipe_ntotal++;
+ /* rc = DosSetNPipeSem((HPIPE)i, (HSEM) hPipeSem, i);
+ if(rc) { fprintf(stderr,"Error SETNPIPE rc = %d\n",rc); return -1;} */
+ sd -> pipe_have_write=TRUE;
+ }
+ }
+ }
+ }
+
+
+return(sd->socket_ntotal);
+}
+
+
+int os2_check_sockets(sd,readfds,writefds)
+struct select_data *sd;
+fd_set *readfds,*writefds;
+{
+ int e,i;
+ int j,n;
+ memcpy(sd->tcp_select_copy,sd->tcp_select_mask,
+ sd->socket_ntotal*sizeof(int));
+
+ e = os2_tcp_select(sd->tcp_select_copy,sd->socket_nread,
+ sd->socket_nwrite, 0, 0);
+
+ if(e == 0) return(e);
+/* We have something ready? */
+ if(e>0){
+ j = 0; n = 0;
+ for (i = 0; i < sd->socket_nread; ++i, ++j)
+ if (sd->tcp_select_copy[j] != -1)
+ {
+ FD_SET (sd->tcp_emx_handles[j], readfds);
+ n ++;
+ }
+ for (i = 0; i < sd->socket_nwrite; ++i, ++j)
+ if (sd->tcp_select_copy[j] != -1)
+ {
+ FD_SET (sd->tcp_emx_handles[j], writefds);
+ n ++;
+ }
+ errno = 0;
+
+ return n;
+ }
+ if(e<0){
+ /*Error -- TODO. EBADF is a good choice for now. */
+ fprintf(stderr,"Error in server select! e=%d\n",e);
+ errno = EBADF;
+ return (-1);
+ }
+ }
+
+/* Check to see if anything is ready on pipes */
+
+int os2_check_pipes(sd,readfds,writefds)
+struct select_data *sd;
+fd_set *readfds,*writefds;
+{
+int i,e;
+ULONG ulPostCount;
+PIPESEMSTATE pipeSemState[128];
+APIRET rc;
+ e = 0;
+ rc = DosResetEventSem(hPipeSem,&ulPostCount);
+ rc = DosQueryNPipeSemState((HSEM) hPipeSem, (PPIPESEMSTATE)&pipeSemState,
+ sizeof(pipeSemState));
+ if(rc) fprintf(stderr,"SELECT: rc from QueryNPipeSem: %d\n",rc);
+ i=0;
+ while (pipeSemState[i].fStatus != 0) {
+ /*fprintf(stderr,"SELECT: sem entry, stat=%d, flag=%d, key=%d,avail=%d\n",
+ pipeSemState[i].fStatus,pipeSemState[i].fFlag,pipeSemState[i].usKey,
+ pipeSemState[i].usAvail); */
+ if((pipeSemState[i].fStatus == 1) &&
+ (FD_ISSET(pipeSemState[i].usKey,&sd->read_copy))){
+ FD_SET(pipeSemState[i].usKey,readfds);
+ e++;
+ }
+ else if((pipeSemState[i].fStatus == 2) &&
+ (FD_ISSET(pipeSemState[i].usKey,&sd->write_copy))){
+ FD_SET(pipeSemState[i].usKey,writefds);
+ e++;
+ }
+ else if( (pipeSemState[i].fStatus == 3) &&
+ ( (FD_ISSET(pipeSemState[i].usKey,&sd->read_copy)) ||
+ (FD_ISSET(pipeSemState[i].usKey,&sd->write_copy)) )){
+ errno = EBADF;
+ /* fprintf(stderr,"Pipe has closed down, fd=%d\n",pipeSemState[i].usKey); */
+ return (-1);
+ }
+ i++;
+ } /* endwhile */
+ /*fprintf(stderr,"Done listing pipe sem entries, total %d entries, total ready entries %d\n",i,e);*/
+errno = 0;
+return(e);
+}
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_video.c
new file mode 100644
index 000000000..c45b3165e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/os2/os2_video.c
@@ -0,0 +1,241 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_video.c,v 3.15 2002/05/31 18:46:02 dawes Exp $ */
+/*
+ * (c) Copyright 1994,1999 by Holger Veit
+ * <Holger.Veit@gmd.de>
+ * Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
+ *
+ * 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
+ * HOLGER VEIT 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 Holger Veit shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Holger Veit.
+ *
+ */
+/* $XConsortium: os2_video.c /main/8 1996/10/27 11:49:02 kaleb $ */
+
+#define I_NEED_OS2_H
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#define INCL_DOSFILEMGR
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#include "compiler.h"
+
+/***************************************************************************/
+/* Video Memory Mapping helper functions */
+/***************************************************************************/
+
+/* This section uses the xf86sup.sys driver developed for xfree86.
+ * The driver allows mapping of physical memory
+ * You must install it with a line DEVICE=path\xf86sup.sys in config.sys.
+ */
+
+#define LOWORD(X) ((X) & 0xffff)
+#define HIWORD(X) ((X) >> 16)
+
+static HFILE mapdev = -1;
+static ULONG stored_virt_addr;
+static char* mappath = "\\DEV\\PMAP$";
+static HFILE open_mmap()
+{
+ APIRET rc;
+ ULONG action;
+
+ if (mapdev != -1)
+ return mapdev;
+
+ rc = DosOpen((PSZ)mappath, (PHFILE)&mapdev, (PULONG)&action,
+ (ULONG)0, FILE_SYSTEM, FILE_OPEN,
+ OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
+ (ULONG)0);
+ if (rc!=0) {
+ mapdev = -1; }
+ else {
+ /* fg030203: ask for driver version of xf86sup.sys;
+ no output prior to version 1.539 */
+ struct {
+ ULONG magic;
+ ULONG drvtype;
+ ULONG version;
+ } drvid;
+ ULONG dlen = sizeof(drvid);
+ if ((rc=DosDevIOCtl(mapdev, (ULONG)0x76, (ULONG)0x61,
+ (PVOID)NULL, (ULONG)0, (PULONG)NULL,
+ (PVOID)&drvid, (ULONG)dlen, (PULONG)&dlen))==0) {
+ xf86Msg(X_INFO,"PMAP$: driver version = %x.%x\n",
+ HIWORD(drvid.version),
+ LOWORD(drvid.version));
+ }
+ }
+ return mapdev;
+}
+
+static void close_mmap()
+{
+ if (mapdev != -1)
+ DosClose(mapdev);
+ mapdev = -1;
+}
+
+/* this structure is used as a parameter packet for the direct access
+ * ioctl of pmap$
+ */
+
+/* Changed here for structure of driver PMAP$ */
+
+typedef struct{
+ ULONG addr;
+ ULONG size;
+} DIOParPkt;
+
+/* This is the data packet for the mapping function */
+
+typedef struct {
+ ULONG addr;
+ USHORT sel;
+} DIODtaPkt;
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+/* ARGSUSED */
+static pointer
+mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ DIOParPkt par;
+ ULONG plen;
+ DIODtaPkt dta;
+ ULONG dlen;
+ static BOOL ErrRedir = FALSE;
+ APIRET rc;
+
+ par.addr = (ULONG)Base;
+ par.size = (ULONG)Size;
+ plen = sizeof(par);
+ dlen = sizeof(dta);
+
+ open_mmap();
+ if (mapdev == -1)
+ FatalError("mapVidMem: install DEVICE=path\\XF86SUP.SYS!");
+
+ if ((rc=DosDevIOCtl(mapdev, (ULONG)0x76, (ULONG)0x44,
+ (PVOID)&par, (ULONG)plen, (PULONG)&plen,
+ (PVOID)&dta, (ULONG)dlen, (PULONG)&dlen)) == 0) {
+ xf86Msg(X_INFO,"mapVidMem succeeded: (ScreenNum=%d, Base=0x%x, Size=0x%x, vaddr=0x%x)\n",
+ ScreenNum, Base, Size, dta.addr);
+
+ if (dlen==sizeof(dta)) {
+ return (pointer)dta.addr;
+ }
+ /*else fail*/
+ }
+
+ /* fail */
+ FatalError("mapVidMem FAILED!!: rc = %d (ScreenNum=%d, Base=0x%x, Size=0x%x, return len=%d, vaddr=0x%x, sel=0x%x)\n",
+ rc, ScreenNum, Base, Size, dlen, dta.addr, dta.sel);
+ return (pointer)0;
+}
+
+/* ARGSUSED */
+static void
+unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ DIOParPkt par;
+ ULONG plen,vmaddr;
+ APIRET rc;
+/* We need here the VIRTADDR for unmapping, not the physical address */
+/* This should be taken care of either here by keeping track of allocated */
+/* pointers, but this is also already done in the driver... Thus it would */
+/* be a waste to do this tracking twice. Can this be changed when the fn. */
+/* is called? This would require tracking this function in all servers, */
+/* and changing it appropriately to call this with the virtual adress */
+/* If the above mapping function is only called once, then we can store */
+/* the virtual adress and use it here.... */
+
+ par.addr = (ULONG)Base;
+ par.size = 0xffffffff; /* This is the virtual address parameter. Set this to ignore */
+ plen = sizeof(par);
+
+ if (mapdev != -1)
+ rc = DosDevIOCtl(mapdev, (ULONG)0x76, (ULONG)0x45,
+ (PVOID)&par, (ULONG)plen, (PULONG)&plen,
+ &vmaddr, sizeof(ULONG), &plen);
+ if (!rc) {
+ xf86Msg(X_INFO,"unmapVidMem: Unmap phys memory at virtual address 0x%x\n",
+ vmaddr);
+ }
+ else {
+ xf86Msg(X_ERROR,"unmapVidMem: Unmap phys memory at base 0x%x, virtual address 0x%x, rc=%d\n",
+ Base,vmaddr,rc);
+ }
+/* Now if more than one region has been allocated and we close the driver,
+ * the other pointers will immediately become invalid. We avoid closing
+ * driver for now, but this should be fixed for server exit
+ */
+
+ /* close_mmap(); */
+}
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool xf86DisableInterrupts()
+{
+ /* allow interrupt disabling but check for side-effects.
+ * Not a good policy on OS/2...
+ */
+ asm ("cli");
+ return TRUE;
+}
+
+void xf86EnableInterrupts()
+{
+ /*Reenable*/
+ asm ("sti");
+}
+
+/***************************************************************************/
+/* Initialize video memory */
+/***************************************************************************/
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ pVidMem->linearSupported = TRUE;
+ pVidMem->mapMem = mapVidMem;
+ pVidMem->unmapMem = unmapVidMem;
+#if 0
+ pVidMem->mapMemSparse = 0;
+ pVidMem->unmapMemSparse = 0;
+#endif
+ pVidMem->setWC = 0; /* no MTRR support */
+ pVidMem->undoWC = 0;
+ pVidMem->initialised = TRUE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/Imakefile
new file mode 100644
index 000000000..37cc186c4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/Imakefile
@@ -0,0 +1,48 @@
+
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/pmax/Imakefile,v 1.11 2002/10/11 01:47:00 dawes Exp $
+
+#include <Server.tmpl>
+
+MOUSESRC = pmax_mouse.c
+MOUSEOBJ = pmax_mouse.o
+
+SRCS = pmax_devs.c pmax_init.c pmax_map.c pmax_pci.c pmax_ppc.c \
+ bios_V4mmap.c VTsw_usl.c sysv_kbd.c std_kbdEv.c \
+ posix_tty.c $(MOUSESRC) xqueue.c ioperm_noop.c \
+ libc_wrapper.c stdResource.c stdPci.o sigiostubs.c pm_noop.c \
+ kmod_noop.c agp_noop.c
+
+OBJS = pmax_devs.o pmax_init.o pmax_map.o pmax_pci.o pmax_ppc.o \
+ bios_V4mmap.o VTsw_usl.o sysv_kbd.o std_kbdEv.o \
+ posix_tty.o $(MOUSESRC) xqueue.o ioperm_noop.o \
+ libc_wrapper.o stdResource.o stdPci.o sigiostubs.o pm_noop.o \
+ kmod_noop.o agp_noop.o
+
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I$(XF86OSSRC)/bus -I. \
+ -I$(SERVERSRC)/include -I$(XINCLUDESRC) -I$(EXTINCSRC) -I../sysv
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+LinkSourceFile(VTsw_usl.c,../shared)
+LinkSourceFile(ioperm_noop.c,../shared)
+LinkSourceFile(sysv_kbd.c,../shared)
+LinkSourceFile(std_kbdEv.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+
+LinkSourceFile(bios_V4mmap.c,../sysv)
+LinkSourceFile(xqueue.c,../sysv)
+
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_devs.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_devs.c
new file mode 100644
index 000000000..f221e0755
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_devs.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * This module was derived in part from the original XFree86
+ * sysv/sysv_io.c which contains the following copyright notice:
+ *
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Dawes makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID DAWES BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/pmax/pmax_devs.c,v 1.7 2002/10/11 01:40:36 dawes Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ if (loudness && pitch)
+ {
+#ifdef KDMKTONE
+ /*
+ * If we have KDMKTONE use it to avoid putting the server
+ * to sleep
+ */
+ ioctl(xf86Info.consoleFd, KDMKTONE,
+ ((1193190 / pitch) & 0xffff) |
+ (((unsigned long)duration *
+ loudness / 50) << 16));
+#else
+ ioctl(xf86Info.consoleFd, KIOCSOUND, 1193180 / pitch);
+ usleep(xf86Info.bell_duration * loudness * 20);
+ ioctl(xf86Info.consoleFd, KIOCSOUND, 0);
+#endif
+ }
+}
+
+void
+xf86SetKbdLeds(int leds)
+{
+#if 0 /* used to be KBIO_SETMODE */
+ ioctl(xf86Info.consoleFd, KBIO_SETMODE, KBM_AT);
+ ioctl(xf86Info.consoleFd, KDSETLED, leds);
+ ioctl(xf86Info.consoleFd, KBIO_SETMODE, KBM_XT);
+#endif
+
+ ioctl(xf86Info.consoleFd, KDSETLED, leds);
+}
+
+#include "xf86OSKbd.h"
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_init.c
new file mode 100644
index 000000000..7da733d22
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_init.c
@@ -0,0 +1,473 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/pmax/pmax_init.c,v 1.2.2.2 1998/07/18 17:53:54 dawes Exp $ */
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * This file was derived in part from the original XFree86 sysv OS
+ * support which contains the following copyright notice:
+ *
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Wexelblat makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/types.h>
+#include <time.h>
+#include <errno.h>
+
+#include <sys/prosrfs.h>
+#include <sys/cpu.h>
+#include <sys/ipl.h>
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+static Bool KeepTty = FALSE;
+static Bool Protect0 = FALSE;
+static Bool pmaxInitialized = FALSE;
+
+#define VT_DEFAULT -2
+#define VT_NONE -1
+
+static int VTnum = VT_DEFAULT;
+
+extern void pmax_init_splmap(void);
+
+int pmax_sys_type; /* Also used by pmax_pci.c */
+
+/*
+ * PowerMAXOS_sys_type()
+ *
+ * Determine type of PowerHawk, PowerStack, PowerMaxion, or NightHawk
+ */
+int
+PowerMAXOS_sys_type(void)
+{
+ int fd;
+ procfile_t procfile;
+
+ fd = open("/system/processor/0",O_RDONLY);
+ if (fd<0) {
+ FatalError("Cannot open '%s'\n", "/system/processor/0");
+ }
+
+ if (read(fd, &procfile, sizeof(procfile)) < 0) {
+ FatalError("Cannot read '%s'\n", "/system/processor/0");
+ }
+ close(fd);
+
+ return(procfile.cpu_model);
+}
+
+void
+pmaxInit(void)
+{
+ char *mach;
+
+ if (pmaxInitialized)
+ return;
+
+ pmaxInitialized = TRUE;
+
+ /*
+ * Determine type of machine
+ */
+ pmax_sys_type = PowerMAXOS_sys_type();
+ switch(pmax_sys_type) {
+
+ case MODEL_NH6400:
+ mach ="PowerMAXION (NH6400)";
+ break;
+
+ case MODEL_NH6408:
+ mach = "PowerMAXION (NH6408)";
+ break;
+
+ case MODEL_NH6800T:
+ mach = "TurboHawk";
+ break;
+
+ case MODEL_MPWR:
+ mach = "PowerStack";
+ break;
+
+ case MODEL_PH610:
+ mach = "PowerHawk 610";
+ break;
+
+ case MODEL_MPWR2:
+ mach = "PowerStack II (utah)";
+ break;
+
+ case MODEL_PH620:
+ mach = "PowerHawk 620";
+ break;
+
+ case MODEL_PH640:
+ mach = "PowerHawk 640";
+ break;
+
+ case MODEL_MMTX:
+ mach = "PowerStack II (MTX)";
+ break;
+
+ default:
+ FatalError("pmaxInit: Unknown/unsupported machine type 0x%x\n",
+ pmax_sys_type);
+ /*NOTREACHED*/
+ }
+
+ xf86Msg(X_INFO, "pmaxInit: Machine type: %s\n", mach);
+
+ /*
+ * Map IPL hardware so that interrupts can be (temporarily) disabled
+ * (see pmax_video.c)
+ */
+ pmax_init_splmap();
+
+ /*
+ * Now that we know the system type, initialize the
+ * pci access routines
+ */
+ pciInit();
+}
+
+void
+xf86OpenConsole()
+{
+ struct vt_mode VT;
+ char vtname[10];
+ MessageType from = X_DEFAULT;
+
+ if (serverGeneration == 1)
+ {
+
+ /* check if we're run with euid==0 */
+ if (geteuid() != 0)
+ {
+ FatalError("xf86OpenConsole: Server must be suid root\n");
+ }
+
+ /* Protect page 0 to help find NULL dereferencing */
+ /* mprotect() doesn't seem to work */
+ if (Protect0)
+ {
+ int fd = -1;
+
+ if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0)
+ {
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: cannot open /dev/zero (%s)\n",
+ strerror(errno));
+ }
+ else
+ {
+ if ((int)mmap(0, 0x1000, PROT_NONE,
+ MAP_FIXED | MAP_SHARED, fd, 0) == -1)
+ {
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: failed to protect page 0 (%s)\n",
+ strerror(errno));
+ }
+ close(fd);
+ }
+ }
+
+ pmaxInit(); /* Initialize OS specific functions */
+
+ /*
+ * setup the virtual terminal manager
+ */
+ if (VTnum == VT_DEFAULT) {
+ int fd;
+
+ /*
+ * No specific VT specified, so ask the vtl term mgr
+ * for the next available VT
+ */
+ if ((fd = open("/dev/vt00",O_WRONLY,0)) < 0) {
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: Could not open /dev/vt00 (%s)\n",
+ strerror(errno));
+ VTnum = VT_NONE;
+ }
+ else {
+ if (ioctl(fd, VT_OPENQRY, &VTnum) < 0)
+ {
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: Cannot find a free VT\n");
+ VTnum = VT_NONE;
+ }
+ close(fd);
+ }
+ } else {
+ from = X_CMDLINE;
+ }
+
+ xf86Info.vtno = VTnum;
+
+ if (xf86Info.vtno == VT_NONE)
+ strcpy(vtname, "/dev/null");
+ else
+ sprintf(vtname,"/dev/vt%02d",xf86Info.vtno);
+
+ xf86Msg(from, "using VT \"%s\"\n\n", vtname);
+
+ if (!KeepTty)
+ {
+ setpgrp();
+ }
+
+ if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) < 0)
+ {
+ FatalError("xf86OpenConsole: Cannot open %s (%s)\n",
+ vtname, strerror(errno));
+ }
+
+ if (xf86Info.vtno != VT_NONE)
+ {
+ /* change ownership of the vt */
+ (void) chown(vtname, getuid(), getgid());
+
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
+ {
+ FatalError("xf86OpenConsole: VT_GETMODE failed\n");
+ }
+
+ signal(SIGUSR1, xf86VTRequest);
+
+ VT.mode = VT_PROCESS;
+ VT.relsig = SIGUSR1;
+ VT.acqsig = SIGUSR1;
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
+ {
+ FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
+ {
+ FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n");
+ }
+ }
+ }
+ else
+ {
+ /* serverGeneration != 1 */
+ /*
+ * now get the VT
+ */
+ if (xf86Info.vtno != VT_NONE)
+ {
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
+ }
+ /*
+ * If the server doesn't have the VT when the reset occurs,
+ * this is to make sure we don't continue until the activate
+ * signal is received.
+ */
+ if (!xf86Screens[0]->vtSema)
+ sleep(5);
+ }
+ }
+ return;
+}
+
+void xf86CloseConsole()
+{
+ struct vt_mode VT;
+
+ if (xf86Info.vtno != VT_NONE)
+ {
+
+#if 0
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno);
+ ioctl(xf86Info.consoleFd, VT_WAITACTIVE, 0);
+#endif
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode ... */
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
+ {
+ VT.mode = VT_AUTO;
+ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */
+ }
+ }
+
+ close(xf86Info.consoleFd); /* make the vt-manager happy */
+ return;
+}
+
+int xf86ProcessArgument(argc, argv, i)
+int argc;
+char *argv[];
+int i;
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful
+ * when debugging (so the server can receive keyboard signals.
+ */
+ if (!strcmp(argv[i], "-keeptty"))
+ {
+ KeepTty = TRUE;
+ return(1);
+ }
+
+ /*
+ * Prevent server from attemping to open a new VT in the "-novt"
+ * flag was specified.
+ */
+ if (!strcmp(argv[i], "-novt"))
+ {
+ VTnum = VT_NONE;
+ return(1);
+ }
+
+ /*
+ * Undocumented flag to protect page 0 from read/write to help
+ * catch NULL pointer dereferences. This is purely a debugging
+ * flag.
+ */
+ if (!strcmp(argv[i], "-protect0"))
+ {
+ Protect0 = TRUE;
+ return(1);
+ }
+
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+ {
+ UseMsg();
+ VTnum = VT_DEFAULT;
+ return(0);
+ }
+ return(1);
+ }
+ return(0);
+}
+
+void xf86UseMsg()
+{
+ ErrorF("vtXX use the specified VT number\n");
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ ErrorF("-novt ");
+ ErrorF("don't allocate and open a new virtual terminal\n");
+ return;
+}
+
+
+void
+xf86_pmax_usleep(unsigned long n)
+{
+ struct timespec requested,remaining;
+ int rv;
+
+ requested.tv_sec = n/1000000;
+ requested.tv_nsec = (n % 1000000) * 1000;
+
+ while ((rv = nanosleep(&requested,&remaining)) < 0) {
+ if (errno != EINTR)
+ break;
+
+ remaining = requested; /* structure assignment */
+ }
+
+ if (rv) {
+ ErrorF("xf86_pmax_usleep: nanosleep() failed: rv=%d, errno=%d\n", rv, errno);
+ }
+}
+
+#ifndef usleep
+
+void
+usleep(unsigned long n)
+{
+ xf86_pmax_usleep(n);
+}
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_map.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_map.c
new file mode 100644
index 000000000..36d3366a2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_map.c
@@ -0,0 +1,239 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/pmax/pmax_map.c,v 1.7 2000/06/27 14:27:31 tsi Exp $ */
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * This file was derived in part from the original XFree86 sysv OS
+ * support which contains the following copyright notice:
+ *
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Wexelblat makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include "Pci.h"
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+/*
+ * Map an I/O region given its address (host POV)
+ */
+void *
+pmax_iomap(unsigned long base, unsigned long len)
+{
+ int fd;
+ void *rv;
+
+ if ((fd = open("/dev/iomem", O_RDWR)) < 0)
+ {
+ ErrorF("pmax_iomap: failed to open /dev/iomem (%s)\n",
+ strerror(errno));
+ return(MAP_FAILED);
+ }
+
+ rv = (void *)mmap((caddr_t)0, len, PROT_READ|PROT_WRITE,
+ MAP_SHARED, fd, (off_t)base);
+
+ close(fd);
+ return(rv);
+}
+
+Bool
+xf86LinearVidMem()
+{
+ return TRUE;
+}
+
+extern void * pmax_iomap(unsigned long, unsigned long);
+
+pointer
+xf86MapVidMem(int ScreenNum, int Region, pointer Base, unsigned long Size)
+{
+ ErrorF("%s: Not supported on this OS. Drivers should use xf86MapPciMem() instead\n",
+ "xf86MapVidMem");
+ FatalError("%s: Cannot map [s=%x,a=%x]\n", "xf86MapVidMem", Size, Base);
+}
+
+
+pointer
+xf86MapPciMem(int ScreenNum, int Flags, PCITAG Tag, pointer Base,
+ unsigned long Size)
+{
+ pointer hostbase = pciBusAddrToHostAddr(Tag, Base);
+ pointer base;
+
+ base = (pointer) pmax_iomap((unsigned long)hostbase, Size);
+ if (base == MAP_FAILED) {
+ xf86Msg(X_WARNING,
+ "xf86MapPciMem: Could not mmap PCI memory "
+ "[base=0x%x,hostbase=0x%x,size=%x] (%s)\n",
+ Base, hostbase, Size, strerror(errno));
+ }
+ return((pointer)base);
+}
+
+
+/* ARGSUSED */
+void
+xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap(Base, Size);
+}
+
+/*
+ * Read BIOS via mmap()ing /dev/iomem.
+ */
+/*ARGSUSED*/
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, int Len)
+{
+ ErrorF("%s: Not supported on this OS. Drivers should use xf86ReadPciBIOS() instead\n",
+ "xf86ReadBIOS");
+ FatalError("%s: Cannot read BIOS [base=0x%x,offset=0x%x,size=%d]\n", "xf86ReadBIOS", Base, Offset, Len);
+}
+
+int
+xf86ReadPciBIOS(unsigned long Base, unsigned long Offset, PCITAG Tag,
+ unsigned char *Buf, int Len)
+{
+ pointer hostbase = pciBusAddrToHostAddr(Tag, (void *)Base);
+ char *base;
+ int psize;
+ int mlen;
+
+ psize = xf86getpagesize();
+ Offset += Base & (psize - 1);
+ Base &= ~(psize - 1);
+ mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+ base = pmax_iomap((unsigned long)hostbase, mlen);
+ if (base == MAP_FAILED) {
+ xf86Msg(X_WARNING, "xf86ReadPciBIOS: Could not mmap PCI memory"
+ " [base=0x%x,hostbase=0x%x,size=%x] (%s)\n",
+ Base, hostbase, mlen, strerror(errno));
+ return(0);
+ }
+
+ (void)memcpy(Buf, base + Offset, Len);
+ (void)munmap(base, mlen);
+ return(Len);
+}
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+#include <sys/ipl.h>
+
+#ifndef PL_HI
+#define PL_HI PL8
+#endif
+
+#ifndef PL_0
+#define PL_0 PL0
+#endif
+
+static void *spl_map_addr = NULL;
+
+void
+pmax_init_splmap(void)
+{
+ spl_map_addr = spl_map(0);
+ if (!spl_map_addr) {
+ xf86Msg(X_WARNING,
+ "pmax_init_splmap: spl_map() failed. "
+ "Cannot bind to IPL register\n");
+ xf86ErrorF("\tInterrupts cannot be disabled/enabled !!!\n");
+ }
+}
+
+
+Bool
+xf86DisableInterrupts()
+{
+ if (spl_map_addr) {
+ (void)spl_request(PL_HI,spl_map_addr);
+ return(TRUE);
+ }
+
+ return(FALSE);
+}
+
+void xf86EnableInterrupts()
+{
+ if (spl_map_addr) {
+ (void)spl_request(PL_0, spl_map_addr);
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_mouse.c
new file mode 100644
index 000000000..1568598c4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_mouse.c
@@ -0,0 +1,60 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/pmax/pmax_mouse.c,v 1.2 1999/09/04 13:04:46 dawes Exp $ */
+
+/*
+ * Copyright 1999 by The XFree86 Project, Inc.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "xqueue.h"
+
+static int
+SupportedInterfaces(void)
+{
+ /* XXX Need to check this. */
+ return MSE_SERIAL | MSE_AUTO;
+}
+
+static const char *internalNames[] = {
+ "Xqueue",
+ NULL
+};
+
+static const char **
+BuiltinNames(void)
+{
+ return internalNames;
+}
+
+static Bool
+CheckProtocol(const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++)
+ if (xf86NameCmp(protocol, internalNames[i]) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+ p->BuiltinNames = BuiltinNames;
+ p->CheckProtocol = CheckProtocol;
+ p->PreInit = XqueueMousePreInit;
+ return p;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_pci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_pci.c
new file mode 100644
index 000000000..21f20dff8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_pci.c
@@ -0,0 +1,1072 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/pmax/pmax_pci.c,v 1.6 2002/07/24 19:06:53 tsi Exp $ */
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include "os.h"
+#include "compiler.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "Pci.h"
+
+#include <sys/prosrfs.h>
+#include <sys/cpu.h>
+
+/*
+ * Night Hawk 6400/6408 platform support
+ */
+#undef NH640X_PCI_MFDEV_SUPPORT
+#undef NH640X_PCI_BRIDGE_SUPPORT
+
+static void nh640xPciInit(void);
+static PCITAG nh640xPciFindNext(void);
+static PCITAG nh640xPciFindFirst(void);
+static CARD32 nh6400PciReadLong(PCITAG tag, int offset);
+static void nh6400PciWriteLong(PCITAG tag, int offset, CARD32 val);
+static ADDRESS nh6400BusToHostAddr(PCITAG tag, ADDRESS addr);
+static ADDRESS nh6400HostToBusAddr(PCITAG tag, ADDRESS addr);
+static CARD32 nh6408PciReadLong(PCITAG tag, int offset);
+static void nh6408PciWriteLong(PCITAG tag, int offset, CARD32 val);
+static ADDRESS nh6408BusToHostAddr(PCITAG tag, ADDRESS addr);
+static ADDRESS nh6408HostToBusAddr(PCITAG tag, ADDRESS addr);
+
+static pciBusFuncs_t nh6400_pci_funcs = {
+ nh6400PciReadLong,
+ nh6400PciWriteLong,
+ nh6400HostToBusAddr,
+ nh6400BusToHostAddr
+};
+
+static pciBusFuncs_t nh6408_pci_funcs = {
+ nh6408PciReadLong,
+ nh6408PciWriteLong,
+ nh6408HostToBusAddr,
+ nh6408BusToHostAddr
+};
+
+/*
+ * NH640x CFG address and data register offsets from base
+ */
+#define NH6400_PCI_CFG_ADDR_REG_OFF 0
+#define NH6400_PCI_CFG_TYPE0_DATA_REG_OFF 0x40
+#define NH6400_PCI_CFG_TYPE1_DATA_REG_OFF 0x80
+
+#define NH6408_PCI_CFG_ADDR_REG_OFF 0
+#define NH6408_PCI_CFG_DATA_REG_OFF 0x10000
+
+/*
+ * Possible cfg addr values for NH640x GMEM PMC ports
+ */
+static unsigned long nh6400_pmc_cfgaddrs[] = {
+ PCI_CFGMECH1_TYPE0_CFGADDR(0,0,0)
+};
+
+/*
+ * Possible cfg addr values for devices on a secondary bus
+ * (e.g. behind DEC 21152 PCI-to-PCI bridge)
+ */
+static unsigned long dec_cfgaddrs[] = {
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,0,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,1,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,2,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,3,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,4,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,5,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,6,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,7,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,8,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,9,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,10,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,11,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,12,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,13,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,14,0,0),
+ PCI_CFGMECH1_TYPE1_CFGADDR(1,15,0,0)
+};
+
+/*
+ * Data structure holding information about various nh640x PCI buses
+ */
+struct nh640x_pci_info {
+ int busnum;
+ int type;
+ unsigned long num_cfg_addrs;
+ unsigned long *cfg_addrs;
+ int primary_bus;
+ unsigned long cfgPhysBase;
+ unsigned long memBase;
+ unsigned long ioBase;
+ unsigned long ioSize;
+ unsigned char *cfgAddrReg; /* After mapping */
+};
+
+/* Type */
+#define PRIMARY_PCI 0
+#define SECONDARY_PCI 1
+
+static struct nh640x_pci_info nh6400_pci_info[] = {
+/* pci4 */ { 4, PRIMARY_PCI, 1, nh6400_pmc_cfgaddrs, 0, 0xa0000000, 0xa1000000, 0, 0xa2000000 },
+/* pci12 */ { 12, SECONDARY_PCI, 16, dec_cfgaddrs, 4 },
+#if 0
+/* pci5 */ { 5, PRIMARY_PCI, 1, nh6400_pmc_cfgaddrs, 0, 0xb0000000, 0xb1000000, 0, 0xb2000000 },
+/* pci13 */ { 13, SECONDARY_PCI, 16, dec_cfgaddrs, 5 },
+#endif
+};
+
+#define NH6400_NUM_PCI_EXPANSION_BUSES (sizeof(nh6400_pci_info)/sizeof(struct nh640x_pci_info))
+
+static struct nh640x_pci_info nh6408_pci_info[] = {
+/* pci8 */ { 8, PRIMARY_PCI, 1, nh6400_pmc_cfgaddrs, 0, 0x98040000, 0x9a800000, 65536, 0xa0000000 },
+/* pci12 */ { 12, SECONDARY_PCI, 16, dec_cfgaddrs, 8, },
+#if 0
+/* pci9 */ { 9, PRIMARY_PCI, 1, nh6400_pmc_cfgaddrs, 0, 0x99040000, 0x9b800000, 65536, 0xb0000000 },
+/* pci13 */ { 13, SECONDARY_PCI, 16, dec_cfgaddrs, 9, },
+#endif
+};
+
+#define NH6408_NUM_PCI_EXPANSION_BUSES (sizeof(nh6408_pci_info)/sizeof(struct nh640x_pci_info))
+
+extern unsigned long pmax_sys_type;
+
+#define MOTOPPC_IO_BASE 0x80000000L /* Start of PCI/ISA I/O region */
+
+extern void * pmax_iomap(unsigned long, unsigned long);
+extern unsigned long ioSize;
+extern volatile unsigned char *ioBase;
+
+void
+pmaxPciInit(void)
+{
+ extern void motoppcPciInit(void);
+ extern void nh640xPciInit(void);
+ extern void nh6800tPciInit(void);
+
+ extern unsigned long motoPciMemBase;
+ extern unsigned long motoPciMemLen;
+ extern unsigned long motoPciMemBaseCPU;
+
+ /*
+ * Determine type of machine
+ */
+ switch(pmax_sys_type) {
+ case MODEL_NH6400:
+ case MODEL_NH6408:
+ nh640xPciInit();
+ break;
+
+ case MODEL_NH6800T:
+ nh6800tPciInit();
+ break;
+
+ case MODEL_PH620:
+ case MODEL_PH640:
+ case MODEL_MMTX:
+ motoPciMemBase = 0;
+ motoPciMemLen = 0x20000000;
+ motoPciMemBaseCPU = 0xa0000000;
+ /*FALLTHROUGH*/
+
+ case MODEL_MPWR:
+ case MODEL_PH610:
+ case MODEL_MPWR2:
+ motoppcPciInit();
+ break;
+
+ default:
+ FatalError("pmaxPciInit: Unsupported machine type\n");
+ break;
+ }
+}
+
+void
+ppcPciIoMap(int pcibus)
+{
+ int primary_bus;
+
+ if (ioBase != MAP_FAILED)
+ munmap((void*)ioBase,ioSize);
+
+ if (!pciBusInfo[pcibus])
+ return;
+
+ primary_bus = pciBusInfo[pcibus]->primary_bus;
+
+ if (!pciBusInfo[primary_bus])
+ return;
+
+ ioSize = min(pciBusInfo[primary_bus]->ppc_io_size, 64 * 1024);
+ if (ioSize) {
+ ioBase = (unsigned char *)pmax_iomap(pciBusInfo[primary_bus]->ppc_io_base, ioSize);
+ if (ioBase == MAP_FAILED)
+ ioSize = 0;
+ }
+}
+
+static void
+nh640xPciInit(void)
+{
+ int i,n;
+ struct nh640x_pci_info *infop;
+ pciBusFuncs_p functions;
+
+ switch (pmax_sys_type) {
+ case MODEL_NH6400:
+ n = NH6400_NUM_PCI_EXPANSION_BUSES;
+ infop = nh6400_pci_info;
+ functions = &nh6400_pci_funcs;
+ break;
+ case MODEL_NH6408:
+ n = NH6408_NUM_PCI_EXPANSION_BUSES;
+ infop = nh6408_pci_info;
+ functions = &nh6408_pci_funcs;
+ break;
+ default:
+ FatalError("Unknown Power MAXION system type\n");
+ /*NOTREACHED*/
+ }
+
+ /*
+ * Initialize entries in pciBusInfo[] table for each defined PCI bus.
+ * This table is actually sparse because undefined or inaccessible
+ * pci buses are left as NULL entries. Of course, pciFindNext() is
+ * aware of this convention, and will skip the undefined buses.
+ */
+ for (i=0; i<n; infop++,i++) {
+ int bus = infop->busnum;
+ pciBusInfo_t *busp;
+
+ if (pciBusInfo[bus])
+ busp = pciBusInfo[bus];
+ else
+ busp = xalloc(sizeof(pciBusInfo_t));
+
+ if (!busp)
+ FatalError("nh640xPciInit: xalloc failed\n");
+
+ /* Initialize pci bus info */
+ busp->configMech = PCI_CFG_MECH_OTHER;
+ busp->numDevices = infop->num_cfg_addrs;
+ busp->secondary = (infop->type == SECONDARY_PCI ? TRUE : FALSE);
+ busp->primary_bus = infop->primary_bus;
+ busp->funcs = functions;
+ busp->pciBusPriv = infop;
+
+ /* Initialize I/O base/size info */
+ if (busp->secondary) {
+ pciBusInfo_t *pri_busp = pciBusInfo[busp->primary_bus];
+ if (pri_busp) {
+ busp->ppc_io_base = pri_busp->ppc_io_base;
+ busp->ppc_io_size = pri_busp->ppc_io_size;
+ }
+ }
+ else if (infop->ioSize) {
+ busp->ppc_io_size = infop->ioSize;
+ busp->ppc_io_base = infop->ioBase;
+ }
+
+ pciBusInfo[bus] = busp;
+
+ /*
+ * Adjust pciNumBuses to reflect the highest defined entry in pciBusInfo
+ */
+ if (pciNumBuses < bus)
+ pciNumBuses = bus + 1;
+ }
+
+ pciFindFirstFP = nh640xPciFindFirst;
+ pciFindNextFP = nh640xPciFindNext;
+}
+
+static PCITAG
+nh640xPciFindNext(void)
+{
+ unsigned long devid, tmp;
+ unsigned char base_class, sub_class, sec_bus, pri_bus;
+
+ for (;;) {
+
+ if (pciBusNum == -1) {
+ /*
+ * Start at top of the order
+ */
+ pciBusNum = 0;
+ pciFuncNum = 0;
+ pciDevNum = 0;
+ }
+ else {
+#ifdef NH640X_PCI_MFDEV_SUPPORT
+ /*
+ * Somewhere in middle of order. Determine who's
+ * next up
+ */
+ if (pciFuncNum == 0) {
+ /*
+ * Is current dev a multifunction device?
+ */
+ if (pciMfDev(pciBusNum, pciDevNum))
+ /* Probe for other functions */
+ pciFuncNum = 1;
+ else
+ /* No more functions this device. Next device please */
+ pciDevNum ++;
+ }
+ else if (++pciFuncNum >= 8) {
+ /* No more functions for this device. Next device please */
+ pciFuncNum = 0;
+ pciDevNum ++;
+ }
+#else /* NH640X_PCI_MFDEV_SUPPORT */
+ pciDevNum++;
+#endif /* NH640X_PCI_MFDEV_SUPPORT */
+
+ if (!pciBusInfo[pciBusNum] || pciDevNum >= pciBusInfo[pciBusNum]->numDevices) {
+ /*
+ * No more devices for this bus. Next bus please
+ */
+ if (++pciBusNum >= pciNumBuses)
+ /* No more buses. All done for now */
+ return(PCI_NOT_FOUND);
+
+ pciDevNum = 0;
+ }
+ }
+
+ if (!pciBusInfo[pciBusNum])
+ continue; /* Undefined bus, next bus/device please */
+
+ /*
+ * At this point, pciBusNum, pciDevNum, and pciFuncNum have been
+ * advanced to the next device. Compute the tag, and read the
+ * device/vendor ID field.
+ */
+ pciDeviceTag = PCI_MAKE_TAG(pciBusNum, pciDevNum, pciFuncNum);
+ devid = pciReadLong(pciDeviceTag, 0);
+ if (devid == 0xffffffff)
+ continue; /* Nobody home. Next device please */
+
+#ifdef NH640X_PCI_BRIDGE_SUPPORT
+ /*
+ * Before checking for a specific devid, look for enabled
+ * PCI to PCI bridge devices. If one is found, create and
+ * initialize a bus info record (if one does not already exist).
+ */
+ tmp = pciReadLong(pciDeviceTag, PCI_CLASS_CODE_REG);
+ base_class = PCI_EXTRACT_BASE_CLASS(tmp);
+ sub_class = PCI_EXTRACT_SUBCLASS(tmp);
+ if (base_class == PCI_CLASS_BRIDGE && sub_class == PCI_SUBCLASS_BRIDGE_PCI) {
+ tmp = pciReadLong(pciDeviceTag, PCI_BRIDGE_BUS_REG);
+ sec_bus = PCI_SECONDARY_BUS_EXTRACT(tmp);
+ pri_bus = PCI_PRIMARY_BUS_EXTRACT(tmp);
+ if (sec_bus > 0 && sec_bus < PCI_MAX_BUSES && pcibusInfo[pri_bus]) {
+ /*
+ * Found a secondary PCI bus
+ */
+ if (!pciBusInfo[sec_bus]) {
+ pciBusInfo[sec_bus] = xalloc(sizeof(pciBusInfo_t));
+
+ if (!pciBusInfo[sec_bus])
+ FatalError("nh640xPciFindNext: alloc failed\n!!!");
+ }
+
+ /* Copy parents settings... */
+ *pciBusInfo[sec_bus] = *pcibusInfo[pri_bus];
+
+ /* ...but not everything same as parent */
+ pciBusInfo[sec_bus]->primary_bus = pri_bus;
+ pciBusInfo[sec_bus]->secondary = TRUE;
+ pciBusInfo[sec_bus]->numDevices = 32;
+
+ if (pciNumBuses < sec_num)
+ pciNumBuses = sec_num+1;
+ }
+ }
+#endif /* NH640X_PCI_BRIDGE_SUPPORT */
+
+ /*
+ * Does this device match the requested devid after
+ * applying mask?
+ */
+ if ((devid & pciDevidMask) == pciDevid) {
+ /* Yes - Return it. Otherwise, next device */
+
+ /* However, before returning it, try to map */
+ /* I/O region for this PCI bus */
+ ppcPciIoMap(PCI_BUS_FROM_TAG(pciDeviceTag));
+
+ return(pciDeviceTag); /* got a match */
+ }
+
+ } /* for */
+
+ /*NOTREACHED*/
+}
+
+static PCITAG
+nh640xPciFindFirst(void)
+{
+ pciBusNum = -1;
+ return(nh640xPciFindNext());
+}
+
+static unsigned long
+nh6400PciReadLong(PCITAG tag, int offset)
+{
+ unsigned long tmp;
+ char *base;
+ int devnum, bus, func, data_reg_offset, ndevs;
+ unsigned long cfgaddr;
+ pciBusInfo_t *busp, *pri_busp;
+ struct nh640x_pci_info *infop, *pri_infop;
+
+ bus = PCI_BUS_FROM_TAG(tag);
+ devnum = PCI_DEV_FROM_TAG(tag);
+ func = PCI_FUNC_FROM_TAG(tag);
+
+ xf86MsgVerb(3, X_INFO,
+ "nh6400PciReadLong: bus=%d, devnum=%d, func=%d, offset=0x%x\n",
+ bus, devnum, func, offset);
+
+ if (bus >= pciNumBuses || !pciBusInfo[bus]) {
+ xf86Msg(X_WARNING, "nh6400PciReadLong: bus pci%d not defined!!!\n",
+ bus);
+ return(0xffffffff);
+ }
+
+ busp = pciBusInfo[bus];
+ infop = (struct nh640x_pci_info *)busp->pciBusPriv;
+
+ if (busp->secondary) {
+ /*
+ * Secondary PCI bus behind a pci-to-pci bridge
+ */
+ pri_busp = pciBusInfo[busp->primary_bus];
+ pri_infop = (struct nh640x_pci_info *)pri_busp->pciBusPriv;
+ ndevs = 16;
+ data_reg_offset = NH6400_PCI_CFG_TYPE1_DATA_REG_OFF; /* For Type 1 cfg cycles */
+
+ if (!pri_busp) {
+ xf86Msg(X_WARNING,
+ "nh6400PciReadLong: pci%d's primary parent [pci%d] "
+ "is not defined!!!\n", bus, busp->primary_bus);
+ return(0xffffffff);
+ }
+ }
+ else {
+ pri_busp = busp;
+ pri_infop = infop;
+ ndevs = infop->num_cfg_addrs;
+ data_reg_offset = NH6400_PCI_CFG_TYPE0_DATA_REG_OFF; /* For Type 0 cfg cycles */
+ }
+
+ if (devnum >= ndevs) {
+ xf86Msg(X_WARNING,
+ "nh6400PciReadLong: devnum %d out of range for bus pci%d\n",
+ devnum, bus);
+ return(0xffffffff);
+ }
+
+ /*
+ * Make sure the cfg address and data registers for this bus are mapped
+ * Secondary buses just use the primary parents addreses
+ */
+ if (!infop->cfgAddrReg) {
+ if (!pri_infop->cfgAddrReg) {
+ pri_infop->cfgAddrReg = pmax_iomap(pri_infop->cfgPhysBase, 0x1000);
+ if (pri_infop->cfgAddrReg == MAP_FAILED) {
+ FatalError("nh6400PciReadLong: Cannot map PCI cfg regs @ 0x%08x\n",
+ pri_infop->cfgPhysBase);
+ /*NOTREACHED*/
+ }
+ }
+ infop->cfgAddrReg = pri_infop->cfgAddrReg;
+ infop->cfgPhysBase = pri_infop->cfgPhysBase;
+ }
+ base = infop->cfgAddrReg;
+
+ if (busp->secondary) {
+ /* cfgaddr = PCI_CFGMECH1_TYPE1_CFGADDR(bus,devnum,func,offset); */
+ cfgaddr = PCI_CFGMECH1_TYPE1_CFGADDR(1,devnum,func,offset); /* Must use bus=1 for now - glb */
+ }
+ else {
+ cfgaddr = infop->cfg_addrs[devnum] + offset;
+ }
+
+ xf86MsgVerb(X_INFO, 3,
+ "nh6400PciReadLong: Writing cfgaddr=0x%x to 0x%x (phys=0x%x)\n",
+ cfgaddr, base, infop->cfgPhysBase);
+
+ /* There may not be any OS interaction while interrupts are disabled */
+ xf86DisableInterrupts();
+
+ *((unsigned long *)(base)) = pciByteSwap(cfgaddr); /* Set cfg address */
+ eieio();
+
+ if (!badaddr(base + data_reg_offset, 4, 0)) {
+ tmp = *((unsigned long *)(base + data_reg_offset));
+ eieio();
+ }
+
+ xf86EnableInterrupts();
+
+ xf86MsgVerb(X_INFO, 3, "nh6400PciReadLong: Read value=0x%x from 0x%x (phys=0x%x)\n",
+ pciByteSwap(tmp), base + data_reg_offset, infop->cfgPhysBase + data_reg_offset);
+
+ return(pciByteSwap(tmp));
+}
+
+static void
+nh6400PciWriteLong(PCITAG tag, int offset, unsigned long val)
+{
+ char *base;
+ int devnum, bus, func, data_reg_offset, ndevs;
+ unsigned long cfgaddr;
+ pciBusInfo_t *busp, *pri_busp;
+ struct nh640x_pci_info *infop, *pri_infop;
+
+ bus = PCI_BUS_FROM_TAG(tag);
+ devnum = PCI_DEV_FROM_TAG(tag);
+ func = PCI_FUNC_FROM_TAG(tag);
+
+ xf86MsgVerb(X_INFO, 3,
+ "nh6400PciWriteLong: bus=%d, devnum=%d, func=%d, offset=0x%x, "
+ val=0x%x\n", bus, devnum, func, offset, val);
+
+ if (bus >= pciNumBuses || !pciBusInfo[bus]) {
+ xf86Msg(X_WARNING, "nh6400PciWriteLong: bus pci%d not defined!!!\n",
+ bus);
+ return;
+ }
+ busp = pciBusInfo[bus];
+ infop = (struct nh640x_pci_info *)busp->pciBusPriv;
+
+ if (busp->secondary) {
+ /*
+ * Secondary PCI bus behind a pci-to-pci bridge
+ */
+ pri_busp = pciBusInfo[busp->primary_bus];
+ pri_infop = (struct nh640x_pci_info *)pri_busp->pciBusPriv;
+ ndevs = 16;
+ data_reg_offset = NH6400_PCI_CFG_TYPE1_DATA_REG_OFF; /* For Type 1 cfg cycles */
+
+ if (!pri_busp) {
+ xf86Msg(X_WARNING,
+ "nh6400PciWriteLong: pci%d's primary parent [pci%d]"
+ " is not defined!!!\n", bus, busp->primary_bus);
+ return;
+ }
+ }
+ else {
+ pri_busp = busp;
+ pri_infop = infop;
+ ndevs = infop->num_cfg_addrs;
+ data_reg_offset = NH6400_PCI_CFG_TYPE0_DATA_REG_OFF; /* For Type 0 cfg cycles */
+ }
+
+ if (devnum >= ndevs) {
+ xf86Msg(X_WARNING,
+ "nh6400PciWriteLong: devnum %d out of range for bus pci%d\n",
+ devnum, bus);
+ return;
+ }
+
+ /*
+ * Make sure the cfg address and data registers for this bus are mapped
+ * Secondary buses just use the primary parents addreses
+ */
+ if (!infop->cfgAddrReg) {
+ if (!pri_infop->cfgAddrReg) {
+ pri_infop->cfgAddrReg = pmax_iomap(pri_infop->cfgPhysBase, 0x1000);
+ if (pri_infop->cfgAddrReg == MAP_FAILED) {
+ FatalError("nh6400PciWriteLong: Cannot map PCI cfg regs @ 0x%08x\n",
+ pri_infop->cfgPhysBase);
+ /*NOTREACHED*/
+ }
+ }
+ infop->cfgAddrReg = pri_infop->cfgAddrReg;
+ infop->cfgPhysBase = pri_infop->cfgPhysBase;
+ }
+ base = infop->cfgAddrReg;
+
+ if (busp->secondary) {
+ /* cfgaddr = PCI_CFGMECH1_TYPE1_CFGADDR(bus,devnum,func,offset); */
+ cfgaddr = PCI_CFGMECH1_TYPE1_CFGADDR(1,devnum,func,offset); /* Must use bus=1 for now - glb */
+ }
+ else {
+ cfgaddr = infop->cfg_addrs[devnum] + offset;
+ }
+
+ xf86MsgVerb(X_INFO, 3,
+ "nh6400PciWriteLong: Writing cfgaddr=0x%x to 0x%x (phys=0x%x)\n",
+ cfgaddr, base, infop->cfgPhysBase);
+
+ /* There may not be any OS interaction while interrupts are disabled */
+ xf86DisableInterrupts();
+
+ *((unsigned long *)(base)) = pciByteSwap(cfgaddr); /* Set cfg address */
+ eieio();
+
+ *((unsigned long *)(base + data_reg_offset)) = pciByteSwap(val);
+ eieio();
+
+ xf86EnableInterrupts();
+
+ xf86MsgVerb(X_INFO, 3,
+ "nh6400PciWriteLong: Wrote value=0x%x to 0x%x (phys=0x%x)\n",
+ val, base + data_reg_offset,
+ infop->cfgPhysBase + data_reg_offset);
+}
+
+/*
+ * These next two functions are for debugging purposes only because
+ * the nh6400 does not translate passed to/from a PCI domain. However,
+ * we do do some bounds checking to make sure things are where they
+ * should be.
+ */
+static ADDRESS
+nh6400BusToHostAddr(PCITAG tag, ADDRESS addr)
+{
+ unsigned long addr_l = (unsigned long)addr;
+ int bus = PCI_BUS_FROM_TAG(tag);
+ struct nh640x_pci_info *infop;
+ int pri_bus;
+ unsigned long membase;
+
+ if (!pciBusInfo[bus])
+ FatalError("nh6400BusToHostAddr: pci%d not defined!!\n", bus);
+
+ if (pciBusInfo[bus]->secondary) {
+ pri_bus = pciBusInfo[bus]->primary_bus;
+
+ if (!pciBusInfo[pri_bus])
+ FatalError("nh6400BusToHostAddr: Primary bus pci%d not defined!!\n", pri_bus);
+ }
+ else
+ pri_bus = bus;
+
+ infop = (struct nh640x_pci_info *)pciBusInfo[pri_bus]->pciBusPriv;
+ membase = infop->memBase;
+
+ if (addr_l < 0x80000000)
+ /*
+ * NH6400 host memory addresses are 0-0x7fffffff
+ */
+ return(addr);
+
+ else if (addr_l >= membase && addr_l < membase + 0x0e000000)
+ /*
+ * NH6400 host can access PCI memory space addresses
+ * [memBase, memBase+0x0dffffff]
+ */
+ return(addr);
+ else
+ /* Other addresses are not valid */
+ FatalError("nh6400BusToHostAddr: Bus address 0x%x not visible to NH6400 host\n",
+ addr_l);
+
+ /*NOTREACHED*/
+}
+
+static ADDRESS
+nh6400HostToBusAddr(PCITAG tag, ADDRESS addr)
+{
+ unsigned long addr_l = (unsigned long) addr;
+ int bus = PCI_BUS_FROM_TAG(tag);
+ struct nh640x_pci_info *infop;
+ int pri_bus;
+ unsigned long membase;
+
+ if (!pciBusInfo[bus])
+ FatalError("nh6400HostToBusAddr: pci%d not defined!!\n", bus);
+
+ if (pciBusInfo[bus]->secondary) {
+ pri_bus = pciBusInfo[bus]->primary_bus;
+
+ if (!pciBusInfo[pri_bus])
+ FatalError("nh6400HostToBusAddr: Primary bus pci%d not defined!!\n", pri_bus);
+ }
+ else
+ pri_bus = bus;
+
+ infop = (struct nh640x_pci_info *)pciBusInfo[pri_bus]->pciBusPriv;
+ membase = infop->memBase;
+
+ if (addr_l < 0x80000000)
+ /*
+ * NH6400 host memory addresses are 0-0x7fffffff
+ */
+ return(addr);
+
+ else if (addr_l >= membase && addr_l < membase + 0x0e000000)
+ /*
+ * NH6400 host can access PCI memory space addresses
+ * [memBase, memBase+0x0dffffff]
+ */
+ return(addr);
+ else
+ /* Other addresses are not valid */
+ FatalError("nh6400HostToBusAddr: Bus address 0x%x not visible to NH6400 host\n",
+ addr_l);
+
+ /*NOTREACHED*/
+}
+
+
+/*
+ * NH6408 platform support
+ */
+static unsigned long
+nh6408PciReadLong(PCITAG tag, int offset)
+{
+ unsigned long tmp;
+ char *base;
+ int devnum, bus, func, ndevs;
+ unsigned long cfgaddr;
+ pciBusInfo_t *busp, *pri_busp;
+ struct nh640x_pci_info *infop, *pri_infop;
+
+ bus = PCI_BUS_FROM_TAG(tag);
+ devnum = PCI_DEV_FROM_TAG(tag);
+ func = PCI_FUNC_FROM_TAG(tag);
+
+ xf86MsgVerb(X_INFO,
+ "nh6408PciReadLong: bus=%d, devnum=%d, func=%d, offset=0x%x\n",
+ bus, devnum, func, offset);
+
+ if (bus >= pciNumBuses || !pciBusInfo[bus]) {
+ xf86Msg(X_WARNING, "nh6408PciReadLong: bus pci%d not defined!!!\n",
+ bus);
+ return(0xffffffff);
+ }
+
+ busp = pciBusInfo[bus];
+ infop = (struct nh640x_pci_info *)busp->pciBusPriv;
+
+ if (busp->secondary) {
+ /*
+ * Secondary PCI bus behind a pci-to-pci bridge
+ */
+ pri_busp = pciBusInfo[busp->primary_bus];
+ pri_infop = (struct nh640x_pci_info *)pri_busp->pciBusPriv;
+ ndevs = 16;
+
+ if (!pri_busp) {
+ xf86Msg(X_WARNING,
+ "nh6408PciReadLong: pci%d's primary parent [pci%d] "
+ "is not defined!!!\n", bus, busp->primary_bus);
+ return(0xffffffff);
+ }
+ }
+ else {
+ pri_busp = busp;
+ pri_infop = infop;
+ ndevs = infop->num_cfg_addrs;
+ }
+
+ if (devnum >= ndevs) {
+ xf86Msg(X_WARNING
+ "nh6408PciReadLong: devnum %d out of range for bus pci%d\n",
+ devnum, bus);
+ return(0xffffffff);
+ }
+
+ /*
+ * Make sure the cfg address and data registers for this bus are mapped
+ * Secondary buses just use the primary parents addreses
+ */
+ if (!infop->cfgAddrReg) {
+ if (!pri_infop->cfgAddrReg) {
+ pri_infop->cfgAddrReg = pmax_iomap(pri_infop->cfgPhysBase, 0x11000);
+ if (pri_infop->cfgAddrReg == MAP_FAILED) {
+ FatalError("nh6408PciReadLong: Cannot map PCI cfg regs @ 0x%08x\n",
+ pri_infop->cfgPhysBase);
+ /*NOTREACHED*/
+ }
+ }
+ infop->cfgAddrReg = pri_infop->cfgAddrReg;
+ infop->cfgPhysBase = pri_infop->cfgPhysBase;
+ }
+ base = infop->cfgAddrReg;
+
+ if (busp->secondary) {
+ /* cfgaddr = PCI_CFGMECH1_TYPE1_CFGADDR(bus,devnum,func,offset); */
+ cfgaddr = PCI_CFGMECH1_TYPE1_CFGADDR(1,devnum,func,offset); /* Must use bus=1 for now - glb */
+ }
+ else {
+ cfgaddr = infop->cfg_addrs[devnum] + offset;
+ }
+
+ xf86MsgVerb(X_INFO, 3,
+ "nh6408PciReadLong: Writing cfgaddr=0x%x to 0x%x (phys=0x%x)\n",
+ cfgaddr, base, infop->cfgPhysBase);
+
+ /* There may not be any OS interaction while interrupts are disabled */
+ xf86DisableInterrupts();
+
+ *((unsigned long *)(base)) = pciByteSwap(cfgaddr); /* Set cfg address */
+ eieio();
+
+ if (!badaddr(base + NH6408_PCI_CFG_DATA_REG_OFF, 4, 0)) {
+ tmp = *((unsigned long *)(base + NH6408_PCI_CFG_DATA_REG_OFF));
+ eieio();
+ }
+
+ xf86EnableInterrupts();
+
+ xf86MsgVerb(X_INFO, 3, "nh6408PciReadLong: Read value=0x%x from 0x%x (phys=0x%x)\n",
+ pciByteSwap(tmp),
+ base + NH6408_PCI_CFG_DATA_REG_OFF,
+ infop->cfgPhysBase + NH6408_PCI_CFG_DATA_REG_OFF);
+
+ return(pciByteSwap(tmp));
+}
+
+static void
+nh6408PciWriteLong(PCITAG tag, int offset, unsigned long val)
+{
+ char *base;
+ int devnum, bus, func, ndevs;
+ unsigned long cfgaddr;
+ pciBusInfo_t *busp, *pri_busp;
+ struct nh640x_pci_info *infop, *pri_infop;
+
+ bus = PCI_BUS_FROM_TAG(tag);
+ devnum = PCI_DEV_FROM_TAG(tag);
+ func = PCI_FUNC_FROM_TAG(tag);
+
+ xf86MsgVerb(X_INFO,
+ "nh6408PciWriteLong: bus=%d, devnum=%d, func=%d, offset=0x%x, "
+ "val=0x%x\n", bus, devnum, func, offset, val);
+
+ if (bus >= pciNumBuses || !pciBusInfo[bus]) {
+ xf86Msg(X_WARNING, "nh6408PciWriteLong: bus pci%d not defined!!!\n",
+ bus);
+ return;
+ }
+
+ busp = pciBusInfo[bus];
+ infop = (struct nh640x_pci_info *)busp->pciBusPriv;
+
+ if (busp->secondary) {
+ /*
+ * Secondary PCI bus behind a pci-to-pci bridge
+ */
+ pri_busp = pciBusInfo[busp->primary_bus];
+ pri_infop = (struct nh640x_pci_info *)pri_busp->pciBusPriv;
+ ndevs = 16;
+
+ if (!pri_busp) {
+ xf86Msg(X_WARNING,
+ "nh6408PciWriteLong: pci%d's primary parent [pci%d] "
+ is not defined!!!\n", bus, busp->primary_bus);
+ return;
+ }
+ }
+ else {
+ pri_busp = busp;
+ pri_infop = infop;
+ ndevs = infop->num_cfg_addrs;
+ }
+
+ if (devnum >= ndevs) {
+ xf86Msg(X_WARNING,
+ "nh6408PciWriteLong: devnum %d out of range for bus pci%d\n",
+ devnum, bus);
+ return;
+ }
+
+ /*
+ * Make sure the cfg address and data registers for this bus are mapped
+ * Secondary buses just use the primary parents addreses
+ */
+ if (!infop->cfgAddrReg) {
+ if (!pri_infop->cfgAddrReg) {
+ pri_infop->cfgAddrReg = pmax_iomap(pri_infop->cfgPhysBase, 0x11000);
+ if (pri_infop->cfgAddrReg == MAP_FAILED) {
+ FatalError("nh6408PciWriteLong: Cannot map PCI cfg regs @ 0x%08x\n",
+ pri_infop->cfgPhysBase);
+ /*NOTREACHED*/
+ }
+ }
+ infop->cfgAddrReg = pri_infop->cfgAddrReg;
+ infop->cfgPhysBase = pri_infop->cfgPhysBase;
+ }
+ base = infop->cfgAddrReg;
+
+ if (busp->secondary) {
+ /* cfgaddr = PCI_CFGMECH1_TYPE1_CFGADDR(bus,devnum,0,offset); */
+ cfgaddr = PCI_CFGMECH1_TYPE1_CFGADDR(1,devnum,0,offset);
+ }
+ else {
+ cfgaddr = infop->cfg_addrs[devnum] + offset;
+ }
+
+ xf86MsgVerb(X_INFO, 3,
+ "nh6408PciWriteLong: Writing cfgaddr=0x%x to 0x%x (phys=0x%x)\n",
+ cfgaddr, base, infop->cfgPhysBase);
+
+ /* There may not be any OS interaction while interrupts are disabled */
+ xf86DisableInterrupts();
+
+ *((unsigned long *)(base)) = pciByteSwap(cfgaddr); /* Set cfg address */
+ eieio();
+
+ *((unsigned long *)(base + NH6408_PCI_CFG_DATA_REG_OFF)) = pciByteSwap(val);
+ eieio();
+
+ xf86EnableInterrupts();
+
+ xf86MsgVerb(X_INFO, 3,
+ "nh6408PciWriteLong: Wrote value=0x%x to 0x%x (phys=0x%x)\n",
+ val, base + NH6408_PCI_CFG_DATA_REG_OFF,
+ infop->cfgPhysBase + NH6408_PCI_CFG_DATA_REG_OFF);
+}
+
+
+static ADDRESS
+nh6408BusToHostAddr(PCITAG tag, ADDRESS addr)
+{
+ unsigned long addr_l = (unsigned long)addr;
+ int bus = PCI_BUS_FROM_TAG(tag);
+ int pri_bus;
+ struct nh640x_pci_info *infop;
+ unsigned long membase;
+
+ if (!pciBusInfo[bus])
+ FatalError("nh6408BusToHostAddr: pci%d not defined!!\n", bus);
+
+ if (pciBusInfo[bus]->secondary) {
+ pri_bus = pciBusInfo[bus]->primary_bus;
+
+ if (!pciBusInfo[pri_bus])
+ FatalError("nh6408BusToHostAddr: Primary bus pci%d not defined!!\n", pri_bus);
+ }
+ else
+ pri_bus = bus;
+
+ infop = (struct nh640x_pci_info *)pciBusInfo[pri_bus]->pciBusPriv;
+ membase = infop->memBase;
+
+ if (addr_l < 0x10000000)
+ /*
+ * NH6408 host sees PCI memory space addresses 0-0x0fffffff
+ * at the primary PCI buses "memBase" [memBase, memBase+0x0fffffff]
+ */
+ return((ADDRESS)(membase + addr_l));
+
+ else if (addr_l >= 0x80000000)
+ /*
+ * NH6408 host memory addresses 0-0x7fffffff are seen at
+ * 0x80000000-0xffffffff on PCI
+ */
+ return((ADDRESS)(addr_l & 0x7fffffff));
+
+ else
+ /* Other addresses are not valid */
+ FatalError("nh6408BusToHostAddr: Bus address 0x%x not visible to NH6408 host\n",
+ addr_l);
+
+ /*NOTREACHED*/
+}
+
+static ADDRESS
+nh6408HostToBusAddr(PCITAG tag, ADDRESS addr)
+{
+ unsigned long addr_l = (unsigned long)addr;
+ int bus = PCI_BUS_FROM_TAG(tag);
+ int pri_bus;
+ struct nh640x_pci_info *infop;
+ unsigned long membase;
+
+ if (!pciBusInfo[bus])
+ FatalError("nh6408HostToBusAddr: pci%d not defined!!\n", bus);
+
+ if (pciBusInfo[bus]->secondary) {
+ pri_bus = pciBusInfo[bus]->primary_bus;
+
+ if (!pciBusInfo[pri_bus])
+ FatalError("nh6408HostToBusAddr: Primary bus pci%d not defined!!\n", pri_bus);
+ }
+ else
+ pri_bus = bus;
+
+ infop = (struct nh640x_pci_info *)pciBusInfo[pri_bus]->pciBusPriv;
+ membase = infop->memBase;
+
+ if (addr_l < 0x80000000)
+ /*
+ * NH6408 host memory addresses 0-0x7fffffff are seen at
+ * 0x80000000-0xffffffff on PCI
+ */
+ return((ADDRESS)(addr_l | 0x80000000));
+
+ else if (addr_l >= membase && addr_l < (membase + 0x10000000))
+ /*
+ * NH6408 host sees PCI memory space addresses 0-0x0fffffff
+ * at the primary PCI buses "memBase" [memBase, memBase+0x0fffffff]
+ */
+ return((ADDRESS)(addr_l - membase));
+
+ else
+ /* Other addresses are not valid */
+ FatalError("nh6408HostToBusAddr: Host address 0x%x not visible to pci%d\n",
+ addr_l, bus);
+
+ /*NOTREACHED*/
+}
+
+/*
+ * NH6800 (Turbo) support
+ */
+static void
+nh6800tPciInit(void)
+{
+ FatalError("nh6800tPciInit: NH6800TURBO not supported (yet)!!!\n");
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_ppc.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_ppc.c
new file mode 100644
index 000000000..aa286d4ac
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_ppc.c
@@ -0,0 +1,251 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/pmax/pmax_ppc.c,v 1.3 1998/07/25 16:56:56 dawes Exp $ */
+/*
+ * Copyright 1998 by Concurrent Computer Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Concurrent Computer
+ * Corporation not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Concurrent Computer Corporation makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Copyright 1998 by Metro Link Incorporated
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Metro Link
+ * Incorporated not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Metro Link Incorporated makes no representations
+ * about the suitability of this software for any purpose. It is
+ * provided "as is" without express or implied warranty.
+ *
+ * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/types.h>
+#include <errno.h>
+
+#include <sys/prosrfs.h>
+#include <sys/cpu.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+volatile unsigned char *ioBase = MAP_FAILED; /* Also referenced by compiler.h */
+unsigned long ioSize = 0;
+
+#undef outb
+#undef outw
+#undef outl
+#undef inb
+#undef inw
+#undef inl
+
+void
+outb(unsigned int a, unsigned char b)
+{
+ if (ioBase == MAP_FAILED) {
+ ErrorF("outb(0x%04X, 0x%02X) fails. Uninitialized ioBase\n", a, b);
+ return;
+ }
+
+ *((volatile unsigned char *)(ioBase + a)) = b; eieio();
+}
+
+void
+outw(unsigned int a, unsigned short w)
+{
+ if (ioBase == MAP_FAILED) {
+ ErrorF("outw(0x%04X, 0x%04X) fails. Unitialized ioBase\n", a, w);
+ return;
+ }
+
+ stw_brx(w,ioBase,a); eieio();
+}
+
+void
+outl(unsigned int a, unsigned int l)
+{
+ if (ioBase == MAP_FAILED) {
+ ErrorF("outl(0x%04X, 0x%08X) fails. Unitialized ioBase\n", a, l);
+ return;
+ }
+
+ stl_brx(l,ioBase,a); eieio();
+}
+
+unsigned char
+inb(unsigned int a)
+{
+ unsigned char b;
+
+ if (ioBase == MAP_FAILED) {
+ FatalError("%s(0x%04X) fails. Unitialized ioBase\n", "inb", a);
+ /*NOTREACHED*/
+ }
+
+ b = *((volatile unsigned char *)(ioBase + a));
+
+ return(b);
+}
+
+unsigned short
+inw(unsigned int a)
+{
+ unsigned short w;
+
+ if (ioBase == MAP_FAILED) {
+ FatalError("%s(0x%04X) fails. Unitialized ioBase\n", "inw", a);
+ /*NOTREACHED*/
+ }
+
+ w = ldw_brx(ioBase,a);
+ return(w);
+}
+
+unsigned int
+inl(unsigned int a)
+{
+ unsigned int l;
+
+ if (ioBase == MAP_FAILED) {
+ FatalError("%s(0x%04X) fails. Unitialized ioBase\n", "inl", a);
+ /*NOTREACHED*/
+ }
+
+ l = ldl_brx(ioBase, a);
+ return(l);
+}
+
+#ifdef PPCIO_DEBUG
+
+void
+debug_outb(unsigned int a, unsigned char b, int line, char *file)
+{
+ if (xf86Verbose > 3)
+ ErrorF("outb(0x%04X, 0x%02X) at line %d, file \"%s\"\n", a, b, line, file);
+
+ outb(a,b);
+}
+
+void
+debug_outw(unsigned int a, unsigned short w, int line, char *file)
+{
+ if (xf86Verbose > 3)
+ ErrorF("outw(0x%04X, 0x%04X) at line %d, file \"%s\"\n", a, w, line, file);
+
+ outw(a,w);
+}
+
+void
+debug_outl(unsigned int a, unsigned int l, int line, char *file)
+{
+ if (xf86Verbose > 3)
+ ErrorF("outl(0x%04X, 0x%08X) at line %d, file \"%s\"\n", a, l, line, file);
+
+ outl(a,l);
+}
+
+
+unsigned char
+debug_inb(unsigned int a, int line, char *file)
+{
+ unsigned char b;
+
+ if (xf86Verbose > 4)
+ ErrorF("Calling %s(0x%04x) at line %d, file \"%s\" ...\n", "inb", a, line, file);
+
+ b = inb(a);
+
+ if (xf86Verbose > 3)
+ ErrorF("... %s(0x%04X) returns 0x%02X\n", "inb", a, b);
+
+ return(b);
+}
+
+unsigned short
+debug_inw(unsigned int a, int line, char *file)
+{
+ unsigned short w;
+
+ if (xf86Verbose > 4)
+ ErrorF("Calling %s(0x%04x) at line %d, file \"%s\" ...\n", "inw", a, line, file);
+
+ w = inw(a);
+
+ if (xf86Verbose > 3)
+ ErrorF("... %s(0x%04X) returns 0x%04X\n", "inw", a, w);
+
+ return(w);
+}
+
+unsigned int
+debug_inl(unsigned int a, int line, char *file)
+{
+ unsigned int l;
+
+ if (xf86Verbose > 4)
+ ErrorF("Calling %s(0x%04x) at line %d, file \"%s\" ...\n", "inl", a, line, file);
+
+ l = inl(a);
+
+ if (xf86Verbose > 3)
+ ErrorF("... %s(0x%04X) returns 0x%08X\n", "inl", a, l);
+
+ return(l);
+}
+
+#endif /* PPCIO_DEBUG */
+
+/*
+ * This is neccessary on the PPC 604 (and 604e) because they have
+ * separate I and D caches and the caches must be manually synchronized
+ * when applying relocation to the instruction portion of loaded modules.
+ */
+#define LINESIZE 32
+#define CACHE_LINE(a) (((unsigned long)a) & ~(LINESIZE-1))
+
+void
+ppc_flush_icache(char *addr)
+{
+ /* Flush D-cache to memory */
+ __inst_dcbf (addr, 0);
+ __inst_dcbf (addr, LINESIZE);
+ __inst_sync ();
+
+ /* Invalidate I-cache */
+ __inst_icbi (addr, 0);
+ __inst_icbi (addr, LINESIZE);
+ __inst_sync ();
+ __inst_isync ();
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/Imakefile
new file mode 100644
index 000000000..0c8e07b37
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/Imakefile
@@ -0,0 +1,37 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/qnx4/Imakefile,v 1.7 2002/10/11 01:47:00 dawes Exp $
+
+#include <Server.tmpl>
+
+
+SRCS = qnx_io.c qnx_init.c qnx_utils.c ioperm_noop.c qnx_video.c \
+ qnx_VTsw.c qnx_kbd.c posix_tty.c qnx_mouse.c qnx_select.c \
+ libc_wrapper.c stdResource.c stdPci.c sigiostubs.c pm_noop.c \
+ kmod_noop.c agp_noop.c
+
+OBJS = qnx_io.o qnx_init.o qnx_utils.o ioperm_noop.o qnx_video.o \
+ qnx_VTsw.o qnx_kbd.o posix_tty.o qnx_mouse.o qnx_select.o \
+ libc_wrapper.o stdResource.o stdPci.o sigiostubs.o pm_noop.o \
+ kmod_noop.o agp_noop.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC)
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(ioperm_noop.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_VTsw.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_VTsw.c
new file mode 100644
index 000000000..7902b5597
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_VTsw.c
@@ -0,0 +1,116 @@
+/*
+ * (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * HOLGER VEIT 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 Sebastien Marineau shall not
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/qnx/qnx_VTsw.c,v 1.1.2.2 1999/07/23 13:42:32 hohndel Exp $
+ */
+
+/* This module contains the code to use _select_receive to handle
+ * messages from the Mouse and Input driver. These cannot be select'ed on.
+ */
+
+/* This module contains the functions which are used to do
+ * VT switching to a text console and back... Experimental.
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include <sys/console.h>
+
+int QNX_console_exist[10];
+Bool QNX_vtswitch_pending = FALSE;
+int QNX_con_toactivate = -1;
+extern struct _console_ctrl *QNX_con_ctrl;
+extern unsigned QNX_con_mask, QNX_con_bits;
+extern pid_t QNX_console_proxy;
+extern int QNX_our_console;
+
+/* This gets called to determine if a VT switch has been requested */
+Bool xf86VTSwitchPending()
+{
+ return(xf86Info.vtRequestsPending ? TRUE : FALSE);
+}
+
+/* This is called to do OS-specific stuff when we switch away from
+ * our console.
+ */
+Bool xf86VTSwitchAway()
+{
+ int ret;
+ unsigned event, bits;
+
+ ErrorF("Called VT switch away!\n");
+
+ /* First check wether we are trying to switch to our console... */
+ if (xf86Info.vtRequestsPending == QNX_our_console) {
+ xf86Info.vtRequestsPending = FALSE;
+ return (FALSE);
+ }
+
+ /* Reenable console switching */
+ QNX_con_bits &= ~QNX_con_mask;
+ bits = console_ctrl(QNX_con_ctrl, -1, QNX_con_bits, QNX_con_mask);
+ QNX_con_mask = 0;
+
+ /* And activate the new console. Check if it is valid first... */
+ ret = console_active(QNX_con_ctrl, xf86Info.vtRequestsPending);
+ ErrorF("xf86VTSwitchAway: Made console %d active, ret %d\n",
+ xf86Info.vtRequestsPending, ret);
+ xf86Info.vtRequestsPending = FALSE;
+
+ if (ret == -1) {
+ QNX_con_mask = CONSOLE_INVISIBLE | CONSOLE_NOSWITCH;
+ QNX_con_bits = console_ctrl (QNX_con_ctrl,
+ QNX_our_console, QNX_con_mask, QNX_con_mask);
+ return (FALSE);
+ }
+ /* Arm the console with the proxy so we know when we come back */
+ console_state(QNX_con_ctrl, QNX_our_console, 0L, _CON_EVENT_ACTIVE);
+ event = _CON_EVENT_ACTIVE;
+ console_arm (QNX_con_ctrl, QNX_our_console, QNX_console_proxy, event);
+
+ return(TRUE);
+}
+
+/* And this is called when we are switching back to the server */
+Bool xf86VTSwitchTo()
+{
+ unsigned bits, mask;
+
+ ErrorF("Called VT switch to the server!\n");
+ QNX_con_mask = CONSOLE_INVISIBLE | CONSOLE_NOSWITCH;
+ QNX_con_bits = console_ctrl (QNX_con_ctrl, QNX_our_console, QNX_con_mask, QNX_con_mask);
+ xf86Info.vtRequestsPending = FALSE;
+ return(TRUE);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_init.c
new file mode 100644
index 000000000..b96cc4d30
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_init.c
@@ -0,0 +1,175 @@
+/*
+ * (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * SEBASTIEN MARINEAU 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/qnx/qnx_init.c,v 1.1.2.2 1999/07/23 13:42:33 hohndel Exp $
+ */
+
+/* This module contains the qnx-specific functions used at server init.
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <i86.h>
+#include <sys/mman.h>
+#include <sys/console.h>
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+struct _console_ctrl *QNX_con_ctrl = NULL;
+unsigned long QNX_con_mask = 0;
+unsigned long QNX_con_bits = 0;
+pid_t QNX_console_proxy = -1;
+int QNX_our_console = -1;
+
+void
+xf86UseMsg()
+{
+ ErrorF("No QNX-specific usage options available at this time\n");
+ return;
+}
+
+int
+xf86ProcessArgument(argc, argv, i)
+int argc;
+char **argv;
+int i;
+{
+
+ return 0;
+
+}
+
+
+void
+xf86OpenConsole()
+{
+struct _console_info info;
+unsigned event;
+int default_console = FALSE;
+char con_name[32];
+int active;
+
+ ErrorF("xf86OpenConsole\n");
+
+ if(QNX_con_ctrl == NULL) {
+ /* First open a channel to default stdout */
+ xf86Info.consoleFd = fileno(stdout);
+ if((QNX_con_ctrl = console_open (fileno(stdout), O_RDWR)) == NULL){
+ /* Hmmm. Didn't work. Try to open con1 as default */
+
+ if (( xf86Info.consoleFd = open("/dev/con1", O_RDWR)) < 0){
+ FatalError("xf86OpenConsole: could not open console driver\n");
+ return;
+ }
+ if((QNX_con_ctrl =
+ console_open (xf86Info.consoleFd, O_RDWR)) == NULL){
+ FatalError("xf86OpenConsole: could not open console\n");
+ }
+ default_console = TRUE;
+ }
+ if(QNX_con_ctrl && console_info(QNX_con_ctrl, 0, &info) == 0 ) {
+ if( info.type != _CON_TYPE_STANDARD ) {
+ FatalError("xf86OpenConsole: console is not a standard text console\n");
+ return;
+ }
+ }
+ else {
+ FatalError("xf86OpenConsole: Error querying console\n");
+ return;
+ }
+ }
+
+ /* We have a console, and it is text. Keep going */
+ /* Next, check if Photon has got the screen */
+ if(qnx_name_locate(0, "/qnx/crt", 0, NULL) != -1) {
+ FatalError("xf86OpenConsole: Photon has already grabbed the display\n");
+ return;
+ }
+ fclose (stdout);
+ /* We have two cases here: either this is the first time through,
+ * and QNX_our_console is not set yet, or we're coming here from
+ * a reset. In that case, make sure our console is now active
+ * before we go further...
+ */
+ if (QNX_our_console < 0) {
+ QNX_our_console = console_active(QNX_con_ctrl, -1);
+ }
+ else {
+ console_arm(QNX_con_ctrl, QNX_our_console, -1, _CON_EVENT_ACTIVE);
+ while ((active = console_active(QNX_con_ctrl, -1)) !=
+ QNX_our_console) {
+ sleep(2);
+ ErrorF("Waiting for our console to become active!\n");
+ }
+ }
+ QNX_con_mask = CONSOLE_INVISIBLE | CONSOLE_NOSWITCH;
+ QNX_con_bits = console_ctrl (QNX_con_ctrl, QNX_our_console,
+ QNX_con_mask, QNX_con_mask);
+ ErrorF("xf86OpenConsole: Locked console %d\n", QNX_our_console);
+
+ /* If we had the wrong console opened in the first place, reopen */
+ if(default_console) {
+ close(xf86Info.consoleFd);
+ sprintf(con_name, "/dev/con%d", QNX_our_console);
+ xf86Info.consoleFd = open(con_name, O_RDWR);
+ ErrorF("xf86OpenConsole: reopened console %d\n", QNX_our_console);
+ }
+
+ /* Next create the proxy used to notify us of console events */
+ if(QNX_console_proxy == -1){
+ if((QNX_console_proxy = qnx_proxy_attach(0, 0, 0, -1)) == -1){
+ ErrorF("xf86OpenConsole: Could not create proxy for VT switching\n");
+ }
+ }
+
+ return;
+}
+
+void
+xf86CloseConsole()
+{
+ unsigned bits;
+ int font;
+
+ ErrorF("xf86CloseConsole\n");
+ if(QNX_con_ctrl == NULL) return;
+ QNX_con_bits &= ~QNX_con_mask; /* To make sure */
+ bits = console_ctrl(QNX_con_ctrl, 0, QNX_con_bits, QNX_con_mask);
+
+ ErrorF("xf86CloseConsole: unlocked console\n");
+ /* For now, dump malloc info as well */
+#if 0
+ malloc_dump(2);
+#endif
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_io.c
new file mode 100644
index 000000000..d1cf5c4bf
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_io.c
@@ -0,0 +1,110 @@
+/*
+ * (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * SEBASTIEN MARINEAU 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_io.c,v 1.2 2002/10/11 01:40:36 dawes Exp $
+ */
+
+/* This module contains the qnx-specific functions to access the keyboard
+ * and the console.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <i86.h>
+#include <sys/mman.h>
+#include <sys/qioctl.h>
+#include <errno.h>
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+
+void
+xf86SoundKbdBell(loudness, pitch, duration)
+int loudness, pitch, duration;
+{
+
+/* Come back and fix! */
+ErrorF("xf86SoundKbdBell: to implement\n");
+}
+
+void
+xf86SetKbdLeds(leds)
+int leds;
+{
+unsigned long bits[2], oldbits;
+
+ bits[0] = leds;
+ bits[1] = LED_CAP | LED_NUM | LED_SCR;
+
+ if (qnx_ioctl (xf86Info.consoleFd, QCTL_DEV_CTL, &bits, 8, &oldbits, 4) == -1)
+ ErrorF("xf86SetKbdLeds: error setting kbd leds, errno %d\n", errno);
+
+}
+
+int
+xf86GetKbdLeds()
+{
+unsigned long bits[2], oldbits = 0;
+
+ bits[0] = bits[1] = 0;
+ if (qnx_ioctl(xf86Info.consoleFd, QCTL_DEV_CTL, &bits, 8, &oldbits, 4) == -1)
+ ErrorF("xf86SetKbdLeds: error getting kbd leds, errno %d\n", errno);
+
+ return(oldbits);
+}
+
+/* This is a no-op for now */
+void
+xf86SetKbdRepeat(rad)
+char rad;
+{
+ return;
+}
+
+
+/* This is a no-op for now */
+void
+xf86KbdInit()
+{
+
+ return;
+}
+
+#include "xf86OSKbd.h"
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_kbd.c
new file mode 100644
index 000000000..88a7209cd
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_kbd.c
@@ -0,0 +1,104 @@
+/*
+ * (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * SEBASTIEN MARINEAU 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/qnx/qnx_kbd.c,v 1.1.2.2 1999/07/23 13:42:35 hohndel Exp $
+ */
+
+/* This module contains the qnx-specific functions to access the keyboard
+ * and the console.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <i86.h>
+#include <sys/mman.h>
+#include <sys/dev.h>
+#include <errno.h>
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+
+int QNX_kbd_fd = -1;
+pid_t QNX_kbd_proxy = -1;
+
+int
+xf86KbdOn()
+{
+
+ if(QNX_kbd_fd == -1)
+ QNX_kbd_fd = open("/dev/kbd", O_RDWR);
+ if(QNX_kbd_proxy == -1)
+ QNX_kbd_proxy = qnx_proxy_attach(0, 0, 0, -1);
+ if (QNX_kbd_fd == -1) {
+ FatalError("xf86KbdOn: Could not open keyboard, errno = %d\n", errno);
+ }
+ if (QNX_kbd_proxy == -1) {
+ FatalError("xf86KbdOn: Could not create kbd proxy, errno = %d\n", errno);
+ }
+ if(xf86Verbose)
+ ErrorF("xf86KbdOn: fd = %d, proxy = %d\n", QNX_kbd_fd, QNX_kbd_proxy);
+ if (dev_arm(QNX_kbd_fd, QNX_kbd_proxy, _DEV_EVENT_RXRDY) == -1)
+ FatalError("xf86KbdOn: could not arm kbd proxy, errno %d\n", errno);
+ return(-1); /* We don't want to select on kbd handle... */
+
+
+}
+
+int
+xf86KbdOff()
+{
+ int fd;
+
+ ErrorF("xf86KbdOff:\n ");
+ fd = QNX_kbd_fd;
+ close(QNX_kbd_fd);
+ QNX_kbd_fd = -1;
+ return(-1);
+}
+
+void xf86KbdEvents()
+{
+ unsigned char rBuf[64];
+ int nBytes, i;
+
+ if ((nBytes = dev_read( QNX_kbd_fd, (char *)rBuf, sizeof(rBuf),
+ 0, 0, 0, 0, NULL)) > 0) {
+ for (i = 0; i < nBytes; i++)
+ xf86PostKbdEvent(rBuf[i]);
+ /* Re-arm proxy */
+ dev_arm(QNX_kbd_fd, QNX_kbd_proxy, _DEV_EVENT_RXRDY);
+
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_mouse.c
new file mode 100644
index 000000000..ec45a30be
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_mouse.c
@@ -0,0 +1,267 @@
+/*
+ * (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * SEBASTIEN MARINEAU 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_mouse.c,v 1.4 2002/01/07 20:38:29 dawes Exp $
+ */
+
+/* This module contains the qnx-specific functions to access the keyboard
+ * and the console.
+ */
+
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <i86.h>
+#include <sys/mman.h>
+#include <sys/dev.h>
+#include <sys/mouse.h>
+#include <sys/proxy.h>
+#include <errno.h>
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+
+extern int miPointerGetMotionEvents(
+ DeviceIntPtr /*pPtr*/,
+ xTimecoord * /*coords*/,
+ unsigned long /*start*/,
+ unsigned long /*stop*/,
+ ScreenPtr /*pScreen*/
+);
+
+struct _mouse_ctrl *QNX_mouse = NULL;
+pid_t QNX_mouse_proxy = -1;
+Bool QNX_mouse_event = FALSE;
+
+/* the following function is converted from old void xf86OsMouseEvents() */
+static void
+OsMouseReadInput(InputInfoPtr pInfo)
+{
+ struct mouse_event events[16];
+ int i, nEvents;
+ int buttons, col, row;
+ int armed = 0;
+ MouseDevPtr pMse;
+
+ pMse = pInfo->private;
+
+ while ((nEvents = mouse_read(QNX_mouse, &events,
+ 16, QNX_mouse_proxy, &armed) ) > 0) {
+ /* ErrorF("Got mouse event, #%d!\n", nEvents);*/
+
+ for (i = 0; i < nEvents; i ++){
+ col = events[i].dx;
+ row = -events[i].dy;
+ buttons = events[i].buttons;
+ pMse->PostEvent(pInfo, buttons, col, row, 0, 0);
+ }
+ }
+ if (!armed) ErrorF("Drained mouse queue, armed = 0??\n");
+ QNX_mouse_event = FALSE;
+}
+
+/* The main mouse setup proc */
+static int
+OsMouseProc(pPointer, what)
+DeviceIntPtr pPointer;
+int what;
+{
+ int i, ret, armed;
+ int nbuttons;
+ unsigned char *map;
+ struct mouse_event mevent;
+ MouseDevPtr pMse;
+ InputInfoPtr pInfo;
+
+ pInfo = pPointer->public.devicePrivate;
+ pMse = pInfo->private;
+ pMse->device = pPointer;
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+ if (QNX_mouse_proxy == -1) {
+ if((QNX_mouse_proxy =
+ qnx_proxy_attach(0, 0, 0, -1)) == -1){
+ FatalError("xf86MouseOn: Could not create mouse proxy; %s\n",
+ strerror(errno));
+ }
+ }
+ if (QNX_mouse == NULL) QNX_mouse =
+ mouse_open(0, NULL, xf86Info.consoleFd);
+ if (QNX_mouse == NULL) {
+ if (xf86AllowMouseOpenFail) {
+ ErrorF("Cannot open mouse (%s) - Continuing...\n",
+ strerror(errno));
+ return(-1);
+ }
+ FatalError("Cannot open mouse (%s)\n", strerror(errno));
+ }
+ /* Ok, so we have opened the channel to the mouse driver */
+ ErrorF("Opened mouse: handle %d buttons\n", QNX_mouse->handle,
+ QNX_mouse->buttons);
+ pInfo->fd = QNX_mouse->fd;
+ mouse_flush(QNX_mouse);
+ QNX_mouse_event = FALSE;
+ /* How de we determine how many buttons we have?? */
+ nbuttons = 3;
+ map = (unsigned char *) xalloc(nbuttons + 1);
+ if (map == (unsigned char *) NULL)
+ FatalError("Failed to allocate memory for mouse structures\n");
+ for(i=0;i <= nbuttons; i++)
+ map[i] = i;
+ InitPointerDeviceStruct ((DevicePtr) pPointer, map, nbuttons,
+ miPointerGetMotionEvents, pMse->Ctrl,
+ miPointerGetMotionBufferSize());
+
+ /* X valuator */
+ xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 0);
+ /* Y valuator */
+ xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 1);
+ xf86MotionHistoryAllocate(pInfo);
+
+ xfree(map);
+ break;
+
+ case DEVICE_ON:
+ if(QNX_mouse == NULL) return(-1);
+ pMse->lastButtons = 0;
+ pMse->lastMappedButtons = 0;
+ pMse->emulateState = 0;
+ pPointer->public.on = TRUE;
+ mouse_flush(QNX_mouse);
+ /* AddEnabledDevice(pInfo->fd); */
+ ret = mouse_read(QNX_mouse, &mevent, 0,
+ QNX_mouse_proxy, NULL);
+ ErrorF("MouseOn: armed proxy, %d, proxy pid %d\n", ret,
+ QNX_mouse_proxy);
+ if (ret < 0) {
+ FatalError("xf86MouseOn: could not arm proxy; %s\n",
+ strerror(errno));
+ }
+ break;
+
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ if(QNX_mouse == NULL) return(-1);
+ pPointer->public.on = FALSE;
+ if (what == DEVICE_CLOSE){
+ mouse_close (QNX_mouse);
+ QNX_mouse = NULL;
+ }
+ pPointer->public.on = FALSE;
+ break;
+ }
+ return (Success);
+}
+
+static int
+SupportedInterfaces(void)
+{
+ /* XXX Need to check this. */
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_MISC | MSE_AUTO;
+}
+
+static const char *internalNames[] = {
+ "OSMouse",
+ NULL
+};
+
+static const char **
+BuiltinNames(void)
+{
+ return internalNames;
+}
+
+static Bool
+CheckProtocol(const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++)
+ if (xf86NameCmp(protocol, internalNames[i]) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+/* XXX Is this appropriate? If not, this function should be removed. */
+static const char *
+DefaultProtocol(void)
+{
+ return "OSMouse";
+}
+
+static Bool
+OsMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ MouseDevPtr pMse;
+
+ /* This is called when the protocol is "OSMouse". */
+
+ pMse = pInfo->private;
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local procs. */
+ pInfo->device_control = OsMouseProc;
+ pInfo->read_input = OsMouseReadInput;
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+ p->BuiltinNames = BuiltinNames;
+ p->DefaultProtocol = DefaultProtocol;
+ p->CheckProtocol = CheckProtocol;
+ p->PreInit = OsMousePreInit;
+ return p;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_select.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_select.c
new file mode 100644
index 000000000..82359fe40
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_select.c
@@ -0,0 +1,75 @@
+/*
+ * (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * HOLGER VEIT 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/qnx/qnx_select.c,v 1.1.2.2 1999/07/23 13:42:37 hohndel Exp $
+ */
+
+/* This module contains the code to use _select_receive to handle
+ * messages from the Mouse and Input driver. These cannot be select'ed on.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#define FD_SETSIZE 256
+#include <sys/select.h>
+#include <sys/kernel.h>
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+extern pid_t QNX_mouse_proxy;
+extern Bool QNX_mouse_event;
+extern pid_t QNX_console_proxy;
+
+pid_t _select_receive ( pid_t proxy)
+{
+
+ pid_t pid;
+ char msg[16];
+
+ pid = Receive(0, msg, sizeof(msg));
+/* ErrorF("Received message from pid %d %d. Mouse pid %d\n", pid, proxy,
+ QNX_mouse_proxy);
+*/
+ if (pid == QNX_mouse_proxy) return (-1);
+ if (pid == QNX_console_proxy) {
+ ErrorF("VT swicth requested by proxy to select()\n");
+ xf86Info.vtRequestsPending = TRUE;
+ return(-1);
+ }
+
+ /* For now; check exact semantics */
+ return (proxy);
+}
+
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_utils.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_utils.c
new file mode 100644
index 000000000..f78c0453e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_utils.c
@@ -0,0 +1,30 @@
+/* This includes various utility functions which are missing otherwise
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/qnx/qnx_utils.c,v 1.1.2.2 1999/07/23 13:42:39 hohndel Exp $
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <limits.h>
+#include <string.h>
+#include <i86.h>
+#include <conio.h>
+#include <time.h>
+
+#include <X11/X.h>
+#include <xf86.h>
+
+void usleep (unsigned long interval) { delay( interval/1000 ); }
+
+/* We have our own version of GetTimeInMillis, because the normal
+ * version calls gettimeofday(), which seems to thrash ES...
+ */
+CARD32
+GetTimeInMillis()
+{
+struct timespec tp;
+
+ qnx_getclock(0, CLOCK_REALTIME, &tp);
+ return((tp.tv_sec * 1000) + (tp.tv_nsec / 1000000));
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_video.c
new file mode 100644
index 000000000..578d33ea0
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_video.c
@@ -0,0 +1,183 @@
+/*
+ * (c) Copyright 1998 by Sebastien Marineau
+ * <sebastien@qnx.com>
+ *
+ * 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
+ * SEBASTIEN MARINEAU 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 Sebastien Marineau shall not be
+ * used in advertising or otherwise to promote the sale, use or other dealings
+ * in this Software without prior written authorization from Sebastien Marineau.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/qnx4/qnx_video.c,v 1.3tsi Exp $
+ */
+
+/* This module contains the qnx-specific functions to deal with video
+ * framebuffer access and interrupts.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <i86.h>
+#include <sys/mman.h>
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+
+/* These are the interrupt enabling/disabling functions. Simply call
+ * the Watcom equivalents.
+ */
+
+void xf86EnableInterrupts()
+{
+ _enable();
+}
+
+void xf86DisableInterrupts()
+{
+ xf86ErrorF("Disable interrupts: not yet...\n");
+ /* _disable(); */
+}
+
+/* These are the routines to map/unmap video memory... */
+
+Bool xf86LinearVidMem()
+{
+ /* Yes we can... */
+ xf86ErrorF("xf86LinearMem: called\n");
+ return(TRUE);
+}
+
+/* This is our shmem "Physical" handle */
+int QNX_PhMem_fd = -1;
+
+
+/* Map a chunk of physical video memory, using mmap */
+
+pointer xf86MapVidMem(ScreenNum, Flags, Base, Size)
+int ScreenNum;
+int Flags;
+unsigned long Base;
+unsigned long Size;
+{
+int fd;
+void *base;
+ xf86ErrorF("xf86MapVidMem called\n");
+ if(QNX_PhMem_fd < 0) {
+ if ((fd = shm_open("Physical", O_RDWR, 0777)) < 0) {
+ FatalError("xf86MapVidMem: Failed to open /dev/shmem\n");
+ }
+ QNX_PhMem_fd = fd;
+ }
+ base = mmap((caddr_t)0, Size,
+ (Flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, QNX_PhMem_fd, (off_t)Base);
+ xf86ErrorF("MapVidMem: addr %08x size %08x addr %08x\n", Base,
+ Size, base);
+ if ((long)base == -1)
+ {
+ FatalError("xf86MapVidMem: Failed to mmap video memory\n");
+ }
+ return(base);
+
+}
+
+void xf86UnMapVidMem(ScreenNum, Base, Size)
+int ScreenNum;
+pointer Base;
+unsigned long Size;
+{
+
+ xf86ErrorF("xf86UnmapVidMem called\n");
+ munmap((caddr_t) Base, Size);
+
+}
+
+/* Finally, this function allows us to read the video BIOS content */
+
+int
+xf86ReadBIOS(Base, Offset, Buf, Len)
+unsigned long Base, Offset;
+unsigned char *Buf;
+int Len;
+{
+ unsigned char * VirtBase;
+
+ xf86ErrorF("xf86ReadBIOS called\n");
+ if (QNX_PhMem_fd == -1)
+ {
+ if ((QNX_PhMem_fd = shm_open("Physical", O_RDWR, 0777)) < 0)
+ {
+ FatalError("xf86ReadBIOS: cannot open Physical memory\n");
+ }
+ }
+
+ /* Use mmap to map BIOS region. Note the restrictions on
+ * mmap alignement of offset variable (which must be on a page
+ * boundary).
+ */
+ VirtBase = (unsigned char *) mmap(0, (size_t)((Offset & 0x7fff) + Len), PROT_READ,
+ MAP_SHARED, QNX_PhMem_fd,
+ (off_t) (Base + (Offset & 0xffff8000)));
+ if((long)VirtBase == -1) {
+ FatalError(
+ "xf86ReadBIOS: Could not mmap BIOS memory space, errno=%i\n",
+ errno);
+ }
+
+ /* So now we have our mapping to the BIOS region */
+ /* Do a sanity check on what we have just mapped */
+ if (((off_t)((off_t)Offset & 0x7FFF) != (off_t)0) &&
+ (VirtBase[0] != 0x55) &&
+ (VirtBase[1] != 0xaa)) {
+ xf86ErrorF(
+ "xf86ReadBIOS: BIOS sanity check failed, addr=%x\n",
+ (int)Base + Offset);
+ munmap(VirtBase, (Offset & 0x7fff) + Len);
+ return(-1);
+ }
+
+ /* Things look good: copy BIOS data */
+ memcpy(Buf, VirtBase + (Offset & 0x7fff), Len);
+ munmap(VirtBase, (Offset & 0x7fff) + Len);
+ return(Len);
+
+}
+
+void
+xf86MapReadSideEffects(int ScreenNum, int Flags, pointer Base,
+ unsigned long Size)
+{
+ return;
+}
+
+Bool
+xf86CheckMTRR(int s)
+{
+ return FALSE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/Imakefile
new file mode 100644
index 000000000..35502389a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/Imakefile
@@ -0,0 +1,56 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sco/Imakefile,v 3.15 2002/10/17 02:22:49 dawes Exp $
+
+
+
+
+XCOMM $XConsortium: Imakefile /main/4 1996/09/28 17:24:25 rws $
+
+#include <Server.tmpl>
+
+SRCS = sco_init.c sco_video.c sco_io.c sco_iop.c sco_mouse.c VTsw_sco.c \
+ std_kbdEv.c posix_tty.c bios_mmap.c vidmem.c \
+ libc_wrapper.c stdResource.c stdPci.c sigiostubs.c pm_noop.c \
+ kmod_noop.c agp_noop.c sco_kbd.c at_scancode.c sco_KbdMap.c
+
+OBJS = sco_init.o sco_video.o sco_io.o sco_iop.o sco_mouse.o VTsw_sco.o \
+ std_kbdEv.o posix_tty.o bios_mmap.o vidmem.o \
+ libc_wrapper.o stdResource.o stdPci.o sigiostubs.o pm_noop.o \
+ kmod_noop.o agp_noop.o sco_kbd.o at_scancode.o sco_KbdMap.o \
+ sco_event.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(SERVERSRC)/mi -I$(XINCLUDESRC) -I$(EXTINCSRC)
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+XCOMM Hack for SCO platforms to get around a bug in GNU ld. The server needs
+XCOMM to link with -levent for the event driver interface. However, that is
+XCOMM a COFF-only library, and GCC/GNU ld only deal with ELF. Theoretically,
+XCOMM GNU ld will convert COFF to ELF on the fly, but it gets it wrong. The
+XCOMM SCO link editor gets it right. So we create an object here that the
+XCOMM server can link against.
+sco_event.o:
+ @ar x /usr/lib/libevent.a mouse.o
+ @/usr/ccs/bin/elf/ld -r -o sco_event.o mouse.o
+ @rm -f mouse.o
+
+LinkSourceFile(bios_mmap.c,../shared)
+LinkSourceFile(std_kbdEv.c,../shared)
+LinkSourceFile(at_scancode.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+LinkSourceFile(vidmem.c,../shared)
+
+DependTarget()
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/VTsw_sco.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/VTsw_sco.c
new file mode 100644
index 000000000..beb86ccad
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/VTsw_sco.c
@@ -0,0 +1,119 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sco/VTsw_sco.c,v 1.2 1998/07/25 16:56:57 dawes Exp $ */
+/*
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ * Copyright 1993 by David McCullough <davidm@stallion.oz.au>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: VTsw_sco.c /main/2 1995/11/13 06:08:36 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/* For the event driver prototypes */
+#include <sys/event.h>
+#include <mouse.h>
+
+/*
+ * Handle the VT-switching interface for SCO
+ */
+
+/*
+ * This function is the signal handler for the VT-switching signal. It
+ * is only referenced inside the OS-support layer. NOTE: we do NOT need
+ * to re-arm the signal here, since we used sigaction() to set the signal
+ * disposition in sco_init.c. If we had used signal(), we would need to
+ * re-arm the signal here. All we need to do now is record the fact that
+ * we got the signal. XFree86 handles the rest.
+ */
+void
+xf86VTRequest(int sig)
+{
+ xf86Info.vtRequestsPending = TRUE;
+ return;
+}
+
+Bool
+xf86VTSwitchPending(void)
+{
+ return(xf86Info.vtRequestsPending ? TRUE : FALSE);
+}
+
+/*
+ * When we switch away, we need to flush and suspend the event driver
+ * before the VT_RELDISP. We also need to get the current LED status
+ * and preserve it, so that we can restore it when we come back.
+ */
+static int sco_ledstatus = -1;
+static unsigned int sco_ledstate = 0;
+
+Bool
+xf86VTSwitchAway(void)
+{
+ ev_flush();
+ ev_suspend();
+
+ sco_ledstatus = ioctl(xf86Info.consoleFd, KDGETLED, &sco_ledstate);
+
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_TRUE) < 0) {
+ return(FALSE);
+ } else {
+ return(TRUE);
+ }
+}
+
+/*
+ * When we come back to the X server, we need to resume the event driver,
+ * and we need to restore the LED settings to what they were when we
+ * switched away.
+ */
+Bool
+xf86VTSwitchTo(void)
+{
+ ev_resume();
+
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) {
+ return(FALSE);
+ } else {
+ if (sco_ledstatus >= 0) {
+ ioctl (xf86Info.consoleFd, KDSETLED, sco_ledstate);
+ }
+ sco_ledstatus = -1;
+
+ /*
+ * Convince the console driver this screen is in graphics mode,
+ * otherwise it assumes it can do more to the screen than it should.
+ */
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) {
+ ErrorF("Failed to set graphics mode (%s)\n", strerror(errno));
+ }
+
+ return TRUE;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_KbdMap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_KbdMap.c
new file mode 100644
index 000000000..6a0e9de04
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_KbdMap.c
@@ -0,0 +1,304 @@
+/* $XFree86$ */
+/*
+ * Copyright 2005 by J. Kean Johnston <jkj@sco.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name J. Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. J. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * J. KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL J. KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Based on xf86KbdMap.c, which is
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ * Copyright (c) 1992-2003 by The XFree86 Project, Inc.
+ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+#include "atKeynames.h"
+#include "xf86Keymap.h"
+
+#include "sco_kbd.h"
+
+#define KD_GET_ENTRY(i,n) \
+ eascii_to_x[((priv->keymap.key[i].spcl << (n+1)) & 0x100) + priv->keymap.key[i].map[n]]
+
+/*
+ * NOTE: Not all possible remappable symbols are remapped. There are two main
+ * reasons:
+ * a) The mapping between scancode and SYSV/386 - symboltable
+ * is inconsistent between different versions and has some
+ * BIG mistakes.
+ * b) In X-Windows there is a difference between numpad-keys
+ * and normal keys. SYSV/386 uses for both kinds of keys
+ * the same symbol.
+ *
+ * Thus only the alpha keypad and the function keys are translated.
+ * Also CapsLock, NumLock, ScrollLock, Shift, Control & Alt.
+ */
+
+static unsigned char remap[128] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0x69, 0x65, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+
+static KeySym eascii_to_x[512] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex,
+ XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla,
+ XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis,
+ XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring,
+ XK_Eacute, XK_ae, XK_AE, XK_ocircumflex,
+ XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave,
+ XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent,
+ XK_sterling, XK_yen, XK_paragraph, XK_section,
+ XK_aacute, XK_iacute, XK_oacute, XK_uacute,
+ XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine,
+ XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf,
+ XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi,
+ XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau,
+ XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta,
+ XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection,
+ XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal,
+ XK_topintegral, XK_botintegral, XK_division, XK_similarequal,
+ XK_degree, NoSymbol, NoSymbol, XK_radical,
+ XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol,
+
+ /*
+ * special marked entries (256 + x)
+ */
+
+ NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R,
+ XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L,
+ NoSymbol, XK_Control_L, XK_Alt_L, XK_Alt_R,
+ XK_Control_L, XK_Control_R, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_F1,
+ XK_F2, XK_F3, XK_F4, XK_F5,
+ XK_F6, XK_F7, XK_F8, XK_F9,
+ XK_F10, XK_F11, XK_F12, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ };
+
+/*
+ * KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+void
+KbdGetMapping (InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ ScoKbdPrivPtr priv = (ScoKbdPrivPtr) pKbd->private;
+ KeySym *k;
+ int i;
+ KeySym *pMap = map;
+
+ for (i = 0; i < priv->keymap.n_keys && i < NUM_KEYCODES; i++) {
+ if (remap[i]) {
+ k = pMap + (remap[i] << 2);
+
+ k[0] = KD_GET_ENTRY(i,0); /* non-shifed */
+ k[1] = KD_GET_ENTRY(i,1); /* shifted */
+ k[2] = KD_GET_ENTRY(i,4); /* alt */
+ k[3] = KD_GET_ENTRY(i,5); /* alt - shifted */
+
+ if (k[3] == k[2]) k[3] = NoSymbol;
+ if (k[2] == k[1]) k[2] = NoSymbol;
+ if (k[1] == k[0]) k[1] = NoSymbol;
+ if (k[0] == k[2] && k[1] == k[3]) k[2] = k[3] = NoSymbol;
+ }
+ }
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = pMap, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += GLYPHS_PER_KEY) {
+
+ switch(*k) {
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+ }
+ }
+
+ pKeySyms->map = pMap;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_init.c
new file mode 100644
index 000000000..bc1f3b56d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_init.c
@@ -0,0 +1,296 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sco/sco_init.c,v 3.13 2002/06/03 21:22:10 dawes Exp $ */
+/*
+ * Copyright 2001-2005 by J. Kean Johnston <jkj@sco.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name J. Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. J. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * J. KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL J. KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $XConsortium$ */
+
+/* Re-written May 2001 to represent the current state of reality */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+static Bool KeepTty = FALSE;
+static int VTnum = -1;
+static char vtdevice[48];
+static int sco_console_mode = -1;
+
+extern Bool mpxLock;
+
+void
+xf86OpenConsole(void)
+{
+ int i, ioctl_ret;
+ struct vt_mode VT;
+ struct vid_info vidinf;
+ struct sigaction sigvtsw;
+ char *ttn;
+
+ if (serverGeneration == 1) {
+ /* check if we're run with euid==0 */
+ if (geteuid() != 0) {
+ FatalError("xf86OpenConsole: Server must be setuid root\n");
+ }
+
+ /* If we are run in the background we will get SIGTTOU. Ignore it. */
+ OsSignal (SIGTTOU, SIG_IGN);
+
+ /*
+ * Set up the virtual terminal (multiscreen in SCO parlance).
+ * For the actual console itself, screens are numbered from
+ * 1 to (usually) 16. However, it is possible to have a nested
+ * server, and it is also possible to be on a multi-console
+ * system such as MaxSpeed or SunRiver. Therefore, we should
+ * not make any assumptions about the TTY name we are on, and
+ * instead we rely on ttyname() to give us the real TTY name.
+ * Previously, we tried to determine the TTY name manually.
+ * This is wrong. The only time we need to futz with the TTY name
+ * is if we were given the name of a TTY to run on explicity on
+ * the command line.
+ */
+
+ if (VTnum == -1) {
+ /*
+ * No device was specified. We need to query the kernel to see which
+ * console device we are on (and in fact if we are on a console at all).
+ */
+ ttn = ttyname (1);
+
+ if (ttn == (char *)0) {
+ FatalError ("xf86OpenConsole: Could not determine TTY name: %s\n",
+ strerror(errno));
+ }
+ strlcpy (vtdevice, ttn, sizeof(vtdevice));
+ } else if (VTnum >= 0) {
+ snprintf (vtdevice, sizeof(vtdevice), "/dev/tty%02d", VTnum);
+ }
+
+ /*
+ * Now we can dispose of stdin/stdout
+ */
+ fclose (stdin);
+ fclose (stdout);
+
+ if ((xf86Info.consoleFd = open(vtdevice, O_RDWR | O_NDELAY, 0)) < 0) {
+ FatalError("xf86OpenConsole: Cannot open %s: %s\n", vtdevice,
+ strerror(errno));
+ }
+
+ /*
+ * We make 100% sure we use the correct VT number. This can get ugly
+ * where there are multi-consoles in use, so we make sure we query
+ * the kernel for the correct VT number. It knows best, we don't.
+ */
+ vidinf.size = sizeof(vidinf);
+ if (ioctl (xf86Info.consoleFd, CONS_GETINFO, &vidinf) < 0) {
+ FatalError ("xf86OpenConsole: %s not a console device "
+ "or error querying device: %s\n", vtdevice, strerror (errno));
+ }
+ xf86Info.vtno = vidinf.m_num;
+ VTnum = vidinf.m_num + 1; /* 0-based */
+
+ ErrorF("(using VT%02d device %s)\n\n", VTnum, vtdevice);
+
+ /* We activate the console just in case its not the one we are on */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) {
+ ErrorF("xf86OpenConsole: VT_ACTIVATE failed (%s)\n", strerror(errno));
+ }
+
+ /* Disassociate from controling TTY */
+ if (!KeepTty) {
+ setpgrp();
+ }
+
+ /*
+ * Now we get the current mode that the console device is in. We will
+ * use this later when we close the console device to restore it to
+ * that same mode.
+ */
+ if ((sco_console_mode = ioctl(xf86Info.consoleFd, CONS_GET, 0L)) < 0) {
+ FatalError("xf86OpenConsole: CONS_GET failed on console (%s)\n",
+ strerror(errno));
+ }
+
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) {
+ FatalError("xf86OpenConsole: VT_GETMODE failed (%s)\n", strerror(errno));
+ }
+
+ sigvtsw.sa_handler = xf86VTRequest;
+ sigfillset(&sigvtsw.sa_mask);
+ sigvtsw.sa_flags = 0;
+
+ /* NOTE: Using sigaction means we dont have to re-arm the signal */
+ sigaction(SIGUSR1, &sigvtsw, NULL);
+
+ VT.mode = VT_PROCESS;
+ VT.relsig = SIGUSR1;
+ VT.acqsig = SIGUSR1;
+ VT.frsig = SIGINT; /* Not implemented */
+ VT.waitv = 0;
+
+ /*
+ * The SCO X server tries the following call 5 times. Lets do the same
+ * thing. It shouldn't really be required but sometimes things take a
+ * while to settle down when switching screens. *helpless shrug* I know
+ * its sucks but ...
+ */
+
+ ioctl_ret = 0;
+ for (i = 0; i < 5; i++) {
+ ioctl_ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT);
+ if (ioctl_ret >= 0)
+ break;
+ usleep(999999); /* Dont use nap() - it forces linking with -lx */
+ }
+
+ if (ioctl_ret < 0) {
+ FatalError("xf86OpenConsole: VT_SETMODE failed (%s)\n", strerror(errno));
+ }
+
+ /*
+ * Convince the console driver we are in graphics mode.
+ */
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) {
+ ErrorF("Failed to set graphics mode (%s)\n", strerror(errno));
+ }
+ } else { /* serverGeneration != 1 */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) {
+ ErrorF("xf86OpenConsole: VT_ACTIVATE failed (%s)\n", strerror(errno));
+ }
+ }
+}
+
+/*
+ * Restore the console to its previous state. This may cause flicker if
+ * the screen was previous in a graphics mode, because we first set it
+ * to text mode. This has the advantage of getting the console driver
+ * to do a soft reset on the card, which really does help settle the
+ * video card down again after coming out of Xfree86.
+ */
+void
+xf86CloseConsole(void)
+{
+ struct vt_mode VT;
+ struct sigaction sigvtsw;
+
+ /* Set text mode (possibly briefly) */
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT0);
+
+ /* Restore the original mode */
+ if (sco_console_mode != -1) {
+ ioctl(xf86Info.consoleFd, MODESWITCH | sco_console_mode, 0L);
+ }
+
+ ioctl(xf86Info.consoleFd, VT_RELDISP, 1); /* Release the display */
+
+ sigvtsw.sa_handler = SIG_DFL;
+ sigfillset(&sigvtsw.sa_mask);
+ sigvtsw.sa_flags = 0;
+
+ sigaction(SIGUSR1, &sigvtsw, NULL);
+
+ VT.mode = VT_AUTO;
+ VT.waitv = 0;
+ VT.relsig = SIGUSR1;
+ VT.acqsig = SIGUSR1;
+ VT.frsig = SIGINT;
+ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* Revert to auto handling */
+
+ close(xf86Info.consoleFd); /* We're done with the device */
+}
+
+int
+xf86ProcessArgument(int argc, char *argv[], int i)
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful
+ * when debugging (so the server can receive keyboard signals).
+ */
+ if (!strcmp(argv[i], "-keeptty")) {
+ KeepTty = TRUE;
+ return(1);
+ }
+
+ /*
+ * By default, the X server wants to bind itself to CPU 0. This makes
+ * sure that the server has full access to the I/O ports at IOPL 3.
+ * Some SMP systems have trouble with I/O on CPU's other than 0. If,
+ * however, you have a system that is well behaved, you can specify
+ * this argument and let the scheduler decide which CPU the server
+ * should run on.
+ */
+ if (!strcmp(argv[i], "-nompxlock")) {
+ mpxLock = FALSE;
+ return (1);
+ }
+
+ /*
+ * Specify the VT number to run on (NOT the device).
+ */
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't')) {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0) {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ if (VTnum <= 0) {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ return(1);
+ }
+
+ /*
+ * Use a device the user specifies.
+ */
+ if (!strcmp(argv[i], "-crt")) {
+ if (++i > argc) {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ } else {
+ VTnum = -2;
+ strlcpy (vtdevice, argv[i], sizeof(vtdevice));
+ return(2);
+ }
+ }
+ return(0);
+}
+
+void
+xf86UseMsg(void)
+{
+ ErrorF("vtXX use the specified VT number\n");
+ ErrorF("-crt DEVICE use the specified VT device\n");
+ ErrorF("-nompxlock dont bind X server to CPU 0\n");
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_io.c
new file mode 100644
index 000000000..c97916cf5
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_io.c
@@ -0,0 +1,269 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sco/sco_io.c,v 3.9 2002/10/11 01:40:36 dawes Exp $ */
+/*
+ * Copyright 2001 by J. Kean Johnston <jkj@sco.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name J. Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. J. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * J. KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL J. KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $XConsortium$ */
+
+/* Re-written May 2001 to represent the current state of reality */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#define _NEED_SYSI86
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86OSpriv.h"
+#include "xf86_OSlib.h"
+
+#include <sys/param.h>
+#include <sys/emap.h>
+#include <sys/nmap.h>
+
+void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ if (loudness && pitch) {
+ ioctl(xf86Info.consoleFd, KIOCSOUND, 1193180 / pitch);
+ usleep(duration * loudness * 20);
+ ioctl(xf86Info.consoleFd, KIOCSOUND, 0);
+ }
+}
+
+void
+xf86SetKbdLeds(int leds)
+{
+ /*
+ * sleep the first time through under SCO. There appears to be a
+ * timing problem in the driver which causes the keyboard to be lost.
+ * This usleep stops it from occurring. NOTE: this was in the old code.
+ * I am not convinced it is true any longer, but it doesn't hurt to
+ * leave this in here.
+ */
+ static int once = 1;
+
+ if (once) {
+ usleep(100);
+ once = 0;
+ }
+
+ ioctl(xf86Info.consoleFd, KDSETLED, leds );
+}
+
+int
+xf86GetKbdLeds(void)
+{
+ int leds;
+
+ ioctl (xf86Info.consoleFd, KDGETLED, &leds);
+ return leds;
+}
+
+/*
+ * Much of the code in this function is duplicated from the Linux code
+ * by Orest Zborowski <obz@Kodak.com> and David Dawes <dawes@xfree86.org>.
+ * Please see the file ../linux/lnx_io.c for full copyright information.
+ *
+ * NOTE: Only OpenServer Release 5.0.6 with Release Supplement 5.0.6A
+ * and later have the required ioctl. 5.0.6A or higher is HIGHLY
+ * recommended. The console driver is quite a different beast on that OS.
+ */
+void
+xf86SetKbdRepeat(char rad)
+{
+#if defined(KBIO_SETRATE)
+ int i;
+ int value = 0x7f; /* Maximum delay with slowest rate */
+ int delay = 250; /* Default delay */
+ int rate = 300; /* Default repeat rate */
+
+ static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150,
+ 133, 120, 109, 100, 92, 86, 80, 75, 67,
+ 60, 55, 50, 46, 43, 40, 37, 33, 30, 27,
+ 25, 23, 21, 20 };
+#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int ))
+
+ static int valid_delays[] = { 250, 500, 750, 1000 };
+#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int ))
+
+ if (xf86Info.kbdRate >= 0)
+ rate = xf86Info.kbdRate * 10;
+ if (xf86Info.kbdDelay >= 0)
+ delay = xf86Info.kbdDelay;
+
+ for (i = 0; i < RATE_COUNT; i++)
+ if (rate >= valid_rates[i]) {
+ value &= 0x60;
+ value |= i;
+ break;
+ }
+
+ for (i = 0; i < DELAY_COUNT; i++)
+ if (delay <= valid_delays[i]) {
+ value &= 0x1f;
+ value |= i << 5;
+ break;
+ }
+
+ ioctl (xf86Info.consoleFd, KBIO_SETRATE, value);
+#endif /* defined(KBIO_SETRATE) */
+}
+
+static Bool use_tcs = TRUE, use_kd = TRUE;
+static Bool no_nmap = TRUE, no_emap = TRUE;
+static int orig_getsc, orig_kbm;
+static struct termios orig_termios;
+static keymap_t keymap, noledmap;
+static uchar_t *sc_mapbuf;
+static uchar_t *sc_mapbuf2;
+
+void
+xf86KbdInit(void)
+{
+ orig_getsc = 0;
+ if (ioctl (xf86Info.consoleFd, TCGETSC, &orig_getsc) < 0)
+ use_tcs = FALSE;
+ if (ioctl (xf86Info.consoleFd, KDGKBMODE, &orig_kbm) < 0)
+ use_kd = FALSE;
+
+ if (!use_tcs && !use_kd)
+ FatalError ("xf86KbdInit: Could not determine keyboard mode\n");
+
+ /*
+ * One day this should be fixed to translate normal ASCII characters
+ * back into scancodes or into events that XFree86 wants, but not
+ * now. For the time being, we only support scancode mode screens.
+ */
+ if (use_tcs && !(orig_getsc & KB_ISSCANCODE))
+ FatalError ("xf86KbdInit: Keyboard can not send scancodes\n");
+
+ /*
+ * We need to get the original keyboard map and NUL out the lock
+ * modifiers. This prevents the scancode API from messing with
+ * the keyboard LED's. We restore the original map when we exit.
+ */
+ if (ioctl (xf86Info.consoleFd, GIO_KEYMAP, &keymap) < 0) {
+ FatalError ("xf86KbdInit: Failed to get keyboard map (%s)\n",
+ strerror(errno));
+ }
+ if (ioctl (xf86Info.consoleFd, GIO_KEYMAP, &noledmap) < 0) {
+ FatalError ("xf86KbdInit: Failed to get keyboard map (%s)\n",
+ strerror(errno));
+ } else {
+ int i, j;
+
+ for (i = 0; i < noledmap.n_keys; i++) {
+ for (j = 0; j < NUM_STATES; j++) {
+ if (IS_SPECIAL(noledmap, i, j) &&
+ ((noledmap.key[i].map[j] == K_CLK) ||
+ (noledmap.key[i].map[j] == K_NLK) ||
+ (noledmap.key[i].map[j] == K_SLK))) {
+ noledmap.key[i].map[j] = K_NOP;
+ }
+ }
+ }
+ }
+
+ if (ioctl (xf86Info.consoleFd, XCGETA, &orig_termios) < 0) {
+ FatalError ("xf86KbdInit: Failed to get terminal modes (%s)\n",
+ strerror(errno));
+ }
+
+ sc_mapbuf = xalloc (10*BSIZE);
+ sc_mapbuf2 = xalloc(10*BSIZE);
+
+ /* Get the emap */
+ if (ioctl (xf86Info.consoleFd, LDGMAP, sc_mapbuf) < 0) {
+ if (errno != ENAVAIL) {
+ FatalError ("xf86KbdInit: Failed to retrieve e-map (%s)\n",
+ strerror (errno));
+ }
+ no_emap = FALSE;
+ }
+
+ /* Get the nmap */
+ if (ioctl (xf86Info.consoleFd, NMGMAP, sc_mapbuf2) < 0) {
+ if (errno != ENAVAIL) {
+ FatalError ("xf86KbdInit: Failed to retrieve n-map (%s)\n",
+ strerror (errno));
+ }
+ no_nmap = FALSE;
+ }
+}
+
+int
+xf86KbdOn(void)
+{
+ struct termios newtio;
+
+ ioctl (xf86Info.consoleFd, LDNMAP); /* Turn e-mapping off */
+ ioctl (xf86Info.consoleFd, NMNMAP); /* Turn n-mapping off */
+
+ newtio = orig_termios; /* structure copy */
+ newtio.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ newtio.c_oflag = 0;
+ newtio.c_cflag = CREAD | CS8 | B9600;
+ newtio.c_lflag = 0;
+ newtio.c_cc[VTIME]=0;
+ newtio.c_cc[VMIN]=1;
+ cfsetispeed(&newtio, 9600);
+ cfsetospeed(&newtio, 9600);
+ ioctl(xf86Info.consoleFd, XCSETA, &newtio);
+
+ /* Now tell the keyboard driver to send us raw scancodes */
+ if (use_tcs) {
+ int nm = orig_getsc;
+ nm &= ~KB_XSCANCODE;
+ ioctl (xf86Info.consoleFd, TCSETSC, &nm);
+ }
+
+ if (use_kd)
+ ioctl (xf86Info.consoleFd, KDSKBMODE, K_RAW);
+
+ ioctl (xf86Info.consoleFd, PIO_KEYMAP, &noledmap);
+
+ return(xf86Info.consoleFd);
+}
+
+int
+xf86KbdOff(void)
+{
+ /* Revert back to original translate scancode mode */
+ if (use_tcs)
+ ioctl (xf86Info.consoleFd, TCSETSC, &orig_getsc);
+ if (use_kd)
+ ioctl (xf86Info.consoleFd, KDSKBMODE, orig_kbm);
+
+ ioctl (xf86Info.consoleFd, PIO_KEYMAP, &keymap);
+
+ if (no_emap)
+ ioctl (xf86Info.consoleFd, LDSMAP, sc_mapbuf);
+ if (no_nmap)
+ ioctl (xf86Info.consoleFd, NMSMAP, sc_mapbuf2);
+
+ ioctl(xf86Info.consoleFd, XCSETA, &orig_termios);
+
+ return(xf86Info.consoleFd);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_iop.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_iop.c
new file mode 100644
index 000000000..35d48e04a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_iop.c
@@ -0,0 +1,136 @@
+/* $XFree86$ */
+/*
+ * Copyright 2001 by J. Kean Johnston <jkj@caldera.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name J. Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. J. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * J. KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL J. KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $XConsortium$ */
+
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#define _NEED_SYSI86
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86OSpriv.h"
+#include "xf86_OSlib.h"
+
+
+/***************************************************************************/
+/* I/O Permissions section */
+/***************************************************************************/
+
+/*
+ * There is a right way and a wrong way of doing this. Unfortunately, we
+ * are forced to do it the wrong way. The right way is to be told the range
+ * or ranges of I/O ports the driver(s) need access to, in order to use the
+ * CONS_IOPERM ioctl() to grant access only to those ports we care about.
+ * This way we can guarantee some small level of stability because a driver
+ * does not have access to all ports (which would mean it could play with
+ * the PIT and thus affect scheduling times, or a whole slew of other
+ * nasty things). However, because XFree86 currently only enables or disables
+ * ALL port access, we need to run at IOPL 3, which basically means the
+ * X Server runs at the same level as the kernel. You can image why this is
+ * unsafe. Oh, and this is not a problem unique to OSR5, other OSes are
+ * affected by this as well.
+ *
+ * So, for the time being, we change our IOPL until such time as the XFree86
+ * architecture is changed to allow for tighter control of I/O ports. If and
+ * when it is, then the CONS_ADDIOP/DELIOP ioctl() should be used to enable
+ * or disable access to the desired ports.
+ */
+
+extern long sysi86 (int cmd, ...);
+
+static Bool IOEnabled = FALSE;
+
+Bool
+xf86EnableIO(void)
+{
+ if (IOEnabled)
+ return TRUE;
+
+ if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) {
+ xf86Msg(X_WARNING,"Failed to set IOPL for extended I/O\n");
+ return FALSE;
+ }
+
+ IOEnabled = TRUE;
+ return TRUE;
+}
+
+void
+xf86DisableIO(void)
+{
+ if (!IOEnabled)
+ return;
+
+ sysi86(SI86V86, V86SC_IOPL, 0);
+ IOEnabled = FALSE;
+}
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts(void)
+{
+ if (!IOEnabled) {
+ if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0)
+ return FALSE;
+ }
+
+#ifdef __GNUC__
+ __asm__ __volatile__("cli");
+#else
+ asm("cli");
+#endif /* __GNUC__ */
+
+ if (!IOEnabled) {
+ sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
+ }
+
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts(void)
+{
+ if (!IOEnabled) {
+ if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0)
+ return;
+ }
+
+#ifdef __GNUC__
+ __asm__ __volatile__("sti");
+#else
+ asm("sti");
+#endif /* __GNUC__ */
+
+ if (!IOEnabled) {
+ sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_kbd.c
new file mode 100644
index 000000000..a26b7e96b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_kbd.c
@@ -0,0 +1,530 @@
+/* $XFree86$ */
+/*
+ * Copyright 2005 by J. Kean Johnston <jkj@sco.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name J. Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. J. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * J. KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL J. KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $XConsortium$ */
+
+/*
+ * Based on sco_io.c which is
+ * (C) Copyright 2003 J. Kean Johnston <jkj@sco.com>
+ *
+ * Based on lnx_kbd.c which is
+ * Copyright (c) 2002 by The XFree86 Project, Inc.
+ *
+ * Based on the code from lnx_io.c which is
+ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ */
+
+#define NEED_EVENTS
+#include "X.h"
+
+#include "compiler.h"
+
+#define _NEED_SYSI86
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86OSpriv.h"
+#include "xf86_OSlib.h"
+
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+#include "atKeynames.h"
+#include "sco_kbd.h"
+
+#include <sys/param.h>
+#include <sys/emap.h>
+#include <sys/nmap.h>
+
+static KbdProtocolRec protocols[] = {
+ { "standard", PROT_STD },
+ { NULL, PROT_UNKNOWN_KBD }
+};
+
+extern Bool VTSwitchEnabled;
+#ifdef USE_VT_SYSREQ
+extern Bool VTSysreqToggle;
+#endif
+
+static void
+SoundBell(InputInfoPtr pInfo, int loudness, int pitch, int duration)
+{
+ if (loudness && pitch) {
+ ioctl(pInfo->fd, KIOCSOUND, 1193180 / pitch);
+ usleep(duration * loudness * 20);
+ ioctl(pInfo->fd, KIOCSOUND, 0);
+ }
+}
+
+static void
+SetKbdLeds(InputInfoPtr pInfo, int leds)
+{
+ int real_leds = 0;
+ static int once = 1;
+
+ /*
+ * sleep the first time through under SCO. There appears to be a
+ * timing problem in the driver which causes the keyboard to be lost.
+ * This usleep stops it from occurring. NOTE: this was in the old code.
+ * I am not convinced it is true any longer, but it doesn't hurt to
+ * leave this in here.
+ */
+ if (once) {
+ usleep(100);
+ once = 0;
+ }
+
+#ifdef LED_CAP
+ if (leds & XLED1)
+ real_leds |= LED_CAP;
+ if (leds & XLED2)
+ real_leds |= LED_NUM;
+ if (leds & XLED3)
+ real_leds |= LED_SCR;
+#ifdef LED_COMP
+ if (leds & XLED4)
+ real_leds |= LED_COMP;
+#else
+ if (leds & XLED4)
+ real_leds |= LED_SCR;
+#endif
+#endif
+ ioctl(pInfo->fd, KDSETLED, real_leds);
+}
+
+static int
+GetKbdLeds(InputInfoPtr pInfo)
+{
+ int real_leds, leds = 0;
+
+ ioctl(pInfo->fd, KDGETLED, &real_leds);
+
+ if (real_leds & LED_CAP) leds |= XLED1;
+ if (real_leds & LED_NUM) leds |= XLED2;
+ if (real_leds & LED_SCR) leds |= XLED3;
+
+ return(leds);
+}
+
+/*
+ * NOTE: Only OpenServer Release 5.0.6 with Release Supplement 5.0.6A
+ * and later have the required ioctl. 5.0.6A or higher is HIGHLY
+ * recommended. The console driver is quite a different beast on that OS.
+ */
+#undef rate
+
+static void
+SetKbdRepeat(InputInfoPtr pInfo, char rad)
+{
+#if defined(KBIO_SETRATE)
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int i;
+ int value = 0x7f; /* Maximum delay with slowest rate */
+ int delay = 250; /* Default delay */
+ int rate = 300; /* Default repeat rate */
+
+ static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150,
+ 133, 120, 109, 100, 92, 86, 80, 75, 67,
+ 60, 55, 50, 46, 43, 40, 37, 33, 30, 27,
+ 25, 23, 21, 20 };
+#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int ))
+
+ static int valid_delays[] = { 250, 500, 750, 1000 };
+#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int ))
+
+ if (pKbd->rate >= 0)
+ rate = pKbd->rate * 10;
+ if (pKbd->delay >= 0)
+ delay = pKbd->delay;
+
+ for (i = 0; i < RATE_COUNT; i++)
+ if (rate >= valid_rates[i]) {
+ value &= 0x60;
+ value |= i;
+ break;
+ }
+
+ for (i = 0; i < DELAY_COUNT; i++)
+ if (delay <= valid_delays[i]) {
+ value &= 0x1f;
+ value |= i << 5;
+ break;
+ }
+
+ ioctl (pInfo->fd, KBIO_SETRATE, value);
+#endif /* defined(KBIO_SETRATE) */
+}
+
+static int
+KbdInit(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ ScoKbdPrivPtr priv = (ScoKbdPrivPtr) pKbd->private;
+
+ if (pKbd->isConsole) {
+ priv->use_tcs = 1;
+ priv->use_kd = 1;
+ priv->no_nmap = 1;
+ priv->no_emap = 1;
+ priv->orig_getsc = 0;
+
+ if (ioctl (pInfo->fd, TCGETSC, &priv->orig_getsc) < 0)
+ priv->use_tcs = 0;
+ if (ioctl (pInfo->fd, KDGKBMODE, &priv->orig_kbm) < 0)
+ priv->use_kd = 0;
+
+ if (!priv->use_tcs && !priv->use_kd) {
+ xf86Msg (X_ERROR, "KbdInit: Could not determine keyboard mode\n");
+ return !Success;
+ }
+
+ /*
+ * One day this should be fixed to translate normal ASCII characters
+ * back into scancodes or into events that XFree86 wants, but not
+ * now. For the time being, we only support scancode mode screens.
+ */
+ if (priv->use_tcs && !(priv->orig_getsc & KB_ISSCANCODE)) {
+ xf86Msg (X_ERROR, "KbdInit: Keyboard can not send scancodes\n");
+ return !Success;
+ }
+
+ /*
+ * We need to get the original keyboard map and NUL out the lock
+ * modifiers. This prevents the scancode API from messing with
+ * the keyboard LED's. We restore the original map when we exit.
+ */
+ if (ioctl (pInfo->fd, GIO_KEYMAP, &priv->keymap) < 0) {
+ xf86Msg (X_ERROR, "KbdInit: Failed to get keyboard map (%s)\n",
+ strerror(errno));
+ return !Success;
+ }
+ if (ioctl (pInfo->fd, GIO_KEYMAP, &priv->noledmap) < 0) {
+ xf86Msg (X_ERROR, "KbdInit: Failed to get keyboard map (%s)\n",
+ strerror(errno));
+ return !Success;
+ } else {
+ int i, j;
+
+ for (i = 0; i < priv->noledmap.n_keys; i++) {
+ for (j = 0; j < NUM_STATES; j++) {
+ if (IS_SPECIAL(priv->noledmap, i, j) &&
+ ((priv->noledmap.key[i].map[j] == K_CLK) ||
+ (priv->noledmap.key[i].map[j] == K_NLK) ||
+ (priv->noledmap.key[i].map[j] == K_SLK))) {
+ priv->noledmap.key[i].map[j] = K_NOP;
+ }
+ }
+ }
+ }
+
+ if (ioctl (pInfo->fd, XCGETA, &priv->kbdtty) < 0) {
+ xf86Msg (X_ERROR, "KbdInit: Failed to get terminal modes (%s)\n",
+ strerror(errno));
+ return !Success;
+ }
+
+ priv->sc_mapbuf = xalloc (10*BSIZE);
+ priv->sc_mapbuf2 = xalloc(10*BSIZE);
+
+ /* Get the emap */
+ if (ioctl (pInfo->fd, LDGMAP, priv->sc_mapbuf) < 0) {
+ if (errno != ENAVAIL) {
+ xf86Msg (X_ERROR, "KbdInit: Failed to retrieve e-map (%s)\n",
+ strerror (errno));
+ return !Success;
+ }
+ priv->no_emap = 0;
+ }
+
+ /* Get the nmap */
+ if (ioctl (pInfo->fd, NMGMAP, priv->sc_mapbuf2) < 0) {
+ if (errno != ENAVAIL) {
+ xf86Msg (X_ERROR, "KbdInit: Failed to retrieve n-map (%s)\n",
+ strerror (errno));
+ return !Success;
+ }
+ priv->no_nmap = 0;
+ }
+ } /* End of if we are on a console */
+
+ return Success;
+}
+
+static int
+KbdOn(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ ScoKbdPrivPtr priv = (ScoKbdPrivPtr) pKbd->private;
+ struct termios newtio;
+
+ if (pKbd->isConsole) {
+ ioctl (pInfo->fd, LDNMAP); /* Turn e-mapping off */
+ ioctl (pInfo->fd, NMNMAP); /* Turn n-mapping off */
+
+ newtio = priv->kbdtty; /* structure copy */
+ newtio.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ newtio.c_oflag = 0;
+ newtio.c_cflag = CREAD | CS8 | B9600;
+ newtio.c_lflag = 0;
+ newtio.c_cc[VTIME]=0;
+ newtio.c_cc[VMIN]=1;
+ cfsetispeed(&newtio, 9600);
+ cfsetospeed(&newtio, 9600);
+ ioctl(pInfo->fd, XCSETA, &newtio);
+
+ /* Now tell the keyboard driver to send us raw scancodes */
+ if (priv->use_tcs) {
+ int nm = priv->orig_getsc;
+ nm &= ~KB_XSCANCODE;
+ ioctl (pInfo->fd, TCSETSC, &nm);
+ }
+
+ if (priv->use_kd)
+ ioctl (pInfo->fd, KDSKBMODE, K_RAW);
+
+ ioctl (pInfo->fd, PIO_KEYMAP, &priv->noledmap);
+ }
+
+ return Success;
+}
+
+static int
+KbdOff(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ ScoKbdPrivPtr priv = (ScoKbdPrivPtr) pKbd->private;
+
+ if (pKbd->isConsole) {
+ /* Revert back to original translate scancode mode */
+ if (priv->use_tcs)
+ ioctl (pInfo->fd, TCSETSC, &priv->orig_getsc);
+ if (priv->use_kd)
+ ioctl (pInfo->fd, KDSKBMODE, priv->orig_kbm);
+
+ ioctl (pInfo->fd, PIO_KEYMAP, &priv->keymap);
+
+ if (priv->no_emap)
+ ioctl (pInfo->fd, LDSMAP, priv->sc_mapbuf);
+ if (priv->no_nmap)
+ ioctl (pInfo->fd, NMSMAP, priv->sc_mapbuf2);
+
+ ioctl(pInfo->fd, XCSETA, &priv->kbdtty);
+ }
+
+ return Success;
+}
+
+static int
+GetSpecialKey(InputInfoPtr pInfo, int scanCode)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int specialkey = scanCode;
+
+ if (pKbd->CustomKeycodes) {
+ specialkey = pKbd->specialMap->map[scanCode];
+ }
+ return specialkey;
+}
+
+#define ModifierSet(k) ((modifiers & (k)) == (k))
+
+static Bool
+SpecialKey(InputInfoPtr pInfo, int key, Bool down, int modifiers)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+
+ if(!pKbd->vtSwitchSupported)
+ return FALSE;
+
+ if ((!ModifierSet(ShiftMask)) && ((ModifierSet(ControlMask | AltMask)) ||
+ (ModifierSet(ControlMask | AltLangMask)))) {
+ if (VTSwitchEnabled && !xf86Info.vtSysreq) {
+ switch (key) {
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ if (down) {
+ int sts = key - KEY_F1;
+ if (sts != xf86Info.vtno) {
+ ioctl(pInfo->fd, VT_ACTIVATE, sts);
+ }
+ return TRUE;
+ }
+ case KEY_F11:
+ case KEY_F12:
+ if (down) {
+ int sts = key - KEY_F11 + 10;
+ if (sts != xf86Info.vtno) {
+ ioctl(pInfo->fd, VT_ACTIVATE, sts);
+ }
+ return TRUE;
+ }
+ }
+ }
+ }
+#ifdef USE_VT_SYSREQ
+ if (VTSwitchEnabled && xf86Info.vtSysreq) {
+ switch (key) {
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ if (VTSysreqToggle && down) {
+ ioctl(pInfo->fd, VT_ACTIVATE, key - KEY_F1);
+ VTSysreqToggle = FALSE;
+ return TRUE;
+ }
+ break;
+ case KEY_F11:
+ case KEY_F12:
+ if (VTSysreqToggle && down) {
+ ioctl(pInfo->fd, VT_ACTIVATE, key - KEY_F11 + 10);
+ VTSysreqToggle = FALSE;
+ return TRUE;
+ }
+ break;
+ /* Ignore these keys -- ie don't let them cancel an alt-sysreq */
+ case KEY_Alt:
+ case KEY_AltLang:
+ break;
+ case KEY_SysReqest:
+ if (!(ModifierSet(ShiftMask) || ModifierSet(ControlMask))) {
+ if ((ModifierSet(AltMask) || ModifierSet(AltLangMask)) && down)
+ VTSysreqToggle = TRUE;
+ }
+ break;
+ default:
+ /*
+ * We only land here when Alt-SysReq is followed by a
+ * non-switching key.
+ */
+ if (VTSysreqToggle)
+ VTSysreqToggle = FALSE;
+ }
+ }
+#endif /* USE_VT_SYSREQ */
+ return FALSE;
+}
+
+static void
+stdReadInput(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ unsigned char rBuf[64];
+ int nBytes, i;
+
+ if ((nBytes = read( pInfo->fd, (char *)rBuf, sizeof(rBuf))) > 0) {
+ for (i = 0; i < nBytes; i++) {
+ pKbd->PostEvent(pInfo, rBuf[i] & 0x7f, rBuf[i] & 0x80 ? FALSE : TRUE);
+ }
+ }
+}
+
+static Bool
+OpenKeyboard(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int i;
+ KbdProtocolId prot = PROT_UNKNOWN_KBD;
+ char *s;
+
+ s = xf86SetStrOption(pInfo->options, "Protocol", NULL);
+ for (i = 0; protocols[i].name; i++) {
+ if (xf86NameCmp(s, protocols[i].name) == 0) {
+ prot = protocols[i].id;
+ break;
+ }
+ }
+
+ switch (prot) {
+ case PROT_STD:
+ pInfo->read_input = stdReadInput;
+ break;
+ default:
+ xf86Msg(X_ERROR,"\"%s\" is not a valid keyboard protocol name\n", s);
+ xfree(s);
+ return FALSE;
+ }
+
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, s);
+ xfree(s);
+
+ s = xf86SetStrOption(pInfo->options, "Device", NULL);
+ if (s == NULL) {
+ pInfo->fd = xf86Info.consoleFd;
+ pKbd->isConsole = TRUE;
+ } else {
+ pInfo->fd = open(s, O_RDONLY | O_NONBLOCK | O_EXCL);
+ if (pInfo->fd == -1) {
+ xf86Msg(X_ERROR, "%s: cannot open \"%s\"\n", pInfo->name, s);
+ xfree(s);
+ return FALSE;
+ }
+ pKbd->isConsole = FALSE;
+ xfree(s);
+ }
+
+ if (pKbd->isConsole)
+ pKbd->vtSwitchSupported = TRUE;
+
+ return TRUE;
+}
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = pInfo->private;
+
+ pKbd->KbdInit = KbdInit;
+ pKbd->KbdOn = KbdOn;
+ pKbd->KbdOff = KbdOff;
+ pKbd->Bell = SoundBell;
+ pKbd->SetLeds = SetKbdLeds;
+ pKbd->GetLeds = GetKbdLeds;
+ pKbd->SetKbdRepeat = SetKbdRepeat;
+ pKbd->KbdGetMapping = KbdGetMapping;
+ pKbd->SpecialKey = SpecialKey;
+ pKbd->GetSpecialKey = GetSpecialKey;
+ pKbd->OpenKeyboard = OpenKeyboard;
+ pKbd->RemapScanCode = ATScancode;
+ pKbd->vtSwitchSupported = FALSE;
+
+ pKbd->private = xcalloc(sizeof(ScoKbdPrivRec), 1);
+ if (pKbd->private == NULL) {
+ xf86Msg(X_ERROR,"can't allocate keyboard OS private data\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_kbd.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_kbd.h
new file mode 100644
index 000000000..a79cd7bb9
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_kbd.h
@@ -0,0 +1,20 @@
+/* $XFree86$ */
+#ifndef SCO_KBD_HDR
+#define SCO_KBD_HDR
+
+typedef struct {
+ int use_tcs;
+ int use_kd;
+ int no_nmap;
+ int no_emap;
+ int orig_getsc;
+ int orig_kbm;
+ struct termios kbdtty;
+ keymap_t keymap, noledmap;
+ uchar_t *sc_mapbuf;
+ uchar_t *sc_mapbuf2;
+} ScoKbdPrivRec, *ScoKbdPrivPtr;
+
+extern void KbdGetMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms,
+ CARD8 *pModMap);
+#endif /* SCO_KBD_HDR */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_mouse.c
new file mode 100644
index 000000000..ea81c947d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_mouse.c
@@ -0,0 +1,261 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sco/sco_mouse.c,v 3.12 2001/06/30 22:41:49 tsi Exp $ */
+/*
+ * Copyright 2001 by J. Kean Johnston <jkj@sco.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name J. Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. J. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * J. KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL J. KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $XConsortium$ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "mipointer.h"
+#include <sys/event.h>
+#include <mouse.h>
+
+static int
+SupportedInterfaces (void)
+{
+ return MSE_MISC;
+}
+
+static const char *internalNames[] = {
+ "OSMouse",
+ NULL
+};
+
+static const char **
+BuiltinNames (void)
+{
+ return internalNames;
+}
+
+static Bool
+CheckProtocol (const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++) {
+ if (xf86NameCmp (protocol, internalNames[i]) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static const char *
+DefaultProtocol (void)
+{
+ return "OSMouse";
+}
+
+static const char *
+evtErrStr (int evterr)
+{
+ switch (evterr) {
+ case -1: return "error in config files";
+ case -2: return "no mouse devices to attach";
+ case -3: return "unable to open device";
+ case -4: return "unable to open event queue";
+ case -999: return "unable to initialize event driver";
+ default: return "unknown event driver error";
+ }
+}
+
+static int
+OsMouseProc (DeviceIntPtr pPointer, int what)
+{
+ InputInfoPtr pInfo;
+ MouseDevPtr pMse;
+ unsigned char map[9];
+ dmask_t dmask;
+ MessageType from = X_CONFIG;
+ int evi;
+
+ pInfo = pPointer->public.devicePrivate;
+ pMse = pInfo->private;
+ pMse->device = pPointer;
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+
+ dmask = D_ABS | D_REL | D_BUTTON;
+ if ((evi = ev_initf(xf86Info.consoleFd)) < 0) {
+ FatalError ("OsMouseProc: Event driver initialization failed (%s)\n",
+ evtErrStr(evi));
+ }
+ pInfo->fd = ev_open (&dmask);
+ if (pInfo->fd < 0) {
+ FatalError ("OsMouseProc: DEVICE_INIT failed (%s)\n", evtErrStr(pInfo->fd));
+ }
+
+ pMse->buttons = xf86SetIntOption (pInfo->options, "Buttons", 0);
+ if (pMse->buttons == 0) {
+ pMse->buttons = 8;
+ from = X_DEFAULT;
+ }
+ xf86Msg (from, "%s: Buttons: %d\n", pInfo->name, pMse->buttons);
+
+ for (evi = 0; evi <= 8; evi++)
+ map[evi] = evi;
+
+ InitPointerDeviceStruct((DevicePtr)pPointer, map, 8,
+ miPointerGetMotionEvents, pMse->Ctrl,
+ miPointerGetMotionBufferSize());
+
+ /* X valuator */
+ xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 0);
+
+ /* Y valuator */
+ xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 1);
+
+ xf86MotionHistoryAllocate(pInfo);
+
+ ev_flush();
+ ev_suspend();
+ break;
+
+ case DEVICE_ON:
+ pMse->lastButtons = 0;
+ pMse->lastMappedButtons = 0;
+ pMse->emulateState = 0;
+ pPointer->public.on = TRUE;
+ ev_resume();
+ AddEnabledDevice (pInfo->fd);
+ break;
+
+ case DEVICE_OFF:
+ case DEVICE_CLOSE:
+ pPointer->public.on = FALSE;
+ RemoveEnabledDevice (pInfo->fd);
+ if (what == DEVICE_CLOSE) {
+ ev_close();
+ pInfo->fd = -1;
+ } else {
+ ev_suspend();
+ }
+ break;
+ }
+
+ return Success;
+}
+
+static void
+OsMouseReadInput (InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse;
+ EVENT *evp;
+
+ pMse = pInfo->private;
+
+ while ((evp = ev_read()) != (EVENT *)0) {
+ int buttons = EV_BUTTONS(*evp);
+ int dx = EV_DX(*evp), dy = -(EV_DY(*evp)), dz = 0;
+
+ if (buttons & WHEEL_FWD)
+ dz = -1;
+ else if (buttons & WHEEL_BACK)
+ dz = 1;
+
+ buttons &= ~(WHEEL_FWD | WHEEL_BACK);
+
+ pMse->PostEvent (pInfo, buttons, dx, dy, dz, 0);
+ ev_pop();
+ }
+}
+
+static Bool
+OsMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ MouseDevPtr pMse;
+
+ /* This is called when the protocol is "OSMouse". */
+
+ pMse = pInfo->private;
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ /* Check if the device can be opened. */
+ pInfo->fd = ev_initf(xf86Info.consoleFd);
+ if (pInfo->fd != -1) {
+ dmask_t dmask = (D_ABS | D_REL | D_BUTTON);
+ pInfo->fd = ev_open(&dmask);
+ } else {
+ pInfo->fd = -999;
+ }
+
+ if (pInfo->fd < 0) {
+ if (xf86GetAllowMouseOpenFail())
+ xf86Msg(X_WARNING, "%s: cannot open event manager (%s)\n",
+ pInfo->name, evtErrStr(pInfo->fd));
+ else {
+ xf86Msg(X_ERROR, "%s: cannot open event manager (%s)\n",
+ pInfo->name, evtErrStr(pInfo->fd));
+ xfree(pMse);
+ return FALSE;
+ }
+ }
+ ev_close();
+ pInfo->fd = -1;
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local procs. */
+ pInfo->device_control = OsMouseProc;
+ pInfo->read_input = OsMouseReadInput;
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit (int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+
+ p->SupportedInterfaces = SupportedInterfaces;
+ p->BuiltinNames = BuiltinNames;
+ p->DefaultProtocol = DefaultProtocol;
+ p->CheckProtocol = CheckProtocol;
+ p->PreInit = OsMousePreInit;
+
+ return p;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_video.c
new file mode 100644
index 000000000..dd81786bb
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sco/sco_video.c
@@ -0,0 +1,296 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sco/sco_video.c,v 3.8tsi Exp $ */
+/*
+ * Copyright 2001 by J. Kean Johnston <jkj@sco.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name J. Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. J. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * J. KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL J. KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $XConsortium$ */
+
+/* Re-written May 2001 to represent the current state of reality */
+
+/*
+ * This file contains the completely re-written SCO OpenServer video
+ * routines for XFree86 4.x. Much of this is based on the SCO X server
+ * code (which is an X11R5 server) and will probably only work on
+ * OpenServer versions 5.0.5, 5.0.6 and later. Please send me (jkj@sco.com)
+ * email if you have any questions.
+ *
+ * Ideally, you should use OSR5.0.6A or later, with the updated console
+ * driver for 5.0.6A (its the default driver in 5.0.7 and later).
+ * However, if you are running on an older system, this code will detect
+ * that and adjust accordingly.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#define _NEED_SYSI86
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86OSpriv.h"
+#include "xf86_OSlib.h"
+
+#include <sys/ci/ciioctl.h>
+#define MPXNAME "/dev/atp1"
+#define BASECPU 1
+
+Bool mpxLock = TRUE;
+
+#define USE_VASMETHOD 1
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+static int sco_mcdone = 0, sco_ismc = 0;
+
+/***************************************************************************/
+/*
+ * To map the video memory, we first need to see if we are on a multi-console
+ * system. If we are, we need to try to use an existing video class in the
+ * kernel. We do this by retrieving the list of currently defined classes
+ * (via the new CONS_GETCLASS ioctl()) to see if we have a class that will
+ * match the range of memory we desire. If we can't find one, we have an
+ * error and we abort.
+ *
+ * If we are not using a multi-console, we can simply use mmap() to map in
+ * the frame buffer, using the classs-access method as a fall-back only if
+ * the mmap() fails (it shouldn't). We always set the appropriate pointers
+ * in the config structure to point ot the right function to map and unmap
+ * the video memory. An alternative to using mmap() is to use the new
+ * CONS_ADDVAS call, which will use vasmalloc() and vasbind() in the kernel
+ * to map the physical address to a virtual one, which it then returns.
+ * I am not 100% sure if this is faster or not, but it may prove easier to
+ * debug things. Just to be on the safe side, I have included both methods
+ * here, and the mmap() method can be used by setting USE_VASMETHOD to 0
+ * above.
+ */
+
+#if !defined(CONS_ADDVAS)
+# undef USE_VASMETHOD
+# define USE_VASMETHOD 0
+#endif
+
+static int
+scoIsMultiConsole (void)
+{
+ int x;
+
+ if (sco_mcdone)
+ return sco_ismc;
+ x = access ("/usr/lib/vidconf/.multiconsole", F_OK);
+ if (x == 0)
+ sco_ismc = 1;
+ sco_mcdone = 1;
+ return sco_ismc;
+}
+
+/*
+ * This maps memory using mmap()
+ */
+static pointer
+mapVidMemMMAP(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ int fd;
+ unsigned long realBase, alignOff;
+ pointer base;
+
+ fd = open (DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
+ if (fd < 0) {
+ FatalError("xf86MapVidMem: failed to open %s (%s)\n", DEV_MEM,
+ strerror(errno));
+ return 0; /* NOTREACHED */
+ }
+
+ realBase = Base & ~(getpagesize() - 1);
+ alignOff = Base - realBase;
+
+#ifdef DEBUG
+ ErrorF("base: %lx, realBase: %lx, alignOff: %lx\n", Base,realBase,alignOff);
+#endif
+
+ base = mmap((caddr_t)0, Size + alignOff,
+ (flags & VIDMEM_READONLY) ? PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, fd, (off_t)realBase);
+ close(fd);
+ if (base == MAP_FAILED) {
+ FatalError("xf86MapVidMem: Could not mmap framebuffer (0x%08x,0x%x) (%s)\n",
+ Base, Size, strerror(errno));
+ return 0; /* NOTREACHED */
+ }
+
+#ifdef DEBUG
+ ErrorF("base: %lx aligned base: %lx\n",base, base + alignOff);
+#endif
+ return (pointer)((char *)base + alignOff);
+}
+
+#if (USE_VASMETHOD)
+/*
+ * This maps memory using the virtual address space (VAS) console calls.
+ */
+static pointer
+mapVidMemVAS(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ struct vidvasmem vas;
+ pointer base;
+
+ vas.base = (long)Base;
+ vas.size = (long)Size;
+
+ base = (pointer)ioctl (xf86Info.consoleFd, CONS_ADDVAS, &vas);
+ if (base == (pointer)-1) {
+ return mapVidMemMMAP(ScreenNum, Base, Size, flags);
+ }
+ return base;
+}
+#endif /* USE_VASMETHOD */
+
+struct vidclass vidclasslist[] = {
+ { "VBE", "", 0xf0000000, 0x2000000, 0 },
+ { "P9000", "", 0xc0000000, 0x400000, 0 },
+ { "TULIP", "", 0x80000000, 0x400000, 0 },
+ { "VIPER", "", 0xa0000000, 0x400000, 0 },
+ { "S3T", "", 0xa0000000, 0x200000, 0 },
+ { "S3DT", "", 0x4000000, 0x400000, 0 },
+ { "MGA", "", 0x2200000, 0x4000, 0 },
+ { "CLVGA", "", 0xa0000, 0x20000, 0 },
+ { "OLIVE", "", 0xd8000000, 0x400000, 0 },
+ { "S3C", "", 0xa0000, 0x10000, 0 },
+ { "MGAVLB", "", 0xac000, 0x34000, 0 },
+ { "ATI8514", "", 0xFF000, 0x1000, 0 },
+ { "GXREGS", "", 0xb0000, 0x10000, 0 },
+ { "GX", "", 0xa0000, 0x10000, 0 },
+ { "CT64300", "", 0xa0000000, 0x400000, 0 },
+ { "SVGA", "", 0xa0000, 0x20000, 0 },
+ { "S3V", "", 0xa0000000, 0x400000, 0 },
+ { "8514A", "", 0xFF000, 0x1000, 0 },
+ { "VGA", "", 0xa0000, 0x10000, 0 },
+ { 0 }
+};
+
+static pointer
+mapVidMemVC(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ struct vidclass *vcp;
+ char *class = NULL;
+ pointer base;
+
+ for (vcp = vidclasslist; vcp->name; vcp++) {
+ if ((vcp->base == Base) && (vcp->size == Size)) {
+ class = vcp->name;
+ break;
+ }
+ }
+
+ if (class == NULL) {
+ /*
+ * As a fall-back, we will try and use the mmap() approach. This may
+ * prove to be the wrong thing to do, but time and testing will tell.
+ */
+ ErrorF("xf86MapVidMem: No class map defined for (0x%08x,0x%08x)\n", Base, Size);
+#if USE_VASMETHOD
+ return mapVidMemVAS(ScreenNum, Base, Size, flags);
+#else /* !USE_VASMETHOD */
+ return mapVidMemMMAP(ScreenNum, Base, Size, flags);
+#endif
+ }
+
+ /*
+ * We found a suitable class. Try and use it.
+ */
+ base = (pointer)ioctl(xf86Info.consoleFd, MAP_CLASS, class);
+ if ((int)base == -1) {
+ FatalError("xf86MapVidMem: Failed to map video memory class `%s'\n", class);
+ return 0; /* NOTREACHED */
+ }
+
+ return base;
+}
+
+/*
+ * Unmapping the video memory is easy. We always call munmap(), as it is
+ * safe to do so even if we haven't actually mapped in any pages via mmap().
+ * In the case where we used the video class, we don't need to do anything
+ * as the kernel will clean up the TSS when we exit, and will undo the
+ * vasbind() that was done when the class was originally mapped. If we used
+ * vasmap, we simply undo the map. Again, it is benign to call vasunmap
+ * even if we got the frame buffer via some other mechanism (like mmap).
+ */
+
+static void
+unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+#if USE_VASMETHOD
+ struct vidvasmem vas;
+ int x;
+
+ vas.base = (long)Base;
+ vas.size = (long)Size;
+
+ x = ioctl (xf86Info.consoleFd, CONS_DELVAS, &vas);
+ if (x == 0)
+ return;
+#endif /* USE_VASMETHOD */
+
+ munmap(Base, Size);
+}
+
+/*
+ * Set things up to point to our local functions. When the kernel gets
+ * MTRR support, we will need to add the required functions for that
+ * here too. MTRR support will most likely appear in 5.0.8 or 5.1.0.
+ *
+ * We also want to lock the X server process to the base CPU in an MPX
+ * system, since we will be going to IOPL 3. Most engine drivers can cope
+ * with I/O access on any CPU but there are a few (AST Manhattan I believe)
+ * that can't, so the server needs to be locked to CPU0.
+ */
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ int mpx_fd;
+
+ if (scoIsMultiConsole ()) {
+ pVidMem->mapMem = mapVidMemVC;
+ } else {
+#if USE_VASMETHOD
+ pVidMem->mapMem = mapVidMemVAS;
+#else
+ pVidMem->mapMem = mapVidMemMMAP;
+#endif
+ }
+
+ pVidMem->unmapMem = unmapVidMem;
+ pVidMem->linearSupported = TRUE;
+ pVidMem->initialised = TRUE;
+
+ if (mpxLock && (mpx_fd = open (MPXNAME, O_RDONLY)) > 0) {
+ if (ioctl (mpx_fd, ACPU_XLOCK, BASECPU) < 0)
+ ErrorF ("xf86OSInitVidMem: Can not bind to CPU 0 (%s)\n",
+ strerror(errno));
+ close (mpx_fd);
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/VTsw_noop.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/VTsw_noop.c
new file mode 100644
index 000000000..ac8ae3b0a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/VTsw_noop.c
@@ -0,0 +1,56 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/VTsw_noop.c,v 3.1.4.1 1998/06/05 16:23:20 dawes Exp $ */
+/*
+ * Copyright 1993 by David Wexelblat <dwex@XFree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: VTsw_noop.c /main/3 1996/02/21 17:53:25 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * No-op functions for OSs without VTs
+ */
+
+Bool
+xf86VTSwitchPending()
+{
+ return(FALSE);
+}
+
+Bool
+xf86VTSwitchAway()
+{
+ return(FALSE);
+}
+
+Bool
+xf86VTSwitchTo()
+{
+ return(TRUE);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/VTsw_usl.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/VTsw_usl.c
new file mode 100644
index 000000000..b38470aea
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/VTsw_usl.c
@@ -0,0 +1,92 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/VTsw_usl.c,v 3.1.4.1 1998/06/05 16:23:21 dawes Exp $ */
+/*
+ * Copyright 1993 by David Wexelblat <dwex@XFree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: VTsw_usl.c /main/3 1996/02/21 17:53:28 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#ifdef OSHEADER
+# include OSHEADER
+#endif
+
+/*
+ * Handle the VT-switching interface for OSs that use USL-style ioctl()s
+ * (the sysv, sco, and linux subdirs).
+ */
+
+/*
+ * This function is the signal handler for the VT-switching signal. It
+ * is only referenced inside the OS-support layer.
+ */
+void
+xf86VTRequest(int sig)
+{
+ signal(sig, (void(*)(int))xf86VTRequest);
+ xf86Info.vtRequestsPending = TRUE;
+ return;
+}
+
+Bool
+xf86VTSwitchPending()
+{
+ return(xf86Info.vtRequestsPending ? TRUE : FALSE);
+}
+
+Bool
+xf86VTSwitchAway()
+{
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, 1) < 0)
+ {
+ return(FALSE);
+ }
+ else
+ {
+#ifdef OSSWITCHAWAY
+ OSSWITCHAWAY;
+#endif
+ return(TRUE);
+ }
+}
+
+Bool
+xf86VTSwitchTo()
+{
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
+ {
+ return(FALSE);
+ }
+ else
+ {
+ return(TRUE);
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/agp_noop.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/agp_noop.c
new file mode 100644
index 000000000..c13b29c38
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/agp_noop.c
@@ -0,0 +1,107 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/agp_noop.c,v 1.5 2003/08/24 17:37:05 dawes Exp $ */
+/*
+ * Copyright (c) 2000-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).
+ */
+
+/*
+ * Abstraction of the AGP GART interface. Stubs for platforms without
+ * AGP GART support.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef __UNIXOS2__
+# define I_NEED_OS2_H
+#endif
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+Bool
+xf86GARTCloseScreen(int screenNum)
+{
+ return FALSE;
+}
+
+Bool
+xf86AgpGARTSupported()
+{
+ return FALSE;
+}
+
+AgpInfoPtr
+xf86GetAGPInfo(int screenNum)
+{
+ return NULL;
+}
+
+Bool
+xf86AcquireGART(int screenNum)
+{
+ return FALSE;
+}
+
+Bool
+xf86ReleaseGART(int screenNum)
+{
+ return FALSE;
+}
+
+int
+xf86AllocateGARTMemory(int screenNum, unsigned long size, int type,
+ unsigned long *physical)
+{
+ return -1;
+}
+
+Bool
+xf86DeallocateGARTMemory(int screenNum, int key)
+{
+ return FALSE;
+}
+
+Bool
+xf86BindGARTMemory(int screenNum, int key, unsigned long offset)
+{
+ return FALSE;
+}
+
+
+Bool
+xf86UnbindGARTMemory(int screenNum, int key)
+{
+ return FALSE;
+}
+
+Bool
+xf86EnableAGP(int screenNum, CARD32 mode)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/at_scancode.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/at_scancode.c
new file mode 100644
index 000000000..8947254bc
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/at_scancode.c
@@ -0,0 +1,132 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/at_scancode.c,v 1.4 2003/08/24 17:37:05 dawes Exp $ */
+/*
+ * Copyright (c) 2002-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
+
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+#include "atKeynames.h"
+
+Bool
+ATScancode(InputInfoPtr pInfo, int *scanCode)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+
+ switch (pKbd->scanPrefix) {
+ case 0:
+ switch (*scanCode) {
+ case KEY_Prefix0:
+ case KEY_Prefix1:
+ pKbd->scanPrefix = *scanCode; /* special prefixes */
+ return TRUE;
+ }
+ if (!xf86IsPc98()) {
+ switch (*scanCode) {
+ case 0x59: *scanCode = KEY_0x59; break;
+ case 0x5a: *scanCode = KEY_0x5A; break;
+ case 0x5b: *scanCode = KEY_0x5B; break;
+ case 0x5c: *scanCode = KEY_KP_Equal; break; /* Keypad Equal */
+ case 0x5d: *scanCode = KEY_0x5D; break;
+ case 0x5e: *scanCode = KEY_0x5E; break;
+ case 0x5f: *scanCode = KEY_0x5F; break;
+ case 0x62: *scanCode = KEY_0x62; break;
+ case 0x63: *scanCode = KEY_0x63; break;
+ case 0x64: *scanCode = KEY_0x64; break;
+ case 0x65: *scanCode = KEY_0x65; break;
+ case 0x66: *scanCode = KEY_0x66; break;
+ case 0x67: *scanCode = KEY_0x67; break;
+ case 0x68: *scanCode = KEY_0x68; break;
+ case 0x69: *scanCode = KEY_0x69; break;
+ case 0x6a: *scanCode = KEY_0x6A; break;
+ case 0x6b: *scanCode = KEY_0x6B; break;
+ case 0x6c: *scanCode = KEY_0x6C; break;
+ case 0x6d: *scanCode = KEY_0x6D; break;
+ case 0x6e: *scanCode = KEY_0x6E; break;
+ case 0x6f: *scanCode = KEY_0x6F; break;
+ case 0x70: *scanCode = KEY_0x70; break;
+ case 0x71: *scanCode = KEY_0x71; break;
+ case 0x72: *scanCode = KEY_0x72; break;
+ case 0x73: *scanCode = KEY_0x73; break;
+ case 0x74: *scanCode = KEY_0x74; break;
+ case 0x75: *scanCode = KEY_0x75; break;
+ case 0x76: *scanCode = KEY_0x76; break;
+ }
+ }
+ break;
+ case KEY_Prefix0:
+ pKbd->scanPrefix = 0;
+ switch (*scanCode) {
+ case KEY_KP_7: *scanCode = KEY_Home; break; /* curs home */
+ case KEY_KP_8: *scanCode = KEY_Up; break; /* curs up */
+ case KEY_KP_9: *scanCode = KEY_PgUp; break; /* curs pgup */
+ case KEY_KP_4: *scanCode = KEY_Left; break; /* curs left */
+ case KEY_KP_5: *scanCode = KEY_Begin; break; /* curs begin */
+ case KEY_KP_6: *scanCode = KEY_Right; break; /* curs right */
+ case KEY_KP_1: *scanCode = KEY_End; break; /* curs end */
+ case KEY_KP_2: *scanCode = KEY_Down; break; /* curs down */
+ case KEY_KP_3: *scanCode = KEY_PgDown; break; /* curs pgdown */
+ case KEY_KP_0: *scanCode = KEY_Insert; break; /* curs insert */
+ case KEY_KP_Decimal: *scanCode = KEY_Delete; break; /* curs delete */
+ case KEY_Enter: *scanCode = KEY_KP_Enter; break; /* keypad enter */
+ case KEY_LCtrl: *scanCode = KEY_RCtrl; break; /* right ctrl */
+ case KEY_KP_Multiply: *scanCode = KEY_Print; break; /* print */
+ case KEY_Slash: *scanCode = KEY_KP_Divide; break; /* keyp divide */
+ case KEY_Alt: *scanCode = KEY_AltLang; break; /* right alt */
+ case KEY_ScrollLock: *scanCode = KEY_Break; break; /* curs break */
+ case 0x5b: *scanCode = KEY_LMeta; break;
+ case 0x5c: *scanCode = KEY_RMeta; break;
+ case 0x5d: *scanCode = KEY_Menu; break;
+ case KEY_F3: *scanCode = KEY_F13; break;
+ case KEY_F4: *scanCode = KEY_F14; break;
+ case KEY_F5: *scanCode = KEY_F15; break;
+ case KEY_F6: *scanCode = KEY_F16; break;
+ case KEY_F7: *scanCode = KEY_F17; break;
+ case KEY_KP_Plus: *scanCode = KEY_KP_DEC; break;
+ case 0x2A:
+ case 0x36:
+ return TRUE;
+ default:
+ xf86MsgVerb(X_INFO, 4, "Unreported Prefix0 scancode: 0x%02x\n",
+ *scanCode);
+ *scanCode += 0x78;
+ }
+ break;
+ case KEY_Prefix1:
+ pKbd->scanPrefix = (*scanCode == KEY_LCtrl) ? KEY_LCtrl : 0;
+ return TRUE;
+ case KEY_LCtrl:
+ pKbd->scanPrefix = 0;
+ if (*scanCode != KEY_NumLock)
+ return TRUE;
+ *scanCode = KEY_Pause; /* pause */
+ }
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/bios_devmem.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/bios_devmem.c
new file mode 100644
index 000000000..8bd6d3f3e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/bios_devmem.c
@@ -0,0 +1,77 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/bios_devmem.c,v 3.5 1998/09/13 00:51:32 dawes Exp $ */
+/*
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: bios_devmem.c /main/5 1996/10/19 18:07:41 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include <string.h>
+
+/*
+ * Read BIOS via /dev/mem.
+ */
+
+#ifndef DEV_MEM
+# define DEV_MEM "/dev/mem"
+#endif
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+ int fd;
+
+#ifdef __ia64__
+ if ((fd = open(DEV_MEM, O_RDONLY | O_SYNC)) < 0)
+#else
+ if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
+#endif
+ {
+ xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ return(-1);
+ }
+
+ if (lseek(fd, (Base+Offset), SEEK_SET) < 0)
+ {
+ xf86Msg(X_WARNING, "xf86ReadBIOS: %s seek failed (%s)\n",
+ DEV_MEM, strerror(errno));
+ close(fd);
+ return(-1);
+ }
+ if (read(fd, Buf, Len) != Len)
+ {
+ xf86Msg(X_WARNING, "xf86ReadBIOS: %s read failed (%s)\n",
+ DEV_MEM, strerror(errno));
+ close(fd);
+ return(-1);
+ }
+ close(fd);
+ return(Len);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/bios_mmap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/bios_mmap.c
new file mode 100644
index 000000000..b4ff8c31f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/bios_mmap.c
@@ -0,0 +1,164 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/bios_mmap.c,v 1.8 2000/11/19 16:38:06 tsi Exp $ */
+/*
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: bios_V4mmap.c /main/4 1996/02/21 17:54:27 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+/*
+ * Read BIOS via mmap()ing DEV_MEM
+ */
+
+#ifndef __alpha__
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+ int fd;
+ unsigned char *ptr;
+ int psize;
+ int mlen;
+
+ if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
+ {
+ xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ return(-1);
+ }
+ psize = xf86getpagesize();
+ Offset += Base & (psize - 1);
+ Base &= ~(psize - 1);
+ mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+ ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ,
+ MAP_SHARED, fd, (off_t)Base);
+ if (ptr == MAP_FAILED)
+ {
+ xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed (%s)\n",
+ DEV_MEM, strerror(errno));
+ close(fd);
+ return(-1);
+ }
+#ifdef DEBUG
+ ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
+ Base, ptr[0] | (ptr[1] << 8));
+#endif
+ (void)memcpy(Buf, (void *)(ptr + Offset), Len);
+ (void)munmap((caddr_t)ptr, mlen);
+ (void)close(fd);
+ return(Len);
+}
+
+#else /* __alpha__ */
+
+ /*
+ * We trick "mmap" into mapping BUS memory for us via BUS_BASE,
+ * which is the KSEG address of the start of the DENSE memory
+ * area.
+ */
+
+ /*
+ * NOTE: there prolly ought to be more validity checks and all
+ * re: boundaries and sizes and such...
+ */
+
+/*
+ * The Jensen lacks dense memory, thus we have to address the bus via
+ * the sparse addressing scheme.
+ *
+ * Martin Ostermann (ost@comnets.rwth-aachen.de) - Apr.-Sep. 1996
+ */
+
+#ifdef linux
+
+#ifdef TEST_JENSEN_CODE /* define to test the Sparse addressing on a non-Jensen */
+#define SPARSE (5)
+#define isJensen (1)
+#else
+#define isJensen (!_bus_base())
+#define SPARSE (7)
+#endif
+
+extern unsigned long _bus_base(void);
+extern unsigned long _bus_base_sparse(void);
+#define BUS_BASE (isJensen ? _bus_base_sparse() : _bus_base())
+#define JENSEN_SHIFT(x) (isJensen ? ((long)x<<SPARSE) : (long)x)
+
+#else
+
+extern u_int64_t dense_base(void);
+#define BUS_BASE dense_base()
+#define JENSEN_SHIFT(x) ((long) x)
+
+#endif
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+ caddr_t base;
+ int fd;
+ int psize;
+ int mlen;
+
+ if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
+ {
+ xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ return(-1);
+ }
+
+ psize = xf86getpagesize();
+ Offset += Base & (psize - 1);
+ Base &= ~(psize - 1);
+ mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+ base = mmap((caddr_t)0, JENSEN_SHIFT(mlen), PROT_READ,
+ MAP_SHARED, fd, (off_t)(JENSEN_SHIFT(Base) + BUS_BASE));
+
+ if (base == MAP_FAILED)
+ {
+ xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to mmap %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ return(-1);
+ }
+
+ xf86SlowBCopyFromBus((unsigned char *)(base+JENSEN_SHIFT(Offset)),
+ Buf, Len);
+
+ munmap((caddr_t)JENSEN_SHIFT(base), JENSEN_SHIFT(mlen));
+ close(fd);
+ return(Len);
+}
+
+#endif /* __alpha__ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ia64Pci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ia64Pci.c
new file mode 100644
index 000000000..ff4312bf5
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ia64Pci.c
@@ -0,0 +1,244 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/ia64Pci.c,v 1.3 2003/02/23 20:26:49 tsi Exp $ */
+/*
+ * Copyright (C) 2002-2003 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, 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
+ * XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+
+/*
+ * This file contains the glue needed to support various IA-64 chipsets.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <linux/pci.h>
+
+#include "compiler.h"
+#include "460gxPCI.h"
+#include "e8870PCI.h"
+#include "zx1PCI.h"
+#include "altixPCI.h"
+#include "Pci.h"
+#include "ia64Pci.h"
+
+/*
+ * We use special in/out routines here since Altix platforms require the
+ * use of the sysfs legacy_io interface. The legacy_io file maps to the I/O
+ * space of a given PCI domain; reads and writes are used to do port I/O.
+ * The file descriptor for the file is stored in the upper bits of the
+ * value passed in by the caller, and is created and populated by
+ * xf86MapDomainIO.
+ *
+ * If the legacy_io interface doesn't exist, we fall back to the glibc in/out
+ * routines, which are prefixed by an underscore (e.g. _outb).
+ */
+static int ia64_port_to_fd(unsigned long port)
+{
+ return (port >> 24) & 0xffffffff;
+}
+
+void outb(unsigned long port, unsigned char val)
+{
+ int fd = ia64_port_to_fd(port);
+
+ if (!fd) {
+ _outb(val, port & 0xffff);
+ goto out;
+ }
+ if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
+ ErrorF("I/O lseek failed\n");
+ goto out;
+ }
+ if (write(fd, &val, 1) != 1) {
+ ErrorF("I/O write failed\n");
+ goto out;
+ }
+ out:
+ return;
+}
+
+void outw(unsigned long port, unsigned short val)
+{
+ int fd = ia64_port_to_fd(port);
+
+ if (!fd) {
+ _outw(val, port & 0xffff);
+ goto out;
+ }
+ if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
+ ErrorF("I/O lseek failed\n");
+ goto out;
+ }
+ if (write(fd, &val, 2) != 2) {
+ ErrorF("I/O write failed\n");
+ goto out;
+ }
+ out:
+ return;
+}
+
+void outl(unsigned long port, unsigned int val)
+{
+ int fd = ia64_port_to_fd(port);
+
+ if (!fd) {
+ _outl(val, port & 0xffff);
+ goto out;
+ }
+ if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
+ ErrorF("I/O lseek failed\n");
+ goto out;
+ }
+ if (write(fd, &val, 4) != 4) {
+ ErrorF("I/O write failed\n");
+ goto out;
+ }
+ out:
+ return;
+}
+
+unsigned int inb(unsigned long port)
+{
+ int fd = ia64_port_to_fd(port);
+ unsigned char val;
+
+ if (!fd)
+ return _inb(port & 0xffff);
+
+ if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
+ ErrorF("I/O lseek failed\n");
+ val = -1;
+ goto out;
+ }
+ if (read(fd, &val, 1) != 1) {
+ ErrorF("I/O read failed\n");
+ val = -1;
+ goto out;
+ }
+ out:
+ return val;
+}
+
+unsigned int inw(unsigned long port)
+{
+ int fd = ia64_port_to_fd(port);
+ unsigned short val;
+
+ if (!fd)
+ return _inw(port & 0xffff);
+
+ if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
+ ErrorF("I/O lseek failed\n");
+ val = -1;
+ goto out;
+ }
+ if (read(fd, &val, 2) != 2) {
+ ErrorF("I/O read failed\n");
+ val = -1;
+ goto out;
+ }
+ out:
+ return val;
+}
+
+unsigned int inl(unsigned long port)
+{
+ int fd = ia64_port_to_fd(port);
+ unsigned int val;
+
+ if (!fd)
+ return _inl(port & 0xffff);
+
+ if (lseek(fd, port & 0xffff, SEEK_SET) == -1) {
+ ErrorF("I/O lseek failed\n");
+ val = -1;
+ goto out;
+ }
+ if (read(fd, &val, 4) != 4) {
+ ErrorF("I/O read failed\n");
+ val = -1;
+ goto out;
+ }
+ out:
+ return val;
+}
+
+void
+ia64ScanPCIWrapper(scanpciWrapperOpt flags)
+{
+ static IA64Chipset chipset = NONE_CHIPSET;
+
+ if (flags == SCANPCI_INIT) {
+
+ /* PCI configuration space probes should be done first */
+ if (xorgProbe460GX(flags)) {
+ chipset = I460GX_CHIPSET;
+ xf86PreScan460GX();
+ return;
+ } else if (xorgProbeE8870(flags)) {
+ chipset = E8870_CHIPSET;
+ xf86PreScanE8870();
+ return;
+ }
+#ifdef OS_PROBE_PCI_CHIPSET
+ chipset = OS_PROBE_PCI_CHIPSET(flags);
+ switch (chipset) {
+ case ZX1_CHIPSET:
+ xf86PreScanZX1();
+ return;
+ case ALTIX_CHIPSET:
+ xf86PreScanAltix();
+ return;
+ default:
+ return;
+ }
+#endif
+ } else /* if (flags == SCANPCI_TERM) */ {
+
+ switch (chipset) {
+ case I460GX_CHIPSET:
+ xf86PostScan460GX();
+ return;
+ case E8870_CHIPSET:
+ xf86PostScanE8870();
+ return;
+ case ZX1_CHIPSET:
+ xf86PostScanZX1();
+ return;
+ case ALTIX_CHIPSET:
+ xf86PostScanAltix();
+ return;
+ default:
+ return;
+ }
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ia64Pci.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ia64Pci.h
new file mode 100644
index 000000000..978c9ff0e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ia64Pci.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004, Egbert Eich
+ *
+ * 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
+ * EGBERT EICH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+ * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Egbert Eich shall not
+ * be used in advertising or otherwise to promote the sale, use or other deal-
+ *ings in this Software without prior written authorization from Egbert Eich.
+ *
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _IA64_PCI_H
+# define _IA64_PCI_H
+
+#include "Pci.h"
+
+typedef enum {
+ NONE_CHIPSET,
+ I460GX_CHIPSET,
+ E8870_CHIPSET,
+ ZX1_CHIPSET,
+ ALTIX_CHIPSET
+} IA64Chipset;
+
+# ifdef OS_PROBE_PCI_CHIPSET
+extern IA64Chipset OS_PROBE_PCI_CHIPSET(scanpciWrapperOpt flags);
+# endif
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/inout.S b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/inout.S
new file mode 100644
index 000000000..73a2cbbb6
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/inout.S
@@ -0,0 +1,111 @@
+/* $XConsortium: inout.s /main/6 1996/02/21 17:53:35 kaleb $ */
+
+
+
+
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/inout.s,v 3.5 1996/12/23 06:50:58 dawes Exp $ */
+
+#include "assyntax.h"
+
+/*
+ * Make i80386 io primitives available at C-level.
+ */
+
+ FILE("inout.s")
+ AS_BEGIN
+ SEG_TEXT
+
+/*
+ *-----------------------------------------------------------------------
+ * inb ---
+ * Input one byte.
+ *
+ * Results:
+ * Byte in al.
+ *-----------------------------------------------------------------------
+ */
+ GLOBL GLNAME(inb)
+GLNAME(inb):
+ MOV_L (REGOFF(4,ESP),EDX)
+ SUB_L (EAX,EAX)
+ IN_B
+ RET
+
+/*
+ *-----------------------------------------------------------------------
+ * outb ---
+ * Output one byte.
+ *
+ * Results:
+ * None.
+ *-----------------------------------------------------------------------
+ */
+ GLOBL GLNAME(outb)
+GLNAME(outb):
+ MOV_L (REGOFF(4,sp),EDX)
+ MOV_L (REGOFF(8,sp),EAX)
+ OUT_B
+ RET
+/*
+ *-----------------------------------------------------------------------
+ * inw ---
+ * Input one 16-bit word.
+ *
+ * Results:
+ * Word in ax.
+ *-----------------------------------------------------------------------
+ */
+ GLOBL GLNAME(inw)
+GLNAME(inw):
+ MOV_L (REGOFF(4,ESP),EDX)
+ IN_W
+ RET
+
+/*
+ *-----------------------------------------------------------------------
+ * outw ---
+ * Output one 16-bit word.
+ *
+ * Results:
+ * None.
+ *-----------------------------------------------------------------------
+ */
+ GLOBL GLNAME(outw)
+GLNAME(outw):
+ MOV_L (REGOFF(4,ESP),EDX)
+ MOV_L (REGOFF(8,ESP),EAX)
+ OUT_W
+ RET
+
+/*
+ *-----------------------------------------------------------------------
+ * inl ---
+ * Input one 32-bit longword.
+ *
+ * Results:
+ * Word in eax.
+ *-----------------------------------------------------------------------
+ */
+ GLOBL GLNAME(inl)
+GLNAME(inl):
+ MOV_L (REGOFF(4,ESP),EDX)
+ IN_L
+ RET
+
+/*
+ *-----------------------------------------------------------------------
+ * outl ---
+ * Output one 32-bit longword.
+ *
+ * Results:
+ * None.
+ *-----------------------------------------------------------------------
+ */
+ GLOBL GLNAME(outl)
+GLNAME(outl):
+ MOV_L (REGOFF(4,ESP),EDX)
+ MOV_L (REGOFF(8,ESP),EAX)
+ OUT_L
+ RET
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c
new file mode 100644
index 000000000..b3ea044f9
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c
@@ -0,0 +1,51 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/ioperm_noop.c,v 3.3 1998/07/25 16:57:00 dawes Exp $ */
+/*
+ * Copyright 1993 by David Wexelblat <dwex@XFree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: ioperm_noop.c /main/3 1996/02/21 17:53:39 kaleb $ */
+
+/*
+ * Some platforms don't bother with I/O permissions,
+ * or the permissions are implicit with opening/enabling the console.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+Bool
+xf86EnableIO()
+{
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ return;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/kbd.c
new file mode 100644
index 000000000..822c8fe52
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/kbd.c
@@ -0,0 +1,39 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/kbd.c,v 1.3 2003/08/24 17:37:05 dawes Exp $ */
+/*
+ * Copyright (c) 2001-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
+
+#include "xf86OSKbd.h"
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/kmod_noop.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/kmod_noop.c
new file mode 100644
index 000000000..620e9bf35
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/kmod_noop.c
@@ -0,0 +1,39 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/kmod_noop.c,v 1.2 2003/08/24 17:37:05 dawes Exp $ */
+/*
+ * Copyright (c) 2000 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
+
+#include "xf86_OSproc.h"
+
+int xf86LoadKernelModule(const char *pathname)
+{
+ (void) pathname;
+ return 0; /* failure */
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/libc_wrapper.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/libc_wrapper.c
new file mode 100644
index 000000000..aba445945
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/libc_wrapper.c
@@ -0,0 +1,2153 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/libc_wrapper.c,v 1.102 2003/11/19 03:52:58 dawes Exp $ */
+/*
+ * Copyright 1997-2003 by The XFree86 Project, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Orest Zborowski and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Orest Zborowski
+ * and David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THE XFREE86 PROJECT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#if defined(linux) && !defined(__GLIBC__)
+#undef __STRICT_ANSI__
+#endif
+#include <X11/X.h>
+#ifdef __UNIXOS2__
+#define I_NEED_OS2_H
+#endif
+#include <X11/Xmd.h>
+#include <X11/Xos.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#if defined(__bsdi__)
+#undef _POSIX_SOURCE
+#undef _ANSI_SOURCE
+#endif
+#include <sys/time.h>
+#include <math.h>
+#ifdef sun
+#include <ieeefp.h>
+#endif
+#include <stdarg.h>
+#include <fcntl.h>
+#include <X11/Xfuncproto.h>
+#include "os.h"
+#include <ctype.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#ifdef __UNIXOS2__
+#define NO_MMAP
+#include <sys/param.h>
+#endif
+#ifdef HAS_SVR3_MMAPDRV
+#define NO_MMAP
+#ifdef SELF_CONTAINED_WRAPPER
+#include <sys/at_ansi.h>
+#include <sys/kd.h>
+#include <sys/sysmacros.h>
+#if !defined(_NEED_SYSI86)
+# include <sys/immu.h>
+# include <sys/region.h>
+#endif
+#include <sys/mmap.h>
+struct kd_memloc MapDSC;
+int mmapFd = -2;
+#else
+extern struct kd_memloc MapDSC;
+extern int mmapFd;
+#endif
+#endif
+#ifndef NO_MMAP
+#include <sys/mman.h>
+#ifndef MAP_FAILED
+#define MAP_FAILED ((caddr_t)-1)
+#endif
+#endif
+#if !defined(ISC)
+#include <stdlib.h>
+#endif
+
+#define NEED_XF86_TYPES
+#define NEED_XF86_PROTOTYPES
+#define DONT_DEFINE_WRAPPERS
+#include "xf86_ansic.h"
+
+#ifndef SELF_CONTAINED_WRAPPER
+#include "xf86.h"
+#include "xf86Priv.h"
+#define NO_OSLIB_PROTOTYPES
+#define XF86_OS_PRIVS
+#define HAVE_WRAPPER_DECLS
+#include "xf86_OSlib.h"
+#else
+void xf86WrapperInit(void);
+#endif
+
+
+#ifndef X_NOT_POSIX
+#include <dirent.h>
+#else
+#ifdef SYSV
+#include <dirent.h>
+#else
+#ifdef USG
+#include <dirent.h>
+#else
+#include <sys/dir.h>
+#ifndef dirent
+#define dirent direct
+#endif
+#endif
+#endif
+#endif
+typedef struct dirent DIRENTRY;
+
+#ifdef __UNIXOS2__
+#define _POSIX_SOURCE
+#endif
+#ifdef ISC202
+#include <sys/types.h>
+#define WIFEXITED(a) ((a & 0x00ff) == 0) /* LSB will be 0 */
+#define WEXITSTATUS(a) ((a & 0xff00) >> 8)
+#define WIFSIGNALED(a) ((a & 0xff00) == 0) /* MSB will be 0 */
+#define WTERMSIG(a) (a & 0x00ff)
+#else
+#if defined(ISC) && !defined(_POSIX_SOURCE)
+#define _POSIX_SOURCE
+#include <sys/types.h>
+#include <sys/wait.h>
+#undef _POSIX_SOURCE
+#else
+#if (defined(ISC) && defined(_POSIX_SOURCE)) || defined(Lynx) || (defined (__alpha__) && defined(linux))
+#include <sys/types.h>
+#endif
+#include <sys/wait.h>
+#endif
+#endif
+#ifdef Lynx
+#if !defined(S_IFIFO) && defined(S_IFFIFO)
+#define S_IFIFO S_IFFIFO
+#endif
+#endif
+
+/* For xf86getpagesize() */
+#if defined(linux)
+#define HAS_SC_PAGESIZE
+#define HAS_GETPAGESIZE
+#elif defined(CSRG_BASED)
+#define HAS_GETPAGESIZE
+#elif defined(DGUX)
+#define HAS_GETPAGESIZE
+#elif defined(sun) && !defined(SVR4)
+#define HAS_GETPAGESIZE
+#endif
+#ifdef XNO_SYSCONF
+#undef _SC_PAGESIZE
+#endif
+#ifdef HAVE_SYSV_IPC
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#endif
+#include <setjmp.h>
+
+#if defined(setjmp) && defined(__GNU_LIBRARY__) && \
+ (!defined(__GLIBC__) || (__GLIBC__ < 2) || \
+ ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 3)))
+#define HAS_GLIBC_SIGSETJMP 1
+#endif
+
+#if 0
+#define SETBUF_RETURNS_INT
+#endif
+
+double xf86HUGE_VAL;
+
+#ifndef SELF_CONTAINED_WRAPPERS
+extern void xf86DisableIO(void);
+#endif
+
+/*
+ * This file contains the XFree86 wrappers for libc functions that can be
+ * called by loadable modules
+ */
+
+double
+xf86hypot(double x, double y)
+{
+ return(hypot(x,y));
+}
+
+void
+xf86qsort(void *base, xf86size_t nmemb, xf86size_t size,
+ int (*comp)(const void *, const void *))
+{
+ qsort(base, nmemb, size, comp);
+}
+
+/* string functions */
+
+char*
+xf86strcat(char* dest, const char* src)
+{
+ return(strcat(dest,src));
+}
+
+char*
+xf86strchr(const char* s, int c)
+{
+ return strchr(s,c);
+}
+
+int
+xf86strcmp(const char* s1, const char* s2)
+{
+ return strcmp(s1,s2);
+}
+
+/* Just like the BSD version. It assumes that tolower() is ANSI-compliant */
+int
+xf86strcasecmp(const char* s1, const char* s2)
+{
+ const unsigned char *us1 = (const unsigned char *)s1;
+ const unsigned char *us2 = (const unsigned char *)s2;
+
+ while (tolower(*us1) == tolower(*us2++))
+ if (*us1++ == '\0')
+ return 0;
+
+ return tolower(*us1) - tolower(*--us2);
+}
+
+char*
+xf86strcpy(char* dest, const char* src)
+{
+ return strcpy(dest,src);
+}
+
+xf86size_t
+xf86strcspn(const char* s1, const char* s2)
+{
+ return (xf86size_t)strcspn(s1,s2);
+}
+
+xf86size_t
+xf86strlen(const char* s)
+{
+ return (xf86size_t)strlen(s);
+}
+
+xf86size_t
+xf86strlcat(char *dest, const char *src, xf86size_t size)
+{
+ return(strlcat(dest, src, size));
+}
+
+xf86size_t
+xf86strlcpy(char *dest, const char *src, xf86size_t size)
+{
+ return strlcpy(dest, src, size);
+}
+
+char*
+xf86strncat(char* dest, const char* src, xf86size_t n)
+{
+ return strncat(dest,src,(size_t)n);
+}
+
+int
+xf86strncmp(const char* s1, const char* s2, xf86size_t n)
+{
+ return strncmp(s1,s2,(size_t)n);
+}
+
+/* Just like the BSD version. It assumes that tolower() is ANSI-compliant */
+int
+xf86strncasecmp(const char* s1, const char* s2, xf86size_t n)
+{
+ if (n != 0) {
+ const unsigned char *us1 = (const unsigned char *)s1;
+ const unsigned char *us2 = (const unsigned char *)s2;
+
+ do {
+ if (tolower(*us1) != tolower(*us2++))
+ return tolower(*us1) - tolower(*--us2);
+ if (*us1++ == '\0')
+ break;
+ } while (--n != 0);
+ }
+ return 0;
+}
+
+char*
+xf86strncpy(char* dest, const char* src, xf86size_t n)
+{
+ return strncpy(dest,src,(size_t)n);
+}
+
+char*
+xf86strpbrk(const char* s1, const char* s2)
+{
+ return strpbrk(s1,s2);
+}
+
+char*
+xf86strrchr(const char* s, int c)
+{
+ return strrchr(s,c);
+}
+
+xf86size_t
+xf86strspn(const char* s1, const char* s2)
+{
+ return strspn(s1,s2);
+}
+
+char*
+xf86strstr(const char* s1, const char* s2)
+{
+ return strstr(s1,s2);
+}
+
+char*
+xf86strtok(char* s1, const char* s2)
+{
+ return strtok(s1,s2);
+}
+
+char*
+xf86strdup(const char* s)
+{
+ return xstrdup(s);
+}
+
+int
+xf86sprintf(char *s, const char *format, ...)
+{
+ int ret;
+ va_list args;
+ va_start(args, format);
+ ret = vsprintf(s, format, args);
+ va_end(args);
+ return ret;
+}
+
+int
+xf86snprintf(char *s, xf86size_t len, const char *format, ...)
+{
+ int ret;
+ va_list args;
+ va_start(args, format);
+ ret = vsnprintf(s, (size_t)len, format, args);
+ va_end(args);
+ return ret;
+}
+
+void
+xf86bzero(void* s, unsigned int n)
+{
+ memset(s, 0, n);
+}
+
+#ifdef HAVE_VSSCANF
+int
+xf86sscanf(char *s, const char *format, ...)
+#else
+int
+xf86sscanf(char *s, const char *format, char *a0, char *a1, char *a2,
+ char *a3, char *a4, char *a5, char *a6, char *a7, char *a8,
+ char *a9) /* limit of ten args */
+#endif
+{
+#ifdef HAVE_VSSCANF
+ int ret;
+ va_list args;
+ va_start(args, format);
+
+ ret = vsscanf(s,format,args);
+ va_end(args);
+ return ret;
+#else
+ return sscanf(s, format, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
+#endif
+}
+
+/* Basic I/O */
+
+int xf86errno;
+
+/* XXX This is not complete */
+
+static int
+xfToOsOpenFlags(int xfflags)
+{
+ int flags = 0;
+
+ /* XXX This assumes O_RDONLY is 0 */
+ if (xfflags & XF86_O_WRONLY)
+ flags |= O_WRONLY;
+ if (xfflags & XF86_O_RDWR)
+ flags |= O_RDWR;
+ if (xfflags & XF86_O_CREAT)
+ flags |= O_CREAT;
+
+ return flags;
+}
+
+int
+xf86open(const char *path, int flags, ...)
+{
+ int fd;
+ va_list ap;
+
+ va_start(ap, flags);
+ flags = xfToOsOpenFlags(flags);
+ if (flags & O_CREAT) {
+ /* can't request a mode_t directly on systems where mode_t
+ is an unsigned short */
+ mode_t mode = (mode_t)va_arg(ap, unsigned int);
+ fd = open(path, flags, mode);
+ } else {
+ fd = open(path, flags);
+ }
+ va_end(ap);
+ xf86errno = xf86GetErrno();
+
+ return fd;
+}
+
+int
+xf86close(int fd)
+{
+ int status = close(fd);
+
+ xf86errno = xf86GetErrno();
+ return status;
+}
+
+long
+xf86lseek(int fd, long offset, int whence)
+{
+ switch (whence) {
+ case XF86_SEEK_SET:
+ whence = SEEK_SET;
+ break;
+ case XF86_SEEK_CUR:
+ whence = SEEK_CUR;
+ break;
+ case XF86_SEEK_END:
+ whence = SEEK_END;
+ break;
+ }
+ return (long)lseek(fd, (off_t)offset, whence);
+}
+
+int
+xf86ioctl(int fd, unsigned long request, pointer argp)
+{
+ int status = ioctl(fd, request, argp);
+
+ xf86errno = xf86GetErrno();
+ return status;
+}
+
+xf86ssize_t
+xf86read(int fd, void *buf, xf86size_t nbytes)
+{
+ xf86ssize_t n = read(fd, buf, (size_t)nbytes);
+
+ xf86errno = xf86GetErrno();
+ return n;
+}
+
+xf86ssize_t
+xf86write(int fd, const void *buf, xf86size_t nbytes)
+{
+ xf86ssize_t n = write(fd, buf, (size_t)nbytes);
+
+ xf86errno = xf86GetErrno();
+ return n;
+}
+
+void*
+xf86mmap(void *start, xf86size_t length, int prot,
+ int flags, int fd, xf86size_t /* off_t */ offset)
+{
+#ifndef NO_MMAP
+ int p=0, f=0;
+ void *rc;
+
+ if (flags & XF86_MAP_FIXED) f |= MAP_FIXED;
+ if (flags & XF86_MAP_SHARED) f |= MAP_SHARED;
+ if (flags & XF86_MAP_PRIVATE) f |= MAP_PRIVATE;
+#if defined(__amd64__) && defined(linux)
+ if (flags & XF86_MAP_32BIT) f |= MAP_32BIT;
+#endif
+ if (prot & XF86_PROT_EXEC) p |= PROT_EXEC;
+ if (prot & XF86_PROT_READ) p |= PROT_READ;
+ if (prot & XF86_PROT_WRITE) p |= PROT_WRITE;
+ if (prot & XF86_PROT_NONE) p |= PROT_NONE;
+
+ rc = mmap(start,(size_t)length,p,f,fd,(off_t)offset);
+
+ xf86errno = xf86GetErrno();
+ if (rc == MAP_FAILED)
+ return XF86_MAP_FAILED;
+ else
+ return rc;
+#else
+#ifdef HAS_SVR3_MMAPDRV
+ void *rc;
+#ifdef SELF_CONTAINED_WRAPPER
+ if(mmapFd < 0) {
+ if ((mmapFd = open("/dev/mmap", O_RDWR)) == -1) {
+ ErrorF("Warning: failed to open /dev/mmap \n");
+ xf86errno = xf86_ENOSYS;
+ return XF86_MAP_FAILED;
+ }
+ }
+#endif
+ MapDSC.vaddr = (char *)start;
+ MapDSC.physaddr = (char *)offset;
+ MapDSC.length = length;
+ MapDSC.ioflg = 1;
+
+ rc = (pointer)ioctl(mmapFd, MAP, &MapDSC);
+ xf86errno = xf86GetErrno();
+ if (rc == NULL)
+ return XF86_MAP_FAILED;
+ else
+ return rc;
+#else
+ ErrorF("Warning: mmap() is not supported on this platform\n");
+ xf86errno = xf86_ENOSYS;
+ return XF86_MAP_FAILED;
+#endif
+#endif
+}
+
+int
+xf86munmap(void *start, xf86size_t length)
+{
+#ifndef NO_MMAP
+ int rc = munmap(start,(size_t)length);
+
+ xf86errno = xf86GetErrno();
+ return rc;
+#else
+#ifdef HAS_SVR3_MMAPDRV
+ int rc = ioctl(mmapFd, UNMAPRM , start);
+
+ xf86errno = xf86GetErrno();
+ return rc;
+#else
+ ErrorF("Warning: munmap() is not supported on this platform\n");
+ xf86errno = xf86_ENOSYS;
+ return -1;
+#endif
+#endif
+}
+
+int
+xf86stat(const char *file_name, struct xf86stat *xfst)
+{
+ int rc;
+ struct stat st;
+
+ rc = stat(file_name, &st);
+ xf86errno = xf86GetErrno();
+ xfst->st_rdev = st.st_rdev; /* Not much is currently supported */
+ return rc;
+}
+
+int
+xf86fstat(int fd, struct xf86stat *xfst)
+{
+ int rc;
+ struct stat st;
+
+ rc = fstat(fd, &st);
+ xf86errno = xf86GetErrno();
+ xfst->st_rdev = st.st_rdev; /* Not much is currently supported */
+ return rc;
+}
+
+static int
+xfToOsAccessMode(int xfmode)
+{
+ switch(xfmode) {
+ case XF86_R_OK: return R_OK;
+ case XF86_W_OK: return W_OK;
+ case XF86_X_OK: return X_OK;
+ case XF86_F_OK: return F_OK;
+ }
+ return 0;
+}
+
+int
+xf86access(const char *pathname, int mode)
+{
+ int rc;
+
+ mode = xfToOsAccessMode(mode);
+ rc = access(pathname, mode);
+ xf86errno = xf86GetErrno();
+ return rc;
+}
+
+
+
+/* limited stdio support */
+
+#define XF86FILE_magic 0x58464856 /* "XFHV" */
+
+typedef struct _xf86_file_ {
+ INT32 fileno;
+ INT32 magic;
+ FILE* filehnd;
+ char* fname;
+} XF86FILE_priv;
+
+XF86FILE_priv stdhnd[3] = {
+ { 0, XF86FILE_magic, NULL, "$stdinp$" },
+ { 0, XF86FILE_magic, NULL, "$stdout$" },
+ { 0, XF86FILE_magic, NULL, "$stderr$" }
+};
+
+XF86FILE* xf86stdin = (XF86FILE*)&stdhnd[0];
+XF86FILE* xf86stdout = (XF86FILE*)&stdhnd[1];
+XF86FILE* xf86stderr = (XF86FILE*)&stdhnd[2];
+
+void
+xf86WrapperInit()
+{
+ if (stdhnd[0].filehnd == NULL)
+ stdhnd[0].filehnd = stdin;
+ if (stdhnd[1].filehnd == NULL)
+ stdhnd[1].filehnd = stdout;
+ if (stdhnd[2].filehnd == NULL)
+ stdhnd[2].filehnd = stderr;
+ xf86HUGE_VAL = HUGE_VAL;
+}
+
+XF86FILE*
+xf86fopen(const char* fn, const char* mode)
+{
+ XF86FILE_priv* fp;
+ FILE *f = fopen(fn,mode);
+ xf86errno = xf86GetErrno();
+ if (!f) return 0;
+
+ fp = xalloc(sizeof(XF86FILE_priv));
+ fp->magic = XF86FILE_magic;
+ fp->filehnd = f;
+ fp->fileno = fileno(f);
+ fp->fname = xf86strdup(fn);
+#ifdef DEBUG
+ ErrorF("xf86fopen(%s,%s) yields FILE %p XF86FILE %p\n",
+ fn,mode,f,fp);
+#endif
+ return (XF86FILE*)fp;
+}
+
+static void _xf86checkhndl(XF86FILE_priv* f,const char *func)
+{
+ if (!f || f->magic != XF86FILE_magic ||
+ !f->filehnd || !f->fname) {
+ FatalError("libc_wrapper error: passed invalid FILE handle to %s",
+ func);
+ exit(42);
+ }
+}
+
+int
+xf86fclose(XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+ int ret;
+
+ _xf86checkhndl(fp,"xf86fclose");
+
+ /* somewhat bad check */
+ if (fp->fileno < 3 && fp->fname[0]=='$') {
+ /* assume this is stdin/out/err, don't dispose */
+ ret = fclose(fp->filehnd);
+ } else {
+ ret = fclose(fp->filehnd);
+ fp->magic = 0; /* invalidate */
+ xfree(fp->fname);
+ xfree(fp);
+ }
+ return ret ? -1 : 0;
+}
+
+int
+xf86printf(const char *format, ...)
+{
+ int ret;
+ va_list args;
+ va_start(args, format);
+
+ ret = printf(format,args);
+ va_end(args);
+ return ret;
+}
+
+int
+xf86fprintf(XF86FILE* f, const char *format, ...)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ int ret;
+ va_list args;
+ va_start(args, format);
+
+#ifdef DEBUG
+ ErrorF("xf86fprintf for XF86FILE %p\n", fp);
+#endif
+ _xf86checkhndl(fp,"xf86fprintf");
+
+ ret = vfprintf(fp->filehnd,format,args);
+ va_end(args);
+ return ret;
+}
+
+int
+xf86vfprintf(XF86FILE* f, const char *format, va_list ap)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+#ifdef DEBUG
+ ErrorF("xf86vfprintf for XF86FILE %p\n", fp);
+#endif
+ _xf86checkhndl(fp,"xf86vfprintf");
+
+ return vfprintf(fp->filehnd,format,ap);
+}
+
+int
+xf86vsprintf(char *s, const char *format, va_list ap)
+{
+ return vsprintf(s, format, ap);
+}
+
+int
+xf86vsnprintf(char *s, xf86size_t len, const char *format, va_list ap)
+{
+ return vsnprintf(s, (size_t)len, format, ap);
+}
+
+#ifdef HAVE_VFSCANF
+int
+xf86fscanf(XF86FILE* f, const char *format, ...)
+#else
+int
+xf86fscanf(XF86FILE* f, const char *format, char *a0, char *a1, char *a2,
+ char *a3, char *a4, char *a5, char *a6, char *a7, char *a8,
+ char *a9) /* limit of ten args */
+#endif
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+#ifdef HAVE_VFSCANF
+ int ret;
+ va_list args;
+ va_start(args, format);
+
+ _xf86checkhndl(fp,"xf86fscanf");
+
+ ret = vfscanf(fp->filehnd,format,args);
+ va_end(args);
+ return ret;
+#else
+ _xf86checkhndl(fp,"xf86fscanf");
+ return fscanf(fp->filehnd, format, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
+#endif
+}
+
+char *
+xf86fgets(char *buf, INT32 n, XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86fgets");
+ return fgets(buf,(int)n,fp->filehnd);
+}
+
+int
+xf86fputs(const char *buf, XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86fputs");
+ return fputs(buf,fp->filehnd);
+}
+
+int
+xf86getc(XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86getc");
+ return getc(fp->filehnd);
+}
+
+int
+xf86fgetc(XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86fgetc");
+ return fgetc(fp->filehnd);
+}
+
+int
+xf86fputc(int c,XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86fputc");
+ return fputc(c,fp->filehnd);
+}
+
+int
+xf86fflush(XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86fflush");
+ return fflush(fp->filehnd);
+}
+
+xf86size_t
+xf86fread(void* buf, xf86size_t sz, xf86size_t cnt, XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+#ifdef DEBUG
+ ErrorF("xf86fread for XF86FILE %p\n", fp);
+#endif
+ _xf86checkhndl(fp,"xf86fread");
+ return fread(buf,(size_t)sz,(size_t)cnt,fp->filehnd);
+}
+
+xf86size_t
+xf86fwrite(const void* buf, xf86size_t sz, xf86size_t cnt, XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86fwrite");
+ return fwrite(buf,(size_t)sz,(size_t)cnt,fp->filehnd);
+}
+
+int
+xf86fseek(XF86FILE* f, long offset, int whence)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86fseek");
+ switch (whence) {
+ case XF86_SEEK_SET:
+ whence = SEEK_SET;
+ break;
+ case XF86_SEEK_CUR:
+ whence = SEEK_CUR;
+ break;
+ case XF86_SEEK_END:
+ whence = SEEK_END;
+ break;
+ }
+ return fseek(fp->filehnd,offset,whence);
+}
+
+long
+xf86ftell(XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86ftell");
+ return ftell(fp->filehnd);
+}
+
+#define mapnum(e) case (xf86_##e): err = e; break;
+
+char*
+xf86strerror(int n)
+{
+ int err;
+
+ switch (n)
+ {
+ case 0: err = 0; break;
+ mapnum (EACCES);
+ mapnum (EAGAIN);
+ mapnum (EBADF);
+ mapnum (EEXIST);
+ mapnum (EFAULT);
+ mapnum (EINTR);
+ mapnum (EINVAL);
+ mapnum (EISDIR);
+ mapnum (ELOOP); /* not POSIX 1 */
+ mapnum (EMFILE);
+ mapnum (ENAMETOOLONG);
+ mapnum (ENFILE);
+ mapnum (ENOENT);
+ mapnum (ENOMEM);
+ mapnum (ENOSPC);
+ mapnum (ENOTDIR);
+ mapnum (EPIPE);
+ mapnum (EROFS);
+#ifndef __UNIXOS2__
+ mapnum (ETXTBSY); /* not POSIX 1 */
+#endif
+ mapnum (ENOTTY);
+#ifdef ENOSYS
+ mapnum (ENOSYS);
+#endif
+ mapnum (EBUSY);
+ mapnum (ENODEV);
+ mapnum (EIO);
+#ifdef ESRCH
+ mapnum (ESRCH);
+#endif
+#ifdef ENXIO
+ mapnum (ENXIO);
+#endif
+#ifdef E2BIG
+ mapnum (E2BIG);
+#endif
+#ifdef ENOEXEC
+ mapnum (ENOEXEC);
+#endif
+#ifdef ECHILD
+ mapnum (ECHILD);
+#endif
+#ifdef ENOTBLK
+ mapnum (ENOTBLK);
+#endif
+#ifdef EXDEV
+ mapnum (EXDEV);
+#endif
+#ifdef EFBIG
+ mapnum (EFBIG);
+#endif
+#ifdef ESPIPE
+ mapnum (ESPIPE);
+#endif
+#ifdef EMLINK
+ mapnum (EMLINK);
+#endif
+#ifdef EDOM
+ mapnum (EDOM);
+#endif
+#ifdef ERANGE
+ mapnum (ERANGE);
+#endif
+
+ default:
+ err = 999;
+ }
+ return strerror(err);
+}
+
+#undef mapnum
+
+
+/* required for portable fgetpos/fsetpos,
+ * use as
+ * XF86fpos_t* pos = xalloc(xf86fpossize());
+ */
+long
+xf86fpossize()
+{
+ return sizeof(fpos_t);
+}
+
+int
+xf86fgetpos(XF86FILE* f,XF86fpos_t* pos)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+ fpos_t *ppos = (fpos_t*)pos;
+
+ _xf86checkhndl(fp,"xf86fgetpos");
+#ifndef ISC
+ return fgetpos(fp->filehnd,ppos);
+#else
+ *ppos = ftell(fp->filehnd);
+ if (*ppos < 0L)
+ return(-1);
+ return(0);
+#endif
+}
+
+int
+xf86fsetpos(XF86FILE* f,const XF86fpos_t* pos)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+ fpos_t *ppos = (fpos_t*)pos;
+
+ /* XXX need to handle xf86errno here */
+ _xf86checkhndl(fp,"xf86fsetpos");
+#ifndef ISC
+ return fsetpos(fp->filehnd,ppos);
+#else
+ if (ppos == NULL)
+ {
+ errno = EINVAL;
+ return EOF;
+ }
+ return fseek(fp->filehnd, *ppos, SEEK_SET);
+#endif
+}
+
+void
+xf86perror(const char *s)
+{
+ perror(s);
+}
+
+int
+xf86remove(const char *s)
+{
+#ifdef _POSIX_SOURCE
+ return remove(s);
+#else
+ return unlink(s);
+#endif
+}
+
+int
+xf86rename(const char *old, const char *new)
+{
+#ifdef _POSIX_SOURCE
+ return rename(old,new);
+#else
+ int ret = link(old,new);
+ if (!ret) {
+ ret = unlink(old);
+ if (ret) unlink(new);
+ } else
+ ret = unlink(new);
+ return ret;
+#endif
+}
+
+void
+xf86rewind(XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86fsetpos");
+ rewind(fp->filehnd);
+}
+
+void
+xf86clearerr(XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86clearerr");
+ clearerr(fp->filehnd);
+}
+
+int
+xf86feof(XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86feof");
+ return feof(fp->filehnd);
+}
+
+int
+xf86ferror(XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86ferror");
+ return ferror(fp->filehnd);
+}
+
+XF86FILE*
+xf86freopen(const char* fname,const char* mode,XF86FILE* fold)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)fold;
+ FILE *fnew;
+
+ _xf86checkhndl(fp,"xf86freopen");
+ fnew = freopen(fname,mode,fp->filehnd);
+ xf86errno = xf86GetErrno();
+ if (!fnew) {
+ xf86fclose(fold); /* discard old XF86FILE structure */
+ return 0;
+ }
+ /* recycle the old XF86FILE structure */
+ fp->magic = XF86FILE_magic;
+ fp->filehnd = fnew;
+ fp->fileno = fileno(fnew);
+ fp->fname = xf86strdup(fname);
+#ifdef DEBUG
+ ErrorF("xf86freopen(%s,%s,%p) yields FILE %p XF86FILE %p\n",
+ fname,mode,fold,fnew,fp);
+#endif
+ return (XF86FILE*)fp;
+}
+
+int
+xf86setbuf(XF86FILE* f, char *buf)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86fsetbuf");
+#ifdef SETBUF_RETURNS_INT
+ return setbuf(fp->filehnd, buf);
+#else
+ setbuf(fp->filehnd, buf);
+ return 0;
+#endif
+}
+
+int
+xf86setvbuf(XF86FILE* f, char *buf, int mode, xf86size_t size)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+ int vbufmode;
+
+ _xf86checkhndl(fp,"xf86fsetvbuf");
+
+ switch (mode) {
+ case XF86_IONBF:
+ vbufmode = _IONBF;
+ break;
+ case XF86_IOLBF:
+ vbufmode = _IOFBF;
+ break;
+ case XF86_IOFBF:
+ vbufmode = _IOLBF;
+ break;
+ default:
+ FatalError("libc_wrapper error: mode in setvbuf incorrect");
+ exit(42);
+ }
+
+ return setvbuf(fp->filehnd,buf,vbufmode,(size_t)size);
+}
+
+XF86FILE*
+xf86tmpfile(void)
+{
+#ifdef NEED_TMPFILE
+ return xf86fopen(tmpnam((char*)0),"w+");
+#else
+ XF86FILE_priv* fp;
+ FILE *f = tmpfile();
+ xf86errno = xf86GetErrno();
+ if (!f) return 0;
+
+ fp = xalloc(sizeof(XF86FILE_priv));
+ fp->magic = XF86FILE_magic;
+ fp->filehnd = f;
+ fp->fileno = fileno(f);
+ fp->fname = xf86strdup("*tmpfile*"); /* so that it can be xfree()'d */
+#ifdef DEBUG
+ ErrorF("xf86tmpfile() yields FILE %p XF86FILE %p\n",f,fp);
+#endif
+ return (XF86FILE*)fp;
+}
+#endif /* HAS_TMPFILE */
+
+
+int
+xf86ungetc(int c,XF86FILE* f)
+{
+ XF86FILE_priv* fp = (XF86FILE_priv*)f;
+
+ _xf86checkhndl(fp,"xf86ungetc");
+ return ungetc(c,fp->filehnd);
+}
+
+/* Misc functions. Some are ANSI C, some are not. */
+
+void
+xf86usleep(usec)
+ unsigned long usec;
+{
+#if (defined(SYSV) || defined(SVR4)) && !defined(sun)
+ syscall(3112, (usec) / 1000 + 1);
+#else
+ usleep(usec);
+#endif
+}
+
+void
+xf86getsecs(long * secs, long * usecs)
+{
+ struct timeval tv;
+
+ X_GETTIMEOFDAY(&tv);
+ if (secs)
+ *secs = tv.tv_sec;
+ if (usecs)
+ *usecs= tv.tv_usec;
+
+ return;
+}
+
+int
+xf86ffs(int mask)
+{
+ int n;
+ if (mask == 0) return 0;
+ for (n = 1; (mask & 1)==0; n++)
+ mask >>= 1;
+ return n;
+}
+
+char *
+xf86getenv(const char * a)
+{
+ /* Only allow this when the real and effective uids are the same */
+ if (getuid() != geteuid())
+ return NULL;
+ else
+ return(getenv(a));
+}
+
+void *
+xf86bsearch(const void *key, const void *base, xf86size_t nmemb,
+ xf86size_t size, int (*compar)(const void *, const void *))
+{
+ return bsearch(key, base, (size_t)nmemb, (size_t)size, compar);
+}
+
+int
+xf86execl(const char *pathname, const char *arg, ...)
+{
+#ifndef __UNIXOS2__
+ int i;
+ pid_t pid;
+ int exit_status;
+ char *arglist[5];
+ va_list args;
+ va_start(args, arg);
+ arglist[0] = (char*)&args;
+ i = 1;
+ while (i < 5 && (arglist[i++] = va_arg(args, char *)) != NULL)
+ ;
+ va_end(args);
+
+ if ((pid = fork()) < 0) {
+ ErrorF("Fork failed (%s)\n", strerror(errno));
+ return -1;
+ } else if (pid == 0) { /* child */
+ /*
+ * Make sure that the child doesn't inherit any I/O permissions it
+ * shouldn't have. It's better to put constraints on the development
+ * of a clock program than to give I/O permissions to a bogus program
+ * in someone's XF86Config file
+ */
+#ifndef SELF_CONTAINED_WRAPPER
+ xf86DisableIO();
+#endif
+ if (setuid(getuid()) == -1) {
+ ErrorF("xf86Execl: setuid() failed: %s\n", strerror(errno));
+ exit(255);
+ }
+#if !defined(SELF_CONTAINED_WRAPPER)
+ /* set stdin, stdout to the consoleFD, and leave stderr alone */
+ for (i = 0; i < 2; i++)
+ {
+ if (xf86Info.consoleFd != i)
+ {
+ close(i);
+ dup(xf86Info.consoleFd);
+ }
+ }
+#endif
+
+ execv(pathname, arglist);
+ ErrorF("Exec failed for command \"%s\" (%s)\n",
+ pathname, strerror(errno));
+ exit(255);
+ }
+
+ /* parent */
+ wait(&exit_status);
+ if (WIFEXITED(exit_status))
+ {
+ switch (WEXITSTATUS(exit_status))
+ {
+ case 0: /* OK */
+ return 0;
+ case 255: /* exec() failed */
+ return(255);
+ default: /* bad exit status */
+ ErrorF("Program \"%s\" had bad exit status %d\n",
+ pathname, WEXITSTATUS(exit_status));
+ return(WEXITSTATUS(exit_status));
+ }
+ }
+ else if (WIFSIGNALED(exit_status))
+ {
+ ErrorF("Program \"%s\" died on signal %d\n",
+ pathname, WTERMSIG(exit_status));
+ return(WTERMSIG(exit_status));
+ }
+#ifdef WIFSTOPPED
+ else if (WIFSTOPPED(exit_status))
+ {
+ ErrorF("Program \"%s\" stopped by signal %d\n",
+ pathname, WSTOPSIG(exit_status));
+ return(WSTOPSIG(exit_status));
+ }
+#endif
+ else /* should never get to this point */
+ {
+ ErrorF("Program \"%s\" has unknown exit condition\n",
+ pathname);
+ return(1);
+ }
+#else
+ return(1);
+#endif /* __UNIXOS2__ Disable this crazy business for now */
+}
+
+void
+xf86abort(void)
+{
+ ErrorF("Module called abort() function\n");
+ abort();
+}
+
+void
+xf86exit(int ex)
+{
+ ErrorF("Module called exit() function with value=%d\n",ex);
+ exit(ex);
+}
+
+/* directory handling functions */
+#define XF86DIR_magic 0x78666876 /* "xfhv" */
+
+typedef struct _xf86_dir_ {
+ DIR *dir;
+ INT32 magic;
+ XF86DIRENT *dirent;
+} XF86DIR_priv;
+
+static void
+_xf86checkdirhndl(XF86DIR_priv* f,const char *func)
+{
+ if (!f || f->magic != XF86DIR_magic || !f->dir || !f->dirent) {
+ FatalError("libc_wrapper error: passed invalid DIR handle to %s",
+ func);
+ exit(42);
+ }
+}
+
+XF86DIR *
+xf86opendir(const char *name)
+{
+ XF86DIR_priv *dp;
+ DIR *dirp;
+
+ dirp = opendir(name);
+ if (!dirp)
+ return (XF86DIR*)0;
+
+ dp = xalloc(sizeof(XF86DIR_priv));
+ dp->magic = XF86DIR_magic; /* This time I have this, Dirk! :-) */
+ dp->dir = dirp;
+ dp->dirent = xalloc(sizeof(struct _xf86dirent));
+
+ return (XF86DIR*)dp;
+}
+
+XF86DIRENT*
+xf86readdir(XF86DIR* dirp)
+{
+ XF86DIR_priv* dp = (XF86DIR_priv*)dirp;
+ DIRENTRY *de;
+ XF86DIRENT* xde;
+ int sz;
+
+ _xf86checkdirhndl(dp,"xf86readdir");
+
+ de = readdir(dp->dir);
+ if (!de)
+ return (XF86DIRENT*)0;
+ xde = dp->dirent;
+ sz = strlen(de->d_name);
+ strncpy(xde->d_name,de->d_name, sz>_XF86NAMELEN ? (_XF86NAMELEN+1) : (sz+1));
+ xde->d_name[_XF86NAMELEN] = '\0'; /* be sure to have a 0 byte */
+ return xde;
+}
+
+void
+xf86rewinddir(XF86DIR* dirp)
+{
+ XF86DIR_priv* dp = (XF86DIR_priv*)dirp;
+
+ _xf86checkdirhndl(dp,"xf86readdir");
+ rewinddir(dp->dir);
+}
+
+int
+xf86closedir(XF86DIR* dir)
+{
+ XF86DIR_priv* dp = (XF86DIR_priv*)dir;
+ int n;
+
+ _xf86checkdirhndl(dp,"xf86readdir");
+
+ n = closedir(dp->dir);
+ dp->magic = 0;
+ xfree(dp->dirent);
+ xfree(dp);
+
+ return n;
+}
+
+static mode_t
+xfToOsChmodMode(xf86mode_t xfmode)
+{
+ mode_t mode = 0;
+
+ if (xfmode & XF86_S_ISUID) mode |= S_ISUID;
+ if (xfmode & XF86_S_ISGID) mode |= S_ISGID;
+#ifndef __UNIXOS2__
+ if (xfmode & XF86_S_ISVTX) mode |= S_ISVTX;
+#endif
+ if (xfmode & XF86_S_IRUSR) mode |= S_IRUSR;
+ if (xfmode & XF86_S_IWUSR) mode |= S_IWUSR;
+ if (xfmode & XF86_S_IXUSR) mode |= S_IXUSR;
+ if (xfmode & XF86_S_IRGRP) mode |= S_IRGRP;
+ if (xfmode & XF86_S_IWGRP) mode |= S_IWGRP;
+ if (xfmode & XF86_S_IXGRP) mode |= S_IXGRP;
+ if (xfmode & XF86_S_IROTH) mode |= S_IROTH;
+ if (xfmode & XF86_S_IWOTH) mode |= S_IWOTH;
+ if (xfmode & XF86_S_IXOTH) mode |= S_IXOTH;
+
+ return mode;
+}
+
+int
+xf86chmod(const char *path, xf86mode_t xfmode)
+{
+ mode_t mode = xfToOsChmodMode(xfmode);
+ int rc = chmod(path, mode);
+
+ xf86errno = xf86GetErrno();
+ return rc;
+}
+
+int
+xf86chown(const char *path, xf86uid_t owner, xf86gid_t group)
+{
+#ifndef __UNIXOS2__
+ int rc = chown(path, owner, group);
+#else
+ int rc = 0;
+#endif
+ xf86errno = xf86GetErrno();
+ return rc;
+}
+
+xf86uid_t
+xf86geteuid(void)
+{
+ return geteuid();
+}
+
+xf86gid_t
+xf86getegid(void)
+{
+ return getegid();
+}
+
+int
+xf86getpid(void)
+{
+ return getpid();
+}
+
+static mode_t
+xfToOsMknodMode(xf86mode_t xfmode)
+{
+ mode_t mode = xfToOsChmodMode(xfmode);
+
+ if (xfmode & XF86_S_IFREG) mode |= S_IFREG;
+ if (xfmode & XF86_S_IFCHR) mode |= S_IFCHR;
+#ifndef __UNIXOS2__
+ if (xfmode & XF86_S_IFBLK) mode |= S_IFBLK;
+#endif
+ if (xfmode & XF86_S_IFIFO) mode |= S_IFIFO;
+
+ return mode;
+}
+
+int xf86mknod(const char *pathname, xf86mode_t xfmode, xf86dev_t dev)
+{
+ mode_t mode = xfToOsMknodMode(xfmode);
+#ifndef __UNIXOS2__
+ int rc = mknod(pathname, mode, dev);
+#else
+ int rc = 0;
+#endif
+ xf86errno = xf86GetErrno();
+ return rc;
+}
+
+unsigned int xf86sleep(unsigned int seconds)
+{
+ return sleep(seconds);
+}
+
+int xf86mkdir(const char *pathname, xf86mode_t xfmode)
+{
+ mode_t mode = xfToOsChmodMode(xfmode);
+ int rc = mkdir(pathname, mode);
+
+ xf86errno = xf86GetErrno();
+ return rc;
+}
+
+
+/* Several math functions */
+
+int
+xf86abs(int x)
+{
+ return abs(x);
+}
+
+double
+xf86acos(double x)
+{
+ return acos(x);
+}
+
+double
+xf86asin(double x)
+{
+ return asin(x);
+}
+
+double
+xf86atan(double x)
+{
+ return atan(x);
+}
+
+double
+xf86atan2(double x,double y)
+{
+ return atan2(x,y);
+}
+
+double
+xf86atof(const char* s)
+{
+ return atof(s);
+}
+
+int
+xf86atoi(const char* s)
+{
+ return atoi(s);
+}
+
+long
+xf86atol(const char* s)
+{
+ return atol(s);
+}
+
+double
+xf86ceil(double x)
+{
+ return ceil(x);
+}
+
+double
+xf86cos(double x)
+{
+ return(cos(x));
+}
+
+double
+xf86exp(double x)
+{
+ return(exp(x));
+}
+
+double
+xf86fabs(double x)
+{
+ return(fabs(x));
+}
+
+int
+xf86finite(double x)
+{
+#ifndef QNX4
+#ifndef __UNIXOS2__
+ return(finite(x));
+#else
+ return(isfinite(x));
+#endif /* __UNIXOS2__ */
+#else
+ /* XXX Replace this with something that really works. */
+ return 1;
+#endif
+}
+
+double
+xf86floor(double x)
+{
+ return floor(x);
+}
+
+double
+xf86fmod(double x,double y)
+{
+ return fmod(x,y);
+}
+
+long
+xf86labs(long x)
+{
+ return labs(x);
+}
+
+double
+xf86ldexp(double x, int exp)
+{
+ return ldexp(x, exp);
+}
+
+double
+xf86log(double x)
+{
+ return(log(x));
+}
+
+double
+xf86log10(double x)
+{
+ return(log10(x));
+}
+
+double
+xf86modf(double x,double* y)
+{
+ return modf(x,y);
+}
+
+double
+xf86pow(double x, double y)
+{
+ return(pow(x,y));
+}
+
+double
+xf86sin(double x)
+{
+ return sin(x);
+}
+
+double
+xf86sqrt(double x)
+{
+ return(sqrt(x));
+}
+
+double
+xf86strtod(const char *s, char **end)
+{
+ return strtod(s,end);
+}
+
+long
+xf86strtol(const char *s, char **end, int radix)
+{
+ return strtol(s,end,radix);
+}
+
+unsigned long
+xf86strtoul(const char *s, char **end,int radix)
+{
+ return strtoul(s,end,radix);
+}
+
+double
+xf86tan(double x)
+{
+ return tan(x);
+}
+
+/* memory functions */
+void*
+xf86memchr(const void* s, int c, xf86size_t n)
+{
+ return memchr(s,c,(size_t)n);
+}
+
+int
+xf86memcmp(const void* s1, const void* s2, xf86size_t n)
+{
+ return(memcmp(s1,s2,(size_t)n));
+}
+
+void*
+xf86memcpy(void* dest, const void* src, xf86size_t n)
+{
+ return(memcpy(dest,src,(size_t)n));
+}
+
+void*
+xf86memmove(void* dest, const void* src, xf86size_t n)
+{
+ return(memmove(dest,src,(size_t)n));
+}
+
+void*
+xf86memset(void* s, int c, xf86size_t n)
+{
+ return(memset(s,c,(size_t)n));
+}
+
+/* ctype functions */
+
+int
+xf86isalnum(int c)
+{
+ return isalnum(c) ? 1 : 0;
+}
+
+int
+xf86isalpha(int c)
+{
+ return isalpha(c) ? 1 : 0;
+}
+
+int
+xf86iscntrl(int c)
+{
+ return iscntrl(c) ? 1 : 0;
+}
+
+int
+xf86isdigit(int c)
+{
+ return isdigit(c) ? 1 : 0;
+}
+
+int
+xf86isgraph(int c)
+{
+ return isgraph(c) ? 1 : 0;
+}
+
+int
+xf86islower(int c)
+{
+ return islower(c) ? 1 : 0;
+}
+
+int
+xf86isprint(int c)
+{
+ return isprint(c) ? 1 : 0;
+}
+
+int
+xf86ispunct(int c)
+{
+ return ispunct(c) ? 1 : 0;
+}
+
+int
+xf86isspace(int c)
+{
+ return isspace(c) ? 1 : 0;
+}
+
+int
+xf86isupper(int c)
+{
+ return isupper(c) ? 1 : 0;
+}
+
+int
+xf86isxdigit(int c)
+{
+ return isxdigit(c) ? 1 : 0;
+}
+
+int
+xf86tolower(int c)
+{
+ return tolower(c);
+}
+
+int
+xf86toupper(int c)
+{
+ return toupper(c);
+}
+
+/* memory allocation functions */
+void*
+xf86calloc(xf86size_t sz,xf86size_t n)
+{
+ return xcalloc(sz, n);
+}
+
+void
+xf86free(void* p)
+{
+ xfree(p);
+}
+
+double
+xf86frexp(double x, int *exp)
+{
+ return frexp(x, exp);
+}
+
+void*
+xf86malloc(xf86size_t n)
+{
+ return xalloc(n);
+}
+
+void*
+xf86realloc(void* p, xf86size_t n)
+{
+ return xrealloc(p,n);
+}
+
+/*
+ * XXX This probably doesn't belong here.
+ */
+int
+xf86getpagesize()
+{
+ static int pagesize = -1;
+
+ if (pagesize != -1)
+ return pagesize;
+
+#if defined(_SC_PAGESIZE) || defined(HAS_SC_PAGESIZE)
+ pagesize = sysconf(_SC_PAGESIZE);
+#endif
+#ifdef _SC_PAGE_SIZE
+ if (pagesize == -1)
+ pagesize = sysconf(_SC_PAGE_SIZE);
+#endif
+#ifdef HAS_GETPAGESIZE
+ if (pagesize == -1)
+ pagesize = getpagesize();
+#endif
+#ifdef PAGE_SIZE
+ if (pagesize == -1)
+ pagesize = PAGE_SIZE;
+#endif
+ if (pagesize == -1)
+ FatalError("xf86getpagesize: Cannot determine page size");
+
+ return pagesize;
+}
+
+
+#define mapnum(e) case (e): return (xf86_##e)
+
+int
+xf86GetErrno ()
+{
+ switch (errno)
+ {
+ case 0: return 0;
+ mapnum (EACCES);
+ mapnum (EAGAIN);
+ mapnum (EBADF);
+ mapnum (EEXIST);
+ mapnum (EFAULT);
+ mapnum (EINTR);
+ mapnum (EINVAL);
+ mapnum (EISDIR);
+ mapnum (ELOOP); /* not POSIX 1 */
+ mapnum (EMFILE);
+ mapnum (ENAMETOOLONG);
+ mapnum (ENFILE);
+ mapnum (ENOENT);
+ mapnum (ENOMEM);
+ mapnum (ENOSPC);
+ mapnum (ENOTDIR);
+ mapnum (EPIPE);
+ mapnum (EROFS);
+#ifndef __UNIXOS2__
+ mapnum (ETXTBSY); /* not POSIX 1 */
+#endif
+ mapnum (ENOTTY);
+#ifdef ENOSYS
+ mapnum (ENOSYS);
+#endif
+ mapnum (EBUSY);
+ mapnum (ENODEV);
+ mapnum (EIO);
+#ifdef ESRCH
+ mapnum (ESRCH);
+#endif
+#ifdef ENXIO
+ mapnum (ENXIO);
+#endif
+#ifdef E2BIG
+ mapnum (E2BIG);
+#endif
+#ifdef ENOEXEC
+ mapnum (ENOEXEC);
+#endif
+#ifdef ECHILD
+ mapnum (ECHILD);
+#endif
+#ifdef ENOTBLK
+ mapnum (ENOTBLK);
+#endif
+#ifdef EXDEV
+ mapnum (EXDEV);
+#endif
+#ifdef EFBIG
+ mapnum (EFBIG);
+#endif
+#ifdef ESPIPE
+ mapnum (ESPIPE);
+#endif
+#ifdef EMLINK
+ mapnum (EMLINK);
+#endif
+#ifdef EDOM
+ mapnum (EDOM);
+#endif
+#ifdef ERANGE
+ mapnum (ERANGE);
+#endif
+ default:
+ return (xf86_UNKNOWN);
+ }
+}
+
+#undef mapnum
+
+
+
+#ifdef HAVE_SYSV_IPC
+
+int
+xf86shmget(xf86key_t key, int size, int xf86shmflg)
+{
+ int shmflg;
+ int ret;
+
+ /* This copies the permissions (SHM_R, SHM_W for u, g, o). */
+ shmflg = xf86shmflg & 0777;
+
+ if (key == XF86IPC_PRIVATE) key = IPC_PRIVATE;
+
+ if (xf86shmflg & XF86IPC_CREAT) shmflg |= IPC_CREAT;
+ if (xf86shmflg & XF86IPC_EXCL) shmflg |= IPC_EXCL;
+ if (xf86shmflg & XF86IPC_NOWAIT) shmflg |= IPC_NOWAIT;
+ ret = shmget((key_t) key, size, shmflg);
+
+ if (ret == -1)
+ xf86errno = xf86GetErrno();
+
+ return ret;
+}
+
+char *
+xf86shmat(int id, char *addr, int xf86shmflg)
+{
+ int shmflg = 0;
+ pointer ret;
+
+#ifdef SHM_RDONLY
+ if (xf86shmflg & XF86SHM_RDONLY) shmflg |= SHM_RDONLY;
+#endif
+#ifdef SHM_RND
+ if (xf86shmflg & XF86SHM_RND) shmflg |= SHM_RND;
+#endif
+#ifdef SHM_REMAP
+ if (xf86shmflg & XF86SHM_REMAP) shmflg |= SHM_REMAP;
+#endif
+
+ ret = shmat(id,addr,shmflg);
+
+ if (ret == (pointer) -1)
+ xf86errno = xf86GetErrno();
+
+ return ret;
+}
+
+int
+xf86shmdt(char *addr)
+{
+ int ret;
+
+ ret = shmdt(addr);
+
+ if (ret == -1)
+ xf86errno = xf86GetErrno();
+
+ return ret;
+}
+
+/*
+ * for now only implement the rmid command.
+ */
+int
+xf86shmctl(int id, int xf86cmd, pointer buf)
+{
+ int cmd;
+ int ret;
+
+ switch (xf86cmd) {
+ case XF86IPC_RMID:
+ cmd = IPC_RMID;
+ break;
+ default:
+ return 0;
+ }
+
+ ret = shmctl(id, cmd, buf);
+
+ if (ret == -1)
+ xf86errno = xf86GetErrno();
+
+ return ret;
+}
+#else
+
+int
+xf86shmget(xf86key_t key, int size, int xf86shmflg)
+{
+ xf86errno = ENOSYS;
+
+ return -1;
+}
+
+char *
+xf86shmat(int id, char *addr, int xf86shmflg)
+{
+ xf86errno = ENOSYS;
+
+ return (char *)-1;
+}
+
+int
+xf86shmctl(int id, int xf86cmd, pointer buf)
+{
+ xf86errno = ENOSYS;
+
+ return -1;
+}
+
+int
+xf86shmdt(char *addr)
+{
+ xf86errno = ENOSYS;
+
+ return -1;
+}
+#endif /* HAVE_SYSV_IPC */
+
+int
+xf86getjmptype()
+{
+#ifdef HAS_GLIBC_SIGSETJMP
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+#ifdef HAS_GLIBC_SIGSETJMP
+
+int
+xf86setjmp(xf86jmp_buf env)
+{
+#if defined(__GLIBC__) && (__GLIBC__ >= 2)
+ return __sigsetjmp((void *)env, xf86setjmp1_arg2());
+#else
+ return xf86setjmp1(env, xf86setjmp1_arg2());
+#endif
+}
+
+int
+xf86setjmp0(xf86jmp_buf env)
+{
+ FatalError("setjmp: type 0 called instead of type %d", xf86getjmptype());
+}
+
+#if !defined(__GLIBC__) || (__GLIBC__ < 2) /* libc5 */
+
+int
+xf86setjmp1(xf86jmp_buf env, int arg2)
+{
+ __sigjmp_save((void *)env, arg2);
+ return __setjmp((void *)env);
+}
+
+#endif
+
+#else /* HAS_GLIBC_SIGSETJMP */
+
+int
+xf86setjmp1(xf86jmp_buf env, int arg2)
+{
+ FatalError("setjmp: type 1 called instead of type %d", xf86getjmptype());
+}
+
+int
+xf86setjmp0(xf86jmp_buf env)
+{
+ return setjmp((void *)env);
+}
+
+#endif /* HAS_GLIBC_SIGSETJMP */
+
+int
+xf86setjmp1_arg2()
+{
+ return 1;
+}
+
+int
+xf86setjmperror(xf86jmp_buf env)
+{
+ FatalError("setjmp: don't know how to handle setjmp() type %d",
+ xf86getjmptype());
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/pm_noop.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/pm_noop.c
new file mode 100644
index 000000000..6e24653ba
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/pm_noop.c
@@ -0,0 +1,48 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/pm_noop.c,v 1.2 2003/08/24 17:37:06 dawes Exp $ */
+/*
+ * Copyright (c) 2000 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).
+ */
+
+/* Stubs for the OS-support layer power-management functions. */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSproc.h"
+
+PMClose
+xf86OSPMOpen(void)
+{
+ return NULL;
+}
+
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/posix_tty.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/posix_tty.c
new file mode 100644
index 000000000..be3703944
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/posix_tty.c
@@ -0,0 +1,689 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/posix_tty.c,v 3.30 2003/08/24 17:37:06 dawes Exp $ */
+/*
+ * Copyright 1993-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 XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+/*
+ *
+ * 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.
+ *
+ */
+
+/* $XConsortium: posix_tty.c /main/7 1996/10/19 18:07:47 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+static int
+GetBaud (int baudrate)
+{
+#ifdef B300
+ if (baudrate == 300)
+ return B300;
+#endif
+#ifdef B1200
+ if (baudrate == 1200)
+ return B1200;
+#endif
+#ifdef B2400
+ if (baudrate == 2400)
+ return B2400;
+#endif
+#ifdef B4800
+ if (baudrate == 4800)
+ return B4800;
+#endif
+#ifdef B9600
+ if (baudrate == 9600)
+ return B9600;
+#endif
+#ifdef B19200
+ if (baudrate == 19200)
+ return B19200;
+#endif
+#ifdef B38400
+ if (baudrate == 38400)
+ return B38400;
+#endif
+#ifdef B57600
+ if (baudrate == 57600)
+ return B57600;
+#endif
+#ifdef B115200
+ if (baudrate == 115200)
+ return B115200;
+#endif
+#ifdef B230400
+ if (baudrate == 230400)
+ return B230400;
+#endif
+#ifdef B460800
+ if (baudrate == 460800)
+ return B460800;
+#endif
+ return (0);
+}
+
+int
+xf86OpenSerial (pointer options)
+{
+#ifdef Lynx
+ struct sgttyb ms_sgtty;
+#endif
+ struct termios t;
+ int fd, i;
+ char *dev;
+
+ dev = xf86SetStrOption (options, "Device", NULL);
+ if (!dev)
+ {
+ xf86Msg (X_ERROR, "xf86OpenSerial: No Device specified.\n");
+ return (-1);
+ }
+
+ SYSCALL (fd = open (dev, O_RDWR | O_NONBLOCK));
+ if (fd == -1)
+ {
+ xf86Msg (X_ERROR,
+ "xf86OpenSerial: Cannot open device %s\n\t%s.\n",
+ dev, strerror (errno));
+ xfree(dev);
+ return (-1);
+ }
+
+ if (!isatty (fd))
+ {
+#if 1
+ /* Allow non-tty devices to be opened. */
+ xfree(dev);
+ return (fd);
+#else
+ xf86Msg (X_WARNING,
+ "xf86OpenSerial: Specified device %s is not a tty\n",
+ dev);
+ SYSCALL (close (fd));
+ errno = EINVAL;
+ xfree(dev);
+ return (-1);
+#endif
+ }
+
+#ifdef Lynx
+ /* LynxOS does not assert DTR without this */
+ ioctl (fd, TIOCGETP, (char *) &ms_sgtty);
+ ioctl (fd, TIOCSDTR, (char *) &ms_sgtty);
+#endif
+
+ /* set up default port parameters */
+ SYSCALL (tcgetattr (fd, &t));
+ t.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR\
+ |IGNCR|ICRNL|IXON);
+ t.c_oflag &= ~OPOST;
+ t.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+ t.c_cflag &= ~(CSIZE|PARENB);
+ t.c_cflag |= CS8|CLOCAL;
+
+ cfsetispeed (&t, B9600);
+ cfsetospeed (&t, B9600);
+ t.c_cc[VMIN] = 1;
+ t.c_cc[VTIME] = 0;
+
+ SYSCALL (tcsetattr (fd, TCSANOW, &t));
+
+ if (xf86SetSerial (fd, options) == -1)
+ {
+ SYSCALL (close (fd));
+ xfree(dev);
+ return (-1);
+ }
+
+ SYSCALL (i = fcntl (fd, F_GETFL, 0));
+ if (i == -1)
+ {
+ SYSCALL (close (fd));
+ xfree(dev);
+ return (-1);
+ }
+ i &= ~O_NONBLOCK;
+ SYSCALL (i = fcntl (fd, F_SETFL, i));
+ if (i == -1)
+ {
+ SYSCALL (close (fd));
+ xfree(dev);
+ return (-1);
+ }
+ xfree(dev);
+ return (fd);
+}
+
+int
+xf86SetSerial (int fd, pointer options)
+{
+ struct termios t;
+ int val;
+ const char *s;
+ int baud, r;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+ SYSCALL (tcgetattr (fd, &t));
+
+ if ((val = xf86SetIntOption (options, "BaudRate", 0)))
+ {
+ if ((baud = GetBaud (val)))
+ {
+ cfsetispeed (&t, baud);
+ cfsetospeed (&t, baud);
+ }
+ else
+ {
+ xf86Msg (X_ERROR,
+ "Invalid Option BaudRate value: %d\n", val);
+ return (-1);
+ }
+ }
+
+ if ((val = xf86SetIntOption (options, "StopBits", 0)))
+ {
+ switch (val)
+ {
+ case 1:
+ t.c_cflag &= ~(CSTOPB);
+ break;
+ case 2:
+ t.c_cflag |= CSTOPB;
+ break;
+ default:
+ xf86Msg (X_ERROR,
+ "Invalid Option StopBits value: %d\n", val);
+ return (-1);
+ break;
+ }
+ }
+
+ if ((val = xf86SetIntOption (options, "DataBits", 0)))
+ {
+ switch (val)
+ {
+ case 5:
+ t.c_cflag &= ~(CSIZE);
+ t.c_cflag |= CS5;
+ break;
+ case 6:
+ t.c_cflag &= ~(CSIZE);
+ t.c_cflag |= CS6;
+ break;
+ case 7:
+ t.c_cflag &= ~(CSIZE);
+ t.c_cflag |= CS7;
+ break;
+ case 8:
+ t.c_cflag &= ~(CSIZE);
+ t.c_cflag |= CS8;
+ break;
+ default:
+ xf86Msg (X_ERROR,
+ "Invalid Option DataBits value: %d\n", val);
+ return (-1);
+ break;
+ }
+ }
+
+ if ((s = xf86SetStrOption (options, "Parity", NULL)))
+ {
+ if (xf86NameCmp (s, "Odd") == 0)
+ {
+ t.c_cflag |= PARENB | PARODD;
+ }
+ else if (xf86NameCmp (s, "Even") == 0)
+ {
+ t.c_cflag |= PARENB;
+ t.c_cflag &= ~(PARODD);
+ }
+ else if (xf86NameCmp (s, "None") == 0)
+ {
+ t.c_cflag &= ~(PARENB);
+ }
+ else
+ {
+ xf86Msg (X_ERROR, "Invalid Option Parity value: %s\n",
+ s);
+ return (-1);
+ }
+ }
+
+ if ((val = xf86SetIntOption (options, "Vmin", -1)) != -1)
+ {
+ t.c_cc[VMIN] = val;
+ }
+ if ((val = xf86SetIntOption (options, "Vtime", -1)) != -1)
+ {
+ t.c_cc[VTIME] = val;
+ }
+
+ if ((s = xf86SetStrOption (options, "FlowControl", NULL)))
+ {
+ xf86MarkOptionUsedByName (options, "FlowControl");
+ if (xf86NameCmp (s, "Xoff") == 0)
+ {
+ t.c_iflag |= IXOFF;
+ }
+ else if (xf86NameCmp (s, "Xon") == 0)
+ {
+ t.c_iflag |= IXON;
+ }
+ else if (xf86NameCmp (s, "XonXoff") == 0)
+ {
+ t.c_iflag |= IXON|IXOFF;
+ }
+ else if (xf86NameCmp (s, "None") == 0)
+ {
+ t.c_iflag &= ~(IXON | IXOFF);
+ }
+ else
+ {
+ xf86Msg (X_ERROR,
+ "Invalid Option FlowControl value: %s\n", s);
+ return (-1);
+ }
+ }
+
+ if ((xf86SetBoolOption (options, "ClearDTR", FALSE)))
+ {
+#ifdef CLEARDTR_SUPPORT
+# if !defined(Lynx) || defined(TIOCMBIC)
+ val = TIOCM_DTR;
+ SYSCALL (ioctl(fd, TIOCMBIC, &val));
+# else
+ SYSCALL (ioctl(fd, TIOCCDTR, NULL));
+# endif
+#else
+ xf86Msg (X_WARNING,
+ "Option ClearDTR not supported on this OS\n");
+ return (-1);
+#endif
+ xf86MarkOptionUsedByName (options, "ClearDTR");
+ }
+
+ if ((xf86SetBoolOption (options, "ClearRTS", FALSE)))
+ {
+#ifdef CLEARRTS_SUPPORT
+ val = TIOCM_RTS;
+ SYSCALL (ioctl(fd, TIOCMBIC, &val));
+#else
+ xf86Msg (X_WARNING,
+ "Option ClearRTS not supported on this OS\n");
+ return (-1);
+#endif
+ xf86MarkOptionUsedByName (options, "ClearRTS");
+ }
+
+ SYSCALL (r = tcsetattr (fd, TCSANOW, &t));
+ return (r);
+}
+
+int
+xf86SetSerialSpeed (int fd, int speed)
+{
+ struct termios t;
+ int baud, r;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+ SYSCALL (tcgetattr (fd, &t));
+
+ if ((baud = GetBaud (speed)))
+ {
+ cfsetispeed (&t, baud);
+ cfsetospeed (&t, baud);
+ }
+ else
+ {
+ xf86Msg (X_ERROR,
+ "Invalid Option BaudRate value: %d\n", speed);
+ return (-1);
+ }
+
+ SYSCALL (r = tcsetattr (fd, TCSANOW, &t));
+ return (r);
+}
+
+int
+xf86ReadSerial (int fd, void *buf, int count)
+{
+ int r;
+#ifdef DEBUG
+ int i;
+#endif
+ SYSCALL (r = read (fd, buf, count));
+#ifdef DEBUG
+ ErrorF("ReadingSerial: 0x%x",
+ (unsigned char)*(((unsigned char *)buf)));
+ for (i = 1; i < r; i++)
+ ErrorF(", 0x%x",(unsigned char)*(((unsigned char *)buf) + i));
+ ErrorF("\n");
+#endif
+ return (r);
+}
+
+int
+xf86WriteSerial (int fd, const void *buf, int count)
+{
+ int r;
+#ifdef DEBUG
+ int i;
+
+ ErrorF("WritingSerial: 0x%x",(unsigned char)*(((unsigned char *)buf)));
+ for (i = 1; i < count; i++)
+ ErrorF(", 0x%x",(unsigned char)*(((unsigned char *)buf) + i));
+ ErrorF("\n");
+#endif
+ SYSCALL (r = write (fd, buf, count));
+ return (r);
+}
+
+int
+xf86CloseSerial (int fd)
+{
+ int r;
+
+ SYSCALL (r = close (fd));
+ return (r);
+}
+
+int
+xf86WaitForInput (int fd, int timeout)
+{
+ fd_set readfds;
+ struct timeval to;
+ int r;
+
+ FD_ZERO(&readfds);
+
+ if (fd >= 0) {
+ FD_SET(fd, &readfds);
+ }
+
+ to.tv_sec = timeout / 1000000;
+ to.tv_usec = timeout % 1000000;
+
+ if (fd >= 0) {
+ SYSCALL (r = select (FD_SETSIZE, &readfds, NULL, NULL, &to));
+ }
+ else {
+ SYSCALL (r = select (FD_SETSIZE, NULL, NULL, NULL, &to));
+ }
+ xf86ErrorFVerb (9,"select returned %d\n", r);
+ return (r);
+}
+
+int
+xf86SerialSendBreak (int fd, int duration)
+{
+ int r;
+
+ SYSCALL (r = tcsendbreak (fd, duration));
+ return (r);
+
+}
+
+int
+xf86FlushInput(int fd)
+{
+ fd_set fds;
+ struct timeval timeout;
+ char c[4];
+
+#ifdef DEBUG
+ ErrorF("FlushingSerial\n");
+#endif
+ if (tcflush(fd, TCIFLUSH) == 0)
+ return 0;
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ while (select(FD_SETSIZE, &fds, NULL, NULL, &timeout) > 0) {
+ if (read(fd, &c, sizeof(c)) < 1)
+ return 0;
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ }
+ return 0;
+}
+
+static struct states {
+ int xf;
+ int os;
+} modemStates[] = {
+#ifdef TIOCM_LE
+ { XF86_M_LE, TIOCM_LE },
+#endif
+#ifdef TIOCM_DTR
+ { XF86_M_DTR, TIOCM_DTR },
+#endif
+#ifdef TIOCM_RTS
+ { XF86_M_RTS, TIOCM_RTS },
+#endif
+#ifdef TIOCM_ST
+ { XF86_M_ST, TIOCM_ST },
+#endif
+#ifdef TIOCM_SR
+ { XF86_M_SR, TIOCM_SR },
+#endif
+#ifdef TIOCM_CTS
+ { XF86_M_CTS, TIOCM_CTS },
+#endif
+#ifdef TIOCM_CAR
+ { XF86_M_CAR, TIOCM_CAR },
+#elif defined(TIOCM_CD)
+ { XF86_M_CAR, TIOCM_CD },
+#endif
+#ifdef TIOCM_RNG
+ { XF86_M_RNG, TIOCM_RNG },
+#elif defined(TIOCM_RI)
+ { XF86_M_CAR, TIOCM_RI },
+#endif
+#ifdef TIOCM_DSR
+ { XF86_M_DSR, TIOCM_DSR },
+#endif
+};
+
+static int numStates = sizeof(modemStates) / sizeof(modemStates[0]);
+
+static int
+xf2osState(int state)
+{
+ int i;
+ int ret = 0;
+
+ for (i = 0; i < numStates; i++)
+ if (state & modemStates[i].xf)
+ ret |= modemStates[i].os;
+ return ret;
+}
+
+static int
+os2xfState(int state)
+{
+ int i;
+ int ret = 0;
+
+ for (i = 0; i < numStates; i++)
+ if (state & modemStates[i].os)
+ ret |= modemStates[i].xf;
+ return ret;
+}
+
+static int
+getOsStateMask(void)
+{
+ int i;
+ int ret = 0;
+ for (i = 0; i < numStates; i++)
+ ret |= modemStates[i].os;
+ return ret;
+}
+
+static int osStateMask = 0;
+
+int
+xf86SetSerialModemState(int fd, int state)
+{
+ int ret;
+ int s;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+#ifndef TIOCMGET
+ return -1;
+#else
+ if (!osStateMask)
+ osStateMask = getOsStateMask();
+
+ state = xf2osState(state);
+ SYSCALL((ret = ioctl(fd, TIOCMGET, &s)));
+ if (ret < 0)
+ return -1;
+ s &= ~osStateMask;
+ s |= state;
+ SYSCALL((ret = ioctl(fd, TIOCMSET, &s)));
+ if (ret < 0)
+ return -1;
+ else
+ return 0;
+#endif
+}
+
+int
+xf86GetSerialModemState(int fd)
+{
+ int ret;
+ int s;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+#ifndef TIOCMGET
+ return -1;
+#else
+ SYSCALL((ret = ioctl(fd, TIOCMGET, &s)));
+ if (ret < 0)
+ return -1;
+ return os2xfState(s);
+#endif
+}
+
+int
+xf86SerialModemSetBits(int fd, int bits)
+{
+ int ret;
+ int s;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+#ifndef TIOCMGET
+ return -1;
+#else
+ s = xf2osState(bits);
+ SYSCALL((ret = ioctl(fd, TIOCMBIS, &s)));
+ return ret;
+#endif
+}
+
+int
+xf86SerialModemClearBits(int fd, int bits)
+{
+ int ret;
+ int s;
+
+ if (fd < 0)
+ return -1;
+
+ /* Don't try to set parameters for non-tty devices. */
+ if (!isatty(fd))
+ return 0;
+
+#ifndef TIOCMGET
+ return -1;
+#else
+ s = xf2osState(bits);
+ SYSCALL((ret = ioctl(fd, TIOCMBIC, &s)));
+ return ret;
+#endif
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sigio.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sigio.c
new file mode 100644
index 000000000..e6da3940f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sigio.c
@@ -0,0 +1,312 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/sigio.c,v 1.16 2003/09/04 00:21:17 dawes Exp $ */
+
+/* sigio.c -- Support for SIGIO handler installation and removal
+ * Created: Thu Jun 3 15:39:18 1999 by faith@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
+ */
+/*
+ * Copyright (c) 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).
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef XFree86Server
+# include <X11/X.h>
+# include "xf86.h"
+# include "xf86Priv.h"
+# include "xf86_OSlib.h"
+# include "inputstr.h"
+#else
+# include <unistd.h>
+# include <signal.h>
+# include <fcntl.h>
+# include <sys/time.h>
+# include <errno.h>
+# include <stdio.h>
+# include <string.h>
+# define SYSCALL(call) while(((call) == -1) && (errno == EINTR))
+#endif
+
+/*
+ * Linux libc5 defines FASYNC, but not O_ASYNC. Don't know if it is
+ * functional or not.
+ */
+#if defined(FASYNC) && !defined(O_ASYNC)
+# define O_ASYNC FASYNC
+#endif
+
+#ifdef MAX_DEVICES
+/* MAX_DEVICES represents the maximimum number of input devices usable
+ * at the same time plus one entry for DRM support.
+ */
+# define MAX_FUNCS (MAX_DEVICES + 1)
+#else
+# define MAX_FUNCS 16
+#endif
+
+typedef struct _xf86SigIOFunc {
+ void (*f) (int, void *);
+ int fd;
+ void *closure;
+} Xf86SigIOFunc;
+
+static Xf86SigIOFunc xf86SigIOFuncs[MAX_FUNCS];
+static int xf86SigIOMax;
+static int xf86SigIOMaxFd;
+static fd_set xf86SigIOMask;
+
+/*
+ * SIGIO gives no way of discovering which fd signalled, select
+ * to discover
+ */
+static void
+xf86SIGIO (int sig)
+{
+ int i;
+ fd_set ready;
+ struct timeval to;
+ int r;
+
+ ready = xf86SigIOMask;
+ to.tv_sec = 0;
+ to.tv_usec = 0;
+ SYSCALL (r = select (xf86SigIOMaxFd, &ready, 0, 0, &to));
+ for (i = 0; r > 0 && i < xf86SigIOMax; i++)
+ if (xf86SigIOFuncs[i].f && FD_ISSET (xf86SigIOFuncs[i].fd, &ready))
+ {
+ (*xf86SigIOFuncs[i].f)(xf86SigIOFuncs[i].fd,
+ xf86SigIOFuncs[i].closure);
+ r--;
+ }
+#ifdef XFree86Server
+ if (r > 0) {
+ xf86Msg(X_ERROR, "SIGIO %d descriptors not handled\n", r);
+ }
+#endif
+}
+
+static int
+xf86IsPipe (int fd)
+{
+ struct stat buf;
+
+ if (fstat (fd, &buf) < 0)
+ return 0;
+ return S_ISFIFO(buf.st_mode);
+}
+
+int
+xf86InstallSIGIOHandler(int fd, void (*f)(int, void *), void *closure)
+{
+ struct sigaction sa;
+ struct sigaction osa;
+ int i;
+ int blocked;
+
+ for (i = 0; i < MAX_FUNCS; i++)
+ {
+ if (!xf86SigIOFuncs[i].f)
+ {
+ if (xf86IsPipe (fd))
+ return 0;
+ blocked = xf86BlockSIGIO();
+ if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC) == -1) {
+#ifdef XFree86Server
+ xf86Msg(X_WARNING, "fcntl(%d, O_ASYNC): %s\n",
+ fd, strerror(errno));
+#else
+ fprintf(stderr,"fcntl(%d, O_ASYNC): %s\n",
+ fd, strerror(errno));
+#endif
+ xf86UnblockSIGIO(blocked);
+ return 0;
+ }
+ if (fcntl(fd, F_SETOWN, getpid()) == -1) {
+#ifdef XFree86Server
+ xf86Msg(X_WARNING, "fcntl(%d, F_SETOWN): %s\n",
+ fd, strerror(errno));
+#else
+ fprintf(stderr,"fcntl(%d, F_SETOWN): %s\n",
+ fd, strerror(errno));
+#endif
+ xf86UnblockSIGIO(blocked);
+ return 0;
+ }
+ sigemptyset(&sa.sa_mask);
+ sigaddset(&sa.sa_mask, SIGIO);
+ sa.sa_flags = 0;
+ sa.sa_handler = xf86SIGIO;
+ sigaction(SIGIO, &sa, &osa);
+ xf86SigIOFuncs[i].fd = fd;
+ xf86SigIOFuncs[i].closure = closure;
+ xf86SigIOFuncs[i].f = f;
+ if (i >= xf86SigIOMax)
+ xf86SigIOMax = i+1;
+ if (fd >= xf86SigIOMaxFd)
+ xf86SigIOMaxFd = fd + 1;
+ FD_SET (fd, &xf86SigIOMask);
+ xf86UnblockSIGIO(blocked);
+ return 1;
+ }
+ /* Allow overwriting of the closure and callback */
+ else if (xf86SigIOFuncs[i].fd == fd)
+ {
+ xf86SigIOFuncs[i].closure = closure;
+ xf86SigIOFuncs[i].f = f;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+int
+xf86RemoveSIGIOHandler(int fd)
+{
+ struct sigaction sa;
+ struct sigaction osa;
+ int i;
+ int max;
+ int maxfd;
+ int ret;
+
+ max = 0;
+ maxfd = -1;
+ ret = 0;
+ for (i = 0; i < MAX_FUNCS; i++)
+ {
+ if (xf86SigIOFuncs[i].f)
+ {
+ if (xf86SigIOFuncs[i].fd == fd)
+ {
+ xf86SigIOFuncs[i].f = 0;
+ xf86SigIOFuncs[i].fd = 0;
+ xf86SigIOFuncs[i].closure = 0;
+ FD_CLR (fd, &xf86SigIOMask);
+ ret = 1;
+ }
+ else
+ {
+ max = i + 1;
+ if (xf86SigIOFuncs[i].fd >= maxfd)
+ maxfd = xf86SigIOFuncs[i].fd + 1;
+ }
+ }
+ }
+ if (ret)
+ {
+ fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_ASYNC);
+ xf86SigIOMax = max;
+ xf86SigIOMaxFd = maxfd;
+ if (!max)
+ {
+ sigemptyset(&sa.sa_mask);
+ sigaddset(&sa.sa_mask, SIGIO);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_DFL;
+ sigaction(SIGIO, &sa, &osa);
+ }
+ }
+ return ret;
+}
+
+int
+xf86BlockSIGIO (void)
+{
+ sigset_t set, old;
+ int ret;
+
+ sigemptyset (&set);
+ sigaddset (&set, SIGIO);
+ sigprocmask (SIG_BLOCK, &set, &old);
+ ret = sigismember (&old, SIGIO);
+#ifdef DEBUG
+ ErrorF("%i = xf86BlockSIGIO()\n",ret);
+#endif
+ return ret;
+}
+
+void
+xf86UnblockSIGIO (int wasset)
+{
+ sigset_t set;
+#ifdef DEBUG
+ ErrorF("xf86UnblockSIGIO(%i)\n",wasset);
+#endif
+
+ if (!wasset)
+ {
+ sigemptyset (&set);
+ sigaddset (&set, SIGIO);
+ sigprocmask (SIG_UNBLOCK, &set, NULL);
+ }
+}
+
+#ifdef XFree86Server
+void
+xf86AssertBlockedSIGIO (char *where)
+{
+ sigset_t set, old;
+
+ sigemptyset (&set);
+ sigprocmask (SIG_BLOCK, &set, &old);
+ if (!sigismember (&old, SIGIO))
+ xf86Msg (X_ERROR, "SIGIO not blocked at %s\n", where);
+}
+
+/* XXX This is a quick hack for the benefit of xf86SetSilkenMouse() */
+
+int
+xf86SIGIOSupported (void)
+{
+ return 1;
+}
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sigiostubs.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sigiostubs.c
new file mode 100644
index 000000000..2173bb991
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sigiostubs.c
@@ -0,0 +1,86 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/sigiostubs.c,v 1.4 2003/08/24 17:37:06 dawes Exp $ */
+/*
+ * Copyright (c) 1999-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).
+ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/shared/sigiostubs.c,v 1.5 2005/07/03 07:01:35 daniels Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef XFree86Server
+#ifdef __UNIXOS2__
+# define I_NEED_OS2_H
+#endif
+# include <X11/X.h>
+# include "xf86.h"
+# include "xf86Priv.h"
+# include "xf86_OSlib.h"
+#else
+# include <unistd.h>
+# include <signal.h>
+# include <fcntl.h>
+# include <sys/time.h>
+# include <errno.h>
+#endif
+
+int
+xf86InstallSIGIOHandler(int fd, void (*f)(int, void *), void *closure)
+{
+ return 0;
+}
+
+int
+xf86RemoveSIGIOHandler(int fd)
+{
+ return 0;
+}
+
+int
+xf86BlockSIGIO (void)
+{
+ return 0;
+}
+
+void
+xf86UnblockSIGIO (int wasset)
+{
+}
+
+#ifdef XFree86Server
+void
+xf86AssertBlockedSIGIO (char *where)
+{
+}
+#endif
+
+/* XXX This is a quick hack for the benefit of xf86SetSilkenMouse() */
+Bool
+xf86SIGIOSupported ()
+{
+ return FALSE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/stdPci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/stdPci.c
new file mode 100644
index 000000000..491406f92
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/stdPci.c
@@ -0,0 +1,52 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/stdPci.c,v 3.4 2003/08/24 17:37:06 dawes Exp $ */
+/*
+ * Copyright (c) 1999-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
+
+#ifdef __UNIXOS2__
+# define I_NEED_OS2_H
+#endif
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Privstr.h"
+#include "xf86Pci.h"
+#define NEED_OS_RAC_PROTOS
+#include "xf86_OSlib.h"
+
+#ifndef HAVE_PCI_SIZE_FUNC
+#define xf86StdGetPciSizeFromOS xf86GetPciSizeFromOS
+#endif
+
+Bool
+xf86StdGetPciSizeFromOS(PCITAG tag, int index, int* bits)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/stdResource.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/stdResource.c
new file mode 100644
index 000000000..4704d8194
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/stdResource.c
@@ -0,0 +1,182 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/stdResource.c,v 1.22 2003/08/24 17:37:06 dawes Exp $ */
+/*
+ * Copyright (c) 1999-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).
+ */
+
+/* Standard resource information code */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef __UNIXOS2__
+# define I_NEED_OS2_H
+#endif
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86Privstr.h"
+#include "xf86Pci.h"
+#define NEED_OS_RAC_PROTOS
+#include "xf86_OSlib.h"
+#include "xf86Resources.h"
+
+#ifdef __UNIXOS2__
+# undef ADDRESS
+#endif
+/* Avoid Imakefile changes */
+#include "bus/Pci.h"
+
+#ifdef USESTDRES
+#define xf86StdBusAccWindowsFromOS xf86BusAccWindowsFromOS
+#define xf86StdAccResFromOS xf86AccResFromOS
+#define xf86StdPciBusAccWindowsFromOS xf86PciBusAccWindowsFromOS
+#define xf86StdIsaBusAccWindowsFromOS xf86IsaBusAccWindowsFromOS
+
+resRange PciAvoid[] = {_PCI_AVOID_PC_STYLE, _END};
+#endif
+
+#ifdef INCLUDE_XF86_NO_DOMAIN
+
+resPtr
+xf86StdBusAccWindowsFromOS(void)
+{
+ /* Fallback is to allow addressing of all memory space */
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /* Fallback is to allow addressing of all I/O space */
+ RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+resPtr
+xf86StdPciBusAccWindowsFromOS(void)
+{
+ /* Fallback is to allow addressing of all memory space */
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /* Fallback is to allow addressing of all I/O space */
+ RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#ifdef INCLUDE_UNUSED
+
+resPtr
+xf86StdIsaBusAccWindowsFromOS(void)
+{
+ /* Fallback is to allow addressing of all memory space */
+ resPtr ret = NULL;
+ resRange range;
+
+ RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /* Fallback is to allow addressing of all I/O space */
+ RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ return ret;
+}
+
+#endif /* INCLUDE_UNUSED */
+
+resPtr
+xf86StdAccResFromOS(resPtr ret)
+{
+ resRange range;
+
+ /*
+ * Fallback is to claim the following areas:
+ *
+ * 0x00000000 - 0x0009ffff low 640k host memory
+ * 0x000c0000 - 0x000effff location of VGA and other extensions ROMS
+ * 0x000f0000 - 0x000fffff system BIOS
+ * 0x00100000 - 0x3fffffff low 1G - 1MB host memory
+ * 0xfec00000 - 0xfecfffff default I/O APIC config space
+ * 0xfee00000 - 0xfeefffff default Local APIC config space
+ * 0xffe00000 - 0xffffffff high BIOS area (should this be included?)
+ *
+ * reference: Intel 440BX AGP specs
+ *
+ * The two APIC spaces appear to be BX-specific and should be dealt with
+ * elsewhere.
+ */
+
+ /* Fallback is to claim 0x0 - 0x9ffff and 0x100000 - 0x7fffffff */
+ RANGE(range, 0x00000000, 0x0009ffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x000c0000, 0x000effff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x000f0000, 0x000fffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x00100000, 0x3fffffff,
+ ResExcMemBlock | ResBios | ResEstimated);
+ ret = xf86AddResToList(ret, &range, -1);
+#if 0
+ RANGE(range, 0xfec00000, 0xfecfffff, ResExcMemBlock | ResBios);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xfee00000, 0xfeefffff, ResExcMemBlock | ResBios);
+ ret = xf86AddResToList(ret, &range, -1);
+#endif
+ RANGE(range, 0xffe00000, 0xffffffff, ResExcMemBlock | ResBios);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /*
+ * Fallback would be to claim well known ports in the 0x0 - 0x3ff range
+ * along with their sparse I/O aliases, but that's too imprecise. Instead
+ * claim a bare minimum here.
+ */
+ RANGE(range, 0x00000000, 0x000000ff, ResExcIoBlock); /* For mainboard */
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /*
+ * At minimum, the top and bottom resources must be claimed, so that
+ * resources that are (or appear to be) unallocated can be relocated.
+ */
+/* RANGE(range, 0x00000000, 0x00000000, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0xffffffff, 0xffffffff, ResExcMemBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+ RANGE(range, 0x00000000, 0x00000000, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1); */
+ RANGE(range, 0x0000ffff, 0x0000ffff, ResExcIoBlock);
+ ret = xf86AddResToList(ret, &range, -1);
+
+ /* XXX add others */
+ return ret;
+}
+
+#endif /* INCLUDE_XF86_NO_DOMAIN */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/std_kbdEv.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/std_kbdEv.c
new file mode 100644
index 000000000..c678162c2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/std_kbdEv.c
@@ -0,0 +1,50 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/std_kbdEv.c,v 3.2 1998/07/25 16:57:01 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Dawes makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID DAWES BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: std_kbdEv.c /main/4 1996/03/11 10:47:33 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+void
+xf86KbdEvents()
+{
+ unsigned char rBuf[64];
+ int nBytes, i;
+
+ if ((nBytes = read( xf86Info.consoleFd, (char *)rBuf, sizeof(rBuf)))
+ > 0)
+ {
+ for (i = 0; i < nBytes; i++)
+ xf86PostKbdEvent(rBuf[i]);
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sysv_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sysv_kbd.c
new file mode 100644
index 000000000..3a3544e8c
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/sysv_kbd.c
@@ -0,0 +1,106 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/sysv_kbd.c,v 3.3 1998/07/25 16:57:02 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Dawes <dawes@XFree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Dawes makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID DAWES BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: sysv_kbd.c /main/3 1996/02/21 17:53:59 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+int
+xf86GetKbdLeds()
+{
+ int leds;
+
+ ioctl(xf86Info.consoleFd, KDGETLED, &leds);
+ return(leds);
+}
+
+void
+xf86SetKbdRepeat(char rad)
+{
+#ifdef KDSETRAD
+ ioctl(xf86Info.consoleFd, KDSETRAD, rad);
+#endif
+}
+
+static int kbdtrans;
+static struct termio kbdtty;
+static char *kbdemap = NULL;
+
+void
+xf86KbdInit()
+{
+#ifdef KDGKBMODE
+ ioctl (xf86Info.consoleFd, KDGKBMODE, &kbdtrans);
+#endif
+ ioctl (xf86Info.consoleFd, TCGETA, &kbdtty);
+#if defined(E_TABSZ)
+ kbdemap = xalloc(E_TABSZ);
+ if (ioctl(xf86Info.consoleFd, LDGMAP, kbdemap) < 0)
+ {
+ xfree(kbdemap);
+ kbdemap = NULL;
+ }
+#endif
+}
+
+int
+xf86KbdOn()
+{
+ struct termio nTty;
+
+ ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW);
+ ioctl(xf86Info.consoleFd, LDNMAP, 0); /* disable mapping completely */
+ nTty = kbdtty;
+ nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8 | B9600;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME]=0;
+ nTty.c_cc[VMIN]=1;
+ ioctl(xf86Info.consoleFd, TCSETA, &nTty);
+ return(xf86Info.consoleFd);
+}
+
+int
+xf86KbdOff()
+{
+ if (kbdemap)
+ {
+ ioctl(xf86Info.consoleFd, LDSMAP, kbdemap);
+ }
+ ioctl(xf86Info.consoleFd, KDSKBMODE, kbdtrans);
+ ioctl(xf86Info.consoleFd, TCSETA, &kbdtty);
+ return(xf86Info.consoleFd);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/vidmem.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/vidmem.c
new file mode 100644
index 000000000..237d47a4d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/vidmem.c
@@ -0,0 +1,300 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/vidmem.c,v 1.17 2003/08/24 17:37:06 dawes Exp $ */
+/*
+ * Copyright (c) 1993-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
+
+#ifdef __UNIXOS2__
+# define I_NEED_OS2_H
+#endif
+#include <X11/X.h>
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+/*
+ * This file contains the common part of the video memory mapping functions
+ */
+
+/*
+ * Get a piece of the ScrnInfoRec. At the moment, this is only used to hold
+ * the MTRR option information, but it is likely to be expanded if we do
+ * auto unmapping of memory at VT switch.
+ *
+ */
+
+typedef struct {
+ unsigned long physBase;
+ unsigned long size;
+ pointer virtBase;
+ pointer mtrrInfo;
+ int flags;
+} MappingRec, *MappingPtr;
+
+typedef struct {
+ int numMappings;
+ MappingPtr * mappings;
+ Bool mtrrEnabled;
+ MessageType mtrrFrom;
+ Bool mtrrOptChecked;
+ ScrnInfoPtr pScrn;
+} VidMapRec, *VidMapPtr;
+
+static int vidMapIndex = -1;
+
+#define VIDMAPPTR(p) ((VidMapPtr)((p)->privates[vidMapIndex].ptr))
+
+static VidMemInfo vidMemInfo = {FALSE, };
+static VidMapRec vidMapRec = {0, NULL, TRUE, X_DEFAULT, FALSE, NULL};
+
+static VidMapPtr
+getVidMapRec(int scrnIndex)
+{
+ VidMapPtr vp;
+ ScrnInfoPtr pScrn;
+
+ if ((scrnIndex < 0) ||
+ !(pScrn = xf86Screens[scrnIndex]))
+ return &vidMapRec;
+
+ if (vidMapIndex < 0)
+ vidMapIndex = xf86AllocateScrnInfoPrivateIndex();
+
+ if (VIDMAPPTR(pScrn) != NULL)
+ return VIDMAPPTR(pScrn);
+
+ vp = pScrn->privates[vidMapIndex].ptr = xnfcalloc(sizeof(VidMapRec), 1);
+ vp->mtrrEnabled = TRUE; /* default to enabled */
+ vp->mtrrFrom = X_DEFAULT;
+ vp->mtrrOptChecked = FALSE;
+ vp->pScrn = pScrn;
+ return vp;
+}
+
+static MappingPtr
+newMapping(VidMapPtr vp)
+{
+ vp->mappings = xnfrealloc(vp->mappings, sizeof(MappingPtr) *
+ (vp->numMappings + 1));
+ vp->mappings[vp->numMappings] = xnfcalloc(sizeof(MappingRec), 1);
+ return vp->mappings[vp->numMappings++];
+}
+
+static MappingPtr
+findMapping(VidMapPtr vp, pointer vbase, unsigned long size)
+{
+ int i;
+
+ for (i = 0; i < vp->numMappings; i++) {
+ if (vp->mappings[i]->virtBase == vbase &&
+ vp->mappings[i]->size == size)
+ return vp->mappings[i];
+ }
+ return NULL;
+}
+
+static void
+removeMapping(VidMapPtr vp, MappingPtr mp)
+{
+ int i, found = 0;
+
+ for (i = 0; i < vp->numMappings; i++) {
+ if (vp->mappings[i] == mp) {
+ found = 1;
+ xfree(vp->mappings[i]);
+ } else if (found) {
+ vp->mappings[i - 1] = vp->mappings[i];
+ }
+ }
+ vp->numMappings--;
+ vp->mappings[vp->numMappings] = NULL;
+}
+
+enum { OPTION_MTRR };
+static const OptionInfoRec opts[] =
+{
+ { OPTION_MTRR, "mtrr", OPTV_BOOLEAN, {0}, FALSE },
+ { -1, NULL, OPTV_NONE, {0}, FALSE }
+};
+
+static void
+checkMtrrOption(VidMapPtr vp)
+{
+ if (!vp->mtrrOptChecked && vp->pScrn && vp->pScrn->options != NULL) {
+ OptionInfoPtr options;
+
+ options = xnfalloc(sizeof(opts));
+ (void)memcpy(options, opts, sizeof(opts));
+ xf86ProcessOptions(vp->pScrn->scrnIndex, vp->pScrn->options,
+ options);
+ if (xf86GetOptValBool(options, OPTION_MTRR, &vp->mtrrEnabled))
+ vp->mtrrFrom = X_CONFIG;
+ xfree(options);
+ vp->mtrrOptChecked = TRUE;
+ }
+}
+
+void
+xf86MakeNewMapping(int ScreenNum, int Flags, unsigned long Base, unsigned long Size, pointer Vbase)
+{
+ VidMapPtr vp;
+ MappingPtr mp;
+
+ vp = getVidMapRec(ScreenNum);
+ mp = newMapping(vp);
+ mp->physBase = Base;
+ mp->size = Size;
+ mp->virtBase = Vbase;
+ mp->flags = Flags;
+}
+
+void
+xf86InitVidMem(void)
+{
+ if (!vidMemInfo.initialised) {
+ memset(&vidMemInfo, 0, sizeof(VidMemInfo));
+ xf86OSInitVidMem(&vidMemInfo);
+ }
+}
+
+pointer
+xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
+{
+ pointer vbase = NULL;
+ VidMapPtr vp;
+ MappingPtr mp;
+
+ if (((Flags & VIDMEM_FRAMEBUFFER) &&
+ (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT))))
+ FatalError("Mapping memory with more than one type\n");
+
+ xf86InitVidMem();
+ if (!vidMemInfo.initialised || !vidMemInfo.mapMem)
+ return NULL;
+
+ vbase = vidMemInfo.mapMem(ScreenNum, Base, Size, Flags);
+
+ if (!vbase || vbase == (pointer)-1)
+ return NULL;
+
+ vp = getVidMapRec(ScreenNum);
+ mp = newMapping(vp);
+ mp->physBase = Base;
+ mp->size = Size;
+ mp->virtBase = vbase;
+ mp->flags = Flags;
+
+ /*
+ * Check the "mtrr" option even when MTRR isn't supported to avoid
+ * warnings about unrecognised options.
+ */
+ checkMtrrOption(vp);
+
+ if (vp->mtrrEnabled && vidMemInfo.setWC) {
+ if (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT))
+ mp->mtrrInfo =
+ vidMemInfo.setWC(ScreenNum, Base, Size, FALSE,
+ vp->mtrrFrom);
+ else if (Flags & VIDMEM_FRAMEBUFFER)
+ mp->mtrrInfo =
+ vidMemInfo.setWC(ScreenNum, Base, Size, TRUE,
+ vp->mtrrFrom);
+ }
+ return vbase;
+}
+
+void
+xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ VidMapPtr vp;
+ MappingPtr mp;
+
+ if (!vidMemInfo.initialised || !vidMemInfo.unmapMem) {
+ xf86DrvMsg(ScreenNum, X_WARNING,
+ "xf86UnMapVidMem() called before xf86MapVidMem()\n");
+ return;
+ }
+
+ vp = getVidMapRec(ScreenNum);
+ mp = findMapping(vp, Base, Size);
+ if (!mp) {
+ xf86DrvMsg(ScreenNum, X_WARNING,
+ "xf86UnMapVidMem: cannot find region for [%p,0x%lx]\n",
+ Base, Size);
+ return;
+ }
+ if (vp->mtrrEnabled && vidMemInfo.undoWC && mp)
+ vidMemInfo.undoWC(ScreenNum, mp->mtrrInfo);
+
+ vidMemInfo.unmapMem(ScreenNum, Base, Size);
+ removeMapping(vp, mp);
+}
+
+Bool
+xf86CheckMTRR(int ScreenNum)
+{
+ VidMapPtr vp = getVidMapRec(ScreenNum);
+
+ /*
+ * Check the "mtrr" option even when MTRR isn't supported to avoid
+ * warnings about unrecognised options.
+ */
+ checkMtrrOption(vp);
+
+ if (vp->mtrrEnabled && vidMemInfo.setWC)
+ return TRUE;
+
+ return FALSE;
+}
+
+Bool
+xf86LinearVidMem()
+{
+ xf86InitVidMem();
+ return vidMemInfo.linearSupported;
+}
+
+void
+xf86MapReadSideEffects(int ScreenNum, int Flags, pointer base,
+ unsigned long Size)
+{
+ if (!(Flags & VIDMEM_READSIDEEFFECT))
+ return;
+
+ if (!vidMemInfo.initialised || !vidMemInfo.readSideEffects)
+ return;
+
+ vidMemInfo.readSideEffects(ScreenNum, base, Size);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/xf86Axp.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/xf86Axp.c
new file mode 100644
index 000000000..b8953f119
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/xf86Axp.c
@@ -0,0 +1,50 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/xf86Axp.c,v 1.3 2003/08/24 17:37:06 dawes Exp $ */
+/*
+ * Copyright (c) 2000 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
+
+#include "xf86Axp.h"
+
+axpParams xf86AXPParams[] = {
+ {SYS_NONE, 0, 0, 0},
+ {TSUNAMI, 0, 0, 0},
+ {LCA, 1<<24,0xf8000000, 1UL << 32},
+ {APECS, 1<<24,0xf8000000, 1UL << 32},
+ {T2, 0,0xFC000000, 1UL << 31},
+ {T2_GAMMA, 0,0xFC000000, 1UL << 31},
+ {CIA, 0,0xE0000000, 1UL << 34},
+ {MCPCIA, 0,0xf8000000, 1UL << 31},
+ {JENSEN, 0, 0xE000000, 1UL << 32},
+ {POLARIS, 0, 0, 0},
+ {PYXIS, 0, 0, 0},
+ {PYXIS_CIA, 0,0xE0000000, 1UL << 34},
+ {IRONGATE, 0, 0, 0}
+};
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/xf86Axp.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/xf86Axp.h
new file mode 100644
index 000000000..4b8b08370
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/shared/xf86Axp.h
@@ -0,0 +1,36 @@
+/* $XFree86$ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _XF86_AXP_H_
+#define _XF86_AXP_H_
+
+typedef enum {
+ SYS_NONE,
+ TSUNAMI,
+ LCA,
+ APECS,
+ T2,
+ T2_GAMMA,
+ CIA,
+ MCPCIA,
+ JENSEN,
+ POLARIS,
+ PYXIS,
+ PYXIS_CIA,
+ IRONGATE
+} axpDevice;
+
+typedef struct {
+ axpDevice id;
+ unsigned long hae_thresh;
+ unsigned long hae_mask;
+ unsigned long size;
+} axpParams;
+
+extern axpParams xf86AXPParams[];
+
+#endif
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/Imakefile
new file mode 100644
index 000000000..2ef24f5e4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/Imakefile
@@ -0,0 +1,119 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/Imakefile,v 1.4 2002/10/17 02:22:49 dawes Exp $
+XCOMM $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/Imakefile,v 1.8 2005/11/06 03:49:22 alanc Exp $
+XCOMM
+XCOMM Copyright 2001 The XFree86 Project, Inc. All Rights Reserved.
+XCOMM
+XCOMM Permission is hereby granted, free of charge, to any person obtaining a
+XCOMM copy of this software and associated documentation files (the
+XCOMM "Software"), to deal in the Software without restriction, including
+XCOMM without limitation the rights to use, copy, modify, merge, publish,
+XCOMM distribute, sublicense, and/or sell copies of the Software, and to permit
+XCOMM persons to whom the Software is furnished to do so, subject to the
+XCOMM following conditions:
+XCOMM
+XCOMM The above copyright notice and this permission notice shall be included
+XCOMM in all copies or substantial portions of the Software.
+XCOMM
+XCOMM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+XCOMM OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+XCOMM MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+XCOMM IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR
+XCOMM OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+XCOMM ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+XCOMM OTHER DEALINGS IN THE SOFTWARE.
+XCOMM
+XCOMM Except as contained in this notice, the name of the XFree86 Project shall
+XCOMM not be used in advertising or otherwise to promote the sale, use or other
+XCOMM dealings in this Software without prior written authorization from the
+XCOMM XFree86 Project.
+XCOMM
+
+/* This is a combined Imakefile intended for all SunOS variants */
+
+#include <Server.tmpl>
+
+#if !HasGcc
+# if HasSunC
+# if !defined(AsmArch) || !defined(AsmFlags)
+# error "Unsupported Architecture for building Xorg server with Sun compilers."
+# error "Need to use gcc or add AsmArch & AsmFlag settings in xc/config/cf/sun.cf"
+# endif
+PROWORKS_ASM_ARCH = AsmArch
+PROWORKS_ASM_FLAGS = AsmFlags
+PROWORKS_INOUT_SRC = solaris-$(PROWORKS_ASM_ARCH).S
+PROWORKS_INOUT_OBJ = solaris-$(PROWORKS_ASM_ARCH).o
+
+all:: $(PROWORKS_ASM_ARCH).il
+includes:: $(PROWORKS_ASM_ARCH).il
+
+CppFileTarget($(PROWORKS_ASM_ARCH).il,solaris-$(PROWORKS_ASM_ARCH).S,-DINLINE_ASM,NullParameter)
+
+$(PROWORKS_INOUT_OBJ): $(PROWORKS_INOUT_SRC)
+ $(AS) -P -o $@ $(PROWORKS_ASM_FLAGS) $(PROWORKS_INOUT_SRC)
+
+# elif defined(i386Architecture)
+PROWORKS_INOUT_SRC = sun_inout.s
+PROWORKS_INOUT_OBJ = sun_inout.o
+# endif
+#endif
+
+#if defined(i386Architecture) && (OSMinorVersion < 8)
+IO_SRC = sysv_io.c
+IO_OBJ = sysv_io.o
+KBD_SRCS = sysv_kbd.c std_kbdEv.c
+KBD_OBJS = sysv_kbd.o std_kbdEv.o
+VTSW_SRC = VTsw_usl.c
+VTSW_OBJ = VTsw_usl.o
+#else
+IO_SRC = sun_io.c
+IO_OBJ = sun_io.o
+KBD_SRCS = sun_kbd.c sun_kbdEv.c
+KBD_OBJS = sun_kbd.o sun_kbdEv.o
+VTSW_SRC = VTsw_noop.c
+VTSW_OBJ = VTsw_noop.o
+#endif
+
+#if defined(i386Architecture) || defined(AMD64Architecture)
+AGP_SRC = sun_agp.c
+AGP_OBJ = sun_agp.o
+#else
+AGP_SRC = agp_noop.c
+AGP_OBJ = agp_noop.o
+#endif
+
+#ifdef SVR4Architecture
+SYSVIPCDEFINES = -DHAVE_SYSV_IPC
+#endif
+
+SRCS = sun_bios.c sun_init.c $(IO_SRC) $(KBD_SRCS) $(PROWORKS_INOUT_SRC) \
+ sun_mouse.c sun_vid.c $(AGP_SRC) libc_wrapper.c kmod_noop.c pm_noop.c \
+ posix_tty.c sigiostubs.c stdPci.c stdResource.c $(VTSW_SRC)
+OBJS = sun_bios.o sun_init.o $(IO_OBJ) $(KBD_OBJS) $(PROWORKS_INOUT_OBJ) \
+ sun_mouse.o sun_vid.o $(AGP_OBJ) libc_wrapper.o kmod_noop.o pm_noop.o \
+ posix_tty.o sigiostubs.o stdPci.o stdResource.o $(VTSW_OBJ)
+
+INCLUDES = -I. -I$(XF86OSSRC) -I$(XF86COMSRC) \
+ -I$(SERVERSRC)/mi -I$(SERVERSRC)/include -I$(SERVERSRC)/Xext \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC)
+
+DEFINES = -DUSESTDRES $(VENDOR_DEFINES) $(SYSVIPCDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+NormalAsmObjectRule()
+
+LinkSourceFile($(VTSW_SRC),../shared)
+LinkSourceFile(agp_noop.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(std_kbdEv.c,../shared)
+LinkSourceFile(sysv_io.c,../sysv)
+LinkSourceFile(sysv_kbd.c,../shared)
+
+DependTarget()
+LintTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/agpgart.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/agpgart.h
new file mode 100644
index 000000000..637087527
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/agpgart.h
@@ -0,0 +1,109 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/agpgart.h,v 1.2 2005/07/01 22:43:25 daniels Exp $ */
+/*
+ * AGPGART module version 0.99
+ * Copyright (C) 1999 Jeff Hartmann
+ * Copyright (C) 1999 Precision Insight, Inc.
+ * Copyright (C) 1999 Xi Graphics, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * JEFF HARTMANN, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#ifndef _AGPGART_H
+#define _AGPGART_H
+
+#pragma ident "@(#)agpgart.h 1.1 05/04/04 SMI"
+
+typedef struct _agp_version {
+ uint16_t agpv_major;
+ uint16_t agpv_minor;
+} agp_version_t;
+
+typedef struct _agp_info {
+ agp_version_t agpi_version;
+ uint32_t agpi_devid; /* bridge vendor + device */
+ uint32_t agpi_mode; /* mode of bridge */
+ ulong_t agpi_aperbase; /* base of aperture */
+ size_t agpi_apersize; /* aperture range size */
+ uint32_t agpi_pgtotal; /* max number of pages in aperture */
+ uint32_t agpi_pgsystem; /* same as pg_total */
+ uint32_t agpi_pgused; /* NUMBER of currently used pages */
+} agp_info_t;
+
+typedef struct _agp_setup {
+ uint32_t agps_mode;
+} agp_setup_t;
+
+typedef struct _agp_allocate {
+ int32_t agpa_key;
+ uint32_t agpa_pgcount;
+ uint32_t agpa_type;
+ uint32_t agpa_physical; /* for i810/830 driver */
+} agp_allocate_t;
+
+typedef struct _agp_bind {
+ int32_t agpb_key;
+ uint32_t agpb_pgstart;
+} agp_bind_t;
+
+typedef struct _agp_unbind {
+ int32_t agpu_key;
+ uint32_t agpu_pri; /* no use in solaris */
+} agp_unbind_t;
+
+#define AGPIOC_BASE 'G'
+#define AGPIOC_INFO _IOR(AGPIOC_BASE, 0, 100)
+#define AGPIOC_ACQUIRE _IO(AGPIOC_BASE, 1)
+#define AGPIOC_RELEASE _IO(AGPIOC_BASE, 2)
+#define AGPIOC_SETUP _IOW(AGPIOC_BASE, 3, agp_setup_t)
+#define AGPIOC_ALLOCATE _IOWR(AGPIOC_BASE, 4, agp_allocate_t)
+#define AGPIOC_DEALLOCATE _IOW(AGPIOC_BASE, 5, int)
+#define AGPIOC_BIND _IOW(AGPIOC_BASE, 6, agp_bind_t)
+#define AGPIOC_UNBIND _IOW(AGPIOC_BASE, 7, agp_unbind_t)
+
+#define AGP_DEVICE "/dev/agpgart"
+
+#endif /* _AGPGART_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/find_deps.pl b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/find_deps.pl
new file mode 100755
index 000000000..2eac14f47
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/find_deps.pl
@@ -0,0 +1,150 @@
+#!/usr/bin/perl -w
+#
+# $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/find_deps.pl,v 1.2 2004/09/22 17:20:56 alanc Exp $
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, and/or sell copies of the Software, and to permit persons
+# to whom the Software is furnished to do so, provided that the above
+# copyright notice(s) and this permission notice appear in all copies of
+# the Software and that both the above copyright notice(s) and this
+# permission notice appear in supporting documentation.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+# Except as contained in this notice, the name of a copyright holder
+# shall not be used in advertising or otherwise to promote the sale, use
+# or other dealings in this Software without prior written authorization
+# of the copyright holder.
+#
+#------------------------------------------------------------------------------
+#
+# This script scans the X server, it's libraries, and shared object drivers
+# and generates the linker flags necessary to allow the shared object modules
+# to load via dlopen().
+#
+# WARNING: Do not try this at home boys and girls! Only trained professionals
+# should try this stunt. This script is not intended to serve as an example of
+# proper use of the linker or associated tools, but merely as an unfortunately
+# necessary bit of hackery to get Xserver modules to load via Solaris dlopen
+# instead of the XFree86 custom loader/runtime linker.
+#
+# No guarantee of usability or suitablity is made - in fact it's almost
+# guaranteed this is not suitable for any other use, and maybe not even
+# for the one it was intended.
+#
+# Usage: find_deps.pl [-R ProjectRoot] <paths_to_scan>
+# Expects to be called while cwd is a directory containing Xorg or XFree86
+# server binary.
+
+use strict;
+use File::Find;
+use Getopt::Std;
+
+my @objlist = ();
+my %symtable = ();
+
+my $servername;
+
+my $ProjectRoot = "/usr/X11R6";
+
+my %opts;
+getopts('R:', \%opts);
+if (exists($opts{"R"})) {
+ $ProjectRoot = $opts{"R"};
+}
+
+if (-f "Xorg") {
+ $servername = "Xorg";
+} elsif (-f "XFree86") {
+ $servername = "XFree86";
+} else {
+ die "Cannot find X server";
+}
+
+$File::Find::name = $servername;
+$_ = $servername;
+&scanobjs;
+
+find({wanted => \&scanobjs, preprocess => \&filterobjs}, @ARGV);
+
+for my $f (@objlist) {
+ open(ELFDUMP, "/usr/ccs/bin/elfdump -r $f|") || die "Cannot open file";
+ my $edline;
+ my %deps = ();
+ while ($edline = <ELFDUMP>) {
+ next unless $edline =~ /(GLOB_DAT|R_386_32|R_SPARC_32)/;
+ my @edpart = split /\s+/, $edline;
+ if (exists $symtable{$edpart[$#edpart]}) {
+# print "$f : $edpart[$#edpart] - $symtable{$edpart[$#edpart]}\n";
+ $deps{$symtable{$edpart[$#edpart]}} += 1;
+ } else {
+ print "$f : $edpart[$#edpart] - not found\n";
+ }
+ }
+ close(ELFDUMP);
+
+ my $depslist = "";
+
+ for my $d (sort keys %deps) {
+ next if ($f =~ /$d/ || $d !~ /\.so$/);
+ $depslist .= " -Wl,-N,$d";
+ }
+ print "$f : $depslist\n";
+ my $depsfile = $f ."_deps";
+ if ($depslist ne "") {
+ my $dirlist = "-R $ProjectRoot/lib/modules";
+ if ($f =~ /drivers/) {
+ $dirlist .= " -R $ProjectRoot/lib/modules/drivers";
+ }
+ if ($depslist =~ /libfbdevhw.so/) {
+ $dirlist .= " -R $ProjectRoot/lib/modules/linux/";
+ }
+ if ($depslist =~ /libGLcore.so/) {
+ $dirlist .= " -R $ProjectRoot/lib/modules/extensions/";
+ }
+
+ open(MODDEPSFILE, '>', $depsfile) || die "Cannot write to $depsfile";
+ print MODDEPSFILE $dirlist, $depslist, "\n";
+ close(MODDEPSFILE);
+ } elsif (! -z $depsfile) {
+ unlink($depsfile);
+ system("touch $depsfile");
+ }
+}
+
+
+sub filterobjs {
+ return (grep( ($_ =~ /\.so$/) || (-d $_) , @_));
+}
+
+sub scanobjs {
+ return if /libXfont.so/;
+ return if (-d $_);
+ print "Scanning $File::Find::name ...\n";
+ push @objlist, $File::Find::name;
+ open(NMOUT, "/usr/ccs/bin/nm $_|") || die "Cannot nm file $_";
+ my $nmline;
+ while ($nmline = <NMOUT>) {
+ next unless $nmline =~ /\|/;
+ my @nmpart = split(/\s*\|\s*/, $nmline);
+ next unless ($nmpart[4] eq "GLOB") && ($nmpart[6] ne "UNDEF");
+ chomp($nmpart[7]);
+ if (! exists $symtable{$nmpart[7]}) {
+ $symtable{$nmpart[7]} = $_;
+ }
+ }
+ close(NMOUT);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-amd64.S b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-amd64.S
new file mode 100644
index 000000000..9f5e58cb0
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-amd64.S
@@ -0,0 +1,73 @@
+/ Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+/
+/ Permission is hereby granted, free of charge, to any person obtaining a
+/ copy of this software and associated documentation files (the
+/ "Software"), to deal in the Software without restriction, including
+/ without limitation the rights to use, copy, modify, merge, publish,
+/ distribute, and/or sell copies of the Software, and to permit persons
+/ to whom the Software is furnished to do so, provided that the above
+/ copyright notice(s) and this permission notice appear in all copies of
+/ the Software and that both the above copyright notice(s) and this
+/ permission notice appear in supporting documentation.
+/
+/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+/ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+/ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+/ OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+/ HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+/ INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+/ FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+/ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+/ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+/
+/ Except as contained in this notice, the name of a copyright holder
+/ shall not be used in advertising or otherwise to promote the sale, use
+/ or other dealings in this Software without prior written authorization
+/ of the copyright holder.
+
+#ifdef INLINE_ASM
+#define FUNCTION_START(f,n) .inline f,n
+#define FUNCTION_END(f) .end
+#else
+#define _ASM
+#include <sys/asm_linkage.h>
+#define FUNCTION_START(f,n) ENTRY(f)
+#define FUNCTION_END(f) SET_SIZE(f)
+#endif
+
+ FUNCTION_START(inb,4)
+ movq %rdi, %rdx
+ xorq %rax, %rax
+ inb (%dx)
+ FUNCTION_END(inb)
+
+ FUNCTION_START(inw,4)
+ movq %rdi, %rdx
+ xorq %rax, %rax
+ inw (%dx)
+ FUNCTION_END(inw)
+
+ FUNCTION_START(inl,4)
+ movq %rdi, %rdx
+ xorq %rax, %rax
+ inl (%dx)
+ FUNCTION_END(inl)
+
+ FUNCTION_START(outb,8)
+ movq %rdi, %rdx
+ movq %rsi, %rax
+ outb (%dx)
+ FUNCTION_END(outb)
+
+ FUNCTION_START(outw,8)
+ movq %rdi, %rdx
+ movq %rsi, %rax
+ outw (%dx)
+ FUNCTION_END(outw)
+
+ FUNCTION_START(outl,8)
+ movq %rdi, %rdx
+ movq %rsi, %rax
+ outl (%dx)
+ FUNCTION_END(outl)
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-ia32.S b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-ia32.S
new file mode 100644
index 000000000..e2d9cf60a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-ia32.S
@@ -0,0 +1,73 @@
+/ Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+/
+/ Permission is hereby granted, free of charge, to any person obtaining a
+/ copy of this software and associated documentation files (the
+/ "Software"), to deal in the Software without restriction, including
+/ without limitation the rights to use, copy, modify, merge, publish,
+/ distribute, and/or sell copies of the Software, and to permit persons
+/ to whom the Software is furnished to do so, provided that the above
+/ copyright notice(s) and this permission notice appear in all copies of
+/ the Software and that both the above copyright notice(s) and this
+/ permission notice appear in supporting documentation.
+/
+/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+/ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+/ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+/ OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+/ HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+/ INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+/ FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+/ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+/ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+/
+/ Except as contained in this notice, the name of a copyright holder
+/ shall not be used in advertising or otherwise to promote the sale, use
+/ or other dealings in this Software without prior written authorization
+/ of the copyright holder.
+
+#ifdef INLINE_ASM
+#define FUNCTION_START(f,n) .inline f,n
+#define FUNCTION_END(f) .end
+#else
+#define _ASM
+#include <sys/asm_linkage.h>
+#define FUNCTION_START(f,n) ENTRY(f)
+#define FUNCTION_END(f) SET_SIZE(f)
+#endif
+
+ FUNCTION_START(inb,4)
+ movl (%esp), %edx
+ xorl %eax, %eax
+ inb (%dx)
+ FUNCTION_END(inb)
+
+ FUNCTION_START(inw,4)
+ movl (%esp), %edx
+ xorl %eax, %eax
+ inw (%dx)
+ FUNCTION_END(inw)
+
+ FUNCTION_START(inl,4)
+ movl (%esp), %edx
+ xorl %eax, %eax
+ inl (%dx)
+ FUNCTION_END(inl)
+
+ FUNCTION_START(outb,8)
+ movl (%esp), %edx
+ movl 4(%esp), %eax
+ outb (%dx)
+ FUNCTION_END(outb)
+
+ FUNCTION_START(outw,8)
+ movl (%esp), %edx
+ movl 4(%esp), %eax
+ outw (%dx)
+ FUNCTION_END(outw)
+
+ FUNCTION_START(outl,8)
+ movl (%esp), %edx
+ movl 4(%esp), %eax
+ outl (%dx)
+ FUNCTION_END(outl)
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-sparcv8plus.S b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-sparcv8plus.S
new file mode 100644
index 000000000..fb23942ef
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/solaris-sparcv8plus.S
@@ -0,0 +1,144 @@
+/* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#ifdef INLINE_ASM
+#define FUNCTION_START(f,n) .inline f,n
+#define FUNCTION_END(f) .end
+#else
+#define _ASM
+#include <sys/asm_linkage.h>
+#define FUNCTION_START(f,n) ENTRY(f)
+#define FUNCTION_END(f) SET_SIZE(f)
+#endif
+
+/* Converted from common/compiler.h gcc inline format to Sun cc inline
+ * format by Kenjiro Tsuji
+ *
+ * The value 0x88 means ASI_PRIMARY_LITTLE.
+ * The store or load to/from the address space will be done
+ * as little-endian. In the original xrog code, the value
+ * is defined as the macro ASI_PL.
+ *
+ * In the original xorg code, "membar #StoreStore|#StoreLoad"
+ * is directly implemented as an instruction "0x8143e00a".
+ *
+ */
+
+ FUNCTION_START(outb, 0)
+ stba %o1, [%o0] 0x88
+ membar #StoreStore|#StoreLoad
+ FUNCTION_END(outb)
+
+ FUNCTION_START(outw, 0)
+ stha %o1, [%o0] 0x88
+ membar #StoreStore|#StoreLoad
+ FUNCTION_END(outw)
+
+ FUNCTION_START(outl, 0)
+ sta %o1, [%o0] 0x88
+ membar #StoreStore|#StoreLoad
+ FUNCTION_END(outl)
+
+ FUNCTION_START(inb, 0)
+ lduba [%o0] 0x88, %o0
+ FUNCTION_END(inb)
+
+ FUNCTION_START(inw, 0)
+ lduha [%o0] 0x88, %o0
+ FUNCTION_END(inw)
+
+ FUNCTION_START(inl, 0)
+ lda [%o0] 0x88, %o0
+ FUNCTION_END(inl)
+
+ FUNCTION_START(xf86ReadMmio8, 0)
+ lduba [%o0 + %o1] 0x88, %o0
+ FUNCTION_END(xf86ReadMmio8)
+
+ FUNCTION_START(xf86ReadMmio16Be, 0)
+ lduh [%o0 + %o1], %o0
+ FUNCTION_END(xf86ReadMmio16Be)
+
+ FUNCTION_START(xf86ReadMmio16Le, 0)
+ lduha [%o0 + %o1] 0x88, %o0
+ FUNCTION_END(xf86ReadMmio16Le)
+
+ FUNCTION_START(xf86ReadMmio32Be, 0)
+ ld [%o0 + %o1], %o0
+ FUNCTION_END(xf86ReadMmio32Be)
+
+ FUNCTION_START(xf86ReadMmio32Le, 0)
+ lda [%o0 + %o1] 0x88, %o0
+ FUNCTION_END(xf86ReadMmio32Le)
+
+ FUNCTION_START(xf86WriteMmio8, 0)
+ stba %o2, [%o0 + %o1] 0x88
+ membar #StoreStore|#StoreLoad
+ FUNCTION_END(xf86WriteMmio8)
+
+ FUNCTION_START(xf86WriteMmio16Be, 0)
+ sth %o2, [%o0 + %o1]
+ membar #StoreStore|#StoreLoad
+ FUNCTION_END(xf86WriteMmio16Be)
+
+ FUNCTION_START(xf86WriteMmio16Le, 0)
+ stha %o2, [%o0 + %o1] 0x88
+ membar #StoreStore|#StoreLoad
+ FUNCTION_END(xf86WriteMmio16Le)
+
+ FUNCTION_START(xf86WriteMmio32Be, 0)
+ st %o2, [%o0 + %o1]
+ membar #StoreStore|#StoreLoad
+ FUNCTION_END(xf86WriteMmio32Be)
+
+ FUNCTION_START(xf86WriteMmio32Le, 0)
+ sta %o2, [%o0 + %o1] 0x88
+ membar #StoreStore|#StoreLoad
+ FUNCTION_END(xf86WriteMmio32Le)
+
+ FUNCTION_START(xf86WriteMmio8NB, 0)
+ add %o0, %o1, %o0
+ stba %o2, [%o0] 0x88
+ FUNCTION_END(xf86WriteMmio8NB)
+
+ FUNCTION_START(xf86WriteMmio16BeNB, 0)
+ sth %o2, [%o0 + %o1]
+ FUNCTION_END(xf86WriteMmio16BeNB)
+
+ FUNCTION_START(xf86WriteMmio16LeNB, 0)
+ stha %o2, [%o0 + %o1] 0x88
+ FUNCTION_END(xf86WriteMmio16LeNB)
+
+ FUNCTION_START(xf86WriteMmio32BeNB, 0)
+ st %o2, [%o0 + %o1]
+ FUNCTION_END(xf86WriteMmio32BeNB)
+
+ FUNCTION_START(xf86WriteMmio32LeNB, 0)
+ sta %o2, [%o0 + %o1] 0x88
+ FUNCTION_END(xf86WriteMmio32LeNB)
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_agp.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_agp.c
new file mode 100644
index 000000000..0460f1299
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_agp.c
@@ -0,0 +1,339 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_agp.c,v 1.5 2005/08/24 22:37:15 alanc Exp $ */
+/*
+ * Abstraction of the AGP GART interface.
+ *
+ * This version is for Solaris.
+ *
+ * Copyright © 2000 VA Linux Systems, Inc.
+ * Copyright © 2001 The XFree86 Project, Inc.
+ */
+/* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident "@(#)sun_agp.c 1.1 05/04/04 SMI"
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86_OSproc.h"
+#include <unistd.h>
+#include <sys/ioccom.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include "agpgart.h"
+
+#ifndef AGP_DEVICE
+#define AGP_DEVICE "/dev/agpgart"
+#endif
+/* AGP page size is independent of the host page size. */
+#ifndef AGP_PAGE_SIZE
+#define AGP_PAGE_SIZE 4096
+#endif
+
+static int gartFd = -1;
+static int acquiredScreen = -1;
+static Bool initDone = FALSE;
+/*
+ * Close /dev/agpgart. This frees all associated memory allocated during
+ * this server generation.
+ */
+Bool
+xf86GARTCloseScreen(int screenNum)
+{
+ if (gartFd != -1) {
+ close(gartFd);
+ acquiredScreen = -1;
+ gartFd = -1;
+ initDone = FALSE;
+
+ xf86DrvMsg(screenNum, X_INFO,
+ "xf86GARTCloseScreen: device closed successfully\n");
+
+ }
+ return TRUE;
+}
+
+/*
+ * Open /dev/agpgart. Keep it open until xf86GARTCloseScreen is called.
+ */
+static Bool
+GARTInit(int screenNum)
+{
+ if (initDone)
+ return (gartFd != -1);
+
+ if (gartFd == -1)
+ gartFd = open(AGP_DEVICE, O_RDWR);
+ else
+ return FALSE;
+
+ if (gartFd == -1) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "GARTInit: Unable to open " AGP_DEVICE " (%s)\n",
+ strerror(errno));
+ return FALSE;
+ }
+
+ initDone = TRUE;
+ xf86DrvMsg(screenNum, X_INFO,
+ "GARTInit: " AGP_DEVICE " opened successfully\n");
+
+ return TRUE;
+}
+
+Bool
+xf86AgpGARTSupported(void)
+{
+ return (GARTInit(-1));
+
+}
+
+AgpInfoPtr
+xf86GetAGPInfo(int screenNum)
+{
+ agp_info_t agpinf;
+ AgpInfoPtr info;
+
+ if (!GARTInit(screenNum))
+ return NULL;
+
+ if ((info = xcalloc(sizeof(AgpInfo), 1)) == NULL) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "xf86GetAGPInfo: Failed to allocate AgpInfo\n");
+ return NULL;
+ }
+
+ if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) {
+ xf86DrvMsg(screenNum, X_ERROR,
+ "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n",
+ strerror(errno));
+ return NULL;
+ }
+
+ info->bridgeId = agpinf.agpi_devid;
+ info->agpMode = agpinf.agpi_mode;
+ info->base = agpinf.agpi_aperbase;
+ info->size = agpinf.agpi_apersize;
+ info->totalPages = (unsigned long)agpinf.agpi_pgtotal;
+ info->systemPages = (unsigned long)agpinf.agpi_pgsystem;
+ info->usedPages = (unsigned long)agpinf.agpi_pgused;
+
+ return info;
+}
+
+Bool
+xf86AcquireGART(int screenNum)
+{
+
+ if (!GARTInit(screenNum))
+ return FALSE;
+
+ if (acquiredScreen != screenNum) {
+ if (ioctl(gartFd, AGPIOC_ACQUIRE, 0) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "xf86AcquireGART: AGPIOC_ACQUIRE failed (%s)\n",
+ strerror(errno));
+ return FALSE;
+ }
+ acquiredScreen = screenNum;
+ xf86DrvMsg(screenNum, X_INFO,
+ "xf86AcquireGART: AGPIOC_ACQUIRE succeeded\n");
+ }
+ return TRUE;
+}
+
+Bool
+xf86ReleaseGART(int screenNum)
+{
+
+ if (!GARTInit(screenNum))
+ return FALSE;
+
+ if (acquiredScreen == screenNum) {
+ /*
+ * The FreeBSD agp driver removes allocations on release.
+ * The Solaris driver doesn't. xf86ReleaseGART() is expected
+ * to give up access to the GART, but not to remove any
+ * allocations.
+ */
+
+ if (ioctl(gartFd, AGPIOC_RELEASE, 0) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING,
+ "xf86ReleaseGART: AGPIOC_RELEASE failed (%s)\n",
+ strerror(errno));
+ return FALSE;
+ }
+ acquiredScreen = -1;
+ xf86DrvMsg(screenNum, X_INFO,
+ "xf86ReleaseGART: AGPIOC_RELEASE succeeded\n");
+ return TRUE;
+ }
+ return FALSE;
+}
+
+int
+xf86AllocateGARTMemory(int screenNum, unsigned long size, int type,
+ unsigned long *physical)
+{
+ agp_allocate_t alloc;
+ int pages;
+
+ /*
+ * Allocates "size" bytes of GART memory (rounds up to the next
+ * page multiple) or type "type". A handle (key) for the allocated
+ * memory is returned. On error, the return value is -1.
+ * "size" should be larger than 0, or AGPIOC_ALLOCATE ioctl will
+ * return error.
+ */
+
+ if (!GARTInit(screenNum) || (acquiredScreen != screenNum))
+ return -1;
+
+ pages = (size / AGP_PAGE_SIZE);
+ if (size % AGP_PAGE_SIZE != 0)
+ pages++;
+
+ alloc.agpa_pgcount = pages;
+ alloc.agpa_type = type;
+
+ if (ioctl(gartFd, AGPIOC_ALLOCATE, &alloc) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86AllocateGARTMemory: "
+ "allocation of %d pages failed\n\t(%s)\n", pages,
+ strerror(errno));
+ return -1;
+ }
+
+ if (physical)
+ *physical = (unsigned long)alloc.agpa_physical;
+
+ return alloc.agpa_key;
+}
+
+Bool
+xf86DeallocateGARTMemory(int screenNum, int key)
+{
+ if (!GARTInit(screenNum) || (acquiredScreen != screenNum))
+ return FALSE;
+
+ if (ioctl(gartFd, AGPIOC_DEALLOCATE, (int *)key) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86DeAllocateGARTMemory: "
+ "deallocation of gart memory with key %d failed\n"
+ "\t(%s)\n", key, strerror(errno));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Bind GART memory with "key" at "offset" */
+Bool
+xf86BindGARTMemory(int screenNum, int key, unsigned long offset)
+{
+ agp_bind_t bind;
+ int pageOffset;
+
+ if (!GARTInit(screenNum) || (acquiredScreen != screenNum))
+ return FALSE;
+
+ if (offset % AGP_PAGE_SIZE != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: "
+ "offset (0x%lx) is not page-aligned (%d)\n",
+ offset, AGP_PAGE_SIZE);
+ return FALSE;
+ }
+ pageOffset = offset / AGP_PAGE_SIZE;
+
+ xf86DrvMsgVerb(screenNum, X_INFO, 3,
+ "xf86BindGARTMemory: bind key %d at 0x%08lx "
+ "(pgoffset %d)\n", key, offset, pageOffset);
+
+ bind.agpb_pgstart = pageOffset;
+ bind.agpb_key = key;
+
+ if (ioctl(gartFd, AGPIOC_BIND, &bind) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: "
+ "binding of gart memory with key %d\n"
+ "\tat offset 0x%lx failed (%s)\n",
+ key, offset, strerror(errno));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Unbind GART memory with "key" */
+Bool
+xf86UnbindGARTMemory(int screenNum, int key)
+{
+ agp_unbind_t unbind;
+
+ if (!GARTInit(screenNum) || (acquiredScreen != screenNum))
+ return FALSE;
+
+ unbind.agpu_pri = 0;
+ unbind.agpu_key = key;
+
+ if (ioctl(gartFd, AGPIOC_UNBIND, &unbind) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86UnbindGARTMemory: "
+ "unbinding of gart memory with key %d "
+ "failed (%s)\n", key, strerror(errno));
+ return FALSE;
+ }
+
+ xf86DrvMsgVerb(screenNum, X_INFO, 3,
+ "xf86UnbindGARTMemory: unbind key %d\n", key);
+
+ return TRUE;
+}
+
+
+/* XXX Interface may change. */
+Bool
+xf86EnableAGP(int screenNum, CARD32 mode)
+{
+ agp_setup_t setup;
+
+ if (!GARTInit(screenNum) || (acquiredScreen != screenNum))
+ return FALSE;
+
+ setup.agps_mode = mode;
+ if (ioctl(gartFd, AGPIOC_SETUP, &setup) != 0) {
+ xf86DrvMsg(screenNum, X_WARNING, "xf86EnableAGP: "
+ "AGPIOC_SETUP with mode %x failed (%s)\n",
+ mode, strerror(errno));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_bios.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_bios.c
new file mode 100644
index 000000000..8319de04e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_bios.c
@@ -0,0 +1,104 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_bios.c,v 1.2tsi Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ * Copyright 1999 by David Holland <davidh@iquest.net>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the names of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
+ * SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef i386
+#define _NEED_SYSI86
+#endif
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+extern char *apertureDevName;
+
+/*
+ * Read BIOS via mmap()ing physical memory.
+ */
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+ int Len)
+{
+ int fd;
+ unsigned char *ptr;
+ char solx86_vtname[20];
+ int psize;
+ int mlen;
+
+ /*
+ * Solaris 2.1 x86 SVR4 (10/27/93)
+ * The server must treat the virtual terminal device file
+ * as the standard SVR4 /dev/pmem. By default, then used VT
+ * is considered the "default" file to open.
+ *
+ * Solaris 2.8 x86 (7/26/99) - DWH
+ *
+ * Use /dev/xsvc for everything.
+ */
+ psize = xf86getpagesize();
+ Offset += Base & (psize - 1);
+ Base &= ~(psize - 1);
+ mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+#if defined(i386) && !defined(__SOL8__)
+ if (Base >= 0xA0000 && Base + mlen < 0xFFFFF && xf86Info.vtno >= 0)
+ sprintf(solx86_vtname, "/dev/vt%02d", xf86Info.vtno);
+ else
+#endif
+ {
+ if (!xf86LinearVidMem())
+ FatalError("xf86ReadBIOS: Could not mmap BIOS"
+ " [a=%lx]\n", Base);
+ sprintf(solx86_vtname, apertureDevName);
+ }
+
+ if ((fd = open(solx86_vtname, O_RDONLY)) < 0)
+ {
+ xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
+ solx86_vtname, strerror(errno));
+ return(-1);
+ }
+ ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ,
+ MAP_SHARED, fd, (off_t)Base);
+ if (ptr == MAP_FAILED)
+ {
+ xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed "
+ "[0x%08lx, 0x%04x]\n",
+ solx86_vtname, Base, mlen);
+ close(fd);
+ return -1;
+ }
+
+ (void)memcpy(Buf, (void *)(ptr + Offset), Len);
+ (void)munmap((caddr_t)ptr, mlen);
+ (void)close(fd);
+
+ return Len;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_init.c
new file mode 100644
index 000000000..b2fc3a41e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_init.c
@@ -0,0 +1,393 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_init.c,v 1.5 2001/11/25 13:51:24 tsi Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ * Copyright 1999 by David Holland <davidh@iquest.net>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the names of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_init.c,v 1.5 2005/07/03 07:01:36 daniels Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#if defined(__i386) || defined(__x86)
+# include <sys/kd.h>
+#endif
+
+static Bool KeepTty = FALSE;
+static Bool Protect0 = FALSE;
+#ifdef HAS_USL_VTS
+static int VTnum = -1;
+static int xf86StartVT = -1;
+#endif
+
+#if defined(__SOL8__) || !defined(__i386)
+static char fb_dev[PATH_MAX] = "/dev/fb";
+#else
+static char fb_dev[PATH_MAX] = "/dev/console";
+#endif
+
+void
+xf86OpenConsole(void)
+{
+#ifdef HAS_USL_VTS
+ int fd, i;
+ struct vt_mode VT;
+ struct vt_stat vtinfo;
+ int FreeVTslot;
+ MessageType from = X_PROBED;
+#endif
+
+ if (serverGeneration == 1)
+ {
+ /* Check if we're run with euid==0 */
+ if (geteuid() != 0)
+ FatalError("xf86OpenConsole: Server must be suid root\n");
+
+ /* Protect page 0 to help find NULL dereferencing */
+ /* mprotect() doesn't seem to work */
+ if (Protect0)
+ {
+ int fd = -1;
+
+ if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0)
+ {
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: cannot open /dev/zero (%s)\n",
+ strerror(errno));
+ }
+ else
+ {
+ if ((int)mmap(0, 0x1000, PROT_NONE,
+ MAP_FIXED | MAP_SHARED, fd, 0) == -1)
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: failed to protect page 0 (%s)\n",
+ strerror(errno));
+
+ close(fd);
+ }
+ }
+
+#ifdef HAS_USL_VTS
+
+ /*
+ * Setup the virtual terminal manager
+ */
+ if (VTnum != -1)
+ {
+ xf86Info.vtno = VTnum;
+ from = X_CMDLINE;
+ }
+ else
+ {
+ if ((fd = open("/dev/vt00",O_RDWR,0)) < 0)
+ FatalError("xf86OpenConsole: Cannot open /dev/vt00 (%s)\n",
+ strerror(errno));
+
+ if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0)
+ FatalError("xf86OpenConsole: Cannot determine current VT\n");
+
+ xf86StartVT = vtinfo.v_active;
+
+ /*
+ * There is a SEVERE problem with x86's VT's. The VT_OPENQRY
+ * ioctl() will panic the entire system if all 8 (7 VT's+Console)
+ * terminals are used. The only other way I've found to determine
+ * if there is a free VT is to try activating all the the available
+ * VT's and see if they all succeed - if they do, there there is no
+ * free VT, and the Xserver cannot continue without panic'ing the
+ * system. (It's ugly, but it seems to work.) Note there is a
+ * possible race condition here.
+ *
+ * David Holland 2/23/94
+ */
+
+ FreeVTslot = 0;
+ for (i = 7; (i >= 0) && !FreeVTslot; i--)
+ if (ioctl(fd, VT_ACTIVATE, i) != 0)
+ FreeVTslot = 1;
+
+ if (!FreeVTslot ||
+ (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
+ (xf86Info.vtno == -1))
+ FatalError("xf86OpenConsole: Cannot find a free VT\n");
+
+ close(fd);
+ }
+
+ xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno);
+
+ sprintf(fb_dev, "/dev/vt%02d", xf86Info.vtno); /* Solaris 2.1 x86 */
+
+#endif /* HAS_USL_VTS */
+
+ if (!KeepTty)
+ setpgrp();
+
+ if (((xf86Info.consoleFd = open(fb_dev, O_RDWR | O_NDELAY, 0)) < 0))
+ FatalError("xf86OpenConsole: Cannot open %s (%s)\n",
+ fb_dev, strerror(errno));
+
+#ifdef HAS_USL_VTS
+
+ /* Change ownership of the vt */
+ chown(fb_dev, getuid(), getgid());
+
+ /*
+ * Now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
+
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
+ FatalError("xf86OpenConsole: VT_GETMODE failed\n");
+
+ signal(SIGUSR1, xf86VTRequest);
+
+ VT.mode = VT_PROCESS;
+ VT.relsig = SIGUSR1;
+ VT.acqsig = SIGUSR1;
+
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
+ FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
+#endif
+#ifdef KDSETMODE
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
+ FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n");
+#endif
+ }
+ else /* serverGeneration != 1 */
+ {
+#ifdef HAS_USL_VTS
+ /*
+ * Now re-get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
+
+ /*
+ * If the server doesn't have the VT when the reset occurs,
+ * this is to make sure we don't continue until the activate
+ * signal is received.
+ */
+ if (!xf86Screens[0]->vtSema)
+ sleep(5);
+
+#endif /* HAS_USL_VTS */
+
+ }
+}
+
+void
+xf86CloseConsole(void)
+{
+#ifdef HAS_USL_VTS
+ struct vt_mode VT;
+#endif
+#if defined(__SOL8__) || !defined(i386)
+ int tmp;
+#endif
+
+#if !defined(i386) && !defined(__x86)
+
+ if (!xf86DoProbe && !xf86DoConfigure) {
+ int fd;
+
+ /*
+ * Wipe out framebuffer just like the non-SI Xsun server does. This
+ * could be improved by saving framebuffer contents in
+ * xf86OpenConsole() above and restoring them here. Also, it's unclear
+ * at this point whether this should be done for all framebuffers in
+ * the system, rather than only the console.
+ */
+ if ((fd = open("/dev/fb", O_RDWR, 0)) < 0) {
+ xf86Msg(X_WARNING,
+ "xf86CloseConsole(): unable to open framebuffer (%s)\n",
+ strerror(errno));
+ } else {
+ struct fbgattr fbattr;
+
+ if ((ioctl(fd, FBIOGATTR, &fbattr) < 0) &&
+ (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0)) {
+ xf86Msg(X_WARNING,
+ "xf86CloseConsole(): unable to retrieve framebuffer"
+ " attributes (%s)\n", strerror(errno));
+ } else {
+ pointer fbdata;
+
+ fbdata = mmap(NULL, fbattr.fbtype.fb_size,
+ PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (fbdata == MAP_FAILED) {
+ xf86Msg(X_WARNING,
+ "xf86CloseConsole(): unable to mmap framebuffer"
+ " (%s)\n", strerror(errno));
+ } else {
+ (void)memset(fbdata, 0, fbattr.fbtype.fb_size);
+ (void)munmap(fbdata, fbattr.fbtype.fb_size);
+ }
+ }
+
+ close(fd);
+ }
+ }
+
+#endif
+
+#ifdef KDSETMODE
+ /* Reset the display back to text mode */
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT);
+#endif
+
+#ifdef HAS_USL_VTS
+
+ /*
+ * Solaris 2.1 x86 doesn't seem to "switch" back to the console when the VT
+ * is relinquished and its mode is reset to auto. Also, Solaris 2.1 seems
+ * to associate vt00 with the console so I've opened the "console" back up
+ * and made it the active vt again in text mode and then closed it. There
+ * must be a better hack for this but I'm not aware of one at this time.
+ *
+ * Doug Anson 11/6/93
+ * danson@lgc.com
+ *
+ * Fixed - 12/5/93 - David Holland - davidh@dorite.use.com
+ * Did the whole thing similarly to the way linux does it
+ */
+
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
+ {
+ VT.mode = VT_AUTO; /* Set default vt handling */
+ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT);
+ }
+
+ /* Activate the VT that X was started on */
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86StartVT);
+
+#endif /* HAS_USL_VTS */
+
+ close(xf86Info.consoleFd);
+
+#if defined(__SOL8__) || !defined(i386)
+
+ /*
+ * This probably shouldn't be here. However, there is no corresponding
+ * xf86CloseKbd() routine - DWH
+ */
+
+ /* Set the keyboard into "indirect" mode and turn off even translation */
+ tmp = 0;
+ (void) ioctl(xf86Info.kbdFd, KIOCSDIRECT, &tmp);
+ tmp = TR_ASCII;
+ (void) ioctl(xf86Info.kbdFd, KIOCTRANS, &tmp);
+
+ close(xf86Info.kbdFd);
+
+#endif
+}
+
+int
+xf86ProcessArgument(int argc, char **argv, int i)
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful when
+ * debugging, so the server can receive keyboard signals.
+ */
+ if (!strcmp(argv[i], "-keeptty"))
+ {
+ KeepTty = TRUE;
+ return 1;
+ }
+
+ /*
+ * Undocumented flag to protect page 0 from read/write to help catch NULL
+ * pointer dereferences. This is purely a debugging flag.
+ */
+ if (!strcmp(argv[i], "-protect0"))
+ {
+ Protect0 = TRUE;
+ return 1;
+ }
+
+#ifdef HAS_USL_VTS
+
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+ {
+ UseMsg();
+ VTnum = -1;
+ return 0;
+ }
+
+ return 1;
+ }
+
+#endif /* HAS_USL_VTS */
+
+#if defined(__SOL8__) || !defined(i386)
+
+ if ((i + 1) < argc) {
+ if (!strcmp(argv[i], "-dev")) {
+ strncpy(fb_dev, argv[i+1], PATH_MAX);
+ fb_dev[PATH_MAX - 1] = '\0';
+ return 2;
+ }
+
+ if (!strcmp(argv[i], "-ar1")) {
+ xf86Info.kbdDelay = atoi(argv[i + 1]) * 1000;
+ return 2;
+ }
+
+ if (!strcmp(argv[i], "-ar2")) {
+ xf86Info.kbdRate = atoi(argv[i + 1]) * 1000;
+ return 2;
+ }
+ }
+
+#endif
+
+ return 0;
+}
+
+void xf86UseMsg()
+{
+#ifdef HAS_USL_VTS
+ ErrorF("vtXX Use the specified VT number\n");
+#endif
+#if defined(__SOL8__) || !defined(i386)
+ ErrorF("-dev <fb> Framebuffer device\n");
+ ErrorF("-ar1 <float> Set autorepeat initiate time (sec)\n");
+ ErrorF(" (if not using XKB)\n");
+ ErrorF("-ar2 <float> Set autorepeat interval time (sec)\n");
+ ErrorF(" (if not using XKB)\n");
+#endif
+ ErrorF("-keeptty Don't detach controlling tty\n");
+ ErrorF(" (for debugging only)\n");
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_inout.s b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_inout.s
new file mode 100644
index 000000000..5c0b23ef6
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_inout.s
@@ -0,0 +1,124 @@
+/ $XFree86$
+/
+/ Copyright 1994-2001 The XFree86 Project, Inc. All Rights Reserved.
+/
+/ Permission is hereby granted, free of charge, to any person obtaining a copy
+/ of this software and associated documentation files (the "Software"), to deal
+/ in the Software without restriction, including without limitation the rights
+/ to use, copy, modify, merge, publish, distribute, 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
+/ XFREE86 PROJECT 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 XFree86 Project 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
+/ XFree86 Project.
+/
+/
+/ File: sun_inout.s
+/
+/ Purpose: Provide inb(), inw(), inl(), outb(), outw(), outl() functions
+/ for Solaris x86 using the ProWorks compiler by SunPro
+/
+/ Author: Installed into XFree86 SuperProbe by Doug Anson (danson@lgc.com)
+/ Portions donated to XFree86 by Steve Dever (Steve.Dever@Eng.Sun.Com)
+/
+/ Synopsis: (c callable external declarations)
+/ extern unsigned char inb(int port);
+/ extern unsigned short inw(int port);
+/ extern unsigned long inl(int port);
+/ extern void outb(int port, unsigned char value);
+/ extern void outw(int port, unsigned short value);
+/ extern void outl(int port, unsigned long value);
+/
+
+.file "sunos_inout.s"
+.text
+
+.globl inb
+.globl inw
+.globl inl
+.globl outb
+.globl outw
+.globl outl
+
+/
+/ unsigned char inb(int port);
+/
+.align 4
+inb:
+ movl 4(%esp),%edx
+ subl %eax,%eax
+ inb (%dx)
+ ret
+.type inb,@function
+.size inb,.-inb
+
+/
+/ unsigned short inw(int port);
+/
+.align 4
+inw:
+ movl 4(%esp),%edx
+ subl %eax,%eax
+ inw (%dx)
+ ret
+.type inw,@function
+.size inw,.-inw
+
+/
+/ unsigned long inl(int port);
+/
+.align 4
+inl:
+ movl 4(%esp),%edx
+ inl (%dx)
+ ret
+.type inl,@function
+.size inl,.-inl
+
+/
+/ void outb(int port, unsigned char value);
+/
+.align 4
+outb:
+ movl 4(%esp),%edx
+ movl 8(%esp),%eax
+ outb (%dx)
+ ret
+.type outb,@function
+.size outb,.-outb
+
+/
+/ void outw(int port, unsigned short value);
+/
+.align 4
+outw:
+ movl 4(%esp),%edx
+ movl 8(%esp),%eax
+ outw (%dx)
+ ret
+.type outw,@function
+.size outw,.-outw
+
+/
+/ void outl(int port, unsigned long value);
+/
+.align 4
+outl:
+ movl 4(%esp),%edx
+ movl 8(%esp),%eax
+ outl (%dx)
+ ret
+.type outl,@function
+.size outl,.-outl
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_io.c
new file mode 100644
index 000000000..2269ef3c9
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_io.c
@@ -0,0 +1,160 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_io.c,v 1.2 2002/10/11 01:40:37 dawes Exp $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_io.c,v 1.4 2005/08/13 00:11:28 alanc Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Dawes makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID DAWES DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL THOMAS ROELL OR DAVID DAWES BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+/* Solaris support routines for builtin "keyboard" driver */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "sun_kbd.h"
+
+static sunKbdPrivRec sunKeyboardPriv;
+
+_X_HIDDEN void
+xf86KbdInit(void)
+{
+ const char *kbdName = "keyboard";
+ pointer *kbdOptions = NULL;
+ IDevPtr pDev;
+
+ /* There should be a better way to find the keyboard device name, but
+ this seems to work for now. */
+ for (pDev = xf86ConfigLayout.inputs; pDev && pDev->identifier; pDev++) {
+ if (!xf86NameCmp(pDev->driver, "keyboard")) {
+ kbdName = pDev->identifier;
+ kbdOptions = pDev->commonOptions;
+ break;
+ }
+ }
+
+ if (xf86Info.kbdFd < 0) {
+ xf86Info.kbdFd = sunKbdOpen(kbdName, kbdOptions);
+ if (xf86Info.kbdFd < 0) {
+ FatalError("Unable to open keyboard: /dev/kbd\n");
+ }
+ }
+
+ memset(&sunKeyboardPriv, 0, sizeof(sunKbdPrivRec));
+ if (sunKbdInit(&sunKeyboardPriv, xf86Info.kbdFd,
+ kbdName, kbdOptions) != Success) {
+ FatalError("Unable to initialize keyboard driver\n");
+ }
+}
+
+_X_HIDDEN int
+xf86KbdOn(void)
+{
+ if (sunKbdOn(&sunKeyboardPriv) != Success) {
+ FatalError("Enabling keyboard");
+ }
+
+ return xf86Info.kbdFd;
+}
+
+_X_HIDDEN int
+xf86KbdOff(void)
+{
+ if (sunKbdOff(&sunKeyboardPriv) != Success) {
+ FatalError("Disabling keyboard");
+ }
+
+ return xf86Info.kbdFd;
+}
+
+_X_EXPORT void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ sunKbdSoundBell(&sunKeyboardPriv, loudness, pitch, duration);
+}
+
+_X_HIDDEN void
+xf86SetKbdLeds(int leds)
+{
+ sunKbdSetLeds(&sunKeyboardPriv, leds);
+}
+
+_X_HIDDEN int
+xf86GetKbdLeds(void)
+{
+ return sunKbdGetLeds(&sunKeyboardPriv);
+}
+
+_X_HIDDEN void
+xf86SetKbdRepeat(char rad)
+{
+ sunKbdSetRepeat(&sunKeyboardPriv, rad);
+}
+
+/*
+ * Lets try reading more than one keyboard event at a time in the hopes that
+ * this will be slightly more efficient. Or we could just try the MicroSoft
+ * method, and forget about efficiency. :-)
+ */
+_X_HIDDEN void
+xf86KbdEvents(void)
+{
+ Firm_event event[64];
+ int nBytes, i;
+
+ /* I certainly hope its not possible to read partial events */
+
+ if ((nBytes = read(xf86Info.kbdFd, (char *)event, sizeof(event))) > 0)
+ {
+ for (i = 0; i < (nBytes / sizeof(Firm_event)); i++)
+ sunPostKbdEvent(sunKeyboardPriv.ktype, &event[i]);
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.c
new file mode 100644
index 000000000..0a39155f4
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.c
@@ -0,0 +1,662 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.c,v 1.1 2001/05/28 02:42:31 tsi Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Dawes <dawes@XFree86.org>
+ * Copyright 1999 by David Holland <davidh@iquest.net)
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the names of Thomas Roell, David Dawes, and David Holland not be used
+ * in advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. Thomas Roell, David Dawes, and
+ * David Holland make no representations about the suitability of this software
+ * for any purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THOMAS ROELL, DAVID DAWES, AND DAVID HOLLAND DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL THOMAS ROELL, DAVID DAWES, OR DAVID HOLLAND
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/* Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.c,v 1.7 2005/08/30 22:34:14 alanc Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSKbd.h"
+#include "sun_kbd.h"
+
+/* Define to provide support for using /dev/audio to ring the bell instead of
+ the keyboard beeper */
+#define AUDIO_BELL
+
+#ifdef AUDIO_BELL
+#include <sys/audio.h>
+#include <sys/uio.h>
+#include <limits.h>
+#include <math.h>
+#include <poll.h>
+#endif
+
+/***************************************************************************
+ * Common implementation of routines shared by "keyboard" driver in sun_io.c
+ * and "kbd" driver (later on in this file)
+ */
+
+#include <sys/stropts.h>
+#include <sys/vuid_event.h>
+#include <sys/kbd.h>
+
+_X_HIDDEN int
+sunKbdOpen(const char *devName, pointer options)
+{
+ int kbdFD;
+ const char *kbdPath = NULL;
+ const char *defaultKbd = "/dev/kbd";
+
+ if (options != NULL) {
+ kbdPath = xf86SetStrOption(options, "Device", NULL);
+ }
+ if (kbdPath == NULL) {
+ kbdPath = defaultKbd;
+ }
+
+ kbdFD = open(kbdPath, O_RDONLY | O_NONBLOCK);
+
+ if (kbdFD == -1) {
+ xf86Msg(X_ERROR, "%s: cannot open \"%s\"\n", devName, kbdPath);
+ } else {
+ xf86MsgVerb(X_INFO, 3, "%s: Opened device \"%s\"\n", devName, kbdPath);
+ }
+
+ if ((kbdPath != NULL) && (kbdPath != defaultKbd)) {
+ xfree(kbdPath);
+ }
+ return kbdFD;
+}
+
+
+/*
+ * Save initial keyboard state. This is called at the start of each server
+ * generation.
+ */
+
+_X_HIDDEN int
+sunKbdInit(sunKbdPrivPtr priv, int kbdFD, const char *devName, pointer options)
+{
+ int ktype, klayout, i;
+ const char *ktype_name;
+
+ priv->kbdFD = kbdFD;
+ priv->devName = devName;
+ priv->otranslation = -1;
+ priv->odirect = -1;
+
+ if (options != NULL) {
+ priv->strmod = xf86SetStrOption(options, "StreamsModule", NULL);
+ priv->audioDevName = xf86SetStrOption(options, "BellDevice", NULL);
+
+ if (priv->audioDevName && (priv->audioDevName[0] == '\0')) {
+ xfree(priv->audioDevName);
+ priv->audioDevName = NULL;
+ }
+ } else {
+ priv->strmod = NULL;
+ priv->audioDevName = NULL;
+ }
+
+ if (priv->strmod) {
+ SYSCALL(i = ioctl(priv->kbdFD, I_PUSH, priv->strmod));
+ if (i < 0) {
+ xf86Msg(X_ERROR,
+ "%s: cannot push module '%s' onto keyboard device: %s\n",
+ priv->devName, priv->strmod, strerror(errno));
+ }
+ }
+
+ SYSCALL(i = ioctl(kbdFD, KIOCTYPE, &ktype));
+ if (i < 0) {
+ xf86Msg(X_ERROR, "%s: Unable to determine keyboard type: %s\n",
+ devName, strerror(errno));
+ return BadImplementation;
+ }
+
+ SYSCALL(i = ioctl(kbdFD, KIOCLAYOUT, &klayout));
+ if (i < 0) {
+ xf86Msg(X_ERROR, "%s: Unable to determine keyboard layout: %s\n",
+ devName, strerror(errno));
+ return BadImplementation;
+ }
+
+ switch (ktype) {
+ case KB_SUN3:
+ ktype_name = "Sun Type 3"; break;
+ case KB_SUN4:
+ ktype_name = "Sun Type 4/5/6"; break;
+ case KB_USB:
+ ktype_name = "USB"; break;
+ case KB_PC:
+ ktype_name = "PC"; break;
+ default:
+ ktype_name = "Unknown"; break;
+ }
+
+ xf86Msg(X_PROBED, "%s: Keyboard type: %s (%d)\n",
+ devName, ktype_name, ktype);
+ xf86Msg(X_PROBED, "%s: Keyboard layout: %d\n", devName, klayout);
+
+ priv->ktype = ktype;
+ priv->keyMap = sunGetKbdMapping(ktype);
+ priv->audioState = AB_INITIALIZING;
+ priv->oleds = sunKbdGetLeds(priv);
+
+ return Success;
+}
+
+_X_HIDDEN int
+sunKbdOn(sunKbdPrivPtr priv)
+{
+ int ktrans, kdirect, i;
+
+ SYSCALL(i = ioctl(priv->kbdFD, KIOCGDIRECT, &kdirect));
+ if (i < 0) {
+ xf86Msg(X_ERROR,
+ "%s: Unable to determine keyboard direct setting: %s\n",
+ priv->devName, strerror(errno));
+ return BadImplementation;
+ }
+
+ priv->odirect = kdirect;
+ kdirect = 1;
+
+ SYSCALL(i = ioctl(priv->kbdFD, KIOCSDIRECT, &kdirect));
+ if (i < 0) {
+ xf86Msg(X_ERROR, "%s: Failed turning keyboard direct mode on: %s\n",
+ priv->devName, strerror(errno));
+ return BadImplementation;
+ }
+
+ /* Setup translation */
+
+ SYSCALL(i = ioctl(priv->kbdFD, KIOCGTRANS, &ktrans));
+ if (i < 0) {
+ xf86Msg(X_ERROR,
+ "%s: Unable to determine keyboard translation mode: %s\n",
+ priv->devName, strerror(errno));
+ return BadImplementation;
+ }
+
+ priv->otranslation = ktrans;
+ ktrans = TR_UNTRANS_EVENT;
+
+ SYSCALL(i = ioctl(priv->kbdFD, KIOCTRANS, &ktrans));
+ if (i < 0) {
+ xf86Msg(X_ERROR, "%s: Failed setting keyboard translation mode: %s\n",
+ priv->devName, strerror(errno));
+ return BadImplementation;
+ }
+
+ return Success;
+}
+
+_X_HIDDEN int
+sunKbdOff(sunKbdPrivPtr priv)
+{
+ int i;
+
+ /* restore original state */
+
+ sunKbdSetLeds(priv, priv->oleds);
+
+ if (priv->otranslation != -1) {
+ SYSCALL(i = ioctl(priv->kbdFD, KIOCTRANS, &priv->otranslation));
+ if (i < 0) {
+ xf86Msg(X_ERROR,
+ "%s: Unable to restore keyboard translation mode: %s\n",
+ priv->devName, strerror(errno));
+ return BadImplementation;
+ }
+ priv->otranslation = -1;
+ }
+
+ if (priv->odirect != -1) {
+ SYSCALL(i = ioctl(priv->kbdFD, KIOCSDIRECT, &priv->odirect));
+ if (i < 0) {
+ xf86Msg(X_ERROR,
+ "%s: Unable to restore keyboard direct setting: %s\n",
+ priv->devName, strerror(errno));
+ return BadImplementation;
+ }
+ priv->odirect = -1;
+ }
+
+ if (priv->strmod) {
+ SYSCALL(i = ioctl(priv->kbdFD, I_POP, priv->strmod));
+ if (i < 0) {
+ xf86Msg(X_WARNING,
+ "%s: cannot pop module '%s' off keyboard device: %s\n",
+ priv->devName, priv->strmod, strerror(errno));
+ }
+ }
+
+ return Success;
+}
+
+#ifdef AUDIO_BELL
+
+/* Helper function to ring bell via audio device instead of keyboard beeper */
+
+#define BELL_RATE 48000 /* Samples per second */
+#define BELL_HZ 50 /* Fraction of a second i.e. 1/x */
+#define BELL_MS (1000/BELL_HZ) /* MS */
+#define BELL_SAMPLES (BELL_RATE / BELL_HZ)
+#define BELL_MIN 3 /* Min # of repeats */
+
+static int
+sunKbdAudioBell(sunKbdPrivPtr priv, int loudness, int pitch, int duration)
+{
+ static short samples[BELL_SAMPLES];
+ static short silence[BELL_SAMPLES]; /* "The Sound of Silence" */
+ static int lastFreq;
+ int cnt;
+ int i;
+ int written;
+ int repeats;
+ int freq;
+ audio_info_t audioInfo;
+ struct iovec iov[IOV_MAX];
+ int iovcnt;
+ double ampl, cyclen, phase;
+ int audioFD;
+
+ if ((loudness <= 0) || (pitch <= 0) || (duration <= 0)) {
+ return 0;
+ }
+
+ if ((priv == NULL) || (priv->audioDevName == NULL)) {
+ return -1;
+ }
+
+ if (priv->audioState == AB_INITIALIZING) {
+ priv->audioState = AB_NORMAL;
+ lastFreq = 0;
+ bzero(silence, sizeof(silence));
+ }
+
+ audioFD = open(priv->audioDevName, O_WRONLY | O_NONBLOCK);
+ if (audioFD == -1) {
+ xf86Msg(X_ERROR, "%s: cannot open audio device \"%s\": %s\n",
+ priv->devName, priv->audioDevName, strerror(errno));
+ return -1;
+ }
+
+ freq = pitch;
+ freq = min(freq, (BELL_RATE / 2) - 1);
+ freq = max(freq, 2 * BELL_HZ);
+
+ /*
+ * Ensure full waves per buffer
+ */
+ freq -= freq % BELL_HZ;
+
+ if (freq != lastFreq) {
+ lastFreq = freq;
+ ampl = 16384.0;
+
+ cyclen = (double) freq / (double) BELL_RATE;
+ phase = 0.0;
+
+ for (i = 0; i < BELL_SAMPLES; i++) {
+ samples[i] = (short) (ampl * sin(2.0 * M_PI * phase));
+ phase += cyclen;
+ if (phase >= 1.0)
+ phase -= 1.0;
+ }
+ }
+
+ repeats = (duration + (BELL_MS / 2)) / BELL_MS;
+ repeats = max(repeats, BELL_MIN);
+
+ loudness = max(0, loudness);
+ loudness = min(loudness, 100);
+
+#ifdef DEBUG
+ ErrorF("BELL : freq %d volume %d duration %d repeats %d\n",
+ freq, loudness, duration, repeats);
+#endif
+
+ AUDIO_INITINFO(&audioInfo);
+ audioInfo.play.encoding = AUDIO_ENCODING_LINEAR;
+ audioInfo.play.sample_rate = BELL_RATE;
+ audioInfo.play.channels = 2;
+ audioInfo.play.precision = 16;
+ audioInfo.play.gain = min(AUDIO_MAX_GAIN, AUDIO_MAX_GAIN * loudness / 100);
+
+ if (ioctl(audioFD, AUDIO_SETINFO, &audioInfo) < 0){
+ xf86Msg(X_ERROR,
+ "%s: AUDIO_SETINFO failed on audio device \"%s\": %s\n",
+ priv->devName, priv->audioDevName, strerror(errno));
+ close(audioFD);
+ return -1;
+ }
+
+ iovcnt = 0;
+
+ for (cnt = 0; cnt <= repeats; cnt++) {
+ iov[iovcnt].iov_base = (char *) samples;
+ iov[iovcnt++].iov_len = sizeof(samples);
+ if (cnt == repeats) {
+ /* Insert a bit of silence so that multiple beeps are distinct and
+ * not compressed into a single tone.
+ */
+ iov[iovcnt].iov_base = (char *) silence;
+ iov[iovcnt++].iov_len = sizeof(silence);
+ }
+ if ((iovcnt >= IOV_MAX) || (cnt == repeats)) {
+ written = writev(audioFD, iov, iovcnt);
+
+ if ((written < ((int)(sizeof(samples) * iovcnt)))) {
+ /* audio buffer was full! */
+
+ int naptime;
+
+ if (written == -1) {
+ if (errno != EAGAIN) {
+ xf86Msg(X_ERROR,
+ "%s: writev failed on audio device \"%s\": %s\n",
+ priv->devName, priv->audioDevName,
+ strerror(errno));
+ close(audioFD);
+ return -1;
+ }
+ i = iovcnt;
+ } else {
+ i = ((sizeof(samples) * iovcnt) - written)
+ / sizeof(samples);
+ }
+ cnt -= i;
+
+ /* sleep a little to allow audio buffer to drain */
+ naptime = BELL_MS * i;
+ poll(NULL, 0, naptime);
+
+ i = ((sizeof(samples) * iovcnt) - written) % sizeof(samples);
+ iovcnt = 0;
+ if ((written != -1) && (i > 0)) {
+ iov[iovcnt].iov_base = ((char *) samples) + i;
+ iov[iovcnt++].iov_len = sizeof(samples) - i;
+ }
+ } else {
+ iovcnt = 0;
+ }
+ }
+ }
+
+ close(audioFD);
+ return 0;
+}
+
+#endif /* AUDIO_BELL */
+
+_X_HIDDEN void
+sunKbdSoundBell(sunKbdPrivPtr priv, int loudness, int pitch, int duration)
+{
+ int kbdCmd, i;
+
+ if (loudness && pitch)
+ {
+#ifdef AUDIO_BELL
+ if (priv->audioDevName != NULL) {
+ if (sunKbdAudioBell(priv, loudness, pitch, duration) == 0) {
+ return;
+ }
+ }
+#endif
+
+ kbdCmd = KBD_CMD_BELL;
+
+ SYSCALL(i = ioctl (priv->kbdFD, KIOCCMD, &kbdCmd));
+ if (i < 0) {
+ xf86Msg(X_ERROR, "%s: Failed to activate bell: %s\n",
+ priv->devName, strerror(errno));
+ }
+
+ usleep(duration * loudness * 20);
+
+ kbdCmd = KBD_CMD_NOBELL;
+ SYSCALL(i = ioctl (priv->kbdFD, KIOCCMD, &kbdCmd));
+ if (i < 0) {
+ xf86Msg(X_ERROR, "%s: Failed to deactivate bell: %s\n",
+ priv->devName, strerror(errno));
+ }
+ }
+}
+
+_X_HIDDEN void
+sunKbdSetLeds(sunKbdPrivPtr priv, int leds)
+{
+ int i;
+
+ SYSCALL(i = ioctl(priv->kbdFD, KIOCSLED, &leds));
+ if (i < 0) {
+ xf86Msg(X_ERROR, "%s: Failed to set keyboard LED's: %s\n",
+ priv->devName, strerror(errno));
+ }
+}
+
+_X_HIDDEN int
+sunKbdGetLeds(sunKbdPrivPtr priv)
+{
+ int i, leds = 0;
+
+ SYSCALL(i = ioctl(priv->kbdFD, KIOCGLED, &leds));
+ if (i < 0) {
+ xf86Msg(X_ERROR, "%s: Failed to get keyboard LED's: %s\n",
+ priv->devName, strerror(errno));
+ }
+ return leds;
+}
+
+/* ARGSUSED0 */
+_X_HIDDEN void
+sunKbdSetRepeat(sunKbdPrivPtr priv, char rad)
+{
+ /* Nothing to do */
+}
+
+/***************************************************************************
+ * Routines called from "kbd" driver via proc vectors filled in by
+ * xf86OSKbdPreInit().
+ */
+
+
+static int
+KbdInit(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+
+ return sunKbdInit(priv, pInfo->fd, pInfo->name, pInfo->options);
+}
+
+
+static int
+KbdOn(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+
+ return sunKbdOn(priv);
+}
+
+static int
+KbdOff(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+
+ return sunKbdOff(priv);
+}
+
+
+static void
+SoundKbdBell(InputInfoPtr pInfo, int loudness, int pitch, int duration)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+
+ sunKbdSoundBell(priv, loudness, pitch, duration);
+}
+
+static void
+SetKbdLeds(InputInfoPtr pInfo, int leds)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+ int real_leds = sunKbdGetLeds(priv);
+
+ real_leds &= ~(LED_CAPS_LOCK | LED_NUM_LOCK | LED_SCROLL_LOCK | LED_COMPOSE);
+
+ if (leds & XLED1) real_leds |= LED_CAPS_LOCK;
+ if (leds & XLED2) real_leds |= LED_NUM_LOCK;
+ if (leds & XLED3) real_leds |= LED_SCROLL_LOCK;
+ if (leds & XLED4) real_leds |= LED_COMPOSE;
+
+ sunKbdSetLeds(priv, real_leds);
+}
+
+static int
+GetKbdLeds(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+ int leds = 0;
+ int real_leds = sunKbdGetLeds(priv);
+
+ if (real_leds & LED_CAPS_LOCK) leds |= XLED1;
+ if (real_leds & LED_NUM_LOCK) leds |= XLED2;
+ if (real_leds & LED_SCROLL_LOCK) leds |= XLED3;
+ if (real_leds & LED_COMPOSE) leds |= XLED4;
+
+ return leds;
+}
+
+static void
+SetKbdRepeat(InputInfoPtr pInfo, char rad)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+
+ sunKbdSetRepeat(priv, rad);
+}
+
+static void
+KbdGetMapping (InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ /* Should probably do something better here */
+ xf86KbdGetMapping(pKeySyms, pModMap);
+}
+
+static void
+ReadInput(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+ Firm_event event[64];
+ int nBytes, i;
+
+ /* I certainly hope its not possible to read partial events */
+
+ if ((nBytes = read(pInfo->fd, (char *)event, sizeof(event))) > 0)
+ {
+ for (i = 0; i < (nBytes / sizeof(Firm_event)); i++) {
+ pKbd->PostEvent(pInfo, priv->keyMap[event[i].id],
+ event[i].value == VKEY_DOWN ? TRUE : FALSE);
+ }
+ }
+}
+
+static Bool
+OpenKeyboard(InputInfoPtr pInfo)
+{
+ pInfo->fd = sunKbdOpen(pInfo->name, pInfo->options);
+
+ if (pInfo->fd >= 0) {
+ pInfo->read_input = ReadInput;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+_X_EXPORT Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = pInfo->private;
+
+ pKbd->KbdInit = KbdInit;
+ pKbd->KbdOn = KbdOn;
+ pKbd->KbdOff = KbdOff;
+ pKbd->Bell = SoundKbdBell;
+ pKbd->SetLeds = SetKbdLeds;
+ pKbd->GetLeds = GetKbdLeds;
+ pKbd->SetKbdRepeat = SetKbdRepeat;
+ pKbd->KbdGetMapping = KbdGetMapping;
+
+ pKbd->RemapScanCode = NULL;
+ pKbd->GetSpecialKey = NULL;
+ pKbd->SpecialKey = NULL;
+
+ pKbd->OpenKeyboard = OpenKeyboard;
+
+ pKbd->vtSwitchSupported = FALSE;
+ pKbd->CustomKeycodes = FALSE;
+
+ pKbd->private = xcalloc(sizeof(sunKbdPrivRec), 1);
+ if (pKbd->private == NULL) {
+ xf86Msg(X_ERROR,"can't allocate keyboard OS private data\n");
+ return FALSE;
+ } else {
+ sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+ priv->otranslation = -1;
+ priv->odirect = -1;
+ }
+
+ return TRUE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.h
new file mode 100644
index 000000000..ed2824b1f
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbd.h
@@ -0,0 +1,72 @@
+/* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#ifndef _XORG_SUN_KBD_H_
+#define _XORG_SUN_KBD_H_
+
+/*
+ * Keyboard common implementation routines shared by "keyboard" driver
+ * in sun_io.c and "kbd" driver in sun_kbd.c
+ */
+
+typedef struct {
+ int kbdFD;
+ const char * devName;
+ int ktype; /* Keyboard type from KIOCTYPE */
+ Bool kbdActive; /* Have we set kbd modes for X? */
+ int otranslation; /* Original translation mode */
+ int odirect; /* Original "direct" mode setting */
+ unsigned char oleds; /* Original LED state */
+ const char * strmod; /* Streams module pushed on kbd device */
+ const char * audioDevName; /* Audio device path to use for bell
+ or NULL to use keyboard beeper */
+ enum {AB_INITIALIZING, AB_NORMAL} audioState;
+ const unsigned char *keyMap;
+} sunKbdPrivRec, *sunKbdPrivPtr;
+
+/* sun_kbd.c */
+extern int sunKbdOpen (const char *devName, pointer options);
+extern int sunKbdInit (sunKbdPrivPtr priv, int kbdFD,
+ const char *devName, pointer options);
+extern int sunKbdOn (sunKbdPrivPtr priv);
+extern int sunKbdOff (sunKbdPrivPtr priv);
+
+extern void sunKbdSoundBell (sunKbdPrivPtr priv,
+ int loudness, int pitch, int duration);
+
+extern void sunKbdSetLeds (sunKbdPrivPtr priv, int leds);
+extern int sunKbdGetLeds (sunKbdPrivPtr priv);
+extern void sunKbdSetRepeat (sunKbdPrivPtr priv, char rad);
+
+/* sun_kbdEv.c */
+#include <sys/vuid_event.h>
+extern void sunPostKbdEvent (int ktype, Firm_event *event);
+
+extern const unsigned char *sunGetKbdMapping(int ktype);
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbdEv.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbdEv.c
new file mode 100644
index 000000000..dbae7c775
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbdEv.c
@@ -0,0 +1,892 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbdEv.c,v 1.5 2003/08/26 19:00:36 tsi Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the names of Thomas Roell and David Dawes not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. Thomas Roell and David Dawes make no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL AND DAVID DAWES DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+ * IN NO EVENT SHALL THOMAS ROELL OR DAVID DAWES BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* [JCH-96/01/21] Extended std reverse map to four buttons. */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_kbdEv.c,v 1.9 2005/08/16 00:40:25 alanc Exp $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "sun_kbd.h"
+
+#ifdef XINPUT
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#include "xf86Xinput.h"
+#else
+#include "inputstr.h"
+#endif
+
+#ifdef XFreeXDGA
+#include "dgaproc.h"
+#endif
+
+#include <sys/kbd.h>
+#include "atKeynames.h"
+
+#ifdef XKB
+extern Bool noXkbExtension;
+#endif
+
+#define XE_POINTER 1
+#define XE_KEYBOARD 2
+
+#ifdef XTESTEXT1
+
+#define XTestSERVER_SIDE
+#include <X11/extensions/xtestext1.h>
+extern short xtest_mousex;
+extern short xtest_mousey;
+extern int on_steal_input;
+extern Bool XTestStealKeyData();
+extern void XTestStealMotionData();
+
+#ifdef XINPUT
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ if (!on_steal_input || \
+ XTestStealKeyData((ev)->u.u.detail, (ev)->u.u.type, dev_type, \
+ xtest_mousex, xtest_mousey)) \
+ xf86eqEnqueue((ev))
+#else
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ if (!on_steal_input || \
+ XTestStealKeyData((ev)->u.u.detail, (ev)->u.u.type, dev_type, \
+ xtest_mousex, xtest_mousey)) \
+ mieqEnqueue((ev))
+#endif
+
+#else /* ! XTESTEXT1 */
+
+#ifdef XINPUT
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ xf86eqEnqueue((ev))
+#else
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ mieqEnqueue((ev))
+#endif
+
+#endif
+
+static void startautorepeat(long keycode);
+static CARD32 processautorepeat(OsTimerPtr timer, CARD32 now, pointer arg);
+
+static OsTimerPtr sunTimer = NULL;
+
+/* Map the Solaris keycodes to the "XFree86" keycodes. */
+/*
+ * This doesn't seem right. It probably needs to be dependent on a keyboard
+ * type.
+ */
+
+/* Additional Sun Japanese Keyboard Keys not defined in common/atKeynames.h */
+#define KEY_Kanji 0x82
+#define KEY_Execute 0x83
+
+static unsigned char map[256] = {
+#if defined(i386) || defined(__i386) || defined(__i386__) || defined(__x86)
+ KEY_NOTUSED, /* 0 */
+ KEY_Tilde, /* 1 */
+ KEY_1, /* 2 */
+ KEY_2, /* 3 */
+ KEY_3, /* 4 */
+ KEY_4, /* 5 */
+ KEY_5, /* 6 */
+ KEY_6, /* 7 */
+ KEY_7, /* 8 */
+ KEY_8, /* 9 */
+ KEY_9, /* 10 */
+ KEY_0, /* 11 */
+ KEY_Minus, /* 12 */
+ KEY_Equal, /* 13 */
+ 0x7D, /*KEY_P_YEN*/ /* 14 */
+ KEY_BackSpace, /* 15 */
+ KEY_Tab, /* 16 */
+ KEY_Q, /* 17 */
+ KEY_W, /* 18 */
+ KEY_E, /* 19 */
+ KEY_R, /* 20 */
+ KEY_T, /* 21 */
+ KEY_Y, /* 22 */
+ KEY_U, /* 23 */
+ KEY_I, /* 24 */
+ KEY_O, /* 25 */
+ KEY_P, /* 26 */
+ KEY_LBrace, /* 27 */
+ KEY_RBrace, /* 28 */
+ KEY_BSlash, /* 29 */
+ KEY_CapsLock, /* 30 */
+ KEY_A, /* 31 */
+ KEY_S, /* 32 */
+ KEY_D, /* 33 */
+ KEY_F, /* 34 */
+ KEY_G, /* 35 */
+ KEY_H, /* 36 */
+ KEY_J, /* 37 */
+ KEY_K, /* 38 */
+ KEY_L, /* 39 */
+ KEY_SemiColon, /* 40 */
+ KEY_Quote, /* 41 */
+ KEY_UNKNOWN, /* 42 */
+ KEY_Enter, /* 43 */
+ KEY_ShiftL, /* 44 */
+ KEY_Less, /* 45 */
+ KEY_Z, /* 46 */
+ KEY_X, /* 47 */
+ KEY_C, /* 48 */
+ KEY_V, /* 49 */
+ KEY_B, /* 50 */
+ KEY_N, /* 51 */
+ KEY_M, /* 52 */
+ KEY_Comma, /* 53 */
+ KEY_Period, /* 54 */
+ KEY_Slash, /* 55 */
+ KEY_BSlash2, /* 56 */
+ KEY_ShiftR, /* 57 */
+ KEY_LCtrl, /* 58 */
+ KEY_LMeta, /* 59 */
+ KEY_Alt, /* 60 */
+ KEY_Space, /* 61 */
+ KEY_AltLang, /* 62 */
+ KEY_RMeta, /* 63 */
+ KEY_RCtrl, /* 64 */
+ KEY_Menu, /* 65 */
+ KEY_UNKNOWN, /* 66 */
+ KEY_UNKNOWN, /* 67 */
+ KEY_UNKNOWN, /* 68 */
+ KEY_UNKNOWN, /* 69 */
+ KEY_UNKNOWN, /* 70 */
+ KEY_UNKNOWN, /* 71 */
+ KEY_UNKNOWN, /* 72 */
+ KEY_UNKNOWN, /* 73 */
+ KEY_UNKNOWN, /* 74 */
+ KEY_Insert, /* 75 */
+ KEY_Delete, /* 76 */
+ KEY_UNKNOWN, /* 77 */
+ KEY_UNKNOWN, /* 78 */
+ KEY_Left, /* 79 */
+ KEY_Home, /* 80 */
+ KEY_End, /* 81 */
+ KEY_UNKNOWN, /* 82 */
+ KEY_Up, /* 83 */
+ KEY_Down, /* 84 */
+ KEY_PgUp, /* 85 */
+ KEY_PgDown, /* 86 */
+ KEY_UNKNOWN, /* 87 */
+ KEY_UNKNOWN, /* 88 */
+ KEY_Right, /* 89 */
+ KEY_NumLock, /* 90 */
+ KEY_KP_7, /* 91 */
+ KEY_KP_4, /* 92 */
+ KEY_KP_1, /* 93 */
+ KEY_UNKNOWN, /* 94 */
+ KEY_KP_Divide, /* 95 */
+ KEY_KP_8, /* 96 */
+ KEY_KP_5, /* 97 */
+ KEY_KP_2, /* 98 */
+ KEY_KP_0, /* 99 */
+ KEY_KP_Multiply, /* 100 */
+ KEY_KP_9, /* 101 */
+ KEY_KP_6, /* 102 */
+ KEY_KP_3, /* 103 */
+ KEY_KP_Decimal, /* 104 */
+ KEY_KP_Minus, /* 105 */
+ KEY_KP_Plus, /* 106 */
+ KEY_UNKNOWN, /* 107 */
+ KEY_KP_Enter, /* 108 */
+ KEY_UNKNOWN, /* 109 */
+ KEY_Escape, /* 110 */
+ KEY_UNKNOWN, /* 111 */
+ KEY_F1, /* 112 */
+ KEY_F2, /* 113 */
+ KEY_F3, /* 114 */
+ KEY_F4, /* 115 */
+ KEY_F5, /* 116 */
+ KEY_F6, /* 117 */
+ KEY_F7, /* 118 */
+ KEY_F8, /* 119 */
+ KEY_F9, /* 120 */
+ KEY_F10, /* 121 */
+ KEY_F11, /* 122 */
+ KEY_F12, /* 123 */
+ KEY_Print, /* 124 */
+ KEY_ScrollLock, /* 125 */
+ KEY_Pause, /* 126 */
+ KEY_UNKNOWN, /* 127 */
+ KEY_UNKNOWN, /* 128 */
+ KEY_UNKNOWN, /* 129 */
+ KEY_UNKNOWN, /* 130 */
+ KEY_NFER, /* 131 */
+ KEY_XFER, /* 132 */
+ KEY_HKTG, /* 133 */
+ KEY_UNKNOWN, /* 134 */
+#elif defined(sparc) || defined(__sparc__)
+ KEY_UNKNOWN, /* 0x00 */
+ KEY_UNKNOWN, /* 0x01 */
+ KEY_UNKNOWN, /* 0x02 */
+ KEY_UNKNOWN, /* 0x03 */
+ KEY_UNKNOWN, /* 0x04 */
+ KEY_F1, /* 0x05 */
+ KEY_F2, /* 0x06 */
+ KEY_F10, /* 0x07 */
+ KEY_F3, /* 0x08 */
+ KEY_F11, /* 0x09 */
+ KEY_F4, /* 0x0A */
+ KEY_F12, /* 0x0B */
+ KEY_F5, /* 0x0C */
+ KEY_UNKNOWN, /* 0x0D */
+ KEY_F6, /* 0x0E */
+ KEY_UNKNOWN, /* 0x0F */
+ KEY_F7, /* 0x10 */
+ KEY_F8, /* 0x11 */
+ KEY_F9, /* 0x12 */
+ KEY_Alt, /* 0x13 */
+ KEY_Up, /* 0x14 */
+ KEY_Pause, /* 0x15 */
+ KEY_SysReqest, /* 0x16 */
+ KEY_ScrollLock, /* 0x17 */
+ KEY_Left, /* 0x18 */
+ KEY_UNKNOWN, /* 0x19 */
+ KEY_UNKNOWN, /* 0x1A */
+ KEY_Down, /* 0x1B */
+ KEY_Right, /* 0x1C */
+ KEY_Escape, /* 0x1D */
+ KEY_1, /* 0x1E */
+ KEY_2, /* 0x1F */
+ KEY_3, /* 0x20 */
+ KEY_4, /* 0x21 */
+ KEY_5, /* 0x22 */
+ KEY_6, /* 0x23 */
+ KEY_7, /* 0x24 */
+ KEY_8, /* 0x25 */
+ KEY_9, /* 0x26 */
+ KEY_0, /* 0x27 */
+ KEY_Minus, /* 0x28 */
+ KEY_Equal, /* 0x29 */
+ KEY_Tilde, /* 0x2A */
+ KEY_BackSpace, /* 0x2B */
+ KEY_Insert, /* 0x2C */
+ KEY_UNKNOWN, /* 0x2D */
+ KEY_KP_Divide, /* 0x2E */
+ KEY_KP_Multiply, /* 0x2F */
+ KEY_UNKNOWN, /* 0x30 */
+ KEY_UNKNOWN, /* 0x31 */
+ KEY_KP_Decimal, /* 0x32 */
+ KEY_UNKNOWN, /* 0x33 */
+ KEY_Home, /* 0x34 */
+ KEY_Tab, /* 0x35 */
+ KEY_Q, /* 0x36 */
+ KEY_W, /* 0x37 */
+ KEY_E, /* 0x38 */
+ KEY_R, /* 0x39 */
+ KEY_T, /* 0x3A */
+ KEY_Y, /* 0x3B */
+ KEY_U, /* 0x3C */
+ KEY_I, /* 0x3D */
+ KEY_O, /* 0x3E */
+ KEY_P, /* 0x3F */
+ KEY_LBrace, /* 0x40 */
+ KEY_RBrace, /* 0x41 */
+ KEY_Delete, /* 0x42 */
+ KEY_UNKNOWN, /* 0x43 */
+ KEY_KP_7, /* 0x44 */
+ KEY_KP_8, /* 0x45 */
+ KEY_KP_9, /* 0x46 */
+ KEY_KP_Minus, /* 0x47 */
+ KEY_UNKNOWN, /* 0x48 */
+ KEY_UNKNOWN, /* 0x49 */
+ KEY_End, /* 0x4A */
+ KEY_UNKNOWN, /* 0x4B */
+ KEY_LCtrl, /* 0x4C */
+ KEY_A, /* 0x4D */
+ KEY_S, /* 0x4E */
+ KEY_D, /* 0x4F */
+ KEY_F, /* 0x50 */
+ KEY_G, /* 0x51 */
+ KEY_H, /* 0x52 */
+ KEY_J, /* 0x53 */
+ KEY_K, /* 0x54 */
+ KEY_L, /* 0x55 */
+ KEY_SemiColon, /* 0x56 */
+ KEY_Quote, /* 0x57 */
+ KEY_BSlash, /* 0x58 */
+ KEY_Enter, /* 0x59 */
+ KEY_KP_Enter, /* 0x5A */
+ KEY_KP_4, /* 0x5B */
+ KEY_KP_5, /* 0x5C */
+ KEY_KP_6, /* 0x5D */
+ KEY_KP_0, /* 0x5E */
+ KEY_UNKNOWN, /* 0x5F */
+ KEY_PgUp, /* 0x60 */
+ KEY_UNKNOWN, /* 0x61 */
+ KEY_NumLock, /* 0x62 */
+ KEY_ShiftL, /* 0x63 */
+ KEY_Z, /* 0x64 */
+ KEY_X, /* 0x65 */
+ KEY_C, /* 0x66 */
+ KEY_V, /* 0x67 */
+ KEY_B, /* 0x68 */
+ KEY_N, /* 0x69 */
+ KEY_M, /* 0x6A */
+ KEY_Comma, /* 0x6B */
+ KEY_Period, /* 0x6C */
+ KEY_Slash, /* 0x6D */
+ KEY_ShiftR, /* 0x6E */
+ KEY_UNKNOWN, /* 0x6F */
+ KEY_KP_1, /* 0x70 */
+ KEY_KP_2, /* 0x71 */
+ KEY_KP_3, /* 0x72 */
+ KEY_UNKNOWN, /* 0x73 */
+ KEY_UNKNOWN, /* 0x74 */
+ KEY_UNKNOWN, /* 0x75 */
+ KEY_UNKNOWN, /* 0x76 */
+ KEY_CapsLock, /* 0x77 */
+ KEY_LMeta, /* 0x78 */
+ KEY_Space, /* 0x79 */
+ KEY_RMeta, /* 0x7A */
+ KEY_PgDown, /* 0x7B */
+ KEY_UNKNOWN, /* 0x7C */
+ KEY_KP_Plus, /* 0x7D */
+ KEY_UNKNOWN, /* 0x7E */
+ KEY_UNKNOWN, /* 0x7F */
+#endif
+ /* The rest default to KEY_UNKNOWN */
+};
+
+#if defined(KB_USB)
+static unsigned char usbmap[256] = {
+/*
+ * partially taken from ../bsd/bsd_KbdMap.c
+ *
+ * added keycodes for Sun special keys (left function keys, audio control)
+ */
+ /* 0 */ KEY_NOTUSED,
+ /* 1 */ KEY_NOTUSED,
+ /* 2 */ KEY_NOTUSED,
+ /* 3 */ KEY_NOTUSED,
+ /* 4 */ KEY_A,
+ /* 5 */ KEY_B,
+ /* 6 */ KEY_C,
+ /* 7 */ KEY_D,
+ /* 8 */ KEY_E,
+ /* 9 */ KEY_F,
+ /* 10 */ KEY_G,
+ /* 11 */ KEY_H,
+ /* 12 */ KEY_I,
+ /* 13 */ KEY_J,
+ /* 14 */ KEY_K,
+ /* 15 */ KEY_L,
+ /* 16 */ KEY_M,
+ /* 17 */ KEY_N,
+ /* 18 */ KEY_O,
+ /* 19 */ KEY_P,
+ /* 20 */ KEY_Q,
+ /* 21 */ KEY_R,
+ /* 22 */ KEY_S,
+ /* 23 */ KEY_T,
+ /* 24 */ KEY_U,
+ /* 25 */ KEY_V,
+ /* 26 */ KEY_W,
+ /* 27 */ KEY_X,
+ /* 28 */ KEY_Y,
+ /* 29 */ KEY_Z,
+ /* 30 */ KEY_1, /* 1 !*/
+ /* 31 */ KEY_2, /* 2 @ */
+ /* 32 */ KEY_3, /* 3 # */
+ /* 33 */ KEY_4, /* 4 $ */
+ /* 34 */ KEY_5, /* 5 % */
+ /* 35 */ KEY_6, /* 6 ^ */
+ /* 36 */ KEY_7, /* 7 & */
+ /* 37 */ KEY_8, /* 8 * */
+ /* 38 */ KEY_9, /* 9 ( */
+ /* 39 */ KEY_0, /* 0 ) */
+ /* 40 */ KEY_Enter, /* Return */
+ /* 41 */ KEY_Escape, /* Escape */
+ /* 42 */ KEY_BackSpace, /* Backspace Delete */
+ /* 43 */ KEY_Tab, /* Tab */
+ /* 44 */ KEY_Space, /* Space */
+ /* 45 */ KEY_Minus, /* - _ */
+ /* 46 */ KEY_Equal, /* = + */
+ /* 47 */ KEY_LBrace, /* [ { */
+ /* 48 */ KEY_RBrace, /* ] } */
+ /* 49 */ KEY_BSlash, /* \ | */
+ /* 50 */ KEY_BSlash, /* \ _ # ~ on some keyboards */
+ /* 51 */ KEY_SemiColon, /* ; : */
+ /* 52 */ KEY_Quote, /* ' " */
+ /* 53 */ KEY_Tilde, /* ` ~ */
+ /* 54 */ KEY_Comma, /* , < */
+ /* 55 */ KEY_Period, /* . > */
+ /* 56 */ KEY_Slash, /* / ? */
+ /* 57 */ KEY_CapsLock, /* Caps Lock */
+ /* 58 */ KEY_F1, /* F1 */
+ /* 59 */ KEY_F2, /* F2 */
+ /* 60 */ KEY_F3, /* F3 */
+ /* 61 */ KEY_F4, /* F4 */
+ /* 62 */ KEY_F5, /* F5 */
+ /* 63 */ KEY_F6, /* F6 */
+ /* 64 */ KEY_F7, /* F7 */
+ /* 65 */ KEY_F8, /* F8 */
+ /* 66 */ KEY_F9, /* F9 */
+ /* 67 */ KEY_F10, /* F10 */
+ /* 68 */ KEY_F11, /* F11 */
+ /* 69 */ KEY_F12, /* F12 */
+ /* 70 */ KEY_Print, /* PrintScrn SysReq */
+ /* 71 */ KEY_ScrollLock, /* Scroll Lock */
+ /* 72 */ KEY_Pause, /* Pause Break */
+ /* 73 */ KEY_Insert, /* Insert XXX Help on some Mac Keyboards */
+ /* 74 */ KEY_Home, /* Home */
+ /* 75 */ KEY_PgUp, /* Page Up */
+ /* 76 */ KEY_Delete, /* Delete */
+ /* 77 */ KEY_End, /* End */
+ /* 78 */ KEY_PgDown, /* Page Down */
+ /* 79 */ KEY_Right, /* Right Arrow */
+ /* 80 */ KEY_Left, /* Left Arrow */
+ /* 81 */ KEY_Down, /* Down Arrow */
+ /* 82 */ KEY_Up, /* Up Arrow */
+ /* 83 */ KEY_NumLock, /* Num Lock */
+ /* 84 */ KEY_KP_Divide, /* Keypad / */
+ /* 85 */ KEY_KP_Multiply, /* Keypad * */
+ /* 86 */ KEY_KP_Minus, /* Keypad - */
+ /* 87 */ KEY_KP_Plus, /* Keypad + */
+ /* 88 */ KEY_KP_Enter, /* Keypad Enter */
+ /* 89 */ KEY_KP_1, /* Keypad 1 End */
+ /* 90 */ KEY_KP_2, /* Keypad 2 Down */
+ /* 91 */ KEY_KP_3, /* Keypad 3 Pg Down */
+ /* 92 */ KEY_KP_4, /* Keypad 4 Left */
+ /* 93 */ KEY_KP_5, /* Keypad 5 */
+ /* 94 */ KEY_KP_6, /* Keypad 6 */
+ /* 95 */ KEY_KP_7, /* Keypad 7 Home */
+ /* 96 */ KEY_KP_8, /* Keypad 8 Up */
+ /* 97 */ KEY_KP_9, /* KEypad 9 Pg Up */
+ /* 98 */ KEY_KP_0, /* Keypad 0 Ins */
+ /* 99 */ KEY_KP_Decimal, /* Keypad . Del */
+ /* 100 */ KEY_Less, /* < > on some keyboards */
+ /* 101 */ KEY_Menu, /* Menu */
+ /* 102 */ KEY_Power, /* Sun: Power */
+ /* 103 */ KEY_KP_Equal, /* Keypad = on Mac keyboards */
+ /* 104 */ KEY_NOTUSED,
+ /* 105 */ KEY_NOTUSED,
+ /* 106 */ KEY_NOTUSED,
+ /* 107 */ KEY_NOTUSED,
+ /* 108 */ KEY_NOTUSED,
+ /* 109 */ KEY_NOTUSED,
+ /* 110 */ KEY_NOTUSED,
+ /* 111 */ KEY_NOTUSED,
+ /* 112 */ KEY_NOTUSED,
+ /* 113 */ KEY_NOTUSED,
+ /* 114 */ KEY_NOTUSED,
+ /* 115 */ KEY_NOTUSED,
+ /* 116 */ KEY_L7, /* Sun: Open */
+ /* 117 */ KEY_Help, /* Sun: Help */
+ /* 118 */ KEY_L3, /* Sun: Props */
+ /* 119 */ KEY_L5, /* Sun: Front */
+ /* 120 */ KEY_L1, /* Sun: Stop */
+ /* 121 */ KEY_L2, /* Sun: Again */
+ /* 122 */ KEY_L4, /* Sun: Undo */
+ /* 123 */ KEY_L10, /* Sun: Cut */
+ /* 124 */ KEY_L6, /* Sun: Copy */
+ /* 125 */ KEY_L8, /* Sun: Paste */
+ /* 126 */ KEY_L9, /* Sun: Find */
+ /* 127 */ KEY_Mute, /* Sun: AudioMute */
+ /* 128 */ KEY_AudioRaise, /* Sun: AudioRaise */
+ /* 129 */ KEY_AudioLower, /* Sun: AudioLower */
+ /* 130 */ KEY_NOTUSED,
+ /* 131 */ KEY_NOTUSED,
+ /* 132 */ KEY_NOTUSED,
+ /* 133 */ KEY_NOTUSED,
+ /* 134 */ KEY_NOTUSED,
+ /* 135 */ KEY_BSlash2, /* Sun Japanese Kbd: Backslash / Underscore */
+ /* 136 */ KEY_XFER, /* Sun Japanese Kbd: Henkan Mode */
+ /* 137 */ KEY_Yen, /* Sun Japanese Kbd: Yen / Brokenbar */
+ /* 138 */ KEY_Kanji, /* Sun Japanese Kbd: Kanji */
+ /* 139 */ KEY_Execute, /* Sun Japanese Kbd: Execute */
+ /* 140 */ KEY_NOTUSED,
+ /* 141 */ KEY_NOTUSED,
+ /* 142 */ KEY_NOTUSED,
+ /* 143 */ KEY_NOTUSED,
+ /* 144 */ KEY_NOTUSED,
+ /* 145 */ KEY_NOTUSED,
+ /* 146 */ KEY_NOTUSED,
+ /* 147 */ KEY_NOTUSED,
+ /* 148 */ KEY_NOTUSED,
+ /* 149 */ KEY_NOTUSED,
+ /* 150 */ KEY_NOTUSED,
+ /* 151 */ KEY_NOTUSED,
+ /* 152 */ KEY_NOTUSED,
+ /* 153 */ KEY_NOTUSED,
+ /* 154 */ KEY_NOTUSED,
+ /* 155 */ KEY_NOTUSED,
+ /* 156 */ KEY_NOTUSED,
+ /* 157 */ KEY_NOTUSED,
+ /* 158 */ KEY_NOTUSED,
+ /* 159 */ KEY_NOTUSED,
+ /* 160 */ KEY_NOTUSED,
+ /* 161 */ KEY_NOTUSED,
+ /* 162 */ KEY_NOTUSED,
+ /* 163 */ KEY_NOTUSED,
+ /* 164 */ KEY_NOTUSED,
+ /* 165 */ KEY_NOTUSED,
+ /* 166 */ KEY_NOTUSED,
+ /* 167 */ KEY_NOTUSED,
+ /* 168 */ KEY_NOTUSED,
+ /* 169 */ KEY_NOTUSED,
+ /* 170 */ KEY_NOTUSED,
+ /* 171 */ KEY_NOTUSED,
+ /* 172 */ KEY_NOTUSED,
+ /* 173 */ KEY_NOTUSED,
+ /* 174 */ KEY_NOTUSED,
+ /* 175 */ KEY_NOTUSED,
+ /* 176 */ KEY_NOTUSED,
+ /* 177 */ KEY_NOTUSED,
+ /* 178 */ KEY_NOTUSED,
+ /* 179 */ KEY_NOTUSED,
+ /* 180 */ KEY_NOTUSED,
+ /* 181 */ KEY_NOTUSED,
+ /* 182 */ KEY_NOTUSED,
+ /* 183 */ KEY_NOTUSED,
+ /* 184 */ KEY_NOTUSED,
+ /* 185 */ KEY_NOTUSED,
+ /* 186 */ KEY_NOTUSED,
+ /* 187 */ KEY_NOTUSED,
+ /* 188 */ KEY_NOTUSED,
+ /* 189 */ KEY_NOTUSED,
+ /* 190 */ KEY_NOTUSED,
+ /* 191 */ KEY_NOTUSED,
+ /* 192 */ KEY_NOTUSED,
+ /* 193 */ KEY_NOTUSED,
+ /* 194 */ KEY_NOTUSED,
+ /* 195 */ KEY_NOTUSED,
+ /* 196 */ KEY_NOTUSED,
+ /* 197 */ KEY_NOTUSED,
+ /* 198 */ KEY_NOTUSED,
+ /* 199 */ KEY_NOTUSED,
+ /* 200 */ KEY_NOTUSED,
+ /* 201 */ KEY_NOTUSED,
+ /* 202 */ KEY_NOTUSED,
+ /* 203 */ KEY_NOTUSED,
+ /* 204 */ KEY_NOTUSED,
+ /* 205 */ KEY_NOTUSED,
+ /* 206 */ KEY_NOTUSED,
+ /* 207 */ KEY_NOTUSED,
+ /* 208 */ KEY_NOTUSED,
+ /* 209 */ KEY_NOTUSED,
+ /* 210 */ KEY_NOTUSED,
+ /* 211 */ KEY_NOTUSED,
+ /* 212 */ KEY_NOTUSED,
+ /* 213 */ KEY_NOTUSED,
+ /* 214 */ KEY_NOTUSED,
+ /* 215 */ KEY_NOTUSED,
+ /* 216 */ KEY_NOTUSED,
+ /* 217 */ KEY_NOTUSED,
+ /* 218 */ KEY_NOTUSED,
+ /* 219 */ KEY_NOTUSED,
+ /* 220 */ KEY_NOTUSED,
+ /* 221 */ KEY_NOTUSED,
+ /* 222 */ KEY_NOTUSED,
+ /* 223 */ KEY_NOTUSED,
+ /* 224 */ KEY_LCtrl, /* Left Control */
+ /* 225 */ KEY_ShiftL, /* Left Shift */
+ /* 226 */ KEY_Alt, /* Left Alt */
+ /* 227 */ KEY_LMeta, /* Left Meta */
+ /* 228 */ KEY_RCtrl, /* Right Control */
+ /* 229 */ KEY_ShiftR, /* Right Shift */
+ /* 230 */ KEY_AltLang, /* Right Alt, AKA AltGr */
+ /* 231 */ KEY_RMeta, /* Right Meta */
+};
+
+#endif /* KB_USB */
+
+_X_HIDDEN const unsigned char *
+sunGetKbdMapping(int ktype) {
+#if defined(KB_USB)
+ if (ktype == KB_USB)
+ return usbmap;
+ else
+#endif
+ return map;
+}
+
+
+/*
+ * sunPostKbdEvent --
+ * Translate the raw hardware Firm_event into an XEvent, and tell DIX
+ * about it. KeyCode preprocessing and so on is done ...
+ *
+ * Most of the Solaris stuff has whacked Panix/PC98 support in the
+ * interests of simplicity - DWH 8/30/99
+ */
+
+_X_HIDDEN void
+sunPostKbdEvent(int sun_ktype, Firm_event *event)
+{
+ Bool down;
+ KeyClassRec *keyc = ((DeviceIntPtr)xf86Info.pKeyboard)->key;
+ Bool updateLeds = FALSE;
+ xEvent kevent;
+ KeySym *keysym;
+ int keycode;
+ static int lockkeys = 0;
+
+ /* Give down a value */
+ if (event->value == VKEY_DOWN)
+ down = TRUE;
+ else
+ down = FALSE;
+
+
+#if defined(KB_USB)
+ if(sun_ktype == KB_USB)
+ keycode = usbmap[event->id];
+ else
+#endif
+ keycode = map[event->id];
+
+ /*
+ * and now get some special keysequences
+ */
+
+#ifdef XKB
+ if (((xf86Info.ddxSpecialKeys == SKWhenNeeded) &&
+ (!xf86Info.ActionKeyBindingsSet)) ||
+ noXkbExtension || (xf86Info.ddxSpecialKeys == SKAlways))
+#endif
+ {
+ if (!(ModifierDown(ShiftMask)) &&
+ ((ModifierDown(ControlMask | AltMask)) ||
+ (ModifierDown(ControlMask | AltLangMask))))
+ {
+ switch (keycode) {
+ /*
+ * The idea here is to pass the scancode down to a list of
+ * registered routines. There should be some standard conventions
+ * for processing certain keys.
+ */
+ case KEY_BackSpace:
+ xf86ProcessActionEvent(ACTION_TERMINATE, NULL);
+ break;
+
+ /*
+ * Check grabs
+ */
+ case KEY_KP_Divide:
+ xf86ProcessActionEvent(ACTION_DISABLEGRAB, NULL);
+ break;
+ case KEY_KP_Multiply:
+ xf86ProcessActionEvent(ACTION_CLOSECLIENT, NULL);
+ break;
+
+ /*
+ * Video mode switches
+ */
+ case KEY_KP_Minus: /* Keypad - */
+ if (down) xf86ProcessActionEvent(ACTION_PREV_MODE, NULL);
+ if (!xf86Info.dontZoom) return;
+ break;
+
+ case KEY_KP_Plus: /* Keypad + */
+ if (down) xf86ProcessActionEvent(ACTION_NEXT_MODE, NULL);
+ if (!xf86Info.dontZoom) return;
+ break;
+ }
+ }
+ }
+
+ /*
+ * Now map the scancodes to real X-keycodes ...
+ */
+ if (keycode == KEY_NOTUSED) {
+ xf86MsgVerb(X_INFO, 0,
+ "raw code %d mapped to KEY_NOTUSED -- please report\n", event->id);
+ return;
+ }
+ if (keycode == KEY_UNKNOWN) {
+ xf86MsgVerb(X_INFO, 0,
+ "raw code %d mapped to KEY_UNKNOWN -- please report\n", event->id);
+ return;
+ }
+ keycode += MIN_KEYCODE;
+ keysym = keyc->curKeySyms.map +
+ (keyc->curKeySyms.mapWidth *
+ (keycode - keyc->curKeySyms.minKeyCode));
+
+#ifdef XKB
+ if (noXkbExtension)
+#endif
+ {
+ /*
+ * Toggle lock keys.
+ */
+#define CAPSFLAG 0x01
+#define NUMFLAG 0x02
+#define SCROLLFLAG 0x04
+#define MODEFLAG 0x08
+
+ if (down) {
+ /*
+ * Handle the KeyPresses of the lock keys.
+ */
+
+ switch (keysym[0]) {
+
+ case XK_Caps_Lock:
+ if (lockkeys & CAPSFLAG) {
+ lockkeys &= ~CAPSFLAG;
+ return;
+ }
+ lockkeys |= CAPSFLAG;
+ updateLeds = TRUE;
+ xf86Info.capsLock = down;
+ break;
+
+ case XK_Num_Lock:
+ if (lockkeys & NUMFLAG) {
+ lockkeys &= ~NUMFLAG;
+ return;
+ }
+ lockkeys |= NUMFLAG;
+ updateLeds = TRUE;
+ xf86Info.numLock = down;
+ break;
+
+ case XK_Scroll_Lock:
+ if (lockkeys & SCROLLFLAG) {
+ lockkeys &= ~SCROLLFLAG;
+ return;
+ }
+ lockkeys |= SCROLLFLAG;
+ updateLeds = TRUE;
+ xf86Info.scrollLock = down;
+ break;
+ }
+ } else {
+ /*
+ * Handle the releases of the lock keys.
+ */
+
+ switch (keysym[0]) {
+
+ case XK_Caps_Lock:
+ if (lockkeys & CAPSFLAG)
+ return;
+ updateLeds = TRUE;
+ xf86Info.capsLock = down;
+ break;
+
+ case XK_Num_Lock:
+ if (lockkeys & NUMFLAG)
+ return;
+ updateLeds = TRUE;
+ xf86Info.numLock = down;
+ break;
+
+ case XK_Scroll_Lock:
+ if (lockkeys & SCROLLFLAG)
+ return;
+ updateLeds = TRUE;
+ xf86Info.scrollLock = down;
+ break;
+ }
+ }
+
+ if (updateLeds)
+ xf86KbdLeds();
+
+ /*
+ * If this keycode is not a modifier key, and its down initiate the
+ * autorepeate sequence. (Only necessary if not using XKB).
+ *
+ * If its not down, then reset the timer.
+ */
+ if (!keyc->modifierMap[keycode]) {
+ if (down) {
+ startautorepeat(keycode);
+ } else {
+ TimerFree(sunTimer);
+ sunTimer = NULL;
+ }
+ }
+ }
+
+ xf86Info.lastEventTime =
+ kevent.u.keyButtonPointer.time =
+ GetTimeInMillis();
+
+ /*
+ * And now send these prefixes ...
+ * NOTE: There cannot be multiple Mode_Switch keys !!!!
+ */
+
+ ENQUEUE(&kevent, keycode, (down ? KeyPress : KeyRelease), XE_KEYBOARD);
+}
+
+
+
+/*
+ * Autorepeat stuff
+ */
+
+void
+startautorepeat(long keycode)
+{
+ sunTimer = TimerSet(sunTimer, /* Timer */
+ 0, /* Flags */
+ xf86Info.kbdDelay, /* millis */
+ processautorepeat, /* callback */
+ (pointer) keycode); /* arg for timer */
+}
+
+CARD32
+processautorepeat(OsTimerPtr timer, CARD32 now, pointer arg)
+{
+ xEvent kevent;
+ int keycode;
+
+ keycode = (long)arg;
+
+ xf86Info.lastEventTime =
+ kevent.u.keyButtonPointer.time =
+ GetTimeInMillis();
+
+ /*
+ * Repeat a key by faking a KeyRelease, and a KeyPress event in rapid
+ * succession
+ */
+
+ ENQUEUE(&kevent, keycode, KeyRelease, XE_KEYBOARD);
+ ENQUEUE(&kevent, keycode, KeyPress, XE_KEYBOARD);
+
+ /* And return the appropriate value so we get rescheduled */
+ return xf86Info.kbdRate;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_mouse.c
new file mode 100644
index 000000000..928609f0e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_mouse.c
@@ -0,0 +1,719 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_mouse.c,v 1.4 2002/01/25 21:56:21 tsi Exp $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_mouse.c,v 1.8 2005/07/28 02:38:23 alanc Exp $ */
+/*
+ * Copyright 1999-2001 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, 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
+ * XFREE86 PROJECT 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 XFree86 Project 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
+ * XFree86 Project.
+ */
+/* Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86_OSlib.h"
+#include "xf86OSmouse.h"
+
+#if defined(__SOL8__) || !defined(__i386)
+
+#include "xisb.h"
+#include "mipointer.h"
+#include <sys/stropts.h>
+#include <sys/vuid_event.h>
+#include <sys/msio.h>
+
+/* Wheel mouse support in VUID drivers in Solaris 9 updates & Solaris 10 */
+#ifdef WHEEL_DEVID /* Defined in vuid_event.h if VUID wheel support present */
+# define HAVE_VUID_WHEEL
+#endif
+#ifdef HAVE_VUID_WHEEL
+# include <sys/vuid_wheel.h>
+#endif
+
+/* Support for scaling absolute coordinates to screen size in
+ * Solaris 10 updates and beyond */
+#if !defined(HAVE_ABSOLUTE_MOUSE_SCALING)
+# ifdef MSIOSRESOLUTION /* Defined in msio.h if scaling support present */
+# define HAVE_ABSOLUTE_MOUSE_SCALING
+# endif
+#endif
+
+/* Names of protocols that are handled internally here. */
+
+static const char *internalNames[] = {
+ "VUID",
+ NULL
+};
+
+static const char *solarisMouseDevs[] = {
+ /* Device file: Protocol: */
+ "/dev/mouse", "VUID", /* USB or SPARC */
+#if defined(__i386) || defined(__x86)
+ "/dev/kdmouse", "PS/2", /* PS/2 */
+#endif
+ NULL
+};
+
+typedef struct _VuidMseRec {
+ struct _VuidMseRec *next;
+ InputInfoPtr pInfo;
+ Firm_event event;
+ unsigned char * buffer;
+ char * strmod;
+ Bool(*wrapped_device_control)(DeviceIntPtr device, int what);
+#ifdef HAVE_ABSOLUTE_MOUSE_SCALING
+ Ms_screen_resolution absres;
+#endif
+} VuidMseRec, *VuidMsePtr;
+
+static VuidMsePtr vuidMouseList = NULL;
+
+static int vuidMouseProc(DeviceIntPtr pPointer, int what);
+static void vuidReadInput(InputInfoPtr pInfo);
+
+#ifdef HAVE_ABSOLUTE_MOUSE_SCALING
+static void vuidMouseSendScreenSize(ScreenPtr pScreen, VuidMsePtr pVuidMse);
+static void vuidMouseAdjustFrame(int index, int x, int y, int flags);
+
+static int vuidMouseGeneration = 0;
+static int vuidMouseScreenIndex;
+#define vuidMouseScreenPrivate(s) ((s)->devPrivates[vuidMouseScreenIndex].ptr)
+#endif /* HAVE_ABSOLUTE_MOUSE_SCALING */
+
+static inline
+VuidMsePtr getVuidMsePriv(InputInfoPtr pInfo)
+{
+ VuidMsePtr m = vuidMouseList;
+
+ while ((m != NULL) && (m->pInfo != pInfo)) {
+ m = m->next;
+ }
+
+ return m;
+}
+
+
+/*
+ * Initialize and enable the mouse wheel, if present.
+ *
+ * Returns 1 if mouse wheel was successfully enabled.
+ * Returns 0 if an error occurred or if there is no mouse wheel.
+ */
+static int
+vuidMouseWheelInit(InputInfoPtr pInfo)
+{
+#ifdef HAVE_VUID_WHEEL
+ wheel_state wstate;
+ int nwheel = -1;
+ int i;
+
+ wstate.vers = VUID_WHEEL_STATE_VERS;
+ wstate.id = 0;
+ wstate.stateflags = -1;
+
+ SYSCALL(i = ioctl(pInfo->fd, VUIDGWHEELCOUNT, &nwheel));
+ if (i != 0)
+ return (0);
+
+ SYSCALL(i = ioctl(pInfo->fd, VUIDGWHEELSTATE, &wstate));
+ if (i != 0) {
+ xf86Msg(X_WARNING, "%s: couldn't get wheel state\n", pInfo->name);
+ return (0);
+ }
+
+ wstate.stateflags |= VUID_WHEEL_STATE_ENABLED;
+
+ SYSCALL(i = ioctl(pInfo->fd, VUIDSWHEELSTATE, &wstate));
+ if (i != 0) {
+ xf86Msg(X_WARNING, "%s: couldn't enable wheel\n", pInfo->name);
+ return (0);
+ }
+
+ return (1);
+#else
+ return (0);
+#endif
+}
+
+
+/* This function is called when the protocol is "VUID". */
+static Bool
+vuidPreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ MouseDevPtr pMse = pInfo->private;
+ VuidMsePtr pVuidMse;
+ int buttons, i;
+
+ pVuidMse = xcalloc(sizeof(VuidMseRec), 1);
+ if (pVuidMse == NULL) {
+ xf86Msg(X_ERROR, "%s: cannot allocate VuidMouseRec\n", pInfo->name);
+ xfree(pMse);
+ return FALSE;
+ }
+
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ /* Check if the device can be opened. */
+ pInfo->fd = xf86OpenSerial(pInfo->options);
+ if (pInfo->fd == -1) {
+ if (xf86GetAllowMouseOpenFail())
+ xf86Msg(X_WARNING, "%s: cannot open input device\n", pInfo->name);
+ else {
+ xf86Msg(X_ERROR, "%s: cannot open input device\n", pInfo->name);
+ xfree(pVuidMse);
+ xfree(pMse);
+ return FALSE;
+ }
+ }
+
+ pVuidMse->buffer = (unsigned char *)&pVuidMse->event;
+
+ pVuidMse->strmod = xf86SetStrOption(pInfo->options, "StreamsModule", NULL);
+ if (pVuidMse->strmod) {
+ SYSCALL(i = ioctl(pInfo->fd, I_PUSH, pVuidMse->strmod));
+ if (i < 0) {
+ xf86Msg(X_ERROR,
+ "%s: cannot push module '%s' onto mouse device: %s\n",
+ pInfo->name, pVuidMse->strmod, strerror(errno));
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+ xfree(pVuidMse->strmod);
+ xfree(pVuidMse);
+ xfree(pMse);
+ return FALSE;
+ }
+ }
+
+ buttons = xf86SetIntOption(pInfo->options, "Buttons", 0);
+ if (buttons == 0) {
+ SYSCALL(i = ioctl(pInfo->fd, MSIOBUTTONS, &buttons));
+ if (i == 0) {
+ pInfo->conf_idev->commonOptions =
+ xf86ReplaceIntOption(pInfo->conf_idev->commonOptions,
+ "Buttons", buttons);
+ xf86Msg(X_INFO, "%s: Setting Buttons option to \"%d\"\n",
+ pInfo->name, buttons);
+ }
+ }
+
+ if (pVuidMse->strmod) {
+ SYSCALL(i = ioctl(pInfo->fd, I_POP, pVuidMse->strmod));
+ if (i == -1) {
+ xf86Msg(X_WARNING,
+ "%s: cannot pop module '%s' off mouse device: %s\n",
+ pInfo->name, pVuidMse->strmod, strerror(errno));
+ }
+ }
+
+ xf86CloseSerial(pInfo->fd);
+ pInfo->fd = -1;
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local procs. */
+ pVuidMse->wrapped_device_control = pInfo->device_control;
+ pInfo->device_control = vuidMouseProc;
+ pInfo->read_input = vuidReadInput;
+
+ pMse->xisbscale = sizeof(Firm_event);
+
+#ifdef HAVE_ABSOLUTE_MOUSE_SCALING
+ pVuidMse->absres.height = pVuidMse->absres.width = 0;
+#endif
+ pVuidMse->pInfo = pInfo;
+ pVuidMse->next = vuidMouseList;
+ vuidMouseList = pVuidMse;
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+
+static void
+vuidFlushAbsEvents(InputInfoPtr pInfo, int absX, int absY,
+ Bool *absXset, Bool *absYset)
+{
+#ifdef DEBUG
+ ErrorF("vuidFlushAbsEvents: %d,%d (set: %d, %d)\n", absX, absY,
+ *absXset, *absYset);
+#endif
+ if ((*absXset) && (*absYset)) {
+ xf86PostMotionEvent(pInfo->dev,
+ /* is_absolute: */ TRUE,
+ /* first_valuator: */ 0,
+ /* num_valuators: */ 2,
+ absX, absY);
+ } else if (*absXset) {
+ xf86PostMotionEvent(pInfo->dev,
+ /* is_absolute: */ TRUE,
+ /* first_valuator: */ 0,
+ /* num_valuators: */ 1,
+ absX);
+ } else if (*absYset) {
+ xf86PostMotionEvent(pInfo->dev,
+ /* is_absolute: */ TRUE,
+ /* first_valuator: */ 1,
+ /* num_valuators: */ 1,
+ absY);
+ }
+
+ *absXset = FALSE;
+ *absYset = FALSE;
+}
+
+static void
+vuidReadInput(InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse;
+ VuidMsePtr pVuidMse;
+ int buttons;
+ int dx = 0, dy = 0, dz = 0, dw = 0;
+ unsigned int n;
+ int c;
+ unsigned char *pBuf;
+ int wmask;
+ int absX, absY;
+ Bool absXset = FALSE, absYset = FALSE;
+
+ pMse = pInfo->private;
+ pVuidMse = getVuidMsePriv(pInfo);
+ buttons = pMse->lastButtons;
+ XisbBlockDuration(pMse->buffer, -1);
+ pBuf = pVuidMse->buffer;
+ n = 0;
+
+ do {
+ while (n < sizeof(Firm_event) && (c = XisbRead(pMse->buffer)) >= 0) {
+ pBuf[n++] = (unsigned char)c;
+ }
+
+ if (n == 0)
+ return;
+
+ if (n != sizeof(Firm_event)) {
+ xf86Msg(X_WARNING, "%s: incomplete packet, size %d\n",
+ pInfo->name, n);
+ }
+
+#ifdef DEBUG
+ ErrorF("vuidReadInput: event type: %3d value: %5d\n",
+ pVuidMse->event.id, pVuidMse->event.value);
+#endif
+
+ if (pVuidMse->event.id >= BUT_FIRST && pVuidMse->event.id <= BUT_LAST) {
+ /* button */
+ int butnum = pVuidMse->event.id - BUT_FIRST;
+
+ if (butnum < 3)
+ butnum = 2 - butnum;
+ if (!pVuidMse->event.value)
+ buttons &= ~(1 << butnum);
+ else
+ buttons |= (1 << butnum);
+ } else if (pVuidMse->event.id >= VLOC_FIRST &&
+ pVuidMse->event.id <= VLOC_LAST) {
+ /* axis */
+ int delta = pVuidMse->event.value;
+ switch(pVuidMse->event.id) {
+ case LOC_X_DELTA:
+ dx += delta;
+ break;
+ case LOC_Y_DELTA:
+ dy -= delta;
+ break;
+ case LOC_X_ABSOLUTE:
+ if (absXset) {
+ vuidFlushAbsEvents(pInfo, absX, absY, &absXset, &absYset);
+ }
+ absX = delta;
+ absXset = TRUE;
+ break;
+ case LOC_Y_ABSOLUTE:
+ if (absYset) {
+ vuidFlushAbsEvents(pInfo, absX, absY, &absXset, &absYset);
+ }
+ absY = delta;
+ absYset = TRUE;
+ break;
+ }
+ }
+#ifdef HAVE_VUID_WHEEL
+ else if (vuid_in_range(VUID_WHEEL, pVuidMse->event.id)) {
+ if (vuid_id_offset(pVuidMse->event.id) == 0)
+ dz -= VUID_WHEEL_GETDELTA(pVuidMse->event.value);
+ else
+ dw -= VUID_WHEEL_GETDELTA(pVuidMse->event.value);
+ }
+#endif
+#ifdef HAVE_ABSOLUTE_MOUSE_SCALING
+ else if (pVuidMse->event.id == MOUSE_TYPE_ABSOLUTE) {
+ /* force sending absolute resolution scaling ioctl */
+ pVuidMse->absres.height = pVuidMse->absres.width = 0;
+ vuidMouseSendScreenSize(miPointerCurrentScreen(), pVuidMse);
+ }
+#endif
+
+ n = 0;
+ if ((c = XisbRead(pMse->buffer)) >= 0) {
+ /* Another packet. Handle it right away. */
+ pBuf[n++] = c;
+ }
+ } while (n != 0);
+
+ if (absXset || absYset) {
+ vuidFlushAbsEvents(pInfo, absX, absY, &absXset, &absYset);
+ }
+
+ pMse->PostEvent(pInfo, buttons, dx, dy, dz, dw);
+ return;
+}
+
+#ifdef HAVE_ABSOLUTE_MOUSE_SCALING
+static void vuidMouseSendScreenSize(ScreenPtr pScreen, VuidMsePtr pVuidMse)
+{
+ InputInfoPtr pInfo = pVuidMse->pInfo;
+ ScrnInfoPtr pScr = XF86SCRNINFO(pScreen);
+ int result;
+
+ if ((pVuidMse->absres.width != pScr->currentMode->HDisplay) ||
+ (pVuidMse->absres.height != pScr->currentMode->VDisplay))
+ {
+ pVuidMse->absres.width = pScr->currentMode->HDisplay;
+ pVuidMse->absres.height = pScr->currentMode->VDisplay;
+
+ do {
+ result = ioctl(pInfo->fd, MSIOSRESOLUTION, &(pVuidMse->absres));
+ } while ( (result != 0) && (errno == EINTR) );
+
+ if (result != 0) {
+ xf86Msg(X_WARNING,
+ "%s: couldn't set absolute mouse scaling resolution: %s\n",
+ pInfo->name, strerror(errno));
+#ifdef DEBUG
+ } else {
+ xf86Msg(X_INFO,
+ "%s: absolute mouse scaling resolution set to %d x %d\n",
+ pInfo->name,
+ pVuidMse->absres.width, pVuidMse->absres.height);
+#endif
+ }
+ }
+}
+
+static void vuidMouseAdjustFrame(int index, int x, int y, int flags)
+{
+ ScrnInfoPtr pScrn = xf86Screens[index];
+ ScreenPtr pScreen = pScrn->pScreen;
+ xf86AdjustFrameProc *wrappedAdjustFrame
+ = (xf86AdjustFrameProc *) vuidMouseScreenPrivate(pScreen);
+ VuidMsePtr m;
+
+ if(wrappedAdjustFrame) {
+ pScrn->AdjustFrame = wrappedAdjustFrame;
+ (*pScrn->AdjustFrame)(index, x, y, flags);
+ pScrn->AdjustFrame = vuidMouseAdjustFrame;
+ }
+
+ if (miPointerCurrentScreen() == pScreen) {
+ for (m = vuidMouseList; m != NULL ; m = m->next) {
+ vuidMouseSendScreenSize(pScreen, m);
+ }
+ }
+}
+#endif /* HAVE_ABSOLUTE_MOUSE_SCALING */
+
+
+static int
+vuidMouseProc(DeviceIntPtr pPointer, int what)
+{
+ InputInfoPtr pInfo;
+ MouseDevPtr pMse;
+ VuidMsePtr pVuidMse;
+ int ret = Success;
+ int i;
+
+ pInfo = pPointer->public.devicePrivate;
+ pMse = pInfo->private;
+ pMse->device = pPointer;
+
+ pVuidMse = getVuidMsePriv(pInfo);
+ if (pVuidMse == NULL) {
+ return BadImplementation;
+ }
+
+ switch (what) {
+
+ case DEVICE_INIT:
+#ifdef HAVE_ABSOLUTE_MOUSE_SCALING
+ if (vuidMouseGeneration != serverGeneration) {
+ if ((vuidMouseScreenIndex = AllocateScreenPrivateIndex()) >= 0) {
+ for (i = 0; i < screenInfo.numScreens; i++) {
+ ScreenPtr pScreen = screenInfo.screens[i];
+ ScrnInfoPtr pScrn = XF86SCRNINFO(pScreen);
+ vuidMouseScreenPrivate(pScreen)
+ = (pointer) pScrn->AdjustFrame;
+ pScrn->AdjustFrame = vuidMouseAdjustFrame;
+ }
+ }
+ vuidMouseGeneration = serverGeneration;
+ }
+#endif
+ ret = pVuidMse->wrapped_device_control(pPointer, what);
+ break;
+
+ case DEVICE_ON:
+ ret = pVuidMse->wrapped_device_control(pPointer, DEVICE_ON);
+
+ if ((ret == Success) && (pInfo->fd != -1)) {
+ int fmt = VUID_FIRM_EVENT;
+
+ if (pVuidMse->strmod) {
+ SYSCALL(i = ioctl(pInfo->fd, I_PUSH, pVuidMse->strmod));
+ if (i < 0) {
+ xf86Msg(X_WARNING,
+ "%s: cannot push module '%s' onto mouse device: %s\n",
+ pInfo->name, pVuidMse->strmod, strerror(errno));
+ xfree(pVuidMse->strmod);
+ pVuidMse->strmod = NULL;
+ }
+ }
+ SYSCALL(i = ioctl(pInfo->fd, VUIDSFORMAT, &fmt));
+ if (i < 0) {
+ xf86Msg(X_WARNING,
+ "%s: cannot set mouse device to VUID mode: %s\n",
+ pInfo->name, strerror(errno));
+ }
+ vuidMouseWheelInit(pInfo);
+#ifdef HAVE_ABSOLUTE_MOUSE_SCALING
+ vuidMouseSendScreenSize(screenInfo.screens[0], pVuidMse);
+#endif
+ xf86FlushInput(pInfo->fd);
+ }
+ break;
+
+ case DEVICE_OFF:
+ case DEVICE_CLOSE:
+ if (pInfo->fd != -1) {
+ if (pVuidMse->strmod) {
+ SYSCALL(i = ioctl(pInfo->fd, I_POP, pVuidMse->strmod));
+ if (i == -1) {
+ xf86Msg(X_WARNING,
+ "%s: cannot pop module '%s' off mouse device: %s\n",
+ pInfo->name, pVuidMse->strmod, strerror(errno));
+ }
+ }
+ }
+ ret = pVuidMse->wrapped_device_control(pPointer, what);
+ break;
+
+ default: /* Should never be called, but just in case */
+ ret = pVuidMse->wrapped_device_control(pPointer, what);
+ break;
+ }
+ return ret;
+}
+
+static Bool
+sunMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ /* The protocol is guaranteed to be one of the internalNames[] */
+ if (xf86NameCmp(protocol, "VUID") == 0) {
+ return vuidPreInit(pInfo, protocol, flags);
+ }
+ return TRUE;
+}
+
+static const char **
+BuiltinNames(void)
+{
+ return internalNames;
+}
+
+static Bool
+CheckProtocol(const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++)
+ if (xf86NameCmp(protocol, internalNames[i]) == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
+static const char *
+DefaultProtocol(void)
+{
+ return "Auto";
+}
+
+static Bool
+solarisMouseAutoProbe(InputInfoPtr pInfo, const char **protocol,
+ const char **device)
+{
+ const char **pdev, **pproto, *dev = NULL;
+ int fd = -1;
+ Bool found;
+
+ for (pdev = solarisMouseDevs; *pdev; pdev += 2) {
+ pproto = pdev + 1;
+ if ((*protocol != NULL) && (strcmp(*protocol, "Auto") != 0) &&
+ (*pproto != NULL) && (strcmp(*pproto, *protocol) != 0)) {
+ continue;
+ }
+ if ((*device != NULL) && (strcmp(*device, *pdev) != 0)) {
+ continue;
+ }
+ SYSCALL (fd = open(*pdev, O_RDWR | O_NONBLOCK));
+ if (fd == -1) {
+#ifdef DEBUG
+ ErrorF("Cannot open %s (%s)\n", pdev, strerror(errno));
+#endif
+ } else {
+ found = TRUE;
+ if ((*pproto != NULL) && (strcmp(*pproto, "VUID") == 0)) {
+ int i, r;
+ SYSCALL(r = ioctl(fd, VUIDGFORMAT, &i));
+ if (r < 0) {
+ found = FALSE;
+ }
+ }
+ close(fd);
+ if (found == TRUE) {
+ if (*pproto != NULL) {
+ *protocol = *pproto;
+ }
+ *device = *pdev;
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+
+static const char *
+SetupAuto(InputInfoPtr pInfo, int *protoPara)
+{
+ const char *pdev = NULL;
+ const char *pproto = NULL;
+ MouseDevPtr pMse = pInfo->private;
+
+ if (pInfo->fd == -1) {
+ /* probe to find device/protocol to use */
+ if (solarisMouseAutoProbe(pInfo, &pproto, &pdev) != FALSE) {
+ /* Set the Device option. */
+ pInfo->conf_idev->commonOptions =
+ xf86AddNewOption(pInfo->conf_idev->commonOptions, "Device", pdev);
+ xf86Msg(X_INFO, "%s: Setting Device option to \"%s\"\n",
+ pInfo->name, pdev);
+ }
+ } else if (pMse->protocolID == PROT_AUTO) {
+ pdev = xf86CheckStrOption(pInfo->conf_idev->commonOptions,
+ "Device", NULL);
+ solarisMouseAutoProbe(pInfo, &pproto, &pdev);
+ }
+ return pproto;
+}
+
+static const char *
+FindDevice(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ const char *pdev = NULL;
+ const char *pproto = protocol;
+
+ if (solarisMouseAutoProbe(pInfo, &pproto, &pdev) != FALSE) {
+ /* Set the Device option. */
+ pInfo->conf_idev->commonOptions =
+ xf86AddNewOption(pInfo->conf_idev->commonOptions, "Device", pdev);
+ xf86Msg(X_INFO, "%s: Setting Device option to \"%s\"\n",
+ pInfo->name, pdev);
+ }
+ return pdev;
+}
+
+#else /* __SOL8__ || !__i386 */
+
+#undef MSE_MISC
+#define MSE_MISC 0
+
+#endif /* !__SOL8__ && __i386 */
+
+static int
+SupportedInterfaces(void)
+{
+ /* XXX This needs to be checked. */
+ return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_AUTO | MSE_XPS2 | MSE_MISC;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+#if defined(__SOL8__) || !defined(__i386)
+ p->BuiltinNames = BuiltinNames;
+ p->CheckProtocol = CheckProtocol;
+ p->PreInit = sunMousePreInit;
+ p->DefaultProtocol = DefaultProtocol;
+ p->SetupAuto = SetupAuto;
+ p->FindDevice = FindDevice;
+#endif
+ return p;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c
new file mode 100644
index 000000000..82cd1ae7b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c
@@ -0,0 +1,237 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_vid.c,v 1.2 2001/10/28 03:34:03 tsi Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the names of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
+ * SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <sys/types.h> /* get __x86 definition if not set by compiler */
+
+#if defined(i386) || defined(__x86)
+#define _NEED_SYSI86
+#endif
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+char *apertureDevName = NULL;
+
+Bool
+xf86LinearVidMem(void)
+{
+ int mmapFd;
+
+ if (apertureDevName)
+ return TRUE;
+
+ apertureDevName = "/dev/xsvc";
+ if ((mmapFd = open(apertureDevName, O_RDWR)) < 0)
+ {
+ apertureDevName = "/dev/fbs/aperture";
+ if((mmapFd = open(apertureDevName, O_RDWR)) < 0)
+ {
+ xf86MsgVerb(X_WARNING, 0,
+ "xf86LinearVidMem: failed to open %s (%s)\n",
+ apertureDevName, strerror(errno));
+ xf86MsgVerb(X_WARNING, 0,
+ "xf86LinearVidMem: either /dev/fbs/aperture or /dev/xsvc"
+ " device driver required\n");
+ xf86MsgVerb(X_WARNING, 0,
+ "xf86LinearVidMem: linear memory access disabled\n");
+ apertureDevName = NULL;
+ return FALSE;
+ }
+ }
+ close(mmapFd);
+ return TRUE;
+}
+
+pointer
+xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
+{
+ pointer base;
+ int fd;
+ char vtname[20];
+
+ /*
+ * Solaris 2.1 x86 SVR4 (10/27/93)
+ * The server must treat the virtual terminal device file as the
+ * standard SVR4 /dev/pmem.
+ *
+ * Using the /dev/vtXX device as /dev/pmem only works for the
+ * A0000-FFFFF region - If we wish you mmap the linear aperture
+ * it requires a device driver.
+ *
+ * So what we'll do is use /dev/vtXX for the A0000-FFFFF stuff, and
+ * try to use the /dev/fbs/aperture or /dev/xsvc driver if the server
+ * tries to mmap anything > FFFFF. Its very very unlikely that the
+ * server will try to mmap anything below FFFFF that can't be handled
+ * by /dev/vtXX.
+ *
+ * DWH - 2/23/94
+ * DWH - 1/31/99 (Gee has it really been 5 years?)
+ *
+ * Solaris 2.8 7/26/99
+ * Use /dev/xsvc for everything
+ *
+ * DWH - 7/26/99 - Solaris8/dev/xsvc changes
+ *
+ * TSI - 2001.09 - SPARC changes
+ */
+
+#if defined(i386) && !defined(__SOL8__)
+ if(Base < 0xFFFFF)
+ sprintf(vtname, "/dev/vt%02d", xf86Info.vtno);
+ else
+#endif
+ {
+ if (!xf86LinearVidMem())
+ FatalError("xf86MapVidMem: no aperture device\n");
+
+ strcpy(vtname, apertureDevName);
+ }
+
+ fd = open(vtname, (Flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
+ if (fd < 0)
+ FatalError("xf86MapVidMem: failed to open %s (%s)\n",
+ vtname, strerror(errno));
+
+ base = mmap(NULL, Size,
+ (Flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, fd, (off_t)Base);
+ close(fd);
+ if (base == MAP_FAILED)
+ FatalError("xf86MapVidMem: mmap failure: %s\n",
+ strerror(errno));
+
+ return(base);
+}
+
+/* ARGSUSED */
+void
+xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap(Base, Size);
+}
+
+/***************************************************************************/
+/* I/O Permissions section */
+/***************************************************************************/
+
+#if defined(i386) || defined(__x86)
+static Bool ExtendedEnabled = FALSE;
+#endif
+
+Bool
+xf86EnableIO(void)
+{
+#if defined(i386) || defined(__x86)
+ if (ExtendedEnabled)
+ return TRUE;
+
+ if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) {
+ xf86Msg(X_WARNING,"xf86EnableIOPorts: Failed to set IOPL for I/O\n");
+ return FALSE;
+ }
+ ExtendedEnabled = TRUE;
+#endif /* i386 */
+ return TRUE;
+}
+
+void
+xf86DisableIO(void)
+{
+#if defined(i386) || defined(__x86)
+ if(!ExtendedEnabled)
+ return;
+
+ sysi86(SI86V86, V86SC_IOPL, 0);
+
+ ExtendedEnabled = FALSE;
+#endif /* i386 */
+}
+
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool xf86DisableInterrupts(void)
+{
+#if defined(i386) || defined(__x86)
+ if (!ExtendedEnabled && (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0))
+ return FALSE;
+
+#ifdef __GNUC__
+ __asm__ __volatile__("cli");
+#else
+ asm("cli");
+#endif /* __GNUC__ */
+
+ if (!ExtendedEnabled)
+ sysi86(SI86V86, V86SC_IOPL, 0);
+#endif /* i386 */
+
+ return TRUE;
+}
+
+void xf86EnableInterrupts(void)
+{
+#if defined(i386) || defined(__x86)
+ if (!ExtendedEnabled && (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0))
+ return;
+
+#ifdef __GNUC__
+ __asm__ __volatile__("sti");
+#else
+ asm("sti");
+#endif /* __GNUC__ */
+
+ if (!ExtendedEnabled)
+ sysi86(SI86V86, V86SC_IOPL, 0);
+#endif /* i386 */
+}
+
+void
+xf86MapReadSideEffects(int ScreenNum, int Flags, pointer Base,
+ unsigned long Size)
+{
+}
+
+Bool
+xf86CheckMTRR(int ScreenNum)
+{
+ return FALSE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/Imakefile
new file mode 100644
index 000000000..2ba9baf92
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/Imakefile
@@ -0,0 +1,58 @@
+XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sysv/Imakefile,v 3.24 2002/10/11 01:47:00 dawes Exp $
+
+
+
+
+
+XCOMM $XConsortium: Imakefile /main/10 1996/10/25 11:38:05 kaleb $
+
+#include <Server.tmpl>
+
+#if defined(SVR4Architecture) || defined(i386Sco325Architecture)
+BIOS_MOD = bios_mmap
+#else
+BIOS_MOD = bios_devmem
+#endif
+
+MOUSESRC = sysv_mouse.c
+MOUSEOBJ = sysv_mouse.o
+
+SRCS = sysv_init.c sysv_video.c sysv_io.c $(BIOS_MOD).c VTsw_usl.c \
+ sysv_kbd.c std_kbdEv.c posix_tty.c $(MOUSESRC) xqueue.c \
+ libc_wrapper.c stdResource.c stdPci.c vidmem.c sigiostubs.c pm_noop.c \
+ kmod_noop.c agp_noop.c
+
+OBJS = sysv_init.o sysv_video.o sysv_io.o $(BIOS_MOD).o VTsw_usl.o \
+ sysv_kbd.o std_kbdEv.o posix_tty.o $(MOUSEOBJ) xqueue.o \
+ libc_wrapper.o stdResource.o stdPci.o vidmem.o sigiostubs.o pm_noop.o \
+ kmod_noop.o agp_noop.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(SERVERSRC)/mi
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+#if !defined(SVR4Architecture)
+LinkSourceFile(bios_devmem.c,../shared)
+#else
+LinkSourceFile(bios_mmap.c,../shared)
+#endif
+LinkSourceFile(VTsw_usl.c,../shared)
+LinkSourceFile(sysv_kbd.c,../shared)
+LinkSourceFile(std_kbdEv.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(vidmem.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_init.c
new file mode 100644
index 000000000..3edffd446
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_init.c
@@ -0,0 +1,254 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sysv/sysv_init.c,v 3.4.4.3 1998/07/18 17:53:57 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Wexelblat makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: sysv_init.c /main/4 1996/02/21 17:54:31 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xmd.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+static Bool KeepTty = FALSE;
+#ifdef SVR4
+static Bool Protect0 = FALSE;
+#endif
+static int VTnum = -1;
+
+
+void
+xf86OpenConsole()
+{
+ int fd;
+ struct vt_mode VT;
+ char vtname1[10],vtname2[10];
+ MessageType from = X_PROBED;
+
+ if (serverGeneration == 1)
+ {
+ /* check if we're run with euid==0 */
+ if (geteuid() != 0)
+ {
+ FatalError("xf86OpenConsole: Server must be suid root\n");
+ }
+
+#ifdef SVR4
+ /* Protect page 0 to help find NULL dereferencing */
+ /* mprotect() doesn't seem to work */
+ if (Protect0)
+ {
+ int fd = -1;
+
+ if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0)
+ {
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: cannot open /dev/zero (%s)\n",
+ strerror(errno));
+ }
+ else
+ {
+ if ((int)mmap(0, 0x1000, PROT_NONE,
+ MAP_FIXED | MAP_SHARED, fd, 0) == -1)
+ {
+ xf86Msg(X_WARNING,
+ "xf86OpenConsole: failed to protect page 0 (%s)\n",
+ strerror(errno));
+ }
+ close(fd);
+ }
+ }
+#endif
+ /*
+ * setup the virtual terminal manager
+ */
+ if (VTnum != -1)
+ {
+ xf86Info.vtno = VTnum;
+ from = X_CMDLINE;
+ }
+ else
+ {
+ if ((fd = open("/dev/console",O_WRONLY,0)) < 0)
+ {
+ FatalError(
+ "xf86OpenConsole: Cannot open /dev/console (%s)\n",
+ strerror(errno));
+ }
+ if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
+ (xf86Info.vtno == -1))
+ {
+ FatalError("xf86OpenConsole: Cannot find a free VT\n");
+ }
+ close(fd);
+ }
+ xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno);
+
+ sprintf(vtname1,"/dev/vc%02d",xf86Info.vtno); /* ESIX */
+ sprintf(vtname2,"/dev/vt%02d",xf86Info.vtno); /* rest of the world */
+
+ if (!KeepTty)
+ {
+ setpgrp();
+ }
+
+ if (((xf86Info.consoleFd = open(vtname1, O_RDWR|O_NDELAY, 0)) < 0) &&
+ ((xf86Info.consoleFd = open(vtname2, O_RDWR|O_NDELAY, 0)) < 0))
+ {
+ FatalError("xf86OpenConsole: Cannot open %s (%s) (%s)\n",
+ vtname2, vtname1, strerror(errno));
+ }
+
+ /* change ownership of the vt */
+ if (chown(vtname1, getuid(), getgid()) < 0)
+ {
+ chown(vtname2, getuid(), getgid());
+ }
+
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
+ {
+ FatalError("xf86OpenConsole: VT_GETMODE failed\n");
+ }
+
+ signal(SIGUSR1, xf86VTRequest);
+
+ VT.mode = VT_PROCESS;
+ VT.relsig = SIGUSR1;
+ VT.acqsig = SIGUSR1;
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
+ {
+ FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
+ {
+ FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n");
+ }
+ }
+ else
+ {
+ /* serverGeneration != 1 */
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
+ {
+ xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
+ }
+ /*
+ * If the server doesn't have the VT when the reset occurs,
+ * this is to make sure we don't continue until the activate
+ * signal is received.
+ */
+ if (!xf86Screens[0]->vtSema)
+ sleep(5);
+ }
+ return;
+}
+
+void
+xf86CloseConsole()
+{
+ struct vt_mode VT;
+
+#if 0
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno);
+ ioctl(xf86Info.consoleFd, VT_WAITACTIVE, 0);
+#endif
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode ... */
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
+ {
+ VT.mode = VT_AUTO;
+ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */
+ }
+ close(xf86Info.consoleFd); /* make the vt-manager happy */
+ return;
+}
+
+int
+xf86ProcessArgument(int argc, char *argv[], int i)
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful
+ * when debugging (so the server can receive keyboard signals.
+ */
+ if (!strcmp(argv[i], "-keeptty"))
+ {
+ KeepTty = TRUE;
+ return(1);
+ }
+#ifdef SVR4
+ /*
+ * Undocumented flag to protect page 0 from read/write to help
+ * catch NULL pointer dereferences. This is purely a debugging
+ * flag.
+ */
+ if (!strcmp(argv[i], "-protect0"))
+ {
+ Protect0 = TRUE;
+ return(1);
+ }
+#endif
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+ {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ return(1);
+ }
+ return(0);
+}
+
+void
+xf86UseMsg()
+{
+ ErrorF("vtXX use the specified VT number\n");
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_io.c
new file mode 100644
index 000000000..6fb642bce
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_io.c
@@ -0,0 +1,78 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sysv/sysv_io.c,v 3.10 2002/10/11 01:40:37 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Dawes makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID DAWES BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: sysv_io.c /main/8 1996/10/19 18:08:06 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ if (loudness && pitch)
+ {
+#ifdef KDMKTONE
+ /*
+ * If we have KDMKTONE use it to avoid putting the server
+ * to sleep
+ */
+ ioctl(xf86Info.consoleFd, KDMKTONE,
+ ((1193190 / pitch) & 0xffff) |
+ (((unsigned long)duration *
+ loudness / 50) << 16));
+#else
+ ioctl(xf86Info.consoleFd, KIOCSOUND, 1193180 / pitch);
+ usleep(xf86Info.bell_duration * loudness * 20);
+ ioctl(xf86Info.consoleFd, KIOCSOUND, 0);
+#endif
+ }
+}
+
+void
+xf86SetKbdLeds(int leds)
+{
+#ifdef KBIO_SETMODE
+ ioctl(xf86Info.consoleFd, KBIO_SETMODE, KBM_AT);
+ ioctl(xf86Info.consoleFd, KDSETLED, leds);
+ ioctl(xf86Info.consoleFd, KBIO_SETMODE, KBM_XT);
+#endif
+}
+
+#include "xf86OSKbd.h"
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ return FALSE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_mouse.c
new file mode 100644
index 000000000..f839362fc
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_mouse.c
@@ -0,0 +1,64 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sysv/sysv_mouse.c,v 1.3 1999/09/04 13:04:49 dawes Exp $ */
+
+/*
+ * Copyright 1999 by The XFree86 Project, Inc.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "xqueue.h"
+
+static int
+SupportedInterfaces(void)
+{
+ /* XXX Need to check this. */
+ return MSE_SERIAL | MSE_AUTO;
+}
+
+#ifndef ISC
+static const char *internalNames[] = {
+ "Xqueue",
+ NULL
+};
+
+static const char **
+BuiltinNames(void)
+{
+ return internalNames;
+}
+
+static Bool
+CheckProtocol(const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++)
+ if (xf86NameCmp(protocol, internalNames[i]) == 0)
+ return TRUE;
+ return FALSE;
+}
+#endif
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+ p->SupportedInterfaces = SupportedInterfaces;
+#ifndef ISC
+ p->BuiltinNames = BuiltinNames;
+ p->CheckProtocol = CheckProtocol;
+ p->PreInit = XqueueMousePreInit;
+#endif
+ return p;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c
new file mode 100644
index 000000000..e8c26dada
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c
@@ -0,0 +1,369 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sysv/sysv_video.c,v 3.20tsi Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Thomas Roell and
+ * David Wexelblat makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THOMAS ROELL AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: sysv_video.c /main/8 1996/10/25 11:38:09 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+
+#define _NEED_SYSI86
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+#ifndef SI86IOPL
+#define SET_IOPL() sysi86(SI86V86,V86SC_IOPL,PS_IOPL)
+#define RESET_IOPL() sysi86(SI86V86,V86SC_IOPL,0)
+#else
+#define SET_IOPL() sysi86(SI86IOPL,3)
+#define RESET_IOPL() sysi86(SI86IOPL,0)
+#endif
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+/*
+ * XXX Support for SVR3 will need to be reworked if needed. In particular
+ * the Region parameter is no longer passed, and will need to be dealt
+ * with internally if required.
+ * OK, i'll rework that thing ... (clean it up a lot)
+ * SVR3 Support only with SVR3_MMAPDRV (mr)
+ *
+ */
+
+#ifdef HAS_SVR3_MMAPDRV
+#ifndef MMAP_DEBUG
+#define MMAP_DEBUG 3
+#endif
+
+struct kd_memloc MapDSC;
+int mmapFd = -2;
+
+static int
+mmapStat(pointer Base, unsigned long Size) {
+
+ int nmmreg,i=0,region=-1;
+ mmapinfo_t *ibuf;
+
+ nmmreg = ioctl(mmapFd, GETNMMREG);
+
+ if(nmmreg <= 0)
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "\nNo physical memory mapped currently.\n\n");
+ else {
+ if((ibuf = (mmapinfo_t *)malloc(nmmreg*sizeof(mmapinfo_t))) == NULL)
+ xf86Msg(X_WARNING,
+ "Couldn't allocate memory 4 mmapinfo_t\n");
+ else {
+ if(ioctl(mmapFd, GETMMREG, ibuf) != -1)
+ {
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "# mmapStat: [Size=%x,Base=%x]\n", Size, Base);
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "# Physical Address Size Reference Count\n");
+ for(i = 0; i < nmmreg; i++) {
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "%-4d 0x%08X %5dk %5d ",
+ i, ibuf[i].physaddr, ibuf[i].length/1024, ibuf[i].refcnt);
+ if (ibuf[i].physaddr == Base || ibuf[i].length == Size ) {
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,"MATCH !!!");
+ if (region==-1) region=i;
+ }
+ xf86ErrorFVerb(MMAP_DEBUG, "\n");
+ }
+ xf86ErrorFVerb(MMAP_DEBUG, "\n");
+ }
+ free(ibuf);
+ }
+ }
+ if (region == -1 && nmmreg > 0) region=region * i;
+ return(region);
+}
+#endif
+
+
+static Bool
+linearVidMem()
+{
+#ifdef SVR4
+ return TRUE;
+#elif defined(HAS_SVR3_MMAPDRV)
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "# xf86LinearVidMem: MMAP 2.2.2 called\n");
+
+ if(mmapFd >= 0) return TRUE;
+
+ if ((mmapFd = open("/dev/mmap", O_RDWR)) != -1)
+ {
+ if(ioctl(mmapFd, GETVERSION) < 0x0222) {
+ xf86Msg(X_WARNING,
+ "xf86LinearVidMem: MMAP 2.2.2 or above required\n");
+ xf86ErrorF("\tlinear memory access disabled\n");
+ return FALSE;
+ }
+ return TRUE;
+ }
+ xf86Msg(X_WARNING, "xf86LinearVidMem: failed to open /dev/mmap (%s)\n",
+ strerror(errno));
+ xf86ErrorF("\tlinear memory access disabled\n");
+ return FALSE;
+#endif
+}
+
+static pointer
+mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ pointer base;
+ int fd;
+
+#if defined(SVR4)
+ fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
+ if (fd < 0)
+ {
+ FatalError("xf86MapVidMem: failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ base = mmap((caddr_t)0, Size,
+ (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, fd, (off_t)Base);
+ close(fd);
+ if (base == MAP_FAILED)
+ {
+ FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
+ "xf86MapVidMem", Size, Base, strerror(errno));
+ }
+#else /* SVR4 */
+#ifdef HAS_SVR3_MMAPDRV
+
+ xf86MsgVerb(X_INFO, MMAP_DEBUG, "# xf86MapVidMem: MMAP 2.2.2 called\n");
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "MMAP_VERSION: 0x%x\n",ioctl(mmapFd, GETVERSION));
+ if (ioctl(mmapFd, GETVERSION) == -1)
+ {
+ xf86LinearVidMem();
+ }
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "MMAP_VERSION: 0x%x\n",ioctl(mmapFd, GETVERSION));
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "xf86MapVidMem: Screen: %d\n", ScreenNum);
+ mmapStat(Base,Size);
+ /* To force the MMAP driver to provide the address */
+ base = (pointer)0;
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "xf86MapVidMem: [s=%x,a=%x]\n", Size, Base);
+ MapDSC.vaddr = (char *)base;
+ MapDSC.physaddr = (char *)Base;
+ MapDSC.length = Size;
+ MapDSC.ioflg = 1;
+ if(mmapFd >= 0)
+ {
+ if((base = (pointer)ioctl(mmapFd, MAP, &MapDSC)) == (pointer)-1)
+ {
+ FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
+ "xf86MapVidMem", Size, Base, strerror(errno));
+ /* NOTREACHED */
+ }
+
+ /* Next time we want the same address! */
+ MapDSC.vaddr = (char *)base;
+ }
+
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "MapDSC.vaddr : 0x%x\n", MapDSC.vaddr);
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "MapDSC.physaddr: 0x%x\n", MapDSC.physaddr);
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "MapDSC.length : %d\n", MapDSC.length);
+ mmapStat(Base,Size);
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "xf86MapVidMem: [s=%x,a=%x,b=%x]\n", Size, Base, base);
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "xf86MapVidMem: SUCCEED Mapping FrameBuffer \n");
+#endif /* HAS_SVR3_MMAPDRV */
+#endif /* SVR4 */
+ return(base);
+}
+
+/* ARGSUSED */
+static void
+unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+#if defined (SVR4)
+ munmap(Base, Size);
+#else /* SVR4 */
+#ifdef HAS_SVR3_MMAPDRV
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "# xf86UnMapVidMem: UNMapping FrameBuffer\n");
+ mmapStat(Base,Size);
+ ioctl(mmapFd, UNMAPRM , Base);
+ mmapStat(Base,Size);
+ xf86MsgVerb(X_INFO, MMAP_DEBUG,
+ "# xf86UnMapVidMem: Screen: %d [v=%x]\n", ScreenNum, Base);
+#endif /* HAS_SVR3_MMAPDRV */
+#endif /* SVR4 */
+ return;
+}
+
+#if defined(SVR4) && defined(i386) && !defined(sun)
+/*
+ * For some SVR4 versions, a 32-bit read is done for the first location
+ * in each page when the page is first mapped. If this is done while
+ * memory access is enabled for regions that have read side-effects,
+ * this can cause unexpected results, including lockups on some hardware.
+ * This function is called to make sure each page is mapped while it is
+ * safe to do so.
+ */
+
+/*
+ * XXX Should get this the correct way (see os/xalloc.c), but since this is
+ * for one platform I'll be lazy.
+ */
+#define X_PAGE_SIZE 4096
+
+static void
+readSideEffects(int ScreenNum, pointer Base, unsigned long Size)
+{
+ unsigned long base, end, addr;
+ CARD32 val;
+
+ base = (unsigned long)Base;
+ end = base + Size;
+
+ for (addr = base; addr < end; addr += X_PAGE_SIZE)
+ val = *(volatile CARD32 *)addr;
+}
+#endif
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ pVidMem->linearSupported = linearVidMem();
+ pVidMem->mapMem = mapVidMem;
+ pVidMem->unmapMem = unmapVidMem;
+#if defined(SVR4) && defined(i386) && !defined(sun)
+ pVidMem->readSideEffects = readSideEffects;
+#endif
+ pVidMem->initialised = TRUE;
+}
+
+/***************************************************************************/
+/* I/O Permissions section */
+/***************************************************************************/
+
+static Bool ExtendedEnabled = FALSE;
+static Bool InitDone = FALSE;
+
+Bool
+xf86EnableIO()
+{
+ int i;
+
+ if (ExtendedEnabled)
+ return TRUE;
+
+ if (SET_IOPL() < 0)
+ {
+ xf86Msg(X_WARNING,
+ "xf86EnableIO: Failed to set IOPL for extended I/O\n");
+ return FALSE;
+ }
+ ExtendedEnabled = TRUE;
+
+ return TRUE;
+}
+
+void
+xf86DisableIO()
+{
+ if (!ExtendedEnabled)
+ return;
+
+ RESET_IOPL();
+ ExtendedEnabled = FALSE;
+
+ return;
+}
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts()
+{
+ if (!ExtendedEnabled)
+ {
+ if (SET_IOPL() < 0)
+ {
+ return(FALSE);
+ }
+ }
+
+#ifdef __GNUC__
+ __asm__ __volatile__("cli");
+#else
+ asm("cli");
+#endif /* __GNUC__ */
+
+ if (!ExtendedEnabled)
+ {
+ RESET_IOPL();
+ }
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+ if (!ExtendedEnabled)
+ {
+ if (SET_IOPL() < 0)
+ {
+ return;
+ }
+ }
+
+#ifdef __GNUC__
+ __asm__ __volatile__("sti");
+#else
+ asm("sti");
+#endif /* __GNUC__ */
+
+ if (!ExtendedEnabled)
+ {
+ RESET_IOPL();
+ }
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/xqueue.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/xqueue.c
new file mode 100644
index 000000000..6c2132cef
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/xqueue.c
@@ -0,0 +1,543 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sysv/xqueue.c,v 3.19 2000/02/10 22:33:45 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993-1999 by The XFree86 Project, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. The copyright holders make no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium: xqueue.c /main/8 1996/10/19 18:08:11 kaleb $ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "xqueue.h"
+
+#ifdef XQUEUE
+
+static xqEventQueue *XqueQaddr;
+static int xqueFd = -1;
+#ifndef XQUEUE_ASYNC
+static int xquePipe[2];
+#endif
+
+#ifdef XKB
+#include "inputstr.h"
+#include <X11/extensions/XKB.h>
+#include <X11/extensions/XKBstr.h>
+#include <X11/extensions/XKBsrv.h>
+extern Bool noXkbExtension;
+#endif
+
+#include "xf86Xinput.h"
+#include "mipointer.h"
+
+typedef struct {
+ int xquePending;
+ int xqueSema;
+} XqInfoRec, *XqInfoPtr;
+
+InputInfoPtr XqMouse = NULL;
+InputInfoPtr XqKeyboard = NULL;
+
+#ifndef XQUEUE_ASYNC
+/*
+ * xf86XqueSignal --
+ * Trap the signal from xqueue and let it be known that events are
+ * ready for collection
+ */
+
+static void
+xf86XqueSignal(int signum)
+{
+ ((XqInfoPtr)(((MouseDevPtr)(XqMouse->private))->mousePriv))->xquePending = 1;
+ /*
+ * This is a hack, but it is the only reliable way I can find of letting
+ * the main select() loop know that there is more input waiting. Receiving
+ * a signal will interrupt select(), but there is no way I can find of
+ * dealing with events that come in between the end of processing the
+ * last set and when select() gets called.
+ *
+ * Suggestions for better ways of dealing with this without going back to
+ * asynchronous event processing are welcome.
+ */
+#ifdef DEBUG
+ ErrorF("xf86XqueSignal\n");
+#endif
+ write(xquePipe[1], "X", 1);
+ signal(SIGUSR2, xf86XqueSignal);
+}
+#endif
+
+
+/*
+ * xf86XqueKbdProc --
+ * Handle the initialization, etc. of a keyboard.
+ */
+
+int
+xf86XqueKbdProc(DeviceIntPtr pKeyboard, int what)
+{
+ KeySymsRec keySyms;
+ CARD8 modMap[MAP_LENGTH];
+
+ switch (what) {
+
+ case DEVICE_INIT:
+
+ xf86KbdGetMapping(&keySyms, modMap);
+
+ /*
+ * Get also the initial led settings
+ */
+ ioctl(xf86Info.consoleFd, KDGETLED, &xf86Info.leds);
+
+ /*
+ * Perform final initialization of the system private keyboard
+ * structure and fill in various slots in the device record
+ * itself which couldn't be filled in before.
+ */
+ pKeyboard->public.on = FALSE;
+
+#ifdef XKB
+ if (noXkbExtension) {
+#endif
+ InitKeyboardDeviceStruct((DevicePtr)xf86Info.pKeyboard,
+ &keySyms,
+ modMap,
+ xf86KbdBell,
+ (KbdCtrlProcPtr)xf86KbdCtrl);
+#ifdef XKB
+ } else {
+ XkbComponentNamesRec names;
+ if (XkbInitialMap) {
+ if ((xf86Info.xkbkeymap = strchr(XkbInitialMap, '/')) != NULL)
+ xf86Info.xkbkeymap++;
+ else
+ xf86Info.xkbkeymap = XkbInitialMap;
+ }
+ if (xf86Info.xkbkeymap) {
+ names.keymap = xf86Info.xkbkeymap;
+ names.keycodes = NULL;
+ names.types = NULL;
+ names.compat = NULL;
+ names.symbols = NULL;
+ names.geometry = NULL;
+ } else {
+ names.keymap = NULL;
+ names.keycodes = xf86Info.xkbkeycodes;
+ names.types = xf86Info.xkbtypes;
+ names.compat = xf86Info.xkbcompat;
+ names.symbols = xf86Info.xkbsymbols;
+ names.geometry = xf86Info.xkbgeometry;
+ }
+ if ((xf86Info.xkbkeymap || xf86Info.xkbcomponents_specified)
+ && (xf86Info.xkbmodel == NULL || xf86Info.xkblayout == NULL)) {
+ xf86Info.xkbrules = NULL;
+ }
+ XkbSetRulesDflts(xf86Info.xkbrules, xf86Info.xkbmodel,
+ xf86Info.xkblayout, xf86Info.xkbvariant,
+ xf86Info.xkboptions);
+ XkbInitKeyboardDeviceStruct(pKeyboard,
+ &names,
+ &keySyms,
+ modMap,
+ xf86KbdBell,
+ (KbdCtrlProcPtr)xf86KbdCtrl);
+ }
+#endif
+
+ xf86InitKBD(TRUE);
+ break;
+
+ case DEVICE_ON:
+ pKeyboard->public.on = TRUE;
+ xf86InitKBD(FALSE);
+ break;
+
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ pKeyboard->public.on = FALSE;
+ break;
+ }
+
+ return (Success);
+}
+
+
+/*
+ * xf86XqueEvents --
+ * Get some events from our queue. Nothing to do here ...
+ */
+
+void
+xf86XqueEvents()
+{
+}
+
+
+#ifdef XQUEUE_ASYNC
+static void XqDoInput(int signum);
+#endif
+
+void
+XqReadInput(InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse;
+ XqInfoPtr pXq;
+ xqEvent *XqueEvents;
+ int XqueHead;
+ char buf[100];
+ signed char dx, dy;
+
+ if (xqueFd < 0)
+ return;
+
+ pMse = pInfo->private;
+ pXq = pMse->mousePriv;
+
+ XqueEvents = XqueQaddr->xq_events;
+ XqueHead = XqueQaddr->xq_head;
+
+ while (XqueHead != XqueQaddr->xq_tail) {
+ switch (XqueEvents[XqueHead].xq_type) {
+ case XQ_BUTTON:
+ pMse->PostEvent(pInfo, ~(XqueEvents[XqueHead].xq_code) & 0x07,
+ 0, 0, 0, 0);
+#ifdef DEBUG
+ ErrorF("xqueue: buttons: %d\n", ~(XqueEvents[XqueHead].xq_code) & 0x07);
+#endif
+ break;
+
+ case XQ_MOTION:
+ dx = (signed char)XqueEvents[XqueHead].xq_x;
+ dy = (signed char)XqueEvents[XqueHead].xq_y;
+ pMse->PostEvent(pInfo, ~(XqueEvents[XqueHead].xq_code) & 0x07,
+ (int)dx, (int)dy, 0, 0);
+#ifdef DEBUG
+ ErrorF("xqueue: Motion: (%d, %d) (buttons: %d)\n", dx, dy, ~(XqueEvents[XqueHead].xq_code) & 0x07);
+#endif
+ break;
+
+ case XQ_KEY:
+ /* XXX Need to deal with the keyboard part nicely. */
+#ifdef DEBUG
+ ErrorF("xqueue: key: %d\n", XqueEvents[XqueHead].xq_code);
+#endif
+ xf86PostKbdEvent(XqueEvents[XqueHead].xq_code);
+ break;
+ default:
+ xf86Msg(X_WARNING, "Unknown Xque Event: 0x%02x\n",
+ XqueEvents[XqueHead].xq_type);
+ }
+
+ if ((++XqueHead) == XqueQaddr->xq_size) XqueHead = 0;
+ xf86Info.inputPending = TRUE;
+ }
+
+ /* reenable the signal-processing */
+#ifdef XQUEUE_ASYNC
+ signal(SIGUSR2, XqDoInput);
+#endif
+
+#ifndef XQUEUE_ASYNC
+ {
+ int rval;
+
+ while ((rval = read(xquePipe[0], buf, sizeof(buf))) > 0)
+#ifdef DEBUG
+ ErrorF("Read %d bytes from xquePipe[0]\n", rval);
+#else
+ ;
+#endif
+ }
+#endif
+
+#ifdef DEBUG
+ ErrorF("Leaving XqReadInput()\n");
+#endif
+ pXq->xquePending = 0;
+ XqueQaddr->xq_head = XqueQaddr->xq_tail;
+ XqueQaddr->xq_sigenable = 1; /* UNLOCK */
+}
+
+#ifdef XQUEUE_ASYNC
+static void
+XqDoInput(int signum)
+{
+ if (XqMouse)
+ XqReadInput(XqMouse);
+}
+#endif
+
+static void
+XqBlock(pointer blockData, OSTimePtr pTimeout, pointer pReadmask)
+{
+ InputInfoPtr pInfo;
+ MouseDevPtr pMse;
+ XqInfoPtr pXq;
+ /*
+ * On MP SVR4 boxes, a race condition exists because the XQUEUE does
+ * not have anyway to lock it for exclusive access. This results in one
+ * processor putting something on the queue at the same time the other
+ * processor is taking it something off. The count of items in the queue
+ * can get off by 1. This just goes and checks to see if an extra event
+ * was put in the queue a during this period. The signal for this event
+ * was ignored while processing the previous event.
+ */
+
+ pInfo = blockData;
+ pMse = pInfo->private;
+ pXq = pMse-> mousePriv;
+ if (!pXq->xquePending) {
+#ifdef DEBUG
+ ErrorF("XqBlock: calling XqReadInput()\n");
+#endif
+ XqReadInput((InputInfoPtr)blockData);
+ } else {
+#ifdef DEBUG
+ ErrorF("XqBlock: not calling XqReadInput()\n");
+#endif
+ ;
+ }
+ /*
+ * Make sure that any events that come in here are passed on without.
+ * waiting for the next wakeup.
+ */
+ if (xf86Info.inputPending) {
+#ifdef DEBUG
+ ErrorF("XqBlock: calling ProcessInputEvents()\n");
+#endif
+ ProcessInputEvents();
+ } else {
+#ifdef DEBUG
+ ErrorF("XqBlock: not calling ProcessInputEvents()\n");
+#endif
+ ;
+ }
+}
+
+/*
+ * XqEnable --
+ * Enable the handling of the Xque
+ */
+
+static int
+XqEnable(InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse;
+ XqInfoPtr pXq;
+ static struct kd_quemode xqueMode;
+ static Bool was_here = FALSE;
+
+ pMse = pInfo->private;
+ pXq = pMse->mousePriv;
+
+ if (xqueFd < 0) {
+ if ((xqueFd = open("/dev/mouse", O_RDONLY | O_NDELAY)) < 0) {
+ if (xf86GetAllowMouseOpenFail()) {
+ xf86Msg(X_WARNING,
+ "%s: Cannot open /dev/mouse (%s) - Continuing...\n",
+ pInfo->name, strerror(errno));
+ return Success;
+ } else {
+ xf86Msg(X_ERROR, "%s: Cannot open /dev/mouse (%s)\n",
+ pInfo->name, strerror(errno));
+ return !Success;
+ }
+ }
+ }
+#ifndef XQUEUE_ASYNC
+ if (!was_here) {
+ pipe(xquePipe);
+ fcntl(xquePipe[0], F_SETFL, fcntl(xquePipe[0], F_GETFL, 0) | O_NDELAY);
+ fcntl(xquePipe[1], F_SETFL, fcntl(xquePipe[1], F_GETFL, 0) | O_NDELAY);
+ was_here = TRUE;
+ }
+#endif
+
+ if (pXq->xqueSema++ == 0) {
+#ifdef XQUEUE_ASYNC
+ (void) signal(SIGUSR2, XqDoInput);
+#else
+ (void) signal(SIGUSR2, xf86XqueSignal);
+#endif
+ xqueMode.qsize = 64; /* max events */
+ xqueMode.signo = SIGUSR2;
+ ioctl(xf86Info.consoleFd, KDQUEMODE, NULL);
+
+ if (ioctl(xf86Info.consoleFd, KDQUEMODE, &xqueMode) < 0) {
+ xf86Msg(X_ERROR, "%s: Cannot set KDQUEMODE", pInfo->name);
+ return !Success;
+ }
+ XqueQaddr = (xqEventQueue *)xqueMode.qaddr;
+ XqueQaddr->xq_sigenable = 1; /* UNLOCK */
+ }
+
+ return Success;
+}
+
+
+
+/*
+ * xf86XqueDisable --
+ * disable the handling of the Xque
+ */
+
+static int
+XqDisable(InputInfoPtr pInfo)
+{
+ MouseDevPtr pMse;
+ XqInfoPtr pXq;
+
+ pMse = pInfo->private;
+ pXq = pMse->mousePriv;
+
+ if (pXq->xqueSema-- == 1)
+ {
+ XqueQaddr->xq_sigenable = 0; /* LOCK */
+
+ if (ioctl(xf86Info.consoleFd, KDQUEMODE, NULL) < 0) {
+ xf86Msg(X_ERROR, "%s: Cannot unset KDQUEMODE", pInfo->name);
+ return !Success;
+ }
+ }
+
+ if (xqueFd >= 0) {
+ close(xqueFd);
+ xqueFd = -1;
+ }
+
+ return Success;
+}
+
+/*
+ * XqMouseProc --
+ * Handle the initialization, etc. of a mouse
+ */
+
+static int
+XqMouseProc(DeviceIntPtr pPointer, int what)
+{
+ InputInfoPtr pInfo;
+ MouseDevPtr pMse;
+ unchar map[4];
+ int ret;
+
+ pInfo = pPointer->public.devicePrivate;
+ pMse = pInfo->private;
+ pMse->device = pPointer;
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+
+ map[1] = 1;
+ map[2] = 2;
+ map[3] = 3;
+
+ InitPointerDeviceStruct((DevicePtr)pPointer,
+ map,
+ 3,
+ miPointerGetMotionEvents,
+ pMse->Ctrl,
+ miPointerGetMotionBufferSize());
+ /* X valuator */
+ xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 0);
+ /* Y valuator */
+ xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 1);
+ xf86MotionHistoryAllocate(pInfo);
+ RegisterBlockAndWakeupHandlers(XqBlock, (WakeupHandlerProcPtr)NoopDDA,
+ pInfo);
+ break;
+
+ case DEVICE_ON:
+ pMse->lastButtons = 0;
+ pMse->lastMappedButtons = 0;
+ pMse->emulateState = 0;
+ pPointer->public.on = TRUE;
+ ret = XqEnable(pInfo);
+#ifndef XQUEUE_ASYNC
+ if (xquePipe[0] != -1) {
+ pInfo->fd = xquePipe[0];
+ AddEnabledDevice(xquePipe[0]);
+ }
+#endif
+ return ret;
+
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ pPointer->public.on = FALSE;
+ ret = XqDisable(pInfo);
+#ifndef XQUEUE_ASYNC
+ if (xquePipe[0] != -1) {
+ RemoveEnabledDevice(xquePipe[0]);
+ pInfo->fd = -1;
+ }
+#endif
+ return ret;
+ }
+ return Success;
+}
+
+Bool
+XqueueMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ MouseDevPtr pMse;
+ XqInfoPtr pXq;
+
+ pMse = pInfo->private;
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+ pXq = pMse->mousePriv = xnfcalloc(sizeof(XqInfoRec), 1);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local procs. */
+ pInfo->device_control = XqMouseProc;
+#ifdef XQUEUE_ASYNC
+ pInfo->read_input = NULL;
+#else
+ pInfo->read_input = XqReadInput;
+#endif
+ pInfo->fd = -1;
+
+ XqMouse = pInfo;
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+
+#endif /* XQUEUE */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/xqueue.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/xqueue.h
new file mode 100644
index 000000000..d693d2b36
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/sysv/xqueue.h
@@ -0,0 +1,12 @@
+/* $XFree86$ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _XF86_XQUEUE_H_
+#define _XF86_XQUEUE_H_
+
+Bool XqueueMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags);
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/Imakefile
new file mode 100644
index 000000000..034c9c7d6
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/Imakefile
@@ -0,0 +1,40 @@
+XCOMM $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/Imakefile,v 1.2 2005/11/08 06:33:29 jkj Exp $
+XCOMM $XConsortium$
+
+#include <Server.tmpl>
+
+SRCS = usl_init.c usl_video.c usl_io.c usl_iop.c usl_mouse.c usl_vtsw.c \
+ usl_xqueue.c std_kbdEv.c posix_tty.c bios_mmap.c vidmem.c \
+ libc_wrapper.c stdResource.c stdPci.c sigiostubs.c pm_noop.c \
+ kmod_noop.c agp_noop.c usl_kbd.c at_scancode.c usl_KbdMap.c
+
+OBJS = usl_init.o usl_video.o usl_io.o usl_iop.o usl_mouse.o usl_vtsw.o \
+ usl_xqueue.o std_kbdEv.o posix_tty.o bios_mmap.o vidmem.o \
+ libc_wrapper.o stdResource.o stdPci.o sigiostubs.o pm_noop.o \
+ kmod_noop.o agp_noop.o usl_kbd.o at_scancode.o usl_KbdMap.o
+
+INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \
+ -I$(SERVERSRC)/mi -I$(XINCLUDESRC) -I$(EXTINCSRC)
+
+RESDEFINES = -DUSESTDRES
+
+DEFINES = $(RESDEFINES)
+
+SubdirLibraryRule($(OBJS))
+NormalLibraryObjectRule()
+
+LinkSourceFile(bios_mmap.c,../shared)
+LinkSourceFile(std_kbdEv.c,../shared)
+LinkSourceFile(at_scancode.c,../shared)
+LinkSourceFile(posix_tty.c,../shared)
+LinkSourceFile(libc_wrapper.c,../shared)
+LinkSourceFile(stdResource.c,../shared)
+LinkSourceFile(stdPci.c,../shared)
+LinkSourceFile(sigiostubs.c,../shared)
+LinkSourceFile(pm_noop.c,../shared)
+LinkSourceFile(kmod_noop.c,../shared)
+LinkSourceFile(agp_noop.c,../shared)
+LinkSourceFile(vidmem.c,../shared)
+
+DependTarget()
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_KbdMap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_KbdMap.c
new file mode 100644
index 000000000..57c73f07a
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_KbdMap.c
@@ -0,0 +1,304 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_KbdMap.c,v 1.2 2005/11/08 06:33:29 jkj Exp $ */
+/*
+ * Copyright 2005 by J. Kean Johnston <jkj@sco.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name J. Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. J. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * J. KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL J. KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Based on xf86KbdMap.c, which is
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ * Copyright (c) 1992-2003 by The XFree86 Project, Inc.
+ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+#include "atKeynames.h"
+#include "xf86Keymap.h"
+
+#include "usl_kbd.h"
+
+#define KD_GET_ENTRY(i,n) \
+ eascii_to_x[((priv->keymap.key[i].spcl << (n+1)) & 0x100) + priv->keymap.key[i].map[n]]
+
+/*
+ * NOTE: Not all possible remappable symbols are remapped. There are two main
+ * reasons:
+ * a) The mapping between scancode and SYSV/386 - symboltable
+ * is inconsistent between different versions and has some
+ * BIG mistakes.
+ * b) In X-Windows there is a difference between numpad-keys
+ * and normal keys. SYSV/386 uses for both kinds of keys
+ * the same symbol.
+ *
+ * Thus only the alpha keypad and the function keys are translated.
+ * Also CapsLock, NumLock, ScrollLock, Shift, Control & Alt.
+ */
+
+static unsigned char remap[128] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0x69, 0x65, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+
+static KeySym eascii_to_x[512] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex,
+ XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla,
+ XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis,
+ XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring,
+ XK_Eacute, XK_ae, XK_AE, XK_ocircumflex,
+ XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave,
+ XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent,
+ XK_sterling, XK_yen, XK_paragraph, XK_section,
+ XK_aacute, XK_iacute, XK_oacute, XK_uacute,
+ XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine,
+ XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf,
+ XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi,
+ XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau,
+ XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta,
+ XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection,
+ XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal,
+ XK_topintegral, XK_botintegral, XK_division, XK_similarequal,
+ XK_degree, NoSymbol, NoSymbol, XK_radical,
+ XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol,
+
+ /*
+ * special marked entries (256 + x)
+ */
+
+ NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R,
+ XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L,
+ NoSymbol, XK_Control_L, XK_Alt_L, XK_Alt_R,
+ XK_Control_L, XK_Control_R, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_F1,
+ XK_F2, XK_F3, XK_F4, XK_F5,
+ XK_F6, XK_F7, XK_F8, XK_F9,
+ XK_F10, XK_F11, XK_F12, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ };
+
+/*
+ * KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+void
+KbdGetMapping (InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private;
+ KeySym *k;
+ int i;
+ KeySym *pMap = map;
+
+ for (i = 0; i < priv->keymap.n_keys && i < NUM_KEYCODES; i++) {
+ if (remap[i]) {
+ k = pMap + (remap[i] << 2);
+
+ k[0] = KD_GET_ENTRY(i,0); /* non-shifed */
+ k[1] = KD_GET_ENTRY(i,1); /* shifted */
+ k[2] = KD_GET_ENTRY(i,4); /* alt */
+ k[3] = KD_GET_ENTRY(i,5); /* alt - shifted */
+
+ if (k[3] == k[2]) k[3] = NoSymbol;
+ if (k[2] == k[1]) k[2] = NoSymbol;
+ if (k[1] == k[0]) k[1] = NoSymbol;
+ if (k[0] == k[2] && k[1] == k[3]) k[2] = k[3] = NoSymbol;
+ }
+ }
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = pMap, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4) {
+
+ switch(*k) {
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+ }
+ }
+
+ pKeySyms->map = pMap;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_init.c
new file mode 100644
index 000000000..35410b688
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_init.c
@@ -0,0 +1,359 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_init.c,v 1.2 2005/11/08 06:33:29 jkj Exp $ */
+/*
+ * Copyright 2001-2005 by Kean Johnston <jkj@sco.com>
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell, David Wexelblat
+ * and Kean Johnston not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Thomas Roell, David Wexelblat and Kean Johnston make no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL, DAVID WEXELBLAT AND KEAN JOHNSTON DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THOMAS ROELLm DAVID WEXELBLAT
+ * OR KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ *
+ */
+/* $XConsortium$ */
+
+#include "X.h"
+#include "Xmd.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#include <sys/utsname.h>
+
+static Bool KeepTty = FALSE;
+static Bool Protect0 = FALSE;
+static Bool CRTSpecified = FALSE;
+static int VTnum = -1;
+static char vtdevice[48];
+
+int usl_is_osr6 = -1;
+
+static Bool
+IsConsoleDevice(const char *dev)
+{
+ if ((!strcmp (dev, "/dev/console")) ||
+ (!strcmp (dev, "/dev/syscon")) ||
+ (!strcmp (dev, "/dev/systty")))
+ return TRUE;
+
+ return FALSE;
+}
+
+static int
+is_osr6 (void)
+{
+ struct utsname uts;
+
+ if (usl_is_osr6 == -1) {
+ if (uname (&uts) < 0) {
+ FatalError ("get_usl_ver: Failed to determine UNIX name (%s)\n",
+ strerror (errno));
+ }
+
+ if (uts.version[0] == '6')
+ usl_is_osr6 = 1;
+ else
+ usl_is_osr6 = 0;
+ }
+
+ return usl_is_osr6;
+}
+
+
+void
+xf86OpenConsole(void)
+{
+ int fd, i, ioctl_ret;
+ struct vt_mode VT;
+ struct vt_stat vts;
+ MessageType from = X_PROBED;
+ struct sigaction sigvtsw;
+ char *ttn;
+
+ if (serverGeneration == 1) {
+ int isconsole = 0, consdev = 0;
+
+ /* check if we're run with euid==0 */
+ if (geteuid() != 0) {
+ FatalError("xf86OpenConsole: Server must be suid root\n");
+ }
+
+ /* If we are run in the background we will get SIGTTOU. Ignore it. */
+ OsSignal (SIGTTOU, SIG_IGN);
+
+ /* Protect page 0 to help find NULL dereferencing */
+ /* mprotect() doesn't seem to work */
+ if (Protect0) {
+ int fd = -1;
+
+ if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0) {
+ xf86Msg(X_WARNING, "xf86OpenConsole: cannot open /dev/zero (%s)\n",
+ strerror(errno));
+ } else {
+ if ((int)mmap(0, 0x1000, PROT_NONE,
+ MAP_FIXED | MAP_SHARED, fd, 0) == -1) {
+ xf86Msg(X_WARNING, "xf86OpenConsole: failed to protect page 0 (%s)\n",
+ strerror(errno));
+ }
+ close(fd);
+ }
+ }
+
+ /*
+ * setup the virtual terminal manager
+ */
+ if (VTnum == -1) {
+ /*
+ * No device was specified. We need to query the kernel to see which
+ * console device we are on (and in fact if we are on a console at all).
+ */
+ if (ioctl (0, VT_GETSTATE, &vts) < 0) {
+ FatalError("xf86OpenConsole: Could not query active VT: %s\n",
+ strerror(errno));
+ }
+ VTnum = vts.v_active;
+ if (is_osr6())
+ snprintf (vtdevice, sizeof(vtdevice), "/dev/tty%02d", VTnum + 1);
+ else
+ snprintf (vtdevice, sizeof(vtdevice), "/dev/vt%02d", VTnum);
+ } else {
+ from = X_CMDLINE;
+ if (is_osr6())
+ snprintf (vtdevice, sizeof(vtdevice), "/dev/tty%02d", VTnum + 1);
+ else
+ snprintf (vtdevice, sizeof(vtdevice), "/dev/vt%02d", VTnum);
+ }
+
+ if (IsConsoleDevice(vtdevice)) {
+ isconsole = 1;
+ CRTSpecified = FALSE; /* Dont honour -crt /dev/console */
+ }
+
+ if (ioctl (0, KIOCINFO, 0) >= 0)
+ consdev = 1 + isconsole;
+
+ if ((!CRTSpecified) && (isconsole || (!consdev))) {
+ /*
+ * Need to find a free VT
+ */
+ if ((fd = open ("/dev/console", O_WRONLY | O_NOCTTY)) < 0) {
+ FatalError ("xf86OpenConsole: Could not open /dev/console: %s\n",
+ strerror (errno));
+ }
+
+ if (ioctl (fd, VT_OPENQRY, &VTnum) < 0) {
+ FatalError ("xf86OpenConsole: Cannot find a free VT: %s\n",
+ strerror(errno));
+ }
+ close (fd);
+ if (usl_is_osr6)
+ snprintf (vtdevice, sizeof(vtdevice), "/dev/tty%02d", VTnum + 1);
+ else
+ snprintf (vtdevice, sizeof(vtdevice), "/dev/vt%02d", VTnum);
+ }
+
+ /*
+ * Now we can dispose of stdin/stdout
+ */
+ fclose (stdin);
+ fclose (stdout);
+
+ if (CRTSpecified || isconsole || consdev != 1) {
+ if (!KeepTty) {
+ setpgrp();
+ }
+ }
+
+ if ((xf86Info.consoleFd = open(vtdevice, O_RDWR | O_NONBLOCK, 0)) < 0) {
+ FatalError("xf86OpenConsole: Cannot open %s: %s\n", vtdevice,
+ strerror(errno));
+ }
+
+ xf86Msg (from, "using VT number %d (%s)\n\n", VTnum, vtdevice);
+ xf86Info.vtno = VTnum;
+
+ /* change ownership of the vt */
+ chown(vtdevice, getuid(), getgid());
+
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) {
+ FatalError("xf86OpenConsole: VT_ACTIVATE failed: %s\n",
+ strerror(errno));
+ }
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0) {
+ FatalError("xf86OpenConsole: VT_WAITACTIVE failed: %s\n",strerror(errno));
+ }
+
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) {
+ FatalError("xf86OpenConsole: VT_GETMODE failed: %s\n", strerror(errno));
+ }
+
+ sigvtsw.sa_handler = xf86VTRequest;
+ sigfillset(&sigvtsw.sa_mask);
+ sigvtsw.sa_flags = 0;
+ sigaction(SIGUSR1, &sigvtsw, NULL);
+
+ VT.mode = VT_PROCESS;
+ VT.relsig = SIGUSR1;
+ VT.acqsig = SIGUSR1;
+
+ ioctl_ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT);
+ if (ioctl_ret < 0) {
+ FatalError("xf86OpenConsole: VT_SETMODE failed: %s\n", strerror(errno));
+ }
+
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) {
+ FatalError("xf86OpenConsole: KD_GRAPHICS failed: %s\n", strerror(errno));
+ }
+ } else { /* serverGeneration != 1 */
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) {
+ FatalError("xf86OpenConsole: VT_ACTIVATE failed: %s\n", strerror(errno));
+ }
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0) {
+ FatalError("xf86OpenConsole: VT_WAITACTIVE failed: %s\n",strerror(errno));
+ }
+ /*
+ * If the server doesn't have the VT when the reset occurs,
+ * this is to make sure we don't continue until the activate
+ * signal is received.
+ */
+ if (!xf86Screens[0]->vtSema)
+ sleep(5);
+ }
+ return;
+}
+
+void
+xf86CloseConsole(void)
+{
+ struct vt_mode VT;
+ struct sigaction sigvtsw;
+
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode ... */
+
+ sigvtsw.sa_handler = SIG_DFL;
+ sigfillset(&sigvtsw.sa_mask);
+ sigvtsw.sa_flags = 0;
+ sigaction(SIGUSR1, &sigvtsw, NULL);
+
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) {
+ VT.mode = VT_AUTO;
+ VT.waitv = 0;
+ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */
+ }
+ close(xf86Info.consoleFd); /* make the vt-manager happy */
+ return;
+}
+
+int
+xf86ProcessArgument(int argc, char *argv[], int i)
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful
+ * when debugging (so the server can receive keyboard signals.
+ */
+ if (!strcmp(argv[i], "-keeptty")) {
+ KeepTty = TRUE;
+ return(1);
+ }
+
+ /*
+ * Undocumented flag to protect page 0 from read/write to help
+ * catch NULL pointer dereferences. This is purely a debugging
+ * flag.
+ */
+ if (!strcmp(argv[i], "-protect0")) {
+ Protect0 = TRUE;
+ return(1);
+ }
+
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't')) {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0) {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ VTnum -= is_osr6();
+ CRTSpecified = TRUE;
+ return(1);
+ }
+
+ /*
+ * Use a device the user specifies.
+ */
+ if (!strcmp(argv[i], "-crt")) {
+ if (++i > argc) {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ } else {
+ char *mytty = ttyname(0);
+ char *arg = argv[i];
+
+ if (!mytty)
+ mytty = "\1";
+ if (!arg[0])
+ arg = "\2"; /* Prevent idiots from using -crt "" */
+
+ if (strcmp (mytty, arg) != 0) {
+ char *fmt;
+
+ if (is_osr6())
+ fmt = "/dev/tty%02d";
+ else
+ fmt = "/dev/vt%02d";
+
+ if (sscanf(arg, fmt, &VTnum) == 0) {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+
+ /* OSR6 devices start names at 1, UW7 starts at 0 */
+ VTnum -= is_osr6();
+ CRTSpecified = TRUE;
+ }
+ return(2);
+ }
+ }
+ return(0);
+}
+
+void
+xf86UseMsg(void)
+{
+ if (is_osr6()) {
+ ErrorF("-crt /dev/ttyXX use the specified VT device\n");
+ ErrorF("vtXX use the specified VT number (01-16)\n");
+ } else {
+ ErrorF("-crt /dev/vtXX use the specified VT device\n");
+ ErrorF("vtXX use the specified VT number (00-15)\n");
+ }
+
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ return;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_io.c
new file mode 100644
index 000000000..c93e8058e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_io.c
@@ -0,0 +1,172 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_io.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */
+/*
+ * Copyright 2001-2005 by Kean Johnston <jkj@sco.com>
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell, David Dawes
+ * and Kean Johnston not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Thomas Roell, David Dawes and Kean Johnston make no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL, DAVID DAWES AND KEAN JOHNSTON DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THOMAS ROELLm DAVID WEXELBLAT
+ * OR KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ *
+ */
+/* $XConsortium$ */
+
+#include "X.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+void
+xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ if (loudness && pitch) {
+ ioctl(xf86Info.consoleFd, KIOCSOUND, 1193180 / pitch);
+ usleep(xf86Info.bell_duration * loudness * 20);
+ ioctl(xf86Info.consoleFd, KIOCSOUND, 0);
+ }
+}
+
+void
+xf86SetKbdLeds(int leds)
+{
+ ioctl(xf86Info.consoleFd, KDSETLED, leds);
+}
+
+int
+xf86GetKbdLeds(void)
+{
+ int leds;
+
+ ioctl(xf86Info.consoleFd, KDGETLED, &leds);
+ return(leds);
+}
+
+/*
+ * Much of the code in this function is duplicated from the Linux code
+ * by Orest Zborowski <obz@Kodak.com> and David Dawes <dawes@xfree86.org>.
+ * Please see the file ../linux/lnx_io.c for full copyright information.
+ */
+void
+xf86SetKbdRepeat(char rad)
+{
+ int i;
+ int value = 0x7f; /* Maximum delay with slowest rate */
+ int delay = 250; /* Default delay */
+ int rate = 300; /* Default repeat rate */
+
+ static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150,
+ 133, 120, 109, 100, 92, 86, 80, 75, 67,
+ 60, 55, 50, 46, 43, 40, 37, 33, 30, 27,
+ 25, 23, 21, 20 };
+#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int ))
+
+ static int valid_delays[] = { 250, 500, 750, 1000 };
+#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int ))
+
+ if (xf86Info.kbdRate >= 0)
+ rate = xf86Info.kbdRate * 10;
+ if (xf86Info.kbdDelay >= 0)
+ delay = xf86Info.kbdDelay;
+
+ for (i = 0; i < RATE_COUNT; i++)
+ if (rate >= valid_rates[i]) {
+ value &= 0x60;
+ value |= i;
+ break;
+ }
+
+ for (i = 0; i < DELAY_COUNT; i++)
+ if (delay <= valid_delays[i]) {
+ value &= 0x1f;
+ value |= i << 5;
+ break;
+ }
+
+ ioctl (xf86Info.consoleFd, KDSETTYPEMATICS, value);
+}
+
+static int orig_kbm;
+static struct termio orig_termio;
+static keymap_t keymap, noledmap;
+
+void
+xf86KbdInit(void)
+{
+ ioctl (xf86Info.consoleFd, KDGKBMODE, &orig_kbm);
+ ioctl (xf86Info.consoleFd, TCGETA, &orig_termio);
+ /*
+ * We need to get the original keyboard map and NUL out the lock
+ * modifiers. This prevents the scancode API from messing with
+ * the keyboard LED's. We restore the original map when we exit.
+ */
+ if (ioctl (xf86Info.consoleFd, GIO_KEYMAP, &keymap) < 0) {
+ FatalError ("xf86KbdInit: Failed to get keyboard map (%s)\n",
+ strerror(errno));
+ }
+ if (ioctl (xf86Info.consoleFd, GIO_KEYMAP, &noledmap) < 0) {
+ FatalError ("xf86KbdInit: Failed to get keyboard map (%s)\n",
+ strerror(errno));
+ } else {
+ int i, j;
+
+ for (i = 0; i < noledmap.n_keys; i++) {
+ for (j = 0; j < NUM_STATES; j++) {
+ if (IS_SPECKEY(&noledmap, i, j) &&
+ ((noledmap.key[i].map[j] == K_CLK) ||
+ (noledmap.key[i].map[j] == K_NLK) ||
+ (noledmap.key[i].map[j] == K_SLK))) {
+ noledmap.key[i].map[j] = K_NOP;
+ }
+ }
+ }
+ }
+}
+
+int
+xf86KbdOn(void)
+{
+ struct termio newtio;
+
+ newtio = orig_termio; /* structure copy */
+ newtio.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ newtio.c_oflag = 0;
+ newtio.c_cflag = CREAD | CS8 | B9600;
+ newtio.c_lflag = 0;
+ newtio.c_cc[VTIME]=0;
+ newtio.c_cc[VMIN]=1;
+ ioctl(xf86Info.consoleFd, TCSETA, &newtio);
+
+ ioctl (xf86Info.consoleFd, KDSKBMODE, K_RAW);
+ ioctl (xf86Info.consoleFd, PIO_KEYMAP, &noledmap);
+
+ return(xf86Info.consoleFd);
+}
+
+int
+xf86KbdOff(void)
+{
+ ioctl (xf86Info.consoleFd, KDSKBMODE, orig_kbm);
+ ioctl (xf86Info.consoleFd, PIO_KEYMAP, &keymap);
+ ioctl(xf86Info.consoleFd, TCSETA, &orig_termio);
+
+ return(xf86Info.consoleFd);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_iop.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_iop.c
new file mode 100644
index 000000000..362ac369e
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_iop.c
@@ -0,0 +1,108 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_iop.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */
+/*
+ * Copyright 2001,2005 by Kean Johnston <jkj@sco.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $XConsortium$ */
+
+
+#include "X.h"
+
+#include "compiler.h"
+
+#define _NEED_SYSI86
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86OSpriv.h"
+#include "xf86_OSlib.h"
+
+
+/***************************************************************************/
+/* I/O Permissions section */
+/***************************************************************************/
+
+static Bool IOEnabled = FALSE;
+
+Bool
+xf86EnableIO(void)
+{
+ if (IOEnabled)
+ return TRUE;
+
+ if (sysi86(SI86IOPL, 3) < 0)
+ FatalError("Failed to set IOPL for extended I/O\n");
+ IOEnabled = TRUE;
+ return TRUE;
+}
+
+void
+xf86DisableIO(void)
+{
+ if (!IOEnabled)
+ return;
+
+ sysi86(SI86IOPL, 0);
+ IOEnabled = FALSE;
+}
+
+/***************************************************************************/
+/* Interrupt Handling section */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts(void)
+{
+ if (!IOEnabled) {
+ if (sysi86(SI86IOPL, 3) < 0)
+ return FALSE;
+ }
+
+#ifdef __GNUC__
+ __asm__ __volatile__("cli");
+#else
+ asm("cli");
+#endif /* __GNUC__ */
+
+ if (!IOEnabled) {
+ sysi86(SI86IOPL, 0);
+ }
+
+ return(TRUE);
+}
+
+void
+xf86EnableInterrupts(void)
+{
+ if (!IOEnabled) {
+ if (sysi86(SI86IOPL, 3) < 0)
+ return;
+ }
+
+#ifdef __GNUC__
+ __asm__ __volatile__("sti");
+#else
+ asm("sti");
+#endif /* __GNUC__ */
+
+ if (!IOEnabled) {
+ sysi86(SI86IOPL, 0);
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.c
new file mode 100644
index 000000000..c6e089db8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.c
@@ -0,0 +1,456 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */
+/*
+ * Copyright 2005 by Kean Johnston <jkj@sco.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name Kean Johnston not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Kean Johnston makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * KEAN JOHNSTON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $XConsortium$ */
+
+/*
+ * Based on sco_io.c which is
+ * (C) Copyright 2003 Kean Johnston <jkj@sco.com>
+ *
+ * Based on lnx_kbd.c which is
+ * Copyright (c) 2002 by The XFree86 Project, Inc.
+ *
+ * Based on the code from lnx_io.c which is
+ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ */
+
+#define NEED_EVENTS
+#include "X.h"
+
+#include "compiler.h"
+
+#define _NEED_SYSI86
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86OSpriv.h"
+#include "xf86_OSlib.h"
+
+#include "xf86Xinput.h"
+#include "xf86OSKbd.h"
+#include "atKeynames.h"
+#include "usl_kbd.h"
+#include "usl_xqueue.h"
+
+#include <sys/param.h>
+
+static KbdProtocolRec protocols[] = {
+ { "standard", PROT_STD },
+ { "Xqueue", PROT_XQUEUE },
+ { NULL, PROT_UNKNOWN_KBD }
+};
+
+extern Bool VTSwitchEnabled;
+#ifdef USE_VT_SYSREQ
+extern Bool VTSysreqToggle;
+#endif
+
+static void
+SoundBell(InputInfoPtr pInfo, int loudness, int pitch, int duration)
+{
+ if (loudness && pitch) {
+ ioctl(pInfo->fd, KIOCSOUND, 1193180 / pitch);
+ usleep(duration * loudness * 20);
+ ioctl(pInfo->fd, KIOCSOUND, 0);
+ }
+}
+
+static void
+SetKbdLeds(InputInfoPtr pInfo, int leds)
+{
+ int real_leds = 0;
+
+ if (leds & XLED1)
+ real_leds |= LED_CAP;
+ if (leds & XLED2)
+ real_leds |= LED_NUM;
+ if (leds & XLED3)
+ real_leds |= LED_SCR;
+ ioctl(pInfo->fd, KDSETLED, real_leds);
+}
+
+static int
+GetKbdLeds(InputInfoPtr pInfo)
+{
+ int real_leds, leds = 0;
+
+ ioctl(pInfo->fd, KDGETLED, &real_leds);
+
+ if (real_leds & LED_CAP) leds |= XLED1;
+ if (real_leds & LED_NUM) leds |= XLED2;
+ if (real_leds & LED_SCR) leds |= XLED3;
+
+ return(leds);
+}
+
+static void
+SetKbdRepeat(InputInfoPtr pInfo, char rad)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ int i;
+ int value = 0x7f; /* Maximum delay with slowest rate */
+ int delay = 250; /* Default delay */
+ int rate = 300; /* Default repeat rate */
+
+ static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150,
+ 133, 120, 109, 100, 92, 86, 80, 75, 67,
+ 60, 55, 50, 46, 43, 40, 37, 33, 30, 27,
+ 25, 23, 21, 20 };
+#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int ))
+
+ static int valid_delays[] = { 250, 500, 750, 1000 };
+#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int ))
+
+ if (pKbd->rate >= 0)
+ rate = pKbd->rate * 10;
+ if (pKbd->delay >= 0)
+ delay = pKbd->delay;
+
+ for (i = 0; i < RATE_COUNT; i++)
+ if (rate >= valid_rates[i]) {
+ value &= 0x60;
+ value |= i;
+ break;
+ }
+
+ for (i = 0; i < DELAY_COUNT; i++)
+ if (delay <= valid_delays[i]) {
+ value &= 0x1f;
+ value |= i << 5;
+ break;
+ }
+
+ ioctl (pInfo->fd, KDSETTYPEMATICS, value);
+}
+
+static int
+KbdInit(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private;
+
+ if (pKbd->isConsole) {
+ if (ioctl (pInfo->fd, KDGKBMODE, &priv->orig_kbm) < 0) {
+ xf86Msg (X_ERROR, "KbdInit: Could not determine keyboard mode\n");
+ return !Success;
+ }
+
+ /*
+ * We need to get the original keyboard map and NUL out the lock
+ * modifiers. This prevents the kernel from messing with
+ * the keyboard LED's. We restore the original map when we exit.
+ * Note that we also have to eliminate screen switch sequences
+ * else the VT manager will switch for us, which we don't want.
+ * For example, lets say you had changed the VT manager to switch
+ * on Alt-Fx instead of Ctrl-Alt-Fx. This means that while inside
+ * X, you cant use, for example, Alt-F4, which is a pain in the
+ * fundamental when you're using CDE-like thingies.
+ */
+ if (ioctl (pInfo->fd, GIO_KEYMAP, &priv->keymap) < 0) {
+ xf86Msg (X_ERROR, "KbdInit: Failed to get keyboard map (%s)\n",
+ strerror(errno));
+ return !Success;
+ }
+ if (ioctl (pInfo->fd, GIO_KEYMAP, &priv->noledmap) < 0) {
+ xf86Msg (X_ERROR, "KbdInit: Failed to get keyboard map (%s)\n",
+ strerror(errno));
+ return !Success;
+ } else {
+ int i, j;
+
+ for (i = 0; i < priv->noledmap.n_keys; i++) {
+ for (j = 0; j < NUM_STATES; j++) {
+ if (IS_SPECKEY(&priv->noledmap, i, j) &&
+ ((priv->noledmap.key[i].map[j] == K_CLK) ||
+ (priv->noledmap.key[i].map[j] == K_NLK) ||
+ (priv->noledmap.key[i].map[j] == K_SLK) ||
+ (priv->noledmap.key[i].map[j] == K_FRCNEXT) ||
+ (priv->noledmap.key[i].map[j] == K_FRCPREV) ||
+ ((priv->noledmap.key[i].map[j] >= K_VTF) &&
+ (priv->noledmap.key[i].map[j] <= K_VTL)) )) {
+ priv->noledmap.key[i].map[j] = K_NOP;
+ }
+ }
+ }
+ }
+
+ if (ioctl (pInfo->fd, TCGETA, &priv->kbdtty) < 0) {
+ xf86Msg (X_ERROR, "KbdInit: Failed to get terminal modes (%s)\n",
+ strerror(errno));
+ return !Success;
+ }
+ } /* End of if we are on a console */
+
+ return Success;
+}
+
+static int
+KbdOn(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private;
+ struct termio newtio;
+
+ if (pKbd->isConsole) {
+ /*
+ * Use the calculated keyboard map that does not have active
+ * LED lock handling (we track LEDs ourselves).
+ */
+ ioctl (pInfo->fd, PIO_KEYMAP, &priv->noledmap);
+
+#ifdef NOTYET
+ newtio = priv->kbdtty; /* structure copy */
+ newtio.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ newtio.c_oflag = 0;
+ newtio.c_cflag = CREAD | CS8 | B9600;
+ newtio.c_lflag = 0;
+ newtio.c_cc[VTIME]=0;
+ newtio.c_cc[VMIN]=1;
+ ioctl(pInfo->fd, TCSETA, &newtio);
+
+ if (priv->xq == 0)
+ ioctl (pInfo->fd, KDSKBMODE, K_RAW);
+ else
+#endif
+ XqKbdOnOff (pInfo, 1);
+ }
+
+ return Success;
+}
+
+static int
+KbdOff(InputInfoPtr pInfo, int what)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private;
+
+ if (pKbd->isConsole) {
+ /* Revert back to original translate scancode mode */
+#ifdef NOTYET
+ if (priv->xq == 0)
+ ioctl (pInfo->fd, KDSKBMODE, priv->orig_kbm);
+ else
+#endif
+ XqKbdOnOff (pInfo, 0);
+
+ ioctl (pInfo->fd, PIO_KEYMAP, &priv->keymap);
+ ioctl(pInfo->fd, TCSETA, &priv->kbdtty);
+ }
+
+ return Success;
+}
+
+#define ModifierSet(k) ((modifiers & (k)) == (k))
+
+static Bool
+SpecialKey(InputInfoPtr pInfo, int key, Bool down, int modifiers)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+
+ if(!pKbd->vtSwitchSupported)
+ return FALSE;
+
+ if ((!ModifierSet(ShiftMask)) && ((ModifierSet(ControlMask | AltMask)) ||
+ (ModifierSet(ControlMask | AltLangMask)))) {
+ if (VTSwitchEnabled && !xf86Info.vtSysreq) {
+ switch (key) {
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ if (down) {
+ int sts = key - KEY_F1;
+ if (sts != xf86Info.vtno) {
+ ioctl(pInfo->fd, VT_SWITCH, sts);
+ }
+ return TRUE;
+ }
+ case KEY_F11:
+ case KEY_F12:
+ if (down) {
+ int sts = key - KEY_F11 + 10;
+ if (sts != xf86Info.vtno) {
+ ioctl(pInfo->fd, VT_SWITCH, sts);
+ }
+ return TRUE;
+ }
+ }
+ }
+ }
+#ifdef USE_VT_SYSREQ
+ if (VTSwitchEnabled && xf86Info.vtSysreq) {
+ switch (key) {
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ if (VTSysreqToggle && down) {
+ ioctl(pInfo->fd, VT_ACTIVATE, key - KEY_F1);
+ VTSysreqToggle = FALSE;
+ return TRUE;
+ }
+ break;
+ case KEY_F11:
+ case KEY_F12:
+ if (VTSysreqToggle && down) {
+ ioctl(pInfo->fd, VT_ACTIVATE, key - KEY_F11 + 10);
+ VTSysreqToggle = FALSE;
+ return TRUE;
+ }
+ break;
+ /* Ignore these keys -- ie don't let them cancel an alt-sysreq */
+ case KEY_Alt:
+ case KEY_AltLang:
+ break;
+ case KEY_SysReqest:
+ if (!(ModifierSet(ShiftMask) || ModifierSet(ControlMask))) {
+ if ((ModifierSet(AltMask) || ModifierSet(AltLangMask)) && down)
+ VTSysreqToggle = TRUE;
+ }
+ break;
+ default:
+ /*
+ * We only land here when Alt-SysReq is followed by a
+ * non-switching key.
+ */
+ if (VTSysreqToggle)
+ VTSysreqToggle = FALSE;
+ }
+ }
+#endif /* USE_VT_SYSREQ */
+ return FALSE;
+}
+
+#ifdef NOTYET
+static void
+stdReadInput(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ unsigned char rBuf[64];
+ int nBytes, i;
+
+ if ((nBytes = read( pInfo->fd, (char *)rBuf, sizeof(rBuf))) > 0) {
+ for (i = 0; i < nBytes; i++) {
+ pKbd->PostEvent(pInfo, rBuf[i] & 0x7f, rBuf[i] & 0x80 ? FALSE : TRUE);
+ }
+ }
+}
+#endif
+
+static Bool
+OpenKeyboard(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+ USLKbdPrivPtr priv = (USLKbdPrivPtr) pKbd->private;
+ int i;
+ KbdProtocolId prot = PROT_UNKNOWN_KBD;
+ char *s;
+
+ s = xf86SetStrOption(pInfo->options, "Protocol", NULL);
+ for (i = 0; protocols[i].name; i++) {
+ if (xf86NameCmp(s, protocols[i].name) == 0) {
+ prot = protocols[i].id;
+ break;
+ }
+ }
+
+ switch (prot) {
+ case PROT_STD:
+#ifdef NOTYET
+ pInfo->read_input = stdReadInput;
+ priv->xq = 0;
+ break;
+#endif
+ case PROT_XQUEUE:
+ pInfo->read_input = NULL; /* Handled by the XQUEUE signal handler */
+ priv->xq = 1;
+ break;
+ default:
+ xf86Msg(X_ERROR,"\"%s\" is not a valid keyboard protocol name\n", s);
+ xfree(s);
+ return FALSE;
+ }
+
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, s);
+ xfree(s);
+
+ s = xf86SetStrOption(pInfo->options, "Device", NULL);
+ if (s == NULL) {
+ pInfo->fd = xf86Info.consoleFd;
+ pKbd->isConsole = TRUE;
+ } else {
+ pInfo->fd = open(s, O_RDONLY | O_NONBLOCK | O_EXCL);
+ if (pInfo->fd == -1) {
+ xf86Msg(X_ERROR, "%s: cannot open \"%s\"\n", pInfo->name, s);
+ xfree(s);
+ return FALSE;
+ }
+ pKbd->isConsole = FALSE;
+ xfree(s);
+ }
+
+ if (pKbd->isConsole)
+ pKbd->vtSwitchSupported = TRUE;
+
+ return TRUE;
+}
+
+Bool
+xf86OSKbdPreInit(InputInfoPtr pInfo)
+{
+ KbdDevPtr pKbd = pInfo->private;
+
+ pKbd->KbdInit = KbdInit;
+ pKbd->KbdOn = KbdOn;
+ pKbd->KbdOff = KbdOff;
+ pKbd->Bell = SoundBell;
+ pKbd->SetLeds = SetKbdLeds;
+ pKbd->GetLeds = GetKbdLeds;
+ pKbd->SetKbdRepeat = SetKbdRepeat;
+ pKbd->KbdGetMapping = KbdGetMapping;
+ pKbd->SpecialKey = SpecialKey;
+ pKbd->OpenKeyboard = OpenKeyboard;
+
+ pKbd->GetSpecialKey = NULL;
+ pKbd->RemapScanCode = ATScancode;
+ pKbd->vtSwitchSupported = FALSE;
+
+ pKbd->private = xcalloc(sizeof(USLKbdPrivRec), 1);
+ if (pKbd->private == NULL) {
+ xf86Msg(X_ERROR,"can't allocate keyboard OS private data\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.h
new file mode 100644
index 000000000..a65986fe5
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.h
@@ -0,0 +1,14 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_kbd.h,v 1.2 2005/11/08 06:33:30 jkj Exp $ */
+#ifndef SCO_KBD_HDR
+#define SCO_KBD_HDR
+
+typedef struct {
+ int orig_kbm;
+ struct termio kbdtty;
+ keymap_t keymap, noledmap;
+ int xq;
+} USLKbdPrivRec, *USLKbdPrivPtr;
+
+extern void KbdGetMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms,
+ CARD8 *pModMap);
+#endif /* SCO_KBD_HDR */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_mouse.c
new file mode 100644
index 000000000..708a08e11
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_mouse.c
@@ -0,0 +1,181 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_mouse.c,v 1.3 2005/11/10 02:41:20 jkj Exp $ */
+
+/*
+ * Copyright 2005 Kean Johnston
+ * Copyright 1999 by The XFree86 Project, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of The XFree86 Project, Inc
+ * and Kean Johnston not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * The XFree86 Project, Inc and Kean Johnston make no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THE XFREE86 PROJECT, INC AND KEAN JOHNSTON DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THOMAS ROELLm DAVID WEXELBLAT
+ * OR KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ *
+ */
+
+#include "X.h"
+#include "compiler.h"
+#include "xf86.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "mipointer.h"
+#include "usl_xqueue.h"
+
+static int
+SupportedInterfaces(void)
+{
+ return MSE_MISC;
+}
+
+static const char *internalNames[] = {
+ "Xqueue",
+ NULL
+};
+
+static const char **
+BuiltinNames(void)
+{
+ return internalNames;
+}
+
+static const char *
+DefaultProtocol (void)
+{
+ return "Xqueue";
+}
+
+static Bool
+CheckProtocol(const char *protocol)
+{
+ int i;
+
+ for (i = 0; internalNames[i]; i++)
+ if (xf86NameCmp(protocol, internalNames[i]) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+static int
+OsMouseProc(DeviceIntPtr pPointer, int what)
+{
+ InputInfoPtr pInfo;
+ MouseDevPtr pMse;
+ unsigned char map[9];
+ int ret;
+
+ pInfo = pPointer->public.devicePrivate;
+ pMse = pInfo->private;
+ pMse->device = pPointer;
+
+ switch (what) {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+
+ for (ret = 0; ret <= 8; ret++)
+ map[ret] = ret;
+
+ InitPointerDeviceStruct((DevicePtr)pPointer, map, 8,
+ miPointerGetMotionEvents, pMse->Ctrl,
+ miPointerGetMotionBufferSize());
+ /* X valuator */
+ xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 0);
+
+ /* Y valuator */
+ xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pPointer, 1);
+
+ xf86MotionHistoryAllocate(pInfo);
+ break;
+
+ case DEVICE_ON:
+ pMse->lastButtons = 0;
+ pMse->emulateState = 0;
+ pPointer->public.on = TRUE;
+ XqMseOnOff (pInfo, 1);
+ break;
+
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ pPointer->public.on = FALSE;
+ XqMseOnOff (pInfo, 0);
+ break;
+ }
+ return Success;
+}
+
+static Bool
+OsMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
+{
+ /* This is called when the protocol is "Xqueue" */
+ MouseDevPtr pMse;
+
+ pMse = pInfo->private;
+ pMse->protocol = protocol;
+ xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
+
+ /* Collect the options, and process the common options. */
+ xf86CollectInputOptions(pInfo, NULL, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ pInfo->fd = -1;
+#if 0
+ /* Make sure we can open the mouse */
+ pInfo->fd = open ("/dev/mouse", O_RDONLY | O_NONBLOCK);
+
+ if (pInfo->fd < 0) {
+ if (xf86GetAllowMouseOpenFail()) {
+ xf86Msg(X_WARNING, "%s: cannot open /dev/mouse (%s)\n",
+ pInfo->name, strerror(errno));
+ } else {
+ xf86Msg(X_ERROR, "%s: cannot open /dev/mouse (%s)\n",
+ pInfo->name, strerror(errno));
+ xfree(pMse);
+ return FALSE;
+ }
+ }
+#endif
+
+ /* Process common mouse options (like Emulate3Buttons, etc). */
+ pMse->CommonOptions(pInfo);
+
+ /* Setup the local procs. */
+ pInfo->device_control = OsMouseProc;
+ pInfo->read_input = NULL; /* Handled by the XQUEUE signal handler */
+
+ pInfo->flags |= XI86_CONFIGURED;
+ return TRUE;
+}
+
+OSMouseInfoPtr
+xf86OSMouseInit(int flags)
+{
+ OSMouseInfoPtr p;
+
+ p = xcalloc(sizeof(OSMouseInfoRec), 1);
+ if (!p)
+ return NULL;
+
+ p->SupportedInterfaces = SupportedInterfaces;
+ p->BuiltinNames = BuiltinNames;
+ p->DefaultProtocol = DefaultProtocol;
+ p->CheckProtocol = CheckProtocol;
+ p->PreInit = OsMousePreInit;
+ return p;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_video.c
new file mode 100644
index 000000000..2c85ea92c
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_video.c
@@ -0,0 +1,111 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_video.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */
+/*
+ * Copyrught 2005 Kean Johnston <jkj@sco.com>
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Thomas Roell, David Dawes
+ * and Kean Johnston not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Thomas Roell, David Dawes and Kean Johnston make no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL, DAVID DAWES AND KEAN JOHNSTON DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THOMAS ROELLm DAVID WEXELBLAT
+ * OR KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ *
+ */
+/* $XConsortium$ */
+
+#include "X.h"
+
+#define _NEED_SYSI86
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+static Bool
+linearVidMem(void)
+{
+ return TRUE;
+}
+
+static pointer
+mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+ pointer base;
+ int fd;
+
+ fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
+ if (fd < 0) {
+ FatalError("xf86MapVidMem: failed to open %s (%s)\n",
+ DEV_MEM, strerror(errno));
+ }
+ base = mmap((caddr_t)0, Size, (flags & VIDMEM_READONLY) ?
+ PROT_READ : (PROT_READ | PROT_WRITE),
+ MAP_SHARED, fd, (off_t)Base);
+ close(fd);
+
+ if (base == MAP_FAILED) {
+ FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
+ "xf86MapVidMem", Size, Base, strerror(errno));
+ }
+ return(base);
+}
+
+/* ARGSUSED */
+static void
+unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+ munmap(Base, Size);
+}
+
+/*
+ * For some SVR4 versions, a 32-bit read is done for the first location
+ * in each page when the page is first mapped. If this is done while
+ * memory access is enabled for regions that have read side-effects,
+ * this can cause unexpected results, including lockups on some hardware.
+ * This function is called to make sure each page is mapped while it is
+ * safe to do so.
+ */
+
+#define X_PAGE_SIZE 4096
+
+static void
+readSideEffects(int ScreenNum, pointer Base, unsigned long Size)
+{
+ unsigned long base, end, addr;
+ CARD32 val;
+
+ base = (unsigned long)Base;
+ end = base + Size;
+
+ for (addr = base; addr < end; addr += X_PAGE_SIZE)
+ val = *(volatile CARD32 *)addr;
+}
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+ pVidMem->linearSupported = linearVidMem();
+ pVidMem->mapMem = mapVidMem;
+ pVidMem->unmapMem = unmapVidMem;
+ pVidMem->readSideEffects = readSideEffects;
+ pVidMem->initialised = TRUE;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_vtsw.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_vtsw.c
new file mode 100644
index 000000000..d15a24149
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_vtsw.c
@@ -0,0 +1,97 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_vtsw.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */
+/*
+ * Copyright 2005 by Kean Johnston <jkj@sco.com>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ * Copyright 1993 by David McCullough <davidm@stallion.oz.au>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium$ */
+
+#include "X.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * Handle the VT-switching interface for SCO UnixWare / OpenServer 6
+ */
+
+/*
+ * This function is the signal handler for the VT-switching signal. It
+ * is only referenced inside the OS-support layer. NOTE: we do NOT need
+ * to re-arm the signal here, since we used sigaction() to set the signal
+ * disposition in usl_init.c. If we had used signal(), we would need to
+ * re-arm the signal here. All we need to do now is record the fact that
+ * we got the signal. XFree86 handles the rest.
+ */
+void
+xf86VTRequest(int sig)
+{
+ xf86Info.vtRequestsPending = TRUE;
+ return;
+}
+
+Bool
+xf86VTSwitchPending(void)
+{
+ return(xf86Info.vtRequestsPending ? TRUE : FALSE);
+}
+
+static int usl_ledstatus = -1;
+static unsigned int usl_ledstate = 0;
+
+Bool
+xf86VTSwitchAway(void)
+{
+ usl_ledstatus = ioctl(xf86Info.consoleFd, KDGETLED, &usl_ledstate);
+
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, 1) < 0) {
+ return(FALSE);
+ } else {
+ return(TRUE);
+ }
+}
+
+Bool
+xf86VTSwitchTo(void)
+{
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) {
+ return(FALSE);
+ } else {
+ if (usl_ledstatus >= 0) {
+ ioctl (xf86Info.consoleFd, KDSETLED, usl_ledstate);
+ }
+ usl_ledstatus = -1;
+
+ /*
+ * Convince the console driver this screen is in graphics mode,
+ * otherwise it assumes it can do more to the screen than it should.
+ */
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) {
+ ErrorF("Failed to set graphics mode (%s)\n", strerror(errno));
+ }
+
+ return TRUE;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.c
new file mode 100644
index 000000000..8b66ee1f8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.c
@@ -0,0 +1,360 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.c,v 1.3 2005/11/10 02:41:20 jkj Exp $ */
+/*
+ * Copyright 2005 by Kean Johnston <jkj@sco.com>
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1993-1999 by The XFree86 Project, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. The copyright holders make no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $XConsortium$ */
+
+#include "X.h"
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+#include "xf86Xinput.h"
+#include "xf86OSmouse.h"
+#include "xf86OSKbd.h"
+#include "usl_xqueue.h"
+
+#ifdef XKB
+#include "inputstr.h"
+#include <X11/extensions/XKB.h>
+#include <X11/extensions/XKBstr.h>
+#include <X11/extensions/XKBsrv.h>
+extern Bool noXkbExtension;
+#endif
+
+#include "xf86Xinput.h"
+#include "mipointer.h"
+
+#if !defined(XQ_WHEEL)
+# define XQ_WHEEL 4
+#endif
+
+/*
+ * Implementation notes
+ *
+ * This code is based on a mixture of the original XFree86 sysv/xqueue.c
+ * and information gathered from the SCO X server code (no actual code
+ * was used, just the principles).
+ *
+ * The XFree86 XQUEUE code went to some considerable lengths to implement
+ * what it calls "asynchronous XQUEUE". This involved creating a pipe,
+ * and writing to that pipe each time an XQUEUE signal is received. The
+ * one end of that pipe was then added to the list of selectable file
+ * descriptors with AddEnabledDevice(). I completely fail to see the need
+ * for this, and this code does not implement that mechanism. The server
+ * will be interrupted anyway by the XQUEUE driver, so whether we pull the
+ * events off the queue at the time we receive the signal or whether we
+ * write to a pipe and then have the main select() loop stop and call us,
+ * it makes no difference I can fathom.
+ *
+ * The code also differs from the original XFree86 code in that it maintains
+ * local variables for the number of devices initialized. The original code
+ * stored that information in the private data pointer of the mouse structure,
+ * but this same code is used for both the keyboard and the mouse, so that
+ * was changed.
+ *
+ * Part of the difficulty in dealing with XQUEUE is that it is a single
+ * interface to two devices. The recent changes in XFree86/Xorg try to
+ * treat the mouse and keyboard as discrete devices, and the code is
+ * structured in such a way that they should be able to be independently
+ * opened and closed. But we can't do that with XQUEUE, so we have to
+ * centralize XQUEUE access here in this module.
+ */
+
+static xqEventQueue *xqQaddr = NULL;
+static int xqSigEnable = 1;
+static int xqEnableCount = 0;
+static struct kd_quemode xqMode;
+
+/*
+ * These two pointers are set when the keyboard/mouse handler procs
+ * are called to turn them on or off. This is so that we can call the
+ * correct PostEvent for the device.
+ */
+static InputInfoPtr xqMouse = NULL;
+static InputInfoPtr xqKeyboard = NULL;
+
+static void XqSignalHandler (int signo);
+
+/*
+ * Private functions
+ */
+static void
+XqReset (void)
+{
+ if (xqEnableCount > 0) {
+ xqQaddr->xq_head = xqQaddr->xq_tail;
+ xqQaddr->xq_sigenable = xqSigEnable;
+ }
+}
+
+#ifdef NOTNEEDED
+static void
+XqLock (void)
+{
+ xqSigEnable = 0;
+ if (xqEnableCount > 0) {
+ xqQaddr->xq_sigenable = xqSigEnable;
+ }
+}
+
+static void
+XqUnlock (void)
+{
+ xqSigEnable = 1;
+ if (xqEnableCount > 0) {
+ xqQaddr->xq_sigenable = xqSigEnable;
+ }
+}
+#endif /* NOTNEEDED */
+
+/*
+ * Since this code is shared between two devices, we need to keep track
+ * of how many times we've been enabled or disabled. For example, if the
+ * keyboard has been turned off, but the mouse hasn't, then we do not
+ * want the whole queue off. Only when both devices are turned off do we
+ * actually disable Xqueue mode. When either device is turned on, we
+ * enable it.
+ */
+static int
+XqEnable (InputInfoPtr pInfo)
+{
+ struct sigaction xqsig;
+ static int msefd = -1;
+
+ if (msefd == -1) {
+ msefd = open ("/dev/mouse", O_RDONLY | O_NONBLOCK);
+#if 0
+ msefd = open ("/dev/mouse", O_RDONLY | O_NONBLOCK | O_NOCTTY);
+ if (msefd < 0) {
+ /*
+ * Try giving it a controlling tty
+ */
+ msefd = open (ttyname(xf86Info.consoleFd), O_RDWR | O_NONBLOCK);
+ if (msefd >= 0)
+ close (msefd);
+ msefd = open ("/dev/mouse", O_RDONLY | O_NONBLOCK | O_NOCTTY);
+ if (msefd < 0)
+ sleep(2);
+ }
+#endif
+ }
+
+ if (msefd < 0) {
+ if (xf86GetAllowMouseOpenFail()) {
+ ErrorF("%s: cannot open /dev/mouse (%s)\n",
+ ttyname(xf86Info.consoleFd), strerror(errno));
+ } else {
+ sleep(5);
+ FatalError ("%s: cannot open /dev/mouse (%s)\n",
+ ttyname(xf86Info.consoleFd), strerror(errno));
+ }
+ }
+
+ if (xqEnableCount++ == 0) {
+ xqMode.qaddr = 0;
+ ioctl (xf86Info.consoleFd, KDQUEMODE, NULL);
+
+ /*
+ * Note: We need to make sure the signal is armed before we enable
+ * XQUEUE mode, so that if we get events immediately after the ioctl
+ * we dont have an unhandled signal coming to the Xserver.
+ * Also note that we use sigaction, so that we do not have to re-arm
+ * the signal every time it is delivered, which just slows things
+ * down (setting a signal is a fairly expensive operation).
+ */
+
+ xqsig.sa_handler = XqSignalHandler;
+ sigfillset (&xqsig.sa_mask);
+ xqsig.sa_flags = 0;
+ sigaction (SIGUSR2, &xqsig, NULL);
+
+ /*
+ * This is a fairly large queue size. Since we are reacting to events
+ * asynchronously, its best for performance if we deal with as many
+ * events as possible, and high resolution mice generate a lot of
+ * events.
+ */
+ xqMode.qsize = 64;
+ xqMode.signo = SIGUSR2;
+ xqMode.qaddr = 0;
+ if (ioctl (xf86Info.consoleFd, KDQUEMODE, &xqMode) < 0) {
+ xf86Msg (X_ERROR, "%s: could not set XQUEUE mode (%s)", pInfo->name,
+ strerror(errno));
+ xqEnableCount--;
+
+ xqsig.sa_handler = SIG_DFL;
+ sigfillset (&xqsig.sa_mask);
+ xqsig.sa_flags = 0;
+ sigaction (SIGUSR2, &xqsig, NULL);
+
+ return !Success;
+ }
+
+ /*
+ * We're in business. The workstation is now in XQUEUE mode.
+ */
+ xqQaddr = (xqEventQueue *)xqMode.qaddr;
+ xqQaddr->xq_sigenable = 0; /* LOCK */
+ nap(500);
+ XqReset();
+ }
+ return Success;
+}
+
+static int
+XqDisable (InputInfoPtr pInfo)
+{
+ struct sigaction xqsig;
+
+ if (xqEnableCount-- == 1) {
+ xqQaddr->xq_sigenable = 0; /* LOCK */
+
+ if (ioctl (xf86Info.consoleFd, KDQUEMODE, NULL) < 0) {
+ xf86Msg (X_ERROR, "%s: could not unset XQUEUE mode (%s)", pInfo->name,
+ strerror(errno));
+ xqEnableCount++;
+ return !Success;
+ }
+
+ xqsig.sa_handler = SIG_DFL;
+ sigfillset (&xqsig.sa_mask);
+ xqsig.sa_flags = 0;
+ sigaction (SIGUSR2, &xqsig, NULL);
+ }
+
+ return Success;
+}
+
+/*
+ * XQUEUE signal handler. This is what goes through the list of events
+ * we've already received and dispatches them to either the keyboard or
+ * mouse event poster.
+ */
+static void
+XqSignalHandler (int signo)
+{
+ xqEvent *xqEvents = xqQaddr->xq_events;
+ int xqHead = xqQaddr->xq_head;
+ xEvent xE;
+ MouseDevPtr pMse = NULL;
+ KbdDevPtr pKbd = NULL;
+ signed char dx, dy;
+
+ if (xqMouse)
+ pMse = (MouseDevPtr)xqMouse->private;
+ if (xqKeyboard)
+ pKbd = (KbdDevPtr)xqKeyboard->private;
+
+ while (xqHead != xqQaddr->xq_tail) {
+
+ switch (xqEvents[xqHead].xq_type) {
+ case XQ_MOTION:
+ dx = (signed char)xqEvents[xqHead].xq_x;
+ dy = (signed char)xqEvents[xqHead].xq_y;
+ if (pMse)
+ pMse->PostEvent(xqMouse, ~(xqEvents[xqHead].xq_code) & 0x07,
+ (int)dx, (int)dy, 0, 0);
+ break;
+
+ case XQ_BUTTON:
+ if (pMse)
+ pMse->PostEvent(xqMouse, ~(xqEvents[xqHead].xq_code) & 0x07,
+ 0, 0, 0, 0);
+ break;
+
+ case XQ_WHEEL:
+ if (pMse) {
+ int wbut = pMse->lastButtons, dz;
+ if (xqEvents[xqHead].xq_code == 1)
+ dz = 1;
+ else
+ dz = -1;
+ pMse->PostEvent(xqMouse, wbut, 0, 0, dz, 0);
+ }
+ break;
+
+ case XQ_KEY:
+ if (pKbd)
+ pKbd->PostEvent(xqKeyboard, xqEvents[xqHead].xq_code & 0x7f,
+ xqEvents[xqHead].xq_code & 0x80 ? FALSE : TRUE);
+ break;
+
+ default:
+ xf86Msg(X_WARNING, "XQUEUE: unknown event type %d\n",
+ xqEvents[xqHead].xq_type);
+ break;
+ }
+
+ xqHead++;
+ if (xqHead == xqQaddr->xq_size)
+ xqHead = 0;
+ xf86Info.inputPending = TRUE;
+ }
+
+ XqReset();
+}
+
+/*
+ * Public functions
+ */
+int
+XqMseOnOff (InputInfoPtr pInfo, int on)
+{
+ if (on) {
+ if (xqMouse) {
+ if (xqMouse != pInfo)
+ xf86Msg(X_WARNING, "XqMseOnOff: mouse pointer structure changed!\n");
+ xqMouse = pInfo;
+ } else {
+ xqMouse = pInfo;
+ return XqEnable(pInfo);
+ }
+ } else {
+ xqMouse = NULL;
+ return XqDisable(pInfo);
+ }
+ return Success;
+}
+
+int
+XqKbdOnOff (InputInfoPtr pInfo, int on)
+{
+ if (on) {
+ if (xqKeyboard) {
+ if (xqKeyboard != pInfo)
+ xf86Msg(X_WARNING, "XqKbdOnOff: keyboard pointer structure changed!\n");
+ xqKeyboard = pInfo;
+ } else {
+ xqKeyboard = pInfo;
+ return XqEnable(pInfo);
+ }
+ } else {
+ xqKeyboard = NULL;
+ return XqDisable(pInfo);
+ }
+ return Success;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.h
new file mode 100644
index 000000000..2a777accf
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.h
@@ -0,0 +1,9 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/usl/usl_xqueue.h,v 1.2 2005/11/08 06:33:30 jkj Exp $ */
+
+#ifndef _XF86_USL_XQUEUE_H_
+#define _XF86_USL_XQUEUE_H_
+
+extern int XqMseOnOff (InputInfoPtr pInfo, int on);
+extern int XqKbdOnOff (InputInfoPtr pInfo, int on);
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSKbd.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSKbd.h
new file mode 100644
index 000000000..344f7e901
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSKbd.h
@@ -0,0 +1,133 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86OSKbd.h,v 1.5tsi Exp $ */
+/*
+ * Copyright (c) 2002-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).
+ *
+ * Author: Ivan Pascal.
+ */
+
+#include "xf86Xinput.h"
+
+Bool ATScancode(InputInfoPtr pInfo, int *scanCode);
+
+/* Public interface to OS-specific keyboard support. */
+
+typedef int (*KbdInitProc)(InputInfoPtr pInfo, int what);
+typedef int (*KbdOnProc)(InputInfoPtr pInfo, int what);
+typedef int (*KbdOffProc)(InputInfoPtr pInfo, int what);
+typedef void (*BellProc)(InputInfoPtr pInfo,
+ int loudness, int pitch, int duration);
+typedef void (*SetLedsProc)(InputInfoPtr pInfo, int leds);
+typedef int (*GetLedsProc)(InputInfoPtr pInfo);
+typedef void (*SetKbdRepeatProc)(InputInfoPtr pInfo, char rad);
+typedef void (*KbdGetMappingProc)(InputInfoPtr pInfo,
+ KeySymsPtr pKeySyms, CARD8* pModMap);
+typedef int (*GetSpecialKeyProc)(InputInfoPtr pInfo, int scanCode);
+typedef Bool (*SpecialKeyProc)(InputInfoPtr pInfo,
+ int key, Bool down, int modifiers);
+typedef int (*RemapScanCodeProc)(InputInfoPtr pInfo, int *scanCode);
+typedef Bool (*OpenKeyboardProc)(InputInfoPtr pInfo);
+typedef void (*PostEventProc)(InputInfoPtr pInfo,
+ unsigned int key, Bool down);
+typedef struct {
+ int begin;
+ int end;
+ unsigned char *map;
+} TransMapRec, *TransMapPtr;
+
+typedef struct {
+ KbdInitProc KbdInit;
+ KbdOnProc KbdOn;
+ KbdOffProc KbdOff;
+ BellProc Bell;
+ SetLedsProc SetLeds;
+ GetLedsProc GetLeds;
+ SetKbdRepeatProc SetKbdRepeat;
+ KbdGetMappingProc KbdGetMapping;
+ RemapScanCodeProc RemapScanCode;
+ GetSpecialKeyProc GetSpecialKey;
+ SpecialKeyProc SpecialKey;
+
+ OpenKeyboardProc OpenKeyboard;
+ PostEventProc PostEvent;
+
+ int rate;
+ int delay;
+ int bell_pitch;
+ int bell_duration;
+ Bool autoRepeat;
+ unsigned long leds;
+ unsigned long xledsMask;
+ unsigned long keyLeds;
+ int scanPrefix;
+ Bool vtSwitchSupported;
+ Bool CustomKeycodes;
+ Bool noXkb;
+ Bool isConsole;
+ TransMapPtr scancodeMap;
+ TransMapPtr specialMap;
+
+ /* os specific */
+ pointer private;
+ int kbdType;
+ int consType;
+ int wsKbdType;
+ Bool sunKbd;
+ Bool Panix106;
+
+} KbdDevRec, *KbdDevPtr;
+
+typedef enum {
+ PROT_STD,
+ PROT_XQUEUE,
+ PROT_WSCONS,
+ PROT_USB,
+ PROT_UNKNOWN_KBD
+} KbdProtocolId;
+
+typedef struct {
+ const char *name;
+ KbdProtocolId id;
+} KbdProtocolRec;
+
+Bool xf86OSKbdPreInit(InputInfoPtr pInfo);
+
+/* Adjust this when the kbd interface changes. */
+
+/*
+ * History:
+ *
+ * 1.0.0 - Initial version.
+ */
+
+#define OS_KBD_VERSION_MAJOR 1
+#define OS_KBD_VERSION_MINOR 0
+#define OS_KBD_VERSION_PATCH 0
+
+#define OS_KBD_VERSION_CURRENT \
+ BUILTIN_INTERFACE_VERSION_NUMERIC(OS_KBD_VERSION_MAJOR, \
+ OS_KBD_VERSION_MINOR, \
+ OS_KBD_VERSION_PATCH)
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSmouse.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSmouse.h
new file mode 100644
index 000000000..9db1bac19
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSmouse.h
@@ -0,0 +1,295 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86OSmouse.h,v 1.24 2003/11/03 05:11:51 tsi Exp $ */
+/*
+ * Copyright (c) 1999-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).
+ */
+
+/* Public interface to OS-specific mouse support. */
+
+#ifndef _XF86OSMOUSE_H_
+#define _XF86OSMOUSE_H_
+
+#include "xf86Xinput.h"
+
+/* Mouse interface classes */
+#define MSE_NONE 0x00
+#define MSE_SERIAL 0x01 /* serial port */
+#define MSE_BUS 0x02 /* old bus mouse */
+#define MSE_PS2 0x04 /* standard read-only PS/2 */
+#define MSE_XPS2 0x08 /* extended PS/2 */
+#define MSE_AUTO 0x10 /* auto-detect (PnP) */
+#define MSE_MISC 0x20 /* The OS layer will identify the
+ * specific protocol names that are
+ * supported for this class. */
+
+/* Mouse Protocol IDs. */
+typedef enum {
+ PROT_UNKNOWN = -2,
+ PROT_UNSUP = -1, /* protocol is not supported */
+ PROT_MS = 0,
+ PROT_MSC,
+ PROT_MM,
+ PROT_LOGI,
+ PROT_LOGIMAN,
+ PROT_MMHIT,
+ PROT_GLIDE,
+ PROT_IMSERIAL,
+ PROT_THINKING,
+ PROT_ACECAD,
+ PROT_VALUMOUSESCROLL,
+ PROT_PS2,
+ PROT_GENPS2,
+ PROT_IMPS2,
+ PROT_EXPPS2,
+ PROT_THINKPS2,
+ PROT_MMPS2,
+ PROT_GLIDEPS2,
+ PROT_NETPS2,
+ PROT_NETSCPS2,
+ PROT_BM,
+ PROT_AUTO,
+ PROT_SYSMOUSE,
+ PROT_NUMPROTOS /* This must always be last. */
+} MouseProtocolID;
+
+struct _MouseDevRec;
+
+typedef int (*GetInterfaceTypesProc)(void);
+typedef const char **(*BuiltinNamesProc)(void);
+typedef Bool (*CheckProtocolProc)(const char *protocol);
+typedef Bool (*BuiltinPreInitProc)(InputInfoPtr pInfo, const char *protocol,
+ int flags);
+typedef const char *(*DefaultProtocolProc)(void);
+typedef const char *(*SetupAutoProc)(InputInfoPtr pInfo, int *protoPara);
+typedef void (*SetResProc)(InputInfoPtr pInfo, const char* protocol, int rate,
+ int res);
+typedef const char *(*FindDeviceProc)(InputInfoPtr pInfo, const char *protocol,
+ int flags);
+typedef const char *(*GuessProtocolProc)(InputInfoPtr pInfo, int flags);
+
+/*
+ * OSMouseInfoRec is used to pass information from the OSMouse layer to the
+ * OS-independent mouse driver.
+ */
+typedef struct {
+ GetInterfaceTypesProc SupportedInterfaces;
+ BuiltinNamesProc BuiltinNames;
+ CheckProtocolProc CheckProtocol;
+ BuiltinPreInitProc PreInit;
+ DefaultProtocolProc DefaultProtocol;
+ SetupAutoProc SetupAuto;
+ SetResProc SetPS2Res;
+ SetResProc SetBMRes;
+ SetResProc SetMiscRes;
+ FindDeviceProc FindDevice;
+ GuessProtocolProc GuessProtocol;
+} OSMouseInfoRec, *OSMouseInfoPtr;
+
+/*
+ * SupportedInterfaces: Returns the mouse interface types that the OS support.
+ * If MSE_MISC is returned, then the BuiltinNames and
+ * CheckProtocol should be set.
+ *
+ * BuiltinNames: Returns the names of the protocols that are fully handled
+ * in the OS-specific code. These are names that don't appear
+ * directly in the main "mouse" driver.
+ *
+ * CheckProtocol: Checks if the protocol name given is supported by the
+ * OS. It should return TRUE for both "builtin" protocols and
+ * protocols of type MSE_MISC that are supported by the OS.
+ *
+ * PreInit: The PreInit function for protocols that are builtin. This
+ * function is passed the protocol name.
+ *
+ * DefaultProtocol: Returns the name of a default protocol that should be used
+ * for the OS when none has been supplied in the config file.
+ * This should only be set when there is a reasonable default.
+ *
+ * SetupAuto: This function can be used to do OS-specific protocol
+ * auto-detection. It returns the name of the detected protocol,
+ * or NULL when detection fails. It may also adjust one or more
+ * of the "protoPara" values for the detected protocol by setting
+ * then to something other than -1. SetupAuto gets called in two
+ * ways. The first is before any devices have been opened. This
+ * can be used when the protocol "Auto" always maps to a single
+ * protocol type. The second is with the device open, allowing
+ * OS-specific probing to be done.
+ *
+ * SetPS2Res: Set the resolution and sample rate for MSE_PS2 and MSE_XPS2
+ * protocol types.
+ *
+ * SetBMRes: Set the resolution and sample rate for MSE_BM protocol types.
+ *
+ * SetMiscRes: Set the resolution and sample rate for MSE_MISC protocol types.
+ *
+ * FindDevice: This function gets called when no Device has been specified
+ * in the config file. OS-specific methods may be used to guess
+ * which input device to use. This function is called after the
+ * pre-open attempts at protocol discovery are done, but before
+ * the device is open. I.e., after the first SetupAuto() call,
+ * after the DefaultProtocol() call, but before the PreInit()
+ * call. Available protocol information may be used in locating
+ * the default input device.
+ *
+ * GuessProtocol: A last resort attempt at guessing the mouse protocol by
+ * whatever OS-specific means might be available. OS-independent
+ * things should be in the mouse driver. This function gets
+ * called after the mouse driver's OS-independent methods have
+ * failed.
+ */
+
+extern OSMouseInfoPtr xf86OSMouseInit(int flags);
+
+/* Adjust this when the mouse interface changes. */
+
+/*
+ * History:
+ *
+ * 1.0.0 - Everything up to when versioning was started.
+ * 1.1.0 - FindDevice and GuessProtocol added to OSMouseInfoRec
+ * 1.2.0 - xisbscale added to MouseDevRec
+ *
+ */
+
+#define OS_MOUSE_VERSION_MAJOR 1
+#define OS_MOUSE_VERSION_MINOR 2
+#define OS_MOUSE_VERSION_PATCH 0
+
+#define OS_MOUSE_VERSION_CURRENT \
+ BUILTIN_INTERFACE_VERSION_NUMERIC(OS_MOUSE_VERSION_MAJOR, \
+ OS_MOUSE_VERSION_MINOR, \
+ OS_MOUSE_VERSION_PATCH)
+
+#define HAVE_GUESS_PROTOCOL \
+ (xf86GetBuiltinInterfaceVersion(BUILTIN_IF_OSMOUSE, 0) >= \
+ BUILTIN_INTERFACE_VERSION_NUMERIC(1, 1, 0))
+
+#define HAVE_FIND_DEVICE \
+ (xf86GetBuiltinInterfaceVersion(BUILTIN_IF_OSMOUSE, 0) >= \
+ BUILTIN_INTERFACE_VERSION_NUMERIC(1, 1, 0))
+
+/* Z axis mapping */
+#define MSE_NOZMAP 0
+#define MSE_MAPTOX -1
+#define MSE_MAPTOY -2
+#define MSE_MAPTOZ -3
+#define MSE_MAPTOW -4
+
+/* Generalize for other axes. */
+#define MSE_NOAXISMAP MSE_NOZMAP
+
+#define MSE_MAXBUTTONS 24
+#define MSE_DFLTBUTTONS 3
+
+/*
+ * Mouse device record. This is shared by the mouse driver and the OSMouse
+ * layer.
+ */
+
+typedef void (*checkMovementsProc)(InputInfoPtr,int, int);
+typedef void (*autoProbeProc)(InputInfoPtr, Bool, Bool);
+typedef Bool (*collectDataProc)(struct _MouseDevRec *, unsigned char);
+typedef Bool (*dataGoodProc)(struct _MouseDevRec *);
+
+typedef void (*PostMseEventProc)(InputInfoPtr pInfo, int buttons,
+ int dx, int dy, int dz, int dw);
+typedef void (*MouseCommonOptProc)(InputInfoPtr pInfo);
+
+typedef struct _MouseDevRec {
+ PtrCtrlProcPtr Ctrl;
+ PostMseEventProc PostEvent;
+ MouseCommonOptProc CommonOptions;
+ DeviceIntPtr device;
+ const char * mseDevice;
+ const char * protocol;
+ MouseProtocolID protocolID;
+ MouseProtocolID oldProtocolID; /* hack */
+ int class;
+ int mseModel;
+ int baudRate;
+ int oldBaudRate;
+ int sampleRate;
+ int lastButtons;
+ int threshold; /* acceleration */
+ int num;
+ int den;
+ int buttons; /* # of buttons */
+ int emulateState; /* automata state for 2 button mode */
+ Bool emulate3Buttons;
+ Bool emulate3ButtonsSoft;
+ int emulate3Timeout;/* Timeout for 3 button emulation */
+ Bool chordMiddle;
+ Bool flipXY;
+ int invX;
+ int invY;
+ int mouseFlags; /* Flags to Clear after opening
+ * mouse dev */
+ int truebuttons; /* (not used)
+ * Arg to maintain before
+ * emulate3buttons timer callback */
+ int resolution;
+ int negativeZ; /* button mask */
+ int positiveZ; /* button mask */
+ int negativeW; /* button mask */
+ int positiveW; /* button mask */
+ pointer buffer; /* usually an XISBuffer* */
+ int protoBufTail;
+ unsigned char protoBuf[8];
+ unsigned char protoPara[8];
+ unsigned char inSync; /* driver in sync with datastream */
+ pointer mousePriv; /* private area */
+ InputInfoPtr pInfo;
+ int origProtocolID;
+ const char * origProtocol;
+ Bool emulate3Pending;/* timer waiting */
+ CARD32 emulate3Expires;/* time to fire emulation code */
+ Bool emulateWheel;
+ int wheelInertia;
+ int wheelButton;
+ int negativeX; /* Button values. Unlike the Z and */
+ int positiveX; /* W equivalents, these are button */
+ int negativeY; /* values rather than button masks. */
+ int positiveY;
+ int wheelYDistance;
+ int wheelXDistance;
+ Bool autoProbe;
+ checkMovementsProc checkMovements;
+ autoProbeProc autoProbeMouse;
+ collectDataProc collectData;
+ dataGoodProc dataGood;
+ int angleOffset;
+ pointer pDragLock; /* drag lock area */
+ int xisbscale; /* buffer size for 1 event */
+ int wheelButtonTimeout;/* Timeout for the wheel button emulation */
+ CARD32 wheelButtonExpires;
+ int doubleClickSourceButtonMask;
+ int doubleClickTargetButton;
+ int doubleClickTargetButtonMask;
+ int doubleClickOldSourceState;
+ int lastMappedButtons;
+ int buttonMap[MSE_MAXBUTTONS];
+} MouseDevRec, *MouseDevPtr;
+
+#endif /* _XF86OSMOUSE_H_ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSpriv.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSpriv.h
new file mode 100644
index 000000000..449e8ddd0
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86OSpriv.h
@@ -0,0 +1,57 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86OSpriv.h,v 1.6 2003/08/24 17:37:03 dawes Exp $ */
+/*
+ * Copyright (c) 1999-2000 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 _XF86OSPRIV_H
+#define _XF86OSPRIV_H
+
+typedef pointer (*MapMemProcPtr)(int, unsigned long, unsigned long, int);
+typedef void (*UnmapMemProcPtr)(int, pointer, unsigned long);
+typedef pointer (*SetWCProcPtr)(int, unsigned long, unsigned long, Bool,
+ MessageType);
+typedef void (*ProtectMemProcPtr)(int, pointer, unsigned long, Bool);
+typedef void (*UndoWCProcPtr)(int, pointer);
+typedef void (*ReadSideEffectsProcPtr)(int, pointer, unsigned long);
+
+typedef struct {
+ Bool initialised;
+ MapMemProcPtr mapMem;
+ UnmapMemProcPtr unmapMem;
+ ProtectMemProcPtr protectMem;
+ SetWCProcPtr setWC;
+ UndoWCProcPtr undoWC;
+ ReadSideEffectsProcPtr readSideEffects;
+ Bool linearSupported;
+} VidMemInfo, *VidMemInfoPtr;
+
+void xf86OSInitVidMem(VidMemInfoPtr);
+
+#endif /* _XF86OSPRIV_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_OSlib.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_OSlib.h
new file mode 100644
index 000000000..7e6e60b5b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_OSlib.h
@@ -0,0 +1,759 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86_OSlib.h,v 3.94 2003/11/03 05:11:51 tsi Exp $ */
+/*
+ * Copyright 1990, 1991 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1992 by David Dawes <dawes@XFree86.org>
+ * Copyright 1992 by Jim Tsillas <jtsilla@damon.ccs.northeastern.edu>
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1992 by Robert Baron <Robert.Baron@ernst.mach.cs.cmu.edu>
+ * Copyright 1992 by Orest Zborowski <obz@eskimo.com>
+ * Copyright 1993 by Vrije Universiteit, The Netherlands
+ * Copyright 1993 by David Wexelblat <dwex@XFree86.org>
+ * Copyright 1994, 1996 by Holger Veit <Holger.Veit@gmd.de>
+ * Copyright 1997 by Takis Psarogiannakopoulos <takis@dpmms.cam.ac.uk>
+ * Copyright 1994-2003 by The XFree86 Project, Inc
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of the above listed copyright holders
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. The above listed
+ * copyright holders make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THE ABOVE LISTED COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+ * The ARM32 code here carries the following copyright:
+ *
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ * This software is furnished under license and may be used and copied only in
+ * accordance with the following terms and conditions. Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * this software in source and/or binary form. No title or ownership is
+ * transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and retain
+ * this copyright notice and list of conditions as they appear in the
+ * source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of Digital
+ * Equipment Corporation. Neither the "Digital Equipment Corporation"
+ * name nor any trademark or logo of Digital Equipment Corporation may be
+ * used to endorse or promote products derived from this software without
+ * the prior written permission of Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied warranties,
+ * including but not limited to, any implied warranties of merchantability,
+ * fitness for a particular purpose, or non-infringement are disclaimed.
+ * In no event shall DIGITAL be liable for any damages whatsoever, and in
+ * particular, DIGITAL shall not be liable for special, indirect,
+ * consequential, or incidental damages or damages for lost profits, loss
+ * of revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise, even
+ * if advised of the possibility of such damage.
+ *
+ */
+
+/* $XConsortium: xf86_OSlib.h /main/22 1996/10/27 11:06:31 kaleb $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/xf86_OSlib.h,v 1.13 2005/11/08 06:33:29 jkj Exp $ */
+
+/*
+ * This is private, and should not be included by any drivers. Drivers
+ * may include xf86_OSproc.h to get prototypes for public interfaces.
+ */
+
+#ifndef _XF86_OSLIB_H
+#define _XF86_OSLIB_H
+
+#include <X11/Xos.h>
+#include <X11/Xfuncproto.h>
+
+/*
+ * Define some things from the "ANSI" C wrappers that are needed in the
+ * the core server.
+ */
+#ifndef HAVE_WRAPPER_DECLS
+#define HAVE_WRAPPER_DECLS
+#undef usleep
+#define usleep(a) xf86usleep(a)
+extern void xf86usleep(unsigned long);
+extern int xf86getpagesize(void);
+extern int xf86GetErrno(void);
+typedef unsigned long xf86size_t;
+typedef signed long xf86ssize_t;
+#endif
+
+#include <stdio.h>
+#include <ctype.h>
+#include <stddef.h>
+
+/**************************************************************************/
+/* SYSV386 (SVR3, SVR4), including Solaris */
+/**************************************************************************/
+#if (defined(SYSV) || defined(SVR4)) && \
+ !defined(DGUX) && !defined(sgi) && \
+ (defined(sun) || defined(i386))
+# ifdef SCO325
+# ifndef _SVID3
+# define _SVID3
+# endif
+# ifndef _NO_STATIC
+# define _NO_STATIC
+# endif
+# endif
+# include <sys/ioctl.h>
+# include <signal.h>
+# include <termio.h>
+# include <sys/stat.h>
+# include <sys/types.h>
+# if defined(__SCO__) || defined(ISC)
+# include <sys/param.h>
+# endif
+
+# ifdef ISC
+# define TIOCMSET (TIOC|26) /* set all modem bits */
+# define TIOCMBIS (TIOC|27) /* bis modem bits */
+# define TIOCMBIC (TIOC|28) /* bic modem bits */
+# define TIOCMGET (TIOC|29) /* get all modem bits */
+# endif
+
+# include <errno.h>
+
+# if defined(PowerMAX_OS)
+# define HAS_USL_VTS
+# include <sys/immu.h>
+# include <sys/sysmacros.h>
+# elif defined(_NEED_SYSI86)
+# include <sys/immu.h>
+# if !(defined (sun) && defined (SVR4))
+# include <sys/region.h>
+# endif
+# include <sys/proc.h>
+# include <sys/tss.h>
+# include <sys/sysi86.h>
+# if defined(SVR4) && !defined(sun)
+# include <sys/seg.h>
+# endif /* SVR4 && !sun */
+/* V86SC_IOPL was moved to <sys/sysi86.h> on Solaris 7 and later */
+# if defined(sun) && defined (SVR4) /* Solaris? */
+# if defined(i386) || defined(__x86) /* on x86 or x64? */
+# if !defined(V86SC_IOPL) /* Solaris 7 or later? */
+# include <sys/v86.h> /* Nope */
+# endif
+# endif /* V86SC_IOPL */
+# else
+# include <sys/v86.h> /* Not solaris */
+# endif /* sun && i386 && SVR4 */
+# if defined(sun) && (defined (i386) || defined(__x86)) && defined (SVR4)
+# include <sys/psw.h>
+# endif
+# endif /* _NEED_SYSI86 */
+
+# if defined(HAS_SVR3_MMAPDRV)
+# include <sys/sysmacros.h>
+# if !defined(_NEED_SYSI86)
+# include <sys/immu.h>
+# include <sys/region.h>
+# endif
+# include <sys/mmap.h> /* MMAP driver header */
+# endif
+
+# if !defined(sun) || (!defined(sparc) && !defined(__SOL8__))
+# define HAS_USL_VTS
+# endif
+# if !defined(sun)
+# include <sys/emap.h>
+# endif
+# if defined(SCO325)
+# include <sys/vtkd.h>
+# include <sys/console.h>
+# include <sys/scankbd.h>
+# include <sys/vid.h>
+# define LED_CAP CLKED
+# define LED_NUM NLKED
+# define LED_SCR SLKED
+# elif defined(HAS_USL_VTS)
+# include <sys/at_ansi.h>
+# include <sys/kd.h>
+# include <sys/vt.h>
+# elif defined(sun)
+# include <sys/fbio.h>
+# include <sys/kbd.h>
+# include <sys/kbio.h>
+
+/* undefine symbols from <sys/kbd.h> we don't need that conflict with enum
+ definitions in parser/xf86tokens.h */
+# undef STRING
+# undef LEFTALT
+# undef RIGHTALT
+
+# define LED_CAP LED_CAPS_LOCK
+# define LED_NUM LED_NUM_LOCK
+# define LED_SCR LED_SCROLL_LOCK
+# define LED_COMP LED_COMPOSE
+# endif /* sun */
+
+# if !defined(VT_ACKACQ)
+# define VT_ACKACQ 2
+# endif /* !VT_ACKACQ */
+
+# if defined(__SCO__)
+# include <sys/sysmacros.h>
+# define POSIX_TTY
+# endif /* __SCO__ */
+
+# if defined(SVR4) || defined(SCO325)
+# include <sys/mman.h>
+# if !(defined(sun) && defined (SVR4))
+# define DEV_MEM "/dev/pmem"
+# elif defined(PowerMAX_OS)
+# define DEV_MEM "/dev/iomem"
+# endif
+# ifdef SCO325
+# undef DEV_MEM
+# define DEV_MEM "/dev/mem"
+# endif
+# define CLEARDTR_SUPPORT
+# define POSIX_TTY
+# endif /* SVR4 */
+
+# ifdef ISC
+# include <termios.h>
+# define POSIX_TTY
+# endif
+
+# if defined(sun) && defined (i386) && defined (SVR4) && !defined(__SOL8__)
+# define USE_VT_SYSREQ
+# define VT_SYSREQ_DEFAULT TRUE
+# endif
+
+# if defined(ATT) && !defined(i386)
+# define i386 /* not defined in ANSI C mode */
+# endif /* ATT && !i386 */
+
+# if (defined(ATT) || defined(SVR4)) && !defined(sun)
+# ifndef __UNIXWARE__
+# ifndef XQUEUE
+# define XQUEUE
+# endif
+# endif
+# include <sys/xque.h>
+# endif /* ATT || SVR4 */
+
+# ifdef SYSV
+# if !defined(ISC) || defined(ISC202) || defined(ISC22)
+# define NEED_STRERROR
+# endif
+# endif
+
+#endif /* (SYSV || SVR4) && !DGUX */
+
+
+
+/**************************************************************************/
+/* DG/ux R4.20MU03 Intel AViion Machines */
+/**************************************************************************/
+#if defined(DGUX) && defined(SVR4)
+#include <sys/ioctl.h>
+#include <signal.h>
+#include <ctype.h>
+#include <termios.h> /* Use termios for BSD Flavor ttys */
+#include <sys/termios.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <errno.h>
+#include <sys/sysi86.h>
+#include <unistd.h>
+#include <sys/proc.h>
+#include <sys/map.h>
+#include <sys/sysmacros.h>
+#include <sys/mman.h> /* Memory handling */
+#include <sys/kd.h> /* definitios for KDENABIO KDDISABIO needed for IOPL s */
+#include <sys/kbd.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/stream.h>
+#include <sys/ptms.h>
+
+#include <sys/socket.h>
+#include <sys/utsname.h>
+#include <sys/stropts.h>
+#include <sys/sockio.h>
+
+
+#define POSIX_TTY
+
+#undef HAS_USL_VTS
+#undef USE_VT_SYSREQ
+#undef VT_ACKACQ
+
+#define LED_CAP KBD_LED_CAPS_LOCK
+#define LED_NUM KBD_LED_NUM_LOCK
+#define LED_SCR KBD_LED_SCROLL_LOCK
+
+#define KDGKBTYPE KBD_GET_LANGUAGE
+
+
+/* General keyboard types */
+# define KB_84 2
+# define KB_101 1 /* Because ioctl(dgkeybdFd,KBD_GET_LANGUAGE,&type) gives 1=US keyboard */
+# define KB_OTHER 3
+
+#define KDSETLED KBD_SET_LED
+#define KDGETLED KBD_GET_STATE
+#undef KDMKTONE
+#define KDMKTONE KBD_TONE_HIGH
+
+
+#undef DEV_MEM
+#define DEV_MEM "/dev/mem"
+#define CLEARDTR_SUPPORT
+
+#undef VT_SYSREQ_DEFAULT
+#define VT_SYSREQ_DEFAULT FALSE /* Make sure that we dont define any VTs since DG/ux has none */
+
+#endif /* DGUX && SVR4 */
+
+/**************************************************************************/
+/* Linux or Glibc-based system */
+/**************************************************************************/
+#if defined(__linux__) || defined(__GLIBC__)
+# include <sys/ioctl.h>
+# include <signal.h>
+# include <stdlib.h>
+# include <sys/types.h>
+# include <assert.h>
+
+#ifdef __GNU__ /* GNU/Hurd */
+# define USE_OSMOUSE
+#endif
+
+# ifdef __linux__
+# include <termio.h>
+# else /* __GLIBC__ */
+# include <termios.h>
+# endif
+# ifdef __sparc__
+# include <sys/param.h>
+# endif
+
+# include <errno.h>
+
+# include <sys/stat.h>
+
+# include <sys/mman.h>
+# ifdef __linux__
+# define HAS_USL_VTS
+# include <sys/kd.h>
+# include <sys/vt.h>
+# define LDGMAP GIO_SCRNMAP
+# define LDSMAP PIO_SCRNMAP
+# define LDNMAP LDSMAP
+# define CLEARDTR_SUPPORT
+# define USE_VT_SYSREQ
+# endif
+
+# define POSIX_TTY
+
+#endif /* __linux__ || __GLIBC__ */
+
+/**************************************************************************/
+/* LynxOS AT */
+/**************************************************************************/
+#if defined(Lynx)
+
+# include <termio.h>
+# include <sys/ioctl.h>
+# include <param.h>
+# include <signal.h>
+# include <kd.h>
+# include <vt.h>
+# include <sys/stat.h>
+
+# include <errno.h>
+extern int errno;
+
+/* smem_create et.al. to access physical memory */
+# include <smem.h>
+
+/* keyboard types */
+# define KB_84 1
+# define KB_101 2
+# define KB_OTHER 3
+
+/* atc drivers ignores argument to VT_RELDISP ioctl */
+# define VT_ACKACQ 2
+
+# include <termios.h>
+# define POSIX_TTY
+# define CLEARDTR_SUPPORT
+
+/* LynxOS 2.5.1 has these */
+# ifdef LED_NUMLOCK
+# define LED_CAP LED_CAPSLOCK
+# define LED_NUM LED_NUMLOCK
+# define LED_SCR LED_SCROLLOCK
+# endif
+
+#endif /* Lynx */
+
+/**************************************************************************/
+/* 386BSD and derivatives, BSD/386 */
+/**************************************************************************/
+
+#if defined(__386BSD__) && (defined(__FreeBSD__) || defined(__NetBSD__))
+# undef __386BSD__
+#endif
+
+#ifdef CSRG_BASED
+# include <sys/ioctl.h>
+# include <signal.h>
+
+# include <termios.h>
+# define termio termios
+# define POSIX_TTY
+
+# include <errno.h>
+
+# include <sys/types.h>
+# include <sys/mman.h>
+# include <sys/stat.h>
+
+# if defined(__bsdi__)
+# include <sys/param.h>
+# if (_BSDI_VERSION < 199510)
+# include <i386/isa/vgaioctl.h>
+# endif
+# endif /* __bsdi__ */
+
+#endif /* CSRG_BASED */
+
+/**************************************************************************/
+/* Kernel of *BSD */
+/**************************************************************************/
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
+ defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__)
+
+# include <sys/param.h>
+# if defined(__FreeBSD_version) && !defined(__FreeBSD_kernel_version)
+# define __FreeBSD_kernel_version __FreeBSD_version
+# endif
+
+# if !defined(LINKKIT)
+ /* Don't need this stuff for the Link Kit */
+# if defined(__bsdi__)
+# include <i386/isa/pcconsioctl.h>
+# define CONSOLE_X_MODE_ON PCCONIOCRAW
+# define CONSOLE_X_MODE_OFF PCCONIOCCOOK
+# define CONSOLE_X_BELL PCCONIOCBEEP
+# else /* __bsdi__ */
+# if defined(__OpenBSD__)
+# ifdef PCCONS_SUPPORT
+# include <machine/pccons.h>
+# undef CONSOLE_X_MODE_ON
+# undef CONSOLE_X_MODE_OFF
+# undef CONSOLE_X_BELL
+# endif
+# endif
+# ifdef SYSCONS_SUPPORT
+# define COMPAT_SYSCONS
+# if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+# include <machine/console.h>
+# else
+# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+# if (__FreeBSD_kernel_version >= 410000)
+# include <sys/consio.h>
+# include <sys/kbio.h>
+# else
+# include <machine/console.h>
+# endif /* FreeBSD 4.1 RELEASE or lator */
+# else
+# include <sys/console.h>
+# endif
+# endif
+# endif /* SYSCONS_SUPPORT */
+# if defined(PCVT_SUPPORT)
+# if !defined(SYSCONS_SUPPORT)
+ /* no syscons, so include pcvt specific header file */
+# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
+# include <machine/pcvt_ioctl.h>
+# else
+# if defined(__NetBSD__) || defined(__OpenBSD__)
+# if !defined(WSCONS_SUPPORT)
+# include <machine/pcvt_ioctl.h>
+# endif /* WSCONS_SUPPORT */
+# else
+# include <sys/pcvt_ioctl.h>
+# endif /* __NetBSD__ */
+# endif /* __FreeBSD_kernel__ || __OpenBSD__ */
+# else /* pcvt and syscons: hard-code the ID magic */
+# define VGAPCVTID _IOWR('V',113, struct pcvtid)
+ struct pcvtid {
+ char name[16];
+ int rmajor, rminor;
+ };
+# endif /* PCVT_SUPPORT && SYSCONS_SUPPORT */
+# endif /* PCVT_SUPPORT */
+# ifdef WSCONS_SUPPORT
+# include <dev/wscons/wsconsio.h>
+# include <dev/wscons/wsdisplay_usl_io.h>
+# endif /* WSCONS_SUPPORT */
+# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+# if (__FreeBSD_kernel_version >= 500013)
+# include <sys/mouse.h>
+# else
+# undef MOUSE_GETINFO
+# include <machine/mouse.h>
+# endif
+# endif
+ /* Include these definitions in case ioctl_pc.h didn't get included */
+# ifndef CONSOLE_X_MODE_ON
+# define CONSOLE_X_MODE_ON _IO('t',121)
+# endif
+# ifndef CONSOLE_X_MODE_OFF
+# define CONSOLE_X_MODE_OFF _IO('t',122)
+# endif
+# ifndef CONSOLE_X_BELL
+# define CONSOLE_X_BELL _IOW('t',123,int[2])
+# endif
+# ifndef CONSOLE_X_TV_ON
+# define CONSOLE_X_TV_ON _IOW('t',155,int)
+# define XMODE_RGB 0
+# define XMODE_NTSC 1
+# define XMODE_PAL 2
+# define XMODE_SECAM 3
+# endif
+# ifndef CONSOLE_X_TV_OFF
+# define CONSOLE_X_TV_OFF _IO('t',156)
+# endif
+#ifndef CONSOLE_GET_LINEAR_INFO
+# define CONSOLE_GET_LINEAR_INFO _IOR('t',157,struct map_info)
+#endif
+#ifndef CONSOLE_GET_IO_INFO
+# define CONSOLE_GET_IO_INFO _IOR('t',158,struct map_info)
+#endif
+#ifndef CONSOLE_GET_MEM_INFO
+# define CONSOLE_GET_MEM_INFO _IOR('t',159,struct map_info)
+#endif
+# endif /* __bsdi__ */
+# endif /* !LINKKIT */
+
+#if defined(USE_I386_IOPL) || defined(USE_AMD64_IOPL)
+#include <machine/sysarch.h>
+#endif
+
+# define CLEARDTR_SUPPORT
+
+# if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT)
+# define USE_VT_SYSREQ
+# endif
+
+#endif
+/* __FreeBSD_kernel__ || __NetBSD__ || __OpenBSD__ || __bsdi__ */
+
+/**************************************************************************/
+/* OS/2 */
+/**************************************************************************/
+/* currently OS/2 with a modified EMX/GCC compiler only */
+#if defined(__UNIXOS2__)
+# include <signal.h>
+# include <errno.h>
+# include <sys/stat.h>
+
+/* I would have liked to have this included here always, but
+ * it causes clashes for BYTE and BOOL with Xmd.h, which is too dangerous.
+ * So I'll include it in place where I know it does no harm.
+ */
+#if defined(I_NEED_OS2_H)
+# undef BOOL
+# undef BYTE
+# include <os2.h>
+#endif
+
+ /* keyboard types */
+# define KB_84 1
+# define KB_101 2
+/* could detect more keyboards */
+# define KB_OTHER 3
+
+ /* LEDs */
+# define LED_CAP 0x40
+# define LED_NUM 0x20
+# define LED_SCR 0x10
+
+ /* mouse driver */
+# define OSMOUSE_ONLY
+# define MOUSE_PROTOCOL_IN_KERNEL
+
+extern char* __XOS2RedirRoot(char*);
+
+#endif
+
+/**************************************************************************/
+/* QNX4 */
+/**************************************************************************/
+/* This is the QNX code for Watcom 10.6 and QNX 4.x */
+#if defined(QNX4)
+#include <signal.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <termios.h>
+#include <ioctl.h>
+#include <sys/param.h>
+
+/* Warning: by default, the fd_set size is 32 in QNX! */
+#define FD_SETSIZE 256
+#include <sys/select.h>
+
+ /* keyboard types */
+# define KB_84 1
+# define KB_101 2
+# define KB_OTHER 3
+
+ /* LEDs */
+# define LED_CAP 0x04
+# define LED_NUM 0x02
+# define LED_SCR 0x01
+
+# define POSIX_TTY
+# define OSMOUSE_ONLY
+# define MOUSE_PROTOCOL_IN_KERNEL
+
+#define TIOCM_DTR 0x0001 /* data terminal ready */
+#define TIOCM_RTS 0x0002 /* request to send */
+#define TIOCM_CTS 0x1000 /* clear to send */
+#define TIOCM_DSR 0x2000 /* data set ready */
+#define TIOCM_RI 0x4000 /* ring */
+#define TIOCM_RNG TIOCM_RI
+#define TIOCM_CD 0x8000 /* carrier detect */
+#define TIOCM_CAR TIOCM_CD
+#define TIOCM_LE 0x0100 /* line enable */
+#define TIOCM_ST 0x0200 /* secondary transmit */
+#define TIOCM_SR 0x0400 /* secondary receive */
+
+#endif
+
+/**************************************************************************/
+/* QNX/Neutrino */
+/**************************************************************************/
+/* This is the Neutrino code for for NTO2.0 and GCC */
+#if defined(__QNXNTO__)
+#include <signal.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <termios.h>
+#include <ioctl.h>
+#include <sys/param.h>
+
+/* Warning: by default, the fd_set size is 32 in NTO! */
+#define FD_SETSIZE 256
+#include <sys/select.h>
+
+ /* keyboard types */
+# define KB_84 1
+# define KB_101 2
+# define KB_OTHER 3
+
+# define POSIX_TTY
+
+#endif
+
+/**************************************************************************/
+/* IRIX */
+/**************************************************************************/
+#if defined(sgi)
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#endif
+
+/**************************************************************************/
+/* Generic */
+/**************************************************************************/
+
+#include <sys/wait.h> /* May need to adjust this for other OSs */
+
+/*
+ * Hack originally for ISC 2.2 POSIX headers, but may apply elsewhere,
+ * and it's safe, so just do it.
+ */
+#if !defined(O_NDELAY) && defined(O_NONBLOCK)
+# define O_NDELAY O_NONBLOCK
+#endif /* !O_NDELAY && O_NONBLOCK */
+
+#if !defined(MAXHOSTNAMELEN)
+# define MAXHOSTNAMELEN 32
+#endif /* !MAXHOSTNAMELEN */
+
+#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 */
+
+#ifdef NEED_STRERROR
+# ifndef strerror
+extern char *sys_errlist[];
+extern int sys_nerr;
+# define strerror(n) \
+ ((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error"
+# endif /* !strerror */
+#endif /* NEED_STRERROR */
+
+#if defined(ISC) || defined(Lynx)
+#define rint(x) RInt(x)
+double RInt(
+ double x
+);
+#endif
+
+#ifndef DEV_MEM
+#define DEV_MEM "/dev/mem"
+#endif
+
+#ifndef VT_SYSREQ_DEFAULT
+#define VT_SYSREQ_DEFAULT FALSE
+#endif
+
+#ifdef OSMOUSE_ONLY
+# ifndef MOUSE_PROTOCOL_IN_KERNEL
+# define MOUSE_PROTOCOL_IN_KERNEL
+# endif
+#endif
+
+#define SYSCALL(call) while(((call) == -1) && (errno == EINTR))
+
+#define XF86_OS_PRIVS
+#include "xf86_OSproc.h"
+
+#ifndef NO_COMPILER_H
+#include "compiler.h"
+#endif
+
+#endif /* _XF86_OSLIB_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h
new file mode 100644
index 000000000..83ce9ed2b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h
@@ -0,0 +1,277 @@
+/*
+ * Copyright 1990, 1991 by Thomas Roell, Dinkelscherben, Germany
+ * Copyright 1992 by David Dawes <dawes@XFree86.org>
+ * Copyright 1992 by Jim Tsillas <jtsilla@damon.ccs.northeastern.edu>
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1992 by Robert Baron <Robert.Baron@ernst.mach.cs.cmu.edu>
+ * Copyright 1992 by Orest Zborowski <obz@eskimo.com>
+ * Copyright 1993 by Vrije Universiteit, The Netherlands
+ * Copyright 1993 by David Wexelblat <dwex@XFree86.org>
+ * Copyright 1994, 1996 by Holger Veit <Holger.Veit@gmd.de>
+ * Copyright 1994-2003 by The XFree86 Project, Inc
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of the above listed copyright holders
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. The above listed
+ * copyright holders make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THE ABOVE LISTED COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+ * The ARM32 code here carries the following copyright:
+ *
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ * This software is furnished under license and may be used and copied only in
+ * accordance with the following terms and conditions. Subject to these
+ * conditions, you may download, copy, install, use, modify and distribute
+ * this software in source and/or binary form. No title or ownership is
+ * transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce and retain
+ * this copyright notice and list of conditions as they appear in the
+ * source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of Digital
+ * Equipment Corporation. Neither the "Digital Equipment Corporation"
+ * name nor any trademark or logo of Digital Equipment Corporation may be
+ * used to endorse or promote products derived from this software without
+ * the prior written permission of Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied warranties,
+ * including but not limited to, any implied warranties of merchantability,
+ * fitness for a particular purpose, or non-infringement are disclaimed.
+ * In no event shall DIGITAL be liable for any damages whatsoever, and in
+ * particular, DIGITAL shall not be liable for special, indirect,
+ * consequential, or incidental damages or damages for lost profits, loss
+ * of revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise, even
+ * if advised of the possibility of such damage.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86_OSproc.h,v 3.56 2003/08/24 17:37:03 dawes Exp $ */
+
+#ifndef _XF86_OSPROC_H
+#define _XF86_OSPROC_H
+
+#ifdef XF86_OS_PRIVS
+#include "xf86Pci.h"
+#endif
+
+/*
+ * The actual prototypes have been pulled into this seperate file so
+ * that they can can be used without pulling in all of the OS specific
+ * stuff like sys/stat.h, etc. This casues problem for loadable modules.
+ */
+
+/*
+ * Flags for xf86MapVidMem(). Multiple flags can be or'd together. The
+ * flags may be used as hints. For example it would be permissible to
+ * enable write combining for memory marked only for framebuffer use.
+ */
+
+#define VIDMEM_FRAMEBUFFER 0x01 /* memory for framebuffer use */
+#define VIDMEM_MMIO 0x02 /* memory for I/O use */
+#define VIDMEM_MMIO_32BIT 0x04 /* memory accesses >= 32bit */
+#define VIDMEM_READSIDEEFFECT 0x08 /* reads can have side-effects */
+#define VIDMEM_SPARSE 0x10 /* sparse mapping required
+ * assumed when VIDMEM_MMIO is
+ * set. May be used with
+ * VIDMEM_FRAMEBUFFER) */
+#define VIDMEM_READONLY 0x20 /* read-only mapping
+ * used when reading BIOS images
+ * through xf86MapVidMem() */
+
+/*
+ * OS-independent modem state flags for xf86SetSerialModemState() and
+ * xf86GetSerialModemState().
+ */
+#define XF86_M_LE 0x001 /* line enable */
+#define XF86_M_DTR 0x002 /* data terminal ready */
+#define XF86_M_RTS 0x004 /* request to send */
+#define XF86_M_ST 0x008 /* secondary transmit */
+#define XF86_M_SR 0x010 /* secondary receive */
+#define XF86_M_CTS 0x020 /* clear to send */
+#define XF86_M_CAR 0x040 /* carrier detect */
+#define XF86_M_RNG 0x080 /* ring */
+#define XF86_M_DSR 0x100 /* data set ready */
+
+#ifdef XF86_OS_PRIVS
+extern void xf86WrapperInit(void);
+#endif
+
+#ifndef NO_OSLIB_PROTOTYPES
+/*
+ * This is to prevent re-entrancy to FatalError() when aborting.
+ * Anything that can be called as a result of AbortDDX() should use this
+ * instead of FatalError().
+ */
+
+#define xf86FatalError(a, b) \
+ if (dispatchException & DE_TERMINATE) { \
+ ErrorF(a, b); \
+ ErrorF("\n"); \
+ return; \
+ } else FatalError(a, b)
+
+/***************************************************************************/
+/* Prototypes */
+/***************************************************************************/
+
+#include <X11/Xfuncproto.h>
+#include "opaque.h"
+
+#if defined(XQUEUE)
+#include "input.h" /* for DeviceIntPtr */
+#endif
+
+_XFUNCPROTOBEGIN
+
+/* public functions */
+extern Bool xf86LinearVidMem(void);
+extern Bool xf86CheckMTRR(int);
+extern pointer xf86MapVidMem(int, int, unsigned long, unsigned long);
+extern void xf86UnMapVidMem(int, pointer, unsigned long);
+extern void xf86MapReadSideEffects(int, int, pointer, unsigned long);
+extern int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *, int);
+extern Bool xf86EnableIO(void);
+extern void xf86DisableIO(void);
+extern Bool xf86DisableInterrupts(void);
+extern void xf86EnableInterrupts(void);
+extern void xf86SetTVOut(int);
+extern void xf86SetRGBOut(void);
+extern void xf86SoundKbdBell(int, int, int);
+#if defined(QNX4)
+#pragma aux xf86BusToMem modify [eax ebx ecx edx esi edi];
+#pragma aux xf86MemToBus modify [eax ebx ecx edx esi edi];
+#endif
+extern void xf86BusToMem(unsigned char *, unsigned char *, int);
+extern void xf86MemToBus(unsigned char *, unsigned char *, int);
+extern void xf86IODelay(void);
+extern void xf86UDelay(long usec);
+extern void xf86SlowBcopy(unsigned char *, unsigned char *, int);
+extern int xf86OpenSerial(pointer options);
+extern int xf86SetSerial(int fd, pointer options);
+extern int xf86SetSerialSpeed(int fd, int speed);
+extern int xf86ReadSerial(int fd, void *buf, int count);
+extern int xf86WriteSerial(int fd, const void *buf, int count);
+extern int xf86CloseSerial(int fd);
+extern int xf86FlushInput(int fd);
+extern int xf86WaitForInput(int fd, int timeout);
+extern int xf86SerialSendBreak(int fd, int duration);
+extern int xf86SetSerialModemState(int fd, int state);
+extern int xf86GetSerialModemState(int fd);
+extern int xf86SerialModemSetBits(int fd, int bits);
+extern int xf86SerialModemClearBits(int fd, int bits);
+extern int xf86LoadKernelModule(const char *pathname);
+
+/* AGP GART interface */
+
+typedef struct _AgpInfo {
+ CARD32 bridgeId;
+ CARD32 agpMode;
+ unsigned long base;
+ unsigned long size;
+ unsigned long totalPages;
+ unsigned long systemPages;
+ unsigned long usedPages;
+} AgpInfo, *AgpInfoPtr;
+
+extern Bool xf86AgpGARTSupported(void);
+extern AgpInfoPtr xf86GetAGPInfo(int screenNum);
+extern Bool xf86AcquireGART(int screenNum);
+extern Bool xf86ReleaseGART(int screenNum);
+extern int xf86AllocateGARTMemory(int screenNum, unsigned long size, int type,
+ unsigned long *physical);
+extern Bool xf86DeallocateGARTMemory(int screenNum, int key);
+extern Bool xf86BindGARTMemory(int screenNum, int key, unsigned long offset);
+extern Bool xf86UnbindGARTMemory(int screenNum, int key);
+extern Bool xf86EnableAGP(int screenNum, CARD32 mode);
+extern Bool xf86GARTCloseScreen(int screenNum);
+
+/* These routines are in shared/sigio.c and are not loaded as part of the
+ module. These routines are small, and the code if very POSIX-signal (or
+ OS-signal) specific, so it seemed better to provide more complex
+ wrappers than to wrap each individual function called. */
+extern int xf86InstallSIGIOHandler(int fd, void (*f)(int, void *), void *);
+extern int xf86RemoveSIGIOHandler(int fd);
+extern int xf86BlockSIGIO (void);
+extern void xf86UnblockSIGIO (int);
+#ifdef XFree86Server
+extern void xf86AssertBlockedSIGIO (char *);
+#endif
+extern Bool xf86SIGIOSupported (void);
+
+#ifdef XF86_OS_PRIVS
+typedef void (*PMClose)(void);
+extern void xf86OpenConsole(void);
+extern void xf86CloseConsole(void);
+extern Bool xf86VTSwitchPending(void);
+extern Bool xf86VTSwitchAway(void);
+extern Bool xf86VTSwitchTo(void);
+extern void xf86VTRequest(int sig);
+extern int xf86ProcessArgument(int, char **, int);
+extern void xf86UseMsg(void);
+extern void xf86SetKbdLeds(int);
+extern int xf86GetKbdLeds(void);
+extern void xf86SetKbdRepeat(char);
+extern void xf86KbdInit(void);
+extern int xf86KbdOn(void);
+extern int xf86KbdOff(void);
+extern void xf86KbdEvents(void);
+#ifdef XQUEUE
+extern int xf86XqueKbdProc(DeviceIntPtr, int);
+extern void xf86XqueEvents(void);
+#endif
+extern void xf86ReloadInputDevs(int sig);
+#ifdef WSCONS_SUPPORT
+extern void xf86WSKbdEvents(void);
+#endif
+extern PMClose xf86OSPMOpen(void);
+
+#ifdef NEED_OS_RAC_PROTOS
+/* RAC-related privs */
+/* internal to os-support layer */
+resPtr xf86StdBusAccWindowsFromOS(void);
+resPtr xf86StdPciAccWindowsFromOS(void);
+resPtr xf86StdIsaAccWindowsFromOS(void);
+resPtr xf86StdAccResFromOS(resPtr ret);
+
+/* available to the common layer */
+resPtr xf86BusAccWindowsFromOS(void);
+resPtr xf86PciBusAccWindowsFromOS(void);
+#ifdef INCLUDE_UNUSED
+resPtr xf86IsaBusAccWindowsFromOS(void);
+#endif
+resPtr xf86AccResFromOS(resPtr ret);
+#endif /* NEED_OS_RAC_PROTOS */
+
+extern Bool xf86GetPciSizeFromOS(PCITAG tag, int indx, int* bits);
+extern Bool xf86GetPciOffsetFromOS(PCITAG tag, int indx, unsigned long* bases);
+extern unsigned long xf86GetOSOffsetFromPCI(PCITAG tag, int space, unsigned long base);
+
+extern void xf86MakeNewMapping(int, int, unsigned long, unsigned long, pointer);
+extern void xf86InitVidMem(void);
+
+#endif /* XF86_OS_PRIVS */
+
+
+_XFUNCPROTOEND
+#endif /* NO_OSLIB_PROTOTYPES */
+
+#endif /* _XF86_OSPROC_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h
new file mode 100644
index 000000000..c4090dc16
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h
@@ -0,0 +1,354 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86_ansic.h,v 3.53 2003/10/28 18:36:37 tsi Exp $ */
+/*
+ * Copyright 1997-2003 by The XFree86 Project, Inc
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of the above listed copyright holders
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. The above listed
+ * copyright holders make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * THE ABOVE LISTED COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifndef _XF86_ANSIC_H
+#define _XF86_ANSIC_H
+
+/* Handle <stdarg.h> */
+
+#ifndef IN_MODULE
+# include <stdarg.h>
+#else /* !IN_MODULE */
+# ifndef __OS2ELF__
+# include <stdarg.h>
+# else /* __OS2ELF__ */
+ /* EMX/gcc_elf under OS/2 does not have native header files */
+# if !defined (_VA_LIST)
+# define _VA_LIST
+ typedef char *va_list;
+# endif
+# define _VA_ROUND(t) ((sizeof (t) + 3) & -4)
+# if !defined (va_start)
+# define va_start(ap,v) ap = (va_list)&v + ((sizeof (v) + 3) & -4)
+# define va_end(ap) (ap = 0, (void)0)
+# define va_arg(ap,t) (ap += _VA_ROUND (t), *(t *)(ap - _VA_ROUND (t)))
+# endif
+# endif /* __OS2ELF__ */
+#endif /* IN_MODULE */
+
+/*
+ * The first set of definitions are required both for modules and
+ * libc_wrapper.c.
+ */
+
+#if defined(XFree86LOADER) || defined(NEED_XF86_TYPES)
+
+#if !defined(SYSV) && !defined(SVR4) && !defined(Lynx) || \
+ defined(__SCO__) || defined(__UNIXWARE__)
+#define HAVE_VSSCANF
+#define HAVE_VFSCANF
+#endif
+
+#ifndef NULL
+#if (defined(SVR4) || defined(SYSV)) && !defined(__GNUC__)
+#define NULL 0
+#else
+#define NULL ((void *)0)
+#endif
+#endif
+#ifndef EOF
+#define EOF (-1)
+#endif
+
+#ifndef PATH_MAX
+#define PATH_MAX 1024
+#endif
+
+/* <limits.h> stuff */
+#define x_BITSPERBYTE 8
+#define x_BITS(type) (x_BITSPERBYTE * (int)sizeof(type))
+#define x_SHORTBITS x_BITS(short)
+#define x_INTBITS x_BITS(int)
+#define x_LONGBITS x_BITS(long)
+#ifndef SHRT_MIN
+#define SHRT_MIN ((short)(1 << (x_SHORTBITS - 1)))
+#endif
+
+#ifndef FONTMODULE
+#include "misc.h"
+#endif
+#include "xf86_libc.h"
+#ifndef SHRT_MAX
+#define SHRT_MAX ((short)~SHRT_MIN)
+#endif
+#ifndef USHRT_MAX
+#define USHRT_MAX ((unsigned short)~0)
+#endif
+#ifndef MINSHORT
+#define MINSHORT SHRT_MIN
+#endif
+#ifndef MAXSHORT
+#define MAXSHORT SHRT_MAX
+#endif
+#ifndef INT_MIN
+#define INT_MIN (1 << (x_INTBITS - 1))
+#endif
+#ifndef INT_MAX
+#define INT_MAX (~INT_MIN)
+#endif
+#ifndef UINT_MAX
+#define UINT_MAX (~0)
+#endif
+#ifndef MININT
+#define MININT INT_MIN
+#endif
+#ifndef MAXINT
+#define MAXINT INT_MAX
+#endif
+#ifndef LONG_MIN
+#define LONG_MIN ((long)(1 << (x_LONGBITS - 1)))
+#endif
+#ifndef LONG_MAX
+#define LONG_MAX ((long)~LONG_MIN)
+#endif
+#ifndef ULONG_MAX
+#define ULONG_MAX ((unsigned long)~0UL)
+#endif
+#ifndef MINLONG
+#define MINLONG LONG_MIN
+#endif
+#ifndef MAXLONG
+#define MAXLONG LONG_MAX
+#endif
+
+#endif /* XFree86LOADER || NEED_XF86_TYPES */
+
+#if defined(XFree86LOADER) || defined(NEED_XF86_PROTOTYPES)
+/*
+ * ANSI C compilers only.
+ */
+
+/* ANSI C emulation library */
+
+extern void xf86abort(void);
+extern int xf86abs(int);
+extern double xf86acos(double);
+extern double xf86asin(double);
+extern double xf86atan(double);
+extern double xf86atan2(double,double);
+extern double xf86atof(const char*);
+extern int xf86atoi(const char*);
+extern long xf86atol(const char*);
+extern void *xf86bsearch(const void *, const void *, xf86size_t, xf86size_t,
+ int (*)(const void *, const void *));
+extern double xf86ceil(double);
+extern void* xf86calloc(xf86size_t,xf86size_t);
+extern void xf86clearerr(XF86FILE*);
+extern double xf86cos(double);
+extern void xf86exit(int);
+extern double xf86exp(double);
+extern double xf86fabs(double);
+extern int xf86fclose(XF86FILE*);
+extern int xf86feof(XF86FILE*);
+extern int xf86ferror(XF86FILE*);
+extern int xf86fflush(XF86FILE*);
+extern int xf86fgetc(XF86FILE*);
+extern int xf86getc(XF86FILE*);
+extern int xf86fgetpos(XF86FILE*,XF86fpos_t*);
+extern char* xf86fgets(char*,INT32,XF86FILE*);
+extern int xf86finite(double);
+extern double xf86floor(double);
+extern double xf86fmod(double,double);
+extern XF86FILE* xf86fopen(const char*,const char*);
+extern double xf86frexp(double, int*);
+extern int xf86printf(const char*,...);
+extern int xf86fprintf(XF86FILE*,const char*,...);
+extern int xf86fputc(int,XF86FILE*);
+extern int xf86fputs(const char*,XF86FILE*);
+extern xf86size_t xf86fread(void*,xf86size_t,xf86size_t,XF86FILE*);
+extern void xf86free(void*);
+extern XF86FILE* xf86freopen(const char*,const char*,XF86FILE*);
+#if defined(HAVE_VFSCANF) || !defined(NEED_XF86_PROTOTYPES)
+extern int xf86fscanf(XF86FILE*,const char*,...);
+#else
+extern int xf86fscanf(/*XF86FILE*,const char*,char *,char *,char *,char *,
+ char *,char *,char *,char *,char *,char * */);
+#endif
+extern int xf86fseek(XF86FILE*,long,int);
+extern int xf86fsetpos(XF86FILE*,const XF86fpos_t*);
+extern long xf86ftell(XF86FILE*);
+extern xf86size_t xf86fwrite(const void*,xf86size_t,xf86size_t,XF86FILE*);
+extern char* xf86getenv(const char*);
+extern int xf86isalnum(int);
+extern int xf86isalpha(int);
+extern int xf86iscntrl(int);
+extern int xf86isdigit(int);
+extern int xf86isgraph(int);
+extern int xf86islower(int);
+extern int xf86isprint(int);
+extern int xf86ispunct(int);
+extern int xf86isspace(int);
+extern int xf86isupper(int);
+extern int xf86isxdigit(int);
+extern long xf86labs(long);
+extern double xf86ldexp(double,int);
+extern double xf86log(double);
+extern double xf86log10(double);
+extern void* xf86malloc(xf86size_t);
+extern void* xf86memchr(const void*,int,xf86size_t);
+extern int xf86memcmp(const void*,const void*,xf86size_t);
+extern void* xf86memcpy(void*,const void*,xf86size_t);
+extern void* xf86memmove(void*,const void*,xf86size_t);
+extern void* xf86memset(void*,int,xf86size_t);
+extern double xf86modf(double,double*);
+extern void xf86perror(const char*);
+extern double xf86pow(double,double);
+extern void xf86qsort(void*, xf86size_t, xf86size_t,
+ int(*)(const void*, const void*));
+extern void* xf86realloc(void*,xf86size_t);
+extern int xf86remove(const char*);
+extern int xf86rename(const char*,const char*);
+extern void xf86rewind(XF86FILE*);
+extern int xf86setbuf(XF86FILE*,char*);
+extern int xf86setvbuf(XF86FILE*,char*,int,xf86size_t);
+extern double xf86sin(double);
+extern int xf86sprintf(char*,const char*,...);
+extern int xf86snprintf(char*,xf86size_t,const char*,...);
+extern double xf86sqrt(double);
+#if defined(HAVE_VSSCANF) || !defined(NEED_XF86_PROTOTYPES)
+extern int xf86sscanf(char*,const char*,...);
+#else
+extern int xf86sscanf(/*char*,const char*,char *,char *,char *,char *,
+ char *,char *,char *,char *,char *,char * */);
+#endif
+extern char* xf86strcat(char*,const char*);
+extern char* xf86strchr(const char*, int c);
+extern int xf86strcmp(const char*,const char*);
+extern int xf86strcasecmp(const char*,const char*);
+extern char* xf86strcpy(char*,const char*);
+extern xf86size_t xf86strcspn(const char*,const char*);
+extern char* xf86strerror(int);
+extern xf86size_t xf86strlcat(char*,const char*,xf86size_t);
+extern xf86size_t xf86strlcpy(char*,const char*,xf86size_t);
+extern xf86size_t xf86strlen(const char*);
+extern char* xf86strncat(char *, const char *, xf86size_t);
+extern int xf86strncmp(const char*,const char*,xf86size_t);
+extern int xf86strncasecmp(const char*,const char*,xf86size_t);
+extern char* xf86strncpy(char*,const char*,xf86size_t);
+extern char* xf86strpbrk(const char*,const char*);
+extern char* xf86strrchr(const char*,int);
+extern xf86size_t xf86strspn(const char*,const char*);
+extern char* xf86strstr(const char*,const char*);
+extern double xf86strtod(const char*,char**);
+extern char* xf86strtok(char*,const char*);
+extern long xf86strtol(const char*,char**,int);
+extern unsigned long xf86strtoul(const char*,char**,int);
+extern double xf86tan(double);
+extern XF86FILE* xf86tmpfile(void);
+extern char* xf86tmpnam(char*);
+extern int xf86tolower(int);
+extern int xf86toupper(int);
+extern int xf86ungetc(int,XF86FILE*);
+extern int xf86vfprintf(XF86FILE*,const char*,va_list);
+extern int xf86vsprintf(char*,const char*,va_list);
+extern int xf86vsnprintf(char*,xf86size_t,const char*,va_list);
+
+extern int xf86open(const char*, int,...);
+extern int xf86close(int);
+extern long xf86lseek(int, long, int);
+extern int xf86ioctl(int, unsigned long, pointer);
+extern xf86ssize_t xf86read(int, void *, xf86size_t);
+extern xf86ssize_t xf86write(int, const void *, xf86size_t);
+extern void* xf86mmap(void*, xf86size_t, int, int, int, xf86size_t /* off_t */);
+extern int xf86munmap(void*, xf86size_t);
+extern int xf86stat(const char *, struct xf86stat *);
+extern int xf86fstat(int, struct xf86stat *);
+extern int xf86access(const char *, int);
+extern int xf86errno;
+extern int xf86GetErrno(void);
+
+extern double xf86HUGE_VAL;
+
+extern double xf86hypot(double,double);
+
+/* non-ANSI C functions */
+extern XF86DIR* xf86opendir(const char*);
+extern int xf86closedir(XF86DIR*);
+extern XF86DIRENT* xf86readdir(XF86DIR*);
+extern void xf86rewinddir(XF86DIR*);
+extern void xf86bcopy(const void*,void*,xf86size_t);
+extern int xf86ffs(int);
+extern char* xf86strdup(const char*);
+extern void xf86bzero(void*,unsigned int);
+extern int xf86execl(const char *, const char *, ...);
+extern long xf86fpossize(void);
+extern int xf86chmod(const char *, xf86mode_t);
+extern int xf86chown(const char *, xf86uid_t, xf86gid_t);
+extern xf86uid_t xf86geteuid(void);
+extern xf86gid_t xf86getegid(void);
+extern int xf86getpid(void);
+extern int xf86mknod(const char *, xf86mode_t, xf86dev_t);
+extern int xf86mkdir(const char *, xf86mode_t);
+unsigned int xf86sleep(unsigned int seconds);
+/* sysv IPC */
+extern int xf86shmget(xf86key_t key, int size, int xf86shmflg);
+extern char * xf86shmat(int id, char *addr, int xf86shmflg);
+extern int xf86shmdt(char *addr);
+extern int xf86shmctl(int id, int xf86cmd, pointer buf);
+
+extern int xf86setjmp(xf86jmp_buf env);
+extern int xf86setjmp0(xf86jmp_buf env);
+extern int xf86setjmp1(xf86jmp_buf env, int);
+extern int xf86setjmp1_arg2(void);
+extern int xf86setjmperror(xf86jmp_buf env);
+extern int xf86getjmptype(void);
+extern void xf86longjmp(xf86jmp_buf env, int val);
+#define xf86setjmp_macro(env) \
+ (xf86getjmptype() == 0 ? xf86setjmp0((env)) : \
+ (xf86getjmptype() == 1 ? xf86setjmp1((env), xf86setjmp1_arg2()) : \
+ xf86setjmperror((env))))
+
+#else /* XFree86LOADER || NEED_XF86_PROTOTYPES */
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <ctype.h>
+#ifdef HAVE_SYSV_IPC
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#endif
+#include <sys/stat.h>
+#define stat_t struct stat
+#endif /* XFree86LOADER || NEED_XF86_PROTOTYPES */
+
+/*
+ * These things are always required by drivers (but not by libc_wrapper.c),
+ * even for a static server because some OSs don't provide them.
+ */
+
+extern int xf86getpagesize(void);
+extern void xf86usleep(unsigned long);
+extern void xf86getsecs(long *, long *);
+#ifndef DONT_DEFINE_WRAPPERS
+#undef getpagesize
+#define getpagesize() xf86getpagesize()
+#undef usleep
+#define usleep(ul) xf86usleep(ul)
+#undef getsecs
+#define getsecs(a, b) xf86getsecs(a, b)
+#endif
+#endif /* _XF86_ANSIC_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_libc.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_libc.h
new file mode 100644
index 000000000..c51e0ee14
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/xf86_libc.h
@@ -0,0 +1,726 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h,v 1.9 2005/08/24 11:18:31 daniels Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86_libc.h,v 3.63 2003/12/08 21:46:55 alanh Exp $ */
+/*
+ * 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 is an attempt to make developing code for the new loadable module
+ * architecure simpler. It tries to use macros to hide all libc wrappers so
+ * that all that is needed to "port" a module to this architecture is to
+ * include this one header file
+ *
+ * Revision history:
+ *
+ *
+ * 0.4 Apr 12 1997 add the ANSI defines
+ * 0.3 Feb 24 1997 handle getenv
+ * 0.2 Feb 24 1997 hide few FILE functions
+ * 0.1 Feb 24 1997 hide the trivial functions mem* str*
+ */
+
+#ifndef XF86_LIBC_H
+#define XF86_LIBC_H 1
+
+#include <X11/Xfuncs.h>
+#include <stddef.h>
+
+/*
+ * The first set of definitions are required both for modules and
+ * libc_wrapper.c.
+ */
+
+#if defined(XFree86LOADER) || defined(NEED_XF86_TYPES)
+
+/*
+ * First, the new data types
+ *
+ * note: if some pointer is declared "opaque" here, pass it between
+ * xf86* functions only, and don't rely on it having a whatever internal
+ * structure, even if some source file might reveal the existence of
+ * such a structure.
+ */
+typedef void XF86FILE; /* opaque FILE replacement */
+extern XF86FILE* xf86stdin;
+extern XF86FILE* xf86stdout;
+extern XF86FILE* xf86stderr;
+
+typedef void XF86fpos_t; /* opaque fpos_t replacement */
+
+#define _XF86NAMELEN 263 /* enough for a larger filename */
+ /* (divisble by 8) */
+typedef void XF86DIR; /* opaque DIR replacement */
+
+/* Note: the following is POSIX! POSIX only requires the d_name member.
+ * Normal Unix has often a number of other members, but don't rely on that
+ */
+struct _xf86dirent { /* types in struct dirent/direct: */
+ char d_name[_XF86NAMELEN+1]; /* char [MAXNAMLEN]; might be smaller or unaligned */
+};
+typedef struct _xf86dirent XF86DIRENT;
+
+typedef unsigned long xf86size_t;
+typedef signed long xf86ssize_t;
+typedef unsigned long xf86dev_t;
+typedef unsigned int xf86mode_t;
+typedef unsigned int xf86uid_t;
+typedef unsigned int xf86gid_t;
+
+struct xf86stat {
+ xf86dev_t st_rdev; /* This is incomplete, and makes assumptions */
+};
+
+/* sysv IPC */
+typedef int xf86key_t;
+
+/* setjmp/longjmp */
+#if defined(__ia64__)
+typedef int xf86jmp_buf[1024] __attribute__ ((aligned (16))); /* guarantees 128-bit alignment! */
+#else
+typedef int xf86jmp_buf[1024];
+#endif
+
+/* for setvbuf */
+#define XF86_IONBF 1
+#define XF86_IOFBF 2
+#define XF86_IOLBF 3
+
+/* for open (XXX not complete) */
+#define XF86_O_RDONLY 0x0000
+#define XF86_O_WRONLY 0x0001
+#define XF86_O_RDWR 0x0002
+#define XF86_O_CREAT 0x0200
+
+/* for mmap */
+#define XF86_PROT_EXEC 0x0001
+#define XF86_PROT_READ 0x0002
+#define XF86_PROT_WRITE 0x0004
+#define XF86_PROT_NONE 0x0008
+#define XF86_MAP_FIXED 0x0001
+#define XF86_MAP_SHARED 0x0002
+#define XF86_MAP_PRIVATE 0x0004
+#define XF86_MAP_32BIT 0x0040
+#define XF86_MAP_FAILED ((void *)-1)
+
+/* for fseek */
+#define XF86_SEEK_SET 0
+#define XF86_SEEK_CUR 1
+#define XF86_SEEK_END 2
+
+/* for access */
+#define XF86_R_OK 0
+#define XF86_W_OK 1
+#define XF86_X_OK 2
+#define XF86_F_OK 3
+
+/* for chmod */
+#define XF86_S_ISUID 04000 /* set user ID on execution */
+#define XF86_S_ISGID 02000 /* set group ID on execution */
+#define XF86_S_ISVTX 01000 /* sticky bit */
+#define XF86_S_IRUSR 00400 /* read by owner */
+#define XF86_S_IWUSR 00200 /* write by owner */
+#define XF86_S_IXUSR 00100 /* execute/search by owner */
+#define XF86_S_IRGRP 00040 /* read by group */
+#define XF86_S_IWGRP 00020 /* write by group */
+#define XF86_S_IXGRP 00010 /* execute/search by group */
+#define XF86_S_IROTH 00004 /* read by others */
+#define XF86_S_IWOTH 00002 /* write by others */
+#define XF86_S_IXOTH 00001 /* execute/search by others */
+
+/* for mknod */
+#define XF86_S_IFREG 0010000
+#define XF86_S_IFCHR 0020000
+#define XF86_S_IFBLK 0040000
+#define XF86_S_IFIFO 0100000
+
+/*
+ * errno values
+ * They start at 1000 just so they don't match real errnos at all
+ */
+#define xf86_UNKNOWN 1000
+#define xf86_EACCES 1001
+#define xf86_EAGAIN 1002
+#define xf86_EBADF 1003
+#define xf86_EEXIST 1004
+#define xf86_EFAULT 1005
+#define xf86_EINTR 1006
+#define xf86_EINVAL 1007
+#define xf86_EISDIR 1008
+#define xf86_ELOOP 1009
+#define xf86_EMFILE 1010
+#define xf86_ENAMETOOLONG 1011
+#define xf86_ENFILE 1012
+#define xf86_ENOENT 1013
+#define xf86_ENOMEM 1014
+#define xf86_ENOSPC 1015
+#define xf86_ENOTDIR 1016
+#define xf86_EPIPE 1017
+#define xf86_EROFS 1018
+#define xf86_ETXTBSY 1019
+#define xf86_ENOTTY 1020
+#define xf86_ENOSYS 1021
+#define xf86_EBUSY 1022
+#define xf86_ENODEV 1023
+#define xf86_EIO 1024
+
+#define xf86_ESRCH 1025
+#define xf86_ENXIO 1026
+#define xf86_E2BIG 1027
+#define xf86_ENOEXEC 1028
+#define xf86_ECHILD 1029
+#define xf86_ENOTBLK 1030
+#define xf86_EXDEV 1031
+#define xf86_EFBIG 1032
+#define xf86_ESPIPE 1033
+#define xf86_EMLINK 1034
+#define xf86_EDOM 1035
+#define xf86_ERANGE 1036
+
+
+/* sysv IPV */
+/* xf86shmget() */
+#define XF86IPC_CREAT 01000
+#define XF86IPC_EXCL 02000
+#define XF86IPC_NOWAIT 04000
+#define XF86SHM_R 0400
+#define XF86SHM_W 0200
+#define XF86IPC_PRIVATE ((xf86key_t)0)
+/* xf86shmat() */
+#define XF86SHM_RDONLY 010000 /* attach read-only else read-write */
+#define XF86SHM_RND 020000 /* round attach address to SHMLBA */
+#define XF86SHM_REMAP 040000 /* take-over region on attach */
+/* xf86shmclt() */
+#define XF86IPC_RMID 0
+
+#endif /* defined(XFree86LOADER) || defined(NEED_XF86_TYPES) */
+
+/*
+ * the rest of this file should only be included for code that is supposed
+ * to go into modules
+ */
+
+#if defined(XFree86LOADER) && !defined(DONT_DEFINE_WRAPPERS)
+
+#undef abort
+#define abort() xf86abort()
+#undef abs
+#define abs(i) xf86abs(i)
+#undef acos
+#define acos(d) xf86acos(d)
+#undef asin
+#define asin(d) xf86asin(d)
+#undef atan
+#define atan(d) xf86atan(d)
+#undef atan2
+#define atan2(d1,d2) xf86atan2(d1,d2)
+#undef atof
+#define atof(ccp) xf86atof(ccp)
+#undef atoi
+#define atoi(ccp) xf86atoi(ccp)
+#undef atol
+#define atol(ccp) xf86atol(ccp)
+#undef bsearch
+#define bsearch(a,b,c,d,e) xf86bsearch(a,b,c,d,e)
+#undef ceil
+#define ceil(d) xf86ceil(d)
+#undef calloc
+#define calloc(I1,I2) xf86calloc(I1,I2)
+#undef clearerr
+#define clearerr(FP) xf86clearerr(FP)
+#undef cos
+#define cos(d) xf86cos(d)
+#undef exit
+#define exit(i) xf86exit(i)
+#undef exp
+#define exp(d) xf86exp(d)
+#undef fabs
+#define fabs(d) xf86fabs(d)
+#undef fclose
+#define fclose(FP) xf86fclose(FP)
+#undef feof
+#define feof(FP) xf86feof(FP)
+#undef ferror
+#define ferror(FP) xf86ferror(FP)
+#undef fflush
+#define fflush(FP) xf86fflush(FP)
+#undef fgetc
+#define fgetc(FP) xf86fgetc(FP)
+#undef getc
+#define getc(FP) xf86getc(FP)
+#undef fgetpos
+#define fgetpos(FP,fpp) xf86fgetpos(FP,fpp)
+#undef fgets
+#define fgets(cp,i,FP) xf86fgets(cp,i,FP)
+#undef finite
+#define finite(d) xf86finite(d)
+#undef floor
+#define floor(d) xf86floor(d)
+#undef fmod
+#define fmod(d1,d2) xf86fmod(d1,d2)
+#undef fopen
+#define fopen(ccp1,ccp2) xf86fopen(ccp1,ccp2)
+#undef printf
+#define printf xf86printf
+#undef fprintf
+#define fprintf xf86fprintf
+#undef fputc
+#define fputc(i,FP) xf86fputc(i,FP)
+#undef fputs
+#define fputs(ccp,FP) xf86fputs(ccp,FP)
+#undef fread
+#define fread(vp,I1,I2,FP) xf86fread(vp,I1,I2,FP)
+#undef free
+#define free(vp) xf86free(vp)
+#undef freopen
+#define freopen(ccp1,ccp2,FP) xf86freopen(ccp1,ccp2,FP)
+#undef frexp
+#define frexp(x,exp) xf86frexp(x,exp)
+#undef fscanf
+#define fscanf xf86fscanf
+#undef fseek
+#define fseek(FP,l,i) xf86fseek(FP,l,i)
+#undef fsetpos
+#define fsetpos(FP,cfpp) xf86fsetpos(FP,cfpp)
+#undef ftell
+#define ftell(FP) xf86ftell(FP)
+#undef fwrite
+#define fwrite(cvp,I1,I2,FP) xf86fwrite(cvp,I1,I2,FP)
+#undef getenv
+#define getenv(ccp) xf86getenv(ccp)
+#undef isalnum
+#define isalnum(i) xf86isalnum(i)
+#undef isalpha
+#define isalpha(i) xf86isalpha(i)
+#undef iscntrl
+#define iscntrl(i) xf86iscntrl(i)
+#undef isdigit
+#define isdigit(i) xf86isdigit(i)
+#undef isgraph
+#define isgraph(i) xf86isgraph(i)
+#undef islower
+#define islower(i) xf86islower(i)
+#undef isprint
+#define isprint(i) xf86isprint(i)
+#undef ispunct
+#define ispunct(i) xf86ispunct(i)
+#undef isspace
+#define isspace(i) xf86isspace(i)
+#undef isupper
+#define isupper(i) xf86isupper(i)
+#undef isxdigit
+#define isxdigit(i) xf86isxdigit(i)
+#undef labs
+#define labs(l) xf86labs(l)
+#undef ldexp
+#define ldexp(x, exp) xf86ldexp(x, exp)
+#undef log
+#define log(d) xf86log(d)
+#undef log10
+#define log10(d) xf86log10(d)
+#undef malloc
+#define malloc(I) xf86malloc(I)
+#undef memchr
+#define memchr(cvp,i,I) xf86memchr(cvp,i,I)
+#undef memcmp
+#define memcmp(cvp1,cvp2,I) xf86memcmp(cvp1,cvp2,I)
+#undef memcpy
+#define memcpy(vp,cvp,I) xf86memcpy(vp,cvp,I)
+#undef memmove
+#define memmove(vp,cvp,I) xf86memmove(vp,cvp,I)
+#undef memset
+#define memset(vp,int,I) xf86memset(vp,int,I)
+#undef modf
+#define modf(d,dp) xf86modf(d,dp)
+#undef perror
+#define perror(ccp) xf86perror(ccp)
+#undef pow
+#define pow(d1,d2) xf86pow(d1,d2)
+#undef realloc
+#define realloc(vp,I) xf86realloc(vp,I)
+#undef remove
+#define remove(ccp) xf86remove(ccp)
+#undef rename
+#define rename(ccp1,ccp2) xf86rename(ccp1,ccp2)
+#undef rewind
+#define rewind(FP) xf86rewind(FP)
+#undef setbuf
+#define setbuf(FP,cp) xf86setbuf(FP,cp)
+#undef setvbuf
+#define setvbuf(FP,cp,i,I) xf86setvbuf(FP,cp,i,I)
+#undef sin
+#define sin(d) xf86sin(d)
+#undef snprintf
+#define snprintf xf86snprintf
+#undef sprintf
+#define sprintf xf86sprintf
+#undef sqrt
+#define sqrt(d) xf86sqrt(d)
+#undef sscanf
+#define sscanf xf86sscanf
+#undef strcat
+#define strcat(cp,ccp) xf86strcat(cp,ccp)
+#undef strcmp
+#define strcmp(ccp1,ccp2) xf86strcmp(ccp1,ccp2)
+#undef strcasecmp
+#define strcasecmp(ccp1,ccp2) xf86strcasecmp(ccp1,ccp2)
+#undef strcpy
+#define strcpy(cp,ccp) xf86strcpy(cp,ccp)
+#undef strcspn
+#define strcspn(ccp1,ccp2) xf86strcspn(ccp1,ccp2)
+#undef strerror
+#define strerror(i) xf86strerror(i)
+#undef strlcat
+#define strlcat(cp,ccp,I) xf86strlcat(cp,ccp,I)
+#undef strlcpy
+#define strlcpy(cp,ccp,I) xf86strlcpy(cp,ccp,I)
+#undef strlen
+#define strlen(ccp) xf86strlen(ccp)
+#undef strncmp
+#define strncmp(ccp1,ccp2,I) xf86strncmp(ccp1,ccp2,I)
+#undef strncasecmp
+#define strncasecmp(ccp1,ccp2,I) xf86strncasecmp(ccp1,ccp2,I)
+#undef strncpy
+#define strncpy(cp,ccp,I) xf86strncpy(cp,ccp,I)
+#undef strpbrk
+#define strpbrk(ccp1,ccp2) xf86strpbrk(ccp1,ccp2)
+#undef strchr
+#define strchr(ccp,i) xf86strchr(ccp,i)
+#undef strrchr
+#define strrchr(ccp,i) xf86strrchr(ccp,i)
+#undef strspn
+#define strspn(ccp1,ccp2) xf86strspn(ccp1,ccp2)
+#undef strstr
+#define strstr(ccp1,ccp2) xf86strstr(ccp1,ccp2)
+#undef srttod
+#define strtod(ccp,cpp) xf86strtod(ccp,cpp)
+#undef strtok
+#define strtok(cp,ccp) xf86strtok(cp,ccp)
+#undef strtol
+#define strtol(ccp,cpp,i) xf86strtol(ccp,cpp,i)
+#undef strtoul
+#define strtoul(ccp,cpp,i) xf86strtoul(ccp,cpp,i)
+#undef tan
+#define tan(d) xf86tan(d)
+#undef tmpfile
+#define tmpfile() xf86tmpfile()
+#undef tolower
+#define tolower(i) xf86tolower(i)
+#undef toupper
+#define toupper(i) xf86toupper(i)
+#undef ungetc
+#define ungetc(i,FP) xf86ungetc(i,FP)
+#undef vfprinf
+#define vfprintf(p,f,a) xf86vfprintf(p,f,a)
+#undef vsnprintf
+#define vsnprintf(s,n,f,a) xf86vsnprintf(s,n,f,a)
+#undef vsprintf
+#define vsprintf(s,f,a) xf86vsprintf(s,f,a)
+/* XXX Disable assert as if NDEBUG was defined */
+/* Some X headers defined this away too */
+#undef assert
+#define assert(a) ((void)0)
+#undef HUGE_VAL
+#define HUGE_VAL xf86HUGE_VAL
+
+#undef hypot
+#define hypot(x,y) xf86hypot(x,y)
+
+#undef qsort
+#define qsort(b, n, s, f) xf86qsort(b, n, s, f)
+
+/* non-ANSI C functions */
+#undef opendir
+#define opendir(cp) xf86opendir(cp)
+#undef closedir
+#define closedir(DP) xf86closedir(DP)
+#undef readdir
+#define readdir(DP) xf86readdir(DP)
+#undef rewinddir
+#define rewinddir(DP) xf86rewinddir(DP)
+#undef bcopy
+#define bcopy(vp,cvp,I) xf86memmove(cvp,vp,I)
+#undef ffs
+#define ffs(i) xf86ffs(i)
+#undef strdup
+#define strdup(ccp) xf86strdup(ccp)
+#undef bzero
+#define bzero(vp,ui) xf86bzero(vp,ui)
+#undef execl
+#define execl xf86execl
+#undef chmod
+#define chmod(a,b) xf86chmod(a,b)
+#undef chown
+#define chown(a,b,c) xf86chown(a,b,c)
+#undef geteuid
+#define geteuid xf86geteuid
+#undef getegid
+#define getegid xf86getegid
+#undef getpid
+#define getpid xf86getpid
+#undef mknod
+#define mknod(a,b,c) xf86mknod(a,b,c)
+#undef sleep
+#define sleep(a) xf86sleep(a)
+#undef mkdir
+#define mkdir(a,b) xf86mkdir(a,b)
+#undef getpagesize
+#define getpagesize xf86getpagesize
+#undef shmget
+#define shmget(a,b,c) xf86shmget(a,b,c)
+#undef shmat
+#define shmat(a,b,c) xf86shmat(a,b,c)
+#undef shmdt
+#define shmdt(a) xf86shmdt(a)
+#undef shmctl
+#define shmctl(a,b,c) xf86shmctl(a,b,c)
+
+#undef S_ISUID
+#define S_ISUID XF86_S_ISUID
+#undef S_ISGID
+#define S_ISGID XF86_S_ISGID
+#undef S_ISVTX
+#define S_ISVTX XF86_S_ISVTX
+#undef S_IRUSR
+#define S_IRUSR XF86_S_IRUSR
+#undef S_IWUSR
+#define S_IWUSR XF86_S_IWUSR
+#undef S_IXUSR
+#define S_IXUSR XF86_S_IXUSR
+#undef S_IRGRP
+#define S_IRGRP XF86_S_IRGRP
+#undef S_IWGRP
+#define S_IWGRP XF86_S_IWGRP
+#undef S_IXGRP
+#define S_IXGRP XF86_S_IXGRP
+#undef S_IROTH
+#define S_IROTH XF86_S_IROTH
+#undef S_IWOTH
+#define S_IWOTH XF86_S_IWOTH
+#undef S_IXOTH
+#define S_IXOTH XF86_S_IXOTH
+#undef S_IFREG
+#define S_IFREG XF86_S_IFREG
+#undef S_IFCHR
+#define S_IFCHR XF86_S_IFCHR
+#undef S_IFBLK
+#define S_IFBLK XF86_S_IFBLK
+#undef S_IFIFO
+#define S_IFIFO XF86_S_IFIFO
+
+/* some types */
+#undef FILE
+#define FILE XF86FILE
+#undef fpos_t
+#define fpos_t XF86fpos_t
+#undef DIR
+#define DIR XF86DIR
+#undef DIRENT
+#define DIRENT XF86DIRENT
+#undef size_t
+#define size_t xf86size_t
+#undef ssize_t
+#define ssize_t xf86ssize_t
+#undef dev_t
+#define dev_t xf86dev_t
+#undef mode_t
+#define mode_t xf86mode_t
+#undef uid_t
+#define uid_t xf86uid_t
+#undef gid_t
+#define gid_t xf86gid_t
+#undef stat_t
+#define stat_t struct xf86stat
+
+#undef ulong
+#define ulong unsigned long
+
+/*
+ * There should be no need to #undef any of these. If they are already
+ * defined it is because some illegal header has been included.
+ */
+
+/* some vars */
+#undef stdin
+#define stdin xf86stdin
+#undef stdout
+#define stdout xf86stdout
+#undef stderr
+#define stderr xf86stderr
+
+#undef SEEK_SET
+#define SEEK_SET XF86_SEEK_SET
+#undef SEEK_CUR
+#define SEEK_CUR XF86_SEEK_CUR
+#undef SEEK_END
+#define SEEK_END XF86_SEEK_END
+
+/*
+ * XXX Basic I/O functions BAD,BAD,BAD!
+ */
+#define open xf86open
+#define close(a) xf86close(a)
+#define lseek(a,b,c) xf86lseek(a,b,c)
+#if !defined(__DragonFly__)
+#define ioctl(a,b,c) xf86ioctl(a,b,c)
+#endif
+#define read(a,b,c) xf86read(a,b,c)
+#define write(a,b,c) xf86write(a,b,c)
+#define mmap(a,b,c,d,e,f) xf86mmap(a,b,c,d,e,f)
+#define munmap(a,b) xf86munmap(a,b)
+#define stat(a,b) xf86stat(a,b)
+#define fstat(a,b) xf86fstat(a,b)
+#define access(a,b) xf86access(a,b)
+#undef O_RDONLY
+#define O_RDONLY XF86_O_RDONLY
+#undef O_WRONLY
+#define O_WRONLY XF86_O_WRONLY
+#undef O_RDWR
+#define O_RDWR XF86_O_RDWR
+#undef O_CREAT
+#define O_CREAT XF86_O_CREAT
+#undef PROT_EXEC
+#define PROT_EXEC XF86_PROT_EXEC
+#undef PROT_READ
+#define PROT_READ XF86_PROT_READ
+#undef PROT_WRITE
+#define PROT_WRITE XF86_PROT_WRITE
+#undef PROT_NONE
+#define PROT_NONE XF86_PROT_NONE
+#undef MAP_FIXED
+#define MAP_FIXED XF86_MAP_FIXED
+#undef MAP_SHARED
+#define MAP_SHARED XF86_MAP_SHARED
+#undef MAP_PRIVATE
+#define MAP_PRIVATE XF86_MAP_PRIVATE
+#undef MAP_FAILED
+#define MAP_FAILED XF86_MAP_FAILED
+#undef R_OK
+#define R_OK XF86_R_OK
+#undef W_OK
+#define W_OK XF86_W_OK
+#undef X_OK
+#define X_OK XF86_X_OK
+#undef F_OK
+#define F_OK XF86_F_OK
+#undef errno
+#define errno xf86errno
+#undef putchar
+#define putchar(i) xf86fputc(i, xf86stdout)
+#undef puts
+#define puts(s) xf86fputs(s, xf86stdout)
+
+#undef EACCES
+#define EACCES xf86_EACCES
+#undef EAGAIN
+#define EAGAIN xf86_EAGAIN
+#undef EBADF
+#define EBADF xf86_EBADF
+#undef EEXIST
+#define EEXIST xf86_EEXIST
+#undef EFAULT
+#define EFAULT xf86_EFAULT
+#undef EINTR
+#define EINTR xf86_EINTR
+#undef EINVAL
+#define EINVAL xf86_EINVAL
+#undef EISDIR
+#define EISDIR xf86_EISDIR
+#undef ELOOP
+#define ELOOP xf86_ELOOP
+#undef EMFILE
+#define EMFILE xf86_EMFILE
+#undef ENAMETOOLONG
+#define ENAMETOOLONG xf86_ENAMETOOLONG
+#undef ENFILE
+#define ENFILE xf86_ENFILE
+#undef ENOENT
+#define ENOENT xf86_ENOENT
+#undef ENOMEM
+#define ENOMEM xf86_ENOMEM
+#undef ENOSPC
+#define ENOSPC xf86_ENOSPC
+#undef ENOTDIR
+#define ENOTDIR xf86_ENOTDIR
+#undef EPIPE
+#define EPIPE xf86_EPIPE
+#undef EROFS
+#define EROFS xf86_EROFS
+#undef ETXTBSY
+#define ETXTBSY xf86_ETXTBSY
+#undef ENOTTY
+#define ENOTTY xf86_ENOTTY
+#undef ENOSYS
+#define ENOSYS xf86_ENOSYS
+#undef EBUSY
+#define EBUSY xf86_EBUSY
+#undef ENODEV
+#define ENODEV xf86_ENODEV
+#undef EIO
+#define EIO xf86_EIO
+
+/* IPC stuff */
+#undef SHM_RDONLY
+#define SHM_RDONLY XF86SHM_RDONLY
+#undef SHM_RND
+#define SHM_RND XF86SHM_RND
+#undef SHM_REMAP
+#define SHM_REMAP XF86SHM_REMAP
+#undef IPC_RMID
+#define IPC_RMID XF86IPC_RMID
+#undef IPC_CREAT
+#define IPC_CREAT XF86IPC_CREAT
+#undef IPC_EXCL
+#define IPC_EXCL XF86IPC_EXCL
+#undef PC_NOWAIT
+#define IPC_NOWAIT XF86IPC_NOWAIT
+#undef SHM_R
+#define SHM_R XF86SHM_R
+#undef SHM_W
+#define SHM_W XF86SHM_W
+#undef IPC_PRIVATE
+#define IPC_PRIVATE XF86IPC_PRIVATE
+
+/* Some ANSI macros */
+#undef FILENAME_MAX
+#define FILENAME_MAX 1024
+
+#if (defined(sun) && defined(__SVR4))
+# define _FILEDEFED /* Already have FILE defined, don't redefine it */
+#endif
+
+#endif /* XFree86LOADER && !DONT_DEFINE_WRAPPERS */
+
+#if defined(XFree86LOADER) && \
+ (!defined(DONT_DEFINE_WRAPPERS) || defined(DEFINE_SETJMP_WRAPPERS))
+#undef setjmp
+#define setjmp(a) xf86setjmp_macro(a)
+#undef longjmp
+#define longjmp(a,b) xf86longjmp(a,b)
+#undef jmp_buf
+#define jmp_buf xf86jmp_buf
+#endif
+
+#endif /* XF86_LIBC_H */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Configint.h b/nx-X11/programs/Xserver/hw/xfree86/parser/Configint.h
new file mode 100644
index 000000000..a51116b55
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Configint.h
@@ -0,0 +1,226 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Configint.h,v 1.21 2003/08/24 17:37:07 dawes Exp $ */
+/*
+ *
+ * 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."
+
+/* 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_ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/DRI.c b/nx-X11/programs/Xserver/hw/xfree86/parser/DRI.c
new file mode 100644
index 000000000..93d0d4b52
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/DRI.c
@@ -0,0 +1,187 @@
+/* DRI.c -- DRI Section in XF86Config file
+ * Created: Fri Mar 19 08:40:22 1999 by faith@precisioninsight.com
+ * Revised: Thu Jun 17 16:08:05 1999 by faith@precisioninsight.com
+ *
+ * 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.
+ *
+ * $XFree86: xc/programs/Xserver/hw/xfree86/parser/DRI.c,v 1.13 2003/01/01 19:22:20 paulo Exp $
+ *
+ */
+
+#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);
+ }
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Device.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Device.c
new file mode 100644
index 000000000..6eb2857f0
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Device.c
@@ -0,0 +1,403 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Device.c,v 1.27 2003/08/24 17:37:07 dawes Exp $ */
+/*
+ *
+ * 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 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;
+ parsePrologue (XF86ConfDevicePtr, XF86ConfDeviceRec)
+
+ /* Zero is a valid value for these */
+ ptr->dev_chipid = -1;
+ ptr->dev_chiprev = -1;
+ ptr->dev_irq = -1;
+ while ((token = xf86getToken (DeviceTab)) != ENDSECTION)
+ {
+ 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 (!has_ident)
+ Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+ printf ("Device section parsed\n");
+#endif
+
+ return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printDeviceSection (FILE * cf, XF86ConfDevicePtr ptr)
+{
+ int i;
+
+ while (ptr)
+ {
+ fprintf (cf, "Section \"Device\"\n");
+ if (ptr->dev_comment)
+ fprintf (cf, "%s", ptr->dev_comment);
+ if (ptr->dev_identifier)
+ fprintf (cf, "\tIdentifier \"%s\"\n", ptr->dev_identifier);
+ if (ptr->dev_driver)
+ fprintf (cf, "\tDriver \"%s\"\n", ptr->dev_driver);
+ if (ptr->dev_vendor)
+ fprintf (cf, "\tVendorName \"%s\"\n", ptr->dev_vendor);
+ if (ptr->dev_board)
+ fprintf (cf, "\tBoardName \"%s\"\n", ptr->dev_board);
+ 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, 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);
+ fprintf (cf, "EndSection\n\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 (!device) {
+ xf86validationError ("At least one Device section is required.");
+ return (FALSE);
+ }
+
+ 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);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Extensions.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Extensions.c
new file mode 100644
index 000000000..b64f08111
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Extensions.c
@@ -0,0 +1,111 @@
+/*
+ * 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 <kem@redhat.com>
+ *
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+
+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, 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);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Files.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Files.c
new file mode 100644
index 000000000..cbbcc74c8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Files.c
@@ -0,0 +1,295 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Files.c,v 1.16 2003/08/24 17:37:07 dawes Exp $ */
+/*
+ *
+ * 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 <X11/Xos.h>
+#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 ("File section parsed\n");
+#endif
+
+ return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printFileSection (FILE * cf, XF86ConfFilesPtr ptr)
+{
+ char *p, *s;
+
+ if (ptr == NULL)
+ return;
+
+ 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 = index (s, ',');
+ while (p)
+ {
+ *p = '\000';
+ fprintf (cf, "\tModulePath \"%s\"\n", s);
+ *p = ',';
+ s = p;
+ s++;
+ p = index (s, ',');
+ }
+ fprintf (cf, "\tModulePath \"%s\"\n", s);
+ }
+ if (ptr->file_inputdevs)
+ {
+ s = ptr->file_inputdevs;
+ p = index (s, ',');
+ while (p)
+ {
+ *p = '\000';
+ fprintf (cf, "\tInputDevices \"%s\"\n", s);
+ *p = ',';
+ s = p;
+ s++;
+ p = index (s, ',');
+ }
+ fprintf (cf, "\tInputdevs \"%s\"\n", s);
+ }
+ if (ptr->file_fontpath)
+ {
+ s = ptr->file_fontpath;
+ p = index (s, ',');
+ while (p)
+ {
+ *p = '\000';
+ fprintf (cf, "\tFontPath \"%s\"\n", s);
+ *p = ',';
+ s = p;
+ s++;
+ p = index (s, ',');
+ }
+ fprintf (cf, "\tFontPath \"%s\"\n", s);
+ }
+}
+
+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);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Flags.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Flags.c
new file mode 100644
index 000000000..bda24df1b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Flags.c
@@ -0,0 +1,525 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Flags.c,v 1.23 2003/08/24 17:37:07 dawes Exp $ */
+/*
+ *
+ * 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 <math.h>
+
+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 ("Flags 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, 1);
+ fprintf (f, "EndSection\n\n");
+}
+
+static XF86OptionPtr
+addNewOption2 (XF86OptionPtr head, char *name, char *val, int used)
+{
+ XF86OptionPtr new, old = NULL;
+
+ /* Don't allow duplicates */
+ if (head != NULL && (old = xf86findOption(head, name)) != NULL)
+ new = old;
+ else {
+ new = xf86confcalloc (1, sizeof (XF86OptionRec));
+ new->list.next = NULL;
+ }
+ new->opt_name = name;
+ new->opt_val = val;
+ new->opt_used = used;
+
+ if (old == NULL)
+ return ((XF86OptionPtr) xf86addListItem ((glp) head, (glp) new));
+ else
+ return head;
+}
+
+XF86OptionPtr
+xf86addNewOption (XF86OptionPtr head, char *name, char *val)
+{
+ return addNewOption2(head, name, val, 0);
+}
+
+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)
+{
+ while (list)
+ {
+ if (xf86nameCompare (list->opt_name, name) == 0)
+ return (list);
+ list = list->list.next;
+ }
+ 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);
+}
+
+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]);
+ p = addNewOption2 (p, t1, t2, used);
+ }
+
+ 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;
+ }
+}
+
+XF86OptionPtr
+xf86parseOption(XF86OptionPtr head)
+{
+ XF86OptionPtr option, cnew, old;
+ char *name, *comment = NULL;
+ int token;
+
+ if ((token = xf86getSubToken(&comment)) != STRING) {
+ xf86parseError(BAD_OPTION_MSG, NULL);
+ if (comment)
+ xf86conffree(comment);
+ return (head);
+ }
+
+ name = val.str;
+ 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);
+ }
+
+ old = NULL;
+
+ /* Don't allow duplicates */
+ if (head != NULL && (old = xf86findOption(head, name)) != NULL) {
+ cnew = old;
+ xf86conffree(option->opt_name);
+ TestFree(option->opt_val);
+ TestFree(option->opt_comment);
+ xf86conffree(option);
+ }
+ else
+ cnew = option;
+
+ if (old == NULL)
+ return ((XF86OptionPtr)xf86addListItem((glp)head, (glp)cnew));
+
+ return (head);
+}
+
+void
+xf86printOptionList(FILE *fp, XF86OptionPtr list, int tabs)
+{
+ int i;
+
+ if (!list)
+ return;
+ while (list) {
+ for (i = 0; i < tabs; i++)
+ fputc('\t', fp);
+ if (list->opt_val)
+ fprintf(fp, "Option \"%s\" \"%s\"", list->opt_name, list->opt_val);
+ else
+ fprintf(fp, "Option \"%s\"", list->opt_name);
+ if (list->opt_comment)
+ fprintf(fp, "%s", list->opt_comment);
+ else
+ fputc('\n', fp);
+ list = list->list.next;
+ }
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/parser/Imakefile
new file mode 100644
index 000000000..29708b64b
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Imakefile
@@ -0,0 +1,51 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Imakefile,v 1.12 2001/01/12 19:28:35 dawes Exp $ */
+
+
+
+#define DoNormalLib YES
+#define DoSharedLib NO
+#define DoDebugLib NO
+#define DoProfileLib NO
+#define HasSharedData NO
+#define LibName xf86config
+
+#define UseDBMalloc NO
+
+#if UseDBMalloc
+SYS_LIBRARIES=-ldbmalloc
+DBMALLOCDEFINE=-DDBMALLOC
+#endif
+
+SYS_LIBRARIES = MathLibrary
+
+XCONFIGFILE = XConfigFile
+XCONFIGDIR = XConfigDir
+#if defined XFree86Version
+XVERS = XFree86Version
+#elif defined (XorgVersion)
+XVERS = XorgVersion
+#endif
+
+INCLUDES = -I. -I$(XF86OSSRC)
+
+HEADERS = xf86Parser.h xf86Optrec.h
+
+SRCS = 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 write.c \
+ DRI.c Extensions.c
+OBJS = Device.o Files.o Flags.o Input.o Keyboard.o Layout.o Module.o \
+ Video.o Monitor.o Pointer.o Screen.o Vendor.o read.o scan.o write.o \
+ DRI.o Extensions.o
+
+CONFIG_DEFINES = -DXCONFIGDIR=\"$(XCONFIGDIR)\" \
+ -DXCONFIGFILE=\"$(XCONFIGFILE)\" \
+ -DXVERSION="$(XVERS)"
+
+#include <Library.tmpl>
+
+SpecialCObjectRule(scan,NullParameter,$(CONFIG_DEFINES) $(MODULEDEFINES) $(EXT_DEFINES))
+
+NormalProgramTarget(cpconfig,cpconfig.o $(OBJS),NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+
+AllTarget(ProgramTargetName(cpconfig))
+DependTarget()
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Input.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Input.c
new file mode 100644
index 000000000..9f9323f05
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Input.c
@@ -0,0 +1,215 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Input.c,v 1.14 2003/08/24 17:37:07 dawes Exp $ */
+/*
+ *
+ * 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 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, 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);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Keyboard.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Keyboard.c
new file mode 100644
index 000000000..4ba893a9d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Keyboard.c
@@ -0,0 +1,306 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Keyboard.c,v 1.17 2003/08/24 17:37:07 dawes Exp $ */
+/*
+ *
+ * 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)
+ 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);
+ 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;
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Layout.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Layout.c
new file mode 100644
index 000000000..56d92a79c
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Layout.c
@@ -0,0 +1,513 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Layout.c,v 1.24 2003/08/24 17:37:07 dawes Exp $ */
+/*
+ *
+ * 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 <string.h>
+
+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)
+ 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)
+ 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:
+ 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)
+ Error(INVALID_SCR_MSG, NULL);
+ aptr->adj_y = val.num;
+ } else {
+ if (absKeyword)
+ 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)
+ 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)
+ Error(INVALID_SCR_MSG, NULL);
+ aptr->adj_x = val.num;
+ token = xf86getSubToken(&(ptr->lay_comment));
+ if (token != NUMBER)
+ 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)
+ Error (SCREEN_MSG, NULL);
+ aptr->adj_bottom_str = val.str;
+
+ /* left */
+ if (xf86getSubToken (&(ptr->lay_comment)) != STRING)
+ Error (SCREEN_MSG, NULL);
+ aptr->adj_left_str = val.str;
+
+ /* right */
+ if (xf86getSubToken (&(ptr->lay_comment)) != STRING)
+ 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)
+ 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 ("Layout 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, 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);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Module.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Module.c
new file mode 100644
index 000000000..7a5a25207
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Module.c
@@ -0,0 +1,261 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Module.c,v 1.12 2003/08/24 17:37:08 dawes Exp $ */
+/*
+ *
+ * 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 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->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;
+
+ 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, 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
+ }
+ }
+}
+
+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->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);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Monitor.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Monitor.c
new file mode 100644
index 000000000..52ff5a735
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Monitor.c
@@ -0,0 +1,907 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Monitor.c,v 1.28 2003/08/24 17:37:08 dawes Exp $ */
+/*
+ *
+ * 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 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;
+ parsePrologue (XF86ConfModeLinePtr, XF86ConfModeLineRec)
+
+ /* 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);
+}
+
+XF86ConfModeLinePtr
+xf86parseVerboseMode (void)
+{
+ int token, token2;
+ int had_dotclock = 0, had_htimings = 0, had_vtimings = 0;
+ parsePrologue (XF86ConfModeLinePtr, XF86ConfModeLineRec)
+
+ if (xf86getSubToken (&(ptr->ml_comment)) != STRING)
+ Error ("Mode name expected", NULL);
+ ptr->ml_identifier = val.str;
+ while ((token = xf86getToken (ModeTab)) != ENDMODE)
+ {
+ 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;
+ 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;
+ 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;
+ 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", NULL);
+ break;
+ }
+ token = xf86getSubToken (&(ptr->ml_comment));
+ }
+ xf86unGetToken (token);
+ break;
+ case HSKEW:
+ if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
+ Error ("Horizontal skew expected", NULL);
+ ptr->ml_flags |= XF86CONF_HSKEW;
+ ptr->ml_hskew = val.num;
+ 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;
+ break;
+ case EOF_TOKEN:
+ Error (UNEXPECTED_EOF_MSG, NULL);
+ break;
+ default:
+ Error ("Unexepcted token in verbose \"Mode\" entry\n", NULL);
+ }
+ }
+ 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;
+ parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec)
+
+ while ((token = xf86getToken (MonitorTab)) != ENDSECTION)
+ {
+ 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 {
+ 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;
+ }
+ if (ptr->mon_n_hsync >= CONF_MAX_HSYNC)
+ Error ("Sorry. Too many horizontal sync intervals.", NULL);
+ 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);
+ }
+ else
+ {
+ ptr->mon_gamma_red = ptr->mon_gamma_green =
+ ptr->mon_gamma_blue = val.realnum;
+ if( xf86getSubToken (&(ptr->mon_comment)) == NUMBER )
+ {
+ ptr->mon_gamma_green = val.realnum;
+ if( xf86getSubToken (&(ptr->mon_comment)) == NUMBER )
+ {
+ ptr->mon_gamma_blue = val.realnum;
+ }
+ else
+ {
+ Error (INVALID_GAMMA_MSG, NULL);
+ }
+ }
+ else
+ xf86unGetToken (token);
+ }
+ 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);
+ }
+ break;
+ case EOF_TOKEN:
+ Error (UNEXPECTED_EOF_MSG, NULL);
+ break;
+ default:
+ xf86parseError (INVALID_KEYWORD_MSG, xf86tokenString ());
+ CLEANUP (ptr);
+ return NULL;
+ break;
+ }
+ }
+
+ 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)
+
+ 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;
+ 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 (!has_ident)
+ Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+ printf ("Modes section parsed\n");
+#endif
+ return ptr;
+}
+
+#undef CLEANUP
+
+void
+xf86printMonitorSection (FILE * cf, XF86ConfMonitorPtr ptr)
+{
+ int i;
+ XF86ConfModeLinePtr mlptr;
+ XF86ConfModesLinkPtr mptr;
+
+ while (ptr)
+ {
+ mptr = ptr->mon_modes_sect_lst;
+ fprintf (cf, "Section \"Monitor\"\n");
+ if (ptr->mon_comment)
+ fprintf (cf, "%s", ptr->mon_comment);
+ if (ptr->mon_identifier)
+ fprintf (cf, "\tIdentifier \"%s\"\n", ptr->mon_identifier);
+ 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) {
+ fprintf (cf, "\tUseModes \"%s\"\n", mptr->ml_modes_str);
+ 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 VertSync 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) {
+ if (ptr->mon_gamma_red == ptr->mon_gamma_green
+ && ptr->mon_gamma_red == ptr->mon_gamma_blue)
+ {
+ fprintf (cf, "\tGamma %.4g\n",
+ ptr->mon_gamma_red);
+ } else {
+ fprintf (cf, "\tGamma %.4g %.4g %.4g\n",
+ ptr->mon_gamma_red,
+ ptr->mon_gamma_green,
+ ptr->mon_gamma_blue);
+ }
+ }
+ for (mlptr = ptr->mon_modeline_lst; mlptr; mlptr = mlptr->list.next)
+ {
+ fprintf (cf, "\tModeLine \"%s\" %2.1f ",
+ mlptr->ml_identifier, mlptr->ml_clock / 1000.0);
+ fprintf (cf, "%d %d %d %d %d %d %d %d",
+ mlptr->ml_hdisplay, mlptr->ml_hsyncstart,
+ mlptr->ml_hsyncend, mlptr->ml_htotal,
+ mlptr->ml_vdisplay, mlptr->ml_vsyncstart,
+ mlptr->ml_vsyncend, mlptr->ml_vtotal);
+ if (mlptr->ml_flags & XF86CONF_PHSYNC)
+ fprintf (cf, " +hsync");
+ if (mlptr->ml_flags & XF86CONF_NHSYNC)
+ fprintf (cf, " -hsync");
+ if (mlptr->ml_flags & XF86CONF_PVSYNC)
+ fprintf (cf, " +vsync");
+ if (mlptr->ml_flags & XF86CONF_NVSYNC)
+ fprintf (cf, " -vsync");
+ if (mlptr->ml_flags & XF86CONF_INTERLACE)
+ fprintf (cf, " interlace");
+ if (mlptr->ml_flags & XF86CONF_CSYNC)
+ fprintf (cf, " composite");
+ if (mlptr->ml_flags & XF86CONF_PCSYNC)
+ fprintf (cf, " +csync");
+ if (mlptr->ml_flags & XF86CONF_NCSYNC)
+ fprintf (cf, " -csync");
+ if (mlptr->ml_flags & XF86CONF_DBLSCAN)
+ fprintf (cf, " doublescan");
+ if (mlptr->ml_flags & XF86CONF_HSKEW)
+ fprintf (cf, " hskew %d", mlptr->ml_hskew);
+ if (mlptr->ml_flags & XF86CONF_BCAST)
+ fprintf (cf, " bcast");
+ fprintf (cf, "\n");
+ }
+ xf86printOptionList(cf, ptr->mon_option_lst, 1);
+ fprintf (cf, "EndSection\n\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)
+ {
+ fprintf (cf, "\tModeLine \"%s\" %2.1f ",
+ mlptr->ml_identifier, mlptr->ml_clock / 1000.0);
+ fprintf (cf, "%d %d %d %d %d %d %d %d",
+ mlptr->ml_hdisplay, mlptr->ml_hsyncstart,
+ mlptr->ml_hsyncend, mlptr->ml_htotal,
+ mlptr->ml_vdisplay, mlptr->ml_vsyncstart,
+ mlptr->ml_vsyncend, mlptr->ml_vtotal);
+ if (mlptr->ml_flags & XF86CONF_PHSYNC)
+ fprintf (cf, " +hsync");
+ if (mlptr->ml_flags & XF86CONF_NHSYNC)
+ fprintf (cf, " -hsync");
+ if (mlptr->ml_flags & XF86CONF_PVSYNC)
+ fprintf (cf, " +vsync");
+ if (mlptr->ml_flags & XF86CONF_NVSYNC)
+ fprintf (cf, " -vsync");
+ if (mlptr->ml_flags & XF86CONF_INTERLACE)
+ fprintf (cf, " interlace");
+ if (mlptr->ml_flags & XF86CONF_CSYNC)
+ fprintf (cf, " composite");
+ if (mlptr->ml_flags & XF86CONF_PCSYNC)
+ fprintf (cf, " +csync");
+ if (mlptr->ml_flags & XF86CONF_NCSYNC)
+ fprintf (cf, " -csync");
+ if (mlptr->ml_flags & XF86CONF_DBLSCAN)
+ fprintf (cf, " doublescan");
+ if (mlptr->ml_flags & XF86CONF_HSKEW)
+ fprintf (cf, " hskew %d", mlptr->ml_hskew);
+ if (mlptr->ml_flags & XF86CONF_VSCAN)
+ fprintf (cf, " vscan %d", mlptr->ml_vscan);
+ if (mlptr->ml_flags & XF86CONF_BCAST)
+ fprintf (cf, " bcast");
+ if (mlptr->ml_comment)
+ fprintf (cf, "%s", mlptr->ml_comment);
+ else
+ fprintf (cf, "\n");
+ }
+ 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);
+}
+
+XF86ConfModesPtr
+xf86findModes (const char *ident, XF86ConfModesPtr p)
+{
+ while (p)
+ {
+ if (xf86nameCompare (ident, p->modes_identifier) == 0)
+ return (p);
+
+ p = p->list.next;
+ }
+ return (NULL);
+}
+
+XF86ConfModeLinePtr
+xf86findModeLine (const char *ident, XF86ConfModeLinePtr p)
+{
+ while (p)
+ {
+ if (xf86nameCompare (ident, p->ml_identifier) == 0)
+ return (p);
+
+ p = p->list.next;
+ }
+ return (NULL);
+}
+
+int
+xf86validateMonitor (XF86ConfigPtr p, XF86ConfScreenPtr screen)
+{
+ XF86ConfMonitorPtr monitor = screen->scrn_monitor;
+ XF86ConfModesLinkPtr modeslnk = monitor->mon_modes_sect_lst;
+ XF86ConfModesPtr modes;
+ while(modeslnk)
+ {
+ modes = xf86findModes (modeslnk->ml_modes_str, p->conf_modes_lst);
+ if (!modes)
+ {
+ xf86validationError (UNDEFINED_MODES_MSG,
+ modeslnk->ml_modes_str,
+ screen->scrn_identifier);
+ return (FALSE);
+ }
+ modeslnk->ml_modes = modes;
+ modeslnk = modeslnk->list.next;
+ }
+ return (TRUE);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Pointer.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Pointer.c
new file mode 100644
index 000000000..81984a3e7
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Pointer.c
@@ -0,0 +1,236 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Pointer.c,v 1.13 2003/08/24 17:37:08 dawes Exp $ */
+/*
+ *
+ * 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)
+ 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
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Screen.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Screen.c
new file mode 100644
index 000000000..d572af56c
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Screen.c
@@ -0,0 +1,578 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Screen.c,v 1.28 2003/11/07 23:41:41 dawes Exp $ */
+/*
+ *
+ * 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 DisplayTab[] =
+{
+ {ENDSUBSECTION, "endsubsection"},
+ {MODES, "modes"},
+ {VIEWPORT, "viewport"},
+ {VIRTUAL, "virtual"},
+ {VISUAL, "visual"},
+ {BLACK_TOK, "black"},
+ {WHITE_TOK, "white"},
+ {DEPTH, "depth"},
+ {BPP, "fbbpp"},
+ {WEIGHT, "weight"},
+ {OPTION, "option"},
+ {-1, ""},
+};
+
+#define CLEANUP xf86freeDisplayList
+
+XF86ConfDisplayPtr
+xf86parseDisplaySubSection (void)
+{
+ int token;
+ parsePrologue (XF86ConfDisplayPtr, XF86ConfDisplayRec)
+
+ 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;
+ while ((token = xf86getToken (DisplayTab)) != ENDSUBSECTION)
+ {
+ 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 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);
+ }
+ 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;
+ }
+ }
+
+#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;
+
+ parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec)
+
+ while ((token = xf86getToken (ScreenTab)) != ENDSECTION)
+ {
+ 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;
+ 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");
+ ptr->scrn_device_str = val.str;
+ break;
+ case MONITOR:
+ if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
+ Error (QUOTE_MSG, "Monitor");
+ ptr->scrn_monitor_str = val.str;
+ 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 (!has_ident && !has_driver)
+ Error (NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+ printf ("Screen section parsed\n");
+#endif
+
+ return ptr;
+}
+
+void
+xf86printScreenSection (FILE * cf, XF86ConfScreenPtr ptr)
+{
+ XF86ConfAdaptorLinkPtr aptr;
+ XF86ConfDisplayPtr dptr;
+ XF86ModePtr mptr;
+
+ while (ptr)
+ {
+ fprintf (cf, "Section \"Screen\"\n");
+ if (ptr->scrn_comment)
+ fprintf (cf, "%s", ptr->scrn_comment);
+ if (ptr->scrn_identifier)
+ fprintf (cf, "\tIdentifier \"%s\"\n", ptr->scrn_identifier);
+ if (ptr->scrn_obso_driver)
+ fprintf (cf, "\tDriver \"%s\"\n", ptr->scrn_obso_driver);
+ if (ptr->scrn_device_str)
+ fprintf (cf, "\tDevice \"%s\"\n", ptr->scrn_device_str);
+ if (ptr->scrn_monitor_str)
+ fprintf (cf, "\tMonitor \"%s\"\n", ptr->scrn_monitor_str);
+ if (ptr->scrn_defaultdepth)
+ fprintf (cf, "\tDefaultDepth %d\n",
+ ptr->scrn_defaultdepth);
+ 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, 1);
+ for (aptr = ptr->scrn_adaptor_lst; aptr; aptr = aptr->list.next)
+ {
+ fprintf (cf, "\tVideoAdaptor \"%s\"\n", aptr->al_adaptor_str);
+ }
+ for (dptr = ptr->scrn_display_lst; dptr; dptr = dptr->list.next)
+ {
+ fprintf (cf, "\tSubSection \"Display\"\n");
+ if (dptr->disp_comment)
+ fprintf (cf, "%s", dptr->disp_comment);
+ 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)
+ {
+ fprintf (cf, "\t\tModes ");
+ }
+ for (mptr = dptr->disp_mode_lst; mptr; mptr = mptr->list.next)
+ {
+ fprintf (cf, " \"%s\"", mptr->mode_name);
+ }
+ if (dptr->disp_mode_lst)
+ {
+ fprintf (cf, "\n");
+ }
+ xf86printOptionList(cf, dptr->disp_option_lst, 2);
+ fprintf (cf, "\tEndSubSection\n");
+ }
+ fprintf (cf, "EndSection\n\n");
+ ptr = ptr->list.next;
+ }
+
+}
+
+void
+xf86freeScreenList (XF86ConfScreenPtr ptr)
+{
+ XF86ConfScreenPtr prev;
+
+ while (ptr)
+ {
+ TestFree (ptr->scrn_identifier);
+ TestFree (ptr->scrn_monitor_str);
+ TestFree (ptr->scrn_device_str);
+ TestFree (ptr->scrn_comment);
+ xf86optionListFree (ptr->scrn_option_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);
+ }
+}
+
+int
+xf86validateScreen (XF86ConfigPtr p)
+{
+ XF86ConfScreenPtr screen = p->conf_screen_lst;
+ XF86ConfMonitorPtr monitor;
+ XF86ConfDevicePtr device;
+ XF86ConfAdaptorLinkPtr adaptor;
+
+ if (!screen)
+ {
+ xf86validationError ("At least one Screen section is required.");
+ return (FALSE);
+ }
+
+ while (screen)
+ {
+ if (screen->scrn_obso_driver && !screen->scrn_identifier)
+ screen->scrn_identifier = screen->scrn_obso_driver;
+
+ monitor = xf86findMonitor (screen->scrn_monitor_str, p->conf_monitor_lst);
+ if (screen->scrn_monitor_str)
+ {
+ if (!monitor)
+ {
+ xf86validationError (UNDEFINED_MONITOR_MSG,
+ screen->scrn_monitor_str, screen->scrn_identifier);
+ return (FALSE);
+ }
+ else
+ {
+ screen->scrn_monitor = monitor;
+ if (!xf86validateMonitor(p, screen))
+ 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);
+ }
+ else
+ 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);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Vendor.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Vendor.c
new file mode 100644
index 000000000..9c6469bb8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Vendor.c
@@ -0,0 +1,258 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Vendor.c,v 1.17 2003/08/24 17:37:08 dawes Exp $ */
+/*
+ *
+ * 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 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, 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, 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);
+}
+
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/Video.c b/nx-X11/programs/Xserver/hw/xfree86/parser/Video.c
new file mode 100644
index 000000000..88788aea8
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/Video.c
@@ -0,0 +1,297 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Video.c,v 1.13 2003/08/24 17:37:08 dawes Exp $ */
+/*
+ *
+ * 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 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, 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, 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);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/configProcs.h b/nx-X11/programs/Xserver/hw/xfree86/parser/configProcs.h
new file mode 100644
index 000000000..bb5f4e9b2
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/configProcs.h
@@ -0,0 +1,132 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/configProcs.h,v 1.17 2003/08/24 17:37:08 dawes Exp $ */
+/*
+ * 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).
+ */
+
+/* Private procs. Public procs are in xf86Parser.h and xf86Optrec.h */
+
+/* Device.c */
+XF86ConfDevicePtr xf86parseDeviceSection(void);
+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 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, XF86ConfScreenPtr screen);
+/* Pointer.c */
+XF86ConfInputPtr xf86parsePointerSection(void);
+/* Screen.c */
+XF86ConfDisplayPtr xf86parseDisplaySubSection(void);
+XF86ConfScreenPtr xf86parseScreenSection(void);
+void xf86printScreenSection(FILE *cf, XF86ConfScreenPtr ptr);
+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 */
+int xf86validateConfig(XF86ConfigPtr p);
+/* scan.c */
+unsigned int xf86strToUL(char *str);
+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
+/* Externally provided functions */
+void ErrorF(const char *f, ...);
+void VErrorF(const char *f, va_list args);
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/cpconfig.c b/nx-X11/programs/Xserver/hw/xfree86/parser/cpconfig.c
new file mode 100644
index 000000000..4eb635b30
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/cpconfig.c
@@ -0,0 +1,123 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/cpconfig.c,v 1.6 2000/10/20 14:59:03 alanh Exp $ */
+/*
+ *
+ * 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.
+ *
+ */
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include "xf86Parser.h"
+#include "configProcs.h"
+
+#ifdef MALLOC_FUNCTIONS
+void
+xfree (void *p)
+{
+ free (p);
+ return;
+}
+
+void *
+xalloc (int size)
+{
+ return malloc (size);
+}
+
+void *
+xrealloc (void *p, int size)
+{
+ return realloc (p, size);
+}
+
+#endif
+
+#define CONFPATH "%A,%R,/etc/X11/%R,%P/etc/X11/%R,%E,%F,/etc/X11/%F," \
+ "%P/etc/X11/%F,%D/%X,/etc/X11/%X,/etc/%X,%P/etc/X11/%X.%H," \
+ "%P/etc/X11/%X,%P/lib/X11/%X.%H,%P/lib/X11/%X"
+
+int
+main (int argc, char *argv[])
+{
+ const char *filename;
+ char *cmdline = NULL;
+ XF86ConfigPtr conf;
+
+ if (argc > 1)
+ {
+ cmdline = argv[1];
+ }
+ if ((filename = xf86openConfigFile (CONFPATH, cmdline, NULL)))
+ {
+ fprintf (stderr, "Opened %s for the config file\n", filename);
+ }
+ else
+ {
+ fprintf (stderr, "Unable to open config file\n");
+ exit (1);
+ }
+
+ if ((conf = xf86readConfigFile ()) == NULL)
+ {
+ fprintf (stderr, "Problem when parsing config file\n");
+ }
+ else
+ {
+ fprintf (stderr, "Config file parsed OK\n");
+ }
+ xf86closeConfigFile ();
+
+ if (argc > 2) {
+ fprintf(stderr, "Writing config file to `%s'\n", argv[2]);
+ xf86writeConfigFile (argv[2], conf);
+ }
+ exit(0);
+}
+
+/* Functions that the parser requires */
+
+void
+VErrorF(const char *f, va_list args)
+{
+ vfprintf(stderr, f, args);
+}
+
+void
+ErrorF(const char *f, ...)
+{
+ va_list args;
+
+ va_start(args, f);
+ vfprintf(stderr, f, args);
+ va_end(args);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/read.c b/nx-X11/programs/Xserver/hw/xfree86/parser/read.c
new file mode 100644
index 000000000..59b0ea6fb
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/read.c
@@ -0,0 +1,321 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/read.c,v 1.24 2003/08/24 17:37:08 dawes Exp $ */
+/*
+ *
+ * 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, ""},
+};
+
+#define CLEANUP xf86freeConfig
+
+XF86ConfigPtr
+xf86readConfigFile (void)
+{
+ int token;
+ XF86ConfigPtr ptr = NULL;
+
+ if ((ptr = xf86confcalloc (1, sizeof (XF86ConfigRec))) == NULL)
+ {
+ return NULL;
+ }
+ memset (ptr, 0, sizeof (XF86ConfigRec));
+
+ 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;
+ }
+ }
+
+ if (xf86validateConfig (ptr))
+ return (ptr);
+ else
+ {
+ CLEANUP (ptr);
+ return (NULL);
+ }
+}
+
+#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);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/scan.c b/nx-X11/programs/Xserver/hw/xfree86/parser/scan.c
new file mode 100644
index 000000000..ce3cda128
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/scan.c
@@ -0,0 +1,949 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/scan.c,v 1.30 2003/11/03 05:11:52 tsi Exp $ */
+/*
+ *
+ * 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 "Configint.h"
+#include "xf86tokens.h"
+
+#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 */
+static char *configBuf, *configRBuf; /* buffer for lines */
+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);
+}
+
+/*
+ * xf86getToken --
+ * Read next Token form the config file. Handle the global variable
+ * pushToken.
+ */
+int
+xf86getToken (xf86ConfigSymTabRec * tab)
+{
+ int c, i;
+
+ /*
+ * First check whether pushToken has a different value than LOCK_TOKEN.
+ * In this case rBuf[] contains a valid STRING/TOKEN/NUMBER. But in the
+ * oth * case 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)
+ ret = fgets (configBuf, CONFIG_BUF_LEN - 1, configFile);
+ 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;
+ }
+
+ 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;
+
+ 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 */
+}
+
+int
+xf86getSubToken (char **comment)
+{
+ int token;
+
+ for (;;) {
+ token = xf86getToken(NULL);
+ if (token == COMMENT) {
+ if (comment)
+ *comment = xf86addComment(*comment, val.str);
+ }
+ else
+ return (token);
+ }
+ /*NOTREACHED*/
+}
+
+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, 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
+ return result;
+}
+
+/*
+ * xf86openConfigFile --
+ *
+ * This function take 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. If a
+ * command-line file name is specified, then this function fails if none
+ * of the located files.
+ *
+ * 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.
+ *
+ */
+
+#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
+
+const char *
+xf86openConfigFile(const char *path, const char *cmdline, const char *projroot)
+{
+ char *pathcopy;
+ const char *template;
+ int cmdlineUsed = 0;
+
+ configFile = NULL;
+ configPos = 0; /* current readers position */
+ configLineNo = 0; /* linenumber */
+ pushToken = LOCK_TOKEN;
+
+ if (!path || !path[0])
+ path = DEFAULT_CONF_PATH;
+ pathcopy = xf86confmalloc(strlen(path) + 1);
+ strcpy(pathcopy, path);
+ if (!projroot || !projroot[0])
+ projroot = PROJECTROOT;
+
+ template = strtok(pathcopy, ",");
+
+ /* First, search for a config file. */
+ while (template && !configFile) {
+ if ((configPath = DoSubstitution(template, cmdline, projroot,
+ &cmdlineUsed, NULL,
+ XCONFIGFILE))) {
+ if ((configFile = fopen(configPath, "r")) != 0) {
+ if (cmdline && !cmdlineUsed) {
+ fclose(configFile);
+ configFile = NULL;
+ }
+ }
+ }
+ if (configPath && !configFile) {
+ xf86conffree(configPath);
+ configPath = NULL;
+ }
+ template = strtok(NULL, ",");
+ }
+
+ /* Then search for fallback */
+ if (!configFile) {
+ strcpy(pathcopy, path);
+ template = strtok(pathcopy, ",");
+
+ while (template && !configFile) {
+ if ((configPath = DoSubstitution(template, cmdline, projroot,
+ &cmdlineUsed, NULL,
+ XFREE86CFGFILE))) {
+ if ((configFile = fopen(configPath, "r")) != 0) {
+ if (cmdline && !cmdlineUsed) {
+ fclose(configFile);
+ configFile = NULL;
+ }
+ }
+ }
+ if (configPath && !configFile) {
+ xf86conffree(configPath);
+ configPath = NULL;
+ }
+ template = strtok(NULL, ",");
+ }
+ }
+
+ xf86conffree(pathcopy);
+ if (!configFile) {
+
+ return NULL;
+ }
+
+ configBuf = xf86confmalloc (CONFIG_BUF_LEN);
+ configRBuf = xf86confmalloc (CONFIG_BUF_LEN);
+ configBuf[0] = '\0'; /* sanity ... */
+
+ return configPath;
+}
+
+void
+xf86closeConfigFile (void)
+{
+ xf86conffree (configPath);
+ configPath = NULL;
+ xf86conffree (configRBuf);
+ configRBuf = NULL;
+ xf86conffree (configBuf);
+ configBuf = NULL;
+
+ if (configFile) {
+ 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);
+ configRBuf = xf86confmalloc (CONFIG_BUF_LEN);
+ configBuf[0] = '\0'; /* sanity ... */
+
+}
+
+void
+xf86parseError (char *format,...)
+{
+ va_list ap;
+
+ ErrorF ("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;
+
+ ErrorF ("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;
+
+ ErrorF ("Data incomplete in 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);
+}
+
+
+/*
+ * Compare two names. The characters '_', ' ', and '\t' are ignored
+ * in the comparison.
+ */
+int
+xf86nameCompare (const char *s1, const char *s2)
+{
+ char c1, c2;
+
+ if (!s1 || *s1 == 0) {
+ if (!s2 || *s2 == 0)
+ return (0);
+ else
+ return (1);
+ }
+
+ while (*s1 == '_' || *s1 == ' ' || *s1 == '\t')
+ s1++;
+ while (*s2 == '_' || *s2 == ' ' || *s2 == '\t')
+ s2++;
+ c1 = (isupper (*s1) ? tolower (*s1) : *s1);
+ c2 = (isupper (*s2) ? tolower (*s2) : *s2);
+ while (c1 == c2)
+ {
+ if (c1 == '\0')
+ return (0);
+ s1++;
+ s2++;
+ while (*s1 == '_' || *s1 == ' ' || *s1 == '\t')
+ s1++;
+ while (*s2 == '_' || *s2 == ' ' || *s2 == '\t')
+ s2++;
+ c1 = (isupper (*s1) ? tolower (*s1) : *s1);
+ c2 = (isupper (*s2) ? tolower (*s2) : *s2);
+ }
+ return (c1 - c2);
+}
+
+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);
+}
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/write.c b/nx-X11/programs/Xserver/hw/xfree86/parser/write.c
new file mode 100644
index 000000000..285080d99
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/write.c
@@ -0,0 +1,220 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/write.c,v 1.18 2003/08/24 17:37:08 dawes Exp $ */
+/*
+ *
+ * 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 <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <errno.h>
+
+#if ((defined(sun) && !defined(SVR4)) || defined(macII)) && !defined(__GLIBC__)
+#ifndef strerror
+extern char *sys_errlist[];
+extern int sys_nerr;
+#define strerror(n) \
+ (((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error")
+#endif
+#endif
+
+#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
+#define HAS_SAVED_IDS_AND_SETEUID
+#endif
+#if defined(__UNIXOS2__) || defined(WIN32)
+#define HAS_NO_UIDS
+#endif
+
+#ifdef HAS_NO_UIDS
+#define doWriteConfigFile xf86writeConfigFile
+#define Local /**/
+#else
+#define Local static
+#endif
+
+Local int
+doWriteConfigFile (const char *filename, XF86ConfigPtr cptr)
+{
+ FILE *cf;
+
+ if ((cf = fopen (filename, "w")) == NULL)
+ {
+ return 0;
+ }
+
+ if (cptr->conf_comment)
+ fprintf (cf, "%s\n", cptr->conf_comment);
+
+ xf86printLayoutSection (cf, cptr->conf_layout_lst);
+
+ fprintf (cf, "Section \"Files\"\n");
+ xf86printFileSection (cf, cptr->conf_files);
+ fprintf (cf, "EndSection\n\n");
+
+ fprintf (cf, "Section \"Module\"\n");
+ xf86printModuleSection (cf, cptr->conf_modules);
+ fprintf (cf, "EndSection\n\n");
+
+ xf86printVendorSection (cf, cptr->conf_vendor_lst);
+
+ xf86printServerFlagsSection (cf, cptr->conf_flags);
+
+ xf86printInputSection (cf, cptr->conf_input_lst);
+
+ xf86printVideoAdaptorSection (cf, cptr->conf_videoadaptor_lst);
+
+ xf86printModesSection (cf, cptr->conf_modes_lst);
+
+ xf86printMonitorSection (cf, cptr->conf_monitor_lst);
+
+ xf86printDeviceSection (cf, cptr->conf_device_lst);
+
+ xf86printScreenSection (cf, cptr->conf_screen_lst);
+
+ xf86printDRISection (cf, cptr->conf_dri);
+
+ xf86printExtensionsSection (cf, cptr->conf_extensions);
+
+ fclose(cf);
+ return 1;
+}
+
+#ifndef HAS_NO_UIDS
+
+int
+xf86writeConfigFile (const char *filename, XF86ConfigPtr cptr)
+{
+ int ret;
+
+#if !defined(HAS_SAVED_IDS_AND_SETEUID)
+ int pid, p;
+ int status;
+ void (*csig)(int);
+#else
+ int ruid, euid;
+#endif
+
+ if (getuid() != geteuid())
+ {
+
+#if !defined(HAS_SAVED_IDS_AND_SETEUID)
+ /* Need to fork to change ruid without loosing euid */
+#ifdef SIGCHLD
+ csig = signal(SIGCHLD, SIG_DFL);
+#endif
+ switch ((pid = fork()))
+ {
+ case -1:
+ ErrorF("xf86writeConfigFile(): fork failed (%s)\n",
+ strerror(errno));
+ return 0;
+ case 0: /* child */
+ setuid(getuid());
+ ret = doWriteConfigFile(filename, cptr);
+ exit(ret);
+ break;
+ default: /* parent */
+ do
+ {
+ p = waitpid(pid, &status, 0);
+ } while (p == -1 && errno == EINTR);
+ }
+#ifdef SIGCHLD
+ signal(SIGCHLD, csig);
+#endif
+ if (p != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0)
+ return 1; /* success */
+ else
+ return 0;
+
+#else /* HAS_SAVED_IDS_AND_SETEUID */
+
+ ruid = getuid();
+ euid = geteuid();
+
+ if (seteuid(ruid) == -1)
+ {
+ ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
+ ruid, strerror(errno));
+ return 0;
+ }
+ ret = doWriteConfigFile(filename, cptr);
+
+ if (seteuid(euid) == -1)
+ {
+ ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
+ euid, strerror(errno));
+ }
+ return ret;
+
+#endif /* HAS_SAVED_IDS_AND_SETEUID */
+
+ }
+ else
+ {
+ return doWriteConfigFile(filename, cptr);
+ }
+}
+
+#endif /* !HAS_NO_UIDS */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/xf86Optrec.h b/nx-X11/programs/Xserver/hw/xfree86/parser/xf86Optrec.h
new file mode 100644
index 000000000..c38f2c219
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/xf86Optrec.h
@@ -0,0 +1,113 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/xf86Optrec.h,v 1.11 2003/08/24 17:37:08 dawes Exp $ */
+/*
+ *
+ * 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;
+}
+XF86OptionRec, *XF86OptionPtr;
+
+
+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);
+char *xf86uLongToString(unsigned long i);
+void xf86debugListOptions(XF86OptionPtr);
+XF86OptionPtr xf86parseOption(XF86OptionPtr head);
+void xf86printOptionList(FILE *fp, XF86OptionPtr list, int tabs);
+
+
+#endif /* _xf86Optrec_h_ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/xf86Parser.h b/nx-X11/programs/Xserver/hw/xfree86/parser/xf86Parser.h
new file mode 100644
index 000000000..71568842d
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/xf86Parser.h
@@ -0,0 +1,483 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/xf86Parser.h,v 1.33 2003/10/08 14:58:30 dawes Exp $ */
+/*
+ *
+ * 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.
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifndef _xf86Parser_h_
+#define _xf86Parser_h_
+
+#include "xf86Optrec.h"
+
+#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;
+}
+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"
+
+#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
+
+typedef struct
+{
+ GenericListRec list;
+ char *ml_identifier;
+ int ml_clock;
+ int ml_hdisplay;
+ int ml_hsyncstart;
+ int ml_hsyncend;
+ int ml_htotal;
+ int ml_vdisplay;
+ int ml_vsyncstart;
+ int ml_vsyncend;
+ int ml_vtotal;
+ int ml_vscan;
+ int ml_flags;
+ int ml_hskew;
+ char *ml_comment;
+}
+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;
+
+typedef struct
+{
+ GenericListRec list;
+ char *modes_identifier;
+ XF86ConfModeLinePtr mon_modeline_lst;
+ char *modes_comment;
+}
+XF86ConfModesRec, *XF86ConfModesPtr;
+
+typedef struct
+{
+ GenericListRec list;
+ char *ml_modes_str;
+ XF86ConfModesPtr ml_modes;
+}
+XF86ConfModesLinkRec, *XF86ConfModesLinkPtr;
+
+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;
+}
+XF86ConfMonitorRec, *XF86ConfMonitorPtr;
+
+#define CONF_MAXDACSPEEDS 4
+#define CONF_MAXCLOCKS 128
+
+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;
+}
+XF86ConfDeviceRec, *XF86ConfDevicePtr;
+
+typedef struct
+{
+ GenericListRec list;
+ char *mode_name;
+}
+XF86ModeRec, *XF86ModePtr;
+
+typedef struct
+{
+ GenericListRec list;
+ int disp_frameX0;
+ int disp_frameY0;
+ int disp_virtualX;
+ int disp_virtualY;
+ 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;
+}
+XF86ConfDisplayRec, *XF86ConfDisplayPtr;
+
+typedef struct
+{
+ XF86OptionPtr flg_option_lst;
+ char *flg_comment;
+}
+XF86ConfFlagsRec, *XF86ConfFlagsPtr;
+
+typedef struct
+{
+ GenericListRec list;
+ char *al_adaptor_str;
+ XF86ConfVideoAdaptorPtr al_adaptor;
+}
+XF86ConfAdaptorLinkRec, *XF86ConfAdaptorLinkPtr;
+
+typedef struct
+{
+ GenericListRec list;
+ char *scrn_identifier;
+ char *scrn_obso_driver;
+ int scrn_defaultdepth;
+ int scrn_defaultbpp;
+ int scrn_defaultfbbpp;
+ char *scrn_monitor_str;
+ XF86ConfMonitorPtr scrn_monitor;
+ char *scrn_device_str;
+ XF86ConfDevicePtr scrn_device;
+ XF86ConfAdaptorLinkPtr scrn_adaptor_lst;
+ XF86ConfDisplayPtr scrn_display_lst;
+ XF86OptionPtr scrn_option_lst;
+ char *scrn_comment;
+}
+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);
+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_ */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/parser/xf86tokens.h b/nx-X11/programs/Xserver/hw/xfree86/parser/xf86tokens.h
new file mode 100644
index 000000000..3c7e68ece
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/parser/xf86tokens.h
@@ -0,0 +1,280 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/xf86tokens.h,v 1.20 2003/08/24 17:37:09 dawes Exp $ */
+/*
+ *
+ * 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 */
diff --git a/nx-X11/programs/Xserver/hw/xfree86/xf86Date.h b/nx-X11/programs/Xserver/hw/xfree86/xf86Date.h
new file mode 100644
index 000000000..ce2b6ee24
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/xf86Date.h
@@ -0,0 +1,38 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/xf86Date.h,v 1.6 2005/07/03 07:01:24 daniels Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/xf86Date.h,v 1.54 2003/12/19 04:52:10 dawes Exp $ */
+/*
+ * Copyright (c) 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_DATE
+
+#define XF86_DATE "18 December 2003"
+
+#endif
diff --git a/nx-X11/programs/Xserver/hw/xfree86/xf86Version.h b/nx-X11/programs/Xserver/hw/xfree86/xf86Version.h
new file mode 100644
index 000000000..3996c3581
--- /dev/null
+++ b/nx-X11/programs/Xserver/hw/xfree86/xf86Version.h
@@ -0,0 +1,62 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/xf86Version.h,v 1.5 2005/08/24 11:18:35 daniels Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/xf86Version.h,v 3.566 2003/12/19 04:52:11 dawes Exp $ */
+
+/*
+ * Copyright (c) 1994-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).
+ */
+
+#ifndef XF86_VERSION_CURRENT
+
+#define XF86_VERSION_MAJOR 4
+#define XF86_VERSION_MINOR 3
+#define XF86_VERSION_PATCH 99
+#define XF86_VERSION_SNAP 902
+
+/* This has five arguments for compatibilty reasons */
+#define XF86_VERSION_NUMERIC(major,minor,patch,snap,dummy) \
+ (((major) * 10000000) + ((minor) * 100000) + ((patch) * 1000) + snap)
+
+#define XF86_GET_MAJOR_VERSION(vers) ((vers) / 10000000)
+#define XF86_GET_MINOR_VERSION(vers) (((vers) % 10000000) / 100000)
+#define XF86_GET_PATCH_VERSION(vers) (((vers) % 100000) / 1000)
+#define XF86_GET_SNAP_VERSION(vers) ((vers) % 1000)
+
+/* Define these for compatibility. They'll be removed at some point. */
+#define XF86_VERSION_SUBMINOR XF86_VERSION_PATCH
+#define XF86_VERSION_BETA 0
+#define XF86_VERSION_ALPHA XF86_VERSION_SNAP
+
+#define XF86_VERSION_CURRENT \
+ XF86_VERSION_NUMERIC(XF86_VERSION_MAJOR, \
+ XF86_VERSION_MINOR, \
+ XF86_VERSION_PATCH, \
+ XF86_VERSION_SNAP, \
+ 0)
+
+#endif
+
+/* $XConsortium: xf86Version.h /main/78 1996/10/28 05:42:10 kaleb $ */
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/xf86Version.h,v 1.5 2005/08/24 11:18:35 daniels Exp $ */