aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/hw/xfree86/os-support
diff options
context:
space:
mode:
Diffstat (limited to 'nx-X11/programs/Xserver/hw/xfree86/os-support')
-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
240 files changed, 60009 insertions, 0 deletions
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 */