diff options
author | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:49:22 +0000 |
---|---|---|
committer | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 16:49:22 +0000 |
commit | d568221710959cf7d783e6ff0fb80fb43a231124 (patch) | |
tree | 8d6f039393294c6ffac8533639afdebe5d68bfc1 /hw/xfree86/common | |
parent | 9508a382f8a9f241dab097d921b6d290c1c3a776 (diff) |
XFree86 4.3.0.1xf86-4_3_0_1PRE_xf86-4_3_0_1
Diffstat (limited to 'hw/xfree86/common')
-rw-r--r-- | hw/xfree86/common/atKeynames.h | 159 | ||||
-rw-r--r-- | hw/xfree86/common/compiler.h | 2367 | ||||
-rw-r--r-- | hw/xfree86/common/xf86.h | 1080 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Config.c | 5588 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Cursor.c | 750 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Events.c | 1655 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Init.c | 1804 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Io.c | 304 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Kbd.c | 111 | ||||
-rw-r--r-- | hw/xfree86/common/xf86KbdBSD.c | 896 | ||||
-rw-r--r-- | hw/xfree86/common/xf86KbdLnx.c | 142 | ||||
-rw-r--r-- | hw/xfree86/common/xf86KbdMach.c | 9 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Keymap.h | 356 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Priv.h | 321 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Version.h | 38 | ||||
-rw-r--r-- | hw/xfree86/common/xf86XKB.c | 79 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Xinput.c | 1150 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Xinput.h | 379 |
18 files changed, 8612 insertions, 8576 deletions
diff --git a/hw/xfree86/common/atKeynames.h b/hw/xfree86/common/atKeynames.h index 24ae59a30..23760db5e 100644 --- a/hw/xfree86/common/atKeynames.h +++ b/hw/xfree86/common/atKeynames.h @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/atKeynames.h,v 3.9 1996/12/23 06:43:13 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/atKeynames.h,v 3.18 2001/09/29 20:40:30 herrb Exp $ */ /* * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. * @@ -21,7 +21,7 @@ * PERFORMANCE OF THIS SOFTWARE. * */ -/* $Xorg: atKeynames.h,v 1.3 2000/08/17 19:50:28 cpqbld Exp $ */ +/* $XConsortium: atKeynames.h /main/11 1996/03/09 11:17:41 kaleb $ */ #ifndef _ATKEYNAMES_H #define _ATKEYNAMES_H @@ -29,13 +29,12 @@ #define XK_TECHNICAL #define XK_KATAKANA #include "keysym.h" +#include "XF86keysym.h" #define GLYPHS_PER_KEY 4 -#define NUM_KEYCODES 150 -#define NUM_STD_KEYCODES 127 +#define NUM_KEYCODES 248 #define MIN_KEYCODE 8 #define MAX_KEYCODE (NUM_KEYCODES + MIN_KEYCODE - 1) -#define MAX_STD_KEYCODE (NUM_STD_KEYCODES + MIN_KEYCODE - 1) #define AltMask Mod1Mask #define NumLockMask Mod2Mask @@ -46,8 +45,6 @@ #define KeyPressed(k) (keyc->down[k >> 3] & (1 << (k & 7))) #define ModifierDown(k) ((keyc->state & (k)) == (k)) -#define XF86XK_ModeLock 0x1008FF01 /* Mode Switch Lock */ - /* * NOTE: The AT/MF keyboards can generate (via the 8042) two (MF: three) * sets of scancodes. Set3 can only be generated by a MF keyboard. @@ -72,8 +69,6 @@ * ---------------- ---------- ------- ------ ------ */ -#ifndef PC98 - #define KEY_Escape /* Escape 0x01 */ 1 #define KEY_1 /* 1 ! 0x02 */ 2 #define KEY_2 /* 2 @ 0x03 */ 3 @@ -185,7 +180,7 @@ #define KEY_RCtrl /* Ctrl(right) 0x65 */ 101 #define KEY_Pause /* Pause 0x66 */ 102 #define KEY_Print /* Print 0x67 */ 103 -#define KEY_KP_Divide /* Didive 0x68 */ 104 +#define KEY_KP_Divide /* Divide 0x68 */ 104 #define KEY_AltLang /* AtlLang(right) 0x69 */ 105 #define KEY_Break /* Break 0x6a */ 106 #define KEY_LMeta /* Left Meta 0x6b */ 107 @@ -194,142 +189,18 @@ #define KEY_F13 /* F13 0x6e */ 110 #define KEY_F14 /* F14 0x6f */ 111 #define KEY_F15 /* F15 0x70 */ 112 +#define KEY_HKTG /* Hirugana/Katakana tog 0x70 */ 112 #define KEY_F16 /* F16 0x71 */ 113 #define KEY_F17 /* F17 0x72 */ 114 #define KEY_KP_DEC /* KP_DEC 0x73 */ 115 -#define KEY_SN_KP_7 /* ServerNumLock 7 0x80 */ 128 -#define KEY_SN_KP_8 /* ServerNumLock 8 0x81 */ 129 -#define KEY_SN_KP_9 /* ServerNumLock 9 0x82 */ 130 -#define KEY_SN_KP_4 /* ServerNumLock 4 0x83 */ 131 -#define KEY_SN_KP_5 /* ServerNumLock 5 0x84 */ 132 -#define KEY_SN_KP_6 /* ServerNumLock 6 0x85 */ 133 -#define KEY_SN_KP_1 /* ServerNumLock 1 0x86 */ 134 -#define KEY_SN_KP_2 /* ServerNumLock 2 0x87 */ 135 -#define KEY_SN_KP_3 /* ServerNumLock 4 0x88 */ 136 -#define KEY_SN_KP_0 /* ServerNumLock 0 0x89 */ 137 -#define KEY_SN_KP_Dec /* ServerNumLock Decimal 0x8a */ 138 -#define KEY_SN_KP_Home /* ServerNumLock Home 0x8b */ 139 -#define KEY_SN_KP_Up /* ServerNumLock Up 0x8c */ 140 -#define KEY_SN_KP_Prior /* ServerNumLock Prior 0x8d */ 141 -#define KEY_SN_KP_Left /* ServerNumLock Left 0x8e */ 142 -#define KEY_SN_KP_Begin /* ServerNumLock Begin 0x8f */ 143 -#define KEY_SN_KP_Right /* ServerNumLock Right 0x90 */ 144 -#define KEY_SN_KP_End /* ServerNumLock End 0x91 */ 145 -#define KEY_SN_KP_Down /* ServerNumLock Down 0x92 */ 146 -#define KEY_SN_KP_Next /* ServerNumLock Next 0x93 */ 147 -#define KEY_SN_KP_Ins /* ServerNumLock Ins 0x94 */ 148 -#define KEY_SN_KP_Del /* ServerNumLock Del 0x95 */ 149 - -#else - -#define KEY_Escape /* Escape 0x01 */ 0 -#define KEY_1 /* 1 ! 0x02 */ 1 -#define KEY_2 /* 2 " 0x03 */ 2 -#define KEY_3 /* 3 # 0x04 */ 3 -#define KEY_4 /* 4 $ 0x05 */ 4 -#define KEY_5 /* 5 % 0x06 */ 5 -#define KEY_6 /* 6 & 0x07 */ 6 -#define KEY_7 /* 7 ' 0x08 */ 7 -#define KEY_8 /* 8 ( 0x09 */ 8 -#define KEY_9 /* 9 ) 0x0a */ 9 -#define KEY_0 /* 0 0x0b */ 10 -#define KEY_Minus /* - (Minus) = (Equal) 0x0c */ 11 -#define KEY_Hat /* ^ (Hat) ` 0x0d */ 12 -#define KEY_BSlash /* \(BckSlash) |(VertBar)0x2b */ 13 -#define KEY_BackSpace /* Back Space 0x0e */ 14 -#define KEY_Tab /* Tab 0x0f */ 15 -#define KEY_Q /* Q 0x10 */ 16 -#define KEY_W /* W 0x11 */ 17 -#define KEY_E /* E 0x12 */ 18 -#define KEY_R /* R 0x13 */ 19 -#define KEY_T /* T 0x14 */ 20 -#define KEY_Y /* Y 0x15 */ 21 -#define KEY_U /* U 0x16 */ 22 -#define KEY_I /* I 0x17 */ 23 -#define KEY_O /* O 0x18 */ 24 -#define KEY_P /* P 0x19 */ 25 -#define KEY_At /* @ ~ 0x1a */ 26 -#define KEY_LBrace /* [ { 0x1b */ 27 -#define KEY_Enter /* Enter 0x1c */ 28 -#define KEY_A /* A 0x1d */ 29 -#define KEY_S /* S 0x1e */ 30 -#define KEY_D /* D 0x1f */ 31 -#define KEY_F /* F 0x20 */ 32 -#define KEY_G /* G 0x21 */ 33 -#define KEY_H /* H 0x22 */ 34 -#define KEY_J /* J 0x23 */ 35 -#define KEY_K /* K 0x24 */ 36 -#define KEY_L /* L 0x25 */ 37 -#define KEY_SemiColon /* ;(SemiColon) +(Plus) 0x26 */ 38 -#define KEY_Colon /* :(Colon) *(Quote) 0x27 */ 39 -#define KEY_RBrace /* ] } 0x28 */ 40 -#define KEY_Z /* Z 0x29 */ 41 -#define KEY_X /* X 0x2a */ 42 -#define KEY_C /* C 0x2b */ 43 -#define KEY_V /* V 0x2c */ 44 -#define KEY_B /* B 0x2d */ 45 -#define KEY_N /* N 0x2e */ 46 -#define KEY_M /* M 0x2f */ 47 -#define KEY_Comma /* , (Comma) < (Less) 0x30 */ 48 -#define KEY_Period /* . (Period) >(Greater)0x31 */ 49 -#define KEY_Slash /* / (Slash) ? 0x32 */ 50 -#define KEY_Under /* _ 0x33 */ 51 -#define KEY_Space /* (SpaceBar) 0x34 */ 52 -#define KEY_Xfer /* (XFER) 0x35 */ 53 -#define KEY_PgUp /* PgUp 0x36 */ 54 -#define KEY_Pgdown /* (Roll Down) 0x37 */ 55 -#define KEY_Insert /* Insert 0x38 */ 56 -#define KEY_Delete /* Delete 0x39 */ 57 -#define KEY_Up /* Up 0x3a */ 58 -#define KEY_Left /* Left 0x3b */ 59 -#define KEY_Right /* Right 0x3c */ 60 -#define KEY_Down /* Down 0x3d */ 61 -#define KEY_Home /* Home 0x3e */ 62 -#define KEY_Help /* Help 0x3f */ 63 -#define KEY_KP_Subtract /* - (Minus) 0x40 */ 64 -#define KEY_KP_Minus /* - */ 64 -#define KEY_KP_Divide /* / (Slash) 0x41 */ 65 -#define KEY_KP_7 /* 7 0x42 */ 66 -#define KEY_KP_8 /* 8 0x43 */ 67 -#define KEY_KP_9 /* 9 0x44 */ 68 -#define KEY_KP_Multiply /* * 0x45 */ 69 -#define KEY_KP_4 /* 4 0x46 */ 70 -#define KEY_KP_5 /* 5 0x47 */ 71 -#define KEY_KP_6 /* 6 0x48 */ 72 -#define KEY_KP_Add /* + (Plus) 0x49 */ 73 -#define KEY_KP_Plus /* + */ 73 -#define KEY_KP_1 /* 1 0x4a */ 74 -#define KEY_KP_2 /* 2 0x4b */ 75 -#define KEY_KP_3 /* 3 0x4c */ 76 -#define KEY_KP_Equal /* = 0x4d */ 77 -#define KEY_KP_0 /* 0 0x4e */ 78 -#define KEY_KP_Separator /* , 0x4f */ 79 -#define KEY_KP_Decimal /* . (Decimal) 0x50 */ 80 -#define KEY_Nfer /* (NFER) 0x51 */ 81 -#define KEY_F11 /* F11 0x52 */ 82 -#define KEY_F12 /* F12 0x53 */ 83 -#define KEY_F13 /* F13 0x54 */ 84 -#define KEY_F14 /* F14 0x55 */ 85 -#define KEY_F15 /* F15 0x56 */ 86 -#define KEY_Break /* (Stop) 0x60 */ 96 -#define KEY_Copy /* (Copy) 0x61 */ 97 -#define KEY_Begin /* Begin ?? */ 97 -#define KEY_F1 /* F1 0x62 */ 98 -#define KEY_F2 /* F2 0x63 */ 99 -#define KEY_F3 /* F3 0x64 */ 100 -#define KEY_F4 /* F4 0x65 */ 101 -#define KEY_F5 /* F5 0x66 */ 102 -#define KEY_F6 /* F6 0x67 */ 103 -#define KEY_F7 /* F7 0x68 */ 104 -#define KEY_F8 /* F8 0x69 */ 105 -#define KEY_F9 /* F9 0x6a */ 106 -#define KEY_F10 /* F10 0x6b */ 107 -#define KEY_ShiftL /* Shift(left) 0x70 */ 112 -#define KEY_CapsLock /* CapsLock 0x71 */ 113 -#define KEY_KanaLock /* Kana 0x72 */ 114 -#define KEY_Alt /* Alt(left) 0x73 */ 115 -#define KEY_LCtrl /* Ctrl(left) 0x74 */ 116 - -#endif /* PC98 */ +#define KEY_BSlash2 /* \ _ 0x73 */ 115 +#define KEY_KP_Equal /* Equal (Keypad) 0x76 */ 118 +#define KEY_XFER /* Kanji Transfer 0x79 */ 121 +#define KEY_NFER /* No Kanji Transfer 0x7b */ 123 +#define KEY_Yen /* Yen 0x7d */ 125 + +/* These are for "notused" and "unknown" entries in translation maps. */ +#define KEY_NOTUSED 0 +#define KEY_UNKNOWN 255 #endif /* _ATKEYNAMES_H */ diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h index f85ecd132..4dda2f6c6 100644 --- a/hw/xfree86/common/compiler.h +++ b/hw/xfree86/common/compiler.h @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/compiler.h,v 3.24.2.2 1998/02/07 00:44:37 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/compiler.h,v 3.99 2003/01/29 15:23:20 tsi Exp $ */ /* * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. * @@ -21,182 +21,269 @@ * PERFORMANCE OF THIS SOFTWARE. * */ -/* $Xorg: compiler.h,v 1.3 2000/08/17 19:50:28 cpqbld Exp $ */ +/* $XConsortium: compiler.h /main/16 1996/10/25 15:38:34 kaleb $ */ #ifndef _COMPILER_H -#define _COMPILER_H -#ifndef __STDC__ -# ifdef signed -# undef signed +# if !defined(_XF86_ANSIC_H) && defined(XFree86Module) +# error missing #include "xf86_ansic.h" before #include "compiler.h" # endif -# ifdef volatile -# undef volatile -# endif -# ifdef const -# undef const -# endif -# define signed /**/ -# ifdef __GNUC__ -# define volatile __volatile__ -# define const __const__ -# ifdef PC98 -# undef NO_INLINE -# endif -# else -# define const /**/ -# ifdef PC98 + +# define _COMPILER_H + +/* Allow drivers to use the GCC-supported __inline__ and/or __inline. */ +# ifndef __inline__ +# if defined(__GNUC__) + /* gcc has __inline__ */ +# elif defined(__HIGHC__) +# define __inline__ _Inline +# else # define __inline__ /**/ # endif -# endif /* __GNUC__ */ -#endif /* !__STDC__ */ - -#if defined(IODEBUG) && defined(__GNUC__) -#define outb RealOutb -#define outw RealOutw -#define outl RealOutl -#define inb RealInb -#define inw RealInw -#define inl RealInl -#endif +# endif /* __inline__ */ +# ifndef __inline +# if defined(__GNUC__) + /* gcc has __inline */ +# elif defined(__HIGHC__) +# define __inline _Inline +# else +# define __inline /**/ +# endif +# endif /* __inline */ + +# if defined(IODEBUG) && defined(__GNUC__) +# define outb RealOutb +# define outw RealOutw +# define outl RealOutl +# define inb RealInb +# define inw RealInw +# define inl RealInl +# endif + +# if defined(QNX4) /* Do this for now to keep Watcom happy */ +# define outb outp +# define outw outpw +# define outl outpd +# define inb inp +# define inw inpw +# define inl inpd + +/* Define the ffs function for inlining */ +extern int ffs(unsigned long); +# pragma aux ffs_ = \ + "bsf edx, eax" \ + "jnz bits_set" \ + "xor eax, eax" \ + "jmp exit1" \ + "bits_set:" \ + "mov eax, edx" \ + "inc eax" \ + "exit1:" \ + __parm [eax] \ + __modify [eax edx] \ + __value [eax] \ + ; +# endif + +# if defined(NO_INLINE) || defined(DO_PROTOTYPES) + +# if !defined(__sparc__) && !defined(__arm32__) \ + && !(defined(__alpha__) && defined(linux)) + +extern void outb(unsigned short, unsigned char); +extern void outw(unsigned short, unsigned short); +extern void outl(unsigned short, unsigned int); +extern unsigned int inb(unsigned short); +extern unsigned int inw(unsigned short); +extern unsigned int inl(unsigned short); + +# else /* __sparc__, __arm32__, __alpha__*/ + +extern void outb(unsigned long, unsigned char); +extern void outw(unsigned long, unsigned short); +extern void outl(unsigned long, unsigned int); +extern unsigned int inb(unsigned long); +extern unsigned int inw(unsigned long); +extern unsigned int inl(unsigned long); + +# endif /* __sparc__, __arm32__, __alpha__ */ + +extern unsigned long ldq_u(unsigned long *); +extern unsigned long ldl_u(unsigned int *); +extern unsigned long ldw_u(unsigned short *); +extern void stq_u(unsigned long, unsigned long *); +extern void stl_u(unsigned long, unsigned int *); +extern void stw_u(unsigned long, unsigned short *); +extern void mem_barrier(void); +extern void write_mem_barrier(void); +extern void stl_brx(unsigned long, volatile unsigned char *, int); +extern void stw_brx(unsigned short, volatile unsigned char *, int); +extern unsigned long ldl_brx(volatile unsigned char *, int); +extern unsigned short ldw_brx(volatile unsigned char *, int); + +# endif + +# ifndef NO_INLINE +# ifdef __GNUC__ +# if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && defined(__alpha__) -#ifdef NO_INLINE - -extern void outb(); -extern void outw(); -extern void outl(); -extern unsigned int inb(); -extern unsigned int inw(); -extern unsigned int inl(); -#if NeedFunctionPrototypes -extern unsigned char rdinx(unsigned short int, unsigned char); -extern void wrinx(unsigned short int, unsigned char, unsigned char); -extern void modinx(unsigned short int, unsigned char, unsigned char, unsigned char); -extern int testrg(unsigned short int, unsigned char); -extern int testinx2(unsigned short int, unsigned char, unsigned char); -extern int testinx(unsigned short int, unsigned char); -#else /* NeedFunctionProtoypes */ -extern unsigned char rdinx(); -extern void wrinx(); -extern void modinx(); -extern int testrg(); -extern int testinx2(); -extern int testinx(); -#endif /* NeedFunctionProtoypes */ - -#else /* NO_INLINE */ - -#ifdef __GNUC__ - -#if defined(linux) && defined(__alpha__) +# ifdef linux /* for Linux on Alpha, we use the LIBC _inx/_outx routines */ /* note that the appropriate setup via "ioperm" needs to be done */ /* *before* any inx/outx is done. */ +extern void (*_alpha_outb)(char val, unsigned long port); static __inline__ void -outb(port, val) - unsigned short port; - char val; +outb(unsigned long port, unsigned char val) { - extern void _outb(char val, unsigned short port); - _outb(val, port); + _alpha_outb(val, port); } +extern void (*_alpha_outw)(short val, unsigned long port); static __inline__ void -outw(port, val) - unsigned short port; - short val; +outw(unsigned long port, unsigned short val) { - extern void _outw(short val, unsigned short port); - _outw(val, port); + _alpha_outw(val, port); } +extern void (*_alpha_outl)(int val, unsigned long port); static __inline__ void -outl(port, val) - unsigned short port; - int val; +outl(unsigned long port, unsigned int val) { - extern void _outl(int val, unsigned short port); - _outl(val, port); + _alpha_outl(val, port); } +extern unsigned int (*_alpha_inb)(unsigned long port); static __inline__ unsigned int -inb(port) - unsigned short port; +inb(unsigned long port) { - extern unsigned int _inb(unsigned short port); - return _inb(port); + return _alpha_inb(port); } +extern unsigned int (*_alpha_inw)(unsigned long port); static __inline__ unsigned int -inw(port) - unsigned short port; +inw(unsigned long port) { - extern unsigned int _inw(unsigned short port); - return _inw(port); + return _alpha_inw(port); } +extern unsigned int (*_alpha_inl)(unsigned long port); static __inline__ unsigned int -inl(port) - unsigned short port; +inl(unsigned long port) { - extern unsigned int _inl(unsigned short port); - return _inl(port); + return _alpha_inl(port); } +# endif /* linux */ + +# if (defined(__FreeBSD__) || defined(__OpenBSD__)) \ + && !defined(DO_PROTOTYPES) + +/* for FreeBSD and OpenBSD on Alpha, we use the libio (resp. libalpha) */ +/* inx/outx routines */ +/* note that the appropriate setup via "ioperm" needs to be done */ +/* *before* any inx/outx is done. */ + +extern void outb(unsigned int port, unsigned char val); +extern void outw(unsigned int port, unsigned short val); +extern void outl(unsigned int port, unsigned int val); +extern unsigned char inb(unsigned int port); +extern unsigned short inw(unsigned int port); +extern unsigned int inl(unsigned int port); + +# endif /* (__FreeBSD__ || __OpenBSD__ ) && !DO_PROTOTYPES */ + + +#if defined(__NetBSD__) +#include <machine/pio.h> +#endif /* __NetBSD__ */ /* * inline functions to do unaligned accesses * from linux/include/asm-alpha/unaligned.h */ +/* + * EGCS 1.1 knows about arbitrary unaligned loads. Define some + * packed structures to talk about such things with. + */ + +struct __una_u64 { unsigned long x __attribute__((packed)); }; +struct __una_u32 { unsigned int x __attribute__((packed)); }; +struct __una_u16 { unsigned short x __attribute__((packed)); }; + +/* + * Elemental unaligned loads + */ +/* let's try making these things static */ + static __inline__ unsigned long ldq_u(unsigned long * r11) { +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + const struct __una_u64 *ptr = (const struct __una_u64 *) r11; + return ptr->x; +# else unsigned long r1,r2; __asm__("ldq_u %0,%3\n\t" "ldq_u %1,%4\n\t" "extql %0,%2,%0\n\t" - "extqh %1,%2,%1\n\t" - "bis %1,%0,%0" + "extqh %1,%2,%1" :"=&r" (r1), "=&r" (r2) :"r" (r11), "m" (*r11), - "m" (*(unsigned long *)(7+(char *) r11))); - return r1; + "m" (*(const unsigned long *)(7+(char *) r11))); + return r1 | r2; +# endif } static __inline__ unsigned long ldl_u(unsigned int * r11) { +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + const struct __una_u32 *ptr = (const struct __una_u32 *) r11; + return ptr->x; +# else unsigned long r1,r2; __asm__("ldq_u %0,%3\n\t" "ldq_u %1,%4\n\t" "extll %0,%2,%0\n\t" - "extlh %1,%2,%1\n\t" - "bis %1,%0,%0" + "extlh %1,%2,%1" :"=&r" (r1), "=&r" (r2) :"r" (r11), "m" (*r11), - "m" (*(unsigned long *)(3+(char *) r11))); - return r1; + "m" (*(const unsigned long *)(3+(char *) r11))); + return r1 | r2; +# endif } static __inline__ unsigned long ldw_u(unsigned short * r11) { +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + const struct __una_u16 *ptr = (const struct __una_u16 *) r11; + return ptr->x; +# else unsigned long r1,r2; __asm__("ldq_u %0,%3\n\t" "ldq_u %1,%4\n\t" "extwl %0,%2,%0\n\t" - "extwh %1,%2,%1\n\t" - "bis %1,%0,%0" + "extwh %1,%2,%1" :"=&r" (r1), "=&r" (r2) :"r" (r11), "m" (*r11), - "m" (*(unsigned long *)(1+(char *) r11))); - return r1; + "m" (*(const unsigned long *)(1+(char *) r11))); + return r1 | r2; +# endif } +/* + * Elemental unaligned stores + */ + static __inline__ void stq_u(unsigned long r5, unsigned long * r11) { +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + struct __una_u64 *ptr = (struct __una_u64 *) r11; + ptr->x = r5; +# else unsigned long r1,r2,r3,r4; __asm__("ldq_u %3,%1\n\t" @@ -213,10 +300,15 @@ static __inline__ void stq_u(unsigned long r5, unsigned long * r11) "=m" (*(unsigned long *)(7+(char *) r11)), "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4) :"r" (r5), "r" (r11)); +# endif } static __inline__ void stl_u(unsigned long r5, unsigned int * r11) { +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + struct __una_u32 *ptr = (struct __una_u32 *) r11; + ptr->x = r5; +# else unsigned long r1,r2,r3,r4; __asm__("ldq_u %3,%1\n\t" @@ -233,10 +325,15 @@ static __inline__ void stl_u(unsigned long r5, unsigned int * r11) "=m" (*(unsigned long *)(3+(char *) r11)), "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4) :"r" (r5), "r" (r11)); +# endif } static __inline__ void stw_u(unsigned long r5, unsigned short * r11) { +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + struct __una_u16 *ptr = (struct __una_u16 *) r11; + ptr->x = r5; +# else unsigned long r1,r2,r3,r4; __asm__("ldq_u %3,%1\n\t" @@ -253,66 +350,551 @@ static __inline__ void stw_u(unsigned long r5, unsigned short * r11) "=m" (*(unsigned long *)(1+(char *) r11)), "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4) :"r" (r5), "r" (r11)); +# endif } -#define mem_barrier() __asm__ __volatile__("mb" : : : "memory") -#ifdef __ELF__ -#define write_mem_barrier() __asm__ __volatile__("wmb" : : : "memory") -#else /* ECOFF gas 2.6 doesn't know "wmb" :-( */ -#define write_mem_barrier() mem_barrier() -#endif +/* to flush the I-cache before jumping to code which just got loaded */ +# define PAL_imb 134 +# define istream_mem_barrier() \ + __asm__ __volatile__("call_pal %0 #imb" : : "i" (PAL_imb) : "memory") +# define mem_barrier() __asm__ __volatile__("mb" : : : "memory") +# ifdef __ELF__ +# define write_mem_barrier() __asm__ __volatile__("wmb" : : : "memory") +# else /* ECOFF gas 2.6 doesn't know "wmb" :-( */ +# define write_mem_barrier() mem_barrier() +# endif + + +# elif defined(linux) && defined(__ia64__) + +# include <inttypes.h> + +# include <sys/io.h> + +struct __una_u64 { uint64_t x __attribute__((packed)); }; +struct __una_u32 { uint32_t x __attribute__((packed)); }; +struct __una_u16 { uint16_t x __attribute__((packed)); }; + +static __inline__ unsigned long +__uldq (const unsigned long * r11) +{ + const struct __una_u64 *ptr = (const struct __una_u64 *) r11; + return ptr->x; +} + +static __inline__ unsigned long +__uldl (const unsigned int * r11) +{ + const struct __una_u32 *ptr = (const struct __una_u32 *) r11; + return ptr->x; +} + +static __inline__ unsigned long +__uldw (const unsigned short * r11) +{ + const struct __una_u16 *ptr = (const struct __una_u16 *) r11; + return ptr->x; +} + +static __inline__ void +__ustq (unsigned long r5, unsigned long * r11) +{ + struct __una_u64 *ptr = (struct __una_u64 *) r11; + ptr->x = r5; +} + +static __inline__ void +__ustl (unsigned long r5, unsigned int * r11) +{ + struct __una_u32 *ptr = (struct __una_u32 *) r11; + ptr->x = r5; +} + +static __inline__ void +__ustw (unsigned long r5, unsigned short * r11) +{ + struct __una_u16 *ptr = (struct __una_u16 *) r11; + ptr->x = r5; +} + +# define ldq_u(p) __uldq(p) +# define ldl_u(p) __uldl(p) +# define ldw_u(p) __uldw(p) +# define stq_u(v,p) __ustq(v,p) +# define stl_u(v,p) __ustl(v,p) +# define stw_u(v,p) __ustw(v,p) + +# define mem_barrier() __asm__ __volatile__ ("mf" ::: "memory") +# define write_mem_barrier() __asm__ __volatile__ ("mf" ::: "memory") + +/* + * This is overkill, but for different reasons depending on where it is used. + * This is thus general enough to be used everywhere cache flushes are needed. + * It doesn't handle memory access serialisation by other processors, though. + */ +# define ia64_flush_cache(Addr) \ + __asm__ __volatile__ ( \ + "fc %0;;;" \ + "sync.i;;;" \ + "mf;;;" \ + "srlz.i;;;" \ + :: "r"(Addr) : "memory") + +# undef outb +# undef outw +# undef outl + +# define outb(a,b) _outb(b,a) +# define outw(a,b) _outw(b,a) +# define outl(a,b) _outl(b,a) + +# elif defined(linux) && defined(__x86_64__) + +# include <inttypes.h> + +# define ldq_u(p) (*((unsigned long *)(p))) +# define ldl_u(p) (*((unsigned int *)(p))) +# define ldw_u(p) (*((unsigned short *)(p))) +# define stq_u(v,p) (*(unsigned long *)(p)) = (v) +# define stl_u(v,p) (*(unsigned int *)(p)) = (v) +# define stw_u(v,p) (*(unsigned short *)(p)) = (v) + +# define mem_barrier() \ + __asm__ __volatile__ ("lock; addl $0,0(%%rsp)": : :"memory") +# define write_mem_barrier() \ + __asm__ __volatile__ ("": : :"memory") + + +static __inline__ void +outb(unsigned short port, unsigned char val) +{ + __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port)); +} + + +static __inline__ void +outw(unsigned short port, unsigned short val) +{ + __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port)); +} + +static __inline__ void +outl(unsigned short port, unsigned int val) +{ + __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port)); +} + +static __inline__ unsigned int +inb(unsigned short port) +{ + unsigned char ret; + __asm__ __volatile__("inb %1,%0" : + "=a" (ret) : + "d" (port)); + return ret; +} + +static __inline__ unsigned int +inw(unsigned short port) +{ + unsigned short ret; + __asm__ __volatile__("inw %1,%0" : + "=a" (ret) : + "d" (port)); + return ret; +} + +static __inline__ unsigned int +inl(unsigned short port) +{ + unsigned int ret; + __asm__ __volatile__("inl %1,%0" : + "=a" (ret) : + "d" (port)); + return ret; +} + +# elif (defined(linux) || defined(Lynx) || defined(sun) || defined(__OpenBSD__)) && defined(__sparc__) + +# if !defined(Lynx) +# ifndef ASI_PL +# define ASI_PL 0x88 +# endif + +# define barrier() __asm__ __volatile__(".word 0x8143e00a": : :"memory") + +static __inline__ void +outb(unsigned long port, unsigned char val) +{ + __asm__ __volatile__("stba %0, [%1] %2" + : /* No outputs */ + : "r" (val), "r" (port), "i" (ASI_PL)); + barrier(); +} -#else /* defined(linux) && defined(__alpha__) */ -#if defined(__mips__) +static __inline__ void +outw(unsigned long port, unsigned short val) +{ + __asm__ __volatile__("stha %0, [%1] %2" + : /* No outputs */ + : "r" (val), "r" (port), "i" (ASI_PL)); + barrier(); +} + +static __inline__ void +outl(unsigned long port, unsigned int val) +{ + __asm__ __volatile__("sta %0, [%1] %2" + : /* No outputs */ + : "r" (val), "r" (port), "i" (ASI_PL)); + barrier(); +} + +static __inline__ unsigned int +inb(unsigned long port) +{ + unsigned int ret; + __asm__ __volatile__("lduba [%1] %2, %0" + : "=r" (ret) + : "r" (port), "i" (ASI_PL)); + return ret; +} + +static __inline__ unsigned int +inw(unsigned long port) +{ + unsigned int ret; + __asm__ __volatile__("lduha [%1] %2, %0" + : "=r" (ret) + : "r" (port), "i" (ASI_PL)); + return ret; +} + +static __inline__ unsigned int +inl(unsigned long port) +{ + unsigned int ret; + __asm__ __volatile__("lda [%1] %2, %0" + : "=r" (ret) + : "r" (port), "i" (ASI_PL)); + return ret; +} + +static __inline__ unsigned char +xf86ReadMmio8(__volatile__ void *base, const unsigned long offset) +{ + unsigned long addr = ((unsigned long)base) + offset; + unsigned char ret; + + __asm__ __volatile__("lduba [%1] %2, %0" + : "=r" (ret) + : "r" (addr), "i" (ASI_PL)); + return ret; +} + +static __inline__ unsigned short +xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset) +{ + unsigned long addr = ((unsigned long)base) + offset; + unsigned short ret; + + __asm__ __volatile__("lduh [%1], %0" + : "=r" (ret) + : "r" (addr)); + return ret; +} + +static __inline__ unsigned short +xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset) +{ + unsigned long addr = ((unsigned long)base) + offset; + unsigned short ret; + + __asm__ __volatile__("lduha [%1] %2, %0" + : "=r" (ret) + : "r" (addr), "i" (ASI_PL)); + return ret; +} + +static __inline__ unsigned int +xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset) +{ + unsigned long addr = ((unsigned long)base) + offset; + unsigned int ret; + + __asm__ __volatile__("ld [%1], %0" + : "=r" (ret) + : "r" (addr)); + return ret; +} + +static __inline__ unsigned int +xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset) +{ + unsigned long addr = ((unsigned long)base) + offset; + unsigned int ret; + + __asm__ __volatile__("lda [%1] %2, %0" + : "=r" (ret) + : "r" (addr), "i" (ASI_PL)); + return ret; +} + +static __inline__ void +xf86WriteMmio8(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("stba %0, [%1] %2" + : /* No outputs */ + : "r" (val), "r" (addr), "i" (ASI_PL)); + barrier(); +} + +static __inline__ void +xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("sth %0, [%1]" + : /* No outputs */ + : "r" (val), "r" (addr)); + barrier(); +} + +static __inline__ void +xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("stha %0, [%1] %2" + : /* No outputs */ + : "r" (val), "r" (addr), "i" (ASI_PL)); + barrier(); +} + +static __inline__ void +xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("st %0, [%1]" + : /* No outputs */ + : "r" (val), "r" (addr)); + barrier(); +} + +static __inline__ void +xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("sta %0, [%1] %2" + : /* No outputs */ + : "r" (val), "r" (addr), "i" (ASI_PL)); + barrier(); +} + +static __inline__ void +xf86WriteMmio8NB(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("stba %0, [%1] %2" + : /* No outputs */ + : "r" (val), "r" (addr), "i" (ASI_PL)); +} + +static __inline__ void +xf86WriteMmio16BeNB(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("sth %0, [%1]" + : /* No outputs */ + : "r" (val), "r" (addr)); +} + +static __inline__ void +xf86WriteMmio16LeNB(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("stha %0, [%1] %2" + : /* No outputs */ + : "r" (val), "r" (addr), "i" (ASI_PL)); +} + +static __inline__ void +xf86WriteMmio32BeNB(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("st %0, [%1]" + : /* No outputs */ + : "r" (val), "r" (addr)); +} + +static __inline__ void +xf86WriteMmio32LeNB(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("sta %0, [%1] %2" + : /* No outputs */ + : "r" (val), "r" (addr), "i" (ASI_PL)); +} + +# endif /* !Lynx */ + +/* + * EGCS 1.1 knows about arbitrary unaligned loads. Define some + * packed structures to talk about such things with. + */ + +# if defined(__arch64__) || defined(__sparcv9) +struct __una_u64 { unsigned long x __attribute__((packed)); }; +# endif +struct __una_u32 { unsigned int x __attribute__((packed)); }; +struct __una_u16 { unsigned short x __attribute__((packed)); }; + +static __inline__ unsigned long ldq_u(unsigned long *p) +{ +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) +# if defined(__arch64__) || defined(__sparcv9) + const struct __una_u64 *ptr = (const struct __una_u64 *) p; +# else + const struct __una_u32 *ptr = (const struct __una_u32 *) p; +# endif + return ptr->x; +# else + unsigned long ret; + memmove(&ret, p, sizeof(*p)); + return ret; +# endif +} + +static __inline__ unsigned long ldl_u(unsigned int *p) +{ +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + const struct __una_u32 *ptr = (const struct __una_u32 *) p; + return ptr->x; +# else + unsigned int ret; + memmove(&ret, p, sizeof(*p)); + return ret; +# endif +} + +static __inline__ unsigned long ldw_u(unsigned short *p) +{ +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + const struct __una_u16 *ptr = (const struct __una_u16 *) p; + return ptr->x; +# else + unsigned short ret; + memmove(&ret, p, sizeof(*p)); + return ret; +# endif +} + +static __inline__ void stq_u(unsigned long val, unsigned long *p) +{ +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) +# if defined(__arch64__) || defined(__sparcv9) + struct __una_u64 *ptr = (struct __una_u64 *) p; +# else + struct __una_u32 *ptr = (struct __una_u32 *) p; +# endif + ptr->x = val; +# else + unsigned long tmp = val; + memmove(p, &tmp, sizeof(*p)); +# endif +} + +static __inline__ void stl_u(unsigned long val, unsigned int *p) +{ +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + struct __una_u32 *ptr = (struct __una_u32 *) p; + ptr->x = val; +# else + unsigned int tmp = val; + memmove(p, &tmp, sizeof(*p)); +# endif +} + +static __inline__ void stw_u(unsigned long val, unsigned short *p) +{ +# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) + struct __una_u16 *ptr = (struct __una_u16 *) p; + ptr->x = val; +# else + unsigned short tmp = val; + memmove(p, &tmp, sizeof(*p)); +# endif +} + +# define mem_barrier() /* XXX: nop for now */ +# define write_mem_barrier() /* XXX: nop for now */ + +# elif defined(__mips__) || defined(__arm32__) +#ifdef __arm32__ +#define PORT_SIZE long +#else +#define PORT_SIZE short +#endif unsigned int IOPortBase; /* Memory mapped I/O port area */ static __inline__ void -outb(port, val) - short port; - char val; +outb(unsigned PORT_SIZE port, unsigned char val) { - *(volatile unsigned char*)(((unsigned short)(port))+IOPortBase) = val; + *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val; } static __inline__ void -outw(port, val) - short port; - short val; +outw(unsigned PORT_SIZE port, unsigned short val) { - *(volatile unsigned short*)(((unsigned short)(port))+IOPortBase) = val; + *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val; } static __inline__ void -outl(port, val) - short port; - int val; +outl(unsigned PORT_SIZE port, unsigned int val) { - *(volatile unsigned long*)(((unsigned short)(port))+IOPortBase) = val; + *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val; } static __inline__ unsigned int -inb(port) - short port; +inb(unsigned PORT_SIZE port) { - return(*(volatile unsigned char*)(((unsigned short)(port))+IOPortBase)); + return *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))+IOPortBase); } static __inline__ unsigned int -inw(port) - short port; +inw(unsigned PORT_SIZE port) { - return(*(volatile unsigned short*)(((unsigned short)(port))+IOPortBase)); + return *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))+IOPortBase); } static __inline__ unsigned int -inl(port) - short port; +inl(unsigned PORT_SIZE port) { - return(*(volatile unsigned long*)(((unsigned short)(port))+IOPortBase)); + return *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))+IOPortBase); } +# if defined(__mips__) static __inline__ unsigned long ldq_u(unsigned long * r11) { unsigned long r1; @@ -349,511 +931,409 @@ static __inline__ unsigned long ldw_u(unsigned short * r11) return r1; } -#define stq_u(v,p) stl_u(v,p) -#define stl_u(v,p) ((unsigned char *)(p)) = (v); \ - ((unsigned char *)(p)+1) = ((v) >> 8); \ - ((unsigned char *)(p)+2) = ((v) >> 16); \ - ((unsigned char *)(p)+3) = ((v) >> 24) +# ifdef linux /* don't mess with other OSs */ -#define stw_u(v,p) ((unsigned char *)(p)) = (v); \ - ((unsigned char *)(p)+1) = ((v) >> 8) +/* + * EGCS 1.1 knows about arbitrary unaligned loads (and we don't support older + * versions anyway. Define some packed structures to talk about such things + * with. + */ -#define mem_barrier() /* NOP */ +struct __una_u32 { unsigned int x __attribute__((packed)); }; +struct __una_u16 { unsigned short x __attribute__((packed)); }; -#else /* defined(mips) */ +static __inline__ void stw_u(unsigned long val, unsigned short *p) +{ + struct __una_u16 *ptr = (struct __una_u16 *) p; + ptr->x = val; +} -#define ldq_u(p) (*((unsigned long *)(p))) -#define ldl_u(p) (*((unsigned int *)(p))) -#define ldw_u(p) (*((unsigned short *)(p))) -#define stq_u(v,p) ((unsigned long *)(p)) = (v) -#define stl_u(v,p) ((unsigned int *)(p)) = (v) -#define stw_u(v,p) ((unsigned short *)(p)) = (v) -#define mem_barrier() /* NOP */ -#define write_mem_barrier() /* NOP */ +static __inline__ void stl_u(unsigned long val, unsigned int *p) +{ + struct __una_u32 *ptr = (struct __una_u32 *) p; + ptr->x = val; +} -#if !defined(FAKEIT) && !defined(__mc68000__) -#ifdef GCCUSESGAS +# if X_BYTE_ORDER == X_BIG_ENDIAN +static __inline__ unsigned int +xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset) +{ + unsigned long addr = ((unsigned long)base) + offset; + unsigned int ret; -/* - * If gcc uses gas rather than the native assembler, the syntax of these - * inlines has to be different. DHD - */ -#ifndef PC98 + __asm__ __volatile__("lw %0, 0(%1)" + : "=r" (ret) + : "r" (addr)); + return ret; +} static __inline__ void -#if NeedFunctionPrototypes -outb( -unsigned short int port, -unsigned char val) -#else -outb(port, val) -unsigned short int port; -unsigned char val; -#endif /* NeedFunctionPrototypes */ -{ - __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port)); +xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + unsigned long addr = ((unsigned long)base) + offset; + + __asm__ __volatile__("sw %0, 0(%1)" + : /* No outputs */ + : "r" (val), "r" (addr)); +} +# endif + +# define mem_barrier() \ + __asm__ __volatile__( \ + "# prevent instructions being moved around\n\t" \ + ".set\tnoreorder\n\t" \ + "# 8 nops to fool the R4400 pipeline\n\t" \ + "nop;nop;nop;nop;nop;nop;nop;nop\n\t" \ + ".set\treorder" \ + : /* no output */ \ + : /* no input */ \ + : "memory") +# define write_mem_barrier() mem_barrier() + +# else /* !linux */ + +# define stq_u(v,p) stl_u(v,p) +# define stl_u(v,p) (*(unsigned char *)(p)) = (v); \ + (*(unsigned char *)(p)+1) = ((v) >> 8); \ + (*(unsigned char *)(p)+2) = ((v) >> 16); \ + (*(unsigned char *)(p)+3) = ((v) >> 24) + +# define stw_u(v,p) (*(unsigned char *)(p)) = (v); \ + (*(unsigned char *)(p)+1) = ((v) >> 8) + +# define mem_barrier() /* NOP */ +# endif /* !linux */ +# endif /* __mips__ */ + +# if defined(__arm32__) +# define ldq_u(p) (*((unsigned long *)(p))) +# define ldl_u(p) (*((unsigned int *)(p))) +# define ldw_u(p) (*((unsigned short *)(p))) +# define stq_u(v,p) (*(unsigned long *)(p)) = (v) +# define stl_u(v,p) (*(unsigned int *)(p)) = (v) +# define stw_u(v,p) (*(unsigned short *)(p)) = (v) +# define mem_barrier() /* NOP */ +# define write_mem_barrier() /* NOP */ +# endif /* __arm32__ */ + +# elif (defined(Lynx) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__)) && defined(__powerpc__) + +# ifndef MAP_FAILED +# define MAP_FAILED ((void *)-1) +# endif + +extern volatile unsigned char *ioBase; + +# define eieio() __asm__ __volatile__ ("eieio" ::: "memory") + +static __inline__ unsigned char +xf86ReadMmio8(__volatile__ void *base, const unsigned long offset) +{ + register unsigned char val; + __asm__ __volatile__( + "lbzx %0,%1,%2\n\t" + "eieio" + : "=r" (val) + : "b" (base), "r" (offset), + "m" (*((volatile unsigned char *)base+offset))); + return val; } - -static __inline__ void -#if NeedFunctionPrototypes -outw( -unsigned short int port, -unsigned short int val) -#else -outw(port, val) -unsigned short int port; -unsigned short int val; -#endif /* NeedFunctionPrototypes */ +static __inline__ unsigned short +xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset) { - __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port)); + register unsigned short val; + __asm__ __volatile__( + "lhzx %0,%1,%2\n\t" + "eieio" + : "=r" (val) + : "b" (base), "r" (offset), + "m" (*((volatile unsigned char *)base+offset))); + return val; } -static __inline__ void -#if NeedFunctionPrototypes -outl( -unsigned short int port, -unsigned int val) -#else -outl(port, val) -unsigned short int port; -unsigned int val; -#endif /* NeedFunctionPrototypes */ +static __inline__ unsigned short +xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset) { - __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port)); + register unsigned short val; + __asm__ __volatile__( + "lhbrx %0,%1,%2\n\t" + "eieio" + : "=r" (val) + : "b" (base), "r" (offset), + "m" (*((volatile unsigned char *)base+offset))); + return val; } static __inline__ unsigned int -#if NeedFunctionPrototypes -inb( -unsigned short int port) -#else -inb(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset) { - unsigned char ret; - __asm__ __volatile__("inb %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + register unsigned int val; + __asm__ __volatile__( + "lwzx %0,%1,%2\n\t" + "eieio" + : "=r" (val) + : "b" (base), "r" (offset), + "m" (*((volatile unsigned char *)base+offset))); + return val; } static __inline__ unsigned int -#if NeedFunctionPrototypes -inw( -unsigned short int port) -#else -inw(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset) { - unsigned short int ret; - __asm__ __volatile__("inw %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + register unsigned int val; + __asm__ __volatile__( + "lwbrx %0,%1,%2\n\t" + "eieio" + : "=r" (val) + : "b" (base), "r" (offset), + "m" (*((volatile unsigned char *)base+offset))); + return val; } -static __inline__ unsigned int -#if NeedFunctionPrototypes -inl( -unsigned short int port) -#else -inl(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +static __inline__ void +xf86WriteMmioNB8(__volatile__ void *base, const unsigned long offset, + const unsigned char val) { - unsigned int ret; - __asm__ __volatile__("inl %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + __asm__ __volatile__( + "stbx %1,%2,%3\n\t" + : "=m" (*((volatile unsigned char *)base+offset)) + : "r" (val), "b" (base), "r" (offset)); } -#else /* PC98 */ +static __inline__ void +xf86WriteMmioNB16Le(__volatile__ void *base, const unsigned long offset, + const unsigned short val) +{ + __asm__ __volatile__( + "sthbrx %1,%2,%3\n\t" + : "=m" (*((volatile unsigned char *)base+offset)) + : "r" (val), "b" (base), "r" (offset)); +} static __inline__ void -#if NeedFunctionPrototypes -_outb( -unsigned short int port, -unsigned char val) -#else -_outb(port, val) -unsigned short int port; -unsigned char val; -#endif /* NeedFunctionPrototypes */ +xf86WriteMmioNB16Be(__volatile__ void *base, const unsigned long offset, + const unsigned short val) { - __asm__ __volatile__("outb %0,%1" ::"a" (val), "d" (port)); + __asm__ __volatile__( + "sthx %1,%2,%3\n\t" + : "=m" (*((volatile unsigned char *)base+offset)) + : "r" (val), "b" (base), "r" (offset)); } static __inline__ void -#if NeedFunctionPrototypes -_outw( -unsigned short int port, -unsigned short int val) -#else -_outw(port, val) -unsigned short int port; -unsigned short int val; -#endif /* NeedFunctionPrototypes */ +xf86WriteMmioNB32Le(__volatile__ void *base, const unsigned long offset, + const unsigned int val) { - __asm__ __volatile__("outw %0,%1" ::"a" (val), "d" (port)); + __asm__ __volatile__( + "stwbrx %1,%2,%3\n\t" + : "=m" (*((volatile unsigned char *)base+offset)) + : "r" (val), "b" (base), "r" (offset)); } - + static __inline__ void -#if NeedFunctionPrototypes -_outl( -unsigned short int port, -unsigned int val) -#else -_outl(port, val) -unsigned short int port; -unsigned int val; -#endif /* NeedFunctionPrototypes */ +xf86WriteMmioNB32Be(__volatile__ void *base, const unsigned long offset, + const unsigned int val) { - __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port)); + __asm__ __volatile__( + "stwx %1,%2,%3\n\t" + : "=m" (*((volatile unsigned char *)base+offset)) + : "r" (val), "b" (base), "r" (offset)); } +static __inline__ void +xf86WriteMmio8(__volatile__ void *base, const unsigned long offset, + const unsigned char val) +{ + xf86WriteMmioNB8(base, offset, val); + eieio(); +} -static __inline__ unsigned int -#if NeedFunctionPrototypes -_inb( -unsigned short int port) -#else -_inb(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +static __inline__ void +xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset, + const unsigned short val) { - unsigned char ret; - __asm__ __volatile__("inb %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + xf86WriteMmioNB16Le(base, offset, val); + eieio(); } -static __inline__ unsigned int -#if NeedFunctionPrototypes -_inw( -unsigned short int port) -#else -_inw(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +static __inline__ void +xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset, + const unsigned short val) { - unsigned short ret; - __asm__ __volatile__("inw %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + xf86WriteMmioNB16Be(base, offset, val); + eieio(); } -static __inline__ unsigned int -#if NeedFunctionPrototypes -_inl( -unsigned short int port) -#else -_inl(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +static __inline__ void +xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset, + const unsigned int val) { - unsigned int ret; - __asm__ __volatile__("inl %1,%0" : - "=a" (ret) : - "d" (port)); - return ret; + xf86WriteMmioNB32Le(base, offset, val); + eieio(); } +static __inline__ void +xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset, + const unsigned int val) +{ + xf86WriteMmioNB32Be(base, offset, val); + eieio(); +} -#if defined(PC98_PW) || defined(PC98_XKB) || defined(PC98_NEC) || defined(PC98_PWLB) || defined(PC98_GA968) -#define PW_PORT 0x600 -extern short chipID; -#if NeedFunctionPrototypes -extern void *mmioBase; -#else -extern unsigned char *mmioBase; -#endif -extern unsigned short _port_tbl[]; -#define port_convert(x) _port_tbl[(unsigned short)x] -#endif -#if defined(PC98_WAB) || defined(PC98_GANB_WAP) -static __inline__ unsigned short -port_convert(unsigned short port) +static __inline__ void +outb(unsigned short port, unsigned char value) { - port <<= 8; - port &= 0x7f00; /* Mask 0111 1111 0000 0000 */ - port |= 0xE0; - return port; + if(ioBase == MAP_FAILED) return; + xf86WriteMmio8((void *)ioBase, port, value); } -#endif /* PC98_WAB || PC98_GANB_WAP */ - -#if defined(PC98_WABEP) -static __inline__ unsigned short -port_convert(unsigned short port) + +static __inline__ void +outw(unsigned short port, unsigned short value) { - port &= 0x7f; /* Mask 0000 0000 0111 1111 */ - port |= 0x0f00; - return port; + if(ioBase == MAP_FAILED) return; + xf86WriteMmio16Le((void *)ioBase, port, value); } -#endif /* PC98_WABEP */ -#ifdef PC98_WSNA -static __inline__ unsigned short -port_convert(unsigned short port) +static __inline__ void +outl(unsigned short port, unsigned int value) { - port <<= 8; - port &= 0x7f00; /* Mask 0111 1111 0000 0000 */ - port |= 0xE2; - return port; + if(ioBase == MAP_FAILED) return; + xf86WriteMmio32Le((void *)ioBase, port, value); } -#endif /* PC98_WSNA */ -#ifdef PC98_NKVNEC -#ifdef PC98_NEC_CIRRUS2 -static __inline__ unsigned short -port_convert(unsigned short port) +static __inline__ unsigned int +inb(unsigned short port) { - port = (port & 0xf) + ((port & 0xf0) << 4) + 0x0050; - return port; + if(ioBase == MAP_FAILED) return 0; + return xf86ReadMmio8((void *)ioBase, port); } -#else -static __inline__ unsigned short -port_convert(unsigned short port) + +static __inline__ unsigned int +inw(unsigned short port) { - port = (port & 0xf) + ((port & 0xf0) << 4) + 0x00a0; - return port; + if(ioBase == MAP_FAILED) return 0; + return xf86ReadMmio16Le((void *)ioBase, port); } -#endif /* PC98_NEC_CIRRUS2 */ -#endif /* PC98_NKVNEC */ -#if defined(PC98_TGUI) || defined(PC98_MGA) -#if NeedFunctionPrototypes -extern void *mmioBase; -#else -extern unsigned char *mmioBase; -#endif -#endif +static __inline__ unsigned int +inl(unsigned short port) +{ + if(ioBase == MAP_FAILED) return 0; + return xf86ReadMmio32Le((void *)ioBase, port); +} -static __inline__ void -#if NeedFunctionPrototypes -outb( -unsigned short port, -unsigned char val) -#else -outb(port, val) -unsigned short port; -unsigned char val; -#endif /* NeedFunctionPrototypes */ -{ -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif +# define ldq_u(p) ldl_u(p) +# define ldl_u(p) ((*(unsigned char *)(p)) | \ + (*((unsigned char *)(p)+1)<<8) | \ + (*((unsigned char *)(p)+2)<<16) | \ + (*((unsigned char *)(p)+3)<<24)) +# define ldw_u(p) ((*(unsigned char *)(p)) | \ + (*((unsigned char *)(p)+1)<<8)) -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - *(volatile unsigned char *)((char *)mmioBase+(port)) = (unsigned char)(val); -#else +# define stq_u(v,p) stl_u(v,p) +# define stl_u(v,p) (*(unsigned char *)(p)) = (v); \ + (*((unsigned char *)(p)+1)) = ((v) >> 8); \ + (*((unsigned char *)(p)+2)) = ((v) >> 16); \ + (*((unsigned char *)(p)+3)) = ((v) >> 24) +# define stw_u(v,p) (*(unsigned char *)(p)) = (v); \ + (*((unsigned char *)(p)+1)) = ((v) >> 8) + +# define mem_barrier() eieio() +# define write_mem_barrier() eieio() + +# else /* ix86 */ + +# define ldq_u(p) (*((unsigned long *)(p))) +# define ldl_u(p) (*((unsigned int *)(p))) +# define ldw_u(p) (*((unsigned short *)(p))) +# define stq_u(v,p) (*(unsigned long *)(p)) = (v) +# define stl_u(v,p) (*(unsigned int *)(p)) = (v) +# define stw_u(v,p) (*(unsigned short *)(p)) = (v) +# define mem_barrier() /* NOP */ +# define write_mem_barrier() /* NOP */ + +# if !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__) +# ifdef GCCUSESGAS + +/* + * If gcc uses gas rather than the native assembler, the syntax of these + * inlines has to be different. DHD + */ + +static __inline__ void +outb(unsigned short port, unsigned char val) +{ __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port)); -#endif } -static __inline__ void -#if NeedFunctionPrototypes -outw( -unsigned short port, -unsigned short val) -#else -outw(port, val) -unsigned short port; -unsigned short val; -#endif /* NeedFunctionPrototypes */ -{ -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - *(volatile unsigned short *)((char *)mmioBase+(port)) = (unsigned short)(val); -#else +static __inline__ void +outw(unsigned short port, unsigned short val) +{ __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port)); -#endif } static __inline__ void -#if NeedFunctionPrototypes -outl( -unsigned short port, -unsigned int val) -#else -outl(port, val) -unsigned short port; -unsigned int val; -#endif /* NeedFunctionPrototypes */ -{ -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif - -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - *(volatile unsigned int *)((char *)mmioBase+(port)) = (unsigned int)(val); -#else +outl(unsigned short port, unsigned int val) +{ __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port)); -#endif } static __inline__ unsigned int -#if NeedFunctionPrototypes -inb( -unsigned short port) -#else -inb(port) -unsigned short port; -#endif /* NeedFunctionPrototypes */ +inb(unsigned short port) { unsigned char ret; - -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif - -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - ret =*(volatile unsigned char *)((char *)mmioBase+(port)); -#else __asm__ __volatile__("inb %1,%0" : "=a" (ret) : "d" (port)); -#endif return ret; } static __inline__ unsigned int -#if NeedFunctionPrototypes -inw( -unsigned short port) -#else -inw(port) -unsigned short port; -#endif /* NeedFunctionPrototypes */ +inw(unsigned short port) { unsigned short ret; - -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif - -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - ret =*(volatile unsigned short *)((char *)mmioBase+(port)); -#else __asm__ __volatile__("inw %1,%0" : "=a" (ret) : "d" (port)); -#endif return ret; } static __inline__ unsigned int -#if NeedFunctionPrototypes -inl( -unsigned short port) -#else -inl(port) -unsigned short port; -#endif /* NeedFunctionPrototypes */ +inl(unsigned short port) { unsigned int ret; - -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif - -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - ret =*(volatile unsigned int *)((char *)mmioBase+(port)); -#else __asm__ __volatile__("inl %1,%0" : "=a" (ret) : "d" (port)); -#endif return ret; } -#endif /* PC98 */ - -#else /* GCCUSESGAS */ +# else /* GCCUSESGAS */ static __inline__ void -#if NeedFunctionPrototypes -outb( -unsigned short int port, -unsigned char val) -#else -outb(port, val) -unsigned short int port; -unsigned char val; -#endif /* NeedFunctionPrototypes */ +outb(unsigned short port, unsigned char val) { __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port)); } static __inline__ void -#if NeedFunctionPrototypes -outw( -unsigned short int port, -unsigned short int val) -#else -outw(port, val) -unsigned short int port; -unsigned short int val; -#endif /* NeedFunctionPrototypes */ +outw(unsigned short port, unsigned short val) { __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port)); } static __inline__ void -#if NeedFunctionPrototypes -outl( -unsigned short int port, -unsigned int val) -#else -outl(port, val) -unsigned short int port; -unsigned int val; -#endif /* NeedFunctionPrototypes */ +outl(unsigned short port, unsigned int val) { __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port)); } static __inline__ unsigned int -#if NeedFunctionPrototypes -inb( -unsigned short int port) -#else -inb(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +inb(unsigned short port) { unsigned char ret; __asm__ __volatile__("in%B0 (%1)" : @@ -863,15 +1343,9 @@ unsigned short int port; } static __inline__ unsigned int -#if NeedFunctionPrototypes -inw( -unsigned short int port) -#else -inw(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +inw(unsigned short port) { - unsigned short int ret; + unsigned short ret; __asm__ __volatile__("in%W0 (%1)" : "=a" (ret) : "d" (port)); @@ -879,13 +1353,7 @@ unsigned short int port; } static __inline__ unsigned int -#if NeedFunctionPrototypes -inl( -unsigned short int port) -#else -inl(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +inl(unsigned short port) { unsigned int ret; __asm__ __volatile__("in%L0 (%1)" : @@ -894,567 +1362,382 @@ unsigned short int port; return ret; } -#endif /* GCCUSESGAS */ +# endif /* GCCUSESGAS */ -#else /* !defined(FAKEIT) && !defined(__mc68000__) */ +# else /* !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__)*/ static __inline__ void -#if NeedFunctionPrototypes -outb( -unsigned short int port, -unsigned char val) -#else -outb(port, val) -unsigned short int port; -unsigned char val; -#endif /* NeedFunctionPrototypes */ +outb(unsigned short port, unsigned char val) { } static __inline__ void -#if NeedFunctionPrototypes -outw( -unsigned short int port, -unsigned short int val) -#else -outw(port, val) -unsigned short int port; -unsigned short int val; -#endif /* NeedFunctionPrototypes */ +outw(unsigned short port, unsigned short val) { } static __inline__ void -#if NeedFunctionPrototypes -outl( -unsigned short int port, -unsigned int val) -#else -outl(port, val) -unsigned short int port; -unsigned int val; -#endif /* NeedFunctionPrototypes */ +outl(unsigned short port, unsigned int val) { } static __inline__ unsigned int -#if NeedFunctionPrototypes -inb( -unsigned short int port) -#else -inb(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +inb(unsigned short port) { return 0; } static __inline__ unsigned int -#if NeedFunctionPrototypes -inw( -unsigned short int port) -#else -inw(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +inw(unsigned short port) { return 0; } static __inline__ unsigned int -#if NeedFunctionPrototypes -inl( -unsigned short int port) -#else -inl(port) -unsigned short int port; -#endif /* NeedFunctionPrototypes */ +inl(unsigned short port) { return 0; } -#endif /* FAKEIT */ - -#endif /* defined(mips) */ -#endif /* defined(AlphaArchitecture) && defined(LinuxArchitecture) */ - -#else /* __GNUC__ */ -#if !defined(AMOEBA) && !defined(MINIX) -# if defined(__STDC__) && (__STDC__ == 1) -# ifndef asm -# define asm __asm -# endif -# endif -# ifdef SVR4 -# include <sys/types.h> -# ifndef __HIGHC__ -# ifndef __USLC__ -# define __USLC__ -# endif -# endif -# endif -# ifndef PC98 -# ifndef SCO325 -# include <sys/inline.h> -# else -# include "scoasm.h" -# endif -# else -#if defined(PC98_PW) || defined(PC98_XKB) || defined(PC98_NEC) || defined(PC98_PWLB) || defined(PC98_GA968) -#define PW_PORT 0x600 -extern short chipID; -#if NeedFunctionPrototypes -extern void *mmioBase; -#else -extern unsigned char *mmioBase; -#endif -extern unsigned short _port_tbl[]; -#define port_convert(x) _port_tbl[(unsigned short)x] -#endif - -#if defined(PC98_TGUI) || defined(PC98_MGA) -#if NeedFunctionPrototypes -extern void *mmioBase; -#else -extern unsigned char *mmioBase; -#endif -#endif - -asm void _outl(port,val) -{ -%reg port,val; - movl port, %edx - movl val, %eax - outl (%dx) -%reg port; mem val; - movl port, %edx - movl val, %eax - outl (%dx) -%mem port; reg val; - movw port, %dx - movl val, %eax - outl (%dx) -%mem port,val; - movw port, %dx - movl val, %eax - outl (%dx) -} - -asm void _outw(port,val) -{ -%reg port,val; - movl port, %edx - movl val, %eax - data16 - outl (%dx) -%reg port; mem val; - movl port, %edx - movw val, %ax - data16 - outl (%dx) -%mem port; reg val; - movw port, %dx - movl val, %eax - data16 - outl (%dx) -%mem port,val; - movw port, %dx - movw val, %ax - data16 - outl (%dx) -} - -asm void _outb(port,val) -{ -%reg port,val; - movl port, %edx - movl val, %eax - outb (%dx) -%reg port; mem val; - movl port, %edx - movb val, %al - outb (%dx) -%mem port; reg val; - movw port, %dx - movl val, %eax - outb (%dx) -%mem port,val; - movw port, %dx - movb val, %al - outb (%dx) -} - -asm int _inl(port) -{ -%reg port; - movl port, %edx - inl (%dx) -%mem port; - movw port, %dx - inl (%dx) -} - -asm int _inw(port) -{ -%reg port; - subl %eax, %eax - movl port, %edx - data16 - inl (%dx) -%mem port; - subl %eax, %eax - movw port, %dx - data16 - inl (%dx) -} - -asm int _inb(port) -{ -%reg port; - subl %eax, %eax - movl port, %edx - inb (%dx) -%mem port; - subl %eax, %eax - movw port, %dx - inb (%dx) -} - -#if defined(PC98_WAB) || defined(PC98_GANB_WAP) -static unsigned short -port_convert(unsigned short port) -{ - port <<= 8; - port &= 0x7f00; /* Mask 0111 1111 0000 0000 */ - port |= 0xE0; - return port; -} -#endif /* PC98_WAB || PC98_GANB_WAP */ - -#if defined(PC98_WABEP) -static unsigned short -port_convert(unsigned short port) -{ - port &= 0x7f; /* Mask 0000 0000 0111 1111 */ - port |= 0x0f00; - return port; -} -#endif /* PC98_WABEP */ - -#ifdef PC98_WSNA -static unsigned short -port_convert(unsigned short port) -{ - port <<= 8; - port &= 0x7f00; /* Mask 0111 1111 0000 0000 */ - port |= 0xE2; - return port; -} -#endif /* PC98_WSNA */ - -#ifdef PC98_NKVNEC -#ifdef PC98_NEC_CIRRUS2 -static unsigned short -port_convert(unsigned short port) -{ - port = (port & 0xf) + ((port & 0xf0) << 4) + 0x0050; - return port; -} -#else -static unsigned short -port_convert(unsigned short port) -{ - port = (port & 0xf) + ((port & 0xf0) << 4) + 0x00a0; - return port; -} -#endif /* PC98_NEC_CIRRUS2 */ -#endif /* PC98_NKVNEC */ - -static void outl(port,val) -{ -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif +# endif /* FAKEIT */ -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - *(volatile unsigned int *)((char *)mmioBase+(port)) = (unsigned int)(val); -#else - _outl(port,val); -#endif -} - -static void outw(port,val) -{ -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif - -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - *(volatile unsigned short *)((char *)mmioBase+(port)) = (unsigned short)(val); -#else - _outw(port,val); -#endif -} - -static void outb(port,val) -{ -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif - -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - *(volatile unsigned char *)((char *)mmioBase+(port)) = (unsigned char)(val); -#else - _outb(port,val); -#endif -} - -static int inl(port) -{ - unsigned int ret; - -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif - -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - ret =*(volatile unsigned int *)((char *)mmioBase+(port)); -#else - ret = _inl(port); -#endif - return ret; -} - -static int inw(port) -{ - unsigned short ret; - -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif - -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - ret =*(volatile unsigned short *)((char *)mmioBase+(port)); -#else - ret = _inw(port); -#endif - return ret; -} - -static int inb(port) -{ - unsigned char ret; - -#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \ - defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \ - defined(PC98_XKB) || defined(PC98_NEC) - unsigned short tmp; - tmp=port_convert(port); - port=tmp; -#endif - -#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA) - ret =*(volatile unsigned char *)((char *)mmioBase+(port)); -#else - ret = _inb(port); -#endif - return ret; -} - - -# endif /* PC98 */ -# if !defined(__HIGHC__) && !defined(SCO325) -# pragma asm partial_optimization outl -# pragma asm partial_optimization outw -# pragma asm partial_optimization outb -# pragma asm partial_optimization inl -# pragma asm partial_optimization inw -# pragma asm partial_optimization inb -# endif -#endif -#define ldq_u(p) (*((unsigned long *)(p))) -#define ldl_u(p) (*((unsigned int *)(p))) -#define ldw_u(p) (*((unsigned short *)(p))) -#define stq_u(v,p) ((unsigned long *)(p)) = (v) -#define stl_u(v,p) ((unsigned int *)(p)) = (v) -#define stw_u(v,p) ((unsigned short *)(p)) = (v) -#define mem_barrier() /* NOP */ -#define write_mem_barrier() /* NOP */ -#endif /* __GNUC__ */ - -#if defined(IODEBUG) && defined(__GNUC__) -#undef inb -#undef inw -#undef inl -#undef outb -#undef outw -#undef outl -#define inb(a) __extension__ ({unsigned char __c=RealInb(a); ErrorF("inb(0x%03x) = 0x%02x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;}) -#define inw(a) __extension__ ({unsigned short __c=RealInw(a); ErrorF("inw(0x%03x) = 0x%04x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;}) -#define inl(a) __extension__ ({unsigned long __c=RealInl(a); ErrorF("inl(0x%03x) = 0x%08x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;}) - -#define outb(a,b) (ErrorF("outb(0x%03x, 0x%02x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutb(a,b)) -#define outw(a,b) (ErrorF("outw(0x%03x, 0x%04x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutw(a,b)) -#define outl(a,b) (ErrorF("outl(0x%03x, 0x%08x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutl(a,b)) -#endif +# endif /* ix86 */ +# elif defined(__powerpc__) /* && !__GNUC__ */ /* - * This header sometimes gets included where is isn't needed, and on some - * OSs this causes problems because the following functions generate - * references to inb() and outb() which can't be resolved. Defining - * NO_COMPILER_H_EXTRAS avoids this problem. + * NON-GCC PowerPC - Presumed to be PowerMAX OS for now */ +# ifndef PowerMAX_OS +# error - Non-gcc PowerPC and !PowerMAXOS ??? +# endif -#ifndef NO_COMPILER_H_EXTRAS +# define PPCIO_DEBUG 0 +# define PPCIO_INLINE 1 +# define USE_ABS_MACRO 1 /* - *----------------------------------------------------------------------- - * Port manipulation convenience functions - *----------------------------------------------------------------------- + * Use compiler intrinsics to access certain PPC machine instructions */ +# define eieio() __inst_eieio() +# define stw_brx(val,base,ndx) __inst_sthbrx(val,base,ndx) +# define stl_brx(val,base,ndx) __inst_stwbrx(val,base,ndx) +# define ldw_brx(base,ndx) __inst_lhbrx(base,ndx) +# define ldl_brx(base,ndx) __inst_lwbrx(base,ndx) + +# define ldq_u(p) (*((unsigned long long *)(p))) +# define ldl_u(p) (*((unsigned long *)(p))) +# define ldw_u(p) (*((unsigned short *)(p))) +# define stq_u(v,p) (*(unsigned long long *)(p)) = (v) +# define stl_u(v,p) (*(unsigned long *)(p)) = (v) +# define stw_u(v,p) (*(unsigned short *)(p)) = (v) +# define mem_barrier() eieio() +# define write_mem_barrier() eieio() + +extern volatile unsigned char *ioBase; + +# if !defined(abs) && defined(USE_ABS_MACRO) +# define abs(x) ((x) >= 0 ? (x) : -(x)) +# endif -#ifndef __GNUC__ -#define __inline__ /**/ +# undef inb +# undef inw +# undef inl +# undef outb +# undef outw +# undef outl + +# if PPCIO_DEBUG + +extern void debug_outb(unsigned int a, unsigned char b, int line, char *file); +extern void debug_outw(unsigned int a, unsigned short w, int line, char *file); +extern void debug_outl(unsigned int a, unsigned int l, int line, char *file); +extern unsigned char debug_inb(unsigned int a, int line, char *file); +extern unsigned short debug_inw(unsigned int a, int line, char *file); +extern unsigned int debug_inl(unsigned int a, int line, char *file); + +# define outb(a,b) debug_outb(a,b, __LINE__, __FILE__) +# define outw(a,w) debug_outw(a,w, __LINE__, __FILE__) +# define outl(a,l) debug_outl(a,l, __LINE__, __FILE__) +# define inb(a) debug_inb(a, __LINE__, __FILE__) +# define inw(a) debug_inw(a, __LINE__, __FILE__) +# define inl(a) debug_inl(a, __LINE__, __FILE__) + +# else /* !PPCIO_DEBUG */ + +extern unsigned char inb(unsigned int a); +extern unsigned short inw(unsigned int a); +extern unsigned int inl(unsigned int a); + +# if PPCIO_INLINE + +# define outb(a,b) \ + (*((volatile unsigned char *)(ioBase + (a))) = (b), eieio()) +# define outw(a,w) (stw_brx((w),ioBase,(a)), eieio()) +# define outl(a,l) (stl_brx((l),ioBase,(a)), eieio()) + +# else /* !PPCIO_INLINE */ + +extern void outb(unsigned int a, unsigned char b); +extern void outw(unsigned int a, unsigned short w); +extern void outl(unsigned int a, unsigned int l); + +# endif /* PPCIO_INLINE */ + +# endif /* !PPCIO_DEBUG */ + +# else /* !GNUC && !PPC */ +# if !defined(QNX4) +# if defined(__STDC__) && (__STDC__ == 1) +# ifndef asm +# define asm __asm +# endif +# endif +# ifdef SVR4 +#if 0 +# include <sys/types.h> #endif +# ifndef __HIGHC__ +# ifndef __USLC__ +# define __USLC__ +# endif +# endif +# endif +# ifndef SCO325 +# if defined(USL) +# if defined(IN_MODULE) +# /* avoid including <sys/types.h> for <sys/inline.h> on UnixWare */ +# define ushort unsigned short +# define ushort_t unsigned short +# define ulong unsigned long +# define ulong_t unsigned long +# define uint_t unsigned int +# define uchar_t unsigned char +# else +# include <sys/types.h> +# endif /* IN_MODULE */ +# endif /* USL */ +# include <sys/inline.h> +# else +# include "scoasm.h" +# endif +# if !defined(__HIGHC__) && !defined(SCO325) +# pragma asm partial_optimization outl +# pragma asm partial_optimization outw +# pragma asm partial_optimization outb +# pragma asm partial_optimization inl +# pragma asm partial_optimization inw +# pragma asm partial_optimization inb +# endif +# endif +# define ldq_u(p) (*((unsigned long *)(p))) +# define ldl_u(p) (*((unsigned int *)(p))) +# define ldw_u(p) (*((unsigned short *)(p))) +# define stq_u(v,p) (*(unsigned long *)(p)) = (v) +# define stl_u(v,p) (*(unsigned int *)(p)) = (v) +# define stw_u(v,p) (*(unsigned short *)(p)) = (v) +# define mem_barrier() /* NOP */ +# define write_mem_barrier() /* NOP */ +# endif /* __GNUC__ */ + +# if defined(QNX4) +# include <sys/types.h> +extern unsigned inb(unsigned port); +extern unsigned inw(unsigned port); +extern unsigned inl(unsigned port); +extern void outb(unsigned port, unsigned val); +extern void outw(unsigned port, unsigned val); +extern void outl(unsigned port, unsigned val); +# endif /* QNX4 */ + +# if defined(IODEBUG) && defined(__GNUC__) +# undef inb +# undef inw +# undef inl +# undef outb +# undef outw +# undef outl +# define inb(a) __extension__ ({unsigned char __c=RealInb(a); ErrorF("inb(0x%03x) = 0x%02x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;}) +# define inw(a) __extension__ ({unsigned short __c=RealInw(a); ErrorF("inw(0x%03x) = 0x%04x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;}) +# define inl(a) __extension__ ({unsigned int __c=RealInl(a); ErrorF("inl(0x%03x) = 0x%08x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;}) + +# define outb(a,b) (ErrorF("outb(0x%03x, 0x%02x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutb(a,b)) +# define outw(a,b) (ErrorF("outw(0x%03x, 0x%04x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutw(a,b)) +# define outl(a,b) (ErrorF("outl(0x%03x, 0x%08x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutl(a,b)) +# endif -/* - * rdinx - read the indexed byte port 'port', index 'ind', and return its value - */ -static __inline__ unsigned char -#ifdef __STDC__ -rdinx(unsigned short int port, unsigned char ind) -#else -rdinx(port, ind) -unsigned short int port; -unsigned char ind; -#endif -{ - if (port == 0x3C0) /* reset attribute flip-flop */ - (void) inb(0x3DA); - outb(port, ind); - return(inb(port+1)); -} - -/* - * wrinx - write 'val' to port 'port', index 'ind' - */ -static __inline__ void -#ifdef __STDC__ -wrinx(unsigned short int port, unsigned char ind, unsigned char val) -#else -wrinx(port, ind, val) -unsigned short int port; -unsigned char ind, val; -#endif -{ - outb(port, ind); - outb(port+1, val); -} +# endif /* NO_INLINE */ + +# ifdef __alpha__ +/* entry points for Mmio memory access routines */ +extern int (*xf86ReadMmio8)(void *, unsigned long); +extern int (*xf86ReadMmio16)(void *, unsigned long); +extern int (*xf86ReadMmio32)(void *, unsigned long); +extern void (*xf86WriteMmio8)(int, void *, unsigned long); +extern void (*xf86WriteMmio16)(int, void *, unsigned long); +extern void (*xf86WriteMmio32)(int, void *, unsigned long); +extern void (*xf86WriteMmioNB8)(int, void *, unsigned long); +extern void (*xf86WriteMmioNB16)(int, void *, unsigned long); +extern void (*xf86WriteMmioNB32)(int, void *, unsigned long); +extern void xf86JensenMemToBus(char *, long, long, int); +extern void xf86JensenBusToMem(char *, char *, unsigned long, int); +extern void xf86SlowBCopyFromBus(unsigned char *, unsigned char *, int); +extern void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int); + +/* Some macros to hide the system dependencies for MMIO accesses */ +/* Changed to kill noise generated by gcc's -Wcast-align */ +# define MMIO_IN8(base, offset) (*xf86ReadMmio8)(base, offset) +# define MMIO_IN16(base, offset) (*xf86ReadMmio16)(base, offset) +# define MMIO_IN32(base, offset) (*xf86ReadMmio32)(base, offset) + +# if defined (JENSEN_SUPPORT) +# define MMIO_OUT32(base, offset, val) \ + (*xf86WriteMmio32)((CARD32)(val), base, offset) +# define MMIO_ONB32(base, offset, val) \ + (*xf86WriteMmioNB32)((CARD32)(val), base, offset) +# else +# define MMIO_OUT32(base, offset, val) \ + do { \ + write_mem_barrier(); \ + *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val); \ + } while (0) +# define MMIO_ONB32(base, offset, val) \ + *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val) +# endif -/* - * modinx - in register 'port', index 'ind', set the bits in 'mask' as in 'new'; - * the other bits are unchanged. - */ -static __inline__ void -#ifdef __STDC__ -modinx(unsigned short int port, unsigned char ind, - unsigned char mask, unsigned char new) -#else -modinx(port, ind, mask, new) -unsigned short int port; -unsigned char ind, mask, new; -#endif -{ - unsigned char tmp; +# define MMIO_OUT8(base, offset, val) \ + (*xf86WriteMmio8)((CARD8)(val), base, offset) +# define MMIO_OUT16(base, offset, val) \ + (*xf86WriteMmio16)((CARD16)(val), base, offset) +# define MMIO_ONB8(base, offset, val) \ + (*xf86WriteMmioNB8)((CARD8)(val), base, offset) +# define MMIO_ONB16(base, offset, val) \ + (*xf86WriteMmioNB16)((CARD16)(val), base, offset) +# define MMIO_MOVE32(base, offset, val) \ + MMIO_OUT32(base, offset, val) + +# elif defined(__powerpc__) + /* + * we provide byteswapping and no byteswapping functions here + * with byteswapping as default, + * drivers that don't need byteswapping should define PPC_MMIO_IS_BE + */ +# define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) +# define MMIO_OUT8(base, offset, val) \ + xf86WriteMmio8(base, offset, (CARD8)(val)) +# define MMIO_ONB8(base, offset, val) \ + xf86WriteMmioNB8(base, offset, (CARD8)(val)) + +# if defined(PPC_MMIO_IS_BE) /* No byteswapping */ +# define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset) +# define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset) +# define MMIO_OUT16(base, offset, val) \ + xf86WriteMmio16Be(base, offset, (CARD16)(val)) +# define MMIO_OUT32(base, offset, val) \ + xf86WriteMmio32Be(base, offset, (CARD32)(val)) +# define MMIO_ONB16(base, offset, val) \ + xf86WriteMmioNB16Be(base, offset, (CARD16)(val)) +# define MMIO_ONB32(base, offset, val) \ + xf86WriteMmioNB32Be(base, offset, (CARD32)(val)) +# else /* byteswapping is the default */ +# define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset) +# define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset) +# define MMIO_OUT16(base, offset, val) \ + xf86WriteMmio16Le(base, offset, (CARD16)(val)) +# define MMIO_OUT32(base, offset, val) \ + xf86WriteMmio32Le(base, offset, (CARD32)(val)) +# define MMIO_ONB16(base, offset, val) \ + xf86WriteMmioNB16Le(base, offset, (CARD16)(val)) +# define MMIO_ONB32(base, offset, val) \ + xf86WriteMmioNB32Le(base, offset, (CARD32)(val)) +# endif - tmp = (rdinx(port, ind) & ~mask) | (new & mask); - wrinx(port, ind, tmp); -} +# define MMIO_MOVE32(base, offset, val) \ + xf86WriteMmio32Be(base, offset, (CARD32)(val)) + +static __inline__ void ppc_flush_icache(char *addr) +{ + __asm__ volatile ( + "dcbf 0,%0;" + "sync;" + "icbi 0,%0;" + "sync;" + "isync;" + : : "r"(addr) : "memory"); +} + +# elif defined(__sparc__) + /* + * Like powerpc, we provide byteswapping and no byteswapping functions + * here with byteswapping as default, drivers that don't need byteswapping + * should define SPARC_MMIO_IS_BE (perhaps create a generic macro so that we + * do not need to use PPC_MMIO_IS_BE and the sparc one in all the same places + * of drivers?). + */ +# define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) +# define MMIO_OUT8(base, offset, val) \ + xf86WriteMmio8(base, offset, (CARD8)(val)) +# define MMIO_ONB8(base, offset, val) \ + xf86WriteMmio8NB(base, offset, (CARD8)(val)) + +# if defined(SPARC_MMIO_IS_BE) /* No byteswapping */ +# define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset) +# define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset) +# define MMIO_OUT16(base, offset, val) \ + xf86WriteMmio16Be(base, offset, (CARD16)(val)) +# define MMIO_OUT32(base, offset, val) \ + xf86WriteMmio32Be(base, offset, (CARD32)(val)) +# define MMIO_ONB16(base, offset, val) \ + xf86WriteMmio16BeNB(base, offset, (CARD16)(val)) +# define MMIO_ONB32(base, offset, val) \ + xf86WriteMmio32BeNB(base, offset, (CARD32)(val)) +# else /* byteswapping is the default */ +# define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset) +# define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset) +# define MMIO_OUT16(base, offset, val) \ + xf86WriteMmio16Le(base, offset, (CARD16)(val)) +# define MMIO_OUT32(base, offset, val) \ + xf86WriteMmio32Le(base, offset, (CARD32)(val)) +# define MMIO_ONB16(base, offset, val) \ + xf86WriteMmio16LeNB(base, offset, (CARD16)(val)) +# define MMIO_ONB32(base, offset, val) \ + xf86WriteMmio32LeNB(base, offset, (CARD32)(val)) +# endif -/* - * tstrg - returns true iff the bits in 'mask' of register 'port' are - * readable & writable. - */ +# define MMIO_MOVE32(base, offset, val) \ + xf86WriteMmio32Be(base, offset, (CARD32)(val)) -static __inline__ int -#ifdef __STDC__ -testrg(unsigned short int port, unsigned char mask) -#else -tstrg(port, mask) -unsigned short int port; -unsigned char mask; -#endif -{ - unsigned char old, new1, new2; +# else /* !__alpha__ && !__powerpc__ && !__sparc__ */ - old = inb(port); - outb(port, old & ~mask); - new1 = inb(port) & mask; - outb(port, old | mask); - new2 = inb(port) & mask; - outb(port, old); - return((new1 == 0) && (new2 == mask)); -} +# define MMIO_IN8(base, offset) \ + *(volatile CARD8 *)(((CARD8*)(base)) + (offset)) +# define MMIO_IN16(base, offset) \ + *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset)) +# define MMIO_IN32(base, offset) \ + *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) +# define MMIO_OUT8(base, offset, val) \ + *(volatile CARD8 *)(((CARD8*)(base)) + (offset)) = (val) +# define MMIO_OUT16(base, offset, val) \ + *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset)) = (val) +# define MMIO_OUT32(base, offset, val) \ + *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val) +# define MMIO_ONB8(base, offset, val) MMIO_OUT8(base, offset, val) +# define MMIO_ONB16(base, offset, val) MMIO_OUT16(base, offset, val) +# define MMIO_ONB32(base, offset, val) MMIO_OUT32(base, offset, val) -/* - * testinx2 - returns true iff the bits in 'mask' of register 'port', index - * 'ind' are readable & writable. - */ -static __inline__ int -#ifdef __STDC__ -testinx2(unsigned short int port, unsigned char ind, unsigned char mask) -#else -testinx2(port, ind, mask) -unsigned short int port; -unsigned char ind, mask; -#endif -{ - unsigned char old, new1, new2; +# define MMIO_MOVE32(base, offset, val) MMIO_OUT32(base, offset, val) - old = rdinx(port, ind); - wrinx(port, ind, old & ~mask); - new1 = rdinx(port, ind) & mask; - wrinx(port, ind, old | mask); - new2 = rdinx(port, ind) & mask; - wrinx(port, ind, old); - return((new1 == 0) && (new2 == mask)); -} +# endif /* __alpha__ */ /* - * testinx - returns true iff all bits of register 'port', index 'ind' are - * readable & writable. + * With Intel, the version in os-support/misc/SlowBcopy.s is used. + * This avoids port I/O during the copy (which causes problems with + * some hardware). */ -static __inline__ int -#ifdef __STDC__ -testinx(unsigned short int port, unsigned char ind) -#else -testinx(port, ind, mask) -unsigned short int port; -unsigned char ind; -#endif -{ - return(testinx2(port, ind, 0xFF)); -} -#endif /* NO_COMPILER_H_EXTRAS */ +# ifdef __alpha__ +# define slowbcopy_tobus(src,dst,count) xf86SlowBCopyToBus(src,dst,count) +# define slowbcopy_frombus(src,dst,count) xf86SlowBCopyFromBus(src,dst,count) +# else /* __alpha__ */ +# define slowbcopy_tobus(src,dst,count) xf86SlowBcopy(src,dst,count) +# define slowbcopy_frombus(src,dst,count) xf86SlowBcopy(src,dst,count) +# endif /* __alpha__ */ -#endif /* NO_INLINE */ #endif /* _COMPILER_H */ diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h index ba00913d8..119adc5a6 100644 --- a/hw/xfree86/common/xf86.h +++ b/hw/xfree86/common/xf86.h @@ -1,743 +1,407 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86.h,v 3.47.2.8 1998/02/24 19:05:53 hohndel Exp $ */ -/* - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Thomas Roell not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Thomas Roell makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ -/* $Xorg: xf86.h,v 1.3 2000/08/17 19:50:28 cpqbld Exp $ */ - -#ifndef _XF86_H -#define _XF86_H - -#include "misc.h" -#include "input.h" -#include "scrnintstr.h" - -#include "xf86_Option.h" - -/* - * structure common for all modes - */ -typedef struct _DispM { - struct _DispM *prev,*next; - char *name; /* identifier of this mode */ - /* These are the values that the user sees/provides */ - int Clock; /* pixel clock */ - int HDisplay; /* horizontal timing */ - int HSyncStart; - int HSyncEnd; - int HTotal; - int HSkew; - int VDisplay; /* vertical timing */ - int VSyncStart; - int VSyncEnd; - int VTotal; - int Flags; - /* These are the values the hardware uses */ - int SynthClock; /* Actual clock freq to be programmed */ - int CrtcHDisplay; - int CrtcHSyncStart; - int CrtcHSyncEnd; - int CrtcHTotal; - int CrtcHSkew; - int CrtcVDisplay; - int CrtcVSyncStart; - int CrtcVSyncEnd; - int CrtcVTotal; - Bool CrtcHAdjusted; - Bool CrtcVAdjusted; - int PrivSize; - INT32 *Private; -} DisplayModeRec, *DisplayModePtr; - -#define V_PHSYNC 0x0001 -#define V_NHSYNC 0x0002 -#define V_PVSYNC 0x0004 -#define V_NVSYNC 0x0008 -#define V_INTERLACE 0x0010 -#define V_DBLSCAN 0x0020 -#define V_CSYNC 0x0040 -#define V_PCSYNC 0x0080 -#define V_NCSYNC 0x0100 -#define V_HSKEW 0x0200 /* hskew provided */ -#define V_PIXMUX 0x1000 -#define V_DBLCLK 0x2000 -#define V_CLKDIV2 0x4000 - -/* The monitor description */ - -#define MAX_HSYNC 8 -#define MAX_VREFRESH 8 - -typedef struct { float hi, lo; } range; - -typedef struct { - char *id; - char *vendor; - char *model; - float EMPTY; - int n_hsync; - range hsync[MAX_HSYNC]; - int n_vrefresh; - range vrefresh[MAX_VREFRESH]; - DisplayModePtr Modes, Last; /* Start and end of monitor's mode list */ -} MonRec, *MonPtr; - -#define MAXCLOCKS 128 -#define MAXDACSPEEDS 4 /* for <= 8, 16, 24, 32bpp */ - -/* Set default max allowed clock to 90MHz */ -#define DEFAULT_MAX_CLOCK 90000 - -/* - * the graphic device - */ -typedef struct { - Bool configured; - int tmpIndex; - int scrnIndex; - Bool (* Probe)( -#if NeedNestedPrototypes - void -#endif -); - Bool (* Init)( -#if NeedNestedPrototypes - int scr_index, - ScreenPtr pScreen, - int argc, - char **argv -#endif -); - int (* ValidMode)( -#if NeedNestedPrototypes - DisplayModePtr target, - Bool verbose, - int flag -#endif -); - void (* EnterLeaveVT)( -#if NeedNestedPrototypes - int, - int -#endif -); - void (* EnterLeaveMonitor)( -#if NeedNestedPrototypes - int -#endif -); - void (* EnterLeaveCursor)( -#if NeedNestedPrototypes - int -#endif -); - void (* AdjustFrame)( -#if NeedNestedPrototypes - int x, - int y -#endif -); - Bool (* SwitchMode)( -#if NeedNestedPrototypes - DisplayModePtr modes -#endif -); - void (* DPMSSet)( -#if NeedNestedPrototypes - int level -#endif -); - void (* PrintIdent)( -#if NeedNestedPrototypes - void -#endif -); - int depth; - xrgb weight; - int bitsPerPixel; - int defaultVisual; - int virtualX,virtualY; - int displayWidth; - int frameX0, frameY0, frameX1, frameY1; - OFlagSet options; - OFlagSet clockOptions; - OFlagSet xconfigFlag; - char *chipset; - char *ramdac; - int dacSpeeds[MAXDACSPEEDS]; - int dacSpeedBpp; - int clocks; - int clock[MAXCLOCKS]; - int maxClock; - int videoRam; - int BIOSbase; /* Base address of video BIOS */ - unsigned long MemBase; /* Frame buffer base address */ - int width, height; /* real display dimensions */ - unsigned long speedup; /* Use SpeedUp code */ - DisplayModePtr modes; - MonPtr monitor; - char *clockprog; - int textclock; - Bool bankedMono; /* display supports banking for mono server */ - char *name; - xrgb blackColour; - xrgb whiteColour; - int *validTokens; - char *patchLevel; - unsigned int IObase; /* AGX - video card I/O reg base */ - unsigned int DACbase; /* AGX - dac I/O reg base */ - unsigned long COPbase; /* AGX - coprocessor memory base */ - unsigned int POSbase; /* AGX - I/O address of POS regs */ - int instance; /* AGX - XGA video card instance number */ - int s3Madjust; - int s3Nadjust; - int s3MClk; - int chipID; - int chipRev; - unsigned long VGAbase; /* AGX - 64K aperture memory address */ - int s3RefClk; - int s3BlankDelay; - int textClockFreq; - char *DCConfig; - char *DCOptions; - int MemClk; /* General flag used for memory clocking */ - int LCDClk; -#ifdef XFreeXDGA - int directMode; - void (*setBank)( -#if NeedNestedPrototypes - int -#endif - ); - unsigned long physBase; - int physSize; -#endif -#ifdef XF86SETUP - void *device; /* This should be GDevPtr, but it causes - problems with include file order */ -#endif -} ScrnInfoRec, *ScrnInfoPtr; - -typedef struct { - int token; /* id of the token */ - char *name; /* pointer to the LOWERCASED name */ -} SymTabRec, *SymTabPtr; - -#define VGA_DRIVER 1 -#define V256_DRIVER 2 -#define WGA_DRIVER 3 -#define XGA_DRIVER 4 - -#define ENTER 1 -#define LEAVE 0 - -/* These are possible return values for xf86CheckMode() and ValidMode() */ -#define MODE_OK 0 -#define MODE_HSYNC 1 /* hsync out of range */ -#define MODE_VSYNC 2 /* vsync out of range */ -#define MODE_BAD 255 /* unspecified reason */ - -/* These are the possible flags for ValidMode */ -#define MODE_USED 1 /* this mode is really being used in the */ - /* modes line of the Display Subsection */ -#define MODE_SUGGESTED 2 /* this mode is included in the available*/ - /* modes in the Monitor Section */ -#define MODE_VID 3 /* this is called from the VidMode extension */ - -/* Indicates the level of DPMS support */ -typedef enum { - DPMSSupportUnknown, - DPMSNotSupported, - DPMSFullSupport -} DPMSSupportStatus; - -/* flags for xf86LookupMode */ -#define LOOKUP_DEFAULT 0 /* Use default mode lookup method */ -#define LOOKUP_BEST_REFRESH 1 /* Pick modes with best refresh */ -#define LOOKUP_NO_INTERLACED 2 /* Ignore interlaced modes */ -#define LOOKUP_FORCE_DEFAULT 4 /* Force default lookup method */ - -#define INTERLACE_REFRESH_WEIGHT 1.5 - -/* SpeedUp options */ - -#define SPEEDUP_FILLBOX 1 -#define SPEEDUP_FILLRECT 2 -#define SPEEDUP_BITBLT 4 -#define SPEEDUP_LINE 8 -#define SPEEDUP_TEGBLT8 0x10 -#define SPEEDUP_RECTSTIP 0x20 - -/* - * This is the routines where SpeedUp is quicker than fXF86. The problem is - * that the SpeedUp fillbox is better for drawing vertical and horizontal - * line segments, and the fXF86 version is significantly better for - * more general lines - */ -#define SPEEDUP_BEST (SPEEDUP_FILLRECT | SPEEDUP_BITBLT | \ - SPEEDUP_LINE | SPEEDUP_TEGBLT8 | \ - SPEEDUP_RECTSTIP) -/* -#define SPEEDUP_BEST (SPEEDUP_FILLBOX | SPEEDUP_FILLRECT | \ - SPEEDUP_BITBLT | SPEEDUP_LINE | \ - SPEEDUP_TEGBLT8 | SPEEDUP_RECTSTIP) -*/ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86.h,v 3.169 2003/02/13 10:49:38 eich Exp $ */ /* - * SpeedUp routines which are not dependent on the screen virtual resolution + * Copyright (c) 1997 by The XFree86 Project, Inc. */ -#ifndef SPEEDUP_ANYWIDTH -#define SPEEDUP_ANYWIDTH (SPEEDUP_FILLRECT | SPEEDUP_BITBLT | \ - SPEEDUP_LINE | SPEEDUP_FILLBOX) -#endif /* - * SpeedUp routines which are not dependent on ET4000 + * This file contains declarations for public XFree86 functions and variables, + * and definitions of public macros. + * + * "public" means available to video drivers. */ -#ifndef SPEEDUP_ANYCHIPSET -#define SPEEDUP_ANYCHIPSET (SPEEDUP_TEGBLT8 | SPEEDUP_RECTSTIP) -#endif - -/* All SpeedUps */ -#define SPEEDUP_ALL (SPEEDUP_FILLBOX | SPEEDUP_FILLRECT | \ - SPEEDUP_BITBLT | SPEEDUP_LINE | \ - SPEEDUP_TEGBLT8 | SPEEDUP_RECTSTIP) - -/* SpeedUp flags used if SpeedUp is not in XF86Config */ -#define SPEEDUP_DEFAULT SPEEDUP_ALL - -extern Bool xf86VTSema; -/* Mouse device private record */ - -#define MSE_MAPTOX (-1) -#define MSE_MAPTOY (-2) -#define MSE_MAXBUTTONS 12 -#define MSE_DFLTBUTTONS 3 - -typedef struct _MouseDevRec { - DeviceProc mseProc; /* procedure for initializing */ - void (* mseEvents)( -#if NeedNestedPrototypes - struct _MouseDevRec * -#endif - ); /* proc for processing events */ - DeviceIntPtr device; - int mseFd; - char *mseDevice; - int mseType; - int mseModel; - int baudRate; - int oldBaudRate; - int sampleRate; - int lastButtons; - int threshold, num, den; /* acceleration */ - int buttons; /* # of buttons */ - int emulateState; /* automata state for 2 button mode */ - Bool emulate3Buttons; - int emulate3Timeout; /* Timeout for 3 button emulation */ - Bool chordMiddle; - int mouseFlags; /* Flags to Clear after opening mouse dev */ - int truebuttons; /* Arg to maintain before emulate3buttons timer callback */ - - int resolution; - int negativeZ; - int positiveZ; -#ifndef MOUSE_PROTOCOL_IN_KERNEL - unsigned char protoPara[7]; -#endif - -#ifndef CSRG_BASED - /* xque part */ - int xquePending; /* was xqueFd, but nothing uses that */ - int xqueSema; -#endif -#ifdef XINPUT - struct _LocalDeviceRec *local; -#endif -} MouseDevRec, *MouseDevPtr; +#ifndef _XF86_H +#define _XF86_H -#ifdef XINPUT -#define MOUSE_DEV(dev) (MouseDevPtr) PRIVATE(dev) +#include "xf86str.h" +#include "xf86Opt.h" +#include <X11/Xfuncproto.h> +#ifndef IN_MODULE +#include <stdarg.h> #else -#define MOUSE_DEV(dev) (MouseDevPtr) (dev)->public.devicePrivate +#include "xf86_ansic.h" +#endif + +#include "propertyst.h" + +/* General parameters */ +extern int xf86DoConfigure; +extern Bool xf86DoConfigurePass1; +extern int xf86ScreenIndex; /* Index into pScreen.devPrivates */ +extern int xf86CreateRootWindowIndex; /* Index into pScreen.devPrivates */ +extern int xf86PixmapIndex; +extern Bool xf86ResAccessEnter; +extern ScrnInfoPtr *xf86Screens; /* List of pointers to ScrnInfoRecs */ +extern const unsigned char byte_reversed[256]; +extern PropertyPtr *xf86RegisteredPropertiesTable; +extern ScrnInfoPtr xf86CurrentScreen; +extern Bool pciSlotClaimed; +extern Bool isaSlotClaimed; +extern Bool fbSlotClaimed; +#ifdef __sparc__ +extern Bool sbusSlotClaimed; +#endif +extern confDRIRec xf86ConfigDRI; +extern Bool xf86inSuspend; + +#define XF86SCRNINFO(p) ((ScrnInfoPtr)((p)->devPrivates[xf86ScreenIndex].ptr)) + +#define XF86FLIP_PIXELS() \ + do { \ + if (xf86GetFlipPixels()) { \ + pScreen->whitePixel = (pScreen->whitePixel) ? 0 : 1; \ + pScreen->blackPixel = (pScreen->blackPixel) ? 0 : 1; \ + } \ + while (0) + +#define BOOLTOSTRING(b) ((b) ? "TRUE" : "FALSE") + +#define PIX24TOBPP(p) (((p) == Pix24Use24) ? 24 : \ + (((p) == Pix24Use32) ? 32 : 0)) + +/* variables for debugging */ +#ifdef BUILDDEBUG +extern char* xf86p8bit[]; +extern CARD32 xf86DummyVar1; +extern CARD32 xf86DummyVar2; +extern CARD32 xf86DummyVar3; #endif -/* Global data */ -/* xf86Init.c */ -extern double xf86rGamma, xf86gGamma, xf86bGamma; - -#ifdef XF86VIDMODE -extern Bool xf86VidModeEnabled; -extern Bool xf86VidModeAllowNonLocal; -#endif -#ifdef XF86MISC -extern Bool xf86MiscModInDevEnabled; -extern Bool xf86MiscModInDevAllowNonLocal; -#endif - -/* PCI probe flags */ - - -typedef enum { - PCIProbe1 = 0, - PCIProbe2, - PCIForceConfig1, - PCIForceConfig2 -} PciProbeType; - -extern PciProbeType xf86PCIFlags; - /* Function Prototypes */ #ifndef _NO_XF86_PROTOTYPES -/* xf86Init.c */ -void InitOutput( -#if NeedFunctionPrototypes - ScreenInfo *pScreenInfo, - int argc, - char **argv -#endif -); - -void InitInput( -#if NeedFunctionPrototypes - int argc, - char **argv -#endif -); - -void ddxGiveUp( -#if NeedFunctionPrototypes - void -#endif -); - -void AbortDDX( -#if NeedFunctionPrototypes - void -#endif -); - -int ddxProcessArgument( -#if NeedFunctionPrototypes - int argc, - char *argv[], - int i -#endif -); - -void ddxUseMsg( -#if NeedFunctionPrototypes - void -#endif -); - -/* xf86Config.c */ -unsigned int StrToUL( -#if NeedFunctionPrototypes - char *str -#endif -); - -#ifndef CONFIG_RETURN_TYPE -#ifdef XF86SETUP -#define CONFIG_RETURN_TYPE int -#else -#define CONFIG_RETURN_TYPE void -#endif -#endif - -CONFIG_RETURN_TYPE xf86Config( -#if NeedFunctionPrototypes - int vtopen -#endif -); - -CONFIG_RETURN_TYPE configPointerSection( -#if NeedFunctionPrototypes - MouseDevPtr /*mouse_dev*/, - int /*end_tag*/, - char** /*devicename*/ -#endif -); - -Bool xf86LookupMode( -#if NeedFunctionPrototypes - DisplayModePtr target, - ScrnInfoPtr driver, - int flags -#endif -); - -void xf86VerifyOptions( -#if NeedFunctionPrototypes - OFlagSet *allowedOptions, - ScrnInfoPtr driver -#endif -); - -int xf86CheckMode( -#if NeedFunctionPrototypes - ScrnInfoPtr scrp, - DisplayModePtr dispmp, - MonPtr monp, - int verbose -#endif -); - -int xf86GetNearestClock( -#if NeedFunctionPrototypes - ScrnInfoPtr Screen, - int Frequency -#endif -); - +/* xf86Bus.c */ + +Bool xf86CheckPciSlot(int bus, int device, int func); +int xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp, + int chipset, GDevPtr dev, Bool active); +Bool xf86ParsePciBusString(const char *busID, int *bus, int *device, + int *func); +Bool xf86ComparePciBusString(const char *busID, int bus, int device, int func); +void xf86FormatPciBusNumber(int busnum, char *buffer); +pciVideoPtr *xf86GetPciVideoInfo(void); +pciConfigPtr *xf86GetPciConfigInfo(void); +void xf86SetPciVideo(pciVideoPtr, resType); +void xf86PrintResList(int verb, resPtr list); +resPtr xf86AddRangesToList(resPtr list, resRange *pRange, int entityIndex); +int xf86ClaimIsaSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active); +int xf86GetIsaInfoForScreen(int scrnIndex); +int xf86GetFbInfoForScreen(int scrnIndex); +Bool xf86ParseIsaBusString(const char *busID); +int xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active); +int xf86ClaimNoSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active); +void xf86EnableAccess(ScrnInfoPtr pScrn); +void xf86SetCurrentAccess(Bool Enable, ScrnInfoPtr pScrn); +Bool xf86IsPrimaryPci(pciVideoPtr pPci); +Bool xf86IsPrimaryIsa(void); +int xf86CheckPciGAType(pciVideoPtr pPci); +/* new RAC */ +resPtr xf86AddResToList(resPtr rlist, resRange *Range, int entityIndex); +resPtr xf86JoinResLists(resPtr rlist1, resPtr rlist2); +resPtr xf86DupResList(const resPtr rlist); +void xf86FreeResList(resPtr rlist); +void xf86ClaimFixedResources(resList list, int entityIndex); +Bool xf86DriverHasEntities(DriverPtr drvp); +void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex); +void xf86SetEntityInstanceForScreen(ScrnInfoPtr pScrn, int entityIndex, + int instance); +int xf86GetNumEntityInstances(int entityIndex); +GDevPtr xf86GetDevFromEntity(int entityIndex, int instance); +void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex); +EntityInfoPtr xf86GetEntityInfo(int entityIndex); +pciVideoPtr xf86GetPciInfoForEntity(int entityIndex); +int xf86GetPciEntity(int bus, int dev, int func); +Bool xf86SetEntityFuncs(int entityIndex, EntityProc init, + EntityProc enter, EntityProc leave, pointer); +void xf86DeallocateResourcesForEntity(int entityIndex, unsigned long type); +resPtr xf86RegisterResources(int entityIndex, resList list, + unsigned long Access); +Bool xf86CheckPciMemBase(pciVideoPtr pPci, memType base); +void xf86SetAccessFuncs(EntityInfoPtr pEnt, xf86SetAccessFuncPtr funcs, + xf86SetAccessFuncPtr oldFuncs); +Bool xf86IsEntityPrimary(int entityIndex); +Bool xf86FixPciResource(int entityIndex, int prt, memType alignment, + unsigned long type); +resPtr xf86ReallocatePciResources(int entityIndex, resPtr pRes); +resPtr xf86SetOperatingState(resList list, int entityIndex, int mask); +void xf86EnterServerState(xf86State state); +resRange xf86GetBlock(unsigned long type, memType size, + memType window_start, memType window_end, + memType align_mask, resPtr avoid); +resRange xf86GetSparse(unsigned long type, memType fixed_bits, + memType decode_mask, memType address_mask, + resPtr avoid); +memType xf86ChkConflict(resRange *rgp, int entityIndex); +Bool xf86IsPciDevPresent(int bus, int dev, int func); +ScrnInfoPtr xf86FindScreenForEntity(int entityIndex); +Bool xf86NoSharedResources(int screenIndex, resType res); +resPtr xf86FindIntersectOfLists(resPtr l1, resPtr l2); +pciVideoPtr xf86FindPciDeviceVendor(CARD16 vendorID, CARD16 deviceID, + char n, pciVideoPtr pvp_exclude); +pciVideoPtr xf86FindPciClass(CARD8 intf, CARD8 subClass, CARD16 class, + char n, pciVideoPtr pvp_exclude); +#ifdef INCLUDE_DEPRECATED +void xf86EnablePciBusMaster(pciVideoPtr pPci, Bool enable); +#endif +void xf86RegisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func, pointer arg); +Bool xf86DeregisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func); +#ifdef async +Bool xf86QueueAsyncEvent(void (*func)(pointer),pointer arg); +#endif + +int xf86GetLastScrnFlag(int entityIndex); +void xf86SetLastScrnFlag(int entityIndex, int scrnIndex); +Bool xf86IsEntityShared(int entityIndex); +void xf86SetEntityShared(int entityIndex); +Bool xf86IsEntitySharable(int entityIndex); +void xf86SetEntitySharable(int entityIndex); +Bool xf86IsPrimInitDone(int entityIndex); +void xf86SetPrimInitDone(int entityIndex); +void xf86ClearPrimInitDone(int entityIndex); +int xf86AllocateEntityPrivateIndex(void); +DevUnion *xf86GetEntityPrivate(int entityIndex, int privIndex); + +/* xf86Configure.c */ +GDevPtr xf86AddBusDeviceToConfigure(const char *driver, BusType bus, + void *busData, int chipset); +GDevPtr xf86AddDeviceToConfigure(const char *driver, pciVideoPtr pVideo, + int chipset); + /* xf86Cursor.c */ -void xf86InitViewport( -#if NeedFunctionPrototypes - ScrnInfoPtr pScr -#endif -); - -void xf86SetViewport( -#if NeedFunctionPrototypes - ScreenPtr pScreen, - int x, - int y -#endif -); - -void xf86LockZoom( -#if NeedFunctionPrototypes - ScreenPtr pScreen, - int lock -#endif -); - -void xf86ZoomViewport( -#if NeedFunctionPrototypes - ScreenPtr pScreen, - int zoom -#endif -); - -/* xf86Dl.c */ -void* -xf86LoadModule( -#if NeedFunctionPrototypes - const char * file, - const char * path -#endif -); - -/* xf86Events.c */ -int TimeSinceLastInputEvent( -#if NeedFunctionPrototypes - void -#endif -); - -void SetTimeSinceLastInputEvent( -#if NeedFunctionPrototypes - void -#endif -); - -void ProcessInputEvents( -#if NeedFunctionPrototypes - void -#endif -); -void xf86PostKbdEvent( -#if NeedFunctionPrototypes - unsigned key -#endif -); - -void xf86PostMseEvent( -#if NeedFunctionPrototypes - DeviceIntPtr device, - int buttons, - int dx, - int dy -#endif -); +void xf86LockZoom(ScreenPtr pScreen, int lock); +void xf86InitViewport(ScrnInfoPtr pScr); +void xf86SetViewport(ScreenPtr pScreen, int x, int y); +void xf86ZoomViewport(ScreenPtr pScreen, int zoom); +Bool xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode); +void *xf86GetPointerScreenFuncs(void); +void xf86InitOrigins(void); +void xf86ReconfigureLayout(void); + +/* xf86DPMS.c */ -void xf86Block( -#if NeedFunctionPrototypes - pointer blockData, - OSTimePtr pTimeout, - pointer pReadmask -#endif -); +Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags); -void xf86Wakeup( -#if NeedFunctionPrototypes - pointer blockData, - int err, - pointer pReadmask -#endif -); +/* xf86DGA.c */ -void xf86SigHandler( -#if NeedFunctionPrototypes - int signo -#endif -); - -/* xf86Io.c */ -void xf86KbdBell( -#if NeedFunctionPrototypes - int percent, - DeviceIntPtr pKeyboard, - pointer ctrl, - int unused -#endif -); - -void xf86KbdLeds( -#if NeedFunctionPrototypes - void -#endif -); +Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs, DGAModePtr modes, + int num); +xf86SetDGAModeProc xf86SetDGAMode; -void xf86KbdCtrl( -#if NeedFunctionPrototypes - DevicePtr pKeyboard, - KeybdCtrl *ctrl -#endif -); - -void xf86InitKBD( -#if NeedFunctionPrototypes - Bool init -#endif -); - -int xf86KbdProc( -#if NeedFunctionPrototypes - DeviceIntPtr pKeyboard, - int what -#endif -); - -void xf86MseCtrl( -#if NeedFunctionPrototypes - DevicePtr pPointer, - PtrCtrl *ctrl -#endif -); - -int GetMotionEvents( -#if NeedFunctionPrototypes - DeviceIntPtr, - xTimecoord *, - unsigned long, - unsigned long, - ScreenPtr -#endif -); +/* xf86Events.c */ -int xf86MseProc( -#if NeedFunctionPrototypes - DeviceIntPtr pPointer, - int what -#endif -); +void SetTimeSinceLastInputEvent(void); +pointer xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data); +int xf86RemoveInputHandler(pointer handler); +void xf86DisableInputHandler(pointer handler); +void xf86EnableInputHandler(pointer handler); +void xf86InterceptSignals(int *signo); +Bool xf86EnableVTSwitch(Bool new); +Bool xf86CommonSpecialKey(int key, Bool down, int modifiers); +void xf86ProcessActionEvent(ActionEvent action, void *arg); + +/* xf86Helper.c */ + +void xf86AddDriver(DriverPtr driver, pointer module, int flags); +void xf86DeleteDriver(int drvIndex); +ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags); +void xf86DeleteScreen(int scrnIndex, int flags); +int xf86AllocateScrnInfoPrivateIndex(void); +Bool xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad); +Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp, int fbbpp, + int depth24flags); +void xf86PrintDepthBpp(ScrnInfoPtr scrp); +Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask); +Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual); +Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma newGamma); +void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y); +void xf86SetBlackWhitePixels(ScreenPtr pScreen); +void xf86EnableDisableFBAccess(int scrnIndex, Bool enable); +void xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, + const char *format, va_list args); +void xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, + const char *format, ...); +void xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...); +void xf86MsgVerb(MessageType type, int verb, const char *format, ...); +void xf86Msg(MessageType type, const char *format, ...); +void xf86ErrorFVerb(int verb, const char *format, ...); +void xf86ErrorF(const char *format, ...); +const char *xf86TokenToString(SymTabPtr table, int token); +int xf86StringToToken(SymTabPtr table, const char *string); +void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from); +void xf86PrintChipsets(const char *drvname, const char *drvmsg, + SymTabPtr chips); +int xf86MatchDevice(const char *drivername, GDevPtr **driversectlist); +int xf86MatchPciInstances(const char *driverName, int vendorID, + SymTabPtr chipsets, PciChipsets *PCIchipsets, + GDevPtr *devList, int numDevs, DriverPtr drvp, + int **foundEntities); +int xf86MatchIsaInstances(const char *driverName, SymTabPtr chipsets, + IsaChipsets *ISAchipsets, DriverPtr drvp, + FindIsaDevProc FindIsaDevice, GDevPtr *devList, + int numDevs, int **foundEntities); +void xf86GetClocks(ScrnInfoPtr pScrn, int num, + Bool (*ClockFunc)(ScrnInfoPtr, int), + void (*ProtectRegs)(ScrnInfoPtr, Bool), + void (*BlankScreen)(ScrnInfoPtr, Bool), + IOADDRESS vertsyncreg, int maskval, + int knownclkindex, int knownclkvalue); +void xf86SetPriority(Bool up); +const char *xf86GetVisualName(int visual); +int xf86GetVerbosity(void); +Pix24Flags xf86GetPix24(void); +int xf86GetDepth(void); +rgb xf86GetWeight(void); +Gamma xf86GetGamma(void); +Bool xf86GetFlipPixels(void); +const char *xf86GetServerName(void); +Bool xf86ServerIsExiting(void); +Bool xf86ServerIsResetting(void); +Bool xf86ServerIsInitialising(void); +Bool xf86ServerIsOnlyDetecting(void); +Bool xf86ServerIsOnlyProbing(void); +Bool xf86CaughtSignal(void); +Bool xf86GetVidModeAllowNonLocal(void); +Bool xf86GetVidModeEnabled(void); +Bool xf86GetModInDevAllowNonLocal(void); +Bool xf86GetModInDevEnabled(void); +Bool xf86GetAllowMouseOpenFail(void); +Bool xf86IsPc98(void); +void xf86DisableRandR(void); +CARD32 xf86GetVersion(void); +CARD32 xf86GetModuleVersion(pointer module); +pointer xf86LoadDrvSubModule(DriverPtr drv, const char *name); +pointer xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name); +pointer xf86LoadOneModule(char *name, pointer optlist); +void xf86UnloadSubModule(pointer mod); +Bool xf86LoaderCheckSymbol(const char *name); +void xf86LoaderReqSymLists(const char **, ...); +void xf86LoaderReqSymbols(const char *, ...); +void xf86LoaderRefSymLists(const char **, ...); +void xf86LoaderRefSymbols(const char *, ...); +void xf86SetBackingStore(ScreenPtr pScreen); +void xf86SetSilkenMouse(ScreenPtr pScreen); +int xf86NewSerialNumber(WindowPtr p, pointer unused); +pointer xf86FindXvOptions(int scrnIndex, int adapt_index, char *port_name, + char **adaptor_name, pointer *adaptor_options); +void xf86GetOS(const char **name, int *major, int *minor, int *teeny); +ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn, int scrnFlag, + int entityIndex,PciChipsets *p_chip, + resList res, EntityProc init, + EntityProc enter, EntityProc leave, + pointer private); +ScrnInfoPtr xf86ConfigIsaEntity(ScrnInfoPtr pScrn, int scrnFlag, + int entityIndex, IsaChipsets *i_chip, + resList res, EntityProc init, + EntityProc enter, EntityProc leave, + pointer private); +ScrnInfoPtr xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, + int entityIndex, EntityProc init, + EntityProc enter, EntityProc leave, + pointer private); +/* Obsolete! don't use */ +Bool xf86ConfigActivePciEntity(ScrnInfoPtr pScrn, + int entityIndex,PciChipsets *p_chip, + resList res, EntityProc init, + EntityProc enter, EntityProc leave, + pointer private); +/* Obsolete! don't use */ +Bool xf86ConfigActiveIsaEntity(ScrnInfoPtr pScrn, + int entityIndex, IsaChipsets *i_chip, + resList res, EntityProc init, + EntityProc enter, EntityProc leave, + pointer private); +void xf86ConfigPciEntityInactive(EntityInfoPtr pEnt, PciChipsets *p_chip, + resList res, EntityProc init, + EntityProc enter, EntityProc leave, + pointer private); +void xf86ConfigIsaEntityInactive(EntityInfoPtr pEnt, IsaChipsets *i_chip, + resList res, EntityProc init, + EntityProc enter, EntityProc leave, + pointer private); +void xf86ConfigFbEntityInactive(EntityInfoPtr pEnt, EntityProc init, + EntityProc enter, EntityProc leave, + pointer private); +Bool xf86IsScreenPrimary(int scrnIndex); +int xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type, + int format, unsigned long len, + pointer value); +Bool xf86IsUnblank(int mode); + +#ifdef XFree86LOADER +void xf86AddModuleInfo(ModuleInfoPtr info, pointer module); +void xf86DeleteModuleInfo(int idx); +#endif + +/* xf86Debug.c */ +#ifdef BUILDDEBUG + void xf86Break1(void); +void xf86Break2(void); +void xf86Break3(void); +CARD8 xf86PeekFb8(CARD8 *p); +CARD16 xf86PeekFb16(CARD16 *p); +CARD32 xf86PeekFb32(CARD32 *p); +void xf86PokeFb8(CARD8 *p, CARD8 v); +void xf86PokeFb16(CARD16 *p, CARD16 v); +void xf86PokeFb32(CARD16 *p, CARD32 v); +CARD8 xf86PeekMmio8(pointer Base, unsigned long Offset); +CARD16 xf86PeekMmio16(pointer Base, unsigned long Offset); +CARD32 xf86PeekMmio32(pointer Base, unsigned long Offset); +void xf86PokeMmio8(pointer Base, unsigned long Offset, CARD8 v); +void xf86PokeMmio16(pointer Base, unsigned long Offset, CARD16 v); +void xf86PokeMmio32(pointer Base, unsigned long Offset, CARD32 v); +extern void xf86SPTimestamp(xf86TsPtr* timestamp, char* string); +extern void xf86STimestamp(xf86TsPtr* timestamp); +#endif + +/* xf86Init.c */ -void xf86MseEvents( -#if NeedFunctionPrototypes - MouseDevPtr mouse -#endif -); +PixmapFormatPtr xf86GetPixFormat(ScrnInfoPtr pScrn, int depth); +int xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth); -CARD32 GetTimeInMillis( -#if NeedFunctionPrototypes - void -#endif -); +/* xf86Mode.c */ -void OsVendorInit( -#if NeedFunctionPrototypes - void -#endif -); +int xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2, + int DivFactor, int MulFactor, int *divider); +const char *xf86ModeStatusToString(ModeStatus status); +ModeStatus xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep, + ClockRangePtr clockRanges, LookupModeFlags strategy); +ModeStatus xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor); +ModeStatus xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, + ClockRangePtr clockRanges, + LookupModeFlags strategy, + int maxPitch, int virtualX, + int virtualY); +ModeStatus xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, + int flags); +int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, + char **modeNames, ClockRangePtr clockRanges, + int *linePitches, int minPitch, int maxPitch, + int minHeight, int maxHeight, int pitchInc, + int virtualX, int virtualY, int apertureSize, + LookupModeFlags strategy); +void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode); +void xf86PruneDriverModes(ScrnInfoPtr scrp); +void xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags); +void xf86PrintModes(ScrnInfoPtr scrp); +void xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges); -/* xf86_Mouse.c */ -Bool xf86MouseSupported( -#if NeedFunctionPrototypes - int mousetype -#endif -); +/* xf86Option.c */ -void xf86SetupMouse( -#if NeedFunctionPrototypes - MouseDevPtr mouse -#endif -); +void xf86CollectOptions(ScrnInfoPtr pScrn, pointer extraOpts); -void xf86MouseProtocol( -#if NeedFunctionPrototypes - DeviceIntPtr device, - unsigned char *rBuf, - int nBytes -#endif -); -#ifdef XINPUT -void xf86MouseCtrl( -#if NeedFunctionPrototypes - DeviceIntPtr device, - PtrCtrl *ctrl -#endif -); +/* xf86RandR.c */ +#ifdef RANDR +Bool xf86RandRInit (ScreenPtr pScreen); +void xf86RandRSetInitialMode (ScreenPtr pScreen); #endif -/* xf86_PnPMouse.c */ -int xf86GetPnPMouseProtocol( -#if NeedFunctionPrototypes - MouseDevPtr mouse -#endif -); +/* xf86VidModeExtentionInit.c */ -/* xf86Kbd.c */ -Bool LegalModifier( -#if NeedFunctionPrototypes - unsigned int key, - DevicePtr pDev -#endif -); +Bool VidModeExtensionInit(ScreenPtr pScreen); -void xf86KbdGetMapping( -#if NeedFunctionPrototypes - KeySymsPtr pKeySyms, - CARD8 *pModMap -#endif -); #endif /* _NO_XF86_PROTOTYPES */ -/* End of Prototypes */ - #endif /* _XF86_H */ - - diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index e523dd0fc..1738222f5 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -1,245 +1,98 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 3.269 2003/02/20 04:36:07 dawes Exp $ */ + + /* - * $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 3.113.2.17 1998/02/24 19:05:54 hohndel Exp $ + * Copyright 1991-2002 by The XFree86 Project, Inc. + * Copyright 1997 by Metro Link, Inc. * - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. + * Loosely based on code bearing the following copyright: * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Thomas Roell not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Thomas Roell makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. * - * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * <Put copyright message here> + * + * Author: Dirk Hohndel <hohndel@XFree86.Org> and others. */ -/* $Xorg: xf86Config.c,v 1.3 2000/08/17 19:50:28 cpqbld Exp $ */ - -#ifndef X_NOT_STDC_ENV -#include <stdlib.h> -#else -extern double atof(); -extern char *getenv(); -#endif - -#define NEED_EVENTS 1 -#include "X.h" -#include "Xproto.h" -#include "Xmd.h" -#include "input.h" -#include "servermd.h" -#include "scrnintstr.h" -#ifdef DPMSExtension -#include "opaque.h" -extern CARD32 DPMSStandbyTime; -extern CARD32 DPMSSuspendTime; -extern CARD32 DPMSOffTime; +#ifdef XF86DRI +#include <sys/types.h> +#include <grp.h> #endif -#define NO_COMPILER_H_EXTRAS -#include "xf86Procs.h" +#include "xf86.h" +#include "xf86Parser.h" +#include "xf86tokens.h" +#include "xf86Config.h" +#include "xf86Priv.h" #include "xf86_OSlib.h" -#define INIT_CONFIG -#include "xf86_Config.h" - -#ifdef XKB -#include "inputstr.h" -#include "XKBsrv.h" -#endif - -#ifdef XF86SETUP -#include "xfsconf.h" -#endif +#include "globals.h" #ifdef XINPUT #include "xf86Xinput.h" - -#ifndef XF86SETUP -extern DeviceAssocRec mouse_assoc; -#endif +extern DeviceAssocRec mouse_assoc; #endif -#ifdef NEED_RETURN_VALUE -#define HANDLE_RETURN(xx) if (xx == RET_ERROR) return RET_ERROR -#else -#define HANDLE_RETURN(xx) xx +#ifdef XKB +#define XKB_IN_SERVER +#include "XKBsrv.h" #endif -#define CONFIG_BUF_LEN 1024 - -static FILE * configFile = NULL; -static int configStart = 0; /* start of the current token */ -static int configPos = 0; /* current readers position */ -static int configLineNo = 0; /* linenumber */ -static char *configBuf,*configRBuf; /* buffer for lines */ -static char *configPath; /* path to config file */ -static char *fontPath = NULL; /* font path */ -static char *modulePath = NULL; /* module path */ -static int pushToken = LOCK_TOKEN; -static LexRec val; /* global return value */ -static char DCerr; -static int scr_index = 0; - -#ifdef XF86SETUP -#define STATIC_OR_NOT -#else -#define STATIC_OR_NOT static +#ifdef RENDER +#include "picture.h" #endif -STATIC_OR_NOT int n_monitors = 0; -STATIC_OR_NOT MonPtr monitor_list = NULL; -STATIC_OR_NOT int n_devices = 0; -STATIC_OR_NOT GDevPtr device_list = NULL; - -static int screenno = -100; /* some little number ... */ -extern char *defaultFontPath; -extern char *rgbPath; - -extern Bool xf86fpFlag, xf86coFlag, xf86sFlag; -extern Bool xf86ScreensOpen; - -extern int defaultColorVisualClass; -extern CARD32 defaultScreenSaverTime, ScreenSaverTime; - -char *xf86VisualNames[] = { - "StaticGray", - "GrayScale", - "StaticColor", - "PseudoColor", - "TrueColor", - "DirectColor" -}; - -static CONFIG_RETURN_TYPE configFilesSection( -#if NeedFunctionPrototypes - void -#endif -); -static CONFIG_RETURN_TYPE configServerFlagsSection( -#if NeedFunctionPrototypes - void -#endif -); -static CONFIG_RETURN_TYPE configKeyboardSection( -#if NeedFunctionPrototypes - void -#endif -); -static CONFIG_RETURN_TYPE configDeviceSection( -#if NeedFunctionPrototypes - void -#endif -); -static CONFIG_RETURN_TYPE configScreenSection( -#if NeedFunctionPrototypes - void -#endif -); -static CONFIG_RETURN_TYPE configDisplaySubsection( -#if NeedFunctionPrototypes - DispPtr disp -#endif -); -static CONFIG_RETURN_TYPE configMonitorSection( -#if NeedFunctionPrototypes - void -#endif -); -static CONFIG_RETURN_TYPE configDynamicModuleSection( -#if NeedFunctionPrototypes - void -#endif -); -static char *xf86DCSaveLine( -#if NeedFunctionPrototypes -char *, -int -#endif -); -static char *xf86DCOption( -#if NeedFunctionPrototypes -char *, -LexRec -#endif -); -static char * xf86DCConcatOption( -#if NeedFunctionPrototypes -char *, -char * -#endif -); -#ifndef XF86SETUP -static -#endif -CONFIG_RETURN_TYPE findConfigFile( -#if NeedFunctionPrototypes - char *filename, - FILE **fp -#endif -); -static int getScreenIndex( -#if NeedFunctionPrototypes - int token -#endif -); -static int getStringToken( -#if NeedFunctionPrototypes - SymTabRec tab[] -#endif -); -static CONFIG_RETURN_TYPE readVerboseMode( -#if NeedFunctionPrototypes - MonPtr monp -#endif -); -static Bool validateGraphicsToken( -#if NeedFunctionPrototypes - int *validTokens, - int token -#endif -); -extern char * xf86GetPathElem( -#if NeedFunctionPrototypes - char **pnt -#endif -); -static DisplayModePtr xf86PruneModes( -#if NeedFunctionPrototypes - MonPtr monp, - DisplayModePtr allmodes, - ScrnInfoPtr scrp, - Bool card -#endif -); -static char * xf86ValidateFontPath( -#if NeedFunctionPrototypes - char * /* path */ -#endif -); -#ifdef XINPUT -extern CONFIG_RETURN_TYPE xf86ConfigExtendedInputSection( -#if NeedFunctionPrototypes - LexPtr pval -#endif -); +#if (defined(i386) || defined(__i386__)) && \ + (defined(__FreeBSD__) || defined(__NetBSD__) || defined(linux) || \ + (defined(SVR4) && !defined(sun)) || defined(__GNU__)) +#define SUPPORT_PC98 #endif -#ifdef XKB -extern char *XkbInitialMap; +/* + * These paths define the way the config file search is done. The escape + * sequences are documented in parser/scan.c. + */ +#ifndef ROOT_CONFIGPATH +#define ROOT_CONFIGPATH "%A," "%R," \ + "/etc/X11/%R," "%P/etc/X11/%R," \ + "%E," "%F," \ + "/etc/X11/%F," "%P/etc/X11/%F," \ + "%D/%X," \ + "/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \ + "%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \ + "%P/etc/X11/%X," \ + "%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \ + "%P/lib/X11/%X" +#endif +#ifndef USER_CONFIGPATH +#define USER_CONFIGPATH "/etc/X11/%S," "%P/etc/X11/%S," \ + "/etc/X11/%G," "%P/etc/X11/%G," \ + "/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \ + "%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \ + "%P/etc/X11/%X," \ + "%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \ + "%P/lib/X11/%X" +#endif +#ifndef PROJECTROOT +#define PROJECTROOT "/usr/X11R6" +#endif + +static char *fontPath = NULL; + +/* Forward declarations */ +static Bool configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, + int scrnum, MessageType from); +static Bool configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor); +static Bool configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, + Bool active); +static Bool configInput(IDevPtr inputp, XF86ConfInputPtr conf_input, + MessageType from); +static Bool configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display); +static Bool addDefaultModes(MonPtr monitorp); +#ifdef XF86DRI +static Bool configDRI(XF86ConfDRIPtr drip); #endif -#define DIR_FILE "/fonts.dir" - /* * xf86GetPathElem -- * Extract a single element from the font path string starting at @@ -247,9 +100,8 @@ extern char *XkbInitialMap; * updated to point to the start of the next element, or set to * NULL if there are no more. */ -char * -xf86GetPathElem(pnt) - char **pnt; +static char * +xf86GetPathElem(char **pnt) { char *p1; @@ -263,46 +115,6 @@ xf86GetPathElem(pnt) } /* - * StrToUL -- - * - * A portable, but restricted, version of strtoul(). It only understands - * hex, octal, and decimal. But it's good enough for our needs. - */ -unsigned int StrToUL(str) -char *str; -{ - int base = 10; - char *p = str; - unsigned int tot = 0; - - if (*p == '0') { - p++; - if (*p == 'x') { - p++; - base = 16; - } - else - base = 8; - } - while (*p) { - if ((*p >= '0') && (*p <= ((base == 8)?'7':'9'))) { - tot = tot * base + (*p - '0'); - } - else if ((base == 16) && (*p >= 'a') && (*p <= 'f')) { - tot = tot * base + 10 + (*p - 'a'); - } - else if ((base == 16) && (*p >= 'A') && (*p <= 'F')) { - tot = tot * base + 10 + (*p - 'A'); - } - else { - return(tot); - } - p++; - } - return(tot); -} - -/* * xf86ValidateFontPath -- * Validates the user-specified font path. Each element that * begins with a '/' is checked to make sure the directory exists. @@ -310,31 +122,30 @@ char *str; * is checked. If either check fails, an error is printed and the * element is removed from the font path. */ -#define CHECK_TYPE(mode, type) ((S_IFMT & (mode)) == (type)) + +#define DIR_FILE "/fonts.dir" static char * -xf86ValidateFontPath(path) - char *path; +xf86ValidateFontPath(char *path) { char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem; struct stat stat_buf; int flag; int dirlen; - tmp_path = (char *)Xcalloc(strlen(path)+1); + tmp_path = xcalloc(1,strlen(path)+1); out_pnt = tmp_path; path_elem = NULL; next = path; while (next != NULL) { path_elem = xf86GetPathElem(&next); -#ifndef __EMX__ if (*path_elem == '/') { - dir_elem = (char *)Xcalloc(strlen(path_elem) + 1); +#ifndef __UNIXOS2__ + dir_elem = xnfcalloc(1, strlen(path_elem) + 1); if ((p1 = strchr(path_elem, ':')) != 0) #else /* OS/2 must prepend X11ROOT */ - if (*path_elem == '/') { path_elem = (char*)__XOS2RedirRoot(path_elem); - dir_elem = (char*)xcalloc(1, strlen(path_elem) + 1); + dir_elem = xnfcalloc(1, strlen(path_elem) + 1); if (p1 = strchr(path_elem+2, ':')) #endif dirlen = p1 - path_elem; @@ -344,29 +155,32 @@ xf86ValidateFontPath(path) dir_elem[dirlen] = '\0'; flag = stat(dir_elem, &stat_buf); if (flag == 0) - if (!CHECK_TYPE(stat_buf.st_mode, S_IFDIR)) + if (!S_ISDIR(stat_buf.st_mode)) flag = -1; if (flag != 0) { - ErrorF("Warning: The directory \"%s\" does not exist.\n", dir_elem); - ErrorF(" Entry deleted from font path.\n"); + xf86Msg(X_WARNING, "The directory \"%s\" does not exist.\n", dir_elem); + xf86ErrorF("\tEntry deleted from font path.\n"); + xfree(dir_elem); continue; } else { - p1 = (char *)xalloc(strlen(dir_elem)+strlen(DIR_FILE)+1); + p1 = xnfalloc(strlen(dir_elem)+strlen(DIR_FILE)+1); strcpy(p1, dir_elem); strcat(p1, DIR_FILE); flag = stat(p1, &stat_buf); if (flag == 0) - if (!CHECK_TYPE(stat_buf.st_mode, S_IFREG)) + if (!S_ISREG(stat_buf.st_mode)) flag = -1; -#ifndef __EMX__ +#ifndef __UNIXOS2__ xfree(p1); #endif if (flag != 0) { - ErrorF("Warning: 'fonts.dir' not found (or not valid) in \"%s\".\n", - dir_elem); - ErrorF(" Entry deleted from font path.\n"); - ErrorF(" (Run 'mkfontdir' on \"%s\").\n", dir_elem); + xf86Msg(X_WARNING, + "`fonts.dir' not found (or not valid) in \"%s\".\n", + dir_elem); + xf86ErrorF("\tEntry deleted from font path.\n"); + xf86ErrorF("\t(Run 'mkfontdir' on \"%s\").\n", dir_elem); + xfree(dir_elem); continue; } } @@ -385,3550 +199,2138 @@ xf86ValidateFontPath(path) return(tmp_path); } + /* - * xf86GetToken -- - * Read next Token form the config file. Handle the global variable - * pushToken. + * use the datastructure that the parser provides and pick out the parts + * that we need at this point */ -int -xf86GetToken(tab) - SymTabRec tab[]; +char ** +xf86ModulelistFromConfig(pointer **optlist) { - int c, i; - - /* - * First check whether pushToken has a different value than LOCK_TOKEN. - * In this case rBuf[] contains a valid STRING/TOKEN/NUMBER. But in the other - * case the next token must be read from the input. - */ - if (pushToken == EOF) return(EOF); - else if (pushToken == LOCK_TOKEN) - { - - c = configBuf[configPos]; - - /* - * Get start of next Token. EOF is handled, whitespaces & comments are - * skipped. - */ - do { - if (!c) { - if (fgets(configBuf,CONFIG_BUF_LEN-1,configFile) == NULL) - { - return( pushToken = EOF ); - } - configLineNo++; - configStart = configPos = 0; + int count = 0; + char **modulearray; + pointer *optarray; + XF86LoadPtr modp; + + /* + * make sure the config file has been parsed and that we have a + * ModulePath set; if no ModulePath was given, use the default + * ModulePath + */ + if (xf86configptr == NULL) { + xf86Msg(X_ERROR, "Cannot access global config data structure\n"); + return NULL; + } + + if (xf86configptr->conf_modules) { + /* + * Walk the list of modules in the "Module" section to determine how + * many we have. + */ + modp = xf86configptr->conf_modules->mod_load_lst; + while (modp) { + count++; + modp = (XF86LoadPtr) modp->list.next; } -#ifndef __EMX__ - while (((c=configBuf[configPos++])==' ') || ( c=='\t') || ( c=='\n')); -#else - while (((c=configBuf[configPos++])==' ') || ( c=='\t') || ( c=='\n') - || (c=='\r')); -#endif - if (c == '#') c = '\0'; - } while (!c); - - /* GJA -- handle '-' and ',' - * Be careful: "-hsync" is a keyword. - */ - if ( (c == ',') && !isalpha(configBuf[configPos]) ) { - configStart = configPos; return COMMA; - } else if ( (c == '-') && !isalpha(configBuf[configPos]) ) { - configStart = configPos; return DASH; - } + } + if (count == 0) + return NULL; - configStart = configPos; - /* - * Numbers are returned immediately ... - */ - if (isdigit(c)) - { - int base; - - if (c == '0') - if ((configBuf[configPos] == 'x') || - (configBuf[configPos] == 'X')) - base = 16; - else - base = 8; - else - base = 10; - - configRBuf[0] = c; i = 1; - while (isdigit(c = configBuf[configPos++]) || - (c == '.') || (c == 'x') || - ((base == 16) && (((c >= 'a') && (c <= 'f')) || - ((c >= 'A') && (c <= 'F'))))) - configRBuf[i++] = c; - configPos--; /* GJA -- one too far */ - configRBuf[i] = '\0'; - val.num = StrToUL(configRBuf); - val.realnum = atof(configRBuf); - return(NUMBER); - } - - /* - * All Strings START with a \" ... - */ - else if (c == '\"') - { - i = -1; - do { - configRBuf[++i] = (c = configBuf[configPos++]); -#ifndef __EMX__ - } while ((c != '\"') && (c != '\n') && (c != '\0')); -#else - } while ((c != '\"') && (c != '\n') && (c != '\r') && (c != '\0')); -#endif - configRBuf[i] = '\0'; - val.str = (char *)xalloc(strlen(configRBuf) + 1); - strcpy(val.str, configRBuf); /* private copy ! */ - return(STRING); - } - - /* - * ... and now we MUST have a valid token. The search is - * handled later along with the pushed tokens. - */ - else - { - configRBuf[0] = c; - i = 0; - do { - configRBuf[++i] = (c = configBuf[configPos++]);; -#ifndef __EMX__ - } while ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\0')); -#else - } while ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\r') && (c != '\0') ); -#endif - configRBuf[i] = '\0'; i=0; + /* + * allocate the memory and walk the list again to fill in the pointers + */ + modulearray = xnfalloc((count + 1) * sizeof(char*)); + optarray = xnfalloc((count + 1) * sizeof(pointer)); + count = 0; + if (xf86configptr->conf_modules) { + modp = xf86configptr->conf_modules->mod_load_lst; + while (modp) { + modulearray[count] = modp->load_name; + optarray[count] = modp->load_opt; + count++; + modp = (XF86LoadPtr) modp->list.next; } - } - else - { - - /* - * Here we deal with pushed tokens. Reinitialize pushToken again. If - * the pushed token was NUMBER || STRING return them again ... - */ - int temp = pushToken; - pushToken = LOCK_TOKEN; + modulearray[count] = NULL; + optarray[count] = NULL; + if (optlist) + *optlist = optarray; + else + xfree(optarray); + return modulearray; +} + + +char ** +xf86DriverlistFromConfig() +{ + int count = 0; + int j; + char **modulearray; + screenLayoutPtr slp; - if (temp == COMMA || temp == DASH) return(temp); - if (temp == NUMBER || temp == STRING) return(temp); + /* + * make sure the config file has been parsed and that we have a + * ModulePath set; if no ModulePath was given, use the default + * ModulePath + */ + if (xf86configptr == NULL) { + xf86Msg(X_ERROR, "Cannot access global config data structure\n"); + return NULL; } - - /* - * Joop, at last we have to lookup the token ... - */ - if (tab) - { - i = 0; - while (tab[i].token != -1) - if (StrCaseCmp(configRBuf,tab[i].name) == 0) - return(tab[i].token); - else - i++; + + /* + * Walk the list of driver lines in active "Device" sections to + * determine now many implicitly loaded modules there are. + * + */ + if (xf86ConfigLayout.screens) { + slp = xf86ConfigLayout.screens; + while ((slp++)->screen) { + count++; + } } - - return(ERROR_TOKEN); /* Error catcher */ -} -/* - * xf86GetToken -- - * Lookup a string if it is actually a token in disguise. - */ -static int -getStringToken(tab) - SymTabRec tab[]; -{ - int i; + /* + * Handle the set of inactive "Device" sections. + */ + j = 0; + while (xf86ConfigLayout.inactives[j++].identifier) + count++; - for ( i = 0 ; tab[i].token != -1 ; i++ ) { - if ( ! StrCaseCmp(tab[i].name,val.str) ) return tab[i].token; - } - return(ERROR_TOKEN); -} + if (count == 0) + return NULL; -/* - * getScreenIndex -- - * Given the screen token, returns the index in xf86Screens, or -1 if - * the screen type is not applicable to this server. - */ -static int -getScreenIndex(token) - int token; -{ - int i; - - for (i = 0; xf86ScreenNames[i] >= 0 && xf86ScreenNames[i] != token; i++) - ; - if (xf86ScreenNames[i] < 0) - return(-1); - else - return(i); -} + /* + * allocate the memory and walk the list again to fill in the pointers + */ + modulearray = xnfalloc((count + 1) * sizeof(char*)); + count = 0; + slp = xf86ConfigLayout.screens; + while (slp->screen) { + modulearray[count] = slp->screen->device->driver; + count++; + slp++; + } -/* - * validateGraphicsToken -- - * If token is a graphics token, check it is in the list of validTokens - * XXXX This needs modifying to work as it did with the old format - */ -static Bool -validateGraphicsToken(validTokens, token) - int *validTokens; - int token; -{ - int i; + j = 0; - for (i = 0; ScreenTab[i].token >= 0 && ScreenTab[i].token != token; i++) - ; - if (ScreenTab[i].token < 0) - return(FALSE); /* Not a graphics token */ + while (xf86ConfigLayout.inactives[j].identifier) + modulearray[count++] = xf86ConfigLayout.inactives[j++].driver; - for (i = 0; validTokens[i] >= 0 && validTokens[i] != token; i++) - ; - return(validTokens[i] >= 0); -} + modulearray[count] = NULL; -/* - * xf86TokenToString -- - * returns the string corresponding to token - */ -char * -xf86TokenToString(table, token) - SymTabPtr table; - int token; -{ - int i; - - for (i = 0; table[i].token >= 0 && table[i].token != token; i++) - ; - if (table[i].token < 0) - return("unknown"); - else - return(table[i].name); -} - -/* - * xf86StringToToken -- - * returns the string corresponding to token - */ -int -xf86StringToToken(table, string) - SymTabPtr table; - char *string; -{ - int i; + /* Remove duplicates */ + for (count = 0; modulearray[count] != NULL; count++) { + int i; - for (i = 0; table[i].token >= 0 && StrCaseCmp(string, table[i].name); i++) - ; - return(table[i].token); + for (i = 0; i < count; i++) + if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) { + modulearray[count] = ""; + break; + } + } + return modulearray; } - -/* - * xf86ConfigError -- - * Print a READABLE ErrorMessage!!! All information that is - * interesting is printed. Even a pointer to the erroneous place is - * printed. Maybe our e-mail will be less :-) - */ -#ifdef XF86SETUP -int -XF86SetupXF86ConfigError(msg) -#else -void -xf86ConfigError(msg) -#endif - char *msg; -{ - int i,j; - ErrorF( "\nConfig Error: %s:%d\n\n%s", configPath, configLineNo, configBuf); - for (i = 1, j = 1; i < configStart; i++, j++) - if (configBuf[i-1] != '\t') - ErrorF(" "); - else - do - ErrorF(" "); - while (((j++)%8) != 0); - for (i = configStart; i <= configPos; i++) ErrorF("^"); - ErrorF("\n%s\n", msg); -#ifdef NEED_RETURN_VALUE - return RET_ERROR; -#else - exit(-1); /* simple exit ... */ -#endif -} -#ifndef XF86SETUP -void -xf86DeleteMode(infoptr, dispmp) -ScrnInfoPtr infoptr; -DisplayModePtr dispmp; +Bool +xf86BuiltinInputDriver(const char *name) { - if(infoptr->modes == dispmp) - infoptr->modes = dispmp->next; - - if(dispmp->next == dispmp) - FatalError("No valid modes found.\n"); - - ErrorF("%s %s: Removing mode \"%s\" from list of valid modes.\n", - XCONFIG_PROBED, infoptr->name, dispmp->name); - dispmp->prev->next = dispmp->next; - dispmp->next->prev = dispmp->prev; - - xfree(dispmp->name); - xfree(dispmp); + if (xf86NameCmp(name, "keyboard") == 0) + return TRUE; + else + return FALSE; } -#endif -/* - * findConfigFile -- - * Locate the XF86Config file. Abort if not found. - */ -#ifndef XF86SETUP -static -#endif -CONFIG_RETURN_TYPE -findConfigFile(filename, fp) - char *filename; - FILE **fp; -{ -#define configFile (*fp) -#define MAXPTRIES 6 - char *home = NULL; - char *xconfig = NULL; - char *xwinhome = NULL; - char *configPaths[MAXPTRIES]; - int pcount = 0, idx; - /* - * First open if necessary the config file. - * If the -xf86config flag was used, use the name supplied there (root only). - * If $XF86CONFIG is a pathname, use it as the name of the config file (root) - * If $XF86CONFIG is set but doesn't contain a '/', append it to 'XF86Config' - * and search the standard places (root only). - * If $XF86CONFIG is not set, just search the standard places. - */ - while (!configFile) { +char ** +xf86InputDriverlistFromConfig() +{ + int count = 0; + char **modulearray; + IDevPtr idp; /* - * configPaths[0] is used as a buffer for -xf86config - * and $XF86CONFIG if it contains a path - * configPaths[1...MAXPTRIES-1] is used to store the paths of each of - * the other attempts - */ - for (pcount = idx = 0; idx < MAXPTRIES; idx++) - configPaths[idx] = NULL; - - /* - * First check if the -xf86config option was used. - */ - configPaths[pcount] = (char *)xalloc(PATH_MAX); -#ifndef __EMX__ - if (getuid() == 0 && xf86ConfigFile[0]) -#else - if (xf86ConfigFile[0]) -#endif - { - strcpy(configPaths[pcount], xf86ConfigFile); - if ((configFile = fopen(configPaths[pcount], "r")) != 0) - break; - else - FatalError( - "Cannot read file \"%s\" specified by the -xf86config flag\n", - configPaths[pcount]); - } - /* - * Check if XF86CONFIG is set. + * make sure the config file has been parsed and that we have a + * ModulePath set; if no ModulePath was given, use the default + * ModulePath */ -#ifndef __EMX__ - if (getuid() == 0 - && (xconfig = getenv("XF86CONFIG")) != 0 - && index(xconfig, '/')) -#else - /* no root available, and filenames start with drive letter */ - if ((xconfig = getenv("XF86CONFIG")) != 0 - && isalpha(xconfig[0]) - && xconfig[1]==':') -#endif - { - strcpy(configPaths[pcount], xconfig); - if ((configFile = fopen(configPaths[pcount], "r")) != 0) - break; - else - FatalError( - "Cannot read file \"%s\" specified by XF86CONFIG variable\n", - configPaths[pcount]); - } - -#ifndef __EMX__ - /* - * ~/XF86Config ... - */ - if (getuid() == 0 && (home = getenv("HOME"))) { - configPaths[++pcount] = (char *)xalloc(PATH_MAX); - strcpy(configPaths[pcount],home); - strcat(configPaths[pcount],"/XF86Config"); - if (xconfig) strcat(configPaths[pcount],xconfig); - if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break; + if (xf86configptr == NULL) { + xf86Msg(X_ERROR, "Cannot access global config data structure\n"); + return NULL; } /* - * /etc/XF86Config - */ - configPaths[++pcount] = (char *)xalloc(PATH_MAX); - strcpy(configPaths[pcount], "/etc/XF86Config"); - if (xconfig) strcat(configPaths[pcount],xconfig); - if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break; - - /* - * $(LIBDIR)/XF86Config.<hostname> + * Walk the list of driver lines in active "InputDevice" sections to + * determine now many implicitly loaded modules there are. */ + if (xf86ConfigLayout.inputs) { + idp = xf86ConfigLayout.inputs; + while (idp->identifier) { + if (!xf86BuiltinInputDriver(idp->driver)) + count++; + idp++; + } + } - configPaths[++pcount] = (char *)xalloc(PATH_MAX); - if (getuid() == 0 && (xwinhome = getenv("XWINHOME")) != NULL) - sprintf(configPaths[pcount], "%s/lib/X11/XF86Config", xwinhome); - else - strcpy(configPaths[pcount], SERVER_CONFIG_FILE); - if (getuid() == 0 && xconfig) strcat(configPaths[pcount],xconfig); - strcat(configPaths[pcount], "."); -#ifdef AMOEBA - { - extern char *XServerHostName; + if (count == 0) + return NULL; - strcat(configPaths[pcount], XServerHostName); - } -#else - gethostname(configPaths[pcount]+strlen(configPaths[pcount]), - MAXHOSTNAMELEN); -#endif - if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break; -#endif /* !__EMX__ */ - /* - * $(LIBDIR)/XF86Config + * allocate the memory and walk the list again to fill in the pointers */ - configPaths[++pcount] = (char *)xalloc(PATH_MAX); -#ifndef __EMX__ - if (getuid() == 0 && xwinhome) - sprintf(configPaths[pcount], "%s/lib/X11/XF86Config", xwinhome); - else - strcpy(configPaths[pcount], SERVER_CONFIG_FILE); - if (getuid() == 0 && xconfig) strcat(configPaths[pcount],xconfig); -#else - /* we explicitly forbid numerous config files everywhere for OS/2; - * users should consider them lucky to have one in a standard place - * and another one with the -xf86config option - */ - xwinhome = getenv("X11ROOT"); /* get drive letter */ - if (!xwinhome) FatalError("X11ROOT environment variable not set\n"); - strcpy(configPaths[pcount], __XOS2RedirRoot("/XFree86/lib/X11/XConfig")); -#endif + modulearray = xnfalloc((count + 1) * sizeof(char*)); + count = 0; + idp = xf86ConfigLayout.inputs; + while (idp->identifier) { + if (!xf86BuiltinInputDriver(idp->driver)) { + modulearray[count] = idp->driver; + count++; + } + idp++; + } + modulearray[count] = NULL; - if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break; - - ErrorF("\nCould not find config file!\n"); - ErrorF("- Tried:\n"); - for (idx = 1; idx <= pcount; idx++) - if (configPaths[idx] != NULL) - ErrorF(" %s\n", configPaths[idx]); - FatalError("No config file found!\n%s", getuid() == 0 ? "" : - "Note, the X server no longer looks for XF86Config in $HOME"); - } - strcpy(filename, configPaths[pcount]); - if (xf86Verbose) { - ErrorF("XF86Config: %s\n", filename); - ErrorF("%s stands for supplied, %s stands for probed/default values\n", - XCONFIG_GIVEN, XCONFIG_PROBED); - } - for (idx = 0; idx <= pcount; idx++) - if (configPaths[idx] != NULL) - xfree(configPaths[idx]); -#undef configFile -#undef MAXPTRIES -#ifdef NEED_RETURN_VALUE - return RET_OKAY; -#endif + /* Remove duplicates */ + for (count = 0; modulearray[count] != NULL; count++) { + int i; + + for (i = 0; i < count; i++) + if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) { + modulearray[count] = ""; + break; + } + } + return modulearray; } -static DisplayModePtr pNew, pLast; -static Bool graphFound = FALSE; /* - * xf86GetNearestClock -- - * Find closest clock to given frequency (in kHz). This assumes the - * number of clocks is greater than zero. + * Generate a compiled-in list of driver names. This is used to produce a + * consistent probe order. For the loader server, we also look for vendor- + * provided modules, pre-pending them to our own list. */ -int -xf86GetNearestClock(Screen, Frequency) - ScrnInfoPtr Screen; - int Frequency; +static char ** +GenerateDriverlist(char * dirname, char * drivernames) { - int NearestClock = 0; - int MinimumGap = abs(Frequency - Screen->clock[0]); - int i; - for (i = 1; i < Screen->clocks; i++) - { - int Gap = abs(Frequency - Screen->clock[i]); - if (Gap < MinimumGap) + char *cp, **driverlist; + int count; + + /* Count the number needed */ + count = 0; + cp = drivernames; + while (*cp) { + while (*cp && isspace(*cp)) cp++; + if (!*cp) break; + count++; + while (*cp && !isspace(*cp)) cp++; + } + + if (!count) + return NULL; + + /* Now allocate the array of pointers to 0-terminated driver names */ + driverlist = (char **)xnfalloc((count + 1) * sizeof(char *)); + count = 0; + cp = drivernames; + while (*cp) { + while (*cp && isspace(*cp)) cp++; + if (!*cp) break; + driverlist[count++] = cp; + while (*cp && !isspace(*cp)) cp++; + if (!*cp) break; + *cp++ = 0; + } + driverlist[count] = NULL; + +#ifdef XFree86LOADER { - MinimumGap = Gap; - NearestClock = i; + const char *subdirs[] = {NULL, NULL}; + static const char *patlist[] = {"(.*)_drv\\.so", "(.*)_drv\\.o", NULL}; + char **dlist, **clist, **dcp, **ccp; + int size; + + subdirs[0] = dirname; + + /* Get module list */ + dlist = LoaderListDirs(subdirs, patlist); + if (!dlist) { + xfree(driverlist); + return NULL; /* No modules, no list */ + } + + clist = driverlist; + + /* The resulting list cannot be longer than the module list */ + for (dcp = dlist, count = 0; *dcp++; count++); + driverlist = (char **)xnfalloc((size = count + 1) * sizeof(char *)); + + /* First, add modules not in compiled-in list */ + for (count = 0, dcp = dlist; *dcp; dcp++) { + for (ccp = clist; ; ccp++) { + if (!*ccp) { + driverlist[count++] = *dcp; + if (count >= size) + driverlist = (char**) + xnfrealloc(driverlist, ++size * sizeof(char*)); + break; + } + if (!strcmp(*ccp, *dcp)) + break; + } + } + + /* Next, add compiled-in names that are also modules */ + for (ccp = clist; *ccp; ccp++) { + for (dcp = dlist; *dcp; dcp++) { + if (!strcmp(*ccp, *dcp)) { + driverlist[count++] = *ccp; + if (count >= size) + driverlist = (char**) + xnfrealloc(driverlist, ++size * sizeof(char*)); + break; + } + } + } + + driverlist[count] = NULL; + xfree(clist); + xfree(dlist); } - } - return NearestClock; +#endif /* XFree86LOADER */ + + return driverlist; } -/* - * xf86Config -- - * Fill some internal structure with userdefined setups. Many internal - * Structs are initialized. The drivers are selected and initialized. - * if (! vtopen), XF86Config is read, but devices are not probed. - * if (vtopen), devices are probed (and modes resolved). - * The vtopen argument was added so that XF86Config information could be - * made available before the VT is opened. - */ -CONFIG_RETURN_TYPE -xf86Config (vtopen) - int vtopen; + +char ** +xf86DriverlistFromCompile(void) { - int token; - int i, j; -#if defined(SYSV) || defined(linux) - int xcpipe[2]; -#endif -#ifdef XINPUT - LocalDevicePtr local; -#endif - - if (!vtopen) - { + static char **driverlist = NULL; + static Bool generated = FALSE; - OFLG_ZERO(&GenericXF86ConfigFlag); - configBuf = (char*)xalloc(CONFIG_BUF_LEN); - configRBuf = (char*)xalloc(CONFIG_BUF_LEN); - configPath = (char*)xalloc(PATH_MAX); - - configBuf[0] = '\0'; /* sanity ... */ - - /* - * Read the XF86Config file with the real uid to avoid security problems - * - * For SYSV we fork, and send the data back to the parent through a pipe - */ -#if defined(SYSV) || defined(linux) - if (getuid() != 0) { - if (pipe(xcpipe)) - FatalError("Pipe failed (%s)\n", strerror(errno)); - switch (fork()) { - case -1: - FatalError("Fork failed (%s)\n", strerror(errno)); - break; - case 0: /* child */ - close(xcpipe[0]); - setuid(getuid()); - HANDLE_RETURN(findConfigFile(configPath, &configFile)); - { - unsigned char pbuf[CONFIG_BUF_LEN]; - int nbytes; - - /* Pass the filename back as the first line */ - strcat(configPath, "\n"); - if (write(xcpipe[1], configPath, strlen(configPath)) < 0) - FatalError("Child error writing to pipe (%s)\n", strerror(errno)); - while ((nbytes = fread(pbuf, 1, CONFIG_BUF_LEN, configFile)) > 0) - if (write(xcpipe[1], pbuf, nbytes) < 0) - FatalError("Child error writing to pipe (%s)\n", strerror(errno)); - } - close(xcpipe[1]); - fclose(configFile); - exit(0); - break; - default: /* parent */ - close(xcpipe[1]); - configFile = (FILE *)fdopen(xcpipe[0], "r"); - if (fgets(configPath, PATH_MAX, configFile) == NULL) - FatalError("Error reading config file\n"); - configPath[strlen(configPath) - 1] = '\0'; - } - } - else { - HANDLE_RETURN(findConfigFile(configPath, &configFile)); - } -#else /* ! (SYSV || linux) */ - { -#ifndef __EMX__ /* in OS/2 we don't care about uids */ - int real_uid = getuid(); + /* This string is modified in-place */ + static char drivernames[] = DRIVERS; - if (real_uid) { -#ifdef MINIX - setuid(getuid()); -#else -#if !defined(SVR4) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) - setruid(0); -#endif - seteuid(real_uid); -#endif /* MINIX */ + if (!generated) { + generated = TRUE; + driverlist = GenerateDriverlist("drivers", drivernames); } -#endif /* __EMX__ */ - HANDLE_RETURN(findConfigFile(configPath, &configFile)); -#if defined(MINIX) || defined(__EMX__) - /* no need to restore the uid to root */ -#else - if (real_uid) { - seteuid(0); -#if !defined(SVR4) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) - setruid(real_uid); -#endif + return driverlist; +} + + +char ** +xf86InputDriverlistFromCompile(void) +{ + static char **driverlist = NULL; + static Bool generated = FALSE; + + /* This string is modified in-place */ + static char drivernames[] = IDRIVERS; + + if (!generated) { + generated = TRUE; + driverlist = GenerateDriverlist("input", drivernames); } -#endif /* MINIX */ - } -#endif /* SYSV || linux */ - xf86Info.sharedMonitor = FALSE; - xf86Info.kbdProc = NULL; - xf86Info.notrapSignals = FALSE; - xf86Info.caughtSignal = FALSE; - - /* Allocate mouse device */ -#if defined(XINPUT) && !defined(XF86SETUP) - local = mouse_assoc.device_allocate(); - xf86Info.mouseLocal = (pointer) local; - xf86Info.mouseDev = (MouseDevPtr) local->private; - xf86Info.mouseDev->mseProc = NULL; -#else - xf86Info.mouseDev = (MouseDevPtr) Xcalloc(sizeof(MouseDevRec)); -#endif - - while ((token = xf86GetToken(TopLevelTab)) != EOF) { - switch(token) { - case SECTION: - if (xf86GetToken(NULL) != STRING) - xf86ConfigError("section name string expected"); - if ( StrCaseCmp(val.str, "files") == 0 ) { - HANDLE_RETURN(configFilesSection()); - } else if ( StrCaseCmp(val.str, "serverflags") == 0 ) { - HANDLE_RETURN(configServerFlagsSection()); - } else if ( StrCaseCmp(val.str, "keyboard") == 0 ) { - HANDLE_RETURN(configKeyboardSection()); - } else if ( StrCaseCmp(val.str, "pointer") == 0 ) { - HANDLE_RETURN(configPointerSection(xf86Info.mouseDev, ENDSECTION, NULL)); - } else if ( StrCaseCmp(val.str, "device") == 0 ) { - HANDLE_RETURN(configDeviceSection()); - } else if ( StrCaseCmp(val.str, "monitor") == 0 ) { - HANDLE_RETURN(configMonitorSection()); - } else if ( StrCaseCmp(val.str, "screen") == 0 ) { - HANDLE_RETURN(configScreenSection()); -#ifdef XINPUT - } else if ( StrCaseCmp(val.str, "xinput") == 0 ) { - HANDLE_RETURN(xf86ConfigExtendedInputSection(&val)); -#endif - } else if ( StrCaseCmp(val.str, "module") == 0 ) { - HANDLE_RETURN(configDynamicModuleSection()); - } else { - xf86ConfigError("not a recognized section name"); - } - break; - } - } - - fclose(configFile); - xfree(configBuf); - xfree(configRBuf); - xfree(configPath); - - /* These aren't needed after the XF86Config file has been read */ -#ifndef XF86SETUP - if (monitor_list) - xfree(monitor_list); - if (device_list) - xfree(device_list); -#endif - if (modulePath) - xfree(modulePath); - -#if defined(SYSV) || defined(linux) - if (getuid() != 0) { - /* Wait for the child */ - wait(NULL); - } -#endif - + + return driverlist; +} + + +/* + * xf86ConfigError -- + * Print a READABLE ErrorMessage!!! All information that is + * available is printed. + */ +static void +xf86ConfigError(char *msg, ...) +{ + va_list ap; + + ErrorF("\nConfig Error:\n"); + va_start(ap, msg); + VErrorF(msg, ap); + va_end(ap); + ErrorF("\n"); + return; +} + +static Bool +configFiles(XF86ConfFilesPtr fileconf) +{ + MessageType pathFrom = X_DEFAULT; + + /* FontPath */ + /* Try XF86Config FontPath first */ - if (!xf86fpFlag) - if (fontPath) { - char *f = xf86ValidateFontPath(fontPath); + if (!xf86fpFlag) { + if (fileconf) { + if (fileconf->file_fontpath) { + char *f = xf86ValidateFontPath(fileconf->file_fontpath); + pathFrom = X_CONFIG; if (*f) defaultFontPath = f; - else - ErrorF( - "Warning: FontPath is completely invalid. Using compiled-in default.\n" - ); - xfree(fontPath); - fontPath = (char *)NULL; - } - else - ErrorF("Warning: No FontPath specified, using compiled-in default.\n"); - else /* Use fontpath specified with '-fp' */ - { - OFLG_CLR (XCONFIG_FONTPATH, &GenericXF86ConfigFlag); + else { + xf86Msg(X_WARNING, + "FontPath is completely invalid. Using compiled-in default.\n"); + fontPath = NULL; + pathFrom = X_DEFAULT; + } + } + } else { + xf86Msg(X_WARNING, + "No FontPath specified. Using compiled-in default.\n"); + pathFrom = X_DEFAULT; + } + } else { + /* Use fontpath specified with '-fp' */ if (fontPath) { - xfree(fontPath); - fontPath = (char *)NULL; + fontPath = NULL; } + pathFrom = X_CMDLINE; } - if (!fontPath) { - /* xf86ValidateFontPath will write into it's arg, but defaultFontPath + if (!fileconf) { + /* xf86ValidateFontPath will write into it's arg, but defaultFontPath could be static, so we make a copy. */ - char *f = (char *)xalloc(strlen(defaultFontPath) + 1); + char *f = xnfalloc(strlen(defaultFontPath) + 1); f[0] = '\0'; strcpy (f, defaultFontPath); defaultFontPath = xf86ValidateFontPath(f); xfree(f); + } else { + if (fileconf) { + if (!fileconf->file_fontpath) { + /* xf86ValidateFontPath will write into it's arg, but defaultFontPath + could be static, so we make a copy. */ + char *f = xnfalloc(strlen(defaultFontPath) + 1); + f[0] = '\0'; + strcpy (f, defaultFontPath); + defaultFontPath = xf86ValidateFontPath(f); + xfree(f); + } + } } - else - xfree(fontPath); /* If defaultFontPath is still empty, exit here */ if (! *defaultFontPath) - FatalError("No valid FontPath could be found\n"); - if (xf86Verbose) - ErrorF("%s FontPath set to \"%s\"\n", - OFLG_ISSET(XCONFIG_FONTPATH, &GenericXF86ConfigFlag) ? XCONFIG_GIVEN : - XCONFIG_PROBED, defaultFontPath); - - if (!xf86Info.kbdProc) - FatalError("You must specify a keyboard in XF86Config"); - if (!xf86Info.mouseDev->mseProc) - FatalError("You must specify a mouse in XF86Config"); - - if (!graphFound) - { - Bool needcomma = FALSE; + FatalError("No valid FontPath could be found."); - ErrorF("\nYou must provide a \"Screen\" section in XF86Config for at\n"); - ErrorF("least one of the following graphics drivers: "); - for (i = 0; i < xf86MaxScreens; i++) - { - if (xf86Screens[i]) - { - ErrorF("%s%s", needcomma ? ", " : "", - xf86TokenToString(DriverTab, xf86ScreenNames[i])); - needcomma = TRUE; - } + xf86Msg(pathFrom, "FontPath set to \"%s\"\n", defaultFontPath); + + /* RgbPath */ + + pathFrom = X_DEFAULT; + + if (xf86coFlag) + pathFrom = X_CMDLINE; + else if (fileconf) { + if (fileconf->file_rgbpath) { + rgbPath = fileconf->file_rgbpath; + pathFrom = X_CONFIG; } - ErrorF("\n"); - FatalError("No configured graphics devices"); } - } -#ifndef XF86SETUP - else /* if (vtopen) */ - { - /* - * Probe all configured screens for letting them resolve their modes - */ - xf86ScreensOpen = TRUE; - for ( i=0; i < xf86MaxScreens; i++ ) - if (xf86Screens[i] && xf86Screens[i]->configured && - (xf86Screens[i]->configured = (xf86Screens[i]->Probe)())){ - /* if driver doesn't report error do it here */ - if(xf86DCGetToken(xf86Screens[i]->DCConfig,NULL,DeviceTab) != EOF){ - xf86DCConfigError("Unknown device section keyword"); - FatalError("\n"); - } - if(xf86Screens[i]->DCOptions){ - xf86DCGetOption(xf86Screens[i]->DCOptions,NULL); - FatalError("\n"); - } - xf86InitViewport(xf86Screens[i]); + + xf86Msg(pathFrom, "RgbPath set to \"%s\"\n", rgbPath); + + if (fileconf && fileconf->file_inputdevs) { + xf86InputDeviceList = fileconf->file_inputdevs; + xf86Msg(X_CONFIG, "Input device list set to \"%s\"\n", + xf86InputDeviceList); + } + + +#ifdef XFree86LOADER + /* ModulePath */ + + if (fileconf) { + if (xf86ModPathFrom != X_CMDLINE && fileconf->file_modulepath) { + xf86ModulePath = fileconf->file_modulepath; + xf86ModPathFrom = X_CONFIG; } + } + xf86Msg(xf86ModPathFrom, "ModulePath set to \"%s\"\n", xf86ModulePath); +#endif + +#if 0 + /* LogFile */ /* - * Now sort the drivers to match the order of the ScreenNumbers - * requested by the user. (sorry, slow bubble-sort here) - * Note, that after this sorting the first driver that is not configured - * can be used as last-mark for all configured ones. + * XXX The problem with this is that the log file is already open. + * One option might be to copy the exiting contents to the new location. + * and re-open it. The down side is that the default location would + * already have been overwritten. Another option would be to start with + * unique temporary location, then copy it once the correct name is known. + * A problem with this is what happens if the server exits before that + * happens. */ - for ( j = 0; j < xf86MaxScreens-1; j++) - for ( i=0; i < xf86MaxScreens-j-1; i++ ) - if (!xf86Screens[i] || !xf86Screens[i]->configured || - (xf86Screens[i+1] && xf86Screens[i+1]->configured && - (xf86Screens[i+1]->tmpIndex < xf86Screens[i]->tmpIndex))) - { - ScrnInfoPtr temp = xf86Screens[i+1]; - xf86Screens[i+1] = xf86Screens[i]; - xf86Screens[i] = temp; - } + if (xf86LogFileFrom == X_DEFAULT && fileconf->file_logfile) { + xf86LogFile = fileconf->file_logfile; + xf86LogFileFrom = X_CONFIG; + } +#endif + + return TRUE; +} - } -#endif /* XF86SETUP */ +typedef enum { + FLAG_NOTRAPSIGNALS, + FLAG_DONTVTSWITCH, + FLAG_DONTZAP, + FLAG_DONTZOOM, + FLAG_DISABLEVIDMODE, + FLAG_ALLOWNONLOCAL, + FLAG_DISABLEMODINDEV, + FLAG_MODINDEVALLOWNONLOCAL, + FLAG_ALLOWMOUSEOPENFAIL, + FLAG_VTINIT, + FLAG_VTSYSREQ, + FLAG_XKBDISABLE, + FLAG_PCIPROBE1, + FLAG_PCIPROBE2, + FLAG_PCIFORCECONFIG1, + FLAG_PCIFORCECONFIG2, + FLAG_PCIFORCENONE, + FLAG_PCIOSCONFIG, + FLAG_SAVER_BLANKTIME, + FLAG_DPMS_STANDBYTIME, + FLAG_DPMS_SUSPENDTIME, + FLAG_DPMS_OFFTIME, + FLAG_PIXMAP, + FLAG_PC98, + FLAG_ESTIMATE_SIZES_AGGRESSIVELY, + FLAG_NOPM, + FLAG_XINERAMA, + FLAG_ALLOW_DEACTIVATE_GRABS, + FLAG_ALLOW_CLOSEDOWN_GRABS, + FLAG_LOG, + FLAG_RENDER_COLORMAP_MODE, + FLAG_HANDLE_SPECIAL_KEYS, + FLAG_RANDR +} FlagValues; + +static OptionInfoRec FlagOptions[] = { + { FLAG_NOTRAPSIGNALS, "NoTrapSignals", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_DONTVTSWITCH, "DontVTSwitch", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_DONTZAP, "DontZap", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_DONTZOOM, "DontZoom", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_DISABLEVIDMODE, "DisableVidModeExtension", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_ALLOWNONLOCAL, "AllowNonLocalXvidtune", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_DISABLEMODINDEV, "DisableModInDev", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_MODINDEVALLOWNONLOCAL, "AllowNonLocalModInDev", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_ALLOWMOUSEOPENFAIL, "AllowMouseOpenFail", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_VTINIT, "VTInit", OPTV_STRING, + {0}, FALSE }, + { FLAG_VTSYSREQ, "VTSysReq", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_XKBDISABLE, "XkbDisable", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_PCIPROBE1, "PciProbe1" , OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_PCIPROBE2, "PciProbe2", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_PCIFORCECONFIG1, "PciForceConfig1", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_PCIFORCECONFIG2, "PciForceConfig2", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_PCIFORCENONE, "PciForceNone", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_PCIOSCONFIG, "PciOsConfig", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_SAVER_BLANKTIME, "BlankTime" , OPTV_INTEGER, + {0}, FALSE }, + { FLAG_DPMS_STANDBYTIME, "StandbyTime", OPTV_INTEGER, + {0}, FALSE }, + { FLAG_DPMS_SUSPENDTIME, "SuspendTime", OPTV_INTEGER, + {0}, FALSE }, + { FLAG_DPMS_OFFTIME, "OffTime", OPTV_INTEGER, + {0}, FALSE }, + { FLAG_PIXMAP, "Pixmap", OPTV_INTEGER, + {0}, FALSE }, + { FLAG_PC98, "PC98", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_ESTIMATE_SIZES_AGGRESSIVELY,"EstimateSizesAggressively",OPTV_INTEGER, + {0}, FALSE }, + { FLAG_NOPM, "NoPM", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_XINERAMA, "Xinerama", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_ALLOW_DEACTIVATE_GRABS,"AllowDeactivateGrabs", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_ALLOW_CLOSEDOWN_GRABS, "AllowClosedownGrabs", OPTV_BOOLEAN, + {0}, FALSE }, + { FLAG_LOG, "Log", OPTV_STRING, + {0}, FALSE }, + { FLAG_RENDER_COLORMAP_MODE, "RenderColormapMode", OPTV_STRING, + {0}, FALSE }, + { FLAG_HANDLE_SPECIAL_KEYS, "HandleSpecialKeys", OPTV_STRING, + {0}, FALSE }, + { FLAG_RANDR, "RandR", OPTV_BOOLEAN, + {0}, FALSE }, + { -1, NULL, OPTV_NONE, + {0}, FALSE }, +}; -#ifdef NEED_RETURN_VALUE - return RET_OKAY; +#if defined(i386) || defined(__i386__) +static Bool +detectPC98(void) +{ +#ifdef SUPPORT_PC98 + unsigned char buf[2]; + + if (xf86ReadBIOS(0xf8000, 0xe80, buf, 2) != 2) + return FALSE; + if ((buf[0] == 0x98) && (buf[1] == 0x21)) + return TRUE; + else + return FALSE; +#else + return FALSE; #endif } +#endif /* __i386__ */ -static char* prependRoot(char *pathname) +static Bool +configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) { -#ifndef __EMX__ - return pathname; + XF86OptionPtr optp, tmp; + int i; + Pix24Flags pix24 = Pix24DontCare; + Bool value; + MessageType from; + + /* + * Merge the ServerLayout and ServerFlags options. The former have + * precedence over the latter. + */ + optp = NULL; + if (flagsconf && flagsconf->flg_option_lst) + optp = xf86optionListDup(flagsconf->flg_option_lst); + if (layoutopts) { + tmp = xf86optionListDup(layoutopts); + if (optp) + optp = xf86optionListMerge(optp, tmp); + else + optp = tmp; + } + + xf86ProcessOptions(-1, optp, FlagOptions); + + xf86GetOptValBool(FlagOptions, FLAG_NOTRAPSIGNALS, &xf86Info.notrapSignals); + xf86GetOptValBool(FlagOptions, FLAG_DONTVTSWITCH, &xf86Info.dontVTSwitch); + xf86GetOptValBool(FlagOptions, FLAG_DONTZAP, &xf86Info.dontZap); + xf86GetOptValBool(FlagOptions, FLAG_DONTZOOM, &xf86Info.dontZoom); + + xf86GetOptValBool(FlagOptions, FLAG_ALLOW_DEACTIVATE_GRABS, + &(xf86Info.grabInfo.allowDeactivate)); + xf86GetOptValBool(FlagOptions, FLAG_ALLOW_CLOSEDOWN_GRABS, + &(xf86Info.grabInfo.allowClosedown)); + + /* + * Set things up based on the config file information. Some of these + * settings may be overridden later when the command line options are + * checked. + */ +#ifdef XF86VIDMODE + if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEVIDMODE, &value)) + xf86Info.vidModeEnabled = !value; + if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWNONLOCAL, &value)) + xf86Info.vidModeAllowNonLocal = value; +#endif + +#ifdef XF86MISC + if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEMODINDEV, &value)) + xf86Info.miscModInDevEnabled = !value; + if (xf86GetOptValBool(FlagOptions, FLAG_MODINDEVALLOWNONLOCAL, &value)) + xf86Info.miscModInDevAllowNonLocal = value; +#endif + + if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWMOUSEOPENFAIL, &value)) + xf86Info.allowMouseOpenFail = value; + + if (xf86GetOptValBool(FlagOptions, FLAG_VTSYSREQ, &value)) { +#ifdef USE_VT_SYSREQ + xf86Info.vtSysreq = value; + xf86Msg(X_CONFIG, "VTSysReq %s\n", value ? "enabled" : "disabled"); #else - /* XXXX caveat: multiple path components in line */ - return (char*)__XOS2RedirRoot(pathname); + if (value) + xf86Msg(X_WARNING, "VTSysReq is not supported on this OS\n"); #endif -} + } + + if (xf86GetOptValBool(FlagOptions, FLAG_XKBDISABLE, &value)) { +#ifdef XKB + noXkbExtension = value; + xf86Msg(X_CONFIG, "Xkb %s\n", value ? "disabled" : "enabled"); +#else + if (!value) + xf86Msg(X_WARNING, "Xserver doesn't support XKB\n"); +#endif + } + + xf86Info.vtinit = xf86GetOptValString(FlagOptions, FLAG_VTINIT); + + if (xf86IsOptionSet(FlagOptions, FLAG_PCIPROBE1)) + xf86Info.pciFlags = PCIProbe1; + if (xf86IsOptionSet(FlagOptions, FLAG_PCIPROBE2)) + xf86Info.pciFlags = PCIProbe2; + if (xf86IsOptionSet(FlagOptions, FLAG_PCIFORCECONFIG1)) + xf86Info.pciFlags = PCIForceConfig1; + if (xf86IsOptionSet(FlagOptions, FLAG_PCIFORCECONFIG2)) + xf86Info.pciFlags = PCIForceConfig2; + if (xf86IsOptionSet(FlagOptions, FLAG_PCIOSCONFIG)) + xf86Info.pciFlags = PCIOsConfig; + if (xf86IsOptionSet(FlagOptions, FLAG_PCIFORCENONE)) + xf86Info.pciFlags = PCIForceNone; + + xf86Info.pmFlag = TRUE; + if (xf86GetOptValBool(FlagOptions, FLAG_NOPM, &value)) + xf86Info.pmFlag = !value; + { + const char *s; + if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) { + if (!xf86NameCmp(s,"flush")) { + xf86Msg(X_CONFIG, "Flushing logfile enabled\n"); + xf86Info.log = LogFlush; + } else if (!xf86NameCmp(s,"sync")) { + xf86Msg(X_CONFIG, "Syncing logfile enabled\n"); + xf86Info.log = LogSync; + } else { + xf86Msg(X_WARNING,"Unknown Log option\n"); + } + } + } -static CONFIG_RETURN_TYPE -configFilesSection() -{ - int token; - int i, j; - int k, l; - char *str; - - while ((token = xf86GetToken(FilesTab)) != ENDSECTION) { - switch (token) { - case FONTPATH: - OFLG_SET(XCONFIG_FONTPATH,&GenericXF86ConfigFlag); - if (xf86GetToken(NULL) != STRING) - xf86ConfigError("Font path component expected"); - j = FALSE; - str = prependRoot(val.str); - if (fontPath == NULL) - { - fontPath = (char *)xalloc(1); - fontPath[0] = '\0'; - i = strlen(str) + 1; - } - else - { - i = strlen(fontPath) + strlen(str) + 1; - if (fontPath[strlen(fontPath)-1] != ',') +#ifdef RENDER + { + const char *s; + + if ((s = xf86GetOptValString(FlagOptions, FLAG_RENDER_COLORMAP_MODE))){ + int policy = PictureParseCmapPolicy (s); + if (policy == PictureCmapPolicyInvalid) + xf86Msg(X_WARNING, "Unknown colormap policy \"%s\"\n", s); + else { - i++; - j = TRUE; + xf86Msg(X_CONFIG, "Render colormap policy set to %s\n", s); + PictureCmapPolicy = policy; } } - fontPath = (char *)xrealloc(fontPath, i); - if (j) - strcat(fontPath, ","); - - strcat(fontPath, str); - xfree(val.str); - break; - - case RGBPATH: - OFLG_SET(XCONFIG_RGBPATH, &GenericXF86ConfigFlag); - if (xf86GetToken(NULL) != STRING) xf86ConfigError("RGB path expected"); - if (!xf86coFlag) - rgbPath = val.str; - break; - - case MODULEPATH: - OFLG_SET(XCONFIG_MODULEPATH, &GenericXF86ConfigFlag); - if (xf86GetToken(NULL) != STRING) - xf86ConfigError("Module path expected"); - l = FALSE; - str = prependRoot(val.str); - if (modulePath == NULL) { - modulePath = (char *)xalloc(1); - modulePath[0] = '\0'; - k = strlen(str) + 1; - } - else - { - k = strlen(modulePath) + strlen(str) + 1; - if (modulePath[strlen(modulePath)-1] != ',') - { - k++; - l = TRUE; + } +#endif + { + const char *s; + if ((s = xf86GetOptValString(FlagOptions, FLAG_HANDLE_SPECIAL_KEYS))) { + if (!xf86NameCmp(s,"always")) { + xf86Msg(X_CONFIG, "Always handling special keys in DDX\n"); + xf86Info.ddxSpecialKeys = SKAlways; + } else if (!xf86NameCmp(s,"whenneeded")) { + xf86Msg(X_CONFIG, "Special keys handled in DDX only if needed\n"); + xf86Info.ddxSpecialKeys = SKWhenNeeded; + } else if (!xf86NameCmp(s,"never")) { + xf86Msg(X_CONFIG, "Never handling special keys in DDX\n"); + xf86Info.ddxSpecialKeys = SKNever; + } else { + xf86Msg(X_WARNING,"Unknown HandleSpecialKeys option\n"); } - } - modulePath = (char *)xrealloc(modulePath, k); - if (l) - strcat(modulePath, ","); - - strcat(modulePath, str); - xfree(val.str); - break; + } + } +#ifdef RANDR + xf86Info.disableRandR = FALSE; + xf86Info.randRFrom = X_DEFAULT; + if (xf86GetOptValBool(FlagOptions, FLAG_RANDR, &value)) { + xf86Info.disableRandR = !value; + xf86Info.randRFrom = X_CONFIG; + } +#endif + i = -1; + xf86GetOptValInteger(FlagOptions, FLAG_ESTIMATE_SIZES_AGGRESSIVELY, &i); + if (i >= 0) + xf86Info.estimateSizesAggressively = i; + else + xf86Info.estimateSizesAggressively = 0; + + i = -1; + xf86GetOptValInteger(FlagOptions, FLAG_SAVER_BLANKTIME, &i); + if (i >= 0) + ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN; - case EOF: - FatalError("Unexpected EOF (missing EndSection?)"); - break; /* :-) */ +#ifdef DPMSExtension + i = -1; + xf86GetOptValInteger(FlagOptions, FLAG_DPMS_STANDBYTIME, &i); + if (i >= 0) + DPMSStandbyTime = defaultDPMSStandbyTime = i * MILLI_PER_MIN; + i = -1; + xf86GetOptValInteger(FlagOptions, FLAG_DPMS_SUSPENDTIME, &i); + if (i >= 0) + DPMSSuspendTime = defaultDPMSSuspendTime = i * MILLI_PER_MIN; + i = -1; + xf86GetOptValInteger(FlagOptions, FLAG_DPMS_OFFTIME, &i); + if (i >= 0) + DPMSOffTime = defaultDPMSOffTime = i * MILLI_PER_MIN; +#endif + + i = -1; + xf86GetOptValInteger(FlagOptions, FLAG_PIXMAP, &i); + switch (i) { + case 24: + pix24 = Pix24Use24; + break; + case 32: + pix24 = Pix24Use32; + break; + case -1: + break; default: - xf86ConfigError("File section keyword expected"); - break; + xf86ConfigError("Pixmap option's value (%d) must be 24 or 32\n", i); + return FALSE; } - } -#ifdef NEED_RETURN_VALUE - return RET_OKAY; + if (xf86Pix24 != Pix24DontCare) { + xf86Info.pixmap24 = xf86Pix24; + xf86Info.pix24From = X_CMDLINE; + } else if (pix24 != Pix24DontCare) { + xf86Info.pixmap24 = pix24; + xf86Info.pix24From = X_CONFIG; + } else { + xf86Info.pixmap24 = Pix24DontCare; + xf86Info.pix24From = X_DEFAULT; + } +#if defined(i386) || defined(__i386__) + if (xf86GetOptValBool(FlagOptions, FLAG_PC98, &value)) { + xf86Info.pc98 = value; + if (value) { + xf86Msg(X_CONFIG, "Japanese PC98 architecture\n"); + } + } else + if (detectPC98()) { + xf86Info.pc98 = TRUE; + xf86Msg(X_PROBED, "Japanese PC98 architecture\n"); + } #endif -} -static CONFIG_RETURN_TYPE -configServerFlagsSection() -{ - int token; - - xf86Info.dontZap = FALSE; - xf86Info.dontZoom = FALSE; - - while ((token = xf86GetToken(ServerFlagsTab)) != ENDSECTION) { - switch (token) { - case NOTRAPSIGNALS: - xf86Info.notrapSignals=TRUE; - break; - case DONTZAP: - xf86Info.dontZap = TRUE; - break; - case DONTZOOM: - xf86Info.dontZoom = TRUE; - break; -#ifdef XF86VIDMODE - case DISABLEVIDMODE: - xf86VidModeEnabled = FALSE; - break; - case ALLOWNONLOCAL: - xf86VidModeAllowNonLocal = TRUE; - break; -#endif -#ifdef XF86MISC - case DISABLEMODINDEV: - xf86MiscModInDevEnabled = FALSE; - break; - case MODINDEVALLOWNONLOCAL: - xf86MiscModInDevAllowNonLocal = TRUE; - break; -#endif - case ALLOWMOUSEOPENFAIL: - xf86AllowMouseOpenFail = TRUE; - break; - case PCIPROBE1: - xf86PCIFlags = PCIProbe1; - break; - case PCIPROBE2: - xf86PCIFlags = PCIProbe2; - break; - case PCIFORCECONFIG1: - xf86PCIFlags = PCIForceConfig1; - break; - case PCIFORCECONFIG2: - xf86PCIFlags = PCIForceConfig2; - break; - case EOF: - FatalError("Unexpected EOF (missing EndSection?)"); - break; /* :-) */ - default: - xf86ConfigError("Server flags section keyword expected"); - break; +#ifdef PANORAMIX + from = X_DEFAULT; + if (!noPanoramiXExtension) + from = X_CMDLINE; + else if (xf86GetOptValBool(FlagOptions, FLAG_XINERAMA, &value)) { + noPanoramiXExtension = !value; + from = X_CONFIG; } - } -#ifdef NEED_RETURN_VALUE - return RET_OKAY; + if (!noPanoramiXExtension) + xf86Msg(from, "Xinerama: enabled\n"); #endif + + return TRUE; } -static CONFIG_RETURN_TYPE -configKeyboardSection() +/* + * XXX This function is temporary, and will be removed when the keyboard + * driver is converted into a regular input driver. + */ +static Bool +configInputKbd(IDevPtr inputp) { - int token, ntoken; - + char *s; + MessageType from = X_DEFAULT; + Bool customKeycodesDefault = FALSE; + int verb = 0; + /* Initialize defaults */ - xf86Info.serverNumLock = FALSE; xf86Info.xleds = 0L; xf86Info.kbdDelay = 500; xf86Info.kbdRate = 30; - xf86Info.kbdProc = (DeviceProc)0; + + xf86Info.kbdProc = NULL; xf86Info.vtinit = NULL; xf86Info.vtSysreq = VT_SYSREQ_DEFAULT; - xf86Info.specialKeyMap = (int *)xalloc((RIGHTCTL - LEFTALT + 1) * - sizeof(int)); - xf86Info.specialKeyMap[LEFTALT - LEFTALT] = KM_META; - xf86Info.specialKeyMap[RIGHTALT - LEFTALT] = KM_META; - xf86Info.specialKeyMap[SCROLLLOCK - LEFTALT] = KM_COMPOSE; - xf86Info.specialKeyMap[RIGHTCTL - LEFTALT] = KM_CONTROL; -#if defined(SVR4) && defined(i386) && !defined(PC98) +#if defined(SVR4) && defined(i386) xf86Info.panix106 = FALSE; #endif -#ifdef XKB - xf86Info.xkbkeymap = NULL; - xf86Info.xkbtypes = "default"; -#ifndef PC98 - xf86Info.xkbcompat = "default"; - xf86Info.xkbkeycodes = "xfree86"; - xf86Info.xkbsymbols = "us(pc101)"; - xf86Info.xkbgeometry = "pc"; -#else - xf86Info.xkbcompat = "pc98"; - xf86Info.xkbkeycodes = "xfree98"; - xf86Info.xkbsymbols = "nec/jp(pc98)"; - xf86Info.xkbgeometry = "nec(pc98)"; -#endif - xf86Info.xkbcomponents_specified = False; - xf86Info.xkbrules = "xfree86"; - xf86Info.xkbmodel = NULL; - xf86Info.xkblayout = NULL; - xf86Info.xkbvariant = NULL; - xf86Info.xkboptions = NULL; -#endif - - while ((token = xf86GetToken(KeyboardTab)) != ENDSECTION) { - switch (token) { - case KPROTOCOL: - if (xf86GetToken(NULL) != STRING) - xf86ConfigError("Keyboard protocol name expected"); - if ( StrCaseCmp(val.str,"standard") == 0 ) { - xf86Info.kbdProc = xf86KbdProc; -#ifdef AMOEBA - xf86Info.kbdEvents = NULL; -#else - xf86Info.kbdEvents = xf86KbdEvents; + xf86Info.kbdCustomKeycodes = FALSE; +#ifdef WSCONS_SUPPORT + xf86Info.kbdFd = -1; #endif - } else if ( StrCaseCmp(val.str,"xqueue") == 0 ) { +#ifdef XKB + if (!xf86IsPc98()) { + xf86Info.xkbrules = "xfree86"; + xf86Info.xkbmodel = "pc105"; + xf86Info.xkblayout = "us"; + xf86Info.xkbvariant = NULL; + xf86Info.xkboptions = NULL; + } else { + xf86Info.xkbrules = "xfree98"; + xf86Info.xkbmodel = "pc98"; + xf86Info.xkblayout = "nec/jp"; + xf86Info.xkbvariant = NULL; + xf86Info.xkboptions = NULL; + } + xf86Info.xkbcomponents_specified = FALSE; + /* Should discourage the use of these. */ + xf86Info.xkbkeymap = NULL; + xf86Info.xkbtypes = NULL; + xf86Info.xkbcompat = NULL; + xf86Info.xkbkeycodes = NULL; + xf86Info.xkbsymbols = NULL; + xf86Info.xkbgeometry = NULL; +#endif + + s = xf86SetStrOption(inputp->commonOptions, "Protocol", "standard"); + if (xf86NameCmp(s, "standard") == 0) { + xf86Info.kbdProc = xf86KbdProc; + xf86Info.kbdEvents = xf86KbdEvents; + xfree(s); + } else if (xf86NameCmp(s, "xqueue") == 0) { #ifdef XQUEUE - xf86Info.kbdProc = xf86XqueKbdProc; - xf86Info.kbdEvents = xf86XqueEvents; - xf86Info.mouseDev->xqueSema = 0; - if (xf86Verbose) - ErrorF("%s Xqueue selected for keyboard input\n", - XCONFIG_GIVEN); -#endif - } else { - xf86ConfigError("Not a valid keyboard protocol name"); - } - break; - case AUTOREPEAT: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Autorepeat delay expected"); - xf86Info.kbdDelay = val.num; - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Autorepeat rate expected"); - xf86Info.kbdRate = val.num; - break; - case SERVERNUM: - xf86Info.serverNumLock = TRUE; - break; - - case XLEDS: - while ((token= xf86GetToken(NULL)) == NUMBER) - xf86Info.xleds |= 1L << (val.num-1); - pushToken = token; - break; - case LEFTALT: - case RIGHTALT: - case SCROLLLOCK: - case RIGHTCTL: - ntoken = xf86GetToken(KeyMapTab); - if ((ntoken == EOF) || (ntoken == STRING) || (ntoken == NUMBER)) - xf86ConfigError("KeyMap type token expected"); - else { - switch(ntoken) { - case KM_META: - case KM_COMPOSE: - case KM_MODESHIFT: - case KM_MODELOCK: - case KM_SCROLLLOCK: - case KM_CONTROL: - xf86Info.specialKeyMap[token - LEFTALT] = ntoken; - break; - default: - xf86ConfigError("Illegal KeyMap type"); - break; - } - } - break; - case VTINIT: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("VTInit string expected"); - xf86Info.vtinit = val.str; - if (xf86Verbose) - ErrorF("%s VTInit: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case VTSYSREQ: -#ifdef USE_VT_SYSREQ - xf86Info.vtSysreq = TRUE; - if (xf86Verbose && !VT_SYSREQ_DEFAULT) - ErrorF("%s VTSysReq enabled\n", XCONFIG_GIVEN); -#else - xf86ConfigError("VTSysReq not supported on this OS"); + xf86Info.kbdProc = xf86XqueKbdProc; + xf86Info.kbdEvents = xf86XqueEvents; + xf86Msg(X_CONFIG, "Xqueue selected for keyboard input\n"); +#endif + xfree(s); +#ifdef WSCONS_SUPPORT + } else if (xf86NameCmp(s, "wskbd") == 0) { + xf86Info.kbdProc = xf86KbdProc; + xf86Info.kbdEvents = xf86WSKbdEvents; + xfree(s); + s = xf86SetStrOption(inputp->commonOptions, "Device", NULL); + xf86Msg(X_CONFIG, "Keyboard: Protocol: wskbd\n"); + if (s == NULL) { + xf86ConfigError("A \"device\" option is required with" + " the \"wskbd\" keyboard protocol"); + return FALSE; + } + xf86Info.kbdFd = open(s, O_RDWR | O_NONBLOCK | O_EXCL); + if (xf86Info.kbdFd == -1) { + xf86ConfigError("cannot open \"%s\"", s); + xfree(s); + return FALSE; + } + xfree(s); + /* Find out keyboard type */ + if (ioctl(xf86Info.kbdFd, WSKBDIO_GTYPE, &xf86Info.wsKbdType) == -1) { + xf86ConfigError("cannot get keyboard type"); + close(xf86Info.kbdFd); + return FALSE; + } + switch (xf86Info.wsKbdType) { + case WSKBD_TYPE_PC_XT: + xf86Msg(X_PROBED, "Keyboard type: XT\n"); + break; + case WSKBD_TYPE_PC_AT: + xf86Msg(X_PROBED, "Keyboard type: AT\n"); + break; + case WSKBD_TYPE_USB: + xf86Msg(X_PROBED, "Keyboard type: USB\n"); + break; +#ifdef WSKBD_TYPE_ADB + case WSKBD_TYPE_ADB: + xf86Msg(X_PROBED, "Keyboard type: ADB\n"); + break; #endif - break; - -#ifdef XKB - case XKBDISABLE: - noXkbExtension = TRUE; - if (xf86Verbose) - ErrorF("%s XKB: disabled\n", XCONFIG_GIVEN); - break; - - case XKBKEYMAP: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBKeymap string expected"); - xf86Info.xkbkeymap = val.str; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: keymap: \"%s\" (overrides other XKB settings)\n", - XCONFIG_GIVEN, val.str); - break; - - case XKBCOMPAT: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBCompat string expected"); - xf86Info.xkbcompat = val.str; - xf86Info.xkbcomponents_specified = True; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: compat: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case XKBTYPES: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBTypes string expected"); - xf86Info.xkbtypes = val.str; - xf86Info.xkbcomponents_specified = True; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: types: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case XKBKEYCODES: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBKeycodes string expected"); - xf86Info.xkbkeycodes = val.str; - xf86Info.xkbcomponents_specified = True; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: keycodes: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case XKBGEOMETRY: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBGeometry string expected"); - xf86Info.xkbgeometry = val.str; - xf86Info.xkbcomponents_specified = True; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: geometry: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case XKBSYMBOLS: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBSymbols string expected"); - xf86Info.xkbsymbols = val.str; - xf86Info.xkbcomponents_specified = True; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: symbols: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case XKBRULES: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBRules string expected"); - xf86Info.xkbrules = val.str; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: rules: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case XKBMODEL: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBModel string expected"); - xf86Info.xkbmodel = val.str; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: model: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case XKBLAYOUT: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBLayout string expected"); - xf86Info.xkblayout = val.str; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: layout: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case XKBVARIANT: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBVariant string expected"); - xf86Info.xkbvariant = val.str; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: variant: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; - - case XKBOPTIONS: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBOptions string expected"); - xf86Info.xkboptions = val.str; - if (xf86Verbose && !XkbInitialMap) - ErrorF("%s XKB: options: \"%s\"\n", XCONFIG_GIVEN, val.str); - break; +#ifdef WSKBD_TYPE_SUN + case WSKBD_TYPE_SUN: + xf86Msg(X_PROBED, "Keyboard type: Sun\n"); + break; #endif -#if defined(SVR4) && defined(i386) && !defined(PC98) - case PANIX106: - xf86Info.panix106 = TRUE; - if (xf86Verbose) - ErrorF("%s PANIX106: enabled\n", XCONFIG_GIVEN); - break; + default: + xf86ConfigError("Unsupported wskbd type \"%d\"", + xf86Info.wsKbdType); + close(xf86Info.kbdFd); + return FALSE; + } #endif + } else { + xf86ConfigError("\"%s\" is not a valid keyboard protocol name", s); + xfree(s); + return FALSE; + } - case EOF: - FatalError("Unexpected EOF (missing EndSection?)"); - break; /* :-) */ + s = xf86SetStrOption(inputp->commonOptions, "AutoRepeat", NULL); + if (s) { + if (sscanf(s, "%d %d", &xf86Info.kbdDelay, &xf86Info.kbdRate) != 2) { + xf86ConfigError("\"%s\" is not a valid AutoRepeat value", s); + xfree(s); + return FALSE; + } + xfree(s); + } - default: - xf86ConfigError("Keyboard section keyword expected"); - break; + s = xf86SetStrOption(inputp->commonOptions, "XLeds", NULL); + if (s) { + char *l, *end; + unsigned int i; + l = strtok(s, " \t\n"); + while (l) { + i = strtoul(l, &end, 0); + if (*end == '\0') + xf86Info.xleds |= 1L << (i - 1); + else { + xf86ConfigError("\"%s\" is not a valid XLeds value", l); + xfree(s); + return FALSE; + } + l = strtok(NULL, " \t\n"); } + xfree(s); } - if (xf86Info.kbdProc == (DeviceProc)0) - { - xf86ConfigError("No keyboard device given"); + +#ifdef XKB + from = X_DEFAULT; + if (noXkbExtension) + from = X_CMDLINE; + else if (xf86FindOption(inputp->commonOptions, "XkbDisable")) { + xf86Msg(X_WARNING, "KEYBOARD: XKB should be disabled in the " + "ServerFlags section instead\n" + "\tof in the \"keyboard\" InputDevice section.\n"); + noXkbExtension = + xf86SetBoolOption(inputp->commonOptions, "XkbDisable", FALSE); + from = X_CONFIG; } -#ifdef NEED_RETURN_VALUE - return RET_OKAY; -#endif -} - -CONFIG_RETURN_TYPE -configPointerSection(MouseDevPtr mouse_dev, - int end_tag, - char **devicename) /* used by extended device */ -{ - int token; - int mtoken; - int i; - char *mouseType = "unknown"; - - /* Set defaults */ - mouse_dev->baudRate = 1200; - mouse_dev->oldBaudRate = -1; - mouse_dev->sampleRate = 0; - mouse_dev->resolution = 0; - mouse_dev->buttons = MSE_DFLTBUTTONS; - mouse_dev->emulate3Buttons = FALSE; - mouse_dev->emulate3Timeout = 50; - mouse_dev->chordMiddle = FALSE; - mouse_dev->mouseFlags = 0; - mouse_dev->mseProc = (DeviceProc)0; - mouse_dev->mseDevice = NULL; - mouse_dev->mseType = -1; - mouse_dev->mseModel = 0; - mouse_dev->negativeZ = 0; - mouse_dev->positiveZ = 0; - - while ((token = xf86GetToken(PointerTab)) != end_tag) { - switch (token) { - - case PROTOCOL: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Mouse name expected"); -#if defined(USE_OSMOUSE) || defined(OSMOUSE_ONLY) - if ( StrCaseCmp(val.str,"osmouse") == 0 ) { - if (xf86Verbose) - ErrorF("%s OsMouse selected for mouse input\n", XCONFIG_GIVEN); - /* - * allow an option to be passed to the OsMouse routines - */ - if ((i = xf86GetToken(NULL)) != ERROR_TOKEN) - xf86OsMouseOption(i, (pointer) &val); - else - pushToken = i; - mouse_dev->mseProc = xf86OsMouseProc; - mouse_dev->mseEvents = (void(*)(MouseDevPtr))xf86OsMouseEvents; - break; + if (noXkbExtension) + xf86Msg(from, "XKB: disabled\n"); + +#define NULL_IF_EMPTY(s) (s[0] ? s : (xfree(s), (char *)NULL)) + + if (!noXkbExtension && !XkbInitialMap) { + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbKeymap", NULL))) { + xf86Info.xkbkeymap = NULL_IF_EMPTY(s); + xf86Msg(X_CONFIG, "XKB: keymap: \"%s\" " + "(overrides other XKB settings)\n", xf86Info.xkbkeymap); + } else { + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbCompat", NULL))) { + xf86Info.xkbcompat = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: compat: \"%s\"\n", s); } -#endif -#ifdef XQUEUE - if ( StrCaseCmp(val.str,"xqueue") == 0 ) { - mouse_dev->mseProc = xf86XqueMseProc; - mouse_dev->mseEvents = (void(*)(MouseDevPtr))xf86XqueEvents; - mouse_dev->xqueSema = 0; - if (xf86Verbose) - ErrorF("%s Xqueue selected for mouse input\n", - XCONFIG_GIVEN); - break; + + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbTypes", NULL))) { + xf86Info.xkbtypes = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: types: \"%s\"\n", s); } -#endif -#ifndef OSMOUSE_ONLY -#if defined(MACH) || defined(AMOEBA) - mouseType = (char *) xalloc (strlen (val.str) + 1); - strcpy (mouseType, val.str); -#else - mouseType = (char *)strdup(val.str); /* GJA -- should we free this? */ -#endif - mtoken = getStringToken(MouseTab); /* Which mouse? */ -#ifdef AMOEBA - mouse_dev->mseProc = xf86MseProc; - mouse_dev->mseEvents = NULL; -#else - mouse_dev->mseProc = xf86MseProc; - mouse_dev->mseEvents = xf86MseEvents; -#endif - mouse_dev->mseType = mtoken - MICROSOFT; - if (!xf86MouseSupported(mouse_dev->mseType)) - { - xf86ConfigError("Mouse type not supported by this OS"); + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbKeycodes", NULL))) { + xf86Info.xkbkeycodes = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: keycodes: \"%s\"\n", s); } -#else /* OSMOUSE_ONLY */ - xf86ConfigError("Mouse type not supported by this OS"); -#endif /* OSMOUSE_ONLY */ -#ifdef MACH386 - /* Don't need to specify the device for MACH -- should always be this */ - mouse_dev->mseDevice = "/dev/mouse"; -#endif - break; -#ifndef OSMOUSE_ONLY - case PDEVICE: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Mouse device expected"); - mouse_dev->mseDevice = val.str; - break; - case BAUDRATE: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Baudrate expected"); - if (mouse_dev->mseType + MICROSOFT == LOGIMAN) - { - /* - * XXXX This should be extended to other mouse types -- most - * support only 1200. Should also disallow baudrate for bus mice - */ - /* Moan if illegal baud rate! [CHRIS-211092] */ - if ((val.num != 1200) && (val.num != 9600)) - xf86ConfigError("Only 1200 or 9600 Baud are supported by MouseMan"); - } - else if (val.num%1200 != 0 || val.num < 1200 || val.num > 9600) - xf86ConfigError("Baud rate must be one of 1200, 2400, 4800, or 9600"); - mouse_dev->baudRate = val.num; - break; + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbGeometry", NULL))) { + xf86Info.xkbgeometry = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: geometry: \"%s\"\n", s); + } - case SAMPLERATE: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Sample rate expected"); -#if 0 - if (mouse_dev->mseType + MICROSOFT == LOGIMAN) - { - /* XXXX Most mice don't allow this */ - /* Moan about illegal sample rate! [CHRIS-211092] */ - xf86ConfigError("Selection of sample rate is not supported by MouseMan"); - } -#endif - mouse_dev->sampleRate = val.num; - break; - - case PRESOLUTION: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Resolution expected"); - if (val.num <= 0) - xf86ConfigError("Resolution must be a positive value"); - mouse_dev->resolution = val.num; - break; -#endif /* OSMOUSE_ONLY */ - case EMULATE3: - if (mouse_dev->chordMiddle) - xf86ConfigError("Can't use Emulate3Buttons with ChordMiddle"); - mouse_dev->emulate3Buttons = TRUE; - break; - - case EM3TIMEOUT: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("3 button emulation timeout expected"); - mouse_dev->emulate3Timeout = val.num; - break; - -#ifndef OSMOUSE_ONLY - case CHORDMIDDLE: - if (mouse_dev->mseType + MICROSOFT == MICROSOFT || - mouse_dev->mseType + MICROSOFT == LOGIMAN) - { - if (mouse_dev->emulate3Buttons) - xf86ConfigError("Can't use ChordMiddle with Emulate3Buttons"); - mouse_dev->chordMiddle = TRUE; + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbSymbols", NULL))) { + xf86Info.xkbsymbols = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: symbols: \"%s\"\n", s); } - else - xf86ConfigError("ChordMiddle is only supported for Microsoft and MouseMan"); - break; - case CLEARDTR: -#ifdef CLEARDTR_SUPPORT - if (mouse_dev->mseType + MICROSOFT == MOUSESYS) - mouse_dev->mouseFlags |= MF_CLEAR_DTR; - else - xf86ConfigError("ClearDTR only supported for MouseSystems mouse"); -#else - xf86ConfigError("ClearDTR not supported on this OS"); -#endif - break; - case CLEARRTS: -#ifdef CLEARDTR_SUPPORT - if (mouse_dev->mseType + MICROSOFT == MOUSESYS) - mouse_dev->mouseFlags |= MF_CLEAR_RTS; - else - xf86ConfigError("ClearRTS only supported for MouseSystems mouse"); -#else - xf86ConfigError("ClearRTS not supported on this OS"); -#endif - break; -#endif /* OSMOUSE_ONLY */ + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbRules", NULL))) { + xf86Info.xkbrules = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: rules: \"%s\"\n", s); + } - case DEVICE_NAME: - if (!devicename) /* not called for an extended device */ - xf86ConfigError("Pointer section keyword expected"); + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbModel", NULL))) { + xf86Info.xkbmodel = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: model: \"%s\"\n", s); + } - if (xf86GetToken(NULL) != STRING) - xf86ConfigError("Option string expected"); - *devicename = strdup(val.str); - break; + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbLayout", NULL))) { + xf86Info.xkblayout = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: layout: \"%s\"\n", s); + } -#ifndef XF86SETUP -#ifdef XINPUT - case ALWAYSCORE: - xf86AlwaysCore(mouse_dev->local, TRUE); - break; -#endif -#endif - - case ZAXISMAPPING: - switch (xf86GetToken(ZMapTab)) { - case NUMBER: - if (val.num <= 0 || val.num > MSE_MAXBUTTONS) - xf86ConfigError("Button number (1..12) expected"); - mouse_dev->negativeZ = 1 << (val.num - 1); - if (xf86GetToken(NULL) != NUMBER || - val.num <= 0 || val.num > MSE_MAXBUTTONS) - xf86ConfigError("Button number (1..12) expected"); - mouse_dev->positiveZ = 1 << (val.num - 1); - break; - case XAXIS: - mouse_dev->negativeZ = mouse_dev->positiveZ = MSE_MAPTOX; - break; - case YAXIS: - mouse_dev->negativeZ = mouse_dev->positiveZ = MSE_MAPTOY; - break; - default: - xf86ConfigError("Button number (1..12), X or Y expected"); + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbVariant", NULL))) { + xf86Info.xkbvariant = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: variant: \"%s\"\n", s); } - break; - - case PBUTTONS: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Number of buttons (1..12) expected"); - if (val.num <= 0 || val.num > MSE_MAXBUTTONS) - xf86ConfigError("Number of buttons must be a positive value (1..12)"); - mouse_dev->buttons = val.num; - break; - - case EOF: - FatalError("Unexpected EOF (missing EndSection?)"); - break; /* :-) */ - - default: - xf86ConfigError("Pointer section keyword expected"); - break; - } + if ((s = xf86SetStrOption(inputp->commonOptions, "XkbOptions", NULL))) { + xf86Info.xkboptions = NULL_IF_EMPTY(s); + xf86Info.xkbcomponents_specified = TRUE; + xf86Msg(X_CONFIG, "XKB: options: \"%s\"\n", s); + } + } } - /* Print log and make sanity checks */ - - if (mouse_dev->mseProc == (DeviceProc)0) - { - xf86ConfigError("No mouse protocol given"); +#undef NULL_IF_EMPTY +#endif +#if defined(SVR4) && defined(i386) + if ((xf86Info.panix106 = + xf86SetBoolOption(inputp->commonOptions, "Panix106", FALSE))) { + xf86Msg(X_CONFIG, "PANIX106: enabled\n"); } - +#endif + /* - * if mseProc is set and mseType isn't, then using Xqueue or OSmouse. - * Otherwise, a mouse device is required. + * This was once a compile time option (ASSUME_CUSTOM_KEYCODES) + * defaulting to 1 on Linux/PPC. It is no longer necessary, but for + * backwards compatibility we provide 'Option "CustomKeycodes"' + * and try to autoprobe on Linux/PPC. */ - if (mouse_dev->mseType >= 0 && !mouse_dev->mseDevice) + from = X_DEFAULT; + verb = 2; +#if defined(__linux__) && defined(__powerpc__) { - xf86ConfigError("No mouse device given"); - } - - switch (mouse_dev->negativeZ) { - case 0: /* none */ - case MSE_MAPTOX: - case MSE_MAPTOY: - break; - default: /* buttons */ - for (i = 0; mouse_dev->negativeZ != (1 << i); ++i) - ; - if (i + 1 > mouse_dev->buttons) - mouse_dev->buttons = i + 1; - for (i = 0; mouse_dev->positiveZ != (1 << i); ++i) - ; - if (i + 1 > mouse_dev->buttons) - mouse_dev->buttons = i + 1; - break; - } - - if (xf86Verbose && mouse_dev->mseType >= 0) - { - Bool formatFlag = FALSE; - ErrorF("%s Mouse: type: %s, device: %s", - XCONFIG_GIVEN, mouseType, mouse_dev->mseDevice); - if (mouse_dev->mseType != P_BM - && mouse_dev->mseType != P_PS2 - && mouse_dev->mseType != P_IMPS2 - && mouse_dev->mseType != P_THINKINGPS2 - && mouse_dev->mseType != P_MMANPLUSPS2 - && mouse_dev->mseType != P_GLIDEPOINTPS2 - && mouse_dev->mseType != P_NETPS2 - && mouse_dev->mseType != P_NETSCROLLPS2 - && mouse_dev->mseType != P_SYSMOUSE) - { - formatFlag = TRUE; - ErrorF(", baudrate: %d", mouse_dev->baudRate); - } - if (mouse_dev->sampleRate) - { - ErrorF(formatFlag ? "\n%s Mouse: samplerate: %d" : "%ssamplerate: %d", - formatFlag ? XCONFIG_GIVEN : ", ", mouse_dev->sampleRate); - formatFlag = !formatFlag; - } - if (mouse_dev->resolution) - { - ErrorF(formatFlag ? "\n%s Mouse: resolution: %d" : "%sresolution: %d", - formatFlag ? XCONFIG_GIVEN : ", ", mouse_dev->resolution); - formatFlag = !formatFlag; - } - ErrorF(formatFlag ? "\n%s Mouse: buttons: %d" : "%sbuttons: %d", - formatFlag ? XCONFIG_GIVEN : ", ", mouse_dev->buttons); - formatFlag = !formatFlag; - if (mouse_dev->emulate3Buttons) - { - ErrorF(formatFlag ? "\n%s Mouse: 3 button emulation (timeout: %dms)" : - "%s3 button emulation (timeout: %dms)", - formatFlag ? XCONFIG_GIVEN : ", ", mouse_dev->emulate3Timeout); - formatFlag = !formatFlag; - } - if (mouse_dev->chordMiddle) - ErrorF(formatFlag ? "\n%s Mouse: Chorded middle button" : - "%sChorded middle button", - formatFlag ? XCONFIG_GIVEN : ", "); - ErrorF("\n"); - - switch (mouse_dev->negativeZ) { - case 0: /* none */ - break; - case MSE_MAPTOX: - ErrorF("%s Mouse: zaxismapping: X\n", XCONFIG_GIVEN); - break; - case MSE_MAPTOY: - ErrorF("%s Mouse: zaxismapping: Y\n", XCONFIG_GIVEN); - break; - default: /* buttons */ - for (i = 0; mouse_dev->negativeZ != (1 << i); ++i) - ; - ErrorF("%s Mouse: zaxismapping: (-)%d", XCONFIG_GIVEN, i + 1); - for (i = 0; mouse_dev->positiveZ != (1 << i); ++i) - ; - ErrorF(" (+)%d\n", i + 1); - break; + FILE *f; + + f = fopen("/proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes","r"); + if (f) { + if (fgetc(f) == '0') { + customKeycodesDefault = TRUE; + from = X_PROBED; + verb = 1; + } + fclose(f); } } -#ifdef NEED_RETURN_VALUE - return RET_OKAY; #endif + if (xf86FindOption(inputp->commonOptions, "CustomKeycodes")) { + from = X_CONFIG; + verb = 1; + } + xf86Info.kbdCustomKeycodes = + xf86SetBoolOption(inputp->commonOptions, "CustomKeycodes", + customKeycodesDefault); + xf86MsgVerb(from, verb, "Keyboard: CustomKeycode %s\n", + xf86Info.kbdCustomKeycodes ? "enabled" : "disabled"); + + return TRUE; } - -static CONFIG_RETURN_TYPE -configDeviceSection() -{ - int token; - int i; - GDevPtr devp; - /* Allocate one more device */ - if ( device_list == NULL ) { - device_list = (GDevPtr) xalloc(sizeof(GDevRec)); - } else { - device_list = (GDevPtr) xrealloc(device_list, - (n_devices+1) * sizeof(GDevRec)); - } - devp = &(device_list[n_devices]); /* Point to the last device */ - n_devices++; - - /* Pre-init the newly created device */ - devp->identifier = NULL; - devp->board = NULL; - devp->vendor = NULL; - devp->chipset = NULL; - devp->ramdac = NULL; - for (i=0; i<MAXDACSPEEDS; i++) - devp->dacSpeeds[i] = 0; - OFLG_ZERO(&(devp->options)); - OFLG_ZERO(&(devp->xconfigFlag)); - devp->videoRam = 0; - devp->speedup = SPEEDUP_DEFAULT; - OFLG_ZERO(&(devp->clockOptions)); - devp->clocks = 0; - devp->clockprog = NULL; - devp->textClockValue = -1; - /* GJA -- We initialize the following fields to known values. - * If later on we find they contain different values, - * they might be interesting to print. - */ - devp->IObase = 0; - devp->DACbase = 0; - devp->COPbase = 0; - devp->POSbase = 0; - devp->instance = 0; - devp->BIOSbase = 0; - devp->VGAbase = 0; - devp->MemBase = 0; - devp->s3Madjust = 0; - devp->s3Nadjust = 0; - devp->s3MClk = 0; - devp->chipID = 0; - devp->chipRev = 0; - devp->s3RefClk = 0; - devp->s3BlankDelay = -1; - devp->DCConfig = NULL; - devp->DCOptions = NULL; - devp->MemClk = 0; - devp->LCDClk = 0; - - while ((token = xf86GetToken(DeviceTab)) != ENDSECTION) { - devp->DCConfig = xf86DCSaveLine(devp->DCConfig, token); - switch (token) { - - case IDENTIFIER: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("identifier name expected"); - devp->identifier = val.str; - break; - - case VENDOR: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("vendor name expected"); - devp->vendor = val.str; - break; - - case BOARD: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("board name expected"); - devp->board = val.str; - break; - - case CHIPSET: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Chipset string expected"); - devp->chipset = val.str; - OFLG_SET(XCONFIG_CHIPSET,&(devp->xconfigFlag)); - break; - - case RAMDAC: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("RAMDAC string expected"); - devp->ramdac = val.str; - OFLG_SET(XCONFIG_RAMDAC,&(devp->xconfigFlag)); - break; - - case DACSPEED: - for (i=0; i<MAXDACSPEEDS; i++) - devp->dacSpeeds[i] = 0; - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("DAC speed(s) expected"); - else { - devp->dacSpeeds[0] = (int)(val.realnum * 1000.0 + 0.5); - for(i=1; i<MAXDACSPEEDS; i++) { - if (xf86GetToken(NULL) == NUMBER) - devp->dacSpeeds[i] = (int)(val.realnum * 1000.0 + 0.5); - else { - pushToken = token; - break; +static Bool +checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout) +{ + Bool havePointer = FALSE, haveKeyboard = FALSE; + Bool foundPointer = FALSE, foundKeyboard = FALSE; + IDevPtr indp; + IDevRec Pointer, Keyboard; + XF86ConfInputPtr confInput; + int count = 0; + MessageType from = X_DEFAULT; + + /* Check if a core pointer or core keyboard is needed. */ + for (indp = servlayoutp->inputs; indp->identifier; indp++) { + if ((indp->commonOptions && + xf86FindOption(indp->commonOptions, "CorePointer")) || + (indp->extraOptions && + xf86FindOption(indp->extraOptions, "CorePointer"))) { + havePointer = TRUE; + } + if ((indp->commonOptions && + xf86FindOption(indp->commonOptions, "CoreKeyboard")) || + (indp->extraOptions && + xf86FindOption(indp->extraOptions, "CoreKeyboard"))) { + haveKeyboard = TRUE; + } + count++; + } + if (!havePointer) { + if (xf86PointerName) { + confInput = xf86findInput(xf86PointerName, + xf86configptr->conf_input_lst); + if (!confInput) { + xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n", + xf86PointerName); + return FALSE; + } + from = X_CMDLINE; + } else { + from = X_DEFAULT; + confInput = xf86findInput(CONF_IMPLICIT_POINTER, + xf86configptr->conf_input_lst); + if (!confInput && implicitLayout) { + confInput = xf86findInputByDriver("mouse", + xf86configptr->conf_input_lst); } - } - } - OFLG_SET(XCONFIG_DACSPEED,&(devp->xconfigFlag)); - break; - - case CLOCKCHIP: - /* Only allow one Clock string */ - if (OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(devp->clockOptions))) - { - xf86ConfigError("Only one Clock chip may be specified."); - break; - } - if (devp->clocks == 0) - { - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Option string expected"); - i = 0; - while (xf86_ClockOptionTab[i].token != -1) - { - if (StrCaseCmp(val.str, xf86_ClockOptionTab[i].name) == 0) - { - OFLG_SET(CLOCK_OPTION_PROGRAMABLE, &(devp->clockOptions)); - OFLG_SET(xf86_ClockOptionTab[i].token, - &(devp->clockOptions)); - break; - } - i++; - } - if (xf86_ClockOptionTab[i].token == -1) { - xf86ConfigError("Unknown clock chip"); - break; - } - } - else - { - xf86ConfigError("Clocks previously specified by value"); - } - break; - - case CLOCKS: - OFLG_SET(XCONFIG_CLOCKS,&(devp->xconfigFlag)); - if ((token = xf86GetToken(NULL)) == STRING) - { - xf86ConfigError("Use ClockChip to specify a programmable clock"); - break; - } - if (OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(devp->clockOptions))) - { - xf86ConfigError("Clock previously specified as programmable"); - break; - } - for (i = devp->clocks; token == NUMBER && i < MAXCLOCKS; i++) { - devp->clock[i] = (int)(val.realnum * 1000.0 + 0.5); - token = xf86GetToken(NULL); - } - - devp->clocks = i; - pushToken = token; - break; - - case OPTION: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Option string expected"); - i = 0; - while (xf86_OptionTab[i].token != -1) - { - if (StrCaseCmp(val.str, xf86_OptionTab[i].name) == 0) - { - OFLG_SET(xf86_OptionTab[i].token, &(devp->options)); - break; } - i++; - } - if (xf86_OptionTab[i].token == -1) - /*xf86ConfigError("Unknown option string");*/ - devp->DCOptions = xf86DCOption(devp->DCOptions,val); - break; - - case VIDEORAM: - OFLG_SET(XCONFIG_VIDEORAM,&(devp->xconfigFlag)); - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Video RAM size expected"); - devp->videoRam = val.num; - break; - - case SPEEDUP: - OFLG_SET(XCONFIG_SPEEDUP,&(devp->xconfigFlag)); - if ((token = xf86GetToken(NULL)) == STRING) - if (!strcmp(val.str,"all")) - devp->speedup = SPEEDUP_ALL; + if (confInput) + foundPointer = configInput(&Pointer, confInput, from); + } + if (!haveKeyboard) { + if (xf86KeyboardName) { + confInput = xf86findInput(xf86KeyboardName, + xf86configptr->conf_input_lst); + if (!confInput) { + xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n", + xf86KeyboardName); + return FALSE; + } + from = X_CMDLINE; + } else { + from = X_DEFAULT; + confInput = xf86findInput(CONF_IMPLICIT_KEYBOARD, + xf86configptr->conf_input_lst); + if (!confInput && implicitLayout) { + confInput = xf86findInputByDriver("keyboard", + xf86configptr->conf_input_lst); + } + } + if (confInput) + foundKeyboard = configInput(&Keyboard, confInput, from); + } + if (foundPointer) { + count++; + indp = xnfrealloc(servlayoutp->inputs, (count + 1) * sizeof(IDevRec)); + indp[count - 1] = Pointer; + indp[count - 1].extraOptions = xf86addNewOption(NULL, "CorePointer", NULL); + indp[count].identifier = NULL; + servlayoutp->inputs = indp; + } else if (!havePointer) { + if (implicitLayout) + xf86Msg(X_ERROR, "Unable to find a core pointer device\n"); else - if (!strcmp(val.str,"best")) - devp->speedup = SPEEDUP_BEST; - else - if (!strcmp(val.str,"none")) - devp->speedup = 0; - else - xf86ConfigError("Unrecognised SpeedUp option"); - else - { - pushToken = token; - if ((token = xf86GetToken(NULL)) == NUMBER) - devp->speedup = val.num; + xf86Msg(X_ERROR, "No core pointer device specified\n"); + return FALSE; + } + if (foundKeyboard) { + count++; + indp = xnfrealloc(servlayoutp->inputs, (count + 1) * sizeof(IDevRec)); + indp[count - 1] = Keyboard; + indp[count - 1].extraOptions = xf86addNewOption(NULL, "CoreKeyboard", NULL); + indp[count].identifier = NULL; + servlayoutp->inputs = indp; + } else if (!haveKeyboard) { + if (implicitLayout) + xf86Msg(X_ERROR, "Unable to find a core keyboard device\n"); else - { - pushToken = token; - devp->speedup = SPEEDUP_ALL; - } - } - break; - - case NOSPEEDUP: - OFLG_SET(XCONFIG_SPEEDUP,&(devp->xconfigFlag)); - devp->speedup = 0; - break; - - case CLOCKPROG: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("ClockProg string expected"); - if (val.str[0] != '/') - FatalError("Full pathname must be given for ClockProg \"%s\"\n", - val.str); - if (access(val.str, X_OK) < 0) - { - if (access(val.str, F_OK) < 0) - FatalError("ClockProg \"%s\" does not exist\n", val.str); - else - FatalError("ClockProg \"%s\" is not executable\n", val.str); - } - { - struct stat stat_buf; - stat(val.str, &stat_buf); - if (!CHECK_TYPE(stat_buf.st_mode, S_IFREG)) - FatalError("ClockProg \"%s\" is not a regular file\n", val.str); - } - devp->clockprog = val.str; - if (xf86GetToken(NULL) == NUMBER) - { - devp->textClockValue = (int)(val.realnum * 1000.0 + 0.5); - } - else - { - pushToken = token; - } - break; - - case BIOSBASE: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("BIOS base address expected"); - devp->BIOSbase = val.num; - OFLG_SET(XCONFIG_BIOSBASE, &(devp->xconfigFlag)); - break; - - case MEMBASE: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Memory base address expected"); - devp->MemBase = val.num; - OFLG_SET(XCONFIG_MEMBASE, &(devp->xconfigFlag)); - break; - - case IOBASE: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Direct access register I/O base address expected"); - devp->IObase = val.num; - OFLG_SET(XCONFIG_IOBASE, &(devp->xconfigFlag)); - break; - - case DACBASE: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("DAC base I/O address expected"); - devp->DACbase = val.num; - OFLG_SET(XCONFIG_DACBASE, &(devp->xconfigFlag)); - break; - - case COPBASE: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Coprocessor base memory address expected"); - devp->COPbase = val.num; - OFLG_SET(XCONFIG_COPBASE, &(devp->xconfigFlag)); - break; - - case POSBASE: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("POS base address expected"); - devp->POSbase = val.num; - OFLG_SET(XCONFIG_POSBASE, &(devp->xconfigFlag)); - break; - - case INSTANCE: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Video adapter instance number expected"); - devp->instance = val.num; - OFLG_SET(XCONFIG_INSTANCE, &(devp->xconfigFlag)); - break; - - case S3MNADJUST: - if ((token = xf86GetToken(NULL)) == DASH) { /* negative number */ - token = xf86GetToken(NULL); - val.num = -val.num; - } - if (token != NUMBER || val.num<-31 || val.num>31) - xf86ConfigError("M adjust (max. 31) expected"); - devp->s3Madjust = val.num; - - if ((token = xf86GetToken(NULL)) == DASH) { /* negative number */ - token = xf86GetToken(NULL); - val.num = -val.num; - } - if (token == NUMBER) { - if (val.num<-255 || val.num>255) - xf86ConfigError("N adjust (max. 255) expected"); - else - devp->s3Nadjust = val.num; - } - else pushToken = token; - break; - - case S3MCLK: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("MCLK value in MHz expected"); - devp->s3MClk = (int)(val.realnum * 1000.0 + 0.5); - break; - - case MEMCLOCK: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Memory Clock value in MHz expected"); - devp->MemClk = (int)(val.realnum * 1000.0 + 0.5); - OFLG_SET(XCONFIG_MEMCLOCK,&(devp->xconfigFlag)); - break; - - case LCDCLOCK: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("LCD Clock value in MHz expected"); - devp->LCDClk = (int)(val.realnum * 1000.0 + 0.5); - OFLG_SET(XCONFIG_LCDCLOCK,&(devp->xconfigFlag)); - break; - - case CHIPID: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("ChipID expected"); - devp->chipID = val.num; - break; - - case CHIPREV: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("ChipRev expected"); - devp->chipRev = val.num; - break; - - case VGABASEADDR: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("VGA aperature base address expected"); - devp->VGAbase = val.num; - OFLG_SET(XCONFIG_VGABASE, &(devp->xconfigFlag)); - break; - - case S3REFCLK: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("RefCLK value in MHz expected"); - devp->s3RefClk = (int)(val.realnum * 1000.0 + 0.5); - break; - - case S3BLANKDELAY: - if (xf86GetToken(NULL) != NUMBER || val.num>7) - xf86ConfigError("number(s) 0..7 expected"); - devp->s3BlankDelay = val.num; - if ((token=xf86GetToken(NULL)) == NUMBER) { - if (val.num>7) xf86ConfigError("number2 0..7 expected"); - devp->s3BlankDelay |= val.num<<4; - } - else pushToken = token; - break; - - case TEXTCLOCKFRQ: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Text clock expected"); - devp->textClockValue = (int)(val.realnum * 1000.0 + 0.5); - break; - - case EOF: - FatalError("Unexpected EOF (missing EndSection?)"); - break; /* :-) */ - default: - if(DCerr) - xf86ConfigError("Device section keyword expected"); - break; + xf86Msg(X_ERROR, "No core keyboard device specified\n"); + return FALSE; } - } -#ifdef NEED_RETURN_VALUE - return RET_OKAY; -#endif + return TRUE; } -static CONFIG_RETURN_TYPE -configMonitorSection() +/* + * figure out which layout is active, which screens are used in that layout, + * which drivers and monitors are used in these screens + */ +static Bool +configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, + char *default_layout) { - int token; - int i; - MonPtr monp; - float multiplier; - - /* Allocate one more monitor */ - if ( monitor_list == NULL ) { - monitor_list = (MonPtr) xalloc(sizeof(MonRec)); - } else { - monitor_list = (MonPtr) xrealloc(monitor_list, - (n_monitors+1) * sizeof(MonRec)); - } - monp = &(monitor_list[n_monitors]); /* Point to the new monitor */ - monp->Modes = 0; - monp->Last = 0; - monp->n_hsync = 0; - monp->n_vrefresh = 0; - n_monitors++; - - while ((token = xf86GetToken(MonitorTab)) != ENDSECTION) { - switch (token) { - case IDENTIFIER: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("identifier name expected"); - monp->id = val.str; - break; - case VENDOR: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("vendor name expected"); - monp->vendor = val.str; - break; - case MODEL: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("model name expected"); - monp->model = val.str; - break; - case MODE: - readVerboseMode(monp); - break; - case MODELINE: - token = xf86GetToken(NULL); - pNew = (DisplayModePtr)xalloc(sizeof(DisplayModeRec)); - - if (monp->Last) - monp->Last->next = pNew; - else - monp->Modes = pNew; - - if (token == STRING) - { - pNew->name = val.str; - if ((token = xf86GetToken(NULL)) != NUMBER) - FatalError("Dotclock expected"); - } - else if (monp->Last) - { -#if defined(MACH) || defined(AMOEBA) - pNew->name = (char *) xalloc (strlen (monp->Last->name) + 1); - strcpy (pNew->name, monp->Last->name); -#else - pNew->name = (char *)strdup(monp->Last->name); -#endif - } - else - xf86ConfigError("Mode name expected"); - - pNew->next = NULL; - pNew->prev = NULL; - pNew->Flags = 0; - pNew->Clock = (int)(val.realnum * 1000.0 + 0.5); - pNew->CrtcHAdjusted = FALSE; - pNew->CrtcVAdjusted = FALSE; - pNew->CrtcHSkew = pNew->HSkew = 0; - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcHDisplay = pNew->HDisplay = val.num; - else xf86ConfigError("Horizontal display expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcHSyncStart = pNew->HSyncStart = val.num; - else xf86ConfigError("Horizontal sync start expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcHSyncEnd = pNew->HSyncEnd = val.num; - else xf86ConfigError("Horizontal sync end expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcHTotal = pNew->HTotal = val.num; - else xf86ConfigError("Horizontal total expected"); - - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcVDisplay = pNew->VDisplay = val.num; - else xf86ConfigError("Vertical display expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcVSyncStart = pNew->VSyncStart = val.num; - else xf86ConfigError("Vertical sync start expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcVSyncEnd = pNew->VSyncEnd = val.num; - else xf86ConfigError("Vertical sync end expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcVTotal = pNew->VTotal = val.num; - else xf86ConfigError("Vertical total expected"); - - token = xf86GetToken(TimingTab); - while ( (token == TT_INTERLACE) || (token == TT_PHSYNC) || - (token == TT_NHSYNC) || (token == TT_PVSYNC) || - (token == TT_NVSYNC) || (token == TT_CSYNC) || - (token == TT_PCSYNC) || (token == TT_NCSYNC) || - (token == TT_DBLSCAN) || (token == TT_HSKEW) ) - { - switch(token) { - - case TT_INTERLACE: pNew->Flags |= V_INTERLACE; break; - case TT_PHSYNC: pNew->Flags |= V_PHSYNC; break; - case TT_NHSYNC: pNew->Flags |= V_NHSYNC; break; - case TT_PVSYNC: pNew->Flags |= V_PVSYNC; break; - case TT_NVSYNC: pNew->Flags |= V_NVSYNC; break; - case TT_CSYNC: pNew->Flags |= V_CSYNC; break; - case TT_PCSYNC: pNew->Flags |= V_PCSYNC; break; - case TT_NCSYNC: pNew->Flags |= V_NCSYNC; break; - case TT_DBLSCAN: pNew->Flags |= V_DBLSCAN; break; - case TT_HSKEW: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Horizontal skew expected"); - pNew->CrtcHSkew = pNew->HSkew = val.num; - pNew->Flags |= V_HSKEW; - break; - default: - xf86ConfigError("bug found in config reader"); break; - } - token = xf86GetToken(TimingTab); - } - pushToken = token; - monp->Last = pNew; /* GJA */ - break; - case BANDWIDTH: - /* This should be completely removed at some point */ - if ((token = xf86GetToken(NULL)) != NUMBER) - xf86ConfigError("Bandwidth number expected"); -#if 0 - monp->bandwidth = val.realnum; - /* Handle optional scaler */ - token = xf86GetToken(UnitTab); - switch ( token ) { - case HRZ: multiplier = 1.0e-6; break; - case KHZ: multiplier = 1.0e-3; break; - case MHZ: multiplier = 1.0; break; - default: multiplier = 1.0; pushToken = token; - } - monp->bandwidth *= multiplier; -#endif - break; - case HORIZSYNC: - if ((token = xf86GetToken(NULL)) != NUMBER) - xf86ConfigError("Horizontal sync value expected"); - monp->hsync[monp->n_hsync].lo = val.realnum; - if ((token = xf86GetToken(NULL)) == DASH) { - if ((token = xf86GetToken(NULL)) != NUMBER) - xf86ConfigError("Upperbound for horizontal sync value expected"); - monp->hsync[monp->n_hsync].hi = val.realnum; - } else { - pushToken = token; - monp->hsync[monp->n_hsync].hi = monp->hsync[monp->n_hsync].lo; - } - monp->n_hsync++; - while ( (token = xf86GetToken(NULL)) == COMMA ) { - if ( monp->n_hsync == MAX_HSYNC ) - xf86ConfigError("Sorry. Too many horizontal sync intervals."); - - if ((token = xf86GetToken(NULL)) != NUMBER) - xf86ConfigError("Horizontal sync value expected"); - monp->hsync[monp->n_hsync].lo = val.realnum; - if ((token = xf86GetToken(NULL)) == DASH) { - if ((token = xf86GetToken(NULL)) != NUMBER) - xf86ConfigError("Upperbound for horizontal sync value expected"); - monp->hsync[monp->n_hsync].hi = val.realnum; - } else { - pushToken = token; - monp->hsync[monp->n_hsync].hi = monp->hsync[monp->n_hsync].lo; - } - monp->n_hsync++; - } - pushToken = token; - /* Handle optional scaler */ - token = xf86GetToken(UnitTab); - switch ( token ) { - case HRZ: multiplier = 1.0e-3; break; - case KHZ: multiplier = 1.0; break; - case MHZ: multiplier = 1.0e3; break; - default: multiplier = 1.0; pushToken = token; - } - for ( i = 0 ; i < monp->n_hsync ; i++ ) { - monp->hsync[i].hi *= multiplier; - monp->hsync[i].lo *= multiplier; - } - break; - case VERTREFRESH: - if ((token = xf86GetToken(NULL)) != NUMBER) - xf86ConfigError("Vertical refresh value expected"); - monp->vrefresh[monp->n_vrefresh].lo = val.realnum; - if ((token = xf86GetToken(NULL)) == DASH) { - if ((token = xf86GetToken(NULL)) != NUMBER) - xf86ConfigError("Upperbound for vertical refresh value expected"); - monp->vrefresh[monp->n_vrefresh].hi = val.realnum; - } else { - monp->vrefresh[monp->n_vrefresh].hi = - monp->vrefresh[monp->n_vrefresh].lo; - pushToken = token; - } - monp->n_vrefresh++; - while ( (token = xf86GetToken(NULL)) == COMMA ) { - if ( monp->n_vrefresh == MAX_HSYNC ) - xf86ConfigError("Sorry. Too many vertical refresh intervals."); - - if ((token = xf86GetToken(NULL)) != NUMBER) - xf86ConfigError("Vertical refresh value expected"); - monp->vrefresh[monp->n_vrefresh].lo = val.realnum; - if ((token = xf86GetToken(NULL)) == DASH) { - if ((token = xf86GetToken(NULL)) != NUMBER) - xf86ConfigError("Upperbound for vertical refresh value expected"); - monp->vrefresh[monp->n_vrefresh].hi = val.realnum; - } else { - monp->vrefresh[monp->n_vrefresh].hi = - monp->vrefresh[monp->n_vrefresh].lo; - pushToken = token; - } - monp->n_vrefresh++; - } - pushToken = token; - /* Handle optional scaler */ - token = xf86GetToken(UnitTab); - switch ( token ) { - case HRZ: multiplier = 1.0; break; - case KHZ: multiplier = 1.0e3; break; - case MHZ: multiplier = 1.0e6; break; - default: multiplier = 1.0; pushToken = token; - } - for ( i = 0 ; i < monp->n_vrefresh ; i++ ) { - monp->vrefresh[i].hi *= multiplier; - monp->vrefresh[i].lo *= multiplier; - } - break; - case GAMMA: { - char *msg = "gamma correction value(s) expected\n either one value or three r/g/b values with 0.1 <= gamma <= 10"; - if ((token = xf86GetToken(NULL)) != NUMBER || val.realnum<0.1 || val.realnum>10) - xf86ConfigError(msg); - else { - xf86rGamma = xf86gGamma = xf86bGamma = 1.0 / val.realnum; - if ((token = xf86GetToken(NULL)) == NUMBER) { - if (val.realnum<0.1 || val.realnum>10) xf86ConfigError(msg); - else { - xf86gGamma = 1.0 / val.realnum; - if ((token = xf86GetToken(NULL)) != NUMBER || val.realnum<0.1 || val.realnum>10) - xf86ConfigError(msg); - else { - xf86bGamma = 1.0 / val.realnum; - } - } - } - else pushToken = token; - } - break; + XF86ConfAdjacencyPtr adjp; + XF86ConfInactivePtr idp; + XF86ConfInputrefPtr irp; + int count = 0; + int scrnum; + XF86ConfLayoutPtr l; + MessageType from; + screenLayoutPtr slp; + GDevPtr gdp; + IDevPtr indp; + int i = 0, j; + + if (!servlayoutp) + return FALSE; + + /* + * which layout section is the active one? + * + * If there is a -layout command line option, use that one, otherwise + * pick the first one. + */ + from = X_DEFAULT; + if (xf86LayoutName != NULL) + from = X_CMDLINE; + else if (default_layout) { + xf86LayoutName = default_layout; + from = X_CONFIG; + } + if (xf86LayoutName != NULL) { + if ((l = xf86findLayout(xf86LayoutName, conf_layout)) == NULL) { + xf86Msg(X_ERROR, "No ServerLayout section called \"%s\"\n", + xf86LayoutName); + return FALSE; + } + conf_layout = l; } - case EOF: - FatalError("Unexpected EOF. Missing EndSection?"); - break; /* :-) */ + xf86Msg(from, "ServerLayout \"%s\"\n", conf_layout->lay_identifier); + adjp = conf_layout->lay_adjacency_lst; - default: - xf86ConfigError("Monitor section keyword expected"); - break; + /* + * we know that each screen is referenced exactly once on the left side + * of a layout statement in the Layout section. So to allocate the right + * size for the array we do a quick walk of the list to figure out how + * many sections we have + */ + while (adjp) { + count++; + adjp = (XF86ConfAdjacencyPtr)adjp->list.next; } - } -#ifdef NEED_RETURN_VALUE - return RET_OKAY; +#ifdef DEBUG + ErrorF("Found %d screens in the layout section %s", + count, conf_layout->lay_identifier); #endif -} + slp = xnfcalloc(1, (count + 1) * sizeof(screenLayoutRec)); + slp[count].screen = NULL; + /* + * now that we have storage, loop over the list again and fill in our + * data structure; at this point we do not fill in the adjacency + * information as it is not clear if we need it at all + */ + adjp = conf_layout->lay_adjacency_lst; + count = 0; + while (adjp) { + slp[count].screen = xnfcalloc(1, sizeof(confScreenRec)); + if (adjp->adj_scrnum < 0) + scrnum = count; + else + scrnum = adjp->adj_scrnum; + if (!configScreen(slp[count].screen, adjp->adj_screen, scrnum, + X_CONFIG)) + return FALSE; + slp[count].x = adjp->adj_x; + slp[count].y = adjp->adj_y; + slp[count].refname = adjp->adj_refscreen; + switch (adjp->adj_where) { + case CONF_ADJ_OBSOLETE: + slp[count].where = PosObsolete; + slp[count].topname = adjp->adj_top_str; + slp[count].bottomname = adjp->adj_bottom_str; + slp[count].leftname = adjp->adj_left_str; + slp[count].rightname = adjp->adj_right_str; + break; + case CONF_ADJ_ABSOLUTE: + slp[count].where = PosAbsolute; + break; + case CONF_ADJ_RIGHTOF: + slp[count].where = PosRightOf; + break; + case CONF_ADJ_LEFTOF: + slp[count].where = PosLeftOf; + break; + case CONF_ADJ_ABOVE: + slp[count].where = PosAbove; + break; + case CONF_ADJ_BELOW: + slp[count].where = PosBelow; + break; + case CONF_ADJ_RELATIVE: + slp[count].where = PosRelative; + break; + } + count++; + adjp = (XF86ConfAdjacencyPtr)adjp->list.next; + } -static CONFIG_RETURN_TYPE -configDynamicModuleSection() -{ - int token; - - while ((token = xf86GetToken(ModuleTab)) != ENDSECTION) { - switch (token) { - case LOAD: - if (xf86GetToken(NULL) != STRING) - xf86ConfigError("Dynamic module expected"); - else { -#ifdef DYNAMIC_MODULE - if (!modulePath) { - static Bool firstTime = TRUE; - - modulePath = (char*)Xcalloc(strlen(DEFAULT_MODULE_PATH)+1); - strcpy(modulePath, DEFAULT_MODULE_PATH); - - if (xf86Verbose && firstTime) { - ErrorF("%s no ModulePath specified using default: %s\n", - XCONFIG_PROBED, DEFAULT_MODULE_PATH); - firstTime = FALSE; - } - } - xf86LoadModule(val.str, modulePath); -#else - ErrorF("Dynamic modules not supported. \"%s\" not loaded\n", - val.str); -#endif + /* XXX Need to tie down the upper left screen. */ + + /* Fill in the refscreen and top/bottom/left/right values */ + for (i = 0; i < count; i++) { + for (j = 0; j < count; j++) { + if (slp[i].refname && + strcmp(slp[i].refname, slp[j].screen->id) == 0) { + slp[i].refscreen = slp[j].screen; } - break; + if (slp[i].topname && + strcmp(slp[i].topname, slp[j].screen->id) == 0) { + slp[i].top = slp[j].screen; + } + if (slp[i].bottomname && + strcmp(slp[i].bottomname, slp[j].screen->id) == 0) { + slp[i].bottom = slp[j].screen; + } + if (slp[i].leftname && + strcmp(slp[i].leftname, slp[j].screen->id) == 0) { + slp[i].left = slp[j].screen; + } + if (slp[i].rightname && + strcmp(slp[i].rightname, slp[j].screen->id) == 0) { + slp[i].right = slp[j].screen; + } + } + if (slp[i].where != PosObsolete + && slp[i].where != PosAbsolute + && !slp[i].refscreen) { + xf86Msg(X_ERROR,"Screen %s doesn't exist: deleting placement\n", + slp[i].refname); + slp[i].where = PosAbsolute; + slp[i].x = 0; + slp[i].y = 0; + } + } - case EOF: - FatalError("Unexpected EOF. Missing EndSection?"); - break; /* :-) */ - - default: - xf86ConfigError("Module section keyword expected"); +#ifdef LAYOUT_DEBUG + ErrorF("Layout \"%s\"\n", conf_layout->lay_identifier); + for (i = 0; i < count; i++) { + ErrorF("Screen: \"%s\" (%d):\n", slp[i].screen->id, + slp[i].screen->screennum); + switch (slp[i].where) { + case PosObsolete: + ErrorF("\tObsolete format: \"%s\" \"%s\" \"%s\" \"%s\"\n", + slp[i].top, slp[i].bottom, slp[i].left, slp[i].right); + break; + case PosAbsolute: + if (slp[i].x == -1) + if (slp[i].screen->screennum == 0) + ErrorF("\tImplicitly left-most\n"); + else + ErrorF("\tImplicitly right of screen %d\n", + slp[i].screen->screennum - 1); + else + ErrorF("\t%d %d\n", slp[i].x, slp[i].y); + break; + case PosRightOf: + ErrorF("\tRight of \"%s\"\n", slp[i].refscreen->id); + break; + case PosLeftOf: + ErrorF("\tLeft of \"%s\"\n", slp[i].refscreen->id); break; - } + case PosAbove: + ErrorF("\tAbove \"%s\"\n", slp[i].refscreen->id); + break; + case PosBelow: + ErrorF("\tBelow \"%s\"\n", slp[i].refscreen->id); + break; + case PosRelative: + ErrorF("\t%d %d relative to \"%s\"\n", slp[i].x, slp[i].y, + slp[i].refscreen->id); + break; + } } -#ifdef NEED_RETURN_VALUE - return RET_OKAY; #endif + /* + * Count the number of inactive devices. + */ + count = 0; + idp = conf_layout->lay_inactive_lst; + while (idp) { + count++; + idp = (XF86ConfInactivePtr)idp->list.next; + } +#ifdef DEBUG + ErrorF("Found %d inactive devices in the layout section %s", + count, conf_layout->lay_identifier); +#endif + gdp = xnfalloc((count + 1) * sizeof(GDevRec)); + gdp[count].identifier = NULL; + idp = conf_layout->lay_inactive_lst; + count = 0; + while (idp) { + if (!configDevice(&gdp[count], idp->inactive_device, FALSE)) + return FALSE; + count++; + idp = (XF86ConfInactivePtr)idp->list.next; + } + /* + * Count the number of input devices. + */ + count = 0; + irp = conf_layout->lay_input_lst; + while (irp) { + count++; + irp = (XF86ConfInputrefPtr)irp->list.next; + } +#ifdef DEBUG + ErrorF("Found %d input devices in the layout section %s", + count, conf_layout->lay_identifier); +#endif + indp = xnfalloc((count + 1) * sizeof(IDevRec)); + indp[count].identifier = NULL; + irp = conf_layout->lay_input_lst; + count = 0; + while (irp) { + if (!configInput(&indp[count], irp->iref_inputdev, X_CONFIG)) + return FALSE; + indp[count].extraOptions = irp->iref_option_lst; + count++; + irp = (XF86ConfInputrefPtr)irp->list.next; + } + servlayoutp->id = conf_layout->lay_identifier; + servlayoutp->screens = slp; + servlayoutp->inactives = gdp; + servlayoutp->inputs = indp; + servlayoutp->options = conf_layout->lay_option_lst; + from = X_DEFAULT; + + if (!checkCoreInputDevices(servlayoutp, FALSE)) + return FALSE; + return TRUE; } -static CONFIG_RETURN_TYPE -readVerboseMode(monp) -MonPtr monp; +/* + * No layout section, so find the first Screen section and set that up as + * the only active screen. + */ +static Bool +configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen) { - int token, token2; - int had_dotclock = 0, had_htimings = 0, had_vtimings = 0; - - pNew = (DisplayModePtr)xalloc(sizeof(DisplayModeRec)); - pNew->next = NULL; - pNew->prev = NULL; - pNew->Flags = 0; - pNew->HDisplay = pNew->VDisplay = 0; /* Uninitialized */ - pNew->CrtcHAdjusted = pNew->CrtcVAdjusted = FALSE; - pNew->CrtcHSkew = pNew->HSkew = 0; - - if (monp->Last) - monp->Last->next = pNew; - else - monp->Modes = pNew; - monp->Last = pNew; - - if ( xf86GetToken(NULL) != STRING ) { - FatalError("Mode name expected"); - } - pNew->name = val.str; - while ((token = xf86GetToken(ModeTab)) != ENDMODE) { - switch (token) { - case DOTCLOCK: - if ((token = xf86GetToken(NULL)) != NUMBER) { - FatalError("Dotclock expected"); - } - pNew->Clock = (int)(val.realnum * 1000.0 + 0.5); - had_dotclock = 1; - break; - case HTIMINGS: - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcHDisplay = pNew->HDisplay = val.num; - else xf86ConfigError("Horizontal display expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcHSyncStart = pNew->HSyncStart = val.num; - else xf86ConfigError("Horizontal sync start expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcHSyncEnd = pNew->HSyncEnd = val.num; - else xf86ConfigError("Horizontal sync end expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcHTotal = pNew->HTotal = val.num; - else xf86ConfigError("Horizontal total expected"); - had_htimings = 1; - break; - case VTIMINGS: - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcVDisplay = pNew->VDisplay = val.num; - else xf86ConfigError("Vertical display expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcVSyncStart = pNew->VSyncStart = val.num; - else xf86ConfigError("Vertical sync start expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcVSyncEnd = pNew->VSyncEnd = val.num; - else xf86ConfigError("Vertical sync end expected"); - - if (xf86GetToken(NULL) == NUMBER) - pNew->CrtcVTotal = pNew->VTotal = val.num; - else xf86ConfigError("Vertical total expected"); - had_vtimings = 1; - break; - case FLAGS: - token = xf86GetToken(NULL); - if (token != STRING) - xf86ConfigError("Flag string expected. Note: flags must be in \"\""); - while ( token == STRING ) { - token2 = getStringToken(TimingTab); - switch(token2) { - case TT_INTERLACE: pNew->Flags |= V_INTERLACE; break; - case TT_PHSYNC: pNew->Flags |= V_PHSYNC; break; - case TT_NHSYNC: pNew->Flags |= V_NHSYNC; break; - case TT_PVSYNC: pNew->Flags |= V_PVSYNC; break; - case TT_NVSYNC: pNew->Flags |= V_NVSYNC; break; - case TT_CSYNC: pNew->Flags |= V_CSYNC; break; - case TT_PCSYNC: pNew->Flags |= V_PCSYNC; break; - case TT_NCSYNC: pNew->Flags |= V_NCSYNC; break; - case TT_DBLSCAN: pNew->Flags |= V_DBLSCAN; break; - default: - xf86ConfigError("Unknown flag string"); break; - } - token = xf86GetToken(NULL); - } - pushToken = token; - break; - case HSKEW: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Horizontal skew expected"); - pNew->Flags |= V_HSKEW; - pNew->CrtcHSkew = pNew->HSkew = val.num; - break; + MessageType from; + XF86ConfScreenPtr s; + screenLayoutPtr slp; + IDevPtr indp; + + if (!servlayoutp) + return FALSE; + + if (conf_screen == NULL) { + xf86ConfigError("No Screen sections present\n"); + return FALSE; } - } - if ( !had_dotclock ) xf86ConfigError("the dotclock is missing"); - if ( !had_htimings ) xf86ConfigError("the horizontal timings are missing"); - if ( !had_vtimings ) xf86ConfigError("the vertical timings are missing"); -#ifdef NEED_RETURN_VALUE - return RET_OKAY; -#endif -} -static Bool dummy; + /* + * which screen section is the active one? + * + * If there is a -screen option, use that one, otherwise use the first + * one. + */ -#ifdef XF86SETUP -int xf86setup_scrn_ndisps[8]; -DispPtr xf86setup_scrn_displays[8]; -#endif + from = X_CONFIG; + if (xf86ScreenName != NULL) { + if ((s = xf86findScreen(xf86ScreenName, conf_screen)) == NULL) { + xf86Msg(X_ERROR, "No Screen section called \"%s\"\n", + xf86ScreenName); + return FALSE; + } + conf_screen = s; + from = X_CMDLINE; + } + + /* We have exactly one screen */ + + slp = xnfcalloc(1, 2 * sizeof(screenLayoutRec)); + slp[0].screen = xnfcalloc(1, sizeof(confScreenRec)); + slp[1].screen = NULL; + if (!configScreen(slp[0].screen, conf_screen, 0, from)) + return FALSE; + servlayoutp->id = "(implicit)"; + servlayoutp->screens = slp; + servlayoutp->inactives = xnfcalloc(1, sizeof(GDevRec)); + servlayoutp->options = NULL; + /* Set up an empty input device list, then look for some core devices. */ + indp = xnfalloc(sizeof(IDevRec)); + indp->identifier = NULL; + servlayoutp->inputs = indp; + if (!checkCoreInputDevices(servlayoutp, TRUE)) + return FALSE; + + return TRUE; +} -static CONFIG_RETURN_TYPE -configScreenSection() +static Bool +configXvAdaptor(confXvAdaptorPtr adaptor, XF86ConfVideoAdaptorPtr conf_adaptor) { - int i, j; - int driverno; - int had_monitor = 0, had_device = 0; - int dispIndex = 0; - int numDisps = 0; - DispPtr dispList = NULL; - DispPtr dispp; - - int token; - ScrnInfoPtr screen = NULL; - int textClockValue = -1; - - token = xf86GetToken(ScreenTab); - if ( token != DRIVER ) - xf86ConfigError("The screen section must begin with the 'driver' line"); - - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Driver name expected"); - driverno = getStringToken(DriverTab); - switch ( driverno ) { - case SVGA: - case VGA2: - case MONO: - case VGA16: - case ACCEL: - case FBDEV: - break; - default: - xf86ConfigError("Not a recognized driver name"); - } - scr_index = getScreenIndex(driverno); + int count = 0; + XF86ConfVideoPortPtr conf_port; + + xf86Msg(X_CONFIG, "| |-->VideoAdaptor \"%s\"\n", + conf_adaptor->va_identifier); + adaptor->identifier = conf_adaptor->va_identifier; + adaptor->options = conf_adaptor->va_option_lst; + if (conf_adaptor->va_busid || conf_adaptor->va_driver) { + xf86Msg(X_CONFIG, "| | Unsupported device type, skipping entry\n"); + return FALSE; + } - dummy = scr_index < 0 || !xf86Screens[scr_index]; - if (dummy) - screen = (ScrnInfoPtr)xalloc(sizeof(ScrnInfoRec)); - else - { - screen = xf86Screens[scr_index]; - screen->configured = TRUE; - screen->tmpIndex = screenno++; - screen->scrnIndex = scr_index; /* scrnIndex must not be changed */ - screen->frameX0 = -1; - screen->frameY0 = -1; - screen->virtualX = -1; - screen->virtualY = -1; - screen->defaultVisual = -1; - screen->modes = NULL; - screen->width = 240; - screen->height = 180; - screen->bankedMono = FALSE; - screen->textclock = -1; - screen->blackColour.red = 0; - screen->blackColour.green = 0; - screen->blackColour.blue = 0; - screen->whiteColour.red = 0x3F; - screen->whiteColour.green = 0x3F; - screen->whiteColour.blue = 0x3F; - } - screen->clocks = 0; + /* + * figure out how many videoport subsections there are and fill them in + */ + conf_port = conf_adaptor->va_port_lst; + while(conf_port) { + count++; + conf_port = (XF86ConfVideoPortPtr)conf_port->list.next; + } + adaptor->ports = xnfalloc((count) * sizeof(confXvPortRec)); + adaptor->numports = count; + count = 0; + conf_port = conf_adaptor->va_port_lst; + while(conf_port) { + adaptor->ports[count].identifier = conf_port->vp_identifier; + adaptor->ports[count].options = conf_port->vp_option_lst; + count++; + conf_port = (XF86ConfVideoPortPtr)conf_port->list.next; + } - while ((token = xf86GetToken(ScreenTab)) != ENDSECTION) { - switch (token) { + return TRUE; +} + +static Bool +configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum, + MessageType from) +{ + int count = 0; + XF86ConfDisplayPtr dispptr; + XF86ConfAdaptorLinkPtr conf_adaptor; - case DEFBPP: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Default color depth expected"); - screen->depth = val.num; - break; + xf86Msg(from, "|-->Screen \"%s\" (%d)\n", conf_screen->scrn_identifier, + scrnum); + /* + * now we fill in the elements of the screen + */ + screenp->id = conf_screen->scrn_identifier; + screenp->screennum = scrnum; + screenp->defaultdepth = conf_screen->scrn_defaultdepth; + screenp->defaultbpp = conf_screen->scrn_defaultbpp; + screenp->defaultfbbpp = conf_screen->scrn_defaultfbbpp; + screenp->monitor = xnfcalloc(1, sizeof(MonRec)); + if (!configMonitor(screenp->monitor,conf_screen->scrn_monitor)) + return FALSE; + screenp->device = xnfcalloc(1, sizeof(GDevRec)); + configDevice(screenp->device,conf_screen->scrn_device, TRUE); + screenp->device->myScreenSection = screenp; + screenp->options = conf_screen->scrn_option_lst; + + /* + * figure out how many display subsections there are and fill them in + */ + dispptr = conf_screen->scrn_display_lst; + while(dispptr) { + count++; + dispptr = (XF86ConfDisplayPtr)dispptr->list.next; + } + screenp->displays = xnfalloc((count) * sizeof(DispRec)); + screenp->numdisplays = count; + count = 0; + dispptr = conf_screen->scrn_display_lst; + while(dispptr) { + configDisplay(&(screenp->displays[count]),dispptr); + count++; + dispptr = (XF86ConfDisplayPtr)dispptr->list.next; + } - case SCREENNO: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Screen number expected"); - screen->tmpIndex = val.num; - break; + /* + * figure out how many videoadaptor references there are and fill them in + */ + conf_adaptor = conf_screen->scrn_adaptor_lst; + while(conf_adaptor) { + count++; + conf_adaptor = (XF86ConfAdaptorLinkPtr)conf_adaptor->list.next; + } + screenp->xvadaptors = xnfalloc((count) * sizeof(confXvAdaptorRec)); + screenp->numxvadaptors = 0; + conf_adaptor = conf_screen->scrn_adaptor_lst; + while(conf_adaptor) { + if (configXvAdaptor(&(screenp->xvadaptors[screenp->numxvadaptors]), + conf_adaptor->al_adaptor)) + screenp->numxvadaptors++; + conf_adaptor = (XF86ConfAdaptorLinkPtr)conf_adaptor->list.next; + } - case SUBSECTION: - if ((xf86GetToken(NULL) != STRING) || (StrCaseCmp(val.str, "display") != 0)) { - xf86ConfigError("You must say \"Display\" here"); - } - if (dispList == NULL) { - dispList = (DispPtr)xalloc(sizeof(DispRec)); - } else { - dispList = (DispPtr)xrealloc(dispList, - (numDisps + 1) * sizeof(DispRec)); - } - dispp = dispList + numDisps; - numDisps++; - dispp->depth = -1; - dispp->weight.red = dispp->weight.green = dispp->weight.blue = 0; - dispp->frameX0 = -1; - dispp->frameY0 = -1; - dispp->virtualX = -1; - dispp->virtualY = -1; - dispp->modes = NULL; - dispp->whiteColour.red = dispp->whiteColour.green = - dispp->whiteColour.blue = 0x3F; - dispp->blackColour.red = dispp->blackColour.green = - dispp->blackColour.blue = 0; - dispp->defaultVisual = -1; - OFLG_ZERO(&(dispp->options)); - OFLG_ZERO(&(dispp->xconfigFlag)); - dispp->DCOptions = NULL; - - configDisplaySubsection(dispp); - break; - - case EOF: - FatalError("Unexpected EOF (missing EndSection?)"); - break; /* :-) */ - - case MDEVICE: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Device name expected"); - for ( i = 0 ; i < n_devices ; i++ ) { - if ( strcmp(device_list[i].identifier,val.str) == 0 ) { - /* Copy back */ - if (!dummy && xf86Verbose) { - ErrorF("%s %s: Graphics device ID: \"%s\"\n", - XCONFIG_GIVEN, screen->name, device_list[i].identifier); - } - screen->clocks = device_list[i].clocks; - for ( j = 0 ; j < MAXCLOCKS ; j++ ) { - screen->clock[j] = device_list[i].clock[j]; - } - screen->chipset = device_list[i].chipset; - screen->ramdac = device_list[i].ramdac; - for (j=0; j<MAXDACSPEEDS; j++) - screen->dacSpeeds[j] = device_list[i].dacSpeeds[j]; - screen->dacSpeedBpp = 0; - screen->options = device_list[i].options; - screen->clockOptions = device_list[i].clockOptions; - screen->xconfigFlag = device_list[i].xconfigFlag; - screen->videoRam = device_list[i].videoRam; - screen->speedup = device_list[i].speedup; - screen->clockprog = device_list[i].clockprog; - textClockValue = device_list[i].textClockValue; - if (OFLG_ISSET(XCONFIG_BIOSBASE, &screen->xconfigFlag)) - screen->BIOSbase = device_list[i].BIOSbase; - if (OFLG_ISSET(XCONFIG_MEMBASE, &screen->xconfigFlag)) - screen->MemBase = device_list[i].MemBase; - if (OFLG_ISSET(XCONFIG_IOBASE, &screen->xconfigFlag)) - screen->IObase = device_list[i].IObase; - if (OFLG_ISSET(XCONFIG_DACBASE, &screen->xconfigFlag)) - screen->DACbase = device_list[i].DACbase; - if (OFLG_ISSET(XCONFIG_COPBASE, &screen->xconfigFlag)) - screen->COPbase = device_list[i].COPbase; - if (OFLG_ISSET(XCONFIG_POSBASE, &screen->xconfigFlag)) - screen->POSbase = device_list[i].POSbase; - if (OFLG_ISSET(XCONFIG_INSTANCE, &screen->xconfigFlag)) - screen->instance = device_list[i].instance; - screen->s3Madjust = device_list[i].s3Madjust; - screen->s3Nadjust = device_list[i].s3Nadjust; - screen->s3MClk = device_list[i].s3MClk; - screen->MemClk = device_list[i].MemClk; - screen->LCDClk = device_list[i].LCDClk; - screen->chipID = device_list[i].chipID; - screen->chipRev = device_list[i].chipRev; - screen->s3RefClk = device_list[i].s3RefClk; - screen->s3BlankDelay = device_list[i].s3BlankDelay; - screen->textClockFreq = device_list[i].textClockValue; - if (OFLG_ISSET(XCONFIG_VGABASE, &screen->xconfigFlag)) - screen->VGAbase = device_list[i].VGAbase; - screen->DCConfig = device_list[i].DCConfig; - screen->DCOptions = device_list[i].DCOptions; -#ifdef XF86SETUP - screen->device = (void *) &device_list[i]; -#endif - break; - } - } - if ( i == n_devices ) { /* Exhausted the device list */ - xf86ConfigError("Not a declared device"); - } - had_device = 1; - break; - - case MONITOR: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Monitor name expected"); - for ( i = 0 ; i < n_monitors ; i++ ) { - if ( strcmp(monitor_list[i].id,val.str) == 0 ) { - if (!dummy && xf86Verbose) { - ErrorF("%s %s: Monitor ID: \"%s\"\n", - XCONFIG_GIVEN, screen->name, monitor_list[i].id); - } - if (!dummy) { - monitor_list[i].Modes = xf86PruneModes(&monitor_list[i], - monitor_list[i].Modes, - screen, FALSE); - screen->monitor = (MonPtr)xalloc(sizeof(MonRec)); - memcpy(screen->monitor, &monitor_list[i], sizeof(MonRec)); - } - break; - } - } - if ( i == n_monitors ) { /* Exhausted the monitor list */ - xf86ConfigError("Not a declared monitor"); - } - had_monitor = 1; - break; - - case BLANKTIME: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Screensaver blank time expected"); - if (!dummy && !xf86sFlag) - defaultScreenSaverTime = ScreenSaverTime = val.num * MILLI_PER_MIN; - break; - - case STANDBYTIME: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Screensaver standby time expected"); -#ifdef DPMSExtension - if (!dummy) - DPMSStandbyTime = val.num * MILLI_PER_MIN; -#endif - break; + return TRUE; +} - case SUSPENDTIME: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Screensaver suspend time expected"); -#ifdef DPMSExtension - if (!dummy) - DPMSSuspendTime = val.num * MILLI_PER_MIN; -#endif - break; +static Bool +configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor) +{ + int count; + DisplayModePtr mode,last = NULL; + XF86ConfModeLinePtr cmodep; + XF86ConfModesPtr modes; + XF86ConfModesLinkPtr modeslnk = conf_monitor->mon_modes_sect_lst; + Gamma zeros = {0.0, 0.0, 0.0}; + float badgamma = 0.0; + + xf86Msg(X_CONFIG, "| |-->Monitor \"%s\"\n", + conf_monitor->mon_identifier); + monitorp->id = conf_monitor->mon_identifier; + monitorp->vendor = conf_monitor->mon_vendor; + monitorp->model = conf_monitor->mon_modelname; + monitorp->Modes = NULL; + monitorp->Last = NULL; + monitorp->gamma = zeros; + monitorp->widthmm = conf_monitor->mon_width; + monitorp->heightmm = conf_monitor->mon_height; + monitorp->options = conf_monitor->mon_option_lst; - case OFFTIME: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Screensaver off time expected"); -#ifdef DPMSExtension - if (!dummy) - DPMSOffTime = val.num * MILLI_PER_MIN; -#endif - break; + /* + * fill in the monitor structure + */ + for( count = 0 ; count < conf_monitor->mon_n_hsync; count++) { + monitorp->hsync[count].hi = conf_monitor->mon_hsync[count].hi; + monitorp->hsync[count].lo = conf_monitor->mon_hsync[count].lo; + } + monitorp->nHsync = conf_monitor->mon_n_hsync; + for( count = 0 ; count < conf_monitor->mon_n_vrefresh; count++) { + monitorp->vrefresh[count].hi = conf_monitor->mon_vrefresh[count].hi; + monitorp->vrefresh[count].lo = conf_monitor->mon_vrefresh[count].lo; + } + monitorp->nVrefresh = conf_monitor->mon_n_vrefresh; - default: - if (!dummy && !validateGraphicsToken(screen->validTokens, token)) - { - xf86ConfigError("Screen section keyword expected"); - } - break; + /* + * first we collect the mode lines from the UseModes directive + */ + while(modeslnk) + { + modes = xf86findModes (modeslnk->ml_modes_str, + xf86configptr->conf_modes_lst); + modeslnk->ml_modes = modes; + + + /* now add the modes found in the modes + section to the list of modes for this + monitor unless it has been added before + because we are reusing the same section + for another screen */ + if (xf86itemNotSublist( + (GenericListPtr)conf_monitor->mon_modeline_lst, + (GenericListPtr)modes->mon_modeline_lst)) { + conf_monitor->mon_modeline_lst = (XF86ConfModeLinePtr) + xf86addListItem( + (GenericListPtr)conf_monitor->mon_modeline_lst, + (GenericListPtr)modes->mon_modeline_lst); + } + modeslnk = modeslnk->list.next; } - } - if (!dummy) { - if (dispList == NULL) { - FatalError( - "A \"Display\" subsection is required in each \"Screen\" section\n"); - } else { - /* Work out which if any Display subsection to use based on depth */ - if (xf86bpp < 0) { - /* - * no -bpp option given, so take depth if only one Display subsection - * Don't do this for VGA2 and VGA16 where it makes no sense, and only - * causes problems - */ - if (numDisps == 1) { -#ifndef XF86SETUP - if (dispList[0].depth > 0 - && !(driverno >= VGA2 && driverno <= VGA16)) { - xf86bpp = dispList[0].depth; - } -#endif - dispIndex = 0; - } else { - xf86bpp = screen->depth; - /* Look for a section which matches the driver's default depth */ - for (dispIndex = 0; dispIndex < numDisps; dispIndex++) { - if (dispList[dispIndex].depth == screen->depth) - break; - } - if (dispIndex == numDisps) { - /* No match. This time, allow 15/16 and 24/32 to match */ - for (dispIndex = 0; dispIndex < numDisps; dispIndex++) { - if ((screen->depth == 15 && dispList[dispIndex].depth == 16) || - (screen->depth == 16 && dispList[dispIndex].depth == 15) || - (screen->depth == 24 && dispList[dispIndex].depth == 32) || - (screen->depth == 32 && dispList[dispIndex].depth == 24)) - break; - } - } - if (dispIndex == numDisps) { - /* Still no match, so exit */ - FatalError("No \"Display\" subsection for default depth %d\n", - screen->depth); - } + /* + * we need to hook in the mode lines now + * here both data structures use lists, only our internal one + * is double linked + */ + cmodep = conf_monitor->mon_modeline_lst; + while( cmodep ) { + mode = xnfalloc(sizeof(DisplayModeRec)); + memset(mode,'\0',sizeof(DisplayModeRec)); + mode->type = 0; + mode->Clock = cmodep->ml_clock; + mode->HDisplay = cmodep->ml_hdisplay; + mode->HSyncStart = cmodep->ml_hsyncstart; + mode->HSyncEnd = cmodep->ml_hsyncend; + mode->HTotal = cmodep->ml_htotal; + mode->VDisplay = cmodep->ml_vdisplay; + mode->VSyncStart = cmodep->ml_vsyncstart; + mode->VSyncEnd = cmodep->ml_vsyncend; + mode->VTotal = cmodep->ml_vtotal; + mode->Flags = cmodep->ml_flags; + mode->HSkew = cmodep->ml_hskew; + mode->VScan = cmodep->ml_vscan; + mode->name = xnfstrdup(cmodep->ml_identifier); + if( last ) { + mode->prev = last; + last->next = mode; } - } else { - /* xf86bpp is set */ - if (numDisps == 1 && dispList[0].depth < 0) { - /* one Display subsection, no depth set, so use it */ - /* XXXX Maybe should only do this when xf86bpp == default depth?? */ - dispIndex = 0; - } else { - /* find Display subsection matching xf86bpp */ - for (dispIndex = 0; dispIndex < numDisps; dispIndex++) { - if (dispList[dispIndex].depth == xf86bpp) - break; - } - if (dispIndex == numDisps) { -#if 0 - /* No match. This time, allow 15/16 and 24/32 to match */ - for (dispIndex = 0; dispIndex < numDisps; dispIndex++) { - if ((xf86bpp == 15 && dispList[dispIndex].depth == 16) || - (xf86bpp == 16 && dispList[dispIndex].depth == 15) || - (xf86bpp == 24 && dispList[dispIndex].depth == 32) || - (xf86bpp == 32 && dispList[dispIndex].depth == 24)) - break; -#else - /* No match. This time, allow 15/16 to match */ - for (dispIndex = 0; dispIndex < numDisps; dispIndex++) { - if ((xf86bpp == 15 && dispList[dispIndex].depth == 16) || - (xf86bpp == 16 && dispList[dispIndex].depth == 15)) - break; -#endif - } - } - if (dispIndex == numDisps) { - if (!(driverno >= VGA2 && driverno <= VGA16)) { - /* Still no match, so exit */ - FatalError("No \"Display\" subsection for -bpp depth %d\n", - xf86bpp); - } - else - dispIndex = 0; - } + else { + /* + * this is the first mode + */ + monitorp->Modes = mode; + mode->prev = NULL; } - } - /* Now copy the info across to the screen rec */ - dispp = dispList + dispIndex; - if (xf86bpp > 0) screen->depth = xf86bpp; - else if (dispp->depth > 0) screen->depth = dispp->depth; - if (xf86weight.red || xf86weight.green || xf86weight.blue) - screen->weight = xf86weight; - else if (dispp->weight.red > 0) { - screen->weight = dispp->weight; - xf86weight = dispp->weight; - } - screen->frameX0 = dispp->frameX0; - screen->frameY0 = dispp->frameY0; - screen->virtualX = dispp->virtualX; - screen->virtualY = dispp->virtualY; - screen->modes = dispp->modes; - screen->whiteColour = dispp->whiteColour; - screen->blackColour = dispp->blackColour; - screen->defaultVisual = dispp->defaultVisual; - /* Add any new options that might be set */ - for (i = 0; i < MAX_OFLAGS; i++) { - if (OFLG_ISSET(i, &(dispp->options))) - OFLG_SET(i, &(screen->options)); - if (OFLG_ISSET(i, &(dispp->xconfigFlag))) - OFLG_SET(i, &(screen->xconfigFlag)); - } - screen->DCOptions = xf86DCConcatOption(screen->DCOptions,dispp->DCOptions); -#ifdef XF86SETUP - xf86setup_scrn_ndisps[driverno-SVGA] = numDisps; - xf86setup_scrn_displays[driverno-SVGA] = dispList; -#else - /* Don't need them any more */ - xfree(dispList); -#endif + last = mode; + cmodep = (XF86ConfModeLinePtr)cmodep->list.next; } - - /* Maybe these should be FatalError() instead? */ - if ( !had_monitor ) { - xf86ConfigError("A screen must specify a monitor"); + if(last){ + last->next = NULL; } - if ( !had_device ) { - xf86ConfigError("A screen must specify a device"); + monitorp->Last = last; + + /* add the (VESA) default modes */ + if (! addDefaultModes(monitorp) ) + return FALSE; + + if (conf_monitor->mon_gamma_red > GAMMA_ZERO) + monitorp->gamma.red = conf_monitor->mon_gamma_red; + if (conf_monitor->mon_gamma_green > GAMMA_ZERO) + monitorp->gamma.green = conf_monitor->mon_gamma_green; + if (conf_monitor->mon_gamma_blue > GAMMA_ZERO) + monitorp->gamma.blue = conf_monitor->mon_gamma_blue; + + /* Check that the gamma values are within range */ + if (monitorp->gamma.red > GAMMA_ZERO && + (monitorp->gamma.red < GAMMA_MIN || + monitorp->gamma.red > GAMMA_MAX)) { + badgamma = monitorp->gamma.red; + } else if (monitorp->gamma.green > GAMMA_ZERO && + (monitorp->gamma.green < GAMMA_MIN || + monitorp->gamma.green > GAMMA_MAX)) { + badgamma = monitorp->gamma.green; + } else if (monitorp->gamma.blue > GAMMA_ZERO && + (monitorp->gamma.blue < GAMMA_MIN || + monitorp->gamma.blue > GAMMA_MAX)) { + badgamma = monitorp->gamma.blue; + } + if (badgamma > GAMMA_ZERO) { + xf86ConfigError("Gamma value %.f is out of range (%.2f - %.1f)\n", + badgamma, GAMMA_MIN, GAMMA_MAX); + return FALSE; } - } - /* Check for information that must be specified in XF86Config */ - if (scr_index >= 0 && xf86Screens[scr_index]) - { - ScrnInfoPtr driver = xf86Screens[scr_index]; + return TRUE; +} - graphFound = TRUE; +static int +lookupVisual(const char *visname) +{ + int i; - if (driver->clockprog && !driver->clocks) - { - if (!OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(screen->clockOptions))){ - ErrorF("%s: No clock line specified: assuming programmable clocks\n"); - OFLG_SET(CLOCK_OPTION_PROGRAMABLE, &(screen->clockOptions));} - driver->textclock = textClockValue; - } + if (!visname || !*visname) + return -1; - /* Find the Index of the Text Clock for the ClockProg */ - if (driver->clockprog && textClockValue > 0 - && !OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(screen->clockOptions))) - { - driver->textclock = xf86GetNearestClock(driver, textClockValue); - if (abs(textClockValue - driver->clock[driver->textclock]) > - CLOCK_TOLERANCE) - FatalError( - "There is no defined dot-clock matching the text clock\n"); - if (xf86Verbose) - ErrorF("%s %s: text clock = %7.3f, clock used = %7.3f\n", - XCONFIG_GIVEN, - driver->name, textClockValue / 1000.0, - driver->clock[driver->textclock] / 1000.0); - } - if (xf86Verbose && driver->defaultVisual > 0) { - char *visualname; - switch (driver->defaultVisual) { - case StaticGray: - case GrayScale: - case StaticColor: - case PseudoColor: - case TrueColor: - case DirectColor: - visualname = xf86VisualNames[driver->defaultVisual]; - break; - default: - xf86ConfigError("unknown visual type"); - } - ErrorF("%s %s: Default visual: %s\n", XCONFIG_GIVEN, driver->name, - visualname); + for (i = 0; i <= DirectColor; i++) { + if (!xf86nameCompare(visname, xf86VisualNames[i])) + break; } - if (defaultColorVisualClass < 0) - defaultColorVisualClass = driver->defaultVisual; - /* GJA --Moved these from the device code. Had to reorganize it - * a bit. - */ - if (xf86Verbose) { - if (OFLG_ISSET(XCONFIG_IOBASE, &driver->xconfigFlag)) - ErrorF("%s %s: Direct Access Register I/O Base Address: %x\n", - XCONFIG_GIVEN, driver->name, driver->IObase); - - if (OFLG_ISSET(XCONFIG_DACBASE, &driver->xconfigFlag)) - ErrorF("%s %s: DAC Base I/O Address: %x\n", - XCONFIG_GIVEN, driver->name, driver->DACbase); - - if (OFLG_ISSET(XCONFIG_COPBASE, &driver->xconfigFlag)) - ErrorF("%s %s: Coprocessor Base Memory Address: %x\n", - XCONFIG_GIVEN, driver->name, driver->COPbase); - - if (OFLG_ISSET(XCONFIG_POSBASE, &driver->xconfigFlag)) - ErrorF("%s %s: POS Base Address: %x\n", XCONFIG_GIVEN, driver->name, - driver->POSbase); - - if (OFLG_ISSET(XCONFIG_BIOSBASE, &driver->xconfigFlag)) - ErrorF("%s %s: BIOS Base Address: %x\n", XCONFIG_GIVEN, driver->name, - driver->BIOSbase); - - if (OFLG_ISSET(XCONFIG_MEMBASE, &driver->xconfigFlag)) - ErrorF("%s %s: Memory Base Address: %x\n", XCONFIG_GIVEN, - driver->name, driver->MemBase); - - if (OFLG_ISSET(XCONFIG_VGABASE, &driver->xconfigFlag)) - ErrorF("%s %s: VGA Aperture Base Address: %x\n", XCONFIG_GIVEN, - driver->name, driver->VGAbase); - - /* Print clock program */ - if ( driver->clockprog ) { - ErrorF("%s %s: ClockProg: \"%s\"", XCONFIG_GIVEN, driver->name, - driver->clockprog); - if ( textClockValue ) - ErrorF(", Text Clock: %7.3f\n", textClockValue / 1000.0); - ErrorF("\n"); - } - } - } -#ifdef NEED_RETURN_VALUE - return RET_OKAY; -#endif + if (i <= DirectColor) + return i; + + return -1; } -static CONFIG_RETURN_TYPE -configDisplaySubsection(disp) -DispPtr disp; + +static Bool +configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display) { - int token; - int i; - - while ((token = xf86GetToken(DisplayTab)) != ENDSUBSECTION) { - switch (token) { - case DEPTH: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Display depth expected"); - disp->depth = val.num; - break; - - case WEIGHT: - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Display weight expected"); - if (val.num > 9) { - disp->weight.red = (val.num / 100) % 10; - disp->weight.green = (val.num / 10) % 10; - disp->weight.blue = val.num % 10; - } else { - disp->weight.red = val.num; - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Display weight expected"); - disp->weight.green = val.num; - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Display weight expected"); - disp->weight.blue = val.num; - } - break; - - case VIEWPORT: - OFLG_SET(XCONFIG_VIEWPORT,&(disp->xconfigFlag)); - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Viewport X expected"); - disp->frameX0 = val.num; - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Viewport Y expected"); - disp->frameY0 = val.num; - break; - - case VIRTUAL: - OFLG_SET(XCONFIG_VIRTUAL,&(disp->xconfigFlag)); - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Virtual X expected"); - disp->virtualX = val.num; - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Virtual Y expected"); - disp->virtualY = val.num; - break; - - case MODES: - for (pLast=NULL; (token = xf86GetToken(NULL)) == STRING; pLast = pNew) - { - pNew = (DisplayModePtr)xalloc(sizeof(DisplayModeRec)); - pNew->name = val.str; - pNew->PrivSize = 0; - pNew->Private = NULL; - - if (pLast) - { - pLast->next = pNew; - pNew->prev = pLast; - } - else - disp->modes = pNew; - } - /* Make sure at least one mode was present */ - if (!pLast) - xf86ConfigError("Mode name expected"); - pNew->next = disp->modes; - disp->modes->prev = pLast; - pushToken = token; - break; - - case BLACK: - case WHITE: - { - unsigned char rgb[3]; - int ii; - - for (ii = 0; ii < 3; ii++) - { - if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("RGB value expected"); - rgb[ii] = val.num & 0x3F; - } - if (token == BLACK) - { - disp->blackColour.red = rgb[0]; - disp->blackColour.green = rgb[1]; - disp->blackColour.blue = rgb[2]; - } - else - { - disp->whiteColour.red = rgb[0]; - disp->whiteColour.green = rgb[1]; - disp->whiteColour.blue = rgb[2]; - } - } - break; - - case VISUAL: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Visual name expected"); - token = getStringToken(VisualTab); - if (!dummy && disp->defaultVisual >= 0) - xf86ConfigError("Only one default visual may be specified"); - disp->defaultVisual = token - STATICGRAY; - break; - - case OPTION: - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Option string expected"); - i = 0; - while (xf86_OptionTab[i].token != -1) - { - if (StrCaseCmp(val.str, xf86_OptionTab[i].name) == 0) - { - OFLG_SET(xf86_OptionTab[i].token, &(disp->options)); - break; - } - i++; - } - if (xf86_OptionTab[i].token == -1) - disp->DCOptions = xf86DCOption(disp->DCOptions,val); - break; - - /* The following should really go in the S3 server */ - case INVERTVCLK: - case BLANKDELAY: - case EARLYSC: - { - DisplayModePtr p = disp->modes; - if (xf86GetToken(NULL) != STRING) xf86ConfigError("Mode name expected"); - if (disp->modes == NULL) - xf86ConfigError("This must be after the Modes line"); - { - Bool found = FALSE; - int opt; - INT32 value; - char *mode_string = (char *)xalloc(strlen(val.str)+1); - strcpy(mode_string,val.str); - - switch (token) { - default: /* pacify compiler (uninitialized opt, value) */ - case INVERTVCLK: - if (xf86GetToken(NULL) != NUMBER || val.num < 0 || val.num > 1) - xf86ConfigError("0 or 1 expected"); - opt = S3_INVERT_VCLK; - value = val.num; - break; - - case BLANKDELAY: - if (xf86GetToken(NULL) != NUMBER || val.num < 0 || val.num > 7) - xf86ConfigError("number(s) 0..7 expected"); - opt = S3_BLANK_DELAY; - value = val.num; - if ((token=xf86GetToken(NULL)) == NUMBER) { - if (val.num < 0 || val.num > 7) - xf86ConfigError("number2 0..7 expected"); - value |= val.num << 4; - } - else pushToken = token; - break; - - case EARLYSC: - if (xf86GetToken(NULL) != NUMBER || val.num < 0 || val.num > 1) - xf86ConfigError("0 or 1 expected"); - opt = S3_EARLY_SC; - value = val.num; - break; - } - - do { - if (strcmp(p->name, mode_string) == 0 - || strcmp("*", mode_string) == 0) { - found = TRUE; - if (!p->PrivSize || !p->Private) { - p->PrivSize = S3_MODEPRIV_SIZE; - p->Private = (INT32 *)Xcalloc(sizeof(INT32) * S3_MODEPRIV_SIZE); - p->Private[0] = 0; - } - p->Private[0] |= (1 << opt); - p->Private[opt] = value; - } - p = p->next; - } while (p != disp->modes); - if (!found) xf86ConfigError("No mode of that name in the Modes line"); - xfree(mode_string); - } - } - break; + int count = 0; + XF86ModePtr modep; + displayp->frameX0 = conf_display->disp_frameX0; + displayp->frameY0 = conf_display->disp_frameY0; + displayp->virtualX = conf_display->disp_virtualX; + displayp->virtualY = conf_display->disp_virtualY; + displayp->depth = conf_display->disp_depth; + displayp->fbbpp = conf_display->disp_bpp; + displayp->weight.red = conf_display->disp_weight.red; + displayp->weight.green = conf_display->disp_weight.green; + displayp->weight.blue = conf_display->disp_weight.blue; + displayp->blackColour.red = conf_display->disp_black.red; + displayp->blackColour.green = conf_display->disp_black.green; + displayp->blackColour.blue = conf_display->disp_black.blue; + displayp->whiteColour.red = conf_display->disp_white.red; + displayp->whiteColour.green = conf_display->disp_white.green; + displayp->whiteColour.blue = conf_display->disp_white.blue; + displayp->options = conf_display->disp_option_lst; + if (conf_display->disp_visual) { + displayp->defaultVisual = lookupVisual(conf_display->disp_visual); + if (displayp->defaultVisual == -1) { + xf86ConfigError("Invalid visual name: \"%s\"", + conf_display->disp_visual); + return FALSE; + } + } else { + displayp->defaultVisual = -1; + } + + /* + * now hook in the modes + */ + modep = conf_display->disp_mode_lst; + while(modep) { + count++; + modep = (XF86ModePtr)modep->list.next; + } + displayp->modes = xnfalloc((count+1) * sizeof(char*)); + modep = conf_display->disp_mode_lst; + count = 0; + while(modep) { + displayp->modes[count] = modep->mode_name; + count++; + modep = (XF86ModePtr)modep->list.next; + } + displayp->modes[count] = NULL; - case EOF: - FatalError("Unexpected EOF (missing EndSubSection)"); - break; /* :-) */ + return TRUE; +} - default: - xf86ConfigError("Display subsection keyword expected"); - break; +static Bool +configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, Bool active) +{ + int i; + + if (active) + xf86Msg(X_CONFIG, "| |-->Device \"%s\"\n", + conf_device->dev_identifier); + else + xf86Msg(X_CONFIG, "|-->Inactive Device \"%s\"\n", + conf_device->dev_identifier); + + devicep->identifier = conf_device->dev_identifier; + devicep->vendor = conf_device->dev_vendor; + devicep->board = conf_device->dev_board; + devicep->chipset = conf_device->dev_chipset; + devicep->ramdac = conf_device->dev_ramdac; + devicep->driver = conf_device->dev_driver; + devicep->active = active; + devicep->videoRam = conf_device->dev_videoram; + devicep->BiosBase = conf_device->dev_bios_base; + devicep->MemBase = conf_device->dev_mem_base; + devicep->IOBase = conf_device->dev_io_base; + devicep->clockchip = conf_device->dev_clockchip; + devicep->busID = conf_device->dev_busid; + devicep->textClockFreq = conf_device->dev_textclockfreq; + devicep->chipID = conf_device->dev_chipid; + devicep->chipRev = conf_device->dev_chiprev; + devicep->options = conf_device->dev_option_lst; + devicep->irq = conf_device->dev_irq; + devicep->screen = conf_device->dev_screen; + + for (i = 0; i < MAXDACSPEEDS; i++) { + if (i < CONF_MAXDACSPEEDS) + devicep->dacSpeeds[i] = conf_device->dev_dacSpeeds[i]; + else + devicep->dacSpeeds[i] = 0; } - } -#ifdef NEED_RETURN_VALUE - return RET_OKAY; -#endif + devicep->numclocks = conf_device->dev_clocks; + if (devicep->numclocks > MAXCLOCKS) + devicep->numclocks = MAXCLOCKS; + for (i = 0; i < devicep->numclocks; i++) { + devicep->clock[i] = conf_device->dev_clock[i]; + } + devicep->claimed = FALSE; + + return TRUE; } -Bool -xf86LookupMode(target, driver, flags) - DisplayModePtr target; - ScrnInfoPtr driver; - int flags; +#ifdef XF86DRI +static Bool +configDRI(XF86ConfDRIPtr drip) { - DisplayModePtr p; - DisplayModePtr best_mode = NULL; - int i, j, k, Gap; - int Minimum_Gap = CLOCK_TOLERANCE + 1; - Bool found_mode = FALSE; - Bool clock_too_high = FALSE; - static Bool first_time = TRUE; - double refresh, bestRefresh = 0.0; - - if (first_time) - { - ErrorF("%s %s: Maximum allowed dot-clock: %1.3f MHz\n", XCONFIG_PROBED, - driver->name, driver->maxClock / 1000.0); - first_time = FALSE; - /* - * First time through, cull modes which are not valid for the - * card/driver. - */ - driver->monitor->Modes = xf86PruneModes(NULL, driver->monitor->Modes, - driver, TRUE); - } - - if (xf86BestRefresh && !(flags & LOOKUP_FORCE_DEFAULT)) - flags |= LOOKUP_BEST_REFRESH; + int count = 0; + XF86ConfBuffersPtr bufs; + int i; + struct group *grp; + + xf86ConfigDRI.group = -1; + xf86ConfigDRI.mode = 0; + xf86ConfigDRI.bufs_count = 0; + xf86ConfigDRI.bufs = NULL; + + if (drip) { + if (drip->dri_group_name) { + if ((grp = getgrnam(drip->dri_group_name))) + xf86ConfigDRI.group = grp->gr_gid; + } else { + if (drip->dri_group >= 0) + xf86ConfigDRI.group = drip->dri_group; + } + xf86ConfigDRI.mode = drip->dri_mode; + for (bufs = drip->dri_buffers_lst; bufs; bufs = bufs->list.next) + ++count; + + xf86ConfigDRI.bufs_count = count; + xf86ConfigDRI.bufs = xnfalloc(count * sizeof(*xf86ConfigDRI.bufs)); + + for (i = 0, bufs = drip->dri_buffers_lst; + i < count; + i++, bufs = bufs->list.next) { + + xf86ConfigDRI.bufs[i].count = bufs->buf_count; + xf86ConfigDRI.bufs[i].size = bufs->buf_size; + /* FIXME: Flags not implemented. These + could be used, for example, to specify a + contiguous block and/or write-combining + cache policy. */ + xf86ConfigDRI.bufs[i].flags = 0; + } + } - for (p = driver->monitor->Modes; p != NULL; p = p->next) /* scan list */ - { - if (!strcmp(p->name, target->name)) /* names equal ? */ - { - /* First check if the driver objects to the mode */ - if ((driver->ValidMode)(p, xf86Verbose, MODE_USED) != MODE_OK) - { - ErrorF("%s %s: Mode \"%s\" rejected by driver. Deleted.\n", - XCONFIG_PROBED,driver->name, target->name ); - break; - } + return TRUE; +} +#endif - if ((flags & LOOKUP_NO_INTERLACED) && (p->Flags & V_INTERLACE)) - { - continue; - } +static Bool +configInput(IDevPtr inputp, XF86ConfInputPtr conf_input, MessageType from) +{ + xf86Msg(from, "|-->Input Device \"%s\"\n", conf_input->inp_identifier); + inputp->identifier = conf_input->inp_identifier; + inputp->driver = conf_input->inp_driver; + inputp->commonOptions = conf_input->inp_option_lst; + inputp->extraOptions = NULL; - if ((OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(driver->clockOptions))) && - !OFLG_ISSET(OPTION_NO_PROGRAM_CLOCKS, &(driver->options))) - { - if (driver->clocks == 0) - { - /* this we know */ - driver->clock[0] = 25175; /* 25.175Mhz */ - driver->clock[1] = 28322; /* 28.322MHz */ - driver->clocks = 2; - } + /* XXX This is required until the keyboard driver is converted */ + if (!xf86NameCmp(inputp->driver, "keyboard")) + return configInputKbd(inputp); - if ((p->Clock / 1000) > (driver->maxClock / 1000)) - clock_too_high = TRUE; - else - { - /* We fill in the the programmable clocks as we go */ - for (i=0; i < driver->clocks; i++) - if (driver->clock[i] == p->Clock) - break; - - if (i >= MAXCLOCKS) - { - ErrorF("%s %s: Too many programmable clocks used (limit %d)!\n", - XCONFIG_PROBED, driver->name, MAXCLOCKS); - return FALSE; - } - - if (i == driver->clocks) - { - driver->clock[i] = p->Clock; - driver->clocks++; - } - - - if (flags & LOOKUP_BEST_REFRESH) - { - refresh = p->Clock * 1000.0 / p->HTotal / p->VTotal; - if (p->Flags & V_INTERLACE) - { - refresh *= 2; - refresh /= INTERLACE_REFRESH_WEIGHT; - } - else if (p->Flags & V_DBLSCAN) - { - refresh /= 2; - } - if (refresh > bestRefresh) - { - best_mode = p; - bestRefresh = refresh; - target->Clock = i; - } - } - else - { - target->Clock = i; - best_mode = p; - } - } - } - else - { - /* - * go look if any of the clocks in the list matches the one in - * the mode (j=1), or if a better match exists when the clocks - * in the list are divided by 2 (j=2) - */ - if (OFLG_ISSET(OPTION_CLKDIV2, &(driver->options))) - k=2; - else - k=1; - for (j=1 ; j<=k ; j++) - { - i = xf86GetNearestClock(driver, p->Clock*j); - if (flags & LOOKUP_BEST_REFRESH) - { - if ( ((driver->clock[i]/j) / 1000) > (driver->maxClock / 1000) ) - clock_too_high = TRUE; - else - { - refresh = p->Clock * 1000.0 / p->HTotal / p->VTotal; - if (p->Flags & V_INTERLACE) - { - refresh *= 2; - refresh /= INTERLACE_REFRESH_WEIGHT; - } - else if (p->Flags & V_DBLSCAN) - { - refresh /= 2; - } - if (refresh > bestRefresh) - { - target->Clock = i; - if (j==2) p->Flags |= V_CLKDIV2; - best_mode = p; - bestRefresh = refresh; - } - } - } - else - { - Gap = abs( p->Clock - (driver->clock[i]/j) ); - if (Gap < Minimum_Gap) - { - if ( ((driver->clock[i]/j) / 1000) > (driver->maxClock / 1000) ) - clock_too_high = TRUE; - else - { - target->Clock = i; - if (j==2) p->Flags |= V_CLKDIV2; - best_mode = p; - Minimum_Gap = Gap; - } - } - } - } - } - found_mode = TRUE; - } - } + return TRUE; +} + +static Bool +modeIsPresent(char * modename,MonPtr monitorp) +{ + DisplayModePtr knownmodes = monitorp->Modes; - if (best_mode != NULL) - { - target->HDisplay = best_mode->HDisplay; - target->HSyncStart = best_mode->HSyncStart; - target->HSyncEnd = best_mode->HSyncEnd; - target->HTotal = best_mode->HTotal; - target->HSkew = best_mode->HSkew; - target->VDisplay = best_mode->VDisplay; - target->VSyncStart = best_mode->VSyncStart; - target->VSyncEnd = best_mode->VSyncEnd; - target->VTotal = best_mode->VTotal; - target->Flags = best_mode->Flags; - target->CrtcHDisplay = best_mode->CrtcHDisplay; - target->CrtcHSyncStart = best_mode->CrtcHSyncStart; - target->CrtcHSyncEnd = best_mode->CrtcHSyncEnd; - target->CrtcHTotal = best_mode->CrtcHTotal; - target->CrtcHSkew = best_mode->CrtcHSkew; - target->CrtcVDisplay = best_mode->CrtcVDisplay; - target->CrtcVSyncStart = best_mode->CrtcVSyncStart; - target->CrtcVSyncEnd = best_mode->CrtcVSyncEnd; - target->CrtcVTotal = best_mode->CrtcVTotal; - target->CrtcHAdjusted = best_mode->CrtcHAdjusted; - target->CrtcVAdjusted = best_mode->CrtcVAdjusted; - if (target->Flags & V_DBLSCAN) + /* all I can think of is a linear search... */ + while(knownmodes != NULL) { - target->CrtcVDisplay *= 2; - target->CrtcVSyncStart *= 2; - target->CrtcVSyncEnd *= 2; - target->CrtcVTotal *= 2; - target->CrtcVAdjusted = TRUE; + if(!strcmp(modename,knownmodes->name) && + !(knownmodes->type & M_T_DEFAULT)) + return TRUE; + knownmodes = knownmodes->next; } + return FALSE; +} -#if 0 - /* I'm not sure if this is the best place for this in the - * new XF86Config organization. - SRA - */ - if (found_mode) - if ((driver->ValidMode)(target, xf86Verbose, MODE_USED) != MODE_OK) - { - ErrorF("%s %s: Unable to support mode \"%s\"\n", - XCONFIG_GIVEN,driver->name, target->name ); - return(FALSE); - } -#endif +static Bool +addDefaultModes(MonPtr monitorp) +{ + DisplayModePtr mode; + DisplayModePtr last = monitorp->Last; + int i = 0; - if (xf86Verbose) + while (xf86DefaultModes[i].name != NULL) { - ErrorF("%s %s: Mode \"%s\": mode clock = %7.3f", - XCONFIG_GIVEN, driver->name, target->name, - best_mode->Clock / 1000.0); - if (!OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(driver->clockOptions)) || - OFLG_ISSET(OPTION_NO_PROGRAM_CLOCKS, &(driver->options))) { - ErrorF(", clock used = %7.3f", driver->clock[target->Clock] / 1000.0); - if (target->Flags & V_CLKDIV2) - ErrorF("/2"); - } - ErrorF("\n"); + if ( ! modeIsPresent(xf86DefaultModes[i].name,monitorp) ) + do + { + mode = xnfalloc(sizeof(DisplayModeRec)); + memcpy(mode,&xf86DefaultModes[i],sizeof(DisplayModeRec)); + if (xf86DefaultModes[i].name) + mode->name = xnfstrdup(xf86DefaultModes[i].name); + if( last ) { + mode->prev = last; + last->next = mode; + } + else { + /* this is the first mode */ + monitorp->Modes = mode; + mode->prev = NULL; + } + last = mode; + i++; + } + while((xf86DefaultModes[i].name != NULL) && + (!strcmp(xf86DefaultModes[i].name,xf86DefaultModes[i-1].name))); + else + i++; } - } - else if (!found_mode) - ErrorF("%s %s: There is no mode definition named \"%s\"\n", - XCONFIG_PROBED, driver->name, target->name); - else if (clock_too_high) - ErrorF("%s %s: Clock for mode \"%s\" %s\n\tLimit is %7.3f MHz\n", - XCONFIG_PROBED, driver->name, target->name, - "is too high for the configured hardware.", - driver->maxClock / 1000.0); - else - ErrorF("%s %s: There is no defined dot-clock matching mode \"%s\"\n", - XCONFIG_PROBED, driver->name, target->name); - - return (best_mode != NULL); -} + monitorp->Last = last; -void -xf86VerifyOptions(allowedOptions, driver) - OFlagSet *allowedOptions; - ScrnInfoPtr driver; -{ - int j; - - for (j=0; xf86_OptionTab[j].token >= 0; j++) - if ((OFLG_ISSET(xf86_OptionTab[j].token, &driver->options))) - if (OFLG_ISSET(xf86_OptionTab[j].token, allowedOptions)) - { - if (xf86Verbose) - ErrorF("%s %s: Option \"%s\"\n", XCONFIG_GIVEN, - driver->name, xf86_OptionTab[j].name); - } - else - ErrorF("%s %s: Option flag \"%s\" is not defined for this driver\n", - XCONFIG_GIVEN, driver->name, xf86_OptionTab[j].name); + return TRUE; } -/* Note: (To keep me [GJA] from getting confused) - * We have two mode-related datastructures: - * 1. A doubly linked mode name list, with ends marked by self-pointers. - * 2. A doubly linked mode structure list. - * We are operating here on the second structure. - * Initially this is just singly linked. +/* + * load the config file and fill the global data structure */ -static DisplayModePtr -xf86PruneModes(monp, allmodes, scrp, card) - MonPtr monp; /* Monitor specification */ - DisplayModePtr allmodes; /* List to be pruned */ - ScrnInfoPtr scrp; - Bool card; /* TRUE => do driver validity check */ +Bool +xf86HandleConfigFile(void) { - DisplayModePtr dispmp; /* To walk the list */ - DisplayModePtr olddispmp; /* The one being freed. */ - DisplayModePtr remainder; /* The first one retained. */ + const char *filename; + char *searchpath; + MessageType from = X_DEFAULT; - dispmp = allmodes; + if (getuid() == 0) + searchpath = ROOT_CONFIGPATH; + else + searchpath = USER_CONFIGPATH; - /* The first modes to be deleted require that the pointer to the - * mode list is updated. Also, they have no predecessor in the list. - */ - while (dispmp && - (card ? - ((scrp->ValidMode)(dispmp, xf86Verbose, MODE_SUGGESTED) - != MODE_OK) : - (xf86CheckMode(scrp, dispmp, monp, xf86Verbose) != MODE_OK))) { - olddispmp = dispmp; - dispmp = dispmp->next; - xfree(olddispmp->name); - xfree(olddispmp); - } - /* Now we either have a mode that fits, or no mode at all */ - if ( ! dispmp ) { /* No mode at all */ - return NULL; - } - remainder = dispmp; - while ( dispmp->next ) { - if (card ? - ((scrp->ValidMode)(dispmp->next,xf86Verbose,MODE_SUGGESTED) - != MODE_OK) : - (xf86CheckMode(scrp, dispmp->next, monp, xf86Verbose) != - MODE_OK)) { - olddispmp = dispmp->next; - dispmp->next = dispmp->next->next; - xfree(olddispmp->name); - xfree(olddispmp); - } else { - dispmp = dispmp->next; - } - } - return remainder; /* Return pointer to {the first / the list } */ -} + if (xf86ConfigFile) + from = X_CMDLINE; -/* - * Return MODE_OK if the mode pointed to by dispmp agrees with all constraints - * we can make up for the monitor pointed to by monp. - */ -int -xf86CheckMode(scrp, dispmp, monp, verbose) - ScrnInfoPtr scrp; - DisplayModePtr dispmp; - MonPtr monp; - Bool verbose; -{ - int i; - float dotclock, hsyncfreq, vrefreshrate; - char *scrname = scrp->name; - - /* Sanity checks */ - if ((0 >= dispmp->HDisplay) || - (dispmp->HDisplay > dispmp->HSyncStart) || - (dispmp->HSyncStart >= dispmp->HSyncEnd) || - (dispmp->HSyncEnd >= dispmp->HTotal)) - { - ErrorF( - "%s %s: Invalid horizontal timing for mode \"%s\". Deleted.\n", - XCONFIG_PROBED, scrname, dispmp->name); - return MODE_HSYNC; - } + filename = xf86openConfigFile(searchpath, xf86ConfigFile, PROJECTROOT); + if (filename) { + xf86MsgVerb(from, 0, "Using config file: \"%s\"\n", filename); + xf86ConfigFile = xnfstrdup(filename); + } else { + xf86Msg(X_ERROR, "Unable to locate/open config file"); + if (xf86ConfigFile) + xf86ErrorFVerb(0, ": \"%s\"", xf86ConfigFile); + xf86ErrorFVerb(0, "\n"); + return FALSE; + } + if ((xf86configptr = xf86readConfigFile ()) == NULL) { + xf86Msg(X_ERROR, "Problem parsing the config file\n"); + return FALSE; + } + xf86closeConfigFile (); - if ((0 >= dispmp->VDisplay) || - (dispmp->VDisplay > dispmp->VSyncStart) || - (dispmp->VSyncStart >= dispmp->VSyncEnd) || - (dispmp->VSyncEnd >= dispmp->VTotal)) - { - ErrorF( - "%s %s: Invalid vertical timing for mode \"%s\". Deleted.\n", - XCONFIG_PROBED, scrname, dispmp->name); - return MODE_VSYNC; - } + /* Initialise a few things. */ - /* Deal with the dispmp->Clock being a frequency or index */ - if (dispmp->Clock > MAXCLOCKS) { - dotclock = (float)dispmp->Clock; - } else { - dotclock = (float)scrp->clock[dispmp->Clock]; + /* + * now we convert part of the information contained in the parser + * structures into our own structures. + * The important part here is to figure out which Screen Sections + * in the XF86Config file are active so that we can piece together + * the modes that we need later down the road. + * And while we are at it, we'll decode the rest of the stuff as well + */ + + /* First check if a layout section is present, and if it is valid. */ + + if (xf86configptr->conf_layout_lst == NULL || xf86ScreenName != NULL) { + if (xf86ScreenName == NULL) { + xf86Msg(X_WARNING, + "No Layout section. Using the first Screen section.\n"); } - hsyncfreq = dotclock / (float)(dispmp->HTotal); - for ( i = 0 ; i < monp->n_hsync ; i++ ) - if ( (hsyncfreq > 0.999 * monp->hsync[i].lo) && - (hsyncfreq < 1.001 * monp->hsync[i].hi) ) - break; /* In range. */ - - /* Now see whether we ran out of sync frequencies */ - if ( i == monp->n_hsync ) { - if (verbose) { - ErrorF( - "%s %s: Mode \"%s\" needs hsync freq of %.2f kHz. Deleted.\n", - XCONFIG_PROBED, scrname, dispmp->name, hsyncfreq); - } - return MODE_HSYNC; + if (!configImpliedLayout(&xf86ConfigLayout, + xf86configptr->conf_screen_lst)) { + xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); + return FALSE; } - - vrefreshrate = dotclock * 1000.0 / - ((float)(dispmp->HTotal) * (float)(dispmp->VTotal)) ; - if ( dispmp->Flags & V_INTERLACE ) vrefreshrate *= 2.0; - if ( dispmp->Flags & V_DBLSCAN ) vrefreshrate /= 2.0; - for ( i = 0 ; i < monp->n_vrefresh ; i++ ) - if ( (vrefreshrate > 0.999 * monp->vrefresh[i].lo) && - (vrefreshrate < 1.001 * monp->vrefresh[i].hi) ) - break; /* In range. */ - - /* Now see whether we ran out of refresh rates */ - if ( i == monp->n_vrefresh ) { - if (verbose) { - ErrorF( - "%s %s: Mode \"%s\" needs vert refresh rate of %.2f Hz. Deleted.\n", - XCONFIG_PROBED, scrname, dispmp->name, vrefreshrate); - } - return MODE_VSYNC; + } else { + if (xf86configptr->conf_flags != NULL) { + char *dfltlayout = NULL; + pointer optlist = xf86configptr->conf_flags->flg_option_lst; + + if (optlist && xf86FindOption(optlist, "defaultserverlayout")) + dfltlayout = xf86SetStrOption(optlist, "defaultserverlayout", NULL); + if (!configLayout(&xf86ConfigLayout, xf86configptr->conf_layout_lst, + dfltlayout)) { + xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); + return FALSE; + } + } else { + if (!configLayout(&xf86ConfigLayout, xf86configptr->conf_layout_lst, + NULL)) { + xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); + return FALSE; + } } + } - /* Interlaced modes should have an odd VTotal */ - if (dispmp->Flags & V_INTERLACE) - dispmp->CrtcVTotal = dispmp->VTotal |= 1; + /* Now process everything else */ - /* Passed every test. */ - return MODE_OK; -} + if (!configFiles(xf86configptr->conf_files) || + !configServerFlags(xf86configptr->conf_flags, + xf86ConfigLayout.options) +#ifdef XF86DRI + || !configDRI(xf86configptr->conf_dri) +#endif + ) { + ErrorF ("Problem when converting the config data structures\n"); + return FALSE; + } -/* - * Save entire line from config file in memory area, if memory area - * does not exist allocate it. Set DCerr according to value of token. - * Return address of memory area. - */ -static char *xf86DCSaveLine(DCPointer,token) - char *DCPointer; - int token; -{ - static int len = 0; /* length of memory area where to store strings */ - static int pos = 0; /* current position */ - char *currpointer; /* pointer to current position in memory area */ - static int currline; /* lineno of line currently interpreted */ - int addlen; /* len to add to pos */ - - if(DCPointer == NULL){ /* initialize */ - DCPointer = (char *)xalloc(4096); /* initial size 4kB */ - len = 4096; - strcpy(DCPointer,configPath); - pos = strlen(DCPointer) + 1; - currline = -1; /* no line yet */ - } + /* + * Handle some command line options that can override some of the + * ServerFlags settings. + */ +#ifdef XF86VIDMODE + if (xf86VidModeDisabled) + xf86Info.vidModeEnabled = FALSE; + if (xf86VidModeAllowNonLocal) + xf86Info.vidModeAllowNonLocal = TRUE; +#endif - if(configLineNo != currline) /* new line */ - { - currline = configLineNo; - addlen = strlen(configBuf) + 1 + sizeof(int); /* string + lineno */ - while ( (pos + addlen) >= len ){ /* not enough space? */ - DCPointer = (char *)xrealloc(DCPointer, (len + 4096)); - len += 4096; - } - currpointer = DCPointer + pos; /* find current position */ - memcpy(currpointer, &currline, sizeof(int)); /* Grrr unaligned ints.. */ - strcpy((currpointer + sizeof(int)),configBuf); /* store complete line*/ - pos += addlen; /* goto end */ - currpointer += addlen; - *(currpointer) = EOF; /* mark end */ - } - switch(token){ - case STRING: - case DASH: - case NUMBER: - case COMMA: - break; - case ERROR_TOKEN: /* if unknown token unset DCerr to ignore it */ - DCerr = 0; /* and subsequent STRING, DASH, NUMBER, COMMA */ - break; - default: /* set to complain if a valid token is */ - DCerr = 1; /* followed by an unwanted STRING etc. */ - } - return(DCPointer); +#ifdef XF86MISC + if (xf86MiscModInDevDisabled) + xf86Info.miscModInDevEnabled = FALSE; + if (xf86MiscModInDevAllowNonLocal) + xf86Info.miscModInDevAllowNonLocal = TRUE; +#endif + + if (xf86AllowMouseOpenFail) + xf86Info.allowMouseOpenFail = TRUE; + + return TRUE; } -/* - * Store any unknown Option strings (contained in val.str) - * in a memory are pointed to by pointer. If it doesn't - * exist allocate it and return a pointer pointing to it - */ -static char * -xf86DCOption(DCPointer, val) - char *DCPointer; - LexRec val; +/* These make the equivalent parser functions visible to the common layer. */ +Bool +xf86PathIsAbsolute(const char *path) { - static int len = 0; - static int pos = 0; - int addlen; - char *currpointer; /* current position */ - - if (DCPointer == NULL){ /* First time: initialize */ - DCPointer = (char *)xalloc(4096); /* allocate enough space */ - strcpy(DCPointer,configPath); - pos = strlen(DCPointer) + 1; - len = 4096; /* and total length */ - } - - addlen = sizeof(int) + strlen(val.str) + 1; /* token, lineno */ - while( (pos + addlen) >= len ){ /* reallocate if not enough */ - DCPointer = (char *)xrealloc(DCPointer, (len + 4096)); - len += 4096; - } - currpointer = DCPointer + pos; - *(int *)currpointer=configLineNo; - strcpy(currpointer + sizeof(int),val.str); /* store string */ - pos += addlen; - *(currpointer + addlen) = EOF; /* mark end */ - return(DCPointer); + return (xf86pathIsAbsolute(path) != 0); } -static char -* xf86DCConcatOption(Pointer1, Pointer2) -char *Pointer1; -char *Pointer2; +Bool +xf86PathIsSafe(const char *path) { - int s1 = 0; - int s2 = 0; - int s3; - char *ptmp; - - if(Pointer1) - while(*(Pointer1 + s1) != EOF){s1++;} - else if (Pointer2) - return Pointer2; - else return NULL; - if(Pointer2) - while(*(Pointer2 + s2) != EOF){s2++;} - else if (Pointer1) - return Pointer1; - else return NULL; - s3 = strlen(Pointer2) + 1; - s2 -= s3; - - Pointer1 = (char *)xrealloc(Pointer1,s1+s2+1); - ptmp = Pointer1 + s1; - Pointer2 += s3; - do{ - *ptmp = *Pointer2; - *ptmp++; - *Pointer2++; - } while(s2--); - return Pointer1; + return (xf86pathIsSafe(path) != 0); } - + diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c index 6c0943b41..1a214c4ad 100644 --- a/hw/xfree86/common/xf86Cursor.c +++ b/hw/xfree86/common/xf86Cursor.c @@ -1,27 +1,5 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Cursor.c,v 3.13 1996/12/23 06:43:22 dawes Exp $ */ -/* - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Thomas Roell not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Thomas Roell makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ -/* $Xorg: xf86Cursor.c,v 1.3 2000/08/17 19:50:29 cpqbld Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Cursor.c,v 3.35 2003/02/13 10:49:38 eich Exp $ */ +/* $XConsortium: xf86Cursor.c /main/10 1996/10/19 17:58:23 kaleb $ */ #define NEED_EVENTS #include "X.h" @@ -30,73 +8,72 @@ #include "cursor.h" #include "mipointer.h" #include "scrnintstr.h" +#include "globals.h" #include "compiler.h" #include "xf86.h" -#include "xf86Procs.h" -#ifdef XFreeXDGA -#include "Xproto.h" -#include "extnsionst.h" -#include "scrnintstr.h" -#include "servermd.h" - -#define _XF86DGA_SERVER_ -#include "extensions/xf86dgastr.h" -#endif +#include "xf86Priv.h" +#include "xf86_OSproc.h" #ifdef XINPUT -#include "xf86_Config.h" #include "XIproto.h" #include "xf86Xinput.h" #endif -/* #include "atKeynames.h" -hv- dont need that include here */ +#ifdef XFreeXDGA +#include "dgaproc.h" +#endif +typedef struct _xf86EdgeRec { + short screen; + short start; + short end; + DDXPointRec offset; + struct _xf86EdgeRec *next; +} xf86EdgeRec, *xf86EdgePtr; -static Bool xf86CursorOffScreen( -#if NeedFunctionPrototypes - ScreenPtr *pScreen, - int *x, - int *y -#endif -); -static void xf86CrossScreen( -#if NeedFunctionPrototypes - ScreenPtr pScreen, - Bool entering -#endif -); -static void xf86WrapCursor( -#if NeedFunctionPrototypes - ScreenPtr pScreen, - int x, - int y -#endif -); +typedef struct { + xf86EdgePtr left, right, up, down; +} xf86ScreenLayoutRec, *xf86ScreenLayoutPtr; + +static Bool xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y); +static void xf86CrossScreen(ScreenPtr pScreen, Bool entering); +static void xf86WarpCursor(ScreenPtr pScreen, int x, int y); + +static void xf86PointerMoved(int scrnIndex, int x, int y); -miPointerScreenFuncRec xf86PointerScreenFuncs = { +static miPointerScreenFuncRec xf86PointerScreenFuncs = { xf86CursorOffScreen, xf86CrossScreen, - xf86WrapCursor, + xf86WarpCursor, #ifdef XINPUT xf86eqEnqueue, + xf86eqSwitchScreen +#else + /* let miPointerInitialize take care of these */ + NULL, + NULL #endif }; +static xf86ScreenLayoutRec xf86ScreenLayout[MAXSCREENS]; +static Bool HardEdges; /* * xf86InitViewport -- * Initialize paning & zooming parameters, so that a driver must only * check what resolutions are possible and whether the virtual area - * is valid if specifyed. + * is valid if specified. */ void -xf86InitViewport(pScr) - ScrnInfoPtr pScr; +xf86InitViewport(ScrnInfoPtr pScr) { + + pScr->PointerMoved = xf86PointerMoved; + /* * Compute the initial Viewport if necessary */ @@ -131,163 +108,269 @@ xf86InitViewport(pScr) */ void -xf86SetViewport(pScreen, x, y) - ScreenPtr pScreen; - int x, y; +xf86SetViewport(ScreenPtr pScreen, int x, int y) { - Bool frameChanged = FALSE; ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); + (*pScr->PointerMoved)(pScreen->myNum, x, y); +} + + +static void +xf86PointerMoved(int scrnIndex, int x, int y) +{ + Bool frameChanged = FALSE; + ScrnInfoPtr pScr = xf86Screens[scrnIndex]; + /* * check wether (x,y) belongs to the visual part of the screen * if not, change the base of the displayed frame accoring */ if ( pScr->frameX0 > x) { pScr->frameX0 = x; - pScr->frameX1 = x + pScr->modes->HDisplay - 1; + pScr->frameX1 = x + pScr->currentMode->HDisplay - 1; frameChanged = TRUE ; } if ( pScr->frameX1 < x) { pScr->frameX1 = x + 1; - pScr->frameX0 = x - pScr->modes->HDisplay + 1; + pScr->frameX0 = x - pScr->currentMode->HDisplay + 1; frameChanged = TRUE ; } if ( pScr->frameY0 > y) { pScr->frameY0 = y; - pScr->frameY1 = y + pScr->modes->VDisplay - 1; + pScr->frameY1 = y + pScr->currentMode->VDisplay - 1; frameChanged = TRUE; } if ( pScr->frameY1 < y) { pScr->frameY1 = y; - pScr->frameY0 = y - pScr->modes->VDisplay + 1; + pScr->frameY0 = y - pScr->currentMode->VDisplay + 1; frameChanged = TRUE; } - if (frameChanged) (pScr->AdjustFrame)(pScr->frameX0, pScr->frameY0); + if (frameChanged && pScr->AdjustFrame != NULL) + pScr->AdjustFrame(pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0); } - -static Bool xf86ZoomLocked = FALSE; - /* * xf86LockZoom -- * Enable/disable ZoomViewport */ void -xf86LockZoom (pScreen, lock) - ScreenPtr pScreen; - Bool lock; +xf86LockZoom(ScreenPtr pScreen, Bool lock) { - /* - * pScreen is currently ignored, but may be used later to enable locking - * of individual screens. - */ - - xf86ZoomLocked = lock; + XF86SCRNINFO(pScreen)->zoomLocked = lock; } /* - * xf86ZoomViewport -- - * Reinitialize the visual part of the screen for another modes-> + * xf86SwitchMode -- + * This is called by both keyboard processing and the VidMode extension to + * set a new mode. */ -void -xf86ZoomViewport (pScreen, zoom) - ScreenPtr pScreen; - int zoom; +Bool +xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode) { - ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); + ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); + ScreenPtr pCursorScreen; + Bool Switched; + int px, py; - if (xf86ZoomLocked) - return; + if (!pScr->vtSema || !mode || !pScr->SwitchMode) + return FALSE; #ifdef XFreeXDGA - /* - * We should really send the mode change request to the DGA client and let - * it decide what to do. For now just bin the request - */ - if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectGraphics) - return; + if (DGAActive(pScr->scrnIndex)) + return FALSE; #endif - if (pScr->modes != pScr->modes->next) - { - pScr->modes = zoom > 0 ? pScr->modes->next : pScr->modes->prev; + if (mode == pScr->currentMode) + return TRUE; + + if (mode->HDisplay > pScreen->width || mode->VDisplay > pScreen->height) + return FALSE; + + pCursorScreen = miPointerCurrentScreen(); + if (pScreen == pCursorScreen) + miPointerPosition(&px, &py); + + xf86EnterServerState(SETUP); + Switched = (*pScr->SwitchMode)(pScr->scrnIndex, mode, 0); + xf86EnterServerState(OPERATING); + if (Switched) { + pScr->currentMode = mode; + + /* + * Adjust frame for new display size. + */ + if (pScreen == pCursorScreen) + pScr->frameX0 = px - (mode->HDisplay / 2) + 1; + else + pScr->frameX0 = (pScr->frameX0 + pScr->frameX1 + 1 - mode->HDisplay) / 2; + + if (pScr->frameX0 < 0) + pScr->frameX0 = 0; + + pScr->frameX1 = pScr->frameX0 + mode->HDisplay - 1; + if (pScr->frameX1 >= pScr->virtualX) { + pScr->frameX0 = pScr->virtualX - mode->HDisplay; + pScr->frameX1 = pScr->virtualX - 1; + } - if ((pScr->SwitchMode)(pScr->modes)) - { - /* - * adjust new frame for the displaysize - */ - pScr->frameX0 = (pScr->frameX1 + pScr->frameX0 -pScr->modes->HDisplay)/2; - pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1; - - if (pScr->frameX0 < 0) - { - pScr->frameX0 = 0; - pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1; - } - else if (pScr->frameX1 >= pScr->virtualX) - { - pScr->frameX0 = pScr->virtualX - pScr->modes->HDisplay; - pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1; - } - - pScr->frameY0 = (pScr->frameY1 + pScr->frameY0 - pScr->modes->VDisplay)/2; - pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1; - - if (pScr->frameY0 < 0) - { - pScr->frameY0 = 0; - pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1; - } - else if (pScr->frameY1 >= pScr->virtualY) - { - pScr->frameY0 = pScr->virtualY - pScr->modes->VDisplay; - pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1; - } + if (pScreen == pCursorScreen) + pScr->frameY0 = py - (mode->VDisplay / 2) + 1; + else + pScr->frameY0 = (pScr->frameY0 + pScr->frameY1 + 1 - mode->VDisplay) / 2; + + if (pScr->frameY0 < 0) + pScr->frameY0 = 0; + + pScr->frameY1 = pScr->frameY0 + mode->VDisplay - 1; + if (pScr->frameY1 >= pScr->virtualY) { + pScr->frameY0 = pScr->virtualY - mode->VDisplay; + pScr->frameY1 = pScr->virtualY - 1; } - else /* switch failed, so go back to old mode */ - pScr->modes = zoom > 0 ? pScr->modes->prev : pScr->modes->next; } - (pScr->AdjustFrame)(pScr->frameX0, pScr->frameY0); + if (pScr->AdjustFrame) + (*pScr->AdjustFrame)(pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0); + + if (pScreen == pCursorScreen) + xf86WarpCursor(pScreen, px, py); + + return Switched; } + +/* + * xf86ZoomViewport -- + * Reinitialize the visual part of the screen for another mode. + */ +void +xf86ZoomViewport(ScreenPtr pScreen, int zoom) +{ + ScrnInfoPtr pScr = XF86SCRNINFO(pScreen); + DisplayModePtr mode; + + if (pScr->zoomLocked || !(mode = pScr->currentMode)) + return; + + do { + if (zoom > 0) + mode = mode->next; + else + mode = mode->prev; + } while (mode != pScr->currentMode && !(mode->type & M_T_USERDEF)); + + (void)xf86SwitchMode(pScreen, mode); +} + + +static xf86EdgePtr +FindEdge(xf86EdgePtr edge, int val) +{ + while(edge && (edge->end <= val)) + edge = edge->next; + if(edge && (edge->start <= val)) + return edge; + + return NULL; +} /* * xf86CursorOffScreen -- * Check whether it is necessary to switch to another screen */ -/* ARGSUSED */ static Bool -xf86CursorOffScreen (pScreen, x, y) - ScreenPtr *pScreen; - int *x, *y; +xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y) { - int i; - - if ((screenInfo.numScreens > 1) && ((*x < 0) || ((*pScreen)->width <= *x))) { - i = (*pScreen)->myNum; - if (*x < 0) { - i = (i ? i : screenInfo.numScreens) -1; - *pScreen = screenInfo.screens[i]; - *x += (*pScreen)->width; + xf86EdgePtr edge; + int tmp; + + if(screenInfo.numScreens == 1) + return FALSE; + + if(*x < 0) { + tmp = *y; + if(tmp < 0) tmp = 0; + if(tmp >= (*pScreen)->height) tmp = (*pScreen)->height - 1; + + if((edge = xf86ScreenLayout[(*pScreen)->myNum].left)) + edge = FindEdge(edge, tmp); + + if(!edge) *x = 0; + else { + *x += edge->offset.x; + *y += edge->offset.y; + *pScreen = xf86Screens[edge->screen]->pScreen; + } + } + + if(*x >= (*pScreen)->width) { + tmp = *y; + if(tmp < 0) tmp = 0; + if(tmp >= (*pScreen)->height) tmp = (*pScreen)->height - 1; + + if((edge = xf86ScreenLayout[(*pScreen)->myNum].right)) + edge = FindEdge(edge, tmp); + + if(!edge) *x = (*pScreen)->width - 1; + else { + *x += edge->offset.x; + *y += edge->offset.y; + *pScreen = xf86Screens[edge->screen]->pScreen; + } } - else { - *x -= (*pScreen)->width; - i = (i+1) % screenInfo.numScreens; - *pScreen = screenInfo.screens[i]; + + if(*y < 0) { + tmp = *x; + if(tmp < 0) tmp = 0; + if(tmp >= (*pScreen)->width) tmp = (*pScreen)->width - 1; + + if((edge = xf86ScreenLayout[(*pScreen)->myNum].up)) + edge = FindEdge(edge, tmp); + + if(!edge) *y = 0; + else { + *x += edge->offset.x; + *y += edge->offset.y; + *pScreen = xf86Screens[edge->screen]->pScreen; + } } - return(TRUE); - } - return(FALSE); + + if(*y >= (*pScreen)->height) { + tmp = *x; + if(tmp < 0) tmp = 0; + if(tmp >= (*pScreen)->width) tmp = (*pScreen)->width - 1; + + if((edge = xf86ScreenLayout[(*pScreen)->myNum].down)) + edge = FindEdge(edge, tmp); + + if(!edge) *y = (*pScreen)->height - 1; + else { + *x += edge->offset.x; + *y += edge->offset.y; + (*pScreen) = xf86Screens[edge->screen]->pScreen; + } + } + + +#if 0 + /* This presents problems for overlapping screens when + HardEdges is used. Have to think about the logic more */ + if((*x < 0) || (*x >= (*pScreen)->width) || + (*y < 0) || (*y >= (*pScreen)->height)) { + /* We may have crossed more than one screen */ + xf86CursorOffScreen(pScreen, x, y); + } +#endif + + return TRUE; } @@ -297,30 +380,373 @@ xf86CursorOffScreen (pScreen, x, y) * Switch to another screen */ +/* NEED TO CHECK THIS */ /* ARGSUSED */ static void -xf86CrossScreen (pScreen, entering) - ScreenPtr pScreen; - Bool entering; +xf86CrossScreen (ScreenPtr pScreen, Bool entering) { +#if 0 if (xf86Info.sharedMonitor) (XF86SCRNINFO(pScreen)->EnterLeaveMonitor)(entering); (XF86SCRNINFO(pScreen)->EnterLeaveCursor)(entering); +#endif } /* - * xf86WrapCursor -- - * Wrap possible to another screen + * xf86WarpCursor -- + * Warp possible to another screen */ /* ARGSUSED */ static void -xf86WrapCursor (pScreen, x, y) - ScreenPtr pScreen; - int x,y; +xf86WarpCursor (ScreenPtr pScreen, int x, int y) { + int sigstate; + sigstate = xf86BlockSIGIO (); miPointerWarpCursor(pScreen,x,y); xf86Info.currentScreen = pScreen; + xf86UnblockSIGIO (sigstate); +} + + +void * +xf86GetPointerScreenFuncs(void) +{ + return (void *)&xf86PointerScreenFuncs; +} + + +static xf86EdgePtr +AddEdge( + xf86EdgePtr edge, + short min, + short max, + short dx, + short dy, + short screen +){ + xf86EdgePtr pEdge = edge, pPrev = NULL, pNew; + + while(1) { + while(pEdge && (min >= pEdge->end)) { + pPrev = pEdge; + pEdge = pEdge->next; + } + + if(!pEdge) { + if(!(pNew = xalloc(sizeof(xf86EdgeRec)))) + break; + + pNew->screen = screen; + pNew->start = min; + pNew->end = max; + pNew->offset.x = dx; + pNew->offset.y = dy; + pNew->next = NULL; + + if(pPrev) + pPrev->next = pNew; + else + edge = pNew; + + break; + } else if (min < pEdge->start) { + if(!(pNew = xalloc(sizeof(xf86EdgeRec)))) + break; + + pNew->screen = screen; + pNew->start = min; + pNew->offset.x = dx; + pNew->offset.y = dy; + pNew->next = pEdge; + + if(pPrev) pPrev->next = pNew; + else edge = pNew; + + if(max <= pEdge->start) { + pNew->end = max; + break; + } else { + pNew->end = pEdge->start; + min = pEdge->end; + } + } else + min = pEdge->end; + + pPrev = pEdge; + pEdge = pEdge->next; + + if(max <= min) break; + } + + return edge; +} + +static void +FillOutEdge(xf86EdgePtr pEdge, int limit) +{ + xf86EdgePtr pNext; + int diff; + + if(pEdge->start > 0) pEdge->start = 0; + + while((pNext = pEdge->next)) { + diff = pNext->start - pEdge->end; + if(diff > 0) { + pEdge->end += diff >> 1; + pNext->start -= diff - (diff >> 1); + } + pEdge = pNext; + } + + if(pEdge->end < limit) + pEdge->end = limit; +} + +/* + * xf86InitOrigins() can deal with a maximum of 32 screens + * on 32 bit architectures, 64 on 64 bit architectures. + */ + +void +xf86InitOrigins(void) +{ + unsigned long screensLeft, prevScreensLeft, mask; + screenLayoutPtr screen; + ScreenPtr pScreen; + int x1, x2, y1, y2, left, right, top, bottom; + int i, j, ref, minX, minY, min, max; + xf86ScreenLayoutPtr pLayout; + Bool OldStyleConfig = FALSE; + + /* need to have this set up with a config file option */ + HardEdges = FALSE; + + bzero(xf86ScreenLayout, MAXSCREENS * sizeof(xf86ScreenLayoutRec)); + + screensLeft = prevScreensLeft = (1 << xf86NumScreens) - 1; + + while(1) { + for(mask = screensLeft, i = 0; mask; mask >>= 1, i++) { + if(!(mask & 1L)) continue; + + screen = &xf86ConfigLayout.screens[i]; + + switch(screen->where) { + case PosObsolete: + OldStyleConfig = TRUE; + pLayout = &xf86ScreenLayout[i]; + /* force edge lists */ + if(screen->left) { + ref = screen->left->screennum; + pLayout->left = AddEdge(pLayout->left, + 0, xf86Screens[i]->pScreen->height, + xf86Screens[ref]->pScreen->width, 0, ref); + } + if(screen->right) { + ref = screen->right->screennum; + pScreen = xf86Screens[i]->pScreen; + pLayout->right = AddEdge(pLayout->right, + 0, pScreen->height, -pScreen->width, 0, ref); + } + if(screen->top) { + ref = screen->top->screennum; + pLayout->up = AddEdge(pLayout->up, + 0, xf86Screens[i]->pScreen->width, + 0, xf86Screens[ref]->pScreen->height, ref); + } + if(screen->bottom) { + ref = screen->bottom->screennum; + pScreen = xf86Screens[i]->pScreen; + pLayout->down = AddEdge(pLayout->down, + 0, pScreen->width, 0, -pScreen->height, ref); + } + /* we could also try to place it based on those + relative locations if we wanted to */ + screen->x = screen->y = 0; + /* FALLTHROUGH */ + case PosAbsolute: + dixScreenOrigins[i].x = screen->x; + dixScreenOrigins[i].y = screen->y; + screensLeft &= ~(1 << i); + break; + case PosRelative: + ref = screen->refscreen->screennum; + if(screensLeft & (1 << ref)) break; + dixScreenOrigins[i].x = dixScreenOrigins[ref].x + screen->x; + dixScreenOrigins[i].y = dixScreenOrigins[ref].y + screen->y; + screensLeft &= ~(1 << i); + break; + case PosRightOf: + ref = screen->refscreen->screennum; + if(screensLeft & (1 << ref)) break; + pScreen = xf86Screens[ref]->pScreen; + dixScreenOrigins[i].x = + dixScreenOrigins[ref].x + pScreen->width; + dixScreenOrigins[i].y = dixScreenOrigins[ref].y; + screensLeft &= ~(1 << i); + break; + case PosLeftOf: + ref = screen->refscreen->screennum; + if(screensLeft & (1 << ref)) break; + pScreen = xf86Screens[i]->pScreen; + dixScreenOrigins[i].x = + dixScreenOrigins[ref].x - pScreen->width; + dixScreenOrigins[i].y = dixScreenOrigins[ref].y; + screensLeft &= ~(1 << i); + break; + case PosBelow: + ref = screen->refscreen->screennum; + if(screensLeft & (1 << ref)) break; + pScreen = xf86Screens[ref]->pScreen; + dixScreenOrigins[i].x = dixScreenOrigins[ref].x; + dixScreenOrigins[i].y = + dixScreenOrigins[ref].y + pScreen->height; + screensLeft &= ~(1 << i); + break; + case PosAbove: + ref = screen->refscreen->screennum; + if(screensLeft & (1 << ref)) break; + pScreen = xf86Screens[i]->pScreen; + dixScreenOrigins[i].x = dixScreenOrigins[ref].x; + dixScreenOrigins[i].y = + dixScreenOrigins[ref].y - pScreen->height; + screensLeft &= ~(1 << i); + break; + default: + ErrorF("Illegal placement keyword in Layout!\n"); + break; + } + + } + + if(!screensLeft) break; + + if(screensLeft == prevScreensLeft) { + /* All the remaining screens are referencing each other. + Assign a value to one of them and go through again */ + i = 0; + while(!((1 << i) & screensLeft)){ i++; } + + ref = xf86ConfigLayout.screens[i].refscreen->screennum; + dixScreenOrigins[ref].x = dixScreenOrigins[ref].y = 0; + screensLeft &= ~(1 << ref); + } + + prevScreensLeft = screensLeft; + } + + /* justify the topmost and leftmost to (0,0) */ + minX = dixScreenOrigins[0].x; + minY = dixScreenOrigins[0].y; + + for(i = 1; i < xf86NumScreens; i++) { + if(dixScreenOrigins[i].x < minX) + minX = dixScreenOrigins[i].x; + if(dixScreenOrigins[i].y < minY) + minY = dixScreenOrigins[i].y; + } + + if (minX || minY) { + for(i = 0; i < xf86NumScreens; i++) { + dixScreenOrigins[i].x -= minX; + dixScreenOrigins[i].y -= minY; + } + } + + + /* Create the edge lists */ + + if(!OldStyleConfig) { + for(i = 0; i < xf86NumScreens; i++) { + pLayout = &xf86ScreenLayout[i]; + + pScreen = xf86Screens[i]->pScreen; + + left = dixScreenOrigins[i].x; + right = left + pScreen->width; + top = dixScreenOrigins[i].y; + bottom = top + pScreen->height; + + for(j = 0; j < xf86NumScreens; j++) { + if(i == j) continue; + + x1 = dixScreenOrigins[j].x; + x2 = x1 + xf86Screens[j]->pScreen->width; + y1 = dixScreenOrigins[j].y; + y2 = y1 + xf86Screens[j]->pScreen->height; + + if((bottom > y1) && (top < y2)) { + min = y1 - top; + if(min < 0) min = 0; + max = pScreen->height - (bottom - y2); + if(max > pScreen->height) max = pScreen->height; + + if(((left - 1) >= x1) && ((left - 1) < x2)) + pLayout->left = AddEdge(pLayout->left, min, max, + dixScreenOrigins[i].x - dixScreenOrigins[j].x, + dixScreenOrigins[i].y - dixScreenOrigins[j].y, j); + + if((right >= x1) && (right < x2)) + pLayout->right = AddEdge(pLayout->right, min, max, + dixScreenOrigins[i].x - dixScreenOrigins[j].x, + dixScreenOrigins[i].y - dixScreenOrigins[j].y, j); + } + + + if((left < x2) && (right > x1)) { + min = x1 - left; + if(min < 0) min = 0; + max = pScreen->width - (right - x2); + if(max > pScreen->width) max = pScreen->width; + + if(((top - 1) >= y1) && ((top - 1) < y2)) + pLayout->up = AddEdge(pLayout->up, min, max, + dixScreenOrigins[i].x - dixScreenOrigins[j].x, + dixScreenOrigins[i].y - dixScreenOrigins[j].y, j); + + if((bottom >= y1) && (bottom < y2)) + pLayout->down = AddEdge(pLayout->down, min, max, + dixScreenOrigins[i].x - dixScreenOrigins[j].x, + dixScreenOrigins[i].y - dixScreenOrigins[j].y, j); + } + } + } + } + + if(!HardEdges && !OldStyleConfig) { + for(i = 0; i < xf86NumScreens; i++) { + pLayout = &xf86ScreenLayout[i]; + pScreen = xf86Screens[i]->pScreen; + if(pLayout->left) + FillOutEdge(pLayout->left, pScreen->height); + if(pLayout->right) + FillOutEdge(pLayout->right, pScreen->height); + if(pLayout->up) + FillOutEdge(pLayout->up, pScreen->width); + if(pLayout->down) + FillOutEdge(pLayout->down, pScreen->width); + } + } } + +void +xf86ReconfigureLayout(void) +{ + int i; + + for (i = 0; i < MAXSCREENS; i++) { + xf86ScreenLayoutPtr sl = &xf86ScreenLayout[i]; + /* we don't have to zero these, xf86InitOrigins() takes care of that */ + if (sl->left) xfree(sl->left); + if (sl->right) xfree(sl->right); + if (sl->up) xfree(sl->up); + if (sl->down) xfree(sl->down); + } + + xf86InitOrigins(); +} + + diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c index aa0983111..4d0efbcb9 100644 --- a/hw/xfree86/common/xf86Events.c +++ b/hw/xfree86/common/xf86Events.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Events.c,v 3.42.2.4 1998/02/07 09:23:28 hohndel Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Events.c,v 3.146 2003/02/20 04:20:52 dawes Exp $ */ /* * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. * @@ -21,48 +21,42 @@ * PERFORMANCE OF THIS SOFTWARE. * */ -/* $Xorg: xf86Events.c,v 1.3 2000/08/17 19:50:29 cpqbld Exp $ */ +/* $XConsortium: xf86Events.c /main/46 1996/10/25 11:36:30 kaleb $ */ /* [JCH-96/01/21] Extended std reverse map to four buttons. */ -#define NEED_EVENTS #include "X.h" +#include "Xpoll.h" #include "Xproto.h" #include "misc.h" -#include "inputstr.h" -#include "scrnintstr.h" #include "compiler.h" -#include "Xpoll.h" -#include "xf86Procs.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS #include "xf86_OSlib.h" -#include "xf86_Config.h" #include "atKeynames.h" #ifdef XFreeXDGA -#include "XIproto.h" -#include "extnsionst.h" -#include "scrnintstr.h" -#include "servermd.h" - -#include "exevents.h" - -#define _XF86DGA_SERVER_ -#include "extensions/xf86dgastr.h" +#include "dgaproc.h" #endif #ifdef XINPUT #include "XI.h" #include "XIproto.h" -#include "xf86Xinput.h" +#else +#include "inputstr.h" #endif +#include "xf86Xinput.h" +#include "mi.h" #include "mipointer.h" -#include "opaque.h" -#ifdef DPMSExtension -#include "extensions/dpms.h" + +#ifdef XF86BIGFONT +#define _XF86BIGFONT_SERVER_ +#include "xf86bigfont.h" #endif #ifdef XKB @@ -72,6 +66,18 @@ extern Bool noXkbExtension; #define XE_POINTER 1 #define XE_KEYBOARD 2 +#ifdef XINPUT +#define __EqEnqueue(ev) xf86eqEnqueue(ev) +#else +#define __EqEnqueue(ev) mieqEnqueue(ev) +#endif + +#define EqEnqueue(ev) { \ + int __sigstate = xf86BlockSIGIO (); \ + __EqEnqueue (ev); \ + xf86UnblockSIGIO(__sigstate); \ +} + #ifdef XTESTEXT1 #define XTestSERVER_SIDE @@ -81,62 +87,30 @@ 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) - + EqEnqueue((ev)) #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) + EqEnqueue((ev)) #endif -Bool xf86VTSema = TRUE; - -#ifdef XINPUT -extern InputInfo inputInfo; -#endif /* XINPUT */ - /* - * The first of many hack's to get VT switching to work under + * The first of many hacks to get VT switching to work under * Solaris 2.1 for x86. The basic problem is that Solaris is supposed * to be SVR4. It is for the most part, except where the video interface * is concerned. These hacks work around those problems. - * See the comments for Linux, and SCO. + * See the comments for Linux, and SCO. * - * This is a toggleling variable: + * This is a toggling variable: * FALSE = No VT switching keys have been pressed last time around * TRUE = Possible VT switch Pending * (DWH - 12/2/93) @@ -145,167 +119,40 @@ extern InputInfo inputInfo; */ #ifdef USE_VT_SYSREQ -static Bool VTSysreqToggle = FALSE; +Bool VTSysreqToggle = FALSE; #endif /* !USE_VT_SYSREQ */ -static Bool VTSwitchEnabled = TRUE; /* Allows run-time disabling for *BSD */ +Bool VTSwitchEnabled = TRUE; /* Allows run-time disabling for + *BSD and for avoiding VT + switches when using the DRI + automatic full screen mode.*/ extern fd_set EnabledDevices; -#if defined(CODRV_SUPPORT) -extern unsigned char xf86CodrvMap[]; -#endif - -#if defined(XQUEUE) && !defined(XQUEUE_ASYNC) -extern void xf86XqueRequest( -#if NeedFunctionPrototypes - void -#endif - ); +#if defined(XQUEUE) +extern void xf86XqueRequest(void); #endif +extern void (*xf86OSPMClose)(void); -#ifdef DPMSExtension -extern BOOL DPMSEnabled; -extern void DPMSSet(CARD16); -#endif - -static void xf86VTSwitch( -#if NeedFunctionPrototypes - void -#endif - ); -#ifdef XFreeXDGA -static void XF86DirectVideoMoveMouse( -#if NeedFunctionPrototypes - int x, - int y, - CARD32 mtime -#endif - ); -static void XF86DirectVideoKeyEvent( -#if NeedFunctionPrototypes - xEvent *xE, - int keycode, - int etype -#endif - ); -#endif -static CARD32 buttonTimer( -#if NeedFunctionPrototypes - OsTimerPtr timer, - CARD32 now, - pointer arg -#endif - ); +static void xf86VTSwitch(void); /* - * Lets create a simple finite-state machine: - * - * state[?][0]: action1 - * state[?][1]: action2 - * state[?][2]: next state - * - * action > 0: ButtonPress - * action = 0: nothing - * action < 0: ButtonRelease - * - * Why this stuff ??? Normally you cannot press both mousebuttons together, so - * the mouse reports both pressed at the same time ... + * Allow arbitrary drivers or other XFree86 code to register with our main + * Wakeup handler. */ +typedef struct x_IHRec { + int fd; + InputHandlerProc ihproc; + pointer data; + Bool enabled; + struct x_IHRec * next; +} IHRec, *IHPtr; -static char stateTab[48][3] = { - -/* nothing pressed */ - { 0, 0, 0 }, - { 0, 0, 8 }, /* 1 right -> delayed right */ - { 0, 0, 0 }, /* 2 nothing */ - { 0, 0, 8 }, /* 3 right -> delayed right */ - { 0, 0, 16 }, /* 4 left -> delayed left */ - { 2, 0, 24 }, /* 5 left & right (middle press) -> middle pressed */ - { 0, 0, 16 }, /* 6 left -> delayed left */ - { 2, 0, 24 }, /* 7 left & right (middle press) -> middle pressed */ - -/* delayed right */ - { 1, -1, 0 }, /* 8 nothing (right event) -> init */ - { 1, 0, 32 }, /* 9 right (right press) -> right pressed */ - { 1, -1, 0 }, /* 10 nothing (right event) -> init */ - { 1, 0, 32 }, /* 11 right (right press) -> right pressed */ - { 1, -1, 16 }, /* 12 left (right event) -> delayed left */ - { 2, 0, 24 }, /* 13 left & right (middle press) -> middle pressed */ - { 1, -1, 16 }, /* 14 left (right event) -> delayed left */ - { 2, 0, 24 }, /* 15 left & right (middle press) -> middle pressed */ - -/* delayed left */ - { 3, -3, 0 }, /* 16 nothing (left event) -> init */ - { 3, -3, 8 }, /* 17 right (left event) -> delayed right */ - { 3, -3, 0 }, /* 18 nothing (left event) -> init */ - { 3, -3, 8 }, /* 19 right (left event) -> delayed right */ - { 3, 0, 40 }, /* 20 left (left press) -> pressed left */ - { 2, 0, 24 }, /* 21 left & right (middle press) -> pressed middle */ - { 3, 0, 40 }, /* 22 left (left press) -> pressed left */ - { 2, 0, 24 }, /* 23 left & right (middle press) -> pressed middle */ - -/* pressed middle */ - { -2, 0, 0 }, /* 24 nothing (middle release) -> init */ - { -2, 0, 0 }, /* 25 right (middle release) -> init */ - { -2, 0, 0 }, /* 26 nothing (middle release) -> init */ - { -2, 0, 0 }, /* 27 right (middle release) -> init */ - { -2, 0, 0 }, /* 28 left (middle release) -> init */ - { 0, 0, 24 }, /* 29 left & right -> pressed middle */ - { -2, 0, 0 }, /* 30 left (middle release) -> init */ - { 0, 0, 24 }, /* 31 left & right -> pressed middle */ - -/* pressed right */ - { -1, 0, 0 }, /* 32 nothing (right release) -> init */ - { 0, 0, 32 }, /* 33 right -> pressed right */ - { -1, 0, 0 }, /* 34 nothing (right release) -> init */ - { 0, 0, 32 }, /* 35 right -> pressed right */ - { -1, 0, 16 }, /* 36 left (right release) -> delayed left */ - { -1, 2, 24 }, /* 37 left & right (r rel, m prs) -> middle pressed */ - { -1, 0, 16 }, /* 38 left (right release) -> delayed left */ - { -1, 2, 24 }, /* 39 left & right (r rel, m prs) -> middle pressed */ - -/* pressed left */ - { -3, 0, 0 }, /* 40 nothing (left release) -> init */ - { -3, 0, 8 }, /* 41 right (left release) -> delayed right */ - { -3, 0, 0 }, /* 42 nothing (left release) -> init */ - { -3, 0, 8 }, /* 43 right (left release) -> delayed right */ - { 0, 0, 40 }, /* 44 left -> left pressed */ - { -3, 2, 24 }, /* 45 left & right (l rel, mprs) -> middle pressed */ - { 0, 0, 40 }, /* 46 left -> left pressed */ - { -3, 2, 24 }, /* 47 left & right (l rel, mprs) -> middle pressed */ -}; - - -/* - * 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 IHPtr InputHandlers = NULL; /* * TimeSinceLastInputEvent -- - * Function used for screensaver purposes by the os module. Retruns the + * Function used for screensaver purposes by the os module. Returns the * time in milliseconds since there last was any input. */ @@ -348,20 +195,6 @@ ProcessInputEvents () static int generation = 0; #endif -#ifdef AMOEBA -#define MAXEVENTS 32 -#define BUTTON_PRESS 0x1000 -#define MAP_BUTTON(ev,but) (((ev) == EV_ButtonPress) ? \ - ((but) | BUTTON_PRESS) : ((but) & ~BUTTON_PRESS)) -#define KEY_RELEASE 0x80 -#define MAP_KEY(ev, key) (((ev) == EV_KeyReleaseEvent) ? \ - ((key) | KEY_RELEASE) : ((key) & ~KEY_RELEASE)) - - register IOPEvent *e, *elast; - IOPEvent events[MAXEVENTS]; - int dx, dy, nevents; -#endif - /* * With INHERIT_LOCK_STATE defined, the initial state of CapsLock, NumLock * and ScrollLock will be set to match that of the VT the server is @@ -398,37 +231,6 @@ ProcessInputEvents () } #endif -#ifdef AMOEBA - /* - * Get all events from the IOP server - */ - while ((nevents = AmoebaGetEvents(events, MAXEVENTS)) > 0) { - for (e = &events[0], elast = &events[nevents]; e < elast; e++) { - xf86Info.lastEventTime = e->time; - switch (e->type) { - case EV_PointerDelta: - if (e->x != 0 || e->y != 0) { - xf86PostMseEvent(&xf86Info.pMouse, 0, e->x, e->y); - } - break; - case EV_ButtonPress: - case EV_ButtonRelease: - xf86PostMseEvent(&xf86Info.pMouse, MAP_BUTTON(e->type, e->keyorbut), 0, 0); - break; - case EV_KeyPressEvent: - case EV_KeyReleaseEvent: - xf86PostKbdEvent(MAP_KEY(e->type, e->keyorbut)); - break; - default: - /* this shouldn't happen */ - ErrorF("stray event %d (%d,%d) %x\n", - e->type, e->x, e->y, e->keyorbut); - break; - } - } - } -#endif - xf86Info.inputPending = FALSE; #ifdef XINPUT @@ -442,7 +244,111 @@ ProcessInputEvents () xf86SetViewport(xf86Info.currentScreen, x, y); } +void +xf86GrabServerCallback(CallbackListPtr *callbacks, pointer data, pointer args) +{ + ServerGrabInfoRec *grab = (ServerGrabInfoRec*)args; + + xf86Info.grabInfo.server.client = grab->client; + xf86Info.grabInfo.server.grabstate = grab->grabstate; +} +/* + * Handle keyboard events that cause some kind of "action" + * (i.e., server termination, video mode changes, VT switches, etc.) + */ +void +xf86ProcessActionEvent(ActionEvent action, void *arg) +{ +#ifdef DEBUG + ErrorF("ProcessActionEvent(%d,%x)\n", (int) action, arg); +#endif + switch (action) { + case ACTION_TERMINATE: + if (!xf86Info.dontZap) { +#ifdef XFreeXDGA + DGAShutdown(); +#endif + GiveUp(0); + } + break; + case ACTION_NEXT_MODE: + if (!xf86Info.dontZoom) + xf86ZoomViewport(xf86Info.currentScreen, 1); + break; + case ACTION_PREV_MODE: + if (!xf86Info.dontZoom) + xf86ZoomViewport(xf86Info.currentScreen, -1); + break; + case ACTION_DISABLEGRAB: + if (!xf86Info.grabInfo.disabled && xf86Info.grabInfo.allowDeactivate) { + if (inputInfo.pointer && inputInfo.pointer->grab != NULL && + inputInfo.pointer->DeactivateGrab) + inputInfo.pointer->DeactivateGrab(inputInfo.pointer); + if (inputInfo.keyboard && inputInfo.keyboard->grab != NULL && + inputInfo.keyboard->DeactivateGrab) + inputInfo.keyboard->DeactivateGrab(inputInfo.keyboard); + } + break; + case ACTION_CLOSECLIENT: + if (!xf86Info.grabInfo.disabled && xf86Info.grabInfo.allowClosedown) { + ClientPtr pointer, keyboard, server; + + pointer = keyboard = server = NULL; + if (inputInfo.pointer && inputInfo.pointer->grab != NULL) + pointer = clients[CLIENT_ID(inputInfo.pointer->grab->resource)]; + if (inputInfo.keyboard && inputInfo.keyboard->grab != NULL) { + keyboard = clients[CLIENT_ID(inputInfo.keyboard->grab->resource)]; + if (keyboard == pointer) + keyboard = NULL; + } + if ((xf86Info.grabInfo.server.grabstate == SERVER_GRABBED) && + (((server = xf86Info.grabInfo.server.client) == pointer) || + (server == keyboard))) + server = NULL; + + if (pointer) + CloseDownClient(pointer); + if (keyboard) + CloseDownClient(keyboard); + if (server) + CloseDownClient(server); + } + break; +#if !defined(__SOL8__) && (!defined(sun) || defined(i386)) + case ACTION_SWITCHSCREEN: + if (VTSwitchEnabled && !xf86Info.dontVTSwitch && arg) { + int vtno = *((int *) arg); +#if defined(QNX4) + xf86Info.vtRequestsPending = vtno; +#else + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vtno) < 0) + ErrorF("Failed to switch consoles (%s)\n", strerror(errno)); +#endif + } + break; + case ACTION_SWITCHSCREEN_NEXT: + if (VTSwitchEnabled && !xf86Info.dontVTSwitch) { + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno + 1) < 0) +#if defined(SCO) || (defined(sun) && defined (i386) && defined (SVR4)) + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 0) < 0) +#else + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) < 0) +#endif + ErrorF("Failed to switch consoles (%s)\n", strerror(errno)); + } + break; + case ACTION_SWITCHSCREEN_PREV: + if (VTSwitchEnabled && !xf86Info.dontVTSwitch) { + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno - 1) < 0) + ErrorF("Failed to switch consoles (%s)\n", strerror(errno)); + } + break; +#endif + default: + break; + } +} /* * xf86PostKbdEvent -- @@ -454,17 +360,18 @@ ProcessInputEvents () * ifdefs further (hv). */ -#ifdef ASSUME_CUSTOM_KEYCODES +#ifdef __linux__ extern u_char SpecialServerMap[]; -#endif /* ASSUME_CUSTOM_KEYCODES */ +#endif -#if !defined(__EMX__) +#if !defined(__UNIXOS2__) && \ + !defined(__SOL8__) && \ + (!defined(sun) || defined(i386)) void -xf86PostKbdEvent(key) - unsigned key; +xf86PostKbdEvent(unsigned key) { int scanCode = (key & 0x7f); - int specialkey; + int specialkey = 0; Bool down = (key & 0x80 ? FALSE : TRUE); KeyClassRec *keyc = ((DeviceIntPtr)xf86Info.pKeyboard)->key; Bool updateLeds = FALSE; @@ -474,16 +381,17 @@ xf86PostKbdEvent(key) KeySym *keysym; int keycode; static int lockkeys = 0; -#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) +#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT) static Bool first_time = TRUE; #endif - -#if defined(CODRV_SUPPORT) - if (xf86Info.consType == CODRV011 || xf86Info.consType == CODRV01X) - scanCode = xf86CodrvMap[scanCode]; +#if defined(__sparc__) + static int kbdSun = -1; #endif + /* Disable any keyboard processing while in suspend */ + if (xf86inSuspend) + return; -#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) +#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT) if (first_time) { first_time = FALSE; @@ -492,102 +400,78 @@ xf86PostKbdEvent(key) } #endif -#if defined (i386) && defined (SVR4) && !defined (PC98) +#if defined (__sparc__) + if (kbdSun == -1) { + if ((xf86Info.xkbmodel && !strcmp(xf86Info.xkbmodel, "sun")) + || (xf86Info.xkbrules && !strcmp(xf86Info.xkbrules, "sun"))) + kbdSun = 1; + else + kbdSun = 0; + } + if (kbdSun) + goto special; +#endif /* __sparc__ */ + +#if defined (i386) && defined (SVR4) /* * PANIX returns DICOP standards based keycodes in using 106jp * keyboard. We need to remap some keys. */ -#define KEY_P_UP 0x5A -#define KEY_P_PGUP 0x5B -#define KEY_P_LEFT 0x5C -#define KEY_P_BKSL 0x73 -#define KEY_P_YEN 0x7D -#define KEY_P_NFER 0x7B -#define KEY_P_XFER 0x79 - if(xf86Info.panix106 == TRUE){ switch (scanCode) { - /* case 0x78: scanCode = KEY_P_UP; break; not needed*/ - case 0x56: scanCode = KEY_P_BKSL; break; /* Backslash */ - case 0x5A: scanCode = KEY_P_NFER; break; /* No Kanji Transfer*/ - case 0x5B: scanCode = KEY_P_XFER; break; /* Kanji Tranfer */ - case 0x5C: scanCode = KEY_P_YEN; break; /* Yen curs pgup */ - case 0x6B: scanCode = KEY_P_LEFT; break; /* Cur Left */ - case 0x6F: scanCode = KEY_P_PGUP; break; /* Cur PageUp */ + case 0x56: scanCode = KEY_BSlash2; break; /* Backslash */ + case 0x5A: scanCode = KEY_NFER; break; /* No Kanji Transfer*/ + case 0x5B: scanCode = KEY_XFER; break; /* Kanji Tranfer */ + case 0x5C: scanCode = KEY_Yen; break; /* Yen curs pgup */ + case 0x6B: scanCode = KEY_Left; break; /* Cur Left */ + case 0x6F: scanCode = KEY_PgUp; break; /* Cur PageUp */ case 0x72: scanCode = KEY_AltLang; break; /* AltLang(right) */ case 0x73: scanCode = KEY_RCtrl; break; /* not needed */ } } #endif /* i386 && SVR4 */ -#ifndef ASSUME_CUSTOM_KEYCODES +#ifdef __linux__ + if (xf86Info.kbdCustomKeycodes) { + specialkey = SpecialServerMap[scanCode]; + goto customkeycodes; + } +#endif + /* * First do some special scancode remapping ... */ if (xf86Info.scanPrefix == 0) { switch (scanCode) { - -#ifndef PC98 case KEY_Prefix0: case KEY_Prefix1: -#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) +#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT) if (xf86Info.consType == PCCONS || xf86Info.consType == SYSCONS - || xf86Info.consType == PCVT) { + || xf86Info.consType == PCVT +#ifdef WSCONS_SUPPORT + || (xf86Info.consType == WSCONS && xf86Info.kbdEvents != xf86WSKbdEvents) +#endif + ) { #endif xf86Info.scanPrefix = scanCode; /* special prefixes */ return; -#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) +#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT) } break; #endif -#endif /* not PC98 */ - } -#ifndef PC98 - if (xf86Info.serverNumLock) { - if ((!xf86Info.numLock && ModifierDown(ShiftMask)) || - (xf86Info.numLock && !ModifierDown(ShiftMask))) { - /* - * Hardwired numlock handling ... (Some applications break if they have - * these keys double defined, like twm) - */ - switch (scanCode) { - case KEY_KP_7: scanCode = KEY_SN_KP_7; break; /* curs 7 */ - case KEY_KP_8: scanCode = KEY_SN_KP_8; break; /* curs 8 */ - case KEY_KP_9: scanCode = KEY_SN_KP_9; break; /* curs 9 */ - case KEY_KP_4: scanCode = KEY_SN_KP_4; break; /* curs 4 */ - case KEY_KP_5: scanCode = KEY_SN_KP_5; break; /* curs 5 */ - case KEY_KP_6: scanCode = KEY_SN_KP_6; break; /* curs 6 */ - case KEY_KP_1: scanCode = KEY_SN_KP_1; break; /* curs 1 */ - case KEY_KP_2: scanCode = KEY_SN_KP_2; break; /* curs 2 */ - case KEY_KP_3: scanCode = KEY_SN_KP_3; break; /* curs 3 */ - case KEY_KP_0: scanCode = KEY_SN_KP_0; break; /* curs 0 */ - case KEY_KP_Decimal: scanCode = KEY_SN_KP_Dec; break; /* curs decimal */ - } - } else { - switch (scanCode) { - case KEY_KP_7: scanCode = KEY_SN_KP_Home; break; /* curs home */ - case KEY_KP_8: scanCode = KEY_SN_KP_Up ; break; /* curs up */ - case KEY_KP_9: scanCode = KEY_SN_KP_Prior; break; /* curs pgup */ - case KEY_KP_4: scanCode = KEY_SN_KP_Left; break; /* curs left */ - case KEY_KP_5: scanCode = KEY_SN_KP_Begin; break; /* curs begin */ - case KEY_KP_6: scanCode = KEY_SN_KP_Right; break; /* curs right */ - case KEY_KP_1: scanCode = KEY_SN_KP_End; break; /* curs end */ - case KEY_KP_2: scanCode = KEY_SN_KP_Down; break; /* curs down */ - case KEY_KP_3: scanCode = KEY_SN_KP_Next; break; /* curs pgdn */ - case KEY_KP_0: scanCode = KEY_SN_KP_Ins; break; /* curs ins */ - case KEY_KP_Decimal: scanCode = KEY_SN_KP_Del; break; /* curs del */ - } - } } -#endif /* not PC98 */ } -#ifndef PC98 else if ( #ifdef CSRG_BASED (xf86Info.consType == PCCONS || xf86Info.consType == SYSCONS - || xf86Info.consType == PCVT) && + || xf86Info.consType == PCVT +#ifdef WSCONS_SUPPORT + || (xf86Info.consType == WSCONS && xf86Info.kbdEvents != + xf86WSKbdEvents) +#endif + ) && #endif (xf86Info.scanPrefix == KEY_Prefix0)) { xf86Info.scanPrefix = 0; @@ -622,8 +506,18 @@ xf86PostKbdEvent(key) /* * Ignore virtual shifts (E0 2A, E0 AA, E0 36, E0 B6) */ + case 0x2A: + case 0x36: + return; default: - return; /* skip illegal */ + xf86MsgVerb(X_INFO, 4, "Unreported Prefix0 scancode: 0x%02x\n", + scanCode); + /* + * "Internet" keyboards are generating lots of new codes. Let them + * pass. There is little consistency between them, so don't bother + * with symbolic names at this level. + */ + scanCode += 0x78; } } @@ -639,55 +533,140 @@ xf86PostKbdEvent(key) if (scanCode != KEY_NumLock) return; scanCode = KEY_Pause; /* pause */ } -#endif /* not PC98 */ -#endif /* !ASSUME_CUSTOM_KEYCODES */ /* * and now get some special keysequences */ -#ifdef ASSUME_CUSTOM_KEYCODES - specialkey = SpecialServerMap[scanCode]; -#else /* ASSUME_CUSTOM_KEYCODES */ specialkey = scanCode; -#endif /* ASSUME_CUSTOM_KEYCODES */ - if ((ModifierDown(ControlMask | AltMask)) || - (ModifierDown(ControlMask | AltLangMask))) +#ifdef __linux__ +customkeycodes: +#endif +#if defined(i386) || defined(__i386__) + if (xf86IsPc98()) { + switch (scanCode) { + case 0x0e: specialkey = 0x0e; break; /* KEY_BackSpace */ + case 0x40: specialkey = 0x4a; break; /* KEY_KP_Minus */ + case 0x49: specialkey = 0x4e; break; /* KEY_KP_Plus */ + + /* XXX needs cases for KEY_KP_Divide and KEY_KP_Multiply */ + + case 0x62: specialkey = 0x3b; break; /* KEY_F1 */ + case 0x63: specialkey = 0x3c; break; /* KEY_F2 */ + case 0x64: specialkey = 0x3d; break; /* KEY_F3 */ + case 0x65: specialkey = 0x3e; break; /* KEY_F4 */ + case 0x66: specialkey = 0x3f; break; /* KEY_F5 */ + case 0x67: specialkey = 0x40; break; /* KEY_F6 */ + case 0x68: specialkey = 0x41; break; /* KEY_F7 */ + case 0x69: specialkey = 0x42; break; /* KEY_F8 */ + case 0x6a: specialkey = 0x43; break; /* KEY_F9 */ + case 0x6b: specialkey = 0x44; break; /* KEY_F10 */ + /* case 0x73: specialkey = 0x38; break; KEY_Alt */ + /* case 0x74: specialkey = 0x1d; break; KEY_LCtrl */ + default: specialkey = 0x00; break; + } + } +#endif +#if defined (__sparc__) +special: + if (kbdSun) { + switch (scanCode) { + case 0x2b: specialkey = KEY_BackSpace; break; + case 0x47: specialkey = KEY_KP_Minus; break; + case 0x7d: specialkey = KEY_KP_Plus; break; + + /* XXX needs cases for KEY_KP_Divide and KEY_KP_Multiply */ + + case 0x05: specialkey = KEY_F1; break; + case 0x06: specialkey = KEY_F2; break; + case 0x08: specialkey = KEY_F3; break; + case 0x0a: specialkey = KEY_F4; break; + case 0x0c: specialkey = KEY_F5; break; + case 0x0e: specialkey = KEY_F6; break; + case 0x10: specialkey = KEY_F7; break; + case 0x11: specialkey = KEY_F8; break; + case 0x12: specialkey = KEY_F9; break; + case 0x07: specialkey = KEY_F10; break; + case 0x09: specialkey = KEY_F11; break; + case 0x0b: specialkey = KEY_F12; break; + default: specialkey = 0; break; + } + /* + * XXX XXX XXX: + * + * I really don't know what's wrong here, but passing the real + * scanCode offsets by one from XKB's point of view. + * + * (ecd@skynet.be, 980405) + */ + scanCode--; + } +#endif /* defined (__sparc__) */ + +#ifdef XKB + if ((xf86Info.ddxSpecialKeys == SKWhenNeeded && + !xf86Info.ActionKeyBindingsSet) || + noXkbExtension || xf86Info.ddxSpecialKeys == SKAlways) { +#endif + if (!(ModifierDown(ShiftMask)) && + ((ModifierDown(ControlMask | AltMask)) || + (ModifierDown(ControlMask | AltLangMask)))) { - switch (specialkey) { case KEY_BackSpace: - if (!xf86Info.dontZap) { -#ifdef XFreeXDGA - if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectGraphics) + xf86ProcessActionEvent(ACTION_TERMINATE, NULL); break; -#endif - GiveUp(0); - } + + /* + * Check grabs + */ + case KEY_KP_Divide: + xf86ProcessActionEvent(ACTION_DISABLEGRAB, NULL); break; - - /* - * The idea here is to pass the scancode down to a list of - * registered routines. There should be some standard conventions - * for processing certain keys. - */ + case KEY_KP_Multiply: + xf86ProcessActionEvent(ACTION_CLOSECLIENT, NULL); + break; + + /* + * Video mode switches + */ case KEY_KP_Minus: /* Keypad - */ - if (!xf86Info.dontZoom) { - if (down) xf86ZoomViewport(xf86Info.currentScreen, -1); - return; - } + if (down) xf86ProcessActionEvent(ACTION_PREV_MODE, NULL); + if (!xf86Info.dontZoom) return; break; case KEY_KP_Plus: /* Keypad + */ - if (!xf86Info.dontZoom) { - if (down) xf86ZoomViewport(xf86Info.currentScreen, 1); + if (down) xf86ProcessActionEvent(ACTION_NEXT_MODE, NULL); + if (!xf86Info.dontZoom) return; + break; + + /* Under QNX4, we set the vtPending flag for VT switching and + * let the VT switch function do the rest... + * This is a little different from the other OS'es. + */ +#if defined(QNX4) + case KEY_1: + case KEY_2: + case KEY_3: + case KEY_4: + case KEY_5: + case KEY_6: + case KEY_7: + case KEY_8: + case KEY_9: + if (VTSwitchEnabled && !xf86Info.dontVTSwitch) { + if (down) { + int vtno = specialkey - KEY_1 + 1; + xf86ProcessActionEvent(ACTION_SWITCHSCREEN, (void *) &vtno); + } return; } break; +#endif -#if defined(linux) || (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT))) || defined(SCO) +#if defined(linux) || (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT))) || defined(SCO) /* * Under Linux, the raw keycodes are consumed before the kernel * does any processing on them, so we must emulate the vt switching @@ -703,37 +682,23 @@ xf86PostKbdEvent(key) case KEY_F8: case KEY_F9: case KEY_F10: - if (VTSwitchEnabled && !xf86Info.vtSysreq -#if (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT))) - && (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) -#endif - ) - { - if (down) -#ifdef SCO325 - ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey - KEY_F1); -#else - ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey - KEY_F1 + 1); -#endif - return; - } - break; case KEY_F11: case KEY_F12: - if (VTSwitchEnabled && !xf86Info.vtSysreq -#if (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT))) + if ((VTSwitchEnabled && !xf86Info.vtSysreq && !xf86Info.dontVTSwitch) +#if (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT))) && (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) #endif - ) - { - if (down) + ) { + int vtno = specialkey - KEY_F1 + 1; + if (specialkey == KEY_F11 || specialkey == KEY_F12) + vtno = specialkey - KEY_F11 + 11; #ifdef SCO325 - ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey - KEY_F11 + 10); -#else - ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey - KEY_F11 + 11); + vtno--; #endif - return; - } + if (down) + xf86ProcessActionEvent(ACTION_SWITCHSCREEN, (void *) &vtno); + return; + } break; #endif /* linux || BSD with VTs */ @@ -753,7 +718,7 @@ xf86PostKbdEvent(key) */ #ifdef USE_VT_SYSREQ - if (VTSwitchEnabled && xf86Info.vtSysreq) + if (VTSwitchEnabled && xf86Info.vtSysreq && !xf86Info.dontVTSwitch) { switch (specialkey) { @@ -765,7 +730,7 @@ xf86PostKbdEvent(key) case KEY_H: if (VTSysreqToggle && down) { - ioctl(xf86Info.consoleFd, VT_ACTIVATE, 0); + xf86ProcessActionEvent(ACTION_SWITCHSCREEN, NULL); VTSysreqToggle = 0; return; } @@ -780,8 +745,7 @@ xf86PostKbdEvent(key) case KEY_N: if (VTSysreqToggle && down) { - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno - 1 ) < 0) - ErrorF("Failed to switch consoles (%s)\n", strerror(errno)); + xf86ProcessActionEvent(ACTION_SWITCHSCREEN_NEXT, NULL); VTSysreqToggle = FALSE; return; } @@ -790,9 +754,7 @@ xf86PostKbdEvent(key) case KEY_P: if (VTSysreqToggle && down) { - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno + 1 ) < 0) - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 0) < 0) - ErrorF("Failed to switch consoles (%s)\n", strerror(errno)); + xf86ProcessActionEvent(ACTION_SWITCHSCREEN_NEXT, NULL); VTSysreqToggle = FALSE; return; } @@ -809,21 +771,13 @@ xf86PostKbdEvent(key) case KEY_F8: case KEY_F9: case KEY_F10: - if (VTSysreqToggle && down) - { - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey-KEY_F1 + 1) < 0) - ErrorF("Failed to switch consoles (%s)\n", strerror(errno)); - VTSysreqToggle = FALSE; - return; - } - break; - case KEY_F11: case KEY_F12: if (VTSysreqToggle && down) - { - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey-KEY_F11 + 11) < 0) - ErrorF("Failed to switch consoles (%s)\n", strerror(errno)); + { int vtno = specialkey - KEY_F1 + 1; + if (specialkey == KEY_F11 || specialkey == KEY_F12) + vtno = specialkey - KEY_F11 + 11; + xf86ProcessActionEvent(ACTION_SWITCHSCREEN, (void *) &vtno); VTSysreqToggle = FALSE; return; } @@ -831,17 +785,13 @@ xf86PostKbdEvent(key) /* Ignore these keys -- ie don't let them cancel an alt-sysreq */ case KEY_Alt: -#ifndef PC98 case KEY_AltLang: -#endif /* not PC98 */ break; -#ifndef PC98 case KEY_SysReqest: if (down && (ModifierDown(AltMask) || ModifierDown(AltLangMask))) VTSysreqToggle = TRUE; break; -#endif /* not PC98 */ default: if (VTSysreqToggle) @@ -870,14 +820,26 @@ xf86PostKbdEvent(key) */ if (specialkey == KEY_Print && ModifierDown(ControlMask)) { if (down) - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno + 1) < 0) - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 0) < 0) - ErrorF("Failed to switch consoles (%s)\n", strerror(errno)); + xf86ProcessActionEvent(ACTION_SWITCHSCREEN_NEXT, NULL); return; } #endif /* SCO */ +#ifdef XKB + } +#endif /* + * PC keyboards generate separate key codes for + * Alt+Print and Control+Pause but in the X keyboard model + * they need to get the same key code as the base key on the same + * physical keyboard key. + */ + if (scanCode == KEY_SysReqest) + scanCode = KEY_Print; + else if (scanCode == KEY_Break) + scanCode = KEY_Pause; + + /* * Now map the scancodes to real X-keycodes ... */ keycode = scanCode + MIN_KEYCODE; @@ -949,7 +911,6 @@ xf86PostKbdEvent(key) * 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 || @@ -971,28 +932,29 @@ xf86PostKbdEvent(key) if (keysym[1] == XF86XK_ModeLock) xf86Info.modeSwitchLock = flag; updateLeds = TRUE; } -#endif /* not PC98 */ -#ifndef ASSUME_CUSTOM_KEYCODES - /* - * normal, non-keypad keys - */ - if (scanCode < KEY_KP_7 || scanCode > KEY_KP_Decimal) { -#if !defined(CSRG_BASED) && !defined(MACH386) && !defined(MINIX) && !defined(__OSF__) + if (!xf86Info.kbdCustomKeycodes) { /* - * magic ALT_L key on AT84 keyboards for multilingual support + * normal, non-keypad keys */ - if (xf86Info.kbdType == KB_84 && - ModifierDown(AltMask) && - keysym[2] != NoSymbol) - { - UsePrefix = TRUE; - Direction = TRUE; - } -#endif /* !CSRG_BASED && !MACH386 && !MINIX && !__OSF__ */ + if (scanCode < KEY_KP_7 || scanCode > KEY_KP_Decimal) { +#if !defined(CSRG_BASED) && \ + !defined(__GNU__) && \ + defined(KB_84) + /* + * magic ALT_L key on AT84 keyboards for multilingual support + */ + if (xf86Info.kbdType == KB_84 && + ModifierDown(AltMask) && + keysym[2] != NoSymbol) + { + UsePrefix = TRUE; + Direction = TRUE; + } +#endif /* !CSRG_BASED && ... */ + } } -#endif /* !ASSUME_CUSTOM_KEYCODES */ - if (updateLeds) xf86KbdLeds(); + if (updateLeds) xf86UpdateKbdLeds(); #ifdef XKB } #endif @@ -1000,9 +962,14 @@ xf86PostKbdEvent(key) /* * check for an autorepeat-event */ - if ((down && KeyPressed(keycode)) && - (xf86Info.autoRepeat != AutoRepeatModeOn || keyc->modifierMap[keycode])) - return; + if (down && KeyPressed(keycode)) { + KbdFeedbackClassRec *kbdfeed = ((DeviceIntPtr)xf86Info.pKeyboard)->kbdfeed; + if ((xf86Info.autoRepeat != AutoRepeatModeOn) || + keyc->modifierMap[keycode] || + (kbdfeed && !(kbdfeed->ctrl.autoRepeats[keycode>>3] & ( 1<<(keycode&7) )))) + return; + } + xf86Info.lastEventTime = kevent.u.keyButtonPointer.time = GetTimeInMillis(); /* @@ -1023,383 +990,220 @@ xf86PostKbdEvent(key) } else { -#ifdef XFreeXDGA - 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); - - } + ENQUEUE(&kevent, keycode, (down ? KeyPress : KeyRelease), XE_KEYBOARD); } } -#endif /* !__EMX__ */ +#endif /* !__UNIXOS2__ */ +#define ModifierIsSet(k) ((modifiers & (k)) == (k)) -static CARD32 -buttonTimer(timer, now, arg) - OsTimerPtr timer; - CARD32 now; - pointer arg; +Bool +xf86CommonSpecialKey(int key, Bool down, int modifiers) { - MouseDevPtr priv = MOUSE_DEV((DeviceIntPtr) arg); + if ((ModifierIsSet(ControlMask | AltMask)) || + (ModifierIsSet(ControlMask | AltLangMask))) { + switch (key) { + + case KEY_BackSpace: + xf86ProcessActionEvent(ACTION_TERMINATE, NULL); + break; - xf86PostMseEvent(((DeviceIntPtr) arg), priv->truebuttons, 0, 0); - return(0); + /* + * Check grabs + */ + case KEY_KP_Divide: + xf86ProcessActionEvent(ACTION_DISABLEGRAB, NULL); + break; + case KEY_KP_Multiply: + xf86ProcessActionEvent(ACTION_CLOSECLIENT, NULL); + break; + + /* + * The idea here is to pass the scancode down to a list of + * registered routines. There should be some standard conventions + * for processing certain keys. + */ + case KEY_KP_Minus: /* Keypad - */ + if (down) xf86ProcessActionEvent(ACTION_PREV_MODE, NULL); + if (!xf86Info.dontZoom) return TRUE; + break; + + case KEY_KP_Plus: /* Keypad + */ + if (down) xf86ProcessActionEvent(ACTION_NEXT_MODE, NULL); + if (!xf86Info.dontZoom) return TRUE; + break; + } + } + return FALSE; } - -/* - * xf86PostMseEvent -- - * Translate the raw hardware MseEvent into an XEvent(s), and tell DIX - * about it. Perform a 3Button emulation if required. +/* + * xf86Wakeup -- + * Os wakeup handler. */ +/* ARGSUSED */ void -xf86PostMseEvent(device, buttons, dx, dy) - DeviceIntPtr device; - int buttons, dx, dy; +xf86Wakeup(pointer blockData, int err, pointer pReadmask) { - static OsTimerPtr timer = NULL; - MouseDevPtr private = MOUSE_DEV(device); - int id, change; - int truebuttons; - xEvent mevent[2]; -#ifdef XINPUT - deviceKeyButtonPointer *xev = (deviceKeyButtonPointer *) mevent; - deviceValuator *xv = (deviceValuator *) (xev+1); - int is_pointer; /* the mouse is the pointer ? */ -#endif - -#ifdef AMOEBA - int pressed; - - pressed = ((buttons & BUTTON_PRESS) != 0); - buttons &= ~BUTTON_PRESS; -#endif - -#ifdef XINPUT - is_pointer = xf86IsCorePointer(device); - - if (!is_pointer) { - xev->time = xf86Info.lastEventTime = GetTimeInMillis(); - } - else -#endif - xf86Info.lastEventTime = mevent->u.keyButtonPointer.time = GetTimeInMillis(); - - truebuttons = buttons; - if (private->mseType == P_MMHIT) - buttons = reverseBits(hitachMap, buttons); - else - buttons = reverseBits(reverseMap, buttons); - - if (dx || dy) { - - /* - * accelerate the baby now if sqrt(dx*dx + dy*dy) > threshold ! - * but do some simpler arithmetic here... - */ - if ((abs(dx) + abs(dy)) >= private->threshold) { - dx = (dx * private->num) / private->den; - dy = (dy * private->num)/ private->den; - } - -#ifdef XINPUT - if (is_pointer) { -#endif -#ifdef XFreeXDGA - if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectMouse) { - XF86DirectVideoMoveMouse(dx, dy, mevent->u.keyButtonPointer.time); - } else -#endif - { - MOVEPOINTER(dx, dy, mevent->u.keyButtonPointer.time); +#if !defined(__UNIXOS2__) && !defined(__QNX__) + fd_set* LastSelectMask = (fd_set*)pReadmask; + fd_set devicesWithInput; + InputInfoPtr pInfo; + + if (err >= 0) { + + XFD_ANDSET(&devicesWithInput, LastSelectMask, &EnabledDevices); + if (XFD_ANYSET(&devicesWithInput)) { + if (xf86Info.kbdEvents) + (xf86Info.kbdEvents)(); + pInfo = xf86InputDevs; + while (pInfo) { + if (pInfo->read_input && pInfo->fd >= 0 && + (FD_ISSET(pInfo->fd, ((fd_set *)pReadmask)) != 0)) { + int sigstate = xf86BlockSIGIO(); + + pInfo->read_input(pInfo); + xf86UnblockSIGIO(sigstate); + /* + * Must break here because more than one device may share + * the same file descriptor. + */ + break; + } + pInfo = pInfo->next; + } } -#ifdef XINPUT } - else { - xev->type = DeviceMotionNotify; - xev->deviceid = device->id | MORE_EVENTS; - xv->type = DeviceValuator; - xv->deviceid = device->id; - xv->num_valuators = 2; - xv->first_valuator = 0; - xv->device_state = 0; - xv->valuator0 = dx; - xv->valuator1 = dy; - xf86eqEnqueue(mevent); +#else /* __UNIXOS2__ and __QNX__ */ + + InputInfoPtr pInfo; + + (xf86Info.kbdEvents)(); /* Under OS/2 and QNX, always call */ + + pInfo = xf86InputDevs; + while (pInfo) { + if (pInfo->read_input && pInfo->fd >= 0) { + int sigstate = xf86BlockSIGIO(); + + pInfo->read_input(pInfo); + xf86UnblockSIGIO(sigstate); + /* + * Must break here because more than one device may share + * the same file descriptor. + */ + break; + } + pInfo = pInfo->next; } -#endif - } - - if (private->emulate3Buttons) - { - /* - * Hack to operate the middle button even with Emulate3Buttons set. - * Modifying the state table to keep track of the middle button state - * would nearly double its size, so I'll stick with this fix. - TJW - */ - if (private->mseType == P_MMHIT) - change = buttons ^ reverseBits(hitachMap, private->lastButtons); - else - change = buttons ^ reverseBits(reverseMap, private->lastButtons); - if (change & 02) - { -#ifdef XINPUT - if (xf86CheckButton(2, (buttons & 02))) { -#endif - ENQUEUE(mevent, - 2, (buttons & 02) ? ButtonPress : ButtonRelease, - XE_POINTER); -#ifdef XINPUT - } -#endif - } - - /* - * emulate the third button by the other two - */ - if ((id = stateTab[buttons + private->emulateState][0]) != 0) - { -#ifdef XINPUT - if (is_pointer) { - if (xf86CheckButton(abs(id), (id >= 0))) { -#endif - ENQUEUE(mevent, - abs(id), (id < 0 ? ButtonRelease : ButtonPress), - XE_POINTER); -#ifdef XINPUT - } - } - else { - xev->type = (id < 0 ? DeviceButtonRelease : DeviceButtonPress); - xev->deviceid = device->id | MORE_EVENTS; - xev->detail = abs(id); - xv->type = DeviceValuator; - xv->deviceid = device->id; - xv->num_valuators = 0; - xv->device_state = 0; - xf86eqEnqueue(mevent); - } -#endif - } +#endif /* __UNIXOS2__ and __QNX__ */ - if ((id = stateTab[buttons + private->emulateState][1]) != 0) - { -#ifdef XINPUT - if (is_pointer) { - if (xf86CheckButton(abs(id), (id >= 0))) { -#endif - ENQUEUE(mevent, - abs(id), (id < 0 ? ButtonRelease : ButtonPress), - XE_POINTER); -#ifdef XINPUT - } - } - else { - xev->type = (id < 0 ? DeviceButtonRelease : DeviceButtonPress); - xev->deviceid = device->id | MORE_EVENTS; - xev->detail = abs(id); - xv->type = DeviceValuator; - xv->deviceid = device->id; - xv->num_valuators = 0; - xv->device_state = 0; - xf86eqEnqueue(mevent); - } -#endif - } - - private->emulateState = stateTab[buttons + private->emulateState][2]; - if (stateTab[buttons + private->emulateState][0] || - stateTab[buttons + private->emulateState][1]) - { - private->truebuttons = truebuttons; - timer = TimerSet(timer, 0, private->emulate3Timeout, buttonTimer, - (pointer)device); - } - else - { - if (timer) - { - TimerFree(timer); - timer = NULL; - } - } - } - else - { -#ifdef AMOEBA - if (truebuttons != 0) { -#ifdef XINPUT - if (is_pointer) { - if (xf86CheckButton(truebuttons)) { -#endif - ENQUEUE(mevent, - truebuttons, (pressed ? ButtonPress : ButtonRelease), - XE_POINTER); -#ifdef XINPUT - } - } - else { - xev->type = pressed ? DeviceButtonPress : DeviceButtonRelease; - xev->deviceid = device->id | MORE_EVENTS; - xev->detail = truebuttons; - xv->type = DeviceValuator; - xv->deviceid = device->id; - xv->num_valuators = 0; - xv->device_state = 0; - xf86eqEnqueue(mevent); - } -#endif - } -#else - /* - * real three button event - * Note that xf86Info.lastButtons has the hardware button mapping which - * is the reverse of the button mapping reported to the server. - */ - if (private->mseType == P_MMHIT) - change = buttons ^ reverseBits(hitachMap, private->lastButtons); - else - change = buttons ^ reverseBits(reverseMap, private->lastButtons); - while (change) - { - id = ffs(change); - change &= ~(1 << (id-1)); -#ifdef XINPUT - if (is_pointer) { - if (xf86CheckButton(id, (buttons&(1<<(id-1))))) { -#endif - ENQUEUE(mevent, - id, (buttons&(1<<(id-1)))? ButtonPress : ButtonRelease, - XE_POINTER); -#ifdef XINPUT + if (err >= 0) { /* we don't want the handlers called if select() */ + IHPtr ih; /* returned with an error condition, do we? */ + + for (ih = InputHandlers; ih; ih = ih->next) { + if (ih->enabled && ih->fd >= 0 && ih->ihproc && + (FD_ISSET(ih->fd, ((fd_set *)pReadmask)) != 0)) { + ih->ihproc(ih->fd, ih->data); } - } - else { - xev->type = (buttons&(1<<(id-1)))? DeviceButtonPress : DeviceButtonRelease; - xev->deviceid = device->id | MORE_EVENTS; - xev->detail = id; - xv->type = DeviceValuator; - xv->deviceid = device->id; - xv->num_valuators = 0; - xv->device_state = 0; - xf86eqEnqueue(mevent); - } -#endif } -#endif } - private->lastButtons = truebuttons; -} + + if (xf86VTSwitchPending()) xf86VTSwitch(); + if (xf86Info.inputPending) ProcessInputEvents(); +} /* - * xf86Block -- - * Os block handler. + * xf86SigioReadInput -- + * signal handler for the SIGIO signal. */ - -/* ARGSUSED */ -void -xf86Block(blockData, pTimeout, pReadmask) - pointer blockData; - OSTimePtr pTimeout; - pointer pReadmask; +static void +xf86SigioReadInput(int fd, + void *closure) { -} + int sigstate = xf86BlockSIGIO(); + InputInfoPtr pInfo = (InputInfoPtr) closure; + pInfo->read_input(pInfo); -#ifndef AMOEBA + xf86UnblockSIGIO(sigstate); +} /* - * xf86Wakeup -- - * Os wakeup handler. + * xf86AddEnabledDevice -- + * */ - -/* ARGSUSED */ void -xf86Wakeup(blockData, err, pReadmask) - pointer blockData; - int err; - pointer pReadmask; +xf86AddEnabledDevice(InputInfoPtr pInfo) { + if (!xf86InstallSIGIOHandler (pInfo->fd, xf86SigioReadInput, pInfo)) { + AddEnabledDevice(pInfo->fd); + } +} -#ifndef __EMX__ -#ifdef __OSF__ - fd_set kbdDevices; - fd_set mseDevices; -#endif /* __OSF__ */ - fd_set* LastSelectMask = (fd_set*)pReadmask; - fd_set devicesWithInput; - - if ((int)err >= 0) { - XFD_ANDSET(&devicesWithInput, LastSelectMask, &EnabledDevices); -#ifdef __OSF__ - /* - * Until the two devices are made nonblock on read, we have to do this. - */ - - MASKANDSETBITS(devicesWithInput, pReadmask, EnabledDevices); - - CLEARBITS(kbdDevices); - BITSET(kbdDevices, xf86Info.consoleFd); - MASKANDSETBITS(kbdDevices, kbdDevices, devicesWithInput); - - CLEARBITS(mseDevices); - BITSET(mseDevices, xf86Info.mouseDev->mseFd); - MASKANDSETBITS(mseDevices, mseDevices, devicesWithInput); - - if (ANYSET(kbdDevices) || xf86Info.kbdRate) - (xf86Info.kbdEvents)(ANYSET(kbdDevices)); - if (ANYSET(mseDevices)) - (xf86Info.mouseDev->mseEvents)(1); - -#else - if (XFD_ANYSET(&devicesWithInput)) - { - (xf86Info.kbdEvents)(); - (xf86Info.mouseDev->mseEvents)(xf86Info.mouseDev); - } -#endif /* __OSF__ */ - } -#else /* __EMX__ */ - - (xf86Info.kbdEvents)(); /* Under OS/2, always call */ - (xf86Info.mouseDev->mseEvents)(xf86Info.mouseDev); - -#endif /* __EMX__ */ - -#if defined(XQUEUE) && !defined(XQUEUE_ASYNC) - /* This could be done more cleanly */ - if (xf86Info.mouseDev->xqueSema && xf86Info.mouseDev->xquePending) - xf86XqueRequest(); -#endif - - if (xf86VTSwitchPending()) xf86VTSwitch(); - - if (xf86Info.inputPending) ProcessInputEvents(); +/* + * xf86RemoveEnabledDevice -- + * + */ +void +xf86RemoveEnabledDevice(InputInfoPtr pInfo) +{ + if (!xf86RemoveSIGIOHandler (pInfo->fd)) { + RemoveEnabledDevice(pInfo->fd); + } } -#endif /* AMOEBA */ +static int *xf86SignalIntercept = NULL; +void +xf86InterceptSignals(int *signo) +{ + if ((xf86SignalIntercept = signo)) + *signo = -1; +} /* * xf86SigHandler -- - * Catch unexpected signals and exit cleanly. + * Catch unexpected signals and exit or continue cleanly. */ void -xf86SigHandler(signo) - int signo; +xf86SigHandler(int signo) { + if (xf86SignalIntercept && (*xf86SignalIntercept < 0)) { + /* Re-arm handler just in case */ + (void) signal(signo, xf86SigHandler); + *xf86SignalIntercept = signo; + return; + } + signal(signo,SIG_IGN); xf86Info.caughtSignal = TRUE; +#ifdef XF86BIGFONT + XF86BigfontCleanup(); +#endif +#if defined(XFree86LOADER) + if (xf86Initialising) + LoaderCheckUnresolved(LD_RESOLV_IFDONE); + ErrorF("\n" + " *** If unresolved symbols were reported above, they might not\n" + " *** be the reason for the server aborting.\n"); +#endif FatalError("Caught signal %d. Server aborting\n", signo); } +#ifdef MEMDEBUG +void +xf86SigMemDebug(int signo) +{ + CheckMemory(); + (void) signal(signo, xf86SigMemDebug); + return; +} +#endif + /* * xf86VTSwitch -- * Handle requests for switching the vt. @@ -1407,76 +1211,261 @@ xf86SigHandler(signo) static void xf86VTSwitch() { - int j; + int i, prevSIGIO; + InputInfoPtr pInfo; + IHPtr ih; +#ifdef DEBUG + ErrorF("xf86VTSwitch()\n"); +#endif + #ifdef XFreeXDGA + if(!DGAVTSwitch()) + return; +#endif + /* - * Not ideal, but until someone adds DGA events to the DGA client we - * should protect the machine + * Since all screens are currently all in the same state it is sufficient + * check the first. This might change in future. */ - if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectGraphics) { - xf86Info.vtRequestsPending = FALSE; - return; - } + if (xf86Screens[0]->vtSema) { + +#ifdef DEBUG + ErrorF("xf86VTSwitch: Leaving, xf86Exiting is %s\n", + BOOLTOSTRING((dispatchException & DE_TERMINATE) ? TRUE : FALSE)); #endif - if (xf86VTSema) { - for (j = 0; j < screenInfo.numScreens; j++) - (XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(LEAVE, j); + for (i = 0; i < xf86NumScreens; i++) { + if (!(dispatchException & DE_TERMINATE)) + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE); + } +#if !defined(__UNIXOS2__) -#ifndef __EMX__ + /* + * Keep the order: Disable Device > LeaveVT + * EnterVT > EnableDevice + */ DisableDevice((DeviceIntPtr)xf86Info.pKeyboard); - DisableDevice((DeviceIntPtr)xf86Info.pMouse); -#endif + pInfo = xf86InputDevs; + while (pInfo) { + DisableDevice(pInfo->dev); + pInfo = pInfo->next; + } +#endif /* !__UNIXOS2__ */ + xf86EnterServerState(SETUP); + for (i = 0; i < xf86NumScreens; i++) { + xf86Screens[i]->LeaveVT(i, 0); + } + for (ih = InputHandlers; ih; ih = ih->next) + xf86DisableInputHandler(ih); + xf86AccessLeave(); /* We need this here, otherwise */ + xf86AccessLeaveState(); /* console won't be restored */ if (!xf86VTSwitchAway()) { /* * switch failed */ - for (j = 0; j < screenInfo.numScreens; j++) - (XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(ENTER, j); - SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset); -#ifdef DPMSExtension - if (DPMSEnabled) - DPMSSet(DPMSModeOn); +#ifdef DEBUG + ErrorF("xf86VTSwitch: Leave failed\n"); #endif + prevSIGIO = xf86BlockSIGIO(); + xf86AccessEnter(); + xf86EnterServerState(SETUP); + for (i = 0; i < xf86NumScreens; i++) { + if (!xf86Screens[i]->EnterVT(i, 0)) + FatalError("EnterVT failed for screen %d\n", i); + } + xf86EnterServerState(OPERATING); + if (!(dispatchException & DE_TERMINATE)) { + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE); + } + } + SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset); -#ifndef __EMX__ +#if !defined(__UNIXOS2__) EnableDevice((DeviceIntPtr)xf86Info.pKeyboard); - EnableDevice((DeviceIntPtr)xf86Info.pMouse); -#endif + pInfo = xf86InputDevs; + while (pInfo) { + EnableDevice(pInfo->dev); + pInfo = pInfo->next; + } +#endif /* !__UNIXOS2__ */ + for (ih = InputHandlers; ih; ih = ih->next) + xf86EnableInputHandler(ih); + + xf86UnblockSIGIO(prevSIGIO); } else { - xf86VTSema = FALSE; + if (xf86OSPMClose) + xf86OSPMClose(); + xf86OSPMClose = NULL; + + for (i = 0; i < xf86NumScreens; i++) { + /* + * zero all access functions to + * trap calls when switched away. + */ + xf86Screens[i]->vtSema = FALSE; + xf86Screens[i]->access = NULL; + xf86Screens[i]->busAccess = NULL; + } + xf86DisableIO(); } } else { + +#ifdef DEBUG + ErrorF("xf86VTSwitch: Entering\n"); +#endif if (!xf86VTSwitchTo()) return; - - xf86VTSema = TRUE; - for (j = 0; j < screenInfo.numScreens; j++) - (XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(ENTER, j); - + + prevSIGIO = xf86BlockSIGIO(); + xf86OSPMClose = xf86OSPMOpen(); + + xf86EnableIO(); + xf86AccessEnter(); + xf86EnterServerState(SETUP); + for (i = 0; i < xf86NumScreens; i++) { + xf86Screens[i]->vtSema = TRUE; + if (!xf86Screens[i]->EnterVT(i, 0)) + FatalError("EnterVT failed for screen %d\n", i); + } + xf86EnterServerState(OPERATING); + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess)(i, TRUE); + } + /* Turn screen saver off when switching back */ SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset); -#ifdef DPMSExtension - if (DPMSEnabled) - DPMSSet(DPMSModeOn); -#endif -#ifndef __EMX__ +#if !defined(__UNIXOS2__) EnableDevice((DeviceIntPtr)xf86Info.pKeyboard); - EnableDevice((DeviceIntPtr)xf86Info.pMouse); -#endif + pInfo = xf86InputDevs; + while (pInfo) { + EnableDevice(pInfo->dev); + pInfo = pInfo->next; + } +#endif /* !__UNIXOS2__ */ + + for (ih = InputHandlers; ih; ih = ih->next) + xf86EnableInputHandler(ih); + xf86UnblockSIGIO(prevSIGIO); } } + +/* Input handler registration */ + +pointer +xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data) +{ + IHPtr ih; + + if (fd < 0 || !proc) + return NULL; + + ih = xcalloc(sizeof(*ih), 1); + if (!ih) + return NULL; + + ih->fd = fd; + ih->ihproc = proc; + ih->data = data; + ih->enabled = TRUE; + + ih->next = InputHandlers; + InputHandlers = ih; + + AddEnabledDevice(fd); + + return ih; +} + +int +xf86RemoveInputHandler(pointer handler) +{ + IHPtr ih, p; + int fd; + + if (!handler) + return -1; + + ih = handler; + fd = ih->fd; + + if (ih->fd >= 0) + RemoveEnabledDevice(ih->fd); + + if (ih == InputHandlers) + InputHandlers = ih->next; + else { + p = InputHandlers; + while (p && p->next != ih) + p = p->next; + if (ih) + p->next = ih->next; + } + xfree(ih); + return fd; +} + +void +xf86DisableInputHandler(pointer handler) +{ + IHPtr ih; + + if (!handler) + return; + + ih = handler; + ih->enabled = FALSE; + if (ih->fd >= 0) + RemoveEnabledDevice(ih->fd); +} + +void +xf86EnableInputHandler(pointer handler) +{ + IHPtr ih; + + if (!handler) + return; + + ih = handler; + ih->enabled = TRUE; + if (ih->fd >= 0) + AddEnabledDevice(ih->fd); +} + +/* + * As used currently by the DRI, the return value is ignored. + */ +Bool +xf86EnableVTSwitch(Bool new) +{ + static Bool def = TRUE; + Bool old; + + old = VTSwitchEnabled; + if (!new) { + /* Disable VT switching */ + def = VTSwitchEnabled; + VTSwitchEnabled = FALSE; + } else { + /* Restore VT switching to default */ + VTSwitchEnabled = def; + } + return old; +} + #ifdef XTESTEXT1 void -XTestGetPointerPos(fmousex, fmousey) - short *fmousex; - short *fmousey; +XTestGetPointerPos(short *fmousex, short *fmousey) { int x,y; @@ -1488,23 +1477,14 @@ XTestGetPointerPos(fmousex, fmousey) void -XTestJumpPointer(jx, jy, dev_type) - int jx; - int jy; - int dev_type; +XTestJumpPointer(int jx, int jy, int dev_type) { miPointerAbsoluteCursor(jx, jy, GetTimeInMillis() ); } - - void -XTestGenerateEvent(dev_type, keycode, keystate, mousex, mousey) - int dev_type; - int keycode; - int keystate; - int mousex; - int mousey; +XTestGenerateEvent(int dev_type, int keycode, int keystate, int mousex, + int mousey) { xEvent tevent; @@ -1525,51 +1505,30 @@ XTestGenerateEvent(dev_type, keycode, keystate, mousex, mousey) #endif /* XTESTEXT1 */ +#ifdef WSCONS_SUPPORT -#ifdef XFreeXDGA -static void -XF86DirectVideoMoveMouse(x, y, mtime) - int x; - int y; - CARD32 mtime; -{ - xEvent xE; - - xE.u.u.type = MotionNotify; - xE.u.keyButtonPointer.time = xf86Info.lastEventTime = mtime; - xf86Info.lastEventTime = mtime; - - - xE.u.keyButtonPointer.eventY = x; - xE.u.keyButtonPointer.eventY = y; - xE.u.keyButtonPointer.rootX = x; - xE.u.keyButtonPointer.rootY = y; +/* XXX Currently XKB is mandatory. */ - if (((DeviceIntPtr)(xf86Info.pMouse))->grab) - DeliverGrabbedEvent(&xE, (xf86Info.pMouse), FALSE, 1); - else - DeliverDeviceEvents(GetSpriteWindow(), &xE, NullGrab, NullWindow, - (xf86Info.pMouse), 1); -} +extern int WSKbdToKeycode(int); -static void -XF86DirectVideoKeyEvent(xE, keycode, etype) -xEvent *xE; -int keycode; -int etype; +void +xf86PostWSKbdEvent(struct wscons_event *event) { - DeviceIntPtr keybd = (DeviceIntPtr)xf86Info.pKeyboard; - KeyClassPtr keyc = keybd->key; - BYTE *kptr; - - kptr = &keyc->down[keycode >> 3]; - xE->u.u.type = etype; - xE->u.u.detail = keycode; - - /* clear the keypress state */ - if (etype == KeyPress) { - *kptr &= ~(1 << (keycode & 7)); + int type = event->type; + int value = event->value; + unsigned int keycode; + int blocked; + + if (type == WSCONS_EVENT_KEY_UP || type == WSCONS_EVENT_KEY_DOWN) { + Bool down = (type == WSCONS_EVENT_KEY_DOWN ? TRUE : FALSE); + + /* map the scancodes to standard XFree86 scancode */ + keycode = WSKbdToKeycode(value); + if (!down) keycode |= 0x80; + /* It seems better to block SIGIO there */ + blocked = xf86BlockSIGIO(); + xf86PostKbdEvent(keycode); + xf86UnblockSIGIO(blocked); } - keybd->public.processInputProc(xE, keybd, 1); } -#endif +#endif /* WSCONS_SUPPORT */ diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index 864933a84..7c65ce888 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -1,138 +1,199 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Init.c,v 3.198 2003/02/26 09:21:38 dawes Exp $ */ + /* - * $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Init.c,v 3.66.2.2 1997/06/29 08:43:36 dawes Exp $ - * - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. + * Copyright 1991-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 Thomas Roell not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Thomas Roell makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. + * Loosely based on code bearing the following copyright: * - * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. */ -/* $Xorg: xf86Init.c,v 1.3 2000/08/17 19:50:29 cpqbld Exp $ */ -#ifndef X_NOT_STDC_ENV #include <stdlib.h> -#else -extern int atoi(); -#endif #define NEED_EVENTS #include "X.h" #include "Xmd.h" #include "Xproto.h" +#include "Xatom.h" #include "input.h" #include "servermd.h" +#include "windowstr.h" #include "scrnintstr.h" #include "site.h" +#include "mi.h" #include "compiler.h" +#ifdef XFree86LOADER +#include "loaderProcs.h" +#endif +#ifdef XFreeXDGA +#include "dgaproc.h" +#endif + +#define XF86_OS_PRIVS #include "xf86.h" -#include "xf86Procs.h" +#include "xf86Priv.h" +#include "xf86Config.h" #include "xf86_OSlib.h" #include "xf86Version.h" +#include "xf86Date.h" +#include "xf86Build.h" #include "mipointer.h" - #ifdef XINPUT #include "XI.h" #include "XIproto.h" -#include "xf86_Config.h" -#include "xf86Xinput.h" #else #include "inputstr.h" #endif +#include "xf86DDC.h" +#include "xf86Xinput.h" +#include "xf86InPriv.h" +#ifdef RENDER +#include "picturestr.h" +#endif -#include "opaque.h" +#include "globals.h" #ifdef XTESTEXT1 #include "atKeynames.h" extern int xtest_command_key; #endif /* XTESTEXT1 */ -#ifdef __EMX__ -#define seteuid(x) /*nothing*/ -#define setruid(x) /*nothing*/ -#endif -/* xf86Exiting is set while the screen is shutting down (even on a reset) */ -Bool xf86Exiting = FALSE; -Bool xf86Resetting = FALSE; -Bool xf86ProbeFailed = TRUE; -Bool xf86FlipPixels = FALSE; -#ifdef XF86VIDMODE -Bool xf86VidModeEnabled = TRUE; -Bool xf86VidModeAllowNonLocal = FALSE; -#endif -#ifdef XF86MISC -Bool xf86MiscModInDevEnabled = TRUE; -Bool xf86MiscModInDevAllowNonLocal = FALSE; -#endif -Bool xf86AllowMouseOpenFail = FALSE; -PciProbeType xf86PCIFlags = PCIProbe1; -Bool xf86ScreensOpen = FALSE; -int xf86Verbose = 1; -Bool xf86fpFlag = FALSE; -Bool xf86coFlag = FALSE; -Bool xf86sFlag = FALSE; -Bool xf86ProbeOnly = FALSE; -char xf86ConfigFile[PATH_MAX] = ""; -int xf86bpp = -1; -xrgb xf86weight = { 0, 0, 0 } ; /* RGB weighting at 16 bpp */ -double xf86rGamma=1.0, xf86gGamma=1.0, xf86bGamma=1.0; -unsigned char xf86rGammaMap[256], xf86gGammaMap[256], xf86bGammaMap[256]; -char *xf86ServerName = NULL; -Bool xf86BestRefresh = FALSE; - -int vgaIOBase = 0x3d0; -int vgaCRIndex = 0x3d4; -int vgaCRReg = 0x3d5; - -static void xf86PrintBanner( -#if NeedFunctionPrototypes - void -#endif - ); -static void xf86PrintConfig( -#if NeedFunctionPrototypes - void -#endif - ); +/* forward declarations */ + +static void xf86PrintBanner(void); +static void xf86PrintMarkers(void); +static void xf86RunVtInit(void); + #ifdef DO_CHECK_BETA -void xf86CheckBeta( -#if NeedFunctionPrototypes - int, - char * -#endif - ); static int extraDays = 0; static char *expKey = NULL; #endif -extern ScrnInfoPtr xf86Screens[]; -extern int xf86MaxScreens; -extern double pow(); -#ifdef USE_XF86_SERVERLOCK -extern void xf86UnlockServer(); -#endif -#ifdef __EMX__ +#ifdef __UNIXOS2__ extern void os2ServerVideoAccess(); #endif -xf86InfoRec xf86Info; -int xf86ScreenIndex; +void (*xf86OSPMClose)(void) = NULL; + +#ifdef XFree86LOADER +static char *baseModules[] = { + "bitmap", + "pcidata", + NULL +}; +#endif + +/* Common pixmap formats */ + +static PixmapFormatRec formats[MAXFORMATS] = { + { 1, 1, BITMAP_SCANLINE_PAD }, + { 4, 8, BITMAP_SCANLINE_PAD }, + { 8, 8, BITMAP_SCANLINE_PAD }, + { 15, 16, BITMAP_SCANLINE_PAD }, + { 16, 16, BITMAP_SCANLINE_PAD }, + { 24, 32, BITMAP_SCANLINE_PAD }, +#ifdef RENDER + { 32, 32, BITMAP_SCANLINE_PAD }, +#endif +}; +#ifdef RENDER +static int numFormats = 7; +#else +static int numFormats = 6; +#endif +static Bool formatsDone = FALSE; + +InputDriverRec xf86KEYBOARD = { + 1, + "keyboard", + NULL, + NULL, + NULL, + NULL, + 0 +}; + +static Bool +xf86CreateRootWindow(WindowPtr pWin) +{ + int ret = TRUE; + int err = Success; + ScreenPtr pScreen = pWin->drawable.pScreen; + PropertyPtr pRegProp, pOldRegProp; + CreateWindowProcPtr CreateWindow = + (CreateWindowProcPtr)(pScreen->devPrivates[xf86CreateRootWindowIndex].ptr); + +#ifdef DEBUG + ErrorF("xf86CreateRootWindow(%p)\n", pWin); +#endif + + if ( pScreen->CreateWindow != xf86CreateRootWindow ) { + /* Can't find hook we are hung on */ + xf86DrvMsg(pScreen->myNum, X_WARNING /* X_ERROR */, + "xf86CreateRootWindow %p called when not in pScreen->CreateWindow %p n", + xf86CreateRootWindow, pScreen->CreateWindow ); + } + + /* Unhook this function ... */ + pScreen->CreateWindow = CreateWindow; + pScreen->devPrivates[xf86CreateRootWindowIndex].ptr = NULL; + + /* ... and call the previous CreateWindow fuction, if any */ + if (NULL!=pScreen->CreateWindow) { + ret = (*pScreen->CreateWindow)(pWin); + } + + /* Now do our stuff */ + + if (xf86RegisteredPropertiesTable != NULL) { + if (pWin->parent == NULL && xf86RegisteredPropertiesTable != NULL) { + for (pRegProp = xf86RegisteredPropertiesTable[pScreen->myNum]; + pRegProp != NULL && err==Success; + pRegProp = pRegProp->next ) + { + Atom oldNameAtom = pRegProp->propertyName; + char *nameString; + /* propertyName was created before the screen existed, + * so the atom does not belong to any screen; + * we need to create a new atom with the same name. + */ + nameString = NameForAtom(oldNameAtom); + pRegProp->propertyName = MakeAtom(nameString, strlen(nameString), TRUE); + err = ChangeWindowProperty(pWin, + pRegProp->propertyName, pRegProp->type, + pRegProp->format, PropModeReplace, + pRegProp->size, pRegProp->data, + FALSE + ); + } + + /* Look at err */ + ret &= (err==Success); + + /* free memory */ + pOldRegProp = xf86RegisteredPropertiesTable[pScreen->myNum]; + while (pOldRegProp!=NULL) { + pRegProp = pOldRegProp->next; + xfree(pOldRegProp); + pOldRegProp = pRegProp; + } + xf86RegisteredPropertiesTable[pScreen->myNum] = NULL; + } else { + xf86Msg(X_ERROR, "xf86CreateRootWindow unexpectedly called with " + "non-root window %p (parent %p)\n", pWin, pWin->parent); + ret = FALSE; + } + } + +#ifdef DEBUG + ErrorF("xf86CreateRootWindow() returns %d\n", ret); +#endif + return (ret); +} + /* * InitOutput -- @@ -142,23 +203,38 @@ int xf86ScreenIndex; */ void -InitOutput(pScreenInfo, argc, argv) - ScreenInfo *pScreenInfo; - int argc; - char **argv; +InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) { - int i, j, scr_index; - static int numFormats = 0; - static PixmapFormatRec formats[MAXFORMATS]; + int i, j, k, scr_index; static unsigned long generation = 0; - int any_screens = 0; - -#ifdef __EMX__ +#ifdef XFree86LOADER + char **modulelist; + pointer *optionlist; +#endif + screenLayoutPtr layout; + Pix24Flags screenpix24, pix24; + MessageType pix24From = X_DEFAULT; + Bool pix24Fail = FALSE; + +#ifdef __UNIXOS2__ os2ServerVideoAccess(); /* See if we have access to the screen before doing anything */ #endif + xf86Initialising = TRUE; + + /* Do this early? */ + if (generation != serverGeneration) { + xf86ScreenIndex = AllocateScreenPrivateIndex(); + xf86CreateRootWindowIndex = AllocateScreenPrivateIndex(); + xf86PixmapIndex = AllocatePixmapPrivateIndex(); + xf86RegisteredPropertiesTable=NULL; + generation = serverGeneration; + } + if (serverGeneration == 1) { + pScreenInfo->numScreens = 0; + if ((xf86ServerName = strrchr(argv[0], '/')) != 0) xf86ServerName++; else @@ -169,119 +245,517 @@ InitOutput(pScreenInfo, argc, argv) #endif xf86PrintBanner(); + xf86PrintMarkers(); + if (xf86LogFile) { + time_t t; + const char *ct; + t = time(NULL); + ct = ctime(&t); + xf86MsgVerb(xf86LogFileFrom, 0, "Log file: \"%s\", Time: %s", + xf86LogFile, ct); + } + + /* Read and parse the config file */ + if (!xf86DoProbe && !xf86DoConfigure) { + if (!xf86HandleConfigFile()) { + xf86Msg(X_ERROR, "Error from xf86HandleConfigFile()\n"); + return; + } + } - xf86PrintConfig(); + /* + * Install signal handler for unexpected signals + */ + xf86Info.caughtSignal=FALSE; + if (!xf86Info.notrapSignals) { + signal(SIGSEGV,xf86SigHandler); + signal(SIGILL,xf86SigHandler); +#ifdef SIGEMT + signal(SIGEMT,xf86SigHandler); +#endif + signal(SIGFPE,xf86SigHandler); +#ifdef SIGBUS + signal(SIGBUS,xf86SigHandler); +#endif +#ifdef SIGSYS + signal(SIGSYS,xf86SigHandler); +#endif +#ifdef SIGXCPU + signal(SIGXCPU,xf86SigHandler); +#endif +#ifdef SIGXFSZ + signal(SIGXFSZ,xf86SigHandler); +#endif +#ifdef MEMDEBUG + signal(SIGUSR2,xf86SigMemDebug); +#endif + } xf86OpenConsole(); + xf86OSPMClose = xf86OSPMOpen(); + + /* Run an external VT Init program if specified in the config file */ + xf86RunVtInit(); + + /* Do this after XF86Config is read (it's normally in OsInit()) */ + OsInitColors(); + + /* Enable full I/O access */ + xf86EnableIO(); + +#ifdef XFree86LOADER + /* Initialise the loader */ + LoaderInit(); + + /* Tell the loader the default module search path */ + LoaderSetPath(xf86ModulePath); + +#ifdef TESTING + { + char **list, **l; + const char *subdirs[] = { + "drivers", + NULL + }; + const char *patlist[] = { + "(.*)_drv\\.so", + "(.*)_drv\\.o", + NULL + }; + ErrorF("Getting module listing...\n"); + list = LoaderListDirs(NULL, NULL); + if (list) + for (l = list; *l; l++) + ErrorF("module: %s\n", *l); + LoaderFreeDirList(list); + ErrorF("Getting video driver listing...\n"); + list = LoaderListDirs(subdirs, NULL); + if (list) + for (l = list; *l; l++) + ErrorF("video driver: %s\n", *l); + LoaderFreeDirList(list); + ErrorF("Getting driver listing...\n"); + list = LoaderListDirs(NULL, patlist); + if (list) + for (l = list; *l; l++) + ErrorF("video driver: %s\n", *l); + LoaderFreeDirList(list); + } +#endif + + /* Force load mandatory base modules */ + if (!xf86LoadModules(baseModules, NULL)) + FatalError("Unable to load required base modules, Exiting...\n"); + +#endif + + /* Do a general bus probe. This will be a PCI probe for x86 platforms */ + xf86BusProbe(); + + if (xf86DoProbe) + DoProbe(); + + if (xf86DoConfigure) + DoConfigure(); + + /* Initialise the resource broker */ + xf86ResourceBrokerInit(); + +#ifdef XFree86LOADER + /* Load all modules specified explicitly in the config file */ + if ((modulelist = xf86ModulelistFromConfig(&optionlist))) { + xf86LoadModules(modulelist, optionlist); + xfree(modulelist); + xfree(optionlist); + } + + /* Load all driver modules specified in the config file */ + if ((modulelist = xf86DriverlistFromConfig())) { + xf86LoadModules(modulelist, NULL); + xfree(modulelist); + } + + /* Setup the builtin input drivers */ + xf86AddInputDriver(&xf86KEYBOARD, NULL, 0); + /* Load all input driver modules specified in the config file. */ + if ((modulelist = xf86InputDriverlistFromConfig())) { + xf86LoadModules(modulelist, NULL); + xfree(modulelist); + } -#if !defined(AMOEBA) && !defined(MINIX) /* - * If VTInit was set, run that program with consoleFd as stdin and stdout + * It is expected that xf86AddDriver()/xf86AddInputDriver will be + * called for each driver as it is loaded. Those functions save the + * module pointers for drivers. + * XXX Nothing keeps track of them for other modules. */ + /* XXX What do we do if not all of these could be loaded? */ +#endif - if (xf86Info.vtinit) { - switch(fork()) { - case -1: - FatalError("Fork failed for VTInit (%s)\n", strerror(errno)); - break; - case 0: /* child */ - setuid(getuid()); - /* set stdin, stdout to the consoleFd */ - for (i = 0; i < 2; i++) { - if (xf86Info.consoleFd != i) { - close(i); - dup(xf86Info.consoleFd); - } - } - execl("/bin/sh", "sh", "-c", xf86Info.vtinit, NULL); - ErrorF("Warning: exec of /bin/sh failed for VTInit (%s)\n", - strerror(errno)); - exit(255); - break; - default: /* parent */ - wait(NULL); + /* + * At this point, xf86DriverList[] is all filled in with entries for + * each of the drivers to try and xf86NumDrivers has the number of + * drivers. If there are none, return now. + */ + + if (xf86NumDrivers == 0) { + xf86Msg(X_ERROR, "No drivers available.\n"); + return; + } + + /* + * Call each of the Identify functions. The Identify functions print + * out some identifying information, and anything else that might be + * needed at this early stage. + */ + + for (i = 0; i < xf86NumDrivers; i++) + /* The Identify function is mandatory, but if it isn't there continue */ + if (xf86DriverList[i]->Identify != NULL) + xf86DriverList[i]->Identify(0); + else { + xf86Msg(X_WARNING, "Driver `%s' has no Identify function\n", + xf86DriverList[i]->driverName ? xf86DriverList[i]->driverName + : "noname"); } + + /* + * Locate bus slot that had register IO enabled at server startup + */ + + xf86AccessInit(); + xf86FindPrimaryDevice(); + + /* + * Now call each of the Probe functions. Each successful probe will + * result in an extra entry added to the xf86Screens[] list for each + * instance of the hardware found. + */ + + for (i = 0; i < xf86NumDrivers; i++) { + if (xf86DriverList[i]->Probe != NULL) + xf86DriverList[i]->Probe(xf86DriverList[i], PROBE_DEFAULT); + else { + xf86MsgVerb(X_WARNING, 0, + "Driver `%s' has no Probe function (ignoring)\n", + xf86DriverList[i]->driverName ? xf86DriverList[i]->driverName + : "noname"); + } + xf86SetPciVideo(NULL,NONE); } -#endif /* !AMOEBA && !MINIX */ - /* Do this after XF86Config is read (it's normally in OsInit()) */ - OsInitColors(); + /* + * If nothing was detected, return now. + */ - for (i=0; i<256; i++) { - xf86rGammaMap[i] = (int)(pow(i/255.0,xf86rGamma)*255.0+0.5); - xf86gGammaMap[i] = (int)(pow(i/255.0,xf86gGamma)*255.0+0.5); - xf86bGammaMap[i] = (int)(pow(i/255.0,xf86bGamma)*255.0+0.5); + if (xf86NumScreens == 0) { + xf86Msg(X_ERROR, "No devices detected.\n"); + return; } - xf86Config(TRUE); /* Probe displays, and resolve modes */ + /* + * Match up the screens found by the probes against those specified + * in the config file. Remove the ones that won't be used. Sort + * them in the order specified. + */ -#ifdef XKB - xf86InitXkb(); -#endif + /* + * What is the best way to do this? + * + * For now, go through the screens allocated by the probes, and + * look for screen config entry which refers to the same device + * section as picked out by the probe. + * + */ + + for (i = 0; i < xf86NumScreens; i++) { + for (layout = xf86ConfigLayout.screens; layout->screen != NULL; + layout++) { + Bool found = FALSE; + for (j = 0; j < xf86Screens[i]->numEntities; j++) { + + GDevPtr dev = + xf86GetDevFromEntity(xf86Screens[i]->entityList[j], + xf86Screens[i]->entityInstanceList[j]); + + if (dev == layout->screen->device) { + /* A match has been found */ + xf86Screens[i]->confScreen = layout->screen; + found = TRUE; + break; + } + } + if (found) break; + } + if (layout->screen == NULL) { + /* No match found */ + xf86Msg(X_ERROR, + "Screen %d deleted because of no matching config section.\n", i); + xf86DeleteScreen(i--, 0); + } + } /* - * collect all possible formats + * If no screens left, return now. */ - formats[0].depth = 1; - formats[0].bitsPerPixel = 1; - formats[0].scanlinePad = BITMAP_SCANLINE_PAD; - numFormats++; - - for ( i=0; - i < xf86MaxScreens && xf86Screens[i] && xf86Screens[i]->configured; - i++ ) - { - /* - * At least one probe function succeeded. - */ - any_screens = 1; - /* - * add new pixmap format - */ - for ( j=0; j < numFormats; j++ ) { - - if (formats[j].depth == xf86Screens[i]->depth && - formats[j].bitsPerPixel == xf86Screens[i]->bitsPerPixel) - break; /* found */ - } - - if (j == numFormats) { /* not already there */ - formats[j].depth = xf86Screens[i]->depth; - formats[j].bitsPerPixel = xf86Screens[i]->bitsPerPixel; - formats[j].scanlinePad = BITMAP_SCANLINE_PAD; - numFormats++; - if ( numFormats > MAXFORMATS ) - FatalError( "Too many pixmap formats! Exiting\n" ); - } + if (xf86NumScreens == 0) { + xf86Msg(X_ERROR, + "Device(s) detected, but none match those in the config file.\n"); + return; + } + + xf86PostProbe(); + xf86EntityInit(); + + /* + * Sort the drivers to match the requested ording. Using a slow + * bubble sort. + */ + for (j = 0; j < xf86NumScreens - 1; j++) { + for (i = 0; i < xf86NumScreens - j - 1; i++) { + if (xf86Screens[i + 1]->confScreen->screennum < + xf86Screens[i]->confScreen->screennum) { + ScrnInfoPtr tmpScrn = xf86Screens[i + 1]; + xf86Screens[i + 1] = xf86Screens[i]; + xf86Screens[i] = tmpScrn; + } + } + } + /* Fix up the indexes */ + for (i = 0; i < xf86NumScreens; i++) { + xf86Screens[i]->scrnIndex = i; + } + + /* + * Call the driver's PreInit()'s to complete initialisation for the first + * generation. + */ + + for (i = 0; i < xf86NumScreens; i++) { + xf86EnableAccess(xf86Screens[i]); + if (xf86Screens[i]->PreInit && + xf86Screens[i]->PreInit(xf86Screens[i], 0)) + xf86Screens[i]->configured = TRUE; + } + for (i = 0; i < xf86NumScreens; i++) + if (!xf86Screens[i]->configured) + xf86DeleteScreen(i--, 0); + + /* + * If no screens left, return now. + */ + + if (xf86NumScreens == 0) { + xf86Msg(X_ERROR, + "Screen(s) found, but none have a usable configuration.\n"); + return; + } + + /* This could be moved into a separate function */ + + /* + * Check that all screens have initialised the mandatory function + * entry points. Delete those which have not. + */ + +#define WARN_SCREEN(func) \ + xf86Msg(X_ERROR, "Driver `%s' has no %s function, deleting.\n", \ + xf86Screens[i]->name, (warned++, func)) + + for (i = 0; i < xf86NumScreens; i++) { + int warned = 0; + if (xf86Screens[i]->name == NULL) { + xf86Screens[i]->name = xnfalloc(strlen("screen") + 1 + 1); + if (i < 10) + sprintf(xf86Screens[i]->name, "screen%c", i + '0'); + else + sprintf(xf86Screens[i]->name, "screen%c", i - 10 + 'A'); + xf86MsgVerb(X_WARNING, 0, + "Screen driver %d has no name set, using `%s'.\n", + i, xf86Screens[i]->name); } - if (!any_screens) - if (xf86ProbeFailed) - ErrorF("\n *** None of the configured devices were detected.***\n\n"); - else - ErrorF( - "\n *** A configured device found, but display modes could not be resolved.***\n\n"); + if (xf86Screens[i]->ScreenInit == NULL) + WARN_SCREEN("ScreenInit"); + if (xf86Screens[i]->EnterVT == NULL) + WARN_SCREEN("EnterVT"); + if (xf86Screens[i]->LeaveVT == NULL) + WARN_SCREEN("LeaveVT"); + if (warned) + xf86DeleteScreen(i--, 0); + } + + /* + * If no screens left, return now. + */ + + if (xf86NumScreens == 0) { + xf86Msg(X_ERROR, "Screen(s) found, but drivers were unusable.\n"); + return; + } + + /* XXX Should this be before or after loading dependent modules? */ if (xf86ProbeOnly) { - xf86VTSema = FALSE; + OsCleanup(); AbortDDX(); fflush(stderr); exit(0); } - } - else { + +#ifdef XFree86LOADER + /* Remove (unload) drivers that are not required */ + for (i = 0; i < xf86NumDrivers; i++) + if (xf86DriverList[i] && xf86DriverList[i]->refCount <= 0) + xf86DeleteDriver(i); +#endif + + /* + * At this stage we know how many screens there are. + */ + + for (i = 0; i < xf86NumScreens; i++) + xf86InitViewport(xf86Screens[i]); + + /* + * Collect all pixmap formats and check for conflicts at the display + * level. Should we die here? Or just delete the offending screens? + * Also, should this be done for -probeonly? + */ + screenpix24 = Pix24DontCare; + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->imageByteOrder != + xf86Screens[0]->imageByteOrder) + FatalError("Inconsistent display bitmapBitOrder. Exiting\n"); + if (xf86Screens[i]->bitmapScanlinePad != + xf86Screens[0]->bitmapScanlinePad) + FatalError("Inconsistent display bitmapScanlinePad. Exiting\n"); + if (xf86Screens[i]->bitmapScanlineUnit != + xf86Screens[0]->bitmapScanlineUnit) + FatalError("Inconsistent display bitmapScanlineUnit. Exiting\n"); + if (xf86Screens[i]->bitmapBitOrder != + xf86Screens[0]->bitmapBitOrder) + FatalError("Inconsistent display bitmapBitOrder. Exiting\n"); + + /* Determine the depth 24 pixmap format the screens would like */ + if (xf86Screens[i]->pixmap24 != Pix24DontCare) { + if (screenpix24 == Pix24DontCare) + screenpix24 = xf86Screens[i]->pixmap24; + else if (screenpix24 != xf86Screens[i]->pixmap24) + FatalError("Inconsistent depth 24 pixmap format. Exiting\n"); + } + } + /* check if screenpix24 is consistent with the config/cmdline */ + if (xf86Info.pixmap24 != Pix24DontCare) { + pix24 = xf86Info.pixmap24; + pix24From = xf86Info.pix24From; + if (screenpix24 != Pix24DontCare && screenpix24 != xf86Info.pixmap24) + pix24Fail = TRUE; + } else if (screenpix24 != Pix24DontCare) { + pix24 = screenpix24; + pix24From = X_PROBED; + } else + pix24 = Pix24Use32; + + if (pix24Fail) + FatalError("Screen(s) can't use the required depth 24 pixmap format" + " (%d). Exiting\n", PIX24TOBPP(pix24)); + + /* Initialise the depth 24 format */ + for (j = 0; j < numFormats && formats[j].depth != 24; j++) + ; + formats[j].bitsPerPixel = PIX24TOBPP(pix24); + + /* Collect additional formats */ + for (i = 0; i < xf86NumScreens; i++) { + for (j = 0; j < xf86Screens[i]->numFormats; j++) { + for (k = 0; ; k++) { + if (k >= numFormats) { + if (k >= MAXFORMATS) + FatalError("Too many pixmap formats! Exiting\n"); + formats[k] = xf86Screens[i]->formats[j]; + numFormats++; + break; + } + if (formats[k].depth == xf86Screens[i]->formats[j].depth) { + if ((formats[k].bitsPerPixel == + xf86Screens[i]->formats[j].bitsPerPixel) && + (formats[k].scanlinePad == + xf86Screens[i]->formats[j].scanlinePad)) + break; + FatalError("Inconsistent pixmap format for depth %d." + " Exiting\n", formats[k].depth); + } + } + } + } + formatsDone = TRUE; + + /* If a screen uses depth 24, show what the pixmap format is */ + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->depth == 24) { + xf86Msg(pix24From, "Depth 24 pixmap format is %d bpp\n", + PIX24TOBPP(pix24)); + break; + } + } + +#if BITMAP_SCANLINE_UNIT == 64 + /* + * cfb24 doesn't currently work on architectures with a 64 bit + * BITMAP_SCANLINE_UNIT, so check for 24 bit pixel size for pixmaps + * or framebuffers. + */ + { + Bool usesCfb24 = FALSE; + + if (PIX24TOBPP(pix24) == 24) + usesCfb24 = TRUE; + for (i = 0; i < xf86NumScreens; i++) + if (xf86Screens[i]->bitsPerPixel == 24) + usesCfb24 = TRUE; + if (usesCfb24) { + FatalError("24-bit pixel size is not supported on systems with" + " 64-bit scanlines.\n"); + } + } +#endif + +#ifdef XKB + xf86InitXkb(); +#endif + /* set up the proper access funcs */ + xf86PostPreInit(); + + AddCallback(&ServerGrabCallback, xf86GrabServerCallback, NULL); + + } else { /* * serverGeneration != 1; some OSs have to do things here, too. */ xf86OpenConsole(); + + /* + should we reopen it here? We need to deal with an already opened + device. We could leave this to the OS layer. For now we simply + close it here + */ + if (xf86OSPMClose) + xf86OSPMClose(); + if ((xf86OSPMClose = xf86OSPMOpen()) != NULL) + xf86MsgVerb(3,X_INFO,"APM registered successfully\n"); + + /* Make sure full I/O access is enabled */ + xf86EnableIO(); } +#if 0 /* * Install signal handler for unexpected signals */ + xf86Info.caughtSignal=FALSE; if (!xf86Info.notrapSignals) { - xf86Info.caughtSignal=FALSE; signal(SIGSEGV,xf86SigHandler); signal(SIGILL,xf86SigHandler); #ifdef SIGEMT @@ -301,85 +775,146 @@ InitOutput(pScreenInfo, argc, argv) signal(SIGXFSZ,xf86SigHandler); #endif } - +#endif /* - * Use the previous collected parts to setup pScreenInfo + * Use the previously collected parts to setup pScreenInfo */ - pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER; - pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; - pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD; - pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER; - pScreenInfo->numPixmapFormats = numFormats; - for ( i=0; i < numFormats; i++ ) pScreenInfo->formats[i] = formats[i]; - - if (generation != serverGeneration) - { - xf86ScreenIndex = AllocateScreenPrivateIndex(); - generation = serverGeneration; - } - - for ( i=0; - i < xf86MaxScreens && xf86Screens[i] && xf86Screens[i]->configured; - i++ ) - { - /* - * On a server-reset, we have explicitely to remap all stuff ... - * (At startuptime this is implicitely done by probing the device - */ - if (serverGeneration != 1) - { - xf86Resetting = TRUE; - xf86Exiting = FALSE; + pScreenInfo->imageByteOrder = xf86Screens[0]->imageByteOrder; + pScreenInfo->bitmapScanlinePad = xf86Screens[0]->bitmapScanlinePad; + pScreenInfo->bitmapScanlineUnit = xf86Screens[0]->bitmapScanlineUnit; + pScreenInfo->bitmapBitOrder = xf86Screens[0]->bitmapBitOrder; + pScreenInfo->numPixmapFormats = numFormats; + for (i = 0; i < numFormats; i++) + pScreenInfo->formats[i] = formats[i]; + + /* Make sure the server's VT is active */ + + if (serverGeneration != 1) { + xf86Resetting = TRUE; + /* All screens are in the same state, so just check the first */ + if (!xf86Screens[0]->vtSema) { #ifdef HAS_USL_VTS - if (!xf86VTSema) - ioctl(xf86Info.consoleFd,VT_RELDISP,VT_ACKACQ); + ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ); #endif - xf86VTSema = TRUE; - (xf86Screens[i]->EnterLeaveVT)(ENTER, i); - xf86Resetting = FALSE; - } + xf86AccessEnter(); + xf86EnterServerState(SETUP); + } + } #ifdef SCO - else { - /* - * Under SCO we must ack that we got the console at startup, - * I think this is the safest way to assure it - */ - static int once = 1; - if (once) { - once = 0; - if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) - ErrorF("VT_ACKACQ failed"); - } - } + else { + /* + * Under SCO we must ack that we got the console at startup, + * I think this is the safest way to assure it. + */ + static int once = 1; + if (once) { + once = 0; + if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) + xf86Msg(X_WARNING, "VT_ACKACQ failed"); + } + } #endif /* SCO */ - scr_index = AddScreen(xf86Screens[i]->Init, argc, argv); - if (scr_index > -1) - { + + for (i = 0; i < xf86NumScreens; i++) { + xf86EnableAccess(xf86Screens[i]); + /* + * Almost everything uses these defaults, and many of those that + * don't, will wrap them. + */ + xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess; + xf86Screens[i]->SetDGAMode = xf86SetDGAMode; + scr_index = AddScreen(xf86Screens[i]->ScreenInit, argc, argv); + if (scr_index == i) { + /* + * Hook in our ScrnInfoRec, and initialise some other pScreen + * fields. + */ screenInfo.screens[scr_index]->devPrivates[xf86ScreenIndex].ptr = (pointer)xf86Screens[i]; + xf86Screens[i]->pScreen = screenInfo.screens[scr_index]; + /* The driver should set this, but make sure it is set anyway */ + xf86Screens[i]->vtSema = TRUE; + } else { + /* This shouldn't normally happen */ + FatalError("AddScreen/ScreenInit failed for driver %d\n", i); } +#ifdef DEBUG + ErrorF("InitOutput - xf86Screens[%d]->pScreen = %p\n", + i, xf86Screens[i]->pScreen ); + ErrorF("xf86Screens[%d]->pScreen->CreateWindow = %p\n", + i, xf86Screens[i]->pScreen->CreateWindow ); +#endif + + screenInfo.screens[scr_index]->devPrivates[xf86CreateRootWindowIndex].ptr + = (void*)(xf86Screens[i]->pScreen->CreateWindow); + xf86Screens[i]->pScreen->CreateWindow = xf86CreateRootWindow; + +#ifdef RENDER + if (PictureGetSubpixelOrder (xf86Screens[i]->pScreen) == SubPixelUnknown) + { + xf86MonPtr DDC = (xf86MonPtr)(xf86Screens[i]->monitor->DDC); + PictureSetSubpixelOrder (xf86Screens[i]->pScreen, + DDC ? + (DDC->features.input_type ? + SubPixelHorizontalRGB : SubPixelNone) : + SubPixelUnknown); + } +#endif +#ifdef RANDR + if (!xf86Info.disableRandR) + xf86RandRInit (screenInfo.screens[scr_index]); + xf86Msg(xf86Info.randRFrom, "RandR %s\n", + xf86Info.disableRandR ? "disabled" : "enabled"); +#endif +#ifdef NOT_USED /* * Here we have to let the driver getting access of the VT. Note that * this doesn't mean that the graphics board may access automatically * the monitor. If the monitor is shared this is done in xf86CrossScreen! */ if (!xf86Info.sharedMonitor) (xf86Screens[i]->EnterLeaveMonitor)(ENTER); - } +#endif + } -#ifndef AMOEBA - RegisterBlockAndWakeupHandlers(xf86Block, xf86Wakeup, (void *)0); +#ifdef XFree86LOADER + if ((serverGeneration == 1) && LoaderCheckUnresolved(LD_RESOLV_IFDONE)) { + /* For now, just a warning */ + xf86Msg(X_WARNING, "Some symbols could not be resolved!\n"); + } #endif + + xf86PostScreenInit(); + + xf86InitOrigins(); + + xf86Resetting = FALSE; + xf86Initialising = FALSE; + + RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA, xf86Wakeup, + NULL); +} + + +static InputDriverPtr +MatchInput(IDevPtr pDev) +{ + int i; + + for (i = 0; i < xf86NumInputDrivers; i++) { + if (xf86InputDriverList[i] && xf86InputDriverList[i]->driverName && + xf86NameCmp(pDev->driver, xf86InputDriverList[i]->driverName) == 0) + return xf86InputDriverList[i]; + } + return NULL; } /* * InitInput -- - * Initialize all supported input devices...what else is there - * besides pointer and keyboard? Two DeviceRec's are allocated and - * registered as the system pointer and keyboard devices. + * Initialize all supported input devices. */ void @@ -387,129 +922,175 @@ InitInput(argc, argv) int argc; char **argv; { - xf86Info.vtRequestsPending = FALSE; - xf86Info.inputPending = FALSE; + IDevPtr pDev; + InputDriverPtr pDrv; + InputInfoPtr pInfo; + static InputInfoPtr coreKeyboard = NULL, corePointer = NULL; + + xf86Info.vtRequestsPending = FALSE; + xf86Info.inputPending = FALSE; #ifdef XTESTEXT1 - xtest_command_key = KEY_Begin + MIN_KEYCODE; + xtest_command_key = KEY_Begin + MIN_KEYCODE; #endif /* XTESTEXT1 */ - xf86Info.pKeyboard = AddInputDevice(xf86Info.kbdProc, TRUE); - xf86Info.pMouse = AddInputDevice(xf86Info.mouseDev->mseProc, TRUE); - RegisterKeyboardDevice((DevicePtr)xf86Info.pKeyboard); - RegisterPointerDevice((DevicePtr)xf86Info.pMouse); - -#ifdef XINPUT - (xf86Info.pMouse)->public.devicePrivate = xf86Info.mouseLocal; -#if 0 /* Is this needed?? */ - ((LocalDevicePtr) xf86Info.mouseLocal)->dev = xf86Info.pMouse; -#endif -#else - (xf86Info.pMouse)->public.devicePrivate = (pointer) xf86Info.mouseDev; -#endif - -#ifdef XINPUT - InitExtInput(); + if (serverGeneration == 1) { + /* Call the PreInit function for each input device instance. */ + for (pDev = xf86ConfigLayout.inputs; pDev && pDev->identifier; pDev++) { + /* XXX The keyboard driver is a special case for now. */ + if (!xf86NameCmp(pDev->driver, "keyboard")) { + xf86Msg(X_INFO, "Keyboard \"%s\" handled by legacy driver\n", + pDev->identifier); + continue; + } + if ((pDrv = MatchInput(pDev)) == NULL) { + xf86Msg(X_ERROR, "No Input driver matching `%s'\n", pDev->driver); + /* XXX For now, just continue. */ + continue; + } + if (!pDrv->PreInit) { + xf86MsgVerb(X_WARNING, 0, + "Input driver `%s' has no PreInit function (ignoring)\n", + pDrv->driverName); + continue; + } + pInfo = pDrv->PreInit(pDrv, pDev, 0); + if (!pInfo) { + xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n", + pDev->identifier); + continue; + } else if (!(pInfo->flags & XI86_CONFIGURED)) { + xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n", + pDev->identifier); + xf86DeleteInput(pInfo, 0); + continue; + } + if (pInfo->flags & XI86_CORE_KEYBOARD) { + if (coreKeyboard) { + xf86Msg(X_ERROR, + "Attempt to register more than one core keyboard (%s)\n", + pInfo->name); + pInfo->flags &= ~XI86_CORE_KEYBOARD; + } else { + if (!(pInfo->flags & XI86_KEYBOARD_CAPABLE)) { + /* XXX just a warning for now */ + xf86Msg(X_WARNING, + "%s: does not have core keyboard capabilities\n", + pInfo->name); + } + coreKeyboard = pInfo; + } + } + if (pInfo->flags & XI86_CORE_POINTER) { + if (corePointer) { + xf86Msg(X_ERROR, + "Attempt to register more than one core pointer (%s)\n", + pInfo->name); + pInfo->flags &= ~XI86_CORE_POINTER; + } else { + if (!(pInfo->flags & XI86_POINTER_CAPABLE)) { + /* XXX just a warning for now */ + xf86Msg(X_WARNING, + "%s: does not have core pointer capabilities\n", + pInfo->name); + } + corePointer = pInfo; + } + } + } + if (!corePointer) { + xf86Msg(X_WARNING, "No core pointer registered\n"); + /* XXX register a dummy core pointer */ + } +#ifdef NEW_KBD + if (!coreKeyboard) { + xf86Msg(X_WARNING, "No core keyboard registered\n"); + /* XXX register a dummy core keyboard */ + } #endif + } + + /* Initialise all input devices. */ + pInfo = xf86InputDevs; + while (pInfo) { + xf86ActivateDevice(pInfo); + pInfo = pInfo->next; + } - miRegisterPointerDevice(screenInfo.screens[0], (DevicePtr) xf86Info.pMouse); + if (coreKeyboard) { + xf86Info.pKeyboard = coreKeyboard->dev; + xf86Info.kbdEvents = NULL; /* to prevent the internal keybord driver usage*/ + } + else { + xf86Info.pKeyboard = AddInputDevice(xf86Info.kbdProc, TRUE); + } + if (corePointer) + xf86Info.pMouse = corePointer->dev; + RegisterKeyboardDevice(xf86Info.pKeyboard); + + miRegisterPointerDevice(screenInfo.screens[0], xf86Info.pMouse); #ifdef XINPUT - xf86XinputFinalizeInit(xf86Info.pMouse); xf86eqInit ((DevicePtr)xf86Info.pKeyboard, (DevicePtr)xf86Info.pMouse); #else - mieqInit (xf86Info.pKeyboard, xf86Info.pMouse); + mieqInit ((DevicePtr)xf86Info.pKeyboard, (DevicePtr)xf86Info.pMouse); #endif } +#ifndef SET_STDERR_NONBLOCKING +#define SET_STDERR_NONBLOCKING 1 +#endif + /* * OsVendorInit -- * OS/Vendor-specific initialisations. Called from OsInit(), which * is called by dix before establishing the well known sockets. */ -extern Bool OsDelayInitColors; - void OsVendorInit() { + static Bool beenHere = FALSE; + + /* xf86WrapperInit() is called directly from OsInit() */ #ifdef SIGCHLD signal(SIGCHLD, SIG_DFL); /* Need to wait for child processes */ #endif -#ifdef USE_XF86_SERVERLOCK - extern void xf86LockServer(); - static Bool been_here = FALSE; - - if (!been_here) { - xf86LockServer(); - been_here = TRUE; - } -#endif OsDelayInitColors = TRUE; -} - -#ifdef DPMSExtension -extern CARD16 DPMSPowerLevel; - -/* - * DPMSSet -- - * Device dependent DPMS mode setting hook. This is called whenever - * the DPMS mode is to be changed. - */ -void -DPMSSet(CARD16 level) -{ - int i; +#ifdef XFree86LOADER + loadableFonts = TRUE; +#endif - /* For each screen, set the power saver level */ - for (i = 0; i < screenInfo.numScreens; i++) { - (XF86SCRNINFO(screenInfo.screens[i])->DPMSSet)(level); - } + if (!beenHere) + xf86LogInit(); - DPMSPowerLevel = level; -} +#if SET_STDERR_NONBLOCKING + /* Set stderr to non-blocking. */ +#ifndef O_NONBLOCK +#if defined(FNDELAY) +#define O_NONBLOCK FNDELAY +#elif defined(O_NDELAY) +#define O_NONBLOCK O_NDELAY +#endif +#endif -#if 0 -/* - * DPMSGet -- - * Device dependent DPMS mode getting hook. This returns the current - * DPMS mode, or -1 if DPMS is not supported. - * - * This should hook in to the appropriate driver-level function, which - * will be added to the ScrnInfoRec. - * - * NOTES: - * 1. the calling interface should be changed to specify which - * screen to check. - * 2. It isn't clear that this function is ever used. - */ -CARD16 -DPMSGet(CARD16 *level) -{ - int i; +#ifdef O_NONBLOCK + if (!beenHere) { +#if !defined(__EMX__) + if (geteuid() == 0 && getuid() != geteuid()) +#endif + { + int status; - /* For each screen, set the power saver level */ - for (i = 0; i < screenInfo.numScreens; i++) { - ; + status = fcntl(fileno(stderr), F_GETFL, 0); + if (status != -1) { + fcntl(fileno(stderr), F_SETFL, status | O_NONBLOCK); + } } -} + } +#endif #endif -/* - * DPMSSupported -- - * Return TRUE if any screen supports DPMS. - */ -Bool -DPMSSupported(void) -{ - int i; - - /* For each screen, check if DPMS is supported */ - for (i = 0; i < screenInfo.numScreens; i++) { - if (XF86SCRNINFO(screenInfo.screens[i])->DPMSSet != (void (*)())NoopDDA) - return TRUE; - } - return FALSE; + beenHere = TRUE; } -#endif /* DPMSExtension */ /* * ddxGiveUp -- @@ -521,15 +1102,38 @@ DPMSSupported(void) void ddxGiveUp() { + int i; + + if (xf86OSPMClose) + xf86OSPMClose(); + xf86OSPMClose = NULL; + + xf86AccessLeaveState(); + + for (i = 0; i < xf86NumScreens; i++) { + /* + * zero all access functions to + * trap calls when switched away. + */ + xf86Screens[i]->vtSema = FALSE; + xf86Screens[i]->access = NULL; + xf86Screens[i]->busAccess = NULL; + } + #ifdef USE_XF86_SERVERLOCK - xf86UnlockServer(); + xf86UnlockServer(); #endif +#ifdef XFreeXDGA + DGAShutdown(); +#endif + + xf86CloseConsole(); - xf86CloseConsole(); + xf86CloseLog(); - /* If an unexpected signal was caught, dump a core for debugging */ - if (xf86Info.caughtSignal) - abort(); + /* If an unexpected signal was caught, dump a core for debugging */ + if (xf86Info.caughtSignal) + abort(); } @@ -546,18 +1150,11 @@ AbortDDX() { int i; -#if 0 - if (xf86Exiting) - return; -#endif - - xf86Exiting = TRUE; - /* * try to deinitialize all input devices */ - if (xf86Info.pMouse) (xf86Info.mouseDev->mseProc)(xf86Info.pMouse, DEVICE_CLOSE); - if (xf86Info.pKeyboard) (xf86Info.kbdProc)(xf86Info.pKeyboard, DEVICE_CLOSE); + if (xf86Info.pKeyboard) + (xf86Info.kbdProc)(xf86Info.pKeyboard, DEVICE_CLOSE); /* * try to restore the original video state @@ -566,14 +1163,25 @@ AbortDDX() /* Need the sleep when starting X from within another X session */ sleep(1); #endif - if (xf86VTSema && xf86ScreensOpen) - for ( i=0; - i < xf86MaxScreens && xf86Screens[i] && xf86Screens[i]->configured; - i++ ) - (xf86Screens[i]->EnterLeaveVT)(LEAVE, i); - + if (xf86Screens) { + if (xf86Screens[0]->vtSema) + xf86EnterServerState(SETUP); + for (i = 0; i < xf86NumScreens; i++) + if (xf86Screens[i]->vtSema) { + /* + * if we are aborting before ScreenInit() has finished + * we might not have been wrapped yet. Therefore enable + * screen explicitely. + */ + xf86EnableAccess(xf86Screens[i]); + (xf86Screens[i]->LeaveVT)(i, 0); + } + } + + xf86AccessLeave(); + /* - * This is needed for a abnormal server exit, since the normal exit stuff + * This is needed for an abnormal server exit, since the normal exit stuff * MUST also be performed (i.e. the vt must be left in a defined state) */ ddxGiveUp(); @@ -583,7 +1191,11 @@ void OsVendorFatalError() { ErrorF("\nWhen reporting a problem related to a server crash, please send\n" - "the full server output, not just the last messages\n\n"); + "the full server output, not just the last messages.\n"); + if (xf86LogFile && xf86LogFileWasOpened) + ErrorF("This can be found in the log file \"%s\".\n", xf86LogFile); + ErrorF("Please report problems to %s.\n", BUILDERADDR); + ErrorF("\n"); } /* @@ -591,24 +1203,81 @@ OsVendorFatalError() * Process device-dependent command line args. Returns 0 if argument is * not device dependent, otherwise Count of number of elements of argv * that are part of a device dependent commandline option. + * */ + + /* ARGSUSED */ int -ddxProcessArgument (argc, argv, i) - int argc; - char *argv[]; - int i; +ddxProcessArgument(int argc, char **argv, int i) { - if (getuid() == 0 && !strcmp(argv[i], "-xf86config")) + /* + * Note: can't use xalloc/xfree here because OsInit() hasn't been called + * yet. Use malloc/free instead. + */ + +#ifdef DDXOSVERRORF + static Bool beenHere = FALSE; + + if (!beenHere) { + /* + * This initialises our hook into VErrorF() for catching log messages + * that are generated before OsInit() is called. + */ + OsVendorVErrorFProc = OsVendorVErrorF; + beenHere = TRUE; + } +#endif + + /* First the options that are only allowed for root */ + if (getuid() == 0) + { + if (!strcmp(argv[i], "-modulepath")) + { + char *mp; + if (!argv[i + 1]) + return 0; + mp = malloc(strlen(argv[i + 1]) + 1); + if (!mp) + FatalError("Can't allocate memory for ModulePath\n"); + strcpy(mp, argv[i + 1]); + xf86ModulePath = mp; + xf86ModPathFrom = X_CMDLINE; + return 2; + } + else if (!strcmp(argv[i], "-logfile")) + { + char *lf; + if (!argv[i + 1]) + return 0; + lf = malloc(strlen(argv[i + 1]) + 1); + if (!lf) + FatalError("Can't allocate memory for LogFile\n"); + strcpy(lf, argv[i + 1]); + xf86LogFile = lf; + xf86LogFileFrom = X_CMDLINE; + return 2; + } + } + if (!strcmp(argv[i], "-xf86config")) { - if (!argv[i+1]) + if (!argv[i + 1]) return 0; - if (strlen(argv[i+1]) >= PATH_MAX) - FatalError("XF86Config path name too long\n"); - strcpy(xf86ConfigFile, argv[i+1]); + if (getuid() != 0 && !xf86PathIsSafe(argv[i + 1])) { + FatalError("\nInvalid argument for -xf86config\n" + "\tFor non-root users, the file specified with -xf86config must be\n" + "\ta relative path and must not contain any \"..\" elements.\n" + "\tUsing default XF86Config search path.\n\n"); + } + xf86ConfigFile = argv[i + 1]; return 2; } + if (!strcmp(argv[i],"-showunresolved")) + { + xf86ShowUnresolved = TRUE; + return 1; + } if (!strcmp(argv[i],"-probeonly")) { xf86ProbeOnly = TRUE; @@ -622,7 +1291,7 @@ ddxProcessArgument (argc, argv, i) #ifdef XF86VIDMODE if (!strcmp(argv[i],"-disableVidMode")) { - xf86VidModeEnabled = FALSE; + xf86VidModeDisabled = TRUE; return 1; } if (!strcmp(argv[i],"-allowNonLocalXvidtune")) @@ -634,7 +1303,7 @@ ddxProcessArgument (argc, argv, i) #ifdef XF86MISC if (!strcmp(argv[i],"-disableModInDev")) { - xf86MiscModInDevEnabled = FALSE; + xf86MiscModInDevDisabled = TRUE; return 1; } if (!strcmp(argv[i],"-allowNonLocalModInDev")) @@ -642,17 +1311,24 @@ ddxProcessArgument (argc, argv, i) xf86MiscModInDevAllowNonLocal = TRUE; return 1; } +#endif if (!strcmp(argv[i],"-allowMouseOpenFail")) { xf86AllowMouseOpenFail = TRUE; return 1; } -#endif if (!strcmp(argv[i],"-bestRefresh")) { xf86BestRefresh = TRUE; return 1; } + if (!strcmp(argv[i],"-ignoreABI")) + { +#ifdef XFree86LOADER + LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL); +#endif + return 1; + } #ifdef DO_CHECK_BETA if (!strcmp(argv[i],"-extendExpiry")) { @@ -663,8 +1339,34 @@ ddxProcessArgument (argc, argv, i) #endif if (!strcmp(argv[i],"-verbose")) { - if (!xf86Verbose++) - xf86Verbose = 2; + if (++i < argc && argv[i]) + { + char *end; + long val; + val = strtol(argv[i], &end, 0); + if (*end == '\0') + { + xf86Verbose = val; + return 2; + } + } + xf86Verbose++; + return 1; + } + if (!strcmp(argv[i],"-logverbose")) + { + if (++i < argc && argv[i]) + { + char *end; + long val; + val = strtol(argv[i], &end, 0); + if (*end == '\0') + { + xf86LogVerbose = val; + return 2; + } + } + xf86LogVerbose++; return 1; } if (!strcmp(argv[i],"-quiet")) @@ -675,7 +1377,6 @@ ddxProcessArgument (argc, argv, i) if (!strcmp(argv[i],"-showconfig") || !strcmp(argv[i],"-version")) { xf86PrintBanner(); - xf86PrintConfig(); exit(0); } /* Notice the -fp flag, but allow it to pass to the dix layer */ @@ -690,26 +1391,72 @@ ddxProcessArgument (argc, argv, i) xf86coFlag = TRUE; return 0; } + /* Notice the -bs flag, but allow it to pass to the dix layer */ + if (!strcmp(argv[i], "-bs")) + { + xf86bsDisableFlag = TRUE; + return 0; + } + /* Notice the +bs flag, but allow it to pass to the dix layer */ + if (!strcmp(argv[i], "+bs")) + { + xf86bsEnableFlag = TRUE; + return 0; + } /* Notice the -s flag, but allow it to pass to the dix layer */ if (!strcmp(argv[i], "-s")) { xf86sFlag = TRUE; return 0; } -#ifndef XF86MONOVGA if (!strcmp(argv[i], "-bpp")) { + if (++i >= argc) + return 0; + ErrorF("The -bpp option is no longer supported.\n" + "\tUse -depth to set the color depth, and use -fbbpp if you really\n" + "\tneed to force a non-default framebuffer (hardware) pixel format.\n"); + return 2; + } + if (!strcmp(argv[i], "-pixmap24")) + { + xf86Pix24 = Pix24Use24; + return 1; + } + if (!strcmp(argv[i], "-pixmap32")) + { + xf86Pix24 = Pix24Use32; + return 1; + } + if (!strcmp(argv[i], "-fbbpp")) + { int bpp; if (++i >= argc) return 0; if (sscanf(argv[i], "%d", &bpp) == 1) { - xf86bpp = bpp; + xf86FbBpp = bpp; return 2; } else { - ErrorF("Invalid bpp\n"); + ErrorF("Invalid fbbpp\n"); + return 0; + } + } + if (!strcmp(argv[i], "-depth")) + { + int depth; + if (++i >= argc) + return 0; + if (sscanf(argv[i], "%d", &depth) == 1) + { + xf86Depth = depth; + return 2; + } + else + { + ErrorF("Invalid depth\n"); return 0; } } @@ -720,9 +1467,9 @@ ddxProcessArgument (argc, argv, i) return 0; if (sscanf(argv[i], "%1d%1d%1d", &red, &green, &blue) == 3) { - xf86weight.red = red; - xf86weight.green = green; - xf86weight.blue = blue; + xf86Weight.red = red; + xf86Weight.green = green; + xf86Weight.blue = blue; return 2; } else @@ -738,23 +1485,78 @@ ddxProcessArgument (argc, argv, i) if (++i >= argc) return 0; if (sscanf(argv[i], "%lf", &gamma) == 1) { - if (gamma < 0.1 || gamma > 10) { - ErrorF("gamma out of range, only 0.1 < gamma_value < 10 is valid\n"); + if (gamma < GAMMA_MIN || gamma > GAMMA_MAX) { + ErrorF("gamma out of range, only %.2f <= gamma_value <= %.1f" + " is valid\n", GAMMA_MIN, GAMMA_MAX); return 0; } - if (!strcmp(argv[i-1], "-gamma")) - xf86rGamma = xf86gGamma = xf86bGamma = 1.0 / gamma; - else if (!strcmp(argv[i-1], "-rgamma")) xf86rGamma = 1.0 / gamma; - else if (!strcmp(argv[i-1], "-ggamma")) xf86gGamma = 1.0 / gamma; - else if (!strcmp(argv[i-1], "-bgamma")) xf86bGamma = 1.0 / gamma; + if (!strcmp(argv[i-1], "-gamma")) + xf86Gamma.red = xf86Gamma.green = xf86Gamma.blue = gamma; + else if (!strcmp(argv[i-1], "-rgamma")) xf86Gamma.red = gamma; + else if (!strcmp(argv[i-1], "-ggamma")) xf86Gamma.green = gamma; + else if (!strcmp(argv[i-1], "-bgamma")) xf86Gamma.blue = gamma; return 2; } } -#endif /* XF86MONOVGA */ + if (!strcmp(argv[i], "-layout")) + { + if (++i >= argc) + return 0; + xf86LayoutName = argv[i]; + return 2; + } + if (!strcmp(argv[i], "-screen")) + { + if (++i >= argc) + return 0; + xf86ScreenName = argv[i]; + return 2; + } + if (!strcmp(argv[i], "-pointer")) + { + if (++i >= argc) + return 0; + xf86PointerName = argv[i]; + return 2; + } + if (!strcmp(argv[i], "-keyboard")) + { + if (++i >= argc) + return 0; + xf86KeyboardName = argv[i]; + return 2; + } + if (!strcmp(argv[i], "-nosilk")) + { + xf86silkenMouseDisableFlag = TRUE; + return 1; + } + if (!strcmp(argv[i], "-scanpci")) + { + DoScanPci(argc, argv, i); + } + if (!strcmp(argv[i], "-probe")) + { + xf86DoProbe = TRUE; +#if 0 + DoProbe(argc, argv, i); +#endif + return 1; + } + if (!strcmp(argv[i], "-configure")) + { + if (getuid() != 0) { + ErrorF("The '-configure' option can only be used by root.\n"); + exit(1); + } + xf86DoConfigure = TRUE; + xf86AllowMouseOpenFail = TRUE; + return 1; + } + /* OS-specific processing */ return xf86ProcessArgument(argc, argv, i); } - /* * ddxUseMsg -- * Print out correct use of device dependent commandline options. @@ -768,18 +1570,36 @@ ddxUseMsg() ErrorF("\n"); ErrorF("Device Dependent Usage\n"); if (getuid() == 0) + { ErrorF("-xf86config file specify a configuration file\n"); + ErrorF("-modulepath paths specify the module search path\n"); + ErrorF("-logfile file specify a log file name\n"); + ErrorF("-configure probe for devices and write an XF86Config\n"); + } + else + { + ErrorF("-xf86config file specify a configuration file, relative to the\n"); + ErrorF(" XF86Config search path, only root can use absolute\n"); + } ErrorF("-probeonly probe for devices, then exit\n"); - ErrorF("-verbose verbose startup messages\n"); + ErrorF("-scanpci execute the scanpci module and exit\n"); + ErrorF("-verbose [n] verbose startup messages\n"); + ErrorF("-logverbose [n] verbose log messages\n"); ErrorF("-quiet minimal startup messages\n"); -#ifndef XF86MONOVGA - ErrorF("-bpp n set number of bits per pixel. Default: 8\n"); + ErrorF("-pixmap24 use 24bpp pixmaps for depth 24\n"); + ErrorF("-pixmap32 use 32bpp pixmaps for depth 24\n"); + ErrorF("-fbbpp n set bpp for the framebuffer. Default: 8\n"); + ErrorF("-depth n set colour depth. Default: 8\n"); ErrorF("-gamma f set gamma value (0.1 < f < 10.0) Default: 1.0\n"); ErrorF("-rgamma f set gamma value for red phase\n"); ErrorF("-ggamma f set gamma value for green phase\n"); ErrorF("-bgamma f set gamma value for blue phase\n"); ErrorF("-weight nnn set RGB weighting at 16 bpp. Default: 565\n"); -#endif /* XF86MONOVGA */ + ErrorF("-layout name specify the ServerLayout section name\n"); + ErrorF("-screen name specify the Screen section name\n"); + ErrorF("-keyboard name specify the core keyboard InputDevice name\n"); + ErrorF("-pointer name specify the core pointer InputDevice name\n"); + ErrorF("-nosilk disable Silken Mouse\n"); ErrorF("-flipPixels swap default black/white Pixel values\n"); #ifdef XF86VIDMODE ErrorF("-disableVidMode disable mode adjustments with xvidtune\n"); @@ -791,44 +1611,230 @@ ddxUseMsg() ErrorF(" from non-local clients\n"); ErrorF("-allowMouseOpenFail start server even if the mouse can't be initialized\n"); #endif - ErrorF("-bestRefresh Chose modes with the best refresh rate\n"); - ErrorF( - "-showconfig show which drivers are included in the server\n"); + ErrorF("-bestRefresh choose modes with the best refresh rate\n"); + ErrorF("-ignoreABI make module ABI mismatches non-fatal\n"); + ErrorF("-version show the server version\n"); + /* OS-specific usage */ xf86UseMsg(); ErrorF("\n"); } #ifndef OSNAME -#define OSNAME "unknown" +#define OSNAME " unknown" #endif #ifndef OSVENDOR #define OSVENDOR "" #endif +#ifndef PRE_RELEASE +#define PRE_RELEASE XF86_VERSION_SNAP +#endif static void xf86PrintBanner() { - ErrorF("\nXFree86 Version%s/ X Window System\n",XF86_VERSION); - ErrorF("(protocol Version %d, revision %d, vendor release %d)\n", - X_PROTOCOL, X_PROTOCOL_REVISION, VENDOR_RELEASE ); - ErrorF("Release Date: %s\n", XF86_DATE); - ErrorF("\tIf the server is older than 6-12 months, or if your card is " - "newer\n" - "\tthan the above date, look for a newer version before " - "reporting\n" - "\tproblems. (see http://www.XFree86.Org/FAQ)\n"); - ErrorF("Operating System: %s %s\n", OSNAME, OSVENDOR); +#if PRE_RELEASE + ErrorF("\n" + "This is a pre-release version of XFree86, and is not supported in any\n" + "way. Bugs may be reported to XFree86@XFree86.Org and patches submitted\n" + "to fixes@XFree86.Org. Before reporting bugs in pre-release versions,\n" + "please check the latest version in the XFree86 CVS repository\n" + "(http://www.XFree86.Org/cvs).\n"); +#endif + ErrorF("\nXFree86 Version %d.%d.%d", XF86_VERSION_MAJOR, XF86_VERSION_MINOR, + XF86_VERSION_PATCH); +#if XF86_VERSION_SNAP > 0 + ErrorF(".%d", XF86_VERSION_SNAP); +#endif + +#if XF86_VERSION_SNAP >= 900 + ErrorF(" (%d.%d.0 RC %d)", XF86_VERSION_MAJOR, XF86_VERSION_MINOR + 1, + XF86_VERSION_SNAP - 900); +#endif + +#ifdef XF86_CUSTOM_VERSION + ErrorF(" (%s)", XF86_CUSTOM_VERSION); +#endif + ErrorF("\nRelease Date: %s\n", XF86_DATE); + ErrorF("X Protocol Version %d, Revision %d, %s\n", + X_PROTOCOL, X_PROTOCOL_REVISION, XORG_RELEASE ); + ErrorF("Build Operating System:%s%s\n", OSNAME, OSVENDOR); +#ifdef BUILD_DATE + { + struct tm t; + char buf[100]; + + bzero(&t, sizeof(t)); + bzero(buf, sizeof(buf)); + t.tm_mday = BUILD_DATE % 100; + t.tm_mon = (BUILD_DATE / 100) % 100 - 1; + t.tm_year = BUILD_DATE / 10000 - 1900; + if (strftime(buf, sizeof(buf), "%d %B %Y", &t)) + ErrorF("Build Date: %s\n", buf); + } +#endif +#if defined(BUILDERSTRING) + ErrorF("%s \n",BUILDERSTRING); +#endif + ErrorF("\tBefore reporting problems, check http://www.XFree86.Org/\n" + "\tto make sure that you have the latest version.\n"); +#ifdef XFree86LOADER + ErrorF("Module Loader present\n"); +#endif } static void -xf86PrintConfig() +xf86PrintMarkers() { - int i; + /* Show what the marker symbols mean */ + ErrorF("Markers: " X_PROBE_STRING " probed, " + X_CONFIG_STRING " from config file, " + X_DEFAULT_STRING " default setting,\n" + " " X_CMDLINE_STRING " from command line, " + X_NOTICE_STRING " notice, " + X_INFO_STRING " informational,\n" + " " X_WARNING_STRING " warning, " + X_ERROR_STRING " error, " + X_NOT_IMPLEMENTED_STRING " not implemented, " + X_UNKNOWN_STRING " unknown.\n"); +} + +static void +xf86RunVtInit(void) +{ + int i; + + /* + * If VTInit was set, run that program with consoleFd as stdin and stdout + */ + + if (xf86Info.vtinit) { + switch(fork()) { + case -1: + FatalError("xf86RunVtInit: fork failed (%s)\n", strerror(errno)); + break; + case 0: /* child */ + setuid(getuid()); + /* set stdin, stdout to the consoleFd */ + for (i = 0; i < 2; i++) { + if (xf86Info.consoleFd != i) { + close(i); + dup(xf86Info.consoleFd); + } + } + execl("/bin/sh", "sh", "-c", xf86Info.vtinit, (void *)NULL); + xf86Msg(X_WARNING, "exec of /bin/sh failed for VTInit (%s)\n", + strerror(errno)); + exit(255); + break; + default: /* parent */ + wait(NULL); + } + } +} + +#ifdef XFree86LOADER +/* + * xf86LoadModules iterates over a list that is being passed in. + */ +Bool +xf86LoadModules(char **list, pointer *optlist) +{ + int errmaj, errmin; + pointer opt; + int i; + char *name; + Bool failed = FALSE; + + if (!list) + return TRUE; + + for (i = 0; list[i] != NULL; i++) { + +#ifndef NORMALISE_MODULE_NAME + name = xstrdup(list[i]); +#else + /* Normalise the module name */ + name = xf86NormalizeName(list[i]); +#endif + + /* Skip empty names */ + if (name == NULL || *name == '\0') + continue; + + if (optlist) + opt = optlist[i]; + else + opt = NULL; + + if (!LoadModule(name, NULL, NULL, NULL, opt, NULL, &errmaj, &errmin)) { + LoaderErrorMsg(NULL, name, errmaj, errmin); + failed = TRUE; + } + xfree(name); + } + return !failed; +} + +#endif + +/* Pixmap format stuff */ - ErrorF("Configured drivers:\n"); - for (i = 0; i < xf86MaxScreens; i++) - if (xf86Screens[i]) - (xf86Screens[i]->PrintIdent)(); +PixmapFormatPtr +xf86GetPixFormat(ScrnInfoPtr pScrn, int depth) +{ + int i; + static PixmapFormatRec format; /* XXX not reentrant */ + + /* + * When the formats[] list initialisation isn't complete, check the + * depth 24 pixmap config/cmdline options and screen-specified formats. + */ + + if (!formatsDone) { + if (depth == 24) { + Pix24Flags pix24 = Pix24DontCare; + + format.depth = 24; + format.scanlinePad = BITMAP_SCANLINE_PAD; + if (xf86Info.pixmap24 != Pix24DontCare) + pix24 = xf86Info.pixmap24; + else if (pScrn->pixmap24 != Pix24DontCare) + pix24 = pScrn->pixmap24; + if (pix24 == Pix24Use24) + format.bitsPerPixel = 24; + else + format.bitsPerPixel = 32; + return &format; + } + } + + for (i = 0; i < numFormats; i++) + if (formats[i].depth == depth) + break; + if (i != numFormats) + return &formats[i]; + else if (!formatsDone) { + /* Check for screen-specified formats */ + for (i = 0; i < pScrn->numFormats; i++) + if (pScrn->formats[i].depth == depth) + break; + if (i != pScrn->numFormats) + return &pScrn->formats[i]; + } + return NULL; +} + +int +xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth) +{ + PixmapFormatPtr format; + + + format = xf86GetPixFormat(pScrn, depth); + if (format) + return format->bitsPerPixel; + else + return 0; } diff --git a/hw/xfree86/common/xf86Io.c b/hw/xfree86/common/xf86Io.c index 6fddb5e89..06819bccf 100644 --- a/hw/xfree86/common/xf86Io.c +++ b/hw/xfree86/common/xf86Io.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Io.c,v 3.28.2.5 1998/02/24 19:05:55 hohndel Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Io.c,v 3.53 2003/01/15 03:29:05 dawes Exp $ */ /* * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. * @@ -21,8 +21,7 @@ * PERFORMANCE OF THIS SOFTWARE. * */ -/* $Xorg: xf86Io.c,v 1.3 2000/08/17 19:50:29 cpqbld Exp $ */ -/* Patch for PS/2 Intellimouse - Tim Goodwin 1997-11-06. */ +/* $XConsortium: xf86Io.c /main/27 1996/10/19 17:58:55 kaleb $ */ #define NEED_EVENTS #include "X.h" @@ -32,12 +31,16 @@ #include "compiler.h" -#include "xf86Procs.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS #include "xf86_OSlib.h" -#include "xf86_Config.h" +#include "mipointer.h" #ifdef XINPUT #include "xf86Xinput.h" +#include "XIproto.h" +#include "exevents.h" #endif #ifdef XKB @@ -46,18 +49,12 @@ #include <X11/extensions/XKBsrv.h> #endif -extern KeybdCtrl defaultKeyboardControl; - unsigned int xf86InitialCaps = 0; unsigned int xf86InitialNum = 0; unsigned int xf86InitialScroll = 0; #include "atKeynames.h" -extern int miPointerGetMotionEvents(DeviceIntPtr pPtr, xTimecoord *coords, - unsigned long start, unsigned long stop, - ScreenPtr pScreen); - /* * xf86KbdBell -- * Ring the terminal/keyboard bell for an amount of time proportional to @@ -74,50 +71,58 @@ xf86KbdBell(percent, pKeyboard, ctrl, unused) xf86SoundKbdBell(percent, xf86Info.bell_pitch, xf86Info.bell_duration); } -#ifdef AMOEBA -#define LED_CAP IOP_LED_CAP -#define LED_NUM IOP_LED_NUM -#define LED_SCR IOP_LED_SCROLL -#endif - -#ifdef MINIX -#define LED_CAP KBD_LEDS_CAPS -#define LED_NUM KBD_LEDS_NUM -#define LED_SCR KBD_LEDS_SCROLL -#endif +void +xf86UpdateKbdLeds() +{ + int leds = 0; + if (xf86Info.capsLock) leds |= XLED1; + if (xf86Info.numLock) leds |= XLED2; + if (xf86Info.scrollLock || xf86Info.modeSwitchLock) leds |= XLED3; + if (xf86Info.composeLock) leds |= XLED4; + xf86Info.leds = (xf86Info.leds & xf86Info.xleds) | (leds & ~xf86Info.xleds); + xf86KbdLeds(); +} void xf86KbdLeds () { - int leds = 0; -#ifdef XKB - if (!noXkbExtension) { - XkbEventCauseRec cause; - XkbSetCauseUnknown(&cause); - XkbUpdateIndicators((DeviceIntPtr)xf86Info.pKeyboard, - XkbAllIndicatorsMask, False, NULL, &cause); - return; + int leds, real_leds = 0; + +#if defined (__sparc__) + static int kbdSun = -1; + if (kbdSun == -1) { + if ((xf86Info.xkbmodel && !strcmp(xf86Info.xkbmodel, "sun")) || + (xf86Info.xkbrules && !strcmp(xf86Info.xkbrules, "sun"))) + kbdSun = 1; + else + kbdSun = 0; } -#endif -#ifdef LED_CAP - if (xf86Info.capsLock && !(xf86Info.xleds & XLED1)) - leds |= LED_CAP; - - if (xf86Info.numLock && !(xf86Info.xleds & XLED2)) - leds |= LED_NUM; - - if ((xf86Info.scrollLock || - xf86Info.modeSwitchLock || - xf86Info.composeLock) && - !(xf86Info.xleds & XLED3)) - leds |= LED_SCR; - - if ((xf86Info.leds & xf86Info.xleds) & XLED1) leds |= LED_CAP; - if ((xf86Info.leds & xf86Info.xleds) & XLED2) leds |= LED_NUM; - if ((xf86Info.leds & xf86Info.xleds) & XLED3) leds |= LED_SCR; + if (kbdSun) { + if (xf86Info.leds & 0x08) real_leds |= XLED1; + if (xf86Info.leds & 0x04) real_leds |= XLED3; + if (xf86Info.leds & 0x02) real_leds |= XLED4; + if (xf86Info.leds & 0x01) real_leds |= XLED2; + leds = real_leds; + real_leds = 0; + } else { + leds = xf86Info.leds; + } +#else + leds = xf86Info.leds; +#endif /* defined (__sparc__) */ - xf86SetKbdLeds(leds); -#endif /* LED_CAP */ +#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 + xf86SetKbdLeds(real_leds); + return; } /* @@ -131,19 +136,30 @@ xf86KbdCtrl (pKeyboard, ctrl) DevicePtr pKeyboard; /* Keyboard to alter */ KeybdCtrl *ctrl; { + int leds; xf86Info.bell_pitch = ctrl->bell_pitch; xf86Info.bell_duration = ctrl->bell_duration; xf86Info.autoRepeat = ctrl->autoRepeat; - xf86Info.leds = (ctrl->leds & ~(XCAPS | XNUM | XSCR)); xf86Info.composeLock = (ctrl->leds & XCOMP) ? TRUE : FALSE; + leds = (ctrl->leds & ~(XCAPS | XNUM | XSCR)); +#ifdef XKB + if (noXkbExtension) { +#endif + xf86Info.leds = (leds & xf86Info.xleds)|(xf86Info.leds & ~xf86Info.xleds); +#ifdef XKB + } else { + xf86Info.leds = leds; + } +#endif + xf86KbdLeds(); } /* * xf86InitKBD -- - * Reinitialize the keyboard. Only set Lockkeys accrding to ours leds. + * Reinitialize the keyboard. Only set Lockkeys according to ours leds. * Depress all other keys. */ @@ -158,7 +174,6 @@ Bool init; KeyClassRec *keyc = xf86Info.pKeyboard->key; KeySym *map = keyc->curKeySyms.map; -#ifndef MACH386 kevent.u.keyButtonPointer.time = GetTimeInMillis(); kevent.u.keyButtonPointer.rootX = 0; kevent.u.keyButtonPointer.rootY = 0; @@ -192,7 +207,6 @@ Bool init; (* pKeyboard->public.processInputProc)(&kevent, pKeyboard, 1); } } -#endif /* MACH386 */ xf86Info.scanPrefix = 0; @@ -314,7 +328,10 @@ xf86KbdProc (pKeyboard, what) (KbdCtrlProcPtr)xf86KbdCtrl); #ifdef XKB } else { - XkbComponentNamesRec names; + XkbComponentNamesRec names; + XkbDescPtr desc; + Bool foundTerminate = FALSE; + int keyc; if (XkbInitialMap) { if ((xf86Info.xkbkeymap = strchr(XkbInitialMap, '/')) != NULL) xf86Info.xkbkeymap++; @@ -343,12 +360,30 @@ xf86KbdProc (pKeyboard, what) XkbSetRulesDflts(xf86Info.xkbrules, xf86Info.xkbmodel, xf86Info.xkblayout, xf86Info.xkbvariant, xf86Info.xkboptions); + XkbInitKeyboardDeviceStruct(pKeyboard, &names, &keySyms, modMap, xf86KbdBell, (KbdCtrlProcPtr)xf86KbdCtrl); + + /* Search keymap for Terminate action */ + desc = pKeyboard->key->xkbInfo->desc; + for (keyc = desc->min_key_code; keyc <= desc->max_key_code; keyc++) { + int i; + for (i = 1; i <= XkbKeyNumActions(desc, keyc); i++) { + if (XkbKeyAction(desc, keyc, i) + && XkbKeyAction(desc, keyc, i)->type == XkbSA_Terminate) { + foundTerminate = TRUE; + goto searchdone; + } + } + } +searchdone: + xf86Info.ActionKeyBindingsSet = foundTerminate; + if (!foundTerminate) + xf86Msg(X_INFO, "Server_Terminate keybinding not found\n"); } #endif @@ -367,15 +402,21 @@ xf86KbdProc (pKeyboard, what) * passing on parts of the VT switch sequence. */ sleep(1); - if (kbdFd != -1) { - char buf[16]; - read(kbdFd, buf, 16); +#if defined(WSCONS_SUPPORT) + if (xf86Info.consType != WSCONS) { +#endif + if (kbdFd != -1) { + char buf[16]; + read(kbdFd, buf, 16); + } +#if defined(WSCONS_SUPPORT) } +#endif -#ifndef __EMX__ /* Under EMX, keyboard cannot be select()'ed */ +#if !defined(__UNIXOS2__) /* Under EMX, keyboard cannot be select()'ed */ if (kbdFd != -1) AddEnabledDevice(kbdFd); -#endif /* __EMX__ */ +#endif /* __UNIXOS2__ */ pKeyboard->public.on = TRUE; xf86InitKBD(FALSE); @@ -399,144 +440,31 @@ xf86KbdProc (pKeyboard, what) return (Success); } -/* - * xf86MseCtrl -- - * Alter the control parameters for the mouse. Note that all special - * protocol values are handled by dix. - */ - -void -xf86MseCtrl(pPointer, ctrl) - DevicePtr pPointer; - PtrCtrl *ctrl; -{ - MouseDevPtr mouse = MOUSE_DEV((DeviceIntPtr) pPointer); - - mouse->num = ctrl->num; - mouse->den = ctrl->den; - mouse->threshold = ctrl->threshold; -} - -/* - * xf86MseProc -- - * Handle the initialization, etc. of a mouse - */ - -int -xf86MseProc(pPointer, what) - DeviceIntPtr pPointer; - int what; -{ - MouseDevPtr mouse = MOUSE_DEV(pPointer); - - mouse->device = pPointer; - - return xf86MseProcAux(pPointer, what, mouse, NULL, - (PtrCtrlProcPtr)xf86MseCtrl); -} - -int -xf86MseProcAux(pPointer, what, mouse, fd, ctrl) - DeviceIntPtr pPointer; - int what; - MouseDevPtr mouse; - int *fd; - PtrCtrlProcPtr ctrl; -{ - unsigned char map[MSE_MAXBUTTONS + 1]; - int nbuttons; - int mousefd; - - switch (what) - { - case DEVICE_INIT: - pPointer->public.on = FALSE; - - /* - * [KAZU-241097] We don't know exactly how many buttons the - * device has... - */ - for (nbuttons = 0; nbuttons < MSE_MAXBUTTONS; ++nbuttons) - map[nbuttons + 1] = nbuttons + 1; - - InitPointerDeviceStruct((DevicePtr)pPointer, - map, - min(mouse->buttons, MSE_MAXBUTTONS), - miPointerGetMotionEvents, - ctrl, - miPointerGetMotionBufferSize()); - - xf86MouseInit(mouse); - - break; - - case DEVICE_ON: - - mousefd = xf86MouseOn(mouse); - - if (fd) - *fd = mousefd; - - if (mousefd != -1) { - if (mousefd == -2) { - if (fd) - *fd = -1; - } else { - if (mouse->mseType == P_PS2) - write(mousefd, "\364", 1); - - AddEnabledDevice(mousefd); - } - mouse->lastButtons = 0; - mouse->emulateState = 0; - pPointer->public.on = TRUE; - } else { - return !Success; - } - - break; - - case DEVICE_OFF: - case DEVICE_CLOSE: - - mousefd = xf86MouseOff(mouse, what == DEVICE_CLOSE); - - if (mousefd != -1) - RemoveEnabledDevice(mousefd); - - pPointer->public.on = FALSE; - usleep(300000); - break; - } - return Success; -} - -/* - * xf86MseEvents -- - * Read the new events from the device, and pass them to the eventhandler. - * This should is not used if there is only an OS_MOUSE driver. - */ -#ifndef OSMOUSE_ONLY -void -xf86MseEvents(mouse) - MouseDevPtr mouse; -{ - xf86MouseEvents(mouse); -} -#endif - -#if !defined(AMOEBA) && !(defined (sun) && defined(i386) && defined (SVR4)) && !defined(MINIX) && !defined(__mips__) +#if defined(DDXTIME) && !defined(QNX4) /* * These are getting tossed in here until I can think of where * they really belong */ +#define HALFMONTH ((unsigned long) 1<<31) CARD32 GetTimeInMillis() { struct timeval tp; + register CARD32 val; + register INT32 diff; + static CARD32 oldval = 0; + static CARD32 time = 0; gettimeofday(&tp, 0); - return(tp.tv_sec * 1000) + (tp.tv_usec / 1000); + val = (tp.tv_sec * 1000) + (tp.tv_usec / 1000); + if (oldval) { + diff = val - oldval; + if (diff > 0) + time += diff; + } + oldval = val; + + return time; } -#endif /* !AMOEBA && !(sun || SVR4) && !MINIX */ +#endif /* DDXTIME && !QNX4 */ diff --git a/hw/xfree86/common/xf86Kbd.c b/hw/xfree86/common/xf86Kbd.c index f263937a2..c1ad79778 100644 --- a/hw/xfree86/common/xf86Kbd.c +++ b/hw/xfree86/common/xf86Kbd.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Kbd.c,v 3.14 1997/01/05 11:58:08 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Kbd.c,v 3.24 2002/05/31 18:45:58 dawes Exp $ */ /* * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. * @@ -21,7 +21,7 @@ * PERFORMANCE OF THIS SOFTWARE. * */ -/* $Xorg: xf86Kbd.c,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */ +/* $XConsortium: xf86Kbd.c /main/10 1996/02/21 17:38:32 kaleb $ */ #include "X.h" #include "Xmd.h" @@ -30,13 +30,27 @@ #include "compiler.h" -#include "xf86Procs.h" +#include "xf86.h" +#include "xf86Priv.h" #include "xf86_OSlib.h" #include "atKeynames.h" -#include "xf86_Config.h" +#include "xf86Config.h" #include "xf86Keymap.h" +#if defined(KDGKBTYPE) && \ + !defined(Lynx) && \ + !defined(__UNIXOS2__) && !defined(__mips__) && \ + !defined(__arm32__) && !defined(__GNU__) && !defined(__QNX__) +#define HAS_GETKBTYPE +#endif +#if defined(GIO_KEYMAP) && \ + !defined(Lynx) && \ + !defined(__UNIXOS2__) && !defined(__mips__) && \ + !defined(__arm32__) && !defined(__GNU__) && !defined(DGUX) && \ + !defined(__QNX__) +#define HAS_GETKEYMAP + #define KD_GET_ENTRY(i,n) \ eascii_to_x[((keymap.key[i].spcl << (n+1)) & 0x100) + keymap.key[i].map[n]] @@ -208,6 +222,7 @@ static KeySym eascii_to_x[512] = { NoSymbol, NoSymbol, NoSymbol, NoSymbol, }; +#endif /* HAS_GETKEYMAP */ /* * LegalModifier -- @@ -238,14 +253,15 @@ xf86KbdGetMapping (pKeySyms, pModMap) CARD8 *pModMap; { KeySym *k; -#if !defined(Lynx) && !defined(AMOEBA) && !defined(MINIX) && !defined(__OSF__) && !defined(__EMX__) && !defined(__mips__) +#ifdef HAS_GETKEYMAP keymap_t keymap; -#endif /* !Lynx && !AMOEBA && !MINIX && !__OSF__ && !__EMX__ */ - char type; - int i, j; +#endif + int i; KeySym *pMap; + +#ifdef HAS_GETKBTYPE + char type; -#if !defined(Lynx) && !defined(AMOEBA) && !defined(MINIX) && !defined(__OSF__) && !defined(__EMX__) && !defined(__mips__) xf86Info.kbdType = ioctl(xf86Info.consoleFd, KDGKBTYPE, &type) != -1 ? type : KB_101; if (xf86Info.kbdType == KB_84) @@ -253,11 +269,14 @@ xf86KbdGetMapping (pKeySyms, pModMap) else pMap = map; #else +/* OS/2 sets the keyboard type during xf86OpenKbd */ +#ifndef __UNIXOS2__ xf86Info.kbdType = 0; +#endif pMap = map; #endif -#if !defined(Lynx) && !defined(AMOEBA) && !defined(MINIX) && !defined(__OSF__) && !defined(__EMX__) && !defined(__mips__) +#ifdef HAS_GETKEYMAP /* * use the keymap, which can be gotten from our oringinal vt??. * ( ttymap(1) !!!! ) @@ -280,59 +299,7 @@ xf86KbdGetMapping (pKeySyms, pModMap) if (k[0] == k[2] && k[1] == k[3]) k[2] = k[3] = NoSymbol; } } -#endif /* !Lynx && !AMOEBA && !MINIX && !__OSF__ && !__EMX__ */ - - /* - * Apply the special key mapping specified in XF86Config - */ - for (k = pMap, i = MIN_KEYCODE; - i < (NUM_KEYCODES + MIN_KEYCODE); - i++, k += 4) { - switch (k[0]) { - case XK_Alt_L: - j = K_INDEX_LEFTALT; - break; - case XK_Alt_R: - j = K_INDEX_RIGHTALT; - break; - case XK_Scroll_Lock: - j = K_INDEX_SCROLLLOCK; - break; - case XK_Control_R: - j = K_INDEX_RIGHTCTL; - break; - default: - j = -1; - } - if (j >= 0) - switch (xf86Info.specialKeyMap[j]) { - case KM_META: - if (k[0] == XK_Alt_R) - k[1] = XK_Meta_R; - else { - k[0] = XK_Alt_L; - k[1] = XK_Meta_L; - } - break; - case KM_COMPOSE: - k[0] = XK_Multi_key; - break; - case KM_MODESHIFT: - k[0] = XK_Mode_switch; - k[1] = NoSymbol; - break; - case KM_MODELOCK: - k[0] = XK_Mode_switch; - k[1] = XF86XK_ModeLock; - break; - case KM_SCROLLLOCK: - k[0] = XK_Scroll_Lock; - break; - case KM_CONTROL: - k[0] = XK_Control_R; - break; - } - } +#endif /* * compute the modifier map @@ -366,7 +333,7 @@ xf86KbdGetMapping (pKeySyms, pModMap) break; case XK_Num_Lock: - if (!xf86Info.serverNumLock) pModMap[i] = NumLockMask; + pModMap[i] = NumLockMask; break; case XK_Scroll_Lock: @@ -386,22 +353,8 @@ xf86KbdGetMapping (pKeySyms, pModMap) } -#if !defined(Lynx) && !defined(AMOEBA) && !defined(MINIX) && !defined(__OSF__) && !defined(__EMX__) && !defined(__mips__) - xf86Info.kbdType = - ioctl(xf86Info.consoleFd, KDGKBTYPE, &type) != -1 ? type : KB_101; -#else -/* OS/2 sets the keyboard type during xf86OpenKbd */ -#ifndef __EMX__ - xf86Info.kbdType = 0; -#endif -#endif - - pKeySyms->map = pMap; pKeySyms->mapWidth = GLYPHS_PER_KEY; pKeySyms->minKeyCode = MIN_KEYCODE; - if (xf86Info.serverNumLock) - pKeySyms->maxKeyCode = MAX_KEYCODE; - else - pKeySyms->maxKeyCode = MAX_STD_KEYCODE; + pKeySyms->maxKeyCode = MAX_KEYCODE; } diff --git a/hw/xfree86/common/xf86KbdBSD.c b/hw/xfree86/common/xf86KbdBSD.c index bf880dd68..a606b14fb 100644 --- a/hw/xfree86/common/xf86KbdBSD.c +++ b/hw/xfree86/common/xf86KbdBSD.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdBSD.c,v 3.10 1996/12/23 06:43:30 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdBSD.c,v 3.20 2002/05/22 21:38:27 herrb Exp $ */ /* * Derived from xf86Kbd.c by S_ren Schmidt (sos@login.dkuug.dk) * which is Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. @@ -22,7 +22,7 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ -/* $Xorg: xf86KbdBSD.c,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */ +/* $XConsortium: xf86KbdBSD.c /main/6 1996/10/23 13:12:27 kaleb $ */ #include "X.h" #include "Xmd.h" @@ -31,22 +31,17 @@ #include "compiler.h" -#include "xf86Procs.h" +#include "xf86.h" +#include "xf86Priv.h" #include "xf86_OSlib.h" #include "atKeynames.h" -#include "xf86_Config.h" -#include "coKeynames.h" #include "xf86Keymap.h" +#if (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)) && defined(GIO_KEYMAP) #define KD_GET_ENTRY(i,n) \ eascii_to_x[((keymap.key[i].spcl << (n+1)) & 0x100) + keymap.key[i].map[n]] -#ifndef __bsdi__ -static KeySym coGetKeysym(); -#endif - -#ifndef PC98 -static unsigned char remap[128] = { +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 */ @@ -64,27 +59,6 @@ static unsigned char remap[128] = { 0, 0, 0x69, 0x65, 0, 0, 0, 0, /* 0x70 - 0x77 */ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */ }; -#else /* PC98 */ -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, 0, 0, 0, /* 0x30 - 0x37 */ - 0, 0, 0, 0, 0, 0, 0, 0, /* 0x38 - 0x3f */ - 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x47 */ - 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */ - 0, 0, 0x52, 0x53, 0x54, 0x55, 0x56, 0, /* 0x50 - 0x57 */ - 0, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */ - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 - 0x67 */ - 0x68, 0x69, 0x6a, 0x6b, 0, 0, 0, 0, /* 0x68 - 0x6f */ - 0x70, 0x71, 0x72, 0x73, 0x74, 0, 0, 0, /* 0x70 - 0x77 */ - 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */ -}; -#endif /* PC98 */ - /* This table assumes the ibm code page 437 coding for characters * > 0x80. They are returned in this form by PCVT */ @@ -158,6 +132,74 @@ static KeySym eascii_to_x[512] = { * special marked entries (256 + x) */ +#if 1 + /* This has been checked against what syscons actually does */ + NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R, + XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L, + XK_ISO_Left_Tab,XK_Control_L, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, XK_F1, + XK_F2, XK_F3, XK_F4, XK_F5, + XK_F6, XK_F7, XK_F8, XK_F9, + XK_F10, XK_F11, XK_F12, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + XK_Control_R, XK_Alt_R, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol +#else + /* The old table, supposedly for pcvt. */ NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R, XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L, NoSymbol, XK_Control_L, XK_Alt_L, XK_Alt_R, @@ -221,6 +263,8 @@ static KeySym eascii_to_x[512] = { NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol +#endif }; #ifdef __OpenBSD__ @@ -314,6 +358,7 @@ static KeySym latin1_to_x[256] = { XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis }; #endif +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ /* * LegalModifier -- * determine whether a key is a legal modifier key, i.e send a @@ -341,8 +386,7 @@ xf86KbdGetMapping (pKeySyms, pModMap) CARD8 *pModMap; { KeySym *k; - char type; - int i, j; + int i; #ifndef __bsdi__ switch (xf86Info.consType) { @@ -453,7 +497,10 @@ xf86KbdGetMapping (pKeySyms, pModMap) break; #endif -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) +/* + * XXX wscons has no GIO_KEYMAP + */ +#if (defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)) && defined(GIO_KEYMAP) case SYSCONS: case PCVT: { @@ -461,11 +508,7 @@ xf86KbdGetMapping (pKeySyms, pModMap) if (ioctl(xf86Info.consoleFd, GIO_KEYMAP, &keymap) != -1) { for (i = 0; i < keymap.n_keys && i < NUM_KEYCODES; i++) -#ifdef PC98 - if (remap[i] || i == 0) { -#else if (remap[i]) { -#endif k = map + (remap[i] << 2); k[0] = KD_GET_ENTRY(i,0); /* non-shifed */ k[1] = KD_GET_ENTRY(i,1); /* shifted */ @@ -482,102 +525,10 @@ xf86KbdGetMapping (pKeySyms, pModMap) break; #endif /* SYSCONS || PCVT */ -#ifdef CODRV_SUPPORT - case CODRV011: - case CODRV01X: - for (i=1; i<= 128; i++) { - struct kbd_ovlkey cokeymap; - struct oldkbd_ovlkey ocokeymap; - KeySym coGetKeysym(); - - if (xf86Info.consType == CODRV011) { - ocokeymap.keynum = i; - if (ioctl(xf86Info.consoleFd, OLDKBDGCKEY, &ocokeymap) < 0) - break; /* Don't try again if it fails once */ - if ((ocokeymap.type & KBD_OVERLOAD)) { /* changed from default setting */ - k = map + (xf86CodrvMap[i] << 2); - k[0] = coGetKeysym(ocokeymap.type,(CARD8*)&ocokeymap.unshift,k[0]); - k[1] = coGetKeysym(ocokeymap.type,(CARD8*)&ocokeymap.shift,k[1]); - k[2] = coGetKeysym(ocokeymap.type,(CARD8*)&ocokeymap.altgr,k[2]); - k[3] = NoSymbol; - } - } else { - cokeymap.keynum = i; - if (ioctl(xf86Info.consoleFd, KBDGCKEY, &cokeymap) < 0) - break; /* Don't try again if it fails once */ - if ((cokeymap.type & KBD_OVERLOAD)) { /* changed from default setting */ - k = map + (xf86CodrvMap[i] << 2); - k[0] = coGetKeysym(cokeymap.type,(CARD8*)&cokeymap.unshift,k[0]); - k[1] = coGetKeysym(cokeymap.type,(CARD8*)&cokeymap.shift,k[1]); - k[2] = coGetKeysym(cokeymap.type,(CARD8*)&cokeymap.altgr,k[2]); - k[3] = coGetKeysym(cokeymap.type,(CARD8*)&cokeymap.shiftaltgr,k[3]); - } - } - if ((cokeymap.type & KBD_OVERLOAD)) { /* changed from default setting */ - 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 /* CODRV */ } #endif /* !bsdi */ /* - * Apply the special key mapping specified in XF86Config - */ - for (k = map, i = MIN_KEYCODE; - i < (NUM_KEYCODES + MIN_KEYCODE); - i++, k += 4) { - switch (k[0]) { - case XK_Alt_L: - j = K_INDEX_LEFTALT; - break; - case XK_Alt_R: - j = K_INDEX_RIGHTALT; - break; - case XK_Scroll_Lock: - j = K_INDEX_SCROLLLOCK; - break; - case XK_Control_R: - j = K_INDEX_RIGHTCTL; - break; - default: - j = -1; - } - if (j >= 0) - switch (xf86Info.specialKeyMap[j]) { - case KM_META: - if (k[0] == XK_Alt_R) - k[1] = XK_Meta_R; - else { - k[0] = XK_Alt_L; - k[1] = XK_Meta_L; - } - break; - case KM_COMPOSE: - k[0] = XK_Multi_key; - break; - case KM_MODESHIFT: - k[0] = XK_Mode_switch; - k[1] = NoSymbol; - break; - case KM_MODELOCK: - k[0] = XK_Mode_switch; - k[1] = XF86XK_ModeLock; - break; - case KM_SCROLLLOCK: - k[0] = XK_Scroll_Lock; - break; - case KM_CONTROL: - k[0] = XK_Control_R; - break; - } - } - - /* * compute the modifier map */ for (i = 0; i < MAP_LENGTH; i++) @@ -609,7 +560,7 @@ xf86KbdGetMapping (pKeySyms, pModMap) break; case XK_Num_Lock: - if (!xf86Info.serverNumLock) pModMap[i] = NumLockMask; + pModMap[i] = NumLockMask; break; case XK_Scroll_Lock: @@ -634,54 +585,649 @@ xf86KbdGetMapping (pKeySyms, pModMap) pKeySyms->map = map; pKeySyms->mapWidth = GLYPHS_PER_KEY; pKeySyms->minKeyCode = MIN_KEYCODE; - if (xf86Info.serverNumLock) - pKeySyms->maxKeyCode = MAX_KEYCODE; - else - pKeySyms->maxKeyCode = MAX_STD_KEYCODE; + pKeySyms->maxKeyCode = MAX_KEYCODE; } -#ifdef CODRV_SUPPORT -/* Converts a CoDriver ASCII+Special combination into a KeySym +#ifdef WSCONS_SUPPORT +#include "atKeynames.h" + +static CARD8 wsUsbMap[] = { + /* 0 */ KEY_NOTUSED, + /* 1 */ KEY_NOTUSED, + /* 2 */ KEY_NOTUSED, + /* 3 */ KEY_NOTUSED, + /* 4 */ KEY_A, + /* 5 */ KEY_B, + /* 6 */ KEY_C, + /* 7 */ KEY_D, + /* 8 */ KEY_E, + /* 9 */ KEY_F, + /* 10 */ KEY_G, + /* 11 */ KEY_H, + /* 12 */ KEY_I, + /* 13 */ KEY_J, + /* 14 */ KEY_K, + /* 15 */ KEY_L, + /* 16 */ KEY_M, + /* 17 */ KEY_N, + /* 18 */ KEY_O, + /* 19 */ KEY_P, + /* 20 */ KEY_Q, + /* 21 */ KEY_R, + /* 22 */ KEY_S, + /* 23 */ KEY_T, + /* 24 */ KEY_U, + /* 25 */ KEY_V, + /* 26 */ KEY_W, + /* 27 */ KEY_X, + /* 28 */ KEY_Y, + /* 29 */ KEY_Z, + /* 30 */ KEY_1, /* 1 !*/ + /* 31 */ KEY_2, /* 2 @ */ + /* 32 */ KEY_3, /* 3 # */ + /* 33 */ KEY_4, /* 4 $ */ + /* 34 */ KEY_5, /* 5 % */ + /* 35 */ KEY_6, /* 6 ^ */ + /* 36 */ KEY_7, /* 7 & */ + /* 37 */ KEY_8, /* 8 * */ + /* 38 */ KEY_9, /* 9 ( */ + /* 39 */ KEY_0, /* 0 ) */ + /* 40 */ KEY_Enter, /* Return */ + /* 41 */ KEY_Escape, /* Escape */ + /* 42 */ KEY_BackSpace, /* Backspace Delete */ + /* 43 */ KEY_Tab, /* Tab */ + /* 44 */ KEY_Space, /* Space */ + /* 45 */ KEY_Minus, /* - _ */ + /* 46 */ KEY_Equal, /* = + */ + /* 47 */ KEY_LBrace, /* [ { */ + /* 48 */ KEY_RBrace, /* ] } */ + /* 49 */ KEY_BSlash, /* \ | */ + /* 50 */ KEY_BSlash2, /* \ _ # ~ on some keyboards */ + /* 51 */ KEY_SemiColon, /* ; : */ + /* 52 */ KEY_Quote, /* ' " */ + /* 53 */ KEY_Tilde, /* ` ~ */ + /* 54 */ KEY_Comma, /* , < */ + /* 55 */ KEY_Period, /* . > */ + /* 56 */ KEY_Slash, /* / ? */ + /* 57 */ KEY_CapsLock, /* Caps Lock */ + /* 58 */ KEY_F1, /* F1 */ + /* 59 */ KEY_F2, /* F2 */ + /* 60 */ KEY_F3, /* F3 */ + /* 61 */ KEY_F4, /* F4 */ + /* 62 */ KEY_F5, /* F5 */ + /* 63 */ KEY_F6, /* F6 */ + /* 64 */ KEY_F7, /* F7 */ + /* 65 */ KEY_F8, /* F8 */ + /* 66 */ KEY_F9, /* F9 */ + /* 67 */ KEY_F10, /* F10 */ + /* 68 */ KEY_F11, /* F11 */ + /* 69 */ KEY_F12, /* F12 */ + /* 70 */ KEY_Print, /* PrintScrn SysReq */ + /* 71 */ KEY_ScrollLock, /* Scroll Lock */ + /* 72 */ KEY_Pause, /* Pause Break */ + /* 73 */ KEY_Insert, /* Insert XXX Help on some Mac Keyboards */ + /* 74 */ KEY_Home, /* Home */ + /* 75 */ KEY_PgUp, /* Page Up */ + /* 76 */ KEY_Delete, /* Delete */ + /* 77 */ KEY_End, /* End */ + /* 78 */ KEY_PgDown, /* Page Down */ + /* 79 */ KEY_Right, /* Right Arrow */ + /* 80 */ KEY_Left, /* Left Arrow */ + /* 81 */ KEY_Down, /* Down Arrow */ + /* 82 */ KEY_Up, /* Up Arrow */ + /* 83 */ KEY_NumLock, /* Num Lock */ + /* 84 */ KEY_KP_Divide, /* Keypad / */ + /* 85 */ KEY_KP_Multiply, /* Keypad * */ + /* 86 */ KEY_KP_Minus, /* Keypad - */ + /* 87 */ KEY_KP_Plus, /* Keypad + */ + /* 88 */ KEY_KP_Enter, /* Keypad Enter */ + /* 89 */ KEY_KP_1, /* Keypad 1 End */ + /* 90 */ KEY_KP_2, /* Keypad 2 Down */ + /* 91 */ KEY_KP_3, /* Keypad 3 Pg Down */ + /* 92 */ KEY_KP_4, /* Keypad 4 Left */ + /* 93 */ KEY_KP_5, /* Keypad 5 */ + /* 94 */ KEY_KP_6, /* Keypad 6 */ + /* 95 */ KEY_KP_7, /* Keypad 7 Home */ + /* 96 */ KEY_KP_8, /* Keypad 8 Up */ + /* 97 */ KEY_KP_9, /* KEypad 9 Pg Up */ + /* 98 */ KEY_KP_0, /* Keypad 0 Ins */ + /* 99 */ KEY_KP_Decimal, /* Keypad . Del */ + /* 100 */ KEY_Less, /* < > on some keyboards */ + /* 101 */ KEY_Menu, /* Menu */ + /* 102 */ KEY_NOTUSED, + /* 103 */ KEY_KP_Equal, /* Keypad = on Mac keyboards */ + /* 104 */ KEY_NOTUSED, + /* 105 */ KEY_NOTUSED, + /* 106 */ KEY_NOTUSED, + /* 107 */ KEY_NOTUSED, + /* 108 */ KEY_NOTUSED, + /* 109 */ KEY_NOTUSED, + /* 110 */ KEY_NOTUSED, + /* 111 */ KEY_NOTUSED, + /* 112 */ KEY_NOTUSED, + /* 113 */ KEY_NOTUSED, + /* 114 */ KEY_NOTUSED, + /* 115 */ KEY_NOTUSED, + /* 116 */ KEY_NOTUSED, + /* 117 */ KEY_NOTUSED, + /* 118 */ KEY_NOTUSED, + /* 119 */ KEY_NOTUSED, + /* 120 */ KEY_NOTUSED, + /* 121 */ KEY_NOTUSED, + /* 122 */ KEY_NOTUSED, + /* 123 */ KEY_NOTUSED, + /* 124 */ KEY_NOTUSED, + /* 125 */ KEY_NOTUSED, + /* 126 */ KEY_NOTUSED, + /* 127 */ KEY_NOTUSED, + /* 128 */ KEY_NOTUSED, + /* 129 */ KEY_NOTUSED, + /* 130 */ KEY_NOTUSED, + /* 131 */ KEY_NOTUSED, + /* 132 */ KEY_NOTUSED, + /* 133 */ KEY_NOTUSED, + /* 134 */ KEY_NOTUSED, + /* 135 */ KEY_NOTUSED, + /* 136 */ KEY_NOTUSED, + /* 137 */ KEY_NOTUSED, + /* 138 */ KEY_NOTUSED, + /* 139 */ KEY_NOTUSED, + /* 140 */ KEY_NOTUSED, + /* 141 */ KEY_NOTUSED, + /* 142 */ KEY_NOTUSED, + /* 143 */ KEY_NOTUSED, + /* 144 */ KEY_NOTUSED, + /* 145 */ KEY_NOTUSED, + /* 146 */ KEY_NOTUSED, + /* 147 */ KEY_NOTUSED, + /* 148 */ KEY_NOTUSED, + /* 149 */ KEY_NOTUSED, + /* 150 */ KEY_NOTUSED, + /* 151 */ KEY_NOTUSED, + /* 152 */ KEY_NOTUSED, + /* 153 */ KEY_NOTUSED, + /* 154 */ KEY_NOTUSED, + /* 155 */ KEY_NOTUSED, + /* 156 */ KEY_NOTUSED, + /* 157 */ KEY_NOTUSED, + /* 158 */ KEY_NOTUSED, + /* 159 */ KEY_NOTUSED, + /* 160 */ KEY_NOTUSED, + /* 161 */ KEY_NOTUSED, + /* 162 */ KEY_NOTUSED, + /* 163 */ KEY_NOTUSED, + /* 164 */ KEY_NOTUSED, + /* 165 */ KEY_NOTUSED, + /* 166 */ KEY_NOTUSED, + /* 167 */ KEY_NOTUSED, + /* 168 */ KEY_NOTUSED, + /* 169 */ KEY_NOTUSED, + /* 170 */ KEY_NOTUSED, + /* 171 */ KEY_NOTUSED, + /* 172 */ KEY_NOTUSED, + /* 173 */ KEY_NOTUSED, + /* 174 */ KEY_NOTUSED, + /* 175 */ KEY_NOTUSED, + /* 176 */ KEY_NOTUSED, + /* 177 */ KEY_NOTUSED, + /* 178 */ KEY_NOTUSED, + /* 179 */ KEY_NOTUSED, + /* 180 */ KEY_NOTUSED, + /* 181 */ KEY_NOTUSED, + /* 182 */ KEY_NOTUSED, + /* 183 */ KEY_NOTUSED, + /* 184 */ KEY_NOTUSED, + /* 185 */ KEY_NOTUSED, + /* 186 */ KEY_NOTUSED, + /* 187 */ KEY_NOTUSED, + /* 188 */ KEY_NOTUSED, + /* 189 */ KEY_NOTUSED, + /* 190 */ KEY_NOTUSED, + /* 191 */ KEY_NOTUSED, + /* 192 */ KEY_NOTUSED, + /* 193 */ KEY_NOTUSED, + /* 194 */ KEY_NOTUSED, + /* 195 */ KEY_NOTUSED, + /* 196 */ KEY_NOTUSED, + /* 197 */ KEY_NOTUSED, + /* 198 */ KEY_NOTUSED, + /* 199 */ KEY_NOTUSED, + /* 200 */ KEY_NOTUSED, + /* 201 */ KEY_NOTUSED, + /* 202 */ KEY_NOTUSED, + /* 203 */ KEY_NOTUSED, + /* 204 */ KEY_NOTUSED, + /* 205 */ KEY_NOTUSED, + /* 206 */ KEY_NOTUSED, + /* 207 */ KEY_NOTUSED, + /* 208 */ KEY_NOTUSED, + /* 209 */ KEY_NOTUSED, + /* 210 */ KEY_NOTUSED, + /* 211 */ KEY_NOTUSED, + /* 212 */ KEY_NOTUSED, + /* 213 */ KEY_NOTUSED, + /* 214 */ KEY_NOTUSED, + /* 215 */ KEY_NOTUSED, + /* 216 */ KEY_NOTUSED, + /* 217 */ KEY_NOTUSED, + /* 218 */ KEY_NOTUSED, + /* 219 */ KEY_NOTUSED, + /* 220 */ KEY_NOTUSED, + /* 221 */ KEY_NOTUSED, + /* 222 */ KEY_NOTUSED, + /* 223 */ KEY_NOTUSED, + /* 224 */ KEY_LCtrl, /* Left Control */ + /* 225 */ KEY_ShiftL, /* Left Shift */ + /* 226 */ KEY_Alt, /* Left Alt */ + /* 227 */ KEY_LMeta, /* Left Meta */ + /* 228 */ KEY_RCtrl, /* Right Control */ + /* 229 */ KEY_ShiftR, /* Right Shift */ + /* 230 */ KEY_AltLang, /* Right Alt, AKA AltGr */ + /* 231 */ KEY_LMeta, /* Right Meta XXX */ +}; + +#define WS_USB_MAP_SIZE (sizeof(wsUsbMap)/sizeof(unsigned char)) + +/* Map for adb keyboards */ +static CARD8 wsAdbMap[] = { + /* 0 */ KEY_A, + /* 1 */ KEY_S, + /* 2 */ KEY_D, + /* 3 */ KEY_F, + /* 4 */ KEY_H, + /* 5 */ KEY_G, + /* 6 */ KEY_Z, + /* 7 */ KEY_X, + /* 8 */ KEY_C, + /* 9 */ KEY_V, + /* 10 */ KEY_UNKNOWN, /* @ # on french keyboards */ + /* 11 */ KEY_B, + /* 12 */ KEY_Q, + /* 13 */ KEY_W, + /* 14 */ KEY_E, + /* 15 */ KEY_R, + /* 16 */ KEY_Y, + /* 17 */ KEY_T, + /* 18 */ KEY_1, + /* 19 */ KEY_2, + /* 20 */ KEY_3, + /* 21 */ KEY_4, + /* 22 */ KEY_6, + /* 23 */ KEY_5, + /* 24 */ KEY_Equal, + /* 25 */ KEY_9, + /* 26 */ KEY_7, + /* 27 */ KEY_Minus, + /* 28 */ KEY_8, + /* 29 */ KEY_0, + /* 30 */ KEY_RBrace, + /* 31 */ KEY_O, + /* 32 */ KEY_U, + /* 33 */ KEY_LBrace, + /* 34 */ KEY_I, + /* 35 */ KEY_P, + /* 36 */ KEY_Enter, + /* 37 */ KEY_L, + /* 38 */ KEY_J, + /* 39 */ KEY_Quote, + /* 40 */ KEY_K, + /* 41 */ KEY_SemiColon, + /* 42 */ KEY_BSlash, + /* 43 */ KEY_Comma, + /* 44 */ KEY_Slash, + /* 45 */ KEY_N, + /* 46 */ KEY_M, + /* 47 */ KEY_Period, + /* 48 */ KEY_Tab, + /* 49 */ KEY_Space, + /* 50 */ KEY_Tilde, + /* 51 */ KEY_Delete, + /* 52 */ KEY_AltLang, + /* 53 */ KEY_Escape, + /* 54 */ KEY_LCtrl, + /* 55 */ KEY_Alt, + /* 56 */ KEY_ShiftL, + /* 57 */ KEY_CapsLock, + /* 58 */ KEY_LMeta, + /* 59 */ KEY_Left, + /* 60 */ KEY_Right, + /* 61 */ KEY_Down, + /* 62 */ KEY_Up, + /* 63 */ KEY_UNKNOWN, /* Fn */ + /* 64 */ KEY_NOTUSED, + /* 65 */ KEY_KP_Decimal, + /* 66 */ KEY_NOTUSED, + /* 67 */ KEY_KP_Multiply, + /* 68 */ KEY_NOTUSED, + /* 69 */ KEY_KP_Plus, + /* 70 */ KEY_NOTUSED, + /* 71 */ KEY_UNKNOWN, /* Clear */ + /* 72 */ KEY_NOTUSED, + /* 73 */ KEY_NOTUSED, + /* 74 */ KEY_NOTUSED, + /* 75 */ KEY_KP_Divide, + /* 76 */ KEY_KP_Enter, + /* 77 */ KEY_NOTUSED, + /* 78 */ KEY_KP_Minus, + /* 79 */ KEY_NOTUSED, + /* 80 */ KEY_NOTUSED, + /* 81 */ KEY_KP_Equal, /* Keypad = */ + /* 82 */ KEY_KP_0, + /* 83 */ KEY_KP_1, + /* 84 */ KEY_KP_2, + /* 85 */ KEY_KP_3, + /* 86 */ KEY_KP_4, + /* 87 */ KEY_KP_5, + /* 88 */ KEY_KP_6, + /* 89 */ KEY_KP_7, + /* 90 */ KEY_NOTUSED, + /* 91 */ KEY_KP_8, + /* 92 */ KEY_KP_9, + /* 93 */ KEY_NOTUSED, + /* 94 */ KEY_NOTUSED, + /* 95 */ KEY_UNKNOWN, /* Keypad , */ + /* 96 */ KEY_F5, + /* 97 */ KEY_F6, + /* 98 */ KEY_F7, + /* 99 */ KEY_F3, + /* 100 */ KEY_F8, + /* 101 */ KEY_F9, + /* 102 */ KEY_NOTUSED, + /* 103 */ KEY_F11, + /* 104 */ KEY_NOTUSED, + /* 105 */ KEY_NOTUSED, + /* 106 */ KEY_KP_Enter, + /* 107 */ KEY_NOTUSED, + /* 108 */ KEY_NOTUSED, + /* 109 */ KEY_F10, + /* 110 */ KEY_NOTUSED, + /* 111 */ KEY_F12, + /* 112 */ KEY_NOTUSED, + /* 113 */ KEY_NOTUSED, + /* 114 */ KEY_NOTUSED, + /* 115 */ KEY_Home, + /* 116 */ KEY_PgUp, + /* 117 */ KEY_NOTUSED, + /* 118 */ KEY_F4, + /* 119 */ KEY_End, + /* 120 */ KEY_F2, + /* 121 */ KEY_PgDown, + /* 122 */ KEY_F1, + /* 123 */ KEY_NOTUSED, + /* 124 */ KEY_NOTUSED, + /* 125 */ KEY_NOTUSED, + /* 126 */ KEY_NOTUSED, + /* 127 */ KEY_NOTUSED, + /* 128 */ KEY_NOTUSED, + /* 129 */ KEY_NOTUSED, + /* 130 */ KEY_NOTUSED, + /* 131 */ KEY_NOTUSED, + /* 132 */ KEY_NOTUSED, + /* 133 */ KEY_NOTUSED, + /* 134 */ KEY_NOTUSED, + /* 135 */ KEY_NOTUSED, + /* 136 */ KEY_NOTUSED, + /* 137 */ KEY_NOTUSED, + /* 138 */ KEY_NOTUSED, + /* 139 */ KEY_NOTUSED, + /* 140 */ KEY_NOTUSED, + /* 141 */ KEY_NOTUSED, + /* 142 */ KEY_NOTUSED, + /* 143 */ KEY_NOTUSED, + /* 144 */ KEY_NOTUSED, + /* 145 */ KEY_NOTUSED, + /* 146 */ KEY_NOTUSED, + /* 147 */ KEY_NOTUSED, + /* 148 */ KEY_NOTUSED, + /* 149 */ KEY_NOTUSED, + /* 150 */ KEY_NOTUSED, + /* 151 */ KEY_NOTUSED, + /* 152 */ KEY_NOTUSED, + /* 153 */ KEY_NOTUSED, + /* 154 */ KEY_NOTUSED, + /* 155 */ KEY_NOTUSED, + /* 156 */ KEY_NOTUSED, + /* 157 */ KEY_NOTUSED, + /* 158 */ KEY_NOTUSED, + /* 159 */ KEY_NOTUSED, + /* 160 */ KEY_NOTUSED, + /* 161 */ KEY_NOTUSED, + /* 162 */ KEY_NOTUSED, + /* 163 */ KEY_NOTUSED, + /* 164 */ KEY_NOTUSED, + /* 165 */ KEY_NOTUSED, + /* 166 */ KEY_NOTUSED, + /* 167 */ KEY_NOTUSED, + /* 168 */ KEY_NOTUSED, + /* 169 */ KEY_NOTUSED, + /* 170 */ KEY_NOTUSED, + /* 171 */ KEY_NOTUSED, + /* 172 */ KEY_NOTUSED, + /* 173 */ KEY_NOTUSED, + /* 174 */ KEY_NOTUSED, + /* 175 */ KEY_NOTUSED, + /* 176 */ KEY_NOTUSED, + /* 177 */ KEY_NOTUSED, + /* 178 */ KEY_NOTUSED, + /* 179 */ KEY_NOTUSED, + /* 180 */ KEY_NOTUSED, + /* 181 */ KEY_NOTUSED, + /* 182 */ KEY_NOTUSED, + /* 183 */ KEY_NOTUSED, + /* 184 */ KEY_NOTUSED, + /* 185 */ KEY_NOTUSED, + /* 186 */ KEY_NOTUSED, + /* 187 */ KEY_NOTUSED, + /* 188 */ KEY_NOTUSED, + /* 189 */ KEY_NOTUSED, + /* 190 */ KEY_NOTUSED, + /* 191 */ KEY_NOTUSED, + /* 192 */ KEY_NOTUSED, + /* 193 */ KEY_NOTUSED, + /* 194 */ KEY_NOTUSED, + /* 195 */ KEY_NOTUSED, + /* 196 */ KEY_NOTUSED, + /* 197 */ KEY_NOTUSED, + /* 198 */ KEY_NOTUSED, + /* 199 */ KEY_NOTUSED, + /* 200 */ KEY_NOTUSED, + /* 201 */ KEY_NOTUSED, + /* 202 */ KEY_NOTUSED, + /* 203 */ KEY_NOTUSED, + /* 204 */ KEY_NOTUSED, + /* 205 */ KEY_NOTUSED, + /* 206 */ KEY_NOTUSED, + /* 207 */ KEY_NOTUSED, + /* 208 */ KEY_NOTUSED, + /* 209 */ KEY_NOTUSED, + /* 210 */ KEY_NOTUSED, + /* 211 */ KEY_NOTUSED, + /* 212 */ KEY_NOTUSED, + /* 213 */ KEY_NOTUSED, + /* 214 */ KEY_NOTUSED, + /* 215 */ KEY_NOTUSED, + /* 216 */ KEY_NOTUSED, + /* 217 */ KEY_NOTUSED, + /* 218 */ KEY_NOTUSED, + /* 219 */ KEY_NOTUSED, + /* 220 */ KEY_NOTUSED, + /* 221 */ KEY_NOTUSED, + /* 222 */ KEY_NOTUSED, + /* 223 */ KEY_NOTUSED, +}; + +static CARD8 wsSunMap[] = { + /* 0x00 */ KEY_NOTUSED, + /* 0x01 */ KEY_NOTUSED, /* stop */ + /* 0x02 */ KEY_NOTUSED, /* BrightnessDown / S-VolumeDown */ + /* 0x03 */ KEY_NOTUSED, /* again */ + /* 0x04 */ KEY_NOTUSED, /* BridgtnessUp / S-VolumeUp */ + /* 0x05 */ KEY_F1, + /* 0x06 */ KEY_F2, + /* 0x07 */ KEY_F10, + /* 0x08 */ KEY_F3, + /* 0x09 */ KEY_F11, + /* 0x0a */ KEY_F4, + /* 0x0b */ KEY_F12, + /* 0x0c */ KEY_F5, + /* 0x0d */ KEY_AltLang, + /* 0x0e */ KEY_F6, + /* 0x0f */ KEY_NOTUSED, + /* 0x10 */ KEY_F7, + /* 0x11 */ KEY_F8, + /* 0x12 */ KEY_F9, + /* 0x13 */ KEY_Alt, + /* 0x14 */ KEY_Up, + /* 0x15 */ KEY_Pause, + /* 0x16 */ KEY_Print, + /* 0x17 */ KEY_NOTUSED, /* props */ + /* 0x18 */ KEY_Left, + /* 0x19 */ KEY_ScrollLock, + /* 0x1a */ KEY_NOTUSED, /* undo */ + /* 0x1b */ KEY_Down, + /* 0x1c */ KEY_Right, + /* 0x1d */ KEY_Escape, + /* 0x1e */ KEY_1, + /* 0x1f */ KEY_2, + /* 0x20 */ KEY_3, + /* 0x21 */ KEY_4, + /* 0x22 */ KEY_5, + /* 0x23 */ KEY_6, + /* 0x24 */ KEY_7, + /* 0x25 */ KEY_8, + /* 0x26 */ KEY_9, + /* 0x27 */ KEY_0, + /* 0x28 */ KEY_Minus, + /* 0x29 */ KEY_Equal, + /* 0x2a */ KEY_Tilde, + /* 0x2b */ KEY_BackSpace, + /* 0x2c */ KEY_Insert, + /* 0x2d */ KEY_KP_Equal, + /* 0x2e */ KEY_KP_Divide, + /* 0x2f */ KEY_KP_Multiply, + /* 0x30 */ KEY_NOTUSED, + /* 0x31 */ KEY_NOTUSED, /* front */ + /* 0x32 */ KEY_KP_Decimal, + /* 0x33 */ KEY_NOTUSED, /* copy */ + /* 0x34 */ KEY_Home, + /* 0x35 */ KEY_Tab, + /* 0x36 */ KEY_Q, + /* 0x37 */ KEY_W, + /* 0x38 */ KEY_E, + /* 0x39 */ KEY_R, + /* 0x3a */ KEY_T, + /* 0x3b */ KEY_Y, + /* 0x3c */ KEY_U, + /* 0x3d */ KEY_I, + /* 0x3e */ KEY_O, + /* 0x3f */ KEY_P, + /* 0x40 */ KEY_LBrace, + /* 0x41 */ KEY_RBrace, + /* 0x42 */ KEY_Delete, + /* 0x43 */ KEY_NOTUSED, /* compose */ + /* 0x44 */ KEY_KP_7, + /* 0x45 */ KEY_KP_8, + /* 0x46 */ KEY_KP_9, + /* 0x47 */ KEY_KP_Minus, + /* 0x48 */ KEY_NOTUSED, /* open */ + /* 0x49 */ KEY_NOTUSED, /* paste */ + /* 0x4a */ KEY_End, + /* 0x4b */ KEY_NOTUSED, + /* 0x4c */ KEY_LCtrl, + /* 0x4d */ KEY_A, + /* 0x4e */ KEY_S, + /* 0x4f */ KEY_D, + /* 0x50 */ KEY_F, + /* 0x51 */ KEY_G, + /* 0x52 */ KEY_H, + /* 0x53 */ KEY_J, + /* 0x54 */ KEY_K, + /* 0x55 */ KEY_L, + /* 0x56 */ KEY_SemiColon, + /* 0x57 */ KEY_Quote, + /* 0x58 */ KEY_BSlash, + /* 0x59 */ KEY_Enter, + /* 0x5a */ KEY_KP_Enter, + /* 0x5b */ KEY_KP_4, + /* 0x5c */ KEY_KP_5, + /* 0x5d */ KEY_KP_6, + /* 0x5e */ KEY_KP_0, + /* 0x5f */ KEY_NOTUSED, /* find */ + /* 0x60 */ KEY_PgUp, + /* 0x61 */ KEY_NOTUSED, /* cut */ + /* 0x62 */ KEY_NumLock, + /* 0x63 */ KEY_ShiftL, + /* 0x64 */ KEY_Z, + /* 0x65 */ KEY_X, + /* 0x66 */ KEY_C, + /* 0x67 */ KEY_V, + /* 0x68 */ KEY_B, + /* 0x69 */ KEY_N, + /* 0x6a */ KEY_M, + /* 0x6b */ KEY_Comma, + /* 0x6c */ KEY_Period, + /* 0x6d */ KEY_Slash, + /* 0x6e */ KEY_ShiftR, + /* 0x6f */ KEY_NOTUSED, /* linefeed */ + /* 0x70 */ KEY_KP_1, + /* 0x71 */ KEY_KP_2, + /* 0x72 */ KEY_KP_3, + /* 0x73 */ KEY_NOTUSED, + /* 0x74 */ KEY_NOTUSED, + /* 0x75 */ KEY_NOTUSED, + /* 0x76 */ KEY_NOTUSED, /* help */ + /* 0x77 */ KEY_CapsLock, + /* 0x78 */ KEY_LMeta, + /* 0x79 */ KEY_Space, + /* 0x7a */ KEY_RMeta, + /* 0x7b */ KEY_PgDown, + /* 0x7c */ KEY_NOTUSED, + /* 0x7d */ KEY_KP_Plus, + /* 0x7e */ KEY_NOTUSED, + /* 0x7f */ KEY_NOTUSED +}; + +#define WS_SUN_MAP_SIZE (sizeof(wsSunMap)/sizeof(unsigned char)) + + +#define WS_ADB_MAP_SIZE (sizeof(wsAdbMap)/sizeof(unsigned char)) + +/* + * Translate raw wskbd keyboard event values to XFree86 standard keycodes + * (based on the AT keyboard scan codes using the tables above */ -static KeySym -coGetKeysym(typ,str,old) - int typ; - CARD8 *str; - KeySym old; +int +WSKbdToKeycode(int keycode) { - if (strlen((char *)str) > 1) return old; - switch (typ & KBD_MASK) { - case KBD_NONE: - return NoSymbol; - case KBD_SHIFT: - if (old==XK_Shift_L || old==XK_Shift_R) return old; - else return XK_Shift_L; - case KBD_NUM: - return XK_Num_Lock; - case KBD_CTL: - if (old==XK_Control_L || old==XK_Control_R) return old; - else return XK_Control_L; - case KBD_ALTGR: - return XK_Mode_switch; - case KBD_META: - if (old==XK_Alt_L || old==XK_Alt_R) return old; - else return XK_Alt_L; - case KBD_SHFTLOCK: - case KBD_CAPS: - return XK_Caps_Lock; - case KBD_SCROLL: - return XK_Scroll_Lock; - case KBD_BREAK: - return XK_Break; + switch (xf86Info.wsKbdType) { + case WSKBD_TYPE_PC_XT: + case WSKBD_TYPE_PC_AT: + /* No translation needed */ + return keycode; + case WSKBD_TYPE_USB: + if (keycode < 0 || keycode >= WS_USB_MAP_SIZE) + return KEY_UNKNOWN; + else + return wsUsbMap[keycode]; +#ifdef WSKBD_TYPE_ADB + case WSKBD_TYPE_ADB: + if (keycode < 0 || keycode >= WS_ADB_MAP_SIZE) + return KEY_UNKNOWN; + else + return wsAdbMap[keycode]; +#endif +#ifdef WSKBD_TYPE_SUN + case WSKBD_TYPE_SUN: + if (keycode < 0 || keycode >= WS_SUN_MAP_SIZE) + return KEY_UNKNOWN; + else + return wsSunMap[keycode]; +#endif default: - case KBD_KP: /* there are few good reasons to overload - * F Keys and KP Keys, so we ignore any attempt - * at all - */ - return old; - case KBD_ASCII: - return *str; + ErrorF("Unknown wskbd type %d\n", xf86Info.wsKbdType); + return KEY_UNKNOWN; } } -#endif + +#endif /* WSCONS_SUPPORT */ diff --git a/hw/xfree86/common/xf86KbdLnx.c b/hw/xfree86/common/xf86KbdLnx.c index 094044b30..1f97c0b15 100644 --- a/hw/xfree86/common/xf86KbdLnx.c +++ b/hw/xfree86/common/xf86KbdLnx.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdLnx.c,v 3.12 1996/12/23 06:43:31 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdLnx.c,v 3.16 2001/03/05 20:18:20 dawes Exp $ */ /* * Linux version of keymapping setup. The kernel (since 0.99.14) has support * for fully remapping the keyboard, but there are some differences between @@ -28,7 +28,7 @@ * PERFORMANCE OF THIS SOFTWARE. * */ -/* $Xorg: xf86KbdLnx.c,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */ +/* $XConsortium: xf86KbdLnx.c /main/7 1996/10/19 17:59:00 kaleb $ */ #include "X.h" #include "Xmd.h" @@ -37,10 +37,10 @@ #include "compiler.h" -#include "xf86Procs.h" +#include "xf86.h" +#include "xf86Priv.h" #include "xf86_OSlib.h" #include "atKeynames.h" -#include "xf86_Config.h" #include "xf86Keymap.h" #include "DECkeysym.h" @@ -71,63 +71,11 @@ xf86KbdGetMapping (KeySymsPtr pKeySyms, CARD8 *pModMap) { KeySym *k; char type; - int i, j; + int i; readKernelMapping(pKeySyms, pModMap); /* - * Apply the special key mapping specified in XF86Config - */ - for (k = map, i = MIN_KEYCODE; - i < (NUM_KEYCODES + MIN_KEYCODE); - i++, k += 4) { - switch (k[0]) { - case XK_Alt_L: - j = K_INDEX_LEFTALT; - break; - case XK_Alt_R: - j = K_INDEX_RIGHTALT; - break; - case XK_Scroll_Lock: - j = K_INDEX_SCROLLLOCK; - break; - case XK_Control_R: - j = K_INDEX_RIGHTCTL; - break; - default: - j = -1; - } - if (j >= 0) - switch (xf86Info.specialKeyMap[j]) { - case KM_META: - if (k[0] == XK_Alt_R) - k[1] = XK_Meta_R; - else { - k[0] = XK_Alt_L; - k[1] = XK_Meta_L; - } - break; - case KM_COMPOSE: - k[0] = XK_Multi_key; - break; - case KM_MODESHIFT: - k[0] = XK_Mode_switch; - k[1] = NoSymbol; - break; - case KM_MODELOCK: - k[0] = XK_Mode_switch; - k[1] = XF86XK_ModeLock; - break; - case KM_SCROLLLOCK: - k[0] = XK_Scroll_Lock; - break; - case KM_CONTROL: - k[0] = XK_Control_R; - break; - } - } - - /* * compute the modifier map */ for (i = 0; i < MAP_LENGTH; i++) @@ -159,7 +107,7 @@ xf86KbdGetMapping (KeySymsPtr pKeySyms, CARD8 *pModMap) break; case XK_Num_Lock: - if (!xf86Info.serverNumLock) pModMap[i] = NumLockMask; + pModMap[i] = NumLockMask; break; case XK_Scroll_Lock: @@ -185,11 +133,7 @@ xf86KbdGetMapping (KeySymsPtr pKeySyms, CARD8 *pModMap) pKeySyms->map = map; pKeySyms->mapWidth = GLYPHS_PER_KEY; pKeySyms->minKeyCode = MIN_KEYCODE; - if (xf86Info.serverNumLock) - pKeySyms->maxKeyCode = MAX_KEYCODE; - else - pKeySyms->maxKeyCode = MAX_STD_KEYCODE; - + pKeySyms->maxKeyCode = MAX_KEYCODE; } #include <linux/keyboard.h> @@ -226,7 +170,7 @@ static KeySym linux_to_x[256] = { 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_bar, XK_braceright, XK_asciitilde, XK_BackSpace, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, @@ -261,12 +205,10 @@ static KeySym linux_to_x[256] = { XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis }; -#ifndef ASSUME_CUSTOM_KEYCODES - /* * Maps the AT keycodes to Linux keycodes */ -static unsigned char at2lnx[] = +static unsigned char at2lnx[NUM_KEYCODES] = { 0x01, /* KEY_Escape */ 0x02, /* KEY_1 */ 0x03, /* KEY_2 */ 0x04, /* KEY_3 */ @@ -332,34 +274,19 @@ static unsigned char at2lnx[] = 0x5E, /* FOCUS_PF7 */ 0x5F, /* FOCUS_PF8 */ 0x7C, /* JAP_86 */ 0x79, /* FOCUS_PF10 */ 0x00, /* 0x7f */ - /* the following are for ServerNumLock handling */ - 0x47, /* KEY_SN_KP_7 */ 0x48, /* KEY_SN_KP_8 */ - 0x49, /* KEY_SN_KP_9 */ 0x4b, /* KEY_SN_KP_4 */ - 0x4c, /* KEY_SN_KP_5 */ 0x4d, /* KEY_SN_KP_6 */ - 0x4f, /* KEY_SN_KP_1 */ 0x50, /* KEY_SN_KP_2 */ - 0x51, /* KEY_SN_KP_3 */ 0x52, /* KEY_SN_KP_0 */ - 0x53, /* KEY_SN_KP_Decimal */ 0x66, /* KEY_SN_Home */ - 0x67, /* KEY_SN_Up */ 0x68, /* KEY_SN_Prior */ - 0x69, /* KEY_SN_Left */ 0x5d, /* KEY_SN_Begin */ - 0x6a, /* KEY_SN_Right */ 0x6b, /* KEY_SN_End */ - 0x6c, /* KEY_SN_Down */ 0x6d, /* KEY_SN_Next */ - 0x6e, /* KEY_SN_Ins */ 0x6f /* KEY_SN_Del */ }; #define NUM_AT2LNX (sizeof(at2lnx) / sizeof(at2lnx[0])) -#else /* !ASSUME_CUSTOM_KEYCODES */ - -#define NUM_AT2LNX NR_KEYS +#define NUM_CUSTOMKEYS NR_KEYS -u_char SpecialServerMap[NR_KEYS]; - -#endif /* !ASSUME_CUSTOM_KEYCODES */ +u_char SpecialServerMap[NUM_CUSTOMKEYS]; static void readKernelMapping(KeySymsPtr pKeySyms, CARD8 *pModMap) { KeySym *k; int i; + int maxkey; static unsigned char tbl[GLYPHS_PER_KEY] = { 0, /* unshifted */ @@ -377,30 +304,27 @@ readKernelMapping(KeySymsPtr pKeySyms, CARD8 *pModMap) * First, figure out which tables to use for the modeswitch columns * above, from the XF86Config fields. */ - if (xf86Info.specialKeyMap[K_INDEX_RIGHTCTL] == KM_MODESHIFT || - xf86Info.specialKeyMap[K_INDEX_RIGHTCTL] == KM_MODELOCK) - tbl[2] = 4; /* control */ - else if (xf86Info.specialKeyMap[K_INDEX_RIGHTALT] == KM_MODESHIFT || - xf86Info.specialKeyMap[K_INDEX_RIGHTALT] == KM_MODELOCK) - tbl[2] = 2; /* AltGr */ - else - tbl[2] = 8; /* alt */ + tbl[2] = 8; /* alt */ tbl[3] = tbl[2] | 1; -#ifndef ASSUME_CUSTOM_KEYCODES - for (i = 0, k = map+GLYPHS_PER_KEY; i < NUM_AT2LNX; ++i) -#else /* !ASSUME_CUSTOM_KEYCODES */ - for (i = 0, k = map; i < NUM_AT2LNX; ++i) -#endif /* !ASSUME_CUSTOM_KEYCODES */ + if (xf86Info.kbdCustomKeycodes) { + k = map; + maxkey = NUM_CUSTOMKEYS; + } + else { + k = map+GLYPHS_PER_KEY; + maxkey = NUM_AT2LNX; + } + + for (i = 0; i < maxkey; ++i) { struct kbentry kbe; int j; -#ifndef ASSUME_CUSTOM_KEYCODES - kbe.kb_index = at2lnx[i]; -#else /* !ASSUME_CUSTOM_KEYCODES */ - kbe.kb_index = i; -#endif /* !ASSUME_CUSTOM_KEYCODES */ + if (xf86Info.kbdCustomKeycodes) + kbe.kb_index = i; + else + kbe.kb_index = at2lnx[i]; for (j = 0; j < GLYPHS_PER_KEY; ++j, ++k) { @@ -410,9 +334,7 @@ readKernelMapping(KeySymsPtr pKeySyms, CARD8 *pModMap) kbe.kb_table = tbl[j]; if ( -#ifndef ASSUME_CUSTOM_KEYCODES - kbe.kb_index == 0 || -#endif /* !ASSUME_CUSTOM_KEYCODES */ + (!xf86Info.kbdCustomKeycodes && kbe.kb_index == 0) || ioctl(xf86Info.consoleFd, KDGKBENT, &kbe)) continue; @@ -624,11 +546,14 @@ readKernelMapping(KeySymsPtr pKeySyms, CARD8 *pModMap) 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; } -#ifdef ASSUME_CUSTOM_KEYCODES + + if (!xf86Info.kbdCustomKeycodes) + return; + /* * Find the Mapping for the special server functions */ - for (i = 0; i < NR_KEYS; ++i) { + for (i = 0; i < NUM_CUSTOMKEYS; ++i) { struct kbentry kbe; int special = 0; @@ -693,5 +618,4 @@ readKernelMapping(KeySymsPtr pKeySyms, CARD8 *pModMap) } SpecialServerMap[i] = special; } -#endif /* ASSUME_CUSTOM_KEYCODES */ } diff --git a/hw/xfree86/common/xf86KbdMach.c b/hw/xfree86/common/xf86KbdMach.c index cc23ee8e0..fbbafd8af 100644 --- a/hw/xfree86/common/xf86KbdMach.c +++ b/hw/xfree86/common/xf86KbdMach.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdMach.c,v 3.7 1996/12/23 06:43:32 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdMach.c,v 3.8 1998/07/25 16:55:09 dawes Exp $ */ /* ***************************************************************************** * HISTORY @@ -35,7 +35,7 @@ * PERFORMANCE OF THIS SOFTWARE. * */ -/* $Xorg: xf86KbdMach.c,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */ +/* $XConsortium: xf86KbdMach.c /main/9 1996/02/21 17:38:43 kaleb $ */ #include "X.h" #include "Xmd.h" @@ -44,10 +44,11 @@ #include "compiler.h" -#include "xf86Procs.h" +#include "xf86.h" +#include "xf86Priv.h" #include "xf86_OSlib.h" #include "atKeynames.h" -#include "xf86_Config.h" +#include "xf86Config.h" #include "xf86Keymap.h" diff --git a/hw/xfree86/common/xf86Keymap.h b/hw/xfree86/common/xf86Keymap.h index 2b9debff4..45f4dd104 100644 --- a/hw/xfree86/common/xf86Keymap.h +++ b/hw/xfree86/common/xf86Keymap.h @@ -1,13 +1,15 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Keymap.h,v 3.9 1996/12/23 06:43:35 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Keymap.h,v 3.19 2002/05/31 18:45:58 dawes Exp $ */ /* * * For Scancodes see notes in atKeynames.h !!!! * */ -/* $Xorg: xf86Keymap.h,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */ +/* $XConsortium: xf86Keymap.h /main/14 1996/02/21 17:38:47 kaleb $ */ + +static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = { + +#if !defined(__SOL8__) && (!defined(sun) || defined(i386)) -static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = { -#ifndef PC98 /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x01 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol, /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol, @@ -23,7 +25,7 @@ static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = { /* 0x0c */ XK_minus, XK_underscore, NoSymbol, NoSymbol, /* 0x0d */ XK_equal, XK_plus, NoSymbol, NoSymbol, /* 0x0e */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol, - /* 0x0f */ XK_Tab, NoSymbol, NoSymbol, NoSymbol, + /* 0x0f */ XK_Tab, XK_ISO_Left_Tab,NoSymbol, NoSymbol, /* 0x10 */ XK_Q, NoSymbol, NoSymbol, NoSymbol, /* 0x11 */ XK_W, NoSymbol, NoSymbol, NoSymbol, /* 0x12 */ XK_E, NoSymbol, NoSymbol, NoSymbol, @@ -84,7 +86,7 @@ static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = { /* 0x49 */ XK_KP_Prior, XK_KP_9, NoSymbol, NoSymbol, /* 0x4a */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol, /* 0x4b */ XK_KP_Left, XK_KP_4, NoSymbol, NoSymbol, - /* 0x4c */ NoSymbol, XK_KP_5, NoSymbol, NoSymbol, + /* 0x4c */ XK_KP_Begin, XK_KP_5, NoSymbol, NoSymbol, /* 0x4d */ XK_KP_Right, XK_KP_6, NoSymbol, NoSymbol, /* 0x4e */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol, /* 0x4f */ XK_KP_End, XK_KP_1, NoSymbol, NoSymbol, @@ -97,7 +99,6 @@ static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = { /* 0x56 */ XK_less, XK_greater, NoSymbol, NoSymbol, /* 0x57 */ XK_F11, NoSymbol, NoSymbol, NoSymbol, /* 0x58 */ XK_F12, NoSymbol, NoSymbol, NoSymbol, - /* 0x59 */ XK_Home, NoSymbol, NoSymbol, NoSymbol, /* 0x5a */ XK_Up, NoSymbol, NoSymbol, NoSymbol, /* 0x5b */ XK_Prior, NoSymbol, NoSymbol, NoSymbol, @@ -119,180 +120,178 @@ static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = { /* 0x6b */ XK_Meta_L, NoSymbol, NoSymbol, NoSymbol, /* 0x6c */ XK_Meta_R, NoSymbol, NoSymbol, NoSymbol, /* 0x6d */ XK_Menu, NoSymbol, NoSymbol, NoSymbol, - /* 0x6e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x6f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x70 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x71 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x72 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x73 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x6e */ XK_F13, NoSymbol, NoSymbol, NoSymbol, + /* 0x6f */ XK_F14, NoSymbol, NoSymbol, NoSymbol, + /* 0x70 */ XK_F15, NoSymbol, NoSymbol, NoSymbol, + /* 0x71 */ XK_F16, NoSymbol, NoSymbol, NoSymbol, + /* 0x72 */ XK_F17, NoSymbol, NoSymbol, NoSymbol, + /* 0x73 */ XK_backslash, XK_underscore, NoSymbol, NoSymbol, /* 0x74 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x75 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x76 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x77 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x78 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x79 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x79 */ XK_Henkan, XK_Mode_switch, NoSymbol, NoSymbol, /* 0x7a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x7b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7b */ XK_Muhenkan, NoSymbol, NoSymbol, NoSymbol, /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x7d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7d */ XK_backslash, XK_bar, NoSymbol, NoSymbol, /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, -#else /* PC98 */ - /* 0x00 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol, - /* 0x01 */ XK_1, XK_exclam, XK_kana_NU, NoSymbol, - /* 0x02 */ XK_2, XK_quotedbl, XK_kana_FU, NoSymbol, - /* 0x03 */ XK_3, XK_numbersign, XK_kana_A, XK_kana_a, - /* 0x04 */ XK_4, XK_dollar, XK_kana_U, XK_kana_u, - /* 0x05 */ XK_5, XK_percent, XK_kana_E, XK_kana_e, - /* 0x06 */ XK_6, XK_ampersand, XK_kana_O, XK_kana_o, - /* 0x07 */ XK_7, XK_quoteright, XK_kana_YA, XK_kana_ya, - /* 0x08 */ XK_8, XK_parenleft, XK_kana_YU, XK_kana_yu, - /* 0x09 */ XK_9, XK_parenright, XK_kana_YO, XK_kana_yo, - /* 0x0a */ XK_0, NoSymbol, XK_kana_WA, XK_kana_WO, - /* 0x0b */ XK_minus, XK_equal, XK_kana_HO, NoSymbol, - /* 0x0c */ XK_asciicircum, XK_quoteleft, XK_kana_HE, NoSymbol, - /* 0x0d */ XK_backslash, XK_bar, XK_prolongedsound, NoSymbol, - /* 0x0e */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol, - /* 0x0f */ XK_Tab, NoSymbol, NoSymbol, NoSymbol, - /* 0x10 */ XK_Q, NoSymbol, XK_kana_TA, NoSymbol, - /* 0x11 */ XK_W, NoSymbol, XK_kana_TE, NoSymbol, - /* 0x12 */ XK_E, NoSymbol, XK_kana_I, XK_kana_i, - /* 0x13 */ XK_R, NoSymbol, XK_kana_SU, NoSymbol, - /* 0x14 */ XK_T, NoSymbol, XK_kana_KA, NoSymbol, - /* 0x15 */ XK_Y, NoSymbol, XK_kana_N, NoSymbol, - /* 0x16 */ XK_U, NoSymbol, XK_kana_NA, NoSymbol, - /* 0x17 */ XK_I, NoSymbol, XK_kana_NI, NoSymbol, - /* 0x18 */ XK_O, NoSymbol, XK_kana_RA, NoSymbol, - /* 0x19 */ XK_P, NoSymbol, XK_kana_SE, NoSymbol, - /* 0x1a */ XK_at, XK_asciitilde, XK_voicedsound, NoSymbol, - /* 0x1b */ XK_bracketleft, XK_braceleft, XK_semivoicedsound, XK_kana_openingbracket, - /* 0x1c */ XK_Return, NoSymbol, NoSymbol, NoSymbol, - /* 0x1d */ XK_A, NoSymbol, XK_kana_CHI, NoSymbol, - /* 0x1e */ XK_S, NoSymbol, XK_kana_TO, NoSymbol, - /* 0x1f */ XK_D, NoSymbol, XK_kana_SHI, NoSymbol, - /* 0x20 */ XK_F, NoSymbol, XK_kana_HA, NoSymbol, - /* 0x21 */ XK_G, NoSymbol, XK_kana_KI, NoSymbol, - /* 0x22 */ XK_H, NoSymbol, XK_kana_KU, NoSymbol, - /* 0x23 */ XK_J, NoSymbol, XK_kana_MA, NoSymbol, - /* 0x24 */ XK_K, NoSymbol, XK_kana_NO, NoSymbol, - /* 0x25 */ XK_L, NoSymbol, XK_kana_RI, NoSymbol, - /* 0x26 */ XK_semicolon, XK_plus, XK_kana_RE, NoSymbol, - /* 0x27 */ XK_colon, XK_asterisk, XK_kana_KE, NoSymbol, - /* 0x28 */ XK_bracketright,XK_braceright, XK_kana_MU, XK_kana_closingbracket, - /* 0x29 */ XK_Z, NoSymbol, XK_kana_TSU, NoSymbol, - /* 0x2a */ XK_X, NoSymbol, XK_kana_SA, NoSymbol, - /* 0x2b */ XK_C, NoSymbol, XK_kana_SO, NoSymbol, - /* 0x2c */ XK_V, NoSymbol, XK_kana_HI, NoSymbol, - /* 0x2d */ XK_B, NoSymbol, XK_kana_KO, NoSymbol, - /* 0x2e */ XK_N, NoSymbol, XK_kana_MI, NoSymbol, - /* 0x2f */ XK_M, NoSymbol, XK_kana_MO, NoSymbol, - /* 0x30 */ XK_comma, XK_less, XK_kana_NE, XK_kana_comma, - /* 0x31 */ XK_period, XK_greater, XK_kana_RU, XK_kana_fullstop, - /* 0x32 */ XK_slash, XK_question, XK_kana_ME, XK_kana_middledot, - /* 0x33 */ XK_underscore, XK_underscore, XK_kana_RO, NoSymbol, - /* 0x34 */ XK_space, NoSymbol, NoSymbol, NoSymbol, - /* 0x35 */ XK_Henkan, XK_Kanji, NoSymbol, NoSymbol, - /* 0x36 */ XK_Next, NoSymbol, NoSymbol, NoSymbol, - /* 0x37 */ XK_Prior, NoSymbol, NoSymbol, NoSymbol, - /* 0x38 */ XK_Insert, NoSymbol, NoSymbol, NoSymbol, - /* 0x39 */ XK_Delete, NoSymbol, NoSymbol, NoSymbol, - /* 0x3a */ XK_Up, NoSymbol, NoSymbol, NoSymbol, - /* 0x3b */ XK_Left, NoSymbol, NoSymbol, NoSymbol, - /* 0x3c */ XK_Right, NoSymbol, NoSymbol, NoSymbol, - /* 0x3d */ XK_Down, NoSymbol, NoSymbol, NoSymbol, - /* 0x3e */ XK_Clear, XK_Home, NoSymbol, NoSymbol, - /* 0x3f */ XK_Help, NoSymbol, NoSymbol, NoSymbol, - /* 0x40 */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol, - /* 0x41 */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol, - /* 0x42 */ XK_KP_7, NoSymbol, NoSymbol, NoSymbol, - /* 0x43 */ XK_KP_8, NoSymbol, NoSymbol, NoSymbol, - /* 0x44 */ XK_KP_9, NoSymbol, NoSymbol, NoSymbol, - /* 0x45 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol, - /* 0x46 */ XK_KP_4, NoSymbol, NoSymbol, NoSymbol, - /* 0x47 */ XK_KP_5, NoSymbol, NoSymbol, NoSymbol, - /* 0x48 */ XK_KP_6, NoSymbol, NoSymbol, NoSymbol, - /* 0x49 */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol, - /* 0x4a */ XK_KP_1, NoSymbol, NoSymbol, NoSymbol, - /* 0x4b */ XK_KP_2, NoSymbol, NoSymbol, NoSymbol, - /* 0x4c */ XK_KP_3, NoSymbol, NoSymbol, NoSymbol, - /* 0x4d */ XK_KP_Equal, NoSymbol, NoSymbol, NoSymbol, - /* 0x4e */ XK_KP_0, NoSymbol, NoSymbol, NoSymbol, - /* 0x4f */ XK_KP_Separator,NoSymbol, NoSymbol, NoSymbol, - /* 0x50 */ XK_KP_Decimal, NoSymbol, NoSymbol, NoSymbol, - /* 0x51 */ XK_Muhenkan, NoSymbol, NoSymbol, NoSymbol, - /* 0x52 */ XK_F11, NoSymbol, NoSymbol, NoSymbol, - /* 0x53 */ XK_F12, NoSymbol, NoSymbol, NoSymbol, - /* 0x54 */ XK_F13, NoSymbol, NoSymbol, NoSymbol, - /* 0x55 */ XK_F14, NoSymbol, NoSymbol, NoSymbol, - /* 0x56 */ XK_F15, NoSymbol, NoSymbol, NoSymbol, + /* 0x7f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + +#else /* SunOS */ + +/* Assumes a US English keyboard as default - sorry 'bout that + * + * Hopefully it'll be enough someone can have a sorta working + * keyboard, if they're not using XKB + * + * DWH 9/12/99 + */ + + /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x01 */ XK_quoteleft, XK_asciitilde, NoSymbol, NoSymbol, + /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol, + /* 0x03 */ XK_2, XK_at, NoSymbol, NoSymbol, + /* 0x04 */ XK_3, XK_numbersign, NoSymbol, NoSymbol, + /* 0x05 */ XK_4, XK_dollar, NoSymbol, NoSymbol, + /* 0x06 */ XK_5, XK_percent, NoSymbol, NoSymbol, + /* 0x07 */ XK_6, XK_asciicircum, NoSymbol, NoSymbol, + /* 0x08 */ XK_7, XK_ampersand, NoSymbol, NoSymbol, + /* 0x09 */ XK_8, XK_asterisk, NoSymbol, NoSymbol, + /* 0x0a */ XK_9, XK_parenleft, NoSymbol, NoSymbol, + /* 0x0b */ XK_0, XK_parenright, NoSymbol, NoSymbol, + /* 0x0c */ XK_minus, XK_underscore, NoSymbol, NoSymbol, + /* 0x0d */ XK_equal, XK_plus, NoSymbol, NoSymbol, + /* 0x0e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x0f */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol, + /* 0x10 */ XK_Tab, NoSymbol, NoSymbol, NoSymbol, + /* 0x11 */ XK_Q, NoSymbol, NoSymbol, NoSymbol, + /* 0x12 */ XK_W, NoSymbol, NoSymbol, NoSymbol, + /* 0x13 */ XK_E, NoSymbol, NoSymbol, NoSymbol, + /* 0x14 */ XK_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x15 */ XK_T, NoSymbol, NoSymbol, NoSymbol, + /* 0x16 */ XK_Y, NoSymbol, NoSymbol, NoSymbol, + /* 0x17 */ XK_U, NoSymbol, NoSymbol, NoSymbol, + /* 0x18 */ XK_I, NoSymbol, NoSymbol, NoSymbol, + /* 0x19 */ XK_O, NoSymbol, NoSymbol, NoSymbol, + /* 0x1a */ XK_P, NoSymbol, NoSymbol, NoSymbol, + /* 0x1b */ XK_bracketleft, XK_braceleft, NoSymbol, NoSymbol, + /* 0x1c */ XK_bracketright,XK_braceright, NoSymbol, NoSymbol, + /* 0x1d */ XK_backslash, XK_bar, NoSymbol, NoSymbol, + /* 0x1e */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol, + /* 0x1f */ XK_A, NoSymbol, NoSymbol, NoSymbol, + /* 0x20 */ XK_S, NoSymbol, NoSymbol, NoSymbol, + /* 0x21 */ XK_D, NoSymbol, NoSymbol, NoSymbol, + /* 0x22 */ XK_F, NoSymbol, NoSymbol, NoSymbol, + /* 0x23 */ XK_G, NoSymbol, NoSymbol, NoSymbol, + /* 0x24 */ XK_H, NoSymbol, NoSymbol, NoSymbol, + /* 0x25 */ XK_J, NoSymbol, NoSymbol, NoSymbol, + /* 0x26 */ XK_K, NoSymbol, NoSymbol, NoSymbol, + /* 0x27 */ XK_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x28 */ XK_semicolon, XK_colon, NoSymbol, NoSymbol, + /* 0x29 */ XK_quoteright, XK_quotedbl, NoSymbol, NoSymbol, + /* 0x2a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x2b */ XK_Return, NoSymbol, NoSymbol, NoSymbol, + /* 0x2c */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x2d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x2e */ XK_Z, NoSymbol, NoSymbol, NoSymbol, + /* 0x2f */ XK_X, NoSymbol, NoSymbol, NoSymbol, + /* 0x30 */ XK_C, NoSymbol, NoSymbol, NoSymbol, + /* 0x31 */ XK_V, NoSymbol, NoSymbol, NoSymbol, + /* 0x32 */ XK_B, NoSymbol, NoSymbol, NoSymbol, + /* 0x33 */ XK_N, NoSymbol, NoSymbol, NoSymbol, + /* 0x34 */ XK_M, NoSymbol, NoSymbol, NoSymbol, + /* 0x35 */ XK_comma, XK_less, NoSymbol, NoSymbol, + /* 0x36 */ XK_period, XK_greater, NoSymbol, NoSymbol, + /* 0x37 */ XK_slash, XK_question, NoSymbol, NoSymbol, + /* 0x38 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x39 */ XK_Shift_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x3a */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x3b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x3c */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol, + /* 0x3d */ XK_space, NoSymbol, NoSymbol, NoSymbol, + /* 0x3e */ XK_Alt_R, XK_Meta_R, NoSymbol, NoSymbol, + /* 0x3f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x40 */ XK_Control_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x41 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x42 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x43 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x44 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x45 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x46 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x47 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x48 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x49 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x4a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x4b */ XK_Insert, NoSymbol, NoSymbol, NoSymbol, + /* 0x4c */ XK_Delete, NoSymbol, NoSymbol, NoSymbol, + /* 0x4d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x4e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x4f */ XK_Left, NoSymbol, NoSymbol, NoSymbol, + /* 0x50 */ XK_Home, NoSymbol, NoSymbol, NoSymbol, + /* 0x51 */ XK_End, NoSymbol, NoSymbol, NoSymbol, + /* 0x52 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x53 */ XK_Up, NoSymbol, NoSymbol, NoSymbol, + /* 0x54 */ XK_Down, NoSymbol, NoSymbol, NoSymbol, + /* 0x55 */ XK_Prior, NoSymbol, NoSymbol, NoSymbol, + /* 0x56 */ XK_Next, NoSymbol, NoSymbol, NoSymbol, /* 0x57 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x58 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x59 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x5a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x5b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x5c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x5d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x59 */ XK_Right, NoSymbol, NoSymbol, NoSymbol, + /* 0x5a */ XK_Num_Lock, NoSymbol, NoSymbol, NoSymbol, + /* 0x5b */ XK_KP_Home, XK_KP_7, NoSymbol, NoSymbol, + /* 0x5c */ XK_KP_Left, XK_KP_4, NoSymbol, NoSymbol, + /* 0x5d */ XK_KP_End, XK_KP_1, NoSymbol, NoSymbol, /* 0x5e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x5f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x60 */ XK_Break, NoSymbol, NoSymbol, NoSymbol, - /* 0x61 */ XK_Print, NoSymbol, NoSymbol, NoSymbol, - /* 0x62 */ XK_F1, NoSymbol, NoSymbol, NoSymbol, - /* 0x63 */ XK_F2, NoSymbol, NoSymbol, NoSymbol, - /* 0x64 */ XK_F3, NoSymbol, NoSymbol, NoSymbol, - /* 0x65 */ XK_F4, NoSymbol, NoSymbol, NoSymbol, - /* 0x66 */ XK_F5, NoSymbol, NoSymbol, NoSymbol, - /* 0x67 */ XK_F6, NoSymbol, NoSymbol, NoSymbol, - /* 0x68 */ XK_F7, NoSymbol, NoSymbol, NoSymbol, - /* 0x69 */ XK_F8, NoSymbol, NoSymbol, NoSymbol, - /* 0x6a */ XK_F9, NoSymbol, NoSymbol, NoSymbol, - /* 0x6b */ XK_F10, NoSymbol, NoSymbol, NoSymbol, - /* 0x6c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x6d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x6e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x5f */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol, + /* 0x60 */ XK_KP_Up, XK_KP_8, NoSymbol, NoSymbol, + /* 0x61 */ NoSymbol, XK_KP_5, NoSymbol, NoSymbol, + /* 0x62 */ XK_KP_Down, XK_KP_2, NoSymbol, NoSymbol, + /* 0x63 */ XK_KP_Insert, XK_KP_0, NoSymbol, NoSymbol, + /* 0x64 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol, + /* 0x65 */ XK_KP_Prior, XK_KP_9, NoSymbol, NoSymbol, + /* 0x66 */ XK_KP_Right, XK_KP_6, NoSymbol, NoSymbol, + /* 0x67 */ XK_KP_Next, XK_KP_3, NoSymbol, NoSymbol, + /* 0x68 */ XK_KP_Delete, XK_KP_Decimal, NoSymbol, NoSymbol, + /* 0x69 */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol, + /* 0x6a */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol, + /* 0x6b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x6c */ XK_KP_Enter, NoSymbol, NoSymbol, NoSymbol, + /* 0x6d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x6e */ XK_Escape, NoSymbol, NoSymbol, NoSymbol, /* 0x6f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x70 */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol, - /* 0x71 */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol, - /* 0x72 */ XK_kana_switch, NoSymbol, XK_kana_switch, NoSymbol, - /* 0x73 */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol, - /* 0x74 */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol, - /* 0x75 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x76 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x77 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x78 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x79 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x7a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x7b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x7d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, -#endif /* PC98 */ + /* 0x70 */ XK_F1, NoSymbol, NoSymbol, NoSymbol, + /* 0x71 */ XK_F2, NoSymbol, NoSymbol, NoSymbol, + /* 0x72 */ XK_F3, NoSymbol, NoSymbol, NoSymbol, + /* 0x73 */ XK_F4, NoSymbol, NoSymbol, NoSymbol, + /* 0x74 */ XK_F5, NoSymbol, NoSymbol, NoSymbol, + /* 0x75 */ XK_F6, NoSymbol, NoSymbol, NoSymbol, + /* 0x76 */ XK_F7, NoSymbol, NoSymbol, NoSymbol, + /* 0x77 */ XK_F8, NoSymbol, NoSymbol, NoSymbol, + /* 0x78 */ XK_F9, NoSymbol, NoSymbol, NoSymbol, + /* 0x79 */ XK_F10, NoSymbol, NoSymbol, NoSymbol, + /* 0x7a */ XK_F11, NoSymbol, NoSymbol, NoSymbol, + /* 0x7b */ XK_F12, NoSymbol, NoSymbol, NoSymbol, + /* 0x7c */ XK_Print, NoSymbol, NoSymbol, NoSymbol, + /* 0x7d */ XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol, + /* 0x7e */ XK_Pause, NoSymbol, NoSymbol, NoSymbol, /* 0x7f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* These are for ServerNumLock handling */ - /* 0x80 */ XK_KP_7, NoSymbol, NoSymbol, NoSymbol, - /* 0x81 */ XK_KP_8, NoSymbol, NoSymbol, NoSymbol, - /* 0x82 */ XK_KP_9, NoSymbol, NoSymbol, NoSymbol, - /* 0x83 */ XK_KP_4, NoSymbol, NoSymbol, NoSymbol, - /* 0x84 */ XK_KP_5, NoSymbol, NoSymbol, NoSymbol, - /* 0x85 */ XK_KP_6, NoSymbol, NoSymbol, NoSymbol, - /* 0x86 */ XK_KP_1, NoSymbol, NoSymbol, NoSymbol, - /* 0x87 */ XK_KP_2, NoSymbol, NoSymbol, NoSymbol, - /* 0x88 */ XK_KP_3, NoSymbol, NoSymbol, NoSymbol, - /* 0x89 */ XK_KP_0, NoSymbol, NoSymbol, NoSymbol, - /* 0x8a */ XK_KP_Decimal, NoSymbol, NoSymbol, NoSymbol, - /* 0x8b */ XK_Home, NoSymbol, NoSymbol, NoSymbol, - /* 0x8c */ XK_Up, NoSymbol, NoSymbol, NoSymbol, - /* 0x8d */ XK_Prior, NoSymbol, NoSymbol, NoSymbol, - /* 0x8e */ XK_Left, NoSymbol, NoSymbol, NoSymbol, - /* 0x8f */ XK_Begin, NoSymbol, NoSymbol, NoSymbol, - /* 0x90 */ XK_Right, NoSymbol, NoSymbol, NoSymbol, - /* 0x91 */ XK_End, NoSymbol, NoSymbol, NoSymbol, - /* 0x92 */ XK_Down, NoSymbol, NoSymbol, NoSymbol, - /* 0x93 */ XK_Next, NoSymbol, NoSymbol, NoSymbol, - /* 0x94 */ XK_Insert, NoSymbol, NoSymbol, NoSymbol, - /* 0x95 */ XK_Delete, NoSymbol, NoSymbol, NoSymbol, +#endif /* SunOS */ + }; -static KeySym map84[NUM_KEYCODES * GLYPHS_PER_KEY] = { +#if !defined(Lynx) && \ + !defined(__UNIXOS2__) && \ + !defined(__mips__) && \ + !defined(linux) && \ + !defined(CSRG_BASED) && \ + !defined(__CYGWIN__) && \ + !defined(__SOL8__) && \ + (!defined(sun) || defined(i386)) + +static KeySym map84[NUM_KEYCODES * GLYPHS_PER_KEY] = { /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x01 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol, /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol, @@ -382,7 +381,6 @@ static KeySym map84[NUM_KEYCODES * GLYPHS_PER_KEY] = { /* 0x56 */ XK_less, XK_greater, NoSymbol, NoSymbol, /* 0x57 */ XK_F11, NoSymbol, NoSymbol, NoSymbol, /* 0x58 */ XK_F12, NoSymbol, NoSymbol, NoSymbol, - /* 0x59 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x5a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x5b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, @@ -421,29 +419,5 @@ static KeySym map84[NUM_KEYCODES * GLYPHS_PER_KEY] = { /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x7d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - /* 0x7f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, - - /* These are for ServerNumLock handling */ - /* 0x80 */ XK_KP_7, NoSymbol, NoSymbol, NoSymbol, - /* 0x81 */ XK_KP_8, NoSymbol, NoSymbol, NoSymbol, - /* 0x82 */ XK_KP_9, NoSymbol, NoSymbol, NoSymbol, - /* 0x83 */ XK_KP_4, NoSymbol, NoSymbol, NoSymbol, - /* 0x84 */ XK_KP_5, NoSymbol, NoSymbol, NoSymbol, - /* 0x85 */ XK_KP_6, NoSymbol, NoSymbol, NoSymbol, - /* 0x86 */ XK_KP_1, NoSymbol, NoSymbol, NoSymbol, - /* 0x87 */ XK_KP_2, NoSymbol, NoSymbol, NoSymbol, - /* 0x88 */ XK_KP_3, NoSymbol, NoSymbol, NoSymbol, - /* 0x89 */ XK_KP_0, NoSymbol, NoSymbol, NoSymbol, - /* 0x8a */ XK_KP_Decimal, NoSymbol, NoSymbol, NoSymbol, - /* 0x8b */ XK_Home, NoSymbol, NoSymbol, NoSymbol, - /* 0x8c */ XK_Up, NoSymbol, NoSymbol, NoSymbol, - /* 0x8d */ XK_Prior, NoSymbol, NoSymbol, NoSymbol, - /* 0x8e */ XK_Left, NoSymbol, NoSymbol, NoSymbol, - /* 0x8f */ XK_Begin, NoSymbol, NoSymbol, NoSymbol, - /* 0x90 */ XK_Right, NoSymbol, NoSymbol, NoSymbol, - /* 0x91 */ XK_End, NoSymbol, NoSymbol, NoSymbol, - /* 0x92 */ XK_Down, NoSymbol, NoSymbol, NoSymbol, - /* 0x93 */ XK_Next, NoSymbol, NoSymbol, NoSymbol, - /* 0x94 */ XK_Insert, NoSymbol, NoSymbol, NoSymbol, - /* 0x95 */ XK_Delete, NoSymbol, NoSymbol, NoSymbol, }; +#endif diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h index 3c73f6e56..308e7a72c 100644 --- a/hw/xfree86/common/xf86Priv.h +++ b/hw/xfree86/common/xf86Priv.h @@ -1,175 +1,202 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Priv.h,v 3.24.2.1 1998/02/01 16:04:47 robin Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Priv.h,v 3.80 2002/12/12 18:29:10 eich Exp $ */ + /* - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Thomas Roell not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Thomas Roell makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 1997 by The XFree86 Project, Inc. + */ + +/* + * This file contains declarations for private XFree86 functions and variables, + * and definitions of private macros. * + * "private" means not available to video drivers. */ -/* $Xorg: xf86Priv.h,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */ #ifndef _XF86PRIV_H #define _XF86PRIV_H -#ifndef _XF86VIDMODE_SERVER_ -#include "Xproto.h" -#include "xf86_OSproc.h" +#include "xf86Privstr.h" +#include "propertyst.h" + +/* + * Parameters set ONLY from the command line options + * The global state of these things is held in xf86InfoRec (when appropriate). + */ +extern const char *xf86ConfigFile; +extern Bool xf86AllowMouseOpenFail; +#ifdef XF86VIDMODE +extern Bool xf86VidModeDisabled; +extern Bool xf86VidModeAllowNonLocal; +#endif +#ifdef XF86MISC +extern Bool xf86MiscModInDevDisabled; +extern Bool xf86MiscModInDevAllowNonLocal; +#endif +extern Bool xf86fpFlag; +extern Bool xf86coFlag; +extern Bool xf86sFlag; +extern Bool xf86bsEnableFlag; +extern Bool xf86bsDisableFlag; +extern Bool xf86silkenMouseDisableFlag; +extern char *xf86LayoutName; +extern char *xf86ScreenName; +extern char *xf86PointerName; +extern char *xf86KeyboardName; +#ifdef KEEPBPP +extern int xf86Bpp; #endif +extern int xf86FbBpp; +extern int xf86Depth; +extern Pix24Flags xf86Pix24; +extern rgb xf86Weight; +extern Bool xf86FlipPixels; +extern Bool xf86BestRefresh; +extern Gamma xf86Gamma; +extern char *xf86ServerName; +extern Bool xf86ShowUnresolved; -typedef struct { +/* Other parameters */ - /* keyboard part */ - DeviceIntPtr pKeyboard; - DeviceProc kbdProc; /* procedure for initializing */ - void (* kbdEvents)( /* proc for processing events */ -#if NeedNestedPrototypes && !defined(__OSF__) - void -#endif - ); -#ifndef MINIX - int consoleFd; +extern xf86InfoRec xf86Info; +extern const char *xf86InputDeviceList; +extern const char *xf86ModulePath; +extern MessageType xf86ModPathFrom; +extern const char *xf86LogFile; +extern MessageType xf86LogFileFrom; +extern Bool xf86LogFileWasOpened; +extern serverLayoutRec xf86ConfigLayout; +extern Pix24Flags xf86ConfigPix24; + +extern unsigned short xf86MouseCflags[]; +extern Bool xf86SupportedMouseTypes[]; +extern int xf86NumMouseTypes; + +#ifdef XFree86LOADER +extern DriverPtr *xf86DriverList; +extern ModuleInfoPtr *xf86ModuleInfoList; +extern int xf86NumModuleInfos; #else - int kbdFd; -#endif /* MINIX */ -#if defined(MACH386) || defined(__OSF__) - int kbdFd; -#endif /* MACH386 || __OSF__ */ - int vtno; - int kbdType; /* AT84 / AT101 */ - int kbdRate; - int kbdDelay; - int bell_pitch; - int bell_duration; - Bool autoRepeat; - unsigned long leds; - unsigned long xleds; - char *vtinit; - int *specialKeyMap; - int scanPrefix; /* scancode-state */ - Bool capsLock; - Bool numLock; - Bool scrollLock; - Bool modeSwitchLock; - Bool serverNumLock; - Bool composeLock; - Bool vtSysreq; -#if defined(SVR4) && defined(i386) - Bool panix106; -#endif /* SVR4 && i386 */ - - /* mouse part */ - DeviceIntPtr pMouse; -#ifdef XINPUT - pointer mouseLocal; +extern DriverPtr xf86DriverList[]; #endif - MouseDevPtr mouseDev; - - /* event handler part */ - int lastEventTime; - Bool vtRequestsPending; - Bool inputPending; - Bool dontZap; - Bool dontZoom; - Bool notrapSignals; /* don't exit cleanly - die at fault */ - Bool caughtSignal; - - /* graphics part */ - Bool sharedMonitor; - ScreenPtr currentScreen; -#ifdef CSRG_BASED - int screenFd; /* fd for memory mapped access to vga card */ - int consType; /* Which console driver? */ +extern int xf86NumDrivers; +extern Bool xf86Resetting; +extern Bool xf86Initialising; +extern Bool xf86ProbeFailed; +extern int xf86NumScreens; +extern pciVideoPtr *xf86PciVideoInfo; +extern xf86CurrentAccessRec xf86CurrentAccess; +extern const char *xf86VisualNames[]; +extern int xf86Verbose; /* verbosity level */ +extern int xf86LogVerbose; /* log file verbosity level */ +extern Bool xf86ProbeOnly; +extern Bool xf86DoProbe; + +#ifndef DEFAULT_VERBOSE +#define DEFAULT_VERBOSE 0 #endif -#if defined(AMOEBA) - void *screenPtr; +#ifndef DEFAULT_LOG_VERBOSE +#define DEFAULT_LOG_VERBOSE 3 #endif - -#ifdef XKB -/* - * would like to use an XkbComponentNamesRec here but can't without - * pulling in a bunch of header files. :-( - */ - char *xkbkeymap; - char *xkbkeycodes; - char *xkbtypes; - char *xkbcompat; - char *xkbsymbols; - char *xkbgeometry; - Bool xkbcomponents_specified; - char *xkbrules; - char *xkbmodel; - char *xkblayout; - char *xkbvariant; - char *xkboptions; +#ifndef DEFAULT_DPI +#define DEFAULT_DPI 75 #endif -} xf86InfoRec, *xf86InfoPtr; +#define DEFAULT_UNRESOLVED TRUE +#define DEFAULT_BEST_REFRESH FALSE -extern xf86InfoRec xf86Info; +/* Function Prototypes */ +#ifndef _NO_XF86_PROTOTYPES + +/* xf86Beta.c */ +extern void xf86CheckBeta(int extraDays, char *key); + +/* xf86Bus.c */ -/* ISC's cc can't handle ~ of UL constants, so explicitly type cast them. */ -#define XLED1 ((unsigned long) 0x00000001) -#define XLED2 ((unsigned long) 0x00000002) -#define XLED3 ((unsigned long) 0x00000004) -#define XCAPS ((unsigned long) 0x20000000) -#define XNUM ((unsigned long) 0x40000000) -#define XSCR ((unsigned long) 0x80000000) -#define XCOMP ((unsigned long) 0x00008000) - -/* 386BSD console driver types (consType) */ -#ifdef CSRG_BASED -#define PCCONS 0 -#define CODRV011 1 -#define CODRV01X 2 -#define SYSCONS 8 -#define PCVT 16 +void xf86BusProbe(void); +void xf86ChangeBusIndex(int oldIndex, int newIndex); +void xf86AccessInit(void); +void xf86AccessEnter(void); +void xf86AccessLeave(void); +void xf86EntityInit(void); +void xf86EntityEnter(void); +void xf86EntityLeave(void); +void xf86AccessLeaveState(void); + +void xf86FindPrimaryDevice(void); +/* new RAC */ +void xf86ResourceBrokerInit(void); +void xf86PostProbe(void); +void xf86ClearEntityListForScreen(int scrnIndex); +void xf86AddDevToEntity(int entityIndex, GDevPtr dev); +extern void xf86PostPreInit(void); +extern void xf86PostScreenInit(void); +extern memType getValidBIOSBase(PCITAG tag, int num); +extern int pciTestMultiDeviceCard(int bus, int dev, int func, PCITAG** pTag); + +/* xf86Config.c */ + +Bool xf86PathIsAbsolute(const char *path); +Bool xf86PathIsSafe(const char *path); + +/* xf86DefaultModes */ + +extern DisplayModeRec xf86DefaultModes []; + +/* xf86DoScanPci.c */ + +void DoScanPci(int argc, char **argv, int i); + +/* xf86DoProbe.c */ +void DoProbeArgs(int argc, char **argv, int i); +void DoProbe(void); +void DoConfigure(void); + +/* xf86Events.c */ + +void xf86PostKbdEvent(unsigned key); +void xf86PostMseEvent(DeviceIntPtr device, int buttons, int dx, int dy); +void xf86Wakeup(pointer blockData, int err, pointer pReadmask); +void xf86SigHandler(int signo); +#ifdef MEMDEBUG +void xf86SigMemDebug(int signo); #endif +void xf86HandlePMEvents(int fd, pointer data); +extern int (*xf86PMGetEventFromOs)(int fd,pmEvent *events,int num); +extern pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event); +void xf86GrabServerCallback(CallbackListPtr *, pointer, pointer); -/* Values of xf86Info.mouseFlags */ -#define MF_CLEAR_DTR 1 -#define MF_CLEAR_RTS 2 +/* xf86Helper.c */ +void xf86LogInit(void); +void xf86CloseLog(void); +void OsVendorVErrorF(const char *f, va_list args); -extern int xf86ScreenIndex; +/* xf86Init.c */ +Bool xf86LoadModules(char **list, pointer *optlist); -#define XF86SCRNINFO(p) ((ScrnInfoPtr)((p)->devPrivates[xf86ScreenIndex].ptr)) +/* xf86Io.c */ -extern int xf86MaxScreens; -extern ScrnInfoPtr xf86Screens[]; -extern int xf86ScreenNames[]; +void xf86KbdBell(int percent, DeviceIntPtr pKeyboard, pointer ctrl, + int unused); +void xf86KbdLeds(void); +void xf86UpdateKbdLeds(void); +void xf86KbdCtrl(DevicePtr pKeyboard, KeybdCtrl *ctrl); +void xf86InitKBD(Bool init); +int xf86KbdProc(DeviceIntPtr pKeyboard, int what); -extern char xf86ConfigFile[]; -extern int xf86Verbose; -extern Bool xf86ProbeOnly, xf86ProbeFailed; -extern unsigned short xf86MouseCflags[]; -extern Bool xf86SupportedMouseTypes[]; -extern int xf86NumMouseTypes; -extern int xf86bpp; -extern xrgb xf86weight; -extern Bool xf86AllowMouseOpenFail; -extern Bool xf86BestRefresh; +/* xf86Kbd.c */ -extern Bool xf86FlipPixels; -#define XF86FLIP_PIXELS() \ - if (xf86FlipPixels) { \ - pScreen->whitePixel = (pScreen->whitePixel) ? 0 : 1; \ - pScreen->blackPixel = (pScreen->blackPixel) ? 0 : 1; \ - } +void xf86KbdGetMapping(KeySymsPtr pKeySyms, CARD8 *pModMap); -#endif /* _XF86PRIV_H */ +/* xf86Lock.c */ +#ifdef USE_XF86_SERVERLOCK +void xf86UnlockServer(void); +#endif +/* xf86XKB.c */ + +void xf86InitXkb(void); + +#endif /* _NO_XF86_PROTOTYPES */ + + +#endif /* _XF86PRIV_H */ diff --git a/hw/xfree86/common/xf86Version.h b/hw/xfree86/common/xf86Version.h index f403c31f5..e548b0437 100644 --- a/hw/xfree86/common/xf86Version.h +++ b/hw/xfree86/common/xf86Version.h @@ -1,23 +1,33 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/xf86Version.h,v 3.236.2.50 1998/03/02 09:58:21 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/xf86Version.h,v 3.543.2.1 2003/05/10 01:10:10 dawes Exp $ */ -#define XF86_VERSION " 3.3.2 " +#ifndef XF86_VERSION_CURRENT -/* The finer points in versions... */ -#define XF86_VERSION_MAJOR 3 +#define XF86_VERSION_MAJOR 4 #define XF86_VERSION_MINOR 3 -#define XF86_VERSION_SUBMINOR 2 -#define XF86_VERSION_BETA 0 /* 0="", 1="A", 2="B", etc... */ -#define XF86_VERSION_ALPHA 0 /* 0="", 1="a", 2="b", etc... */ +#define XF86_VERSION_PATCH 0 +#define XF86_VERSION_SNAP 1 + +/* This has five arguments for compatibilty reasons */ +#define XF86_VERSION_NUMERIC(major,minor,patch,snap,dummy) \ + (((major) * 10000000) + ((minor) * 100000) + ((patch) * 1000) + snap) + +#define XF86_GET_MAJOR_VERSION(vers) ((vers) / 10000000) +#define XF86_GET_MINOR_VERSION(vers) (((vers) % 10000000) / 100000) +#define XF86_GET_PATCH_VERSION(vers) (((vers) % 100000) / 1000) +#define XF86_GET_SNAP_VERSION(vers) ((vers) % 1000) + +/* Define these for compatibility. They'll be removed at some point. */ +#define XF86_VERSION_SUBMINOR XF86_VERSION_PATCH +#define XF86_VERSION_BETA 0 +#define XF86_VERSION_ALPHA XF86_VERSION_SNAP -#define XF86_VERSION_NUMERIC(major,minor,subminor,beta,alpha) \ - ((((((((major << 7) | minor) << 7) | subminor) << 5) | beta) << 5) | alpha) #define XF86_VERSION_CURRENT \ XF86_VERSION_NUMERIC(XF86_VERSION_MAJOR, \ XF86_VERSION_MINOR, \ - XF86_VERSION_SUBMINOR, \ - XF86_VERSION_BETA, \ - XF86_VERSION_ALPHA) + XF86_VERSION_PATCH, \ + XF86_VERSION_SNAP, \ + 0) -#define XF86_DATE "March 2 1998" +#endif -/* $Xorg: xf86Version.h,v 1.3 2000/08/17 19:48:48 cpqbld Exp $ */ +/* $XConsortium: xf86Version.h /main/78 1996/10/28 05:42:10 kaleb $ */ diff --git a/hw/xfree86/common/xf86XKB.c b/hw/xfree86/common/xf86XKB.c index c5ac740fd..ddd3055ab 100644 --- a/hw/xfree86/common/xf86XKB.c +++ b/hw/xfree86/common/xf86XKB.c @@ -1,4 +1,4 @@ -/* $Xorg: xf86XKB.c,v 1.3 2000/08/17 19:50:31 cpqbld Exp $ */ +/* $XConsortium: xf86XKB.c /main/4 1996/02/04 09:28:04 kaleb $ */ /************************************************************ Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. @@ -24,7 +24,7 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86XKB.c,v 3.6 1996/12/28 11:14:43 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86XKB.c,v 3.11 2002/10/11 01:40:31 dawes Exp $ */ #include <stdio.h> #define NEED_EVENTS 1 @@ -38,81 +38,14 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "compiler.h" -#include "xf86Procs.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS #include "xf86_OSlib.h" -#include "xf86_Config.h" #include "XKBsrv.h" -#ifdef AMOEBA -#define LED_CAP IOP_LED_CAP -#define LED_NUM IOP_LED_NUM -#define LED_SCR IOP_LED_SCROLL -#endif - -#ifdef MINIX -#define LED_CAP KBD_LEDS_CAPS -#define LED_NUM KBD_LEDS_NUM -#define LED_SCR KBD_LEDS_SCROLL -#endif - -void -xf86InitXkb() -{ -} - -void -#if NeedFunctionPrototypes -XkbDDXUpdateIndicators(DeviceIntPtr pXDev,CARD32 new) -#else -XkbDDXUpdateIndicators(pXDev,new) - DeviceIntPtr pXDev; - CARD32 new; -#endif -{ - CARD32 old; -#ifdef DEBUG -/* if (xkbDebugFlags)*/ - ErrorF("XkbDDXUpdateIndicators(...,0x%x) -- XFree86 version\n",new); -#endif -#ifdef LED_CAP - old= new; - new= 0; - if (old&XLED1) new|= LED_CAP; - if (old&XLED2) new|= LED_NUM; - if (old&XLED3) new|= LED_SCR; -#endif - xf86SetKbdLeds(new); - return; -} - void -#if NeedFunctionPrototypes -XkbDDXUpdateDeviceIndicators( DeviceIntPtr dev, - XkbSrvLedInfoPtr sli, - CARD32 new) -#else -XkbDDXUpdateDeviceIndicators(dev,sli,new) - DeviceIntPtr dev; - XkbSrvLedInfoPtr sli; - CARD32 new; -#endif +xf86InitXkb(void) { - if (sli->fb.kf==dev->kbdfeed) - XkbDDXUpdateIndicators(dev,new); - else if (sli->class==KbdFeedbackClass) { - KbdFeedbackPtr kf; - kf= sli->fb.kf; - if (kf && kf->CtrlProc) { - (*kf->CtrlProc)(dev,&kf->ctrl); - } - } - else if (sli->class==LedFeedbackClass) { - LedFeedbackPtr lf; - lf= sli->fb.lf; - if (lf && lf->CtrlProc) { - (*lf->CtrlProc)(dev,&lf->ctrl); - } - } - return; } diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c index 7659deb3f..53fa1b3ff 100644 --- a/hw/xfree86/common/xf86Xinput.c +++ b/hw/xfree86/common/xf86Xinput.c @@ -1,6 +1,6 @@ -/* $Xorg: xf86Xinput.c,v 1.3 2000/08/17 19:50:31 cpqbld Exp $ */ +/* $XConsortium: xf86Xinput.c /main/14 1996/10/27 11:05:25 kaleb $ */ /* - * Copyright 1995,1996 by Frederic Lepied, France. <fred@sugix.frmug.fr.net> + * Copyright 1995-1999 by Frederic Lepied, France. <Lepied@XFree86.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -22,25 +22,37 @@ * */ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Xinput.c,v 3.22.2.7 1998/02/07 10:05:22 hohndel Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Xinput.c,v 3.68 2002/10/11 01:40:31 dawes Exp $ */ +#include "Xfuncproto.h" #include "Xmd.h" +#ifdef XINPUT #include "XI.h" #include "XIproto.h" +#endif #include "xf86.h" -#include "Xpoll.h" #include "xf86Priv.h" -#include "xf86_Config.h" #include "xf86Xinput.h" -#include "xf86Procs.h" +#ifdef XINPUT +#include "XIstubs.h" +#endif #include "mipointer.h" +#include "xf86InPriv.h" #ifdef DPMSExtension +#define DPMS_SERVER #include "extensions/dpms.h" +#include "dpmsproc.h" +#endif + +#ifdef XFreeXDGA +#include "dgaproc.h" #endif #include "exevents.h" /* AddInputDevice */ +#include "exglobals.h" +#define EXTENSION_PROC_ARGS void * #include "extnsionst.h" #include "extinit.h" /* LookupDeviceIntRec */ @@ -48,40 +60,34 @@ #include <stdarg.h> -extern InputInfo inputInfo; +#include "osdep.h" /* EnabledDevices */ +#include "Xpoll.h" +#include "xf86_OSproc.h" /* sigio stuff */ -#ifndef DYNAMIC_MODULE -#ifdef JOYSTICK_SUPPORT -extern DeviceAssocRec joystick_assoc; -#endif -#ifdef WACOM_SUPPORT -extern DeviceAssocRec wacom_stylus_assoc; -extern DeviceAssocRec wacom_cursor_assoc; -extern DeviceAssocRec wacom_eraser_assoc; -#endif -#ifdef ELOGRAPHICS_SUPPORT -extern DeviceAssocRec elographics_assoc; -#endif -#ifdef SUMMASKETCH_SUPPORT -extern DeviceAssocRec summasketch_assoc; +/****************************************************************************** + * debugging macro + *****************************************************************************/ +#ifdef DBG +#undef DBG #endif +#ifdef DEBUG +#undef DEBUG #endif -extern DeviceAssocRec mouse_assoc; +#define DEBUG 0 -static int num_devices; -static LocalDevicePtr *localDevices; -static int max_devices; +#if DEBUG +static int debug_level = 0; -static DeviceAssocPtr *deviceAssoc = NULL; -static int numAssoc = 0; -static int maxAssoc = 0; +#define DBG(lvl, f) {if ((lvl) <= debug_level) f;} +#else +#define DBG(lvl, f) +#endif -static SymTabRec XinputTab[] = { - { ENDSECTION, "endsection"}, - { SUBSECTION, "subsection" }, - { -1, "" }, -}; +/****************************************************************************** + * macros + *****************************************************************************/ +#define ENQUEUE(e) xf86eqEnqueue((e)) /*********************************************************************** * @@ -110,20 +116,27 @@ xf86AlwaysCoreControl(DeviceIntPtr device, int xf86IsCorePointer(DeviceIntPtr device) { + return(device == inputInfo.pointer); +} + +static int +xf86ShareCorePointer(DeviceIntPtr device) +{ LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate; return((local->always_core_feedback && - local->always_core_feedback->ctrl.integer_displayed) || - (device == inputInfo.pointer)); + local->always_core_feedback->ctrl.integer_displayed)); } -static int -xf86IsAlwaysCore(DeviceIntPtr device) +static Bool +xf86SendDragEvents(DeviceIntPtr device) { - LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate; + LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate; - return(local->always_core_feedback && - local->always_core_feedback->ctrl.integer_displayed); + if (inputInfo.pointer->button->buttonsDown > 0) + return (local->flags & XI86_SEND_DRAG_EVENTS); + else + return (TRUE); } int @@ -136,8 +149,7 @@ xf86IsCoreKeyboard(DeviceIntPtr device) } void -xf86AlwaysCore(LocalDevicePtr local, - Bool always) +xf86XInputSetSendCoreEvents(LocalDevicePtr local, Bool always) { if (always) { local->flags |= XI86_ALWAYS_CORE; @@ -146,6 +158,8 @@ xf86AlwaysCore(LocalDevicePtr local, } } +static int xf86CoreButtonState; + /*********************************************************************** * * xf86CheckButton -- @@ -159,153 +173,64 @@ Bool xf86CheckButton(int button, int down) { - /* The device may have up to MSE_MAXBUTTONS (12) buttons. */ - int state = (inputInfo.pointer->button->state & 0x0fff00) >> 8; - int check = (state & (1 << (button - 1))); + int check; + int bit = (1 << (button - 1)); + + check = xf86CoreButtonState & bit; - if ((check && down) && (!check && !down)) { + DBG(5, ErrorF("xf86CheckButton " + "button=%d down=%d state=%d check=%d returns ", + button, down, state, check)); + if ((check && down) || (!check && !down)) { + DBG(5, ErrorF("FALSE\n")); return FALSE; } + xf86CoreButtonState ^= bit; + DBG(5, ErrorF("TRUE\n")); return TRUE; } /*********************************************************************** * - * ReadInput -- - * Wakeup handler to catch input and dispatch it to our - * input routines if necessary. + * xf86ProcessCommonOptions -- + * + * Process global options. * *********************************************************************** */ -static void -ReadInput(pointer block_data, - int select_status, - pointer read_mask) +void +xf86ProcessCommonOptions(LocalDevicePtr local, + pointer list) { - int i; - LocalDevicePtr local_dev; - fd_set* LastSelectMask = (fd_set*) read_mask; - fd_set devices_with_input; - extern fd_set EnabledDevices; - - if (select_status < 1) - return; - - XFD_ANDSET(&devices_with_input, LastSelectMask, &EnabledDevices); - if (!XFD_ANYSET(&devices_with_input)) - return; - - for (i = 0; i < num_devices; i++) { - local_dev = localDevices[i]; - if (local_dev->read_input && - (local_dev->fd >= 0) && - (FD_ISSET(local_dev->fd, ((fd_set *) read_mask)) != 0)) { - (*local_dev->read_input)(local_dev); - break; + if (xf86SetBoolOption(list, "AlwaysCore", 0) || + xf86SetBoolOption(list, "SendCoreEvents", 0)) { + local->flags |= XI86_ALWAYS_CORE; + xf86Msg(X_CONFIG, "%s: always reports core events\n", local->name); } - } -} -/*********************************************************************** - * - * configExtendedInputSection -- - * - *********************************************************************** - */ - -void -xf86ConfigExtendedInputSection(LexPtr val) -{ - int i; - int token; - -#ifndef DYNAMIC_MODULE -# ifdef JOYSTICK_SUPPORT - xf86AddDeviceAssoc(&joystick_assoc); -# endif -# ifdef WACOM_SUPPORT - xf86AddDeviceAssoc(&wacom_stylus_assoc); - xf86AddDeviceAssoc(&wacom_cursor_assoc); - xf86AddDeviceAssoc(&wacom_eraser_assoc); -# endif -# ifdef ELOGRAPHICS_SUPPORT - xf86AddDeviceAssoc(&elographics_assoc); -# endif -# ifdef SUMMASKETCH_SUPPORT - xf86AddDeviceAssoc(&summasketch_assoc); -# endif -#endif + if (xf86SetBoolOption(list, "CorePointer", 0)) { + local->flags |= XI86_CORE_POINTER; + xf86Msg(X_CONFIG, "%s: Core Pointer\n", local->name); + } - xf86AddDeviceAssoc(&mouse_assoc); - - num_devices = 0; - max_devices = 3; - localDevices = (LocalDevicePtr*) xalloc(sizeof(LocalDevicePtr)*max_devices); - - while ((token = xf86GetToken(XinputTab)) != ENDSECTION) - { - if (token == SUBSECTION) - { - int found = 0; - - if (xf86GetToken(NULL) != STRING) - xf86ConfigError("SubSection name expected"); - - for(i=0; !found && i<numAssoc; i++) - { - if (StrCaseCmp(val->str, deviceAssoc[i]->config_section_name) == 0) - { - if (num_devices == max_devices) { - max_devices *= 2; - localDevices = (LocalDevicePtr*) xrealloc(localDevices, - sizeof(LocalDevicePtr)*max_devices); - } - localDevices[num_devices] = deviceAssoc[i]->device_allocate(); - - if (localDevices[num_devices] && localDevices[num_devices]->device_config) - { - (*localDevices[num_devices]->device_config)(localDevices, - num_devices, - num_devices+1, - val); - localDevices[num_devices]->flags |= XI86_CONFIGURED; - num_devices++; - } - found = 1; - } - } - if (!found) - xf86ConfigError("Invalid SubSection name"); - } - else - xf86ConfigError("XInput keyword section expected"); + if (xf86SetBoolOption(list, "CoreKeyboard", 0)) { + local->flags |= XI86_CORE_KEYBOARD; + xf86Msg(X_CONFIG, "%s: Core Keyboard\n", local->name); } -} -/*********************************************************************** - * - * xf86AddDeviceAssoc -- - * - * Add an association to the array deviceAssoc. This is needed to - * allow dynamic loading of devices to register themself. - * - *********************************************************************** - */ -void -xf86AddDeviceAssoc(DeviceAssocPtr assoc) -{ - if (!deviceAssoc) { - maxAssoc = 10; - deviceAssoc = (DeviceAssocPtr*) xalloc(sizeof(DeviceAssocPtr)*maxAssoc); + if (xf86SetBoolOption(list, "SendDragEvents", 1)) { + local->flags |= XI86_SEND_DRAG_EVENTS; } else { - if (maxAssoc == numAssoc) { - maxAssoc *= 2; - deviceAssoc = (DeviceAssocPtr*) xrealloc(deviceAssoc, sizeof(DeviceAssocPtr)*maxAssoc); - } + xf86Msg(X_CONFIG, "%s: doesn't report drag events\n", local->name); + } + + local->history_size = xf86SetIntOption(list, "HistorySize", 0); + + if (local->history_size > 0) { + xf86Msg(X_CONFIG, "%s: has a history of %d motions\n", local->name, + local->history_size); } - deviceAssoc[numAssoc] = assoc; - numAssoc++; } /*********************************************************************** @@ -321,6 +246,9 @@ void xf86XinputFinalizeInit(DeviceIntPtr dev) { LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate; + + local->dxremaind = 0.0; + local->dyremaind = 0.0; if (InitIntegerFeedbackClassDeviceStruct(dev, xf86AlwaysCoreControl) == FALSE) { ErrorF("Unable to init integer feedback for always core feature\n"); @@ -330,57 +258,61 @@ xf86XinputFinalizeInit(DeviceIntPtr dev) } } - /*********************************************************************** * - * InitExtInput -- + * xf86ActivateDevice -- * - * Initialize any extended devices we might have. It is called from - * ddx InitInput. + * Initialize an input device. * *********************************************************************** */ - void -InitExtInput() +xf86ActivateDevice(LocalDevicePtr local) { DeviceIntPtr dev; - int i; - /* Register a Wakeup handler to handle input when generated */ - RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr) NoopDDA, ReadInput, - NULL); - - /* Add each device */ - for (i = 0; i < num_devices; i++) { - if (localDevices[i]->flags & XI86_CONFIGURED) { - int open_on_init; - - open_on_init = !(localDevices[i]->flags & XI86_NO_OPEN_ON_INIT) || - (localDevices[i]->flags & XI86_ALWAYS_CORE); - - dev = AddInputDevice(localDevices[i]->device_control, - open_on_init); - if (dev == NULL) - FatalError("Too many input devices"); - - localDevices[i]->atom = MakeAtom(localDevices[i]->name, - strlen(localDevices[i]->name), - TRUE); - dev->public.devicePrivate = (pointer) localDevices[i]; - localDevices[i]->dev = dev; + if (local->flags & XI86_CONFIGURED) { + int open_on_init; + + open_on_init = local->flags & + (XI86_OPEN_ON_INIT | + XI86_ALWAYS_CORE | XI86_CORE_POINTER | XI86_CORE_KEYBOARD); + + dev = AddInputDevice(local->device_control, + open_on_init); + if (dev == NULL) + FatalError("Too many input devices"); + + local->atom = MakeAtom(local->name, + strlen(local->name), + TRUE); + AssignTypeAndName (dev, local->atom, local->name); + dev->public.devicePrivate = (pointer) local; + local->dev = dev; + + xf86XinputFinalizeInit(dev); - xf86XinputFinalizeInit(dev); - + /* + * XXX Can a single device instance be both core keyboard and + * core pointer? If so, this should be changed. + */ + if (local->flags & XI86_CORE_POINTER) + RegisterPointerDevice(dev); + else if (local->flags & XI86_CORE_KEYBOARD) + RegisterKeyboardDevice(dev); +#ifdef XINPUT + else RegisterOtherDevice(dev); - if (serverGeneration == 1) - ErrorF("%s Adding extended device \"%s\" (type: %s)\n", XCONFIG_GIVEN, - localDevices[i]->name, localDevices[i]->type_name); - } +#endif + + if (serverGeneration == 1) + xf86Msg(X_INFO, "XINPUT: Adding extended input device \"%s\" (type: %s)\n", + local->name, local->type_name); } } +#ifdef XINPUT /*********************************************************************** * * Caller: ProcXOpenDevice @@ -405,13 +337,10 @@ InitExtInput() */ void -OpenInputDevice (dev, client, status) - DeviceIntPtr dev; - ClientPtr client; - int *status; +OpenInputDevice(DeviceIntPtr dev, + ClientPtr client, + int *status) { - extern int BadDevice; - if (!dev->inited) { *status = BadDevice; } else { @@ -453,9 +382,7 @@ OpenInputDevice (dev, client, status) */ int -ChangeKeyboardDevice (old_dev, new_dev) - DeviceIntPtr old_dev; - DeviceIntPtr new_dev; +ChangeKeyboardDevice (DeviceIntPtr old_dev, DeviceIntPtr new_dev) { /********************************************************************** * DeleteFocusClassDeviceStruct(old_dev); * defined in xchgptr.c * @@ -496,17 +423,11 @@ ChangeKeyboardDevice (old_dev, new_dev) */ int -#ifdef NeedFunctionPrototypes ChangePointerDevice ( DeviceIntPtr old_dev, DeviceIntPtr new_dev, unsigned char x, unsigned char y) -#else -ChangePointerDevice (old_dev, new_dev, x, y) - DeviceIntPtr old_dev, new_dev; - unsigned char x, y; -#endif /* NeedFunctionPrototypes */ { /************************************************************************ InitFocusClassDeviceStruct(old_dev); * allow focusing old ptr* @@ -518,6 +439,7 @@ ChangePointerDevice (old_dev, new_dev, x, y) else axes_changed = FALSE; *************************************************************************/ + /* * We don't allow axis swap or other exotic features. */ @@ -561,9 +483,7 @@ ChangePointerDevice (old_dev, new_dev, x, y) */ void -CloseInputDevice (d, client) - DeviceIntPtr d; - ClientPtr client; +CloseInputDevice (DeviceIntPtr d, ClientPtr client) { ErrorF("ProcXCloseDevice to close or not ?\n"); } @@ -616,10 +536,7 @@ AddOtherInputDevices () */ int -SetDeviceMode (client, dev, mode) - register ClientPtr client; - DeviceIntPtr dev; - int mode; +SetDeviceMode (ClientPtr client, DeviceIntPtr dev, int mode) { LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate; @@ -645,12 +562,8 @@ SetDeviceMode (client, dev, mode) */ int -SetDeviceValuators (client, dev, valuators, first_valuator, num_valuators) - register ClientPtr client; - DeviceIntPtr dev; - int *valuators; - int first_valuator; - int num_valuators; +SetDeviceValuators (ClientPtr client, DeviceIntPtr dev, int *valuators, + int first_valuator, int num_valuators) { return BadMatch; } @@ -666,10 +579,7 @@ SetDeviceValuators (client, dev, valuators, first_valuator, num_valuators) */ int -ChangeDeviceControl (client, dev, control) - register ClientPtr client; - DeviceIntPtr dev; - xDeviceCtl *control; +ChangeDeviceControl (ClientPtr client, DeviceIntPtr dev, xDeviceCtl *control) { LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate; @@ -680,13 +590,12 @@ ChangeDeviceControl (client, dev, control) return (*local->control_proc)(local, control); } } +#endif /* * adapted from mieq.c to support extended events * */ -extern InputInfo inputInfo; - #define QUEUE_SIZE 256 typedef struct _Event { @@ -710,8 +619,7 @@ typedef struct _EventQueue { static EventQueueRec xf86EventQueue; Bool -xf86eqInit (pKbd, pPtr) - DevicePtr pKbd, pPtr; +xf86eqInit (DevicePtr pKbd, DevicePtr pPtr) { xf86EventQueue.head = xf86EventQueue.tail = 0; xf86EventQueue.lastEventTime = GetTimeInMillis (); @@ -732,46 +640,56 @@ xf86eqInit (pKbd, pPtr) */ void -xf86eqEnqueue (e) - xEvent *e; +xf86eqEnqueue (xEvent *e) { - int oldtail, newtail; - Bool isMotion; + int oldtail, newtail; + Bool isMotion; #ifdef XINPUT - int count; - - switch (e->u.u.type) - { - case KeyPress: - case KeyRelease: - case ButtonPress: - case ButtonRelease: - case MotionNotify: + int count; + + xf86AssertBlockedSIGIO ("xf86eqEnqueue"); + switch (e->u.u.type) { + case KeyPress: + case KeyRelease: +#ifdef XFreeXDGA + /* we do this here, because nobody seems to be calling + xf86PostKeyEvent(). We can't steal MotionNotify events here + because the motion-relative information has been lost already. */ + if(DGAStealKeyEvent(xf86EventQueue.pEnqueueScreen->myNum, e)) + return; +#endif + /* fall through */ + case ButtonPress: + case ButtonRelease: + case MotionNotify: count = 1; break; - default: - if (!((deviceKeyButtonPointer *) e)->deviceid & MORE_EVENTS) - { + default: +#ifdef XFreeXDGA + if (DGAIsDgaEvent (e)) + { + count = 1; + break; + } +#endif + if (!((deviceKeyButtonPointer *) e)->deviceid & MORE_EVENTS) { count = 1; - } - else - { - count = 2; - } + } + else { + count = 2; + } break; - } + } #endif oldtail = xf86EventQueue.tail; isMotion = e->u.u.type == MotionNotify; - if (isMotion && xf86EventQueue.lastMotion && oldtail != xf86EventQueue.head) - { + if (isMotion && xf86EventQueue.lastMotion && oldtail != xf86EventQueue.head) { if (oldtail == 0) oldtail = QUEUE_SIZE; oldtail = oldtail - 1; } - else - { + else { newtail = oldtail + 1; if (newtail == QUEUE_SIZE) newtail = 0; @@ -784,9 +702,8 @@ xf86eqEnqueue (e) xf86EventQueue.lastMotion = isMotion; xf86EventQueue.events[oldtail].event = *e; #ifdef XINPUT - if (count == 2) - { - xf86EventQueue.events[oldtail].val = *((deviceValuator *) (((deviceKeyButtonPointer *) e)+1)); + if (count == 2) { + xf86EventQueue.events[oldtail].val = *((deviceValuator *) (((deviceKeyButtonPointer *) e)+1)); } #endif /* @@ -794,8 +711,8 @@ xf86eqEnqueue (e) * is "unnecessary", but very useful */ if (e->u.keyButtonPointer.time < xf86EventQueue.lastEventTime && - xf86EventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000) - { + xf86EventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000) { + xf86EventQueue.events[oldtail].event.u.keyButtonPointer.time = xf86EventQueue.lastEventTime; } @@ -810,28 +727,31 @@ xf86eqProcessInputEvents () { EventRec *e; int x, y; - xEvent xe; + struct { + xEvent event; +#ifdef XINPUT + deviceValuator val; +#endif + } xe; #ifdef XINPUT DeviceIntPtr dev; int id, count; deviceKeyButtonPointer *dev_xe; #endif - while (xf86EventQueue.head != xf86EventQueue.tail) - { + while (xf86EventQueue.head != xf86EventQueue.tail) { if (screenIsSaved == SCREEN_SAVER_ON) SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset); #ifdef DPMSExtension - if (DPMSPowerLevel != DPMSModeOn) - DPMSSet(DPMSModeOn); + if (DPMSPowerLevel != DPMSModeOn) + DPMSSet(DPMSModeOn); #endif e = &xf86EventQueue.events[xf86EventQueue.head]; /* * Assumption - screen switching can only occur on motion events */ - if (e->pScreen != xf86EventQueue.pDequeueScreen) - { + if (e->pScreen != xf86EventQueue.pDequeueScreen) { xf86EventQueue.pDequeueScreen = e->pScreen; x = e->event.u.keyButtonPointer.rootX; y = e->event.u.keyButtonPointer.rootY; @@ -841,54 +761,56 @@ xf86eqProcessInputEvents () ++xf86EventQueue.head; NewCurrentScreen (xf86EventQueue.pDequeueScreen, x, y); } - else - { - xe = e->event; + else { + xe.event = e->event; + xe.val = e->val; if (xf86EventQueue.head == QUEUE_SIZE - 1) xf86EventQueue.head = 0; else ++xf86EventQueue.head; - switch (xe.u.u.type) - { + switch (xe.event.u.u.type) { case KeyPress: case KeyRelease: (*xf86EventQueue.pKbd->processInputProc) - (&xe, (DeviceIntPtr)xf86EventQueue.pKbd, 1); + (&xe.event, (DeviceIntPtr)xf86EventQueue.pKbd, 1); break; #ifdef XINPUT case ButtonPress: case ButtonRelease: case MotionNotify: (*(inputInfo.pointer->public.processInputProc)) - (&xe, (DeviceIntPtr)inputInfo.pointer, 1); - break; + (&xe.event, (DeviceIntPtr)inputInfo.pointer, 1); + break; default: - dev_xe = (deviceKeyButtonPointer *) e; - id = dev_xe->deviceid & DEVICE_BITS; - if (!(dev_xe->deviceid & MORE_EVENTS)) { - count = 1; - } else { - count = 2; - } - dev = LookupDeviceIntRec(id); - if (dev == NULL) - { - ErrorF("LookupDeviceIntRec id=0x%x not found\n", id); +#ifdef XFreeXDGA + if (DGADeliverEvent (xf86EventQueue.pDequeueScreen, &xe.event)) + break; +#endif + dev_xe = (deviceKeyButtonPointer *) &xe.event; + id = dev_xe->deviceid & DEVICE_BITS; + if (!(dev_xe->deviceid & MORE_EVENTS)) { + count = 1; + } + else { + count = 2; + } + dev = LookupDeviceIntRec(id); + if (dev == NULL) { + ErrorF("LookupDeviceIntRec id=0x%x not found\n", id); /* FatalError("xf86eqProcessInputEvents : device not found.\n"); */ - break; - } - if (!dev->public.processInputProc) - { - FatalError("xf86eqProcessInputEvents : device has no input proc.\n"); - break; - } - (*dev->public.processInputProc)(&e->event, dev, count); + break; + } + if (!dev->public.processInputProc) { + FatalError("xf86eqProcessInputEvents : device has no input proc.\n"); + break; + } + (*dev->public.processInputProc)(&xe.event, dev, count); #else default: (*xf86EventQueue.pPtr->processInputProc) - (&xe, (DeviceIntPtr)xf86EventQueue.pPtr, 1); + (&xe.event, (DeviceIntPtr)xf86EventQueue.pPtr, 1); #endif break; } @@ -896,6 +818,16 @@ xf86eqProcessInputEvents () } } +void +xf86eqSwitchScreen(ScreenPtr pScreen, + Bool fromDIX) +{ + xf86EventQueue.pEnqueueScreen = pScreen; + + if (fromDIX) + xf86EventQueue.pDequeueScreen = pScreen; +} + /* * convenient functions to post events */ @@ -912,87 +844,206 @@ xf86PostMotionEvent(DeviceIntPtr device, xEvent xE[2]; deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE; deviceValuator *xv = (deviceValuator*) xev+1; - LocalDevicePtr local = (LocalDevicePtr)device->public.devicePrivate; - char *buff; - Time current = GetTimeInMillis(); + LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate; + char *buff = 0; + Time current; + Bool is_core = xf86IsCorePointer(device); + Bool is_shared = xf86ShareCorePointer(device); + Bool drag = xf86SendDragEvents(device); + ValuatorClassPtr val = device->valuator; + int valuator[6]; + int oldaxis[6]; + int *axisvals; + AxisInfoPtr axes; + int dx = 0, dy = 0; + float mult; + int x, y; + int loop_start; + int i; + int num; - if (HAS_MOTION_HISTORY(local)) { + DBG(5, ErrorF("xf86PostMotionEvent BEGIN 0x%x(%s) is_core=%s is_shared=%s is_absolute=%s\n", + device, device->name, + is_core ? "True" : "False", + is_shared ? "True" : "False", + is_absolute ? "True" : "False")); + + xf86Info.lastEventTime = xev->time = current = GetTimeInMillis(); + + if (!is_core) { + if (HAS_MOTION_HISTORY(local)) { buff = ((char *)local->motion_history + (sizeof(INT32) * local->dev->valuator->numAxes + sizeof(Time)) * local->last); - } else - buff = 0; + } + } + + if (num_valuators && (!val || (first_valuator + num_valuators > val->numAxes))) { + ErrorF("Bad valuators reported for device \"%s\"\n", device->name); + return; + } + + axisvals = val->axisVal; + axes = val->axes; va_start(var, num_valuators); + loop_start = first_valuator; for(loop=0; loop<num_valuators; loop++) { - switch (loop % 6) { - case 0: - xv->valuator0 = va_arg(var, int); - break; - case 1: - xv->valuator1 = va_arg(var, int); - break; - case 2: - xv->valuator2 = va_arg(var, int); - break; - case 3: - xv->valuator3 = va_arg(var, int); - break; - case 4: - xv->valuator4 = va_arg(var, int); - break; - case 5: - xv->valuator5 = va_arg(var, int); - break; - } - if ((loop % 6 == 5) || (loop == num_valuators - 1)) { - if (!xf86IsCorePointer(device)) { + + valuator[loop%6] = va_arg(var,int); + + if (loop % 6 == 5 || loop == num_valuators - 1) { + num = loop % 6 + 1; + /* + * Adjust first two relative valuators + */ + if (!is_absolute && num_valuators >= 2 && loop_start == 0) { + + dx = valuator[0]; + dy = valuator[1]; + + /* + * Accelerate + */ + if (device->ptrfeed && device->ptrfeed->ctrl.num) { + /* modeled from xf86Events.c */ + if (device->ptrfeed->ctrl.threshold) { + if ((abs(dx) + abs(dy)) >= device->ptrfeed->ctrl.threshold) { + valuator[0] = (dx * device->ptrfeed->ctrl.num) / + device->ptrfeed->ctrl.den; + valuator[1] = (dy * device->ptrfeed->ctrl.num) / + device->ptrfeed->ctrl.den; + } + } + else if (dx || dy) { + mult = pow((float)(dx*dx+dy*dy), + ((float)(device->ptrfeed->ctrl.num) / + (float)(device->ptrfeed->ctrl.den) - 1.0) / + 2.0) / 2.0; + if (dx) { + local->dxremaind = mult * (float)dx + local->dxremaind; + valuator[0] = (int)local->dxremaind; + local->dxremaind = local->dxremaind - (float)valuator[0]; + } + if (dy) { + local->dyremaind = mult * (float)dy + local->dyremaind; + valuator[1] = (int)local->dyremaind; + local->dyremaind = local->dyremaind - (float)valuator[1]; + } + } + DBG(6, ErrorF("xf86PostMotionEvent acceleration v0=%d v1=%d\n", + valuator[0], valuator[1])); + } + + /* + * Map current position back to device space in case + * the cursor was warped + */ + if (is_core || is_shared) + { + miPointerPosition (&x, &y); + if (local->reverse_conversion_proc) + (*local->reverse_conversion_proc)(local, x, y, axisvals); + else + { + axisvals[0] = x; + axisvals[1] = y; + } + } + } + + /* + * Update axes + */ + for (i = 0; i < num; i++) + { + oldaxis[i] = axisvals[loop_start + i]; + if (is_absolute) + axisvals[loop_start + i] = valuator[i]; + else + axisvals[loop_start + i] += valuator[i]; + } + + /* + * Deliver extension event + */ + if (!is_core) { xev->type = DeviceMotionNotify; xev->detail = 0; - xf86Info.lastEventTime = xev->time = current; xev->deviceid = device->id | MORE_EVENTS; xv->type = DeviceValuator; xv->deviceid = device->id; - xv->num_valuators = (loop % 6) + 1; - xv->first_valuator = first_valuator + (loop / 6) * 6; xv->device_state = 0; + xv->num_valuators = num; + xv->first_valuator = loop_start; + memcpy (&xv->valuator0, &axisvals[loop_start], + sizeof(INT32)*xv->num_valuators); if (HAS_MOTION_HISTORY(local)) { *(Time*)buff = current; - memcpy(buff+sizeof(Time)+sizeof(INT32)*xv->first_valuator, &xv->valuator0, + memcpy(buff+sizeof(Time)+sizeof(INT32)*xv->first_valuator, + &axisvals[loop_start], sizeof(INT32)*xv->num_valuators); } - - xf86eqEnqueue(xE); - } else { - xf86Info.lastEventTime = current; + ENQUEUE(xE); + } - if (num_valuators >= 2) { - if (is_absolute) { - miPointerAbsoluteCursor(xv->valuator0, xv->valuator1, xf86Info.lastEventTime); - } else { - if (device->ptrfeed) { - /* modeled from xf86Events.c */ - if ((abs(xv->valuator0) + abs(xv->valuator1)) >= device->ptrfeed->ctrl.threshold) { - xv->valuator0 = (xv->valuator0 * device->ptrfeed->ctrl.num) / device->ptrfeed->ctrl.den; - xv->valuator1 = (xv->valuator1 * device->ptrfeed->ctrl.num) / device->ptrfeed->ctrl.den; - } - } - miPointerDeltaCursor(xv->valuator0, xv->valuator1, xf86Info.lastEventTime); - } + /* + * Deliver core event + */ + if (is_core || + (is_shared && num_valuators >= 2 && loop_start == 0)) { +#ifdef XFreeXDGA + /* + * Let DGA peek at the event and steal it + */ + xev->type = MotionNotify; + xev->detail = 0; + if (is_absolute) + { + dx = axisvals[0] - oldaxis[0]; + dy = axisvals[1] - oldaxis[1]; + } + if (DGAStealMouseEvent(xf86EventQueue.pEnqueueScreen->myNum, + xE, dx, dy)) + continue; +#endif + if (!(*local->conversion_proc)(local, loop_start, num, + axisvals[0], axisvals[1], + axisvals[2], axisvals[3], + axisvals[4], axisvals[5], + &x, &y)) + continue; + + if (drag) + miPointerAbsoluteCursor (x, y, current); + /* + * Retrieve the position + */ + miPointerPosition (&x, &y); + if (local->reverse_conversion_proc) + (*local->reverse_conversion_proc)(local, x, y, axisvals); + else + { + axisvals[0] = x; + axisvals[1] = y; } - break; } + loop_start += 6; } - va_end(var); } + va_end(var); if (HAS_MOTION_HISTORY(local)) { local->last = (local->last + 1) % device->valuator->numMotionEvents; if (local->last == local->first) local->first = (local->first + 1) % device->valuator->numMotionEvents; } + DBG(5, ErrorF("xf86PostMotionEvent END 0x%x(%s) is_core=%s is_shared=%s\n", + device, device->name, + is_core ? "True" : "False", + is_shared ? "True" : "False")); } void @@ -1007,47 +1058,85 @@ xf86PostProximityEvent(DeviceIntPtr device, xEvent xE[2]; deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE; deviceValuator *xv = (deviceValuator*) xev+1; + ValuatorClassPtr val = device->valuator; + Bool is_core = xf86IsCorePointer(device); + Bool is_absolute = val && ((val->mode & 1) == Relative); + + DBG(5, ErrorF("xf86PostProximityEvent BEGIN 0x%x(%s) prox=%s is_core=%s is_absolute=%s\n", + device, device->name, is_in ? "true" : "false", + is_core ? "True" : "False", + is_absolute ? "True" : "False")); + + if (is_core) { + return; + } + + if (num_valuators && (!val || (first_valuator + num_valuators > val->numAxes))) { + ErrorF("Bad valuators reported for device \"%s\"\n", device->name); + return; + } - va_start(var, num_valuators); - - for(loop=0; loop<num_valuators; loop++) { - switch (loop % 6) { - case 0: - xv->valuator0 = va_arg(var, int); - break; - case 1: - xv->valuator1 = va_arg(var, int); - break; - case 2: - xv->valuator2 = va_arg(var, int); - break; - case 3: - xv->valuator3 = va_arg(var, int); - break; - case 4: - xv->valuator4 = va_arg(var, int); - break; - case 5: - xv->valuator5 = va_arg(var, int); - break; - } - if ((loop % 6 == 5) || (loop == num_valuators - 1)) { - xev->type = is_in ? ProximityIn : ProximityOut; - xev->detail = 0; - xf86Info.lastEventTime = xev->time = GetTimeInMillis(); - xev->deviceid = device->id | MORE_EVENTS; - - xv->type = DeviceValuator; - xv->deviceid = device->id; - - xv->num_valuators = (loop % 6) + 1; - xv->first_valuator = first_valuator + (loop / 6) * 6; - xv->device_state = 0; + xev->type = is_in ? ProximityIn : ProximityOut; + xev->detail = 0; + xev->deviceid = device->id | MORE_EVENTS; - xf86eqEnqueue(xE); + xv->type = DeviceValuator; + xv->deviceid = device->id; + xv->device_state = 0; + + if ((device->valuator->mode & 1) == Relative) { + num_valuators = 0; + } + + if (num_valuators != 0) { + int *axisvals = val->axisVal; + + va_start(var, num_valuators); + + for(loop=0; loop<num_valuators; loop++) { + switch (loop % 6) { + case 0: + xv->valuator0 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 1: + xv->valuator1 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 2: + xv->valuator2 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 3: + xv->valuator3 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 4: + xv->valuator4 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 5: + xv->valuator5 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + } + if ((loop % 6 == 5) || (loop == num_valuators - 1)) { + xf86Info.lastEventTime = xev->time = GetTimeInMillis(); + + xv->num_valuators = (loop % 6) + 1; + xv->first_valuator = first_valuator + (loop / 6) * 6; + ENQUEUE(xE); + } } + va_end(var); } - va_end(var); + else { + /* no valuator */ + xf86Info.lastEventTime = xev->time = GetTimeInMillis(); + + xv->num_valuators = 0; + xv->first_valuator = 0; + ENQUEUE(xE); + } + DBG(5, ErrorF("xf86PostProximityEvent END 0x%x(%s) prox=%s is_core=%s is_absolute=%s\n", + device, device->name, is_in ? "true" : "false", + is_core ? "True" : "False", + is_absolute ? "True" : "False")); + } void @@ -1064,89 +1153,97 @@ xf86PostButtonEvent(DeviceIntPtr device, xEvent xE[2]; deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE; deviceValuator *xv = (deviceValuator*) xev+1; - int is_core_pointer = xf86IsCorePointer(device); - + ValuatorClassPtr val = device->valuator; + Bool is_core = xf86IsCorePointer(device); + Bool is_shared = xf86ShareCorePointer(device); + + DBG(5, ErrorF("xf86PostButtonEvent BEGIN 0x%x(%s) button=%d down=%s is_core=%s is_shared=%s is_absolute=%s\n", + device, device->name, button, + is_down ? "True" : "False", + is_core ? "True" : "False", + is_shared ? "True" : "False", + is_absolute ? "True" : "False")); + /* Check the core pointer button state not to send an inconsistent * event. This can happen with the AlwaysCore feature. */ - if (is_core_pointer && !xf86CheckButton(button, is_down)) { + if ((is_core || is_shared) && + !xf86CheckButton(device->button->map[button], is_down)) + { return; } - va_start(var, num_valuators); - + if (num_valuators && (!val || (first_valuator + num_valuators > val->numAxes))) { + ErrorF("Bad valuators reported for device \"%s\"\n", device->name); + return; + } - for(loop=0; loop<num_valuators; loop++) { - switch (loop % 6) { - case 0: - xv->valuator0 = va_arg(var, int); - break; - case 1: - xv->valuator1 = va_arg(var, int); - break; - case 2: - xv->valuator2 = va_arg(var, int); - break; - case 3: - xv->valuator3 = va_arg(var, int); - break; - case 4: - xv->valuator4 = va_arg(var, int); - break; - case 5: - xv->valuator5 = va_arg(var, int); - break; - } - if (((loop % 6 == 5) || (loop == num_valuators - 1)) && - !is_core_pointer) { - xev->type = is_down ? DeviceButtonPress : DeviceButtonRelease; - xev->detail = button; - - xf86Info.lastEventTime = xev->time = GetTimeInMillis(); - xev->deviceid = device->id | MORE_EVENTS; - - xv->type = DeviceValuator; - xv->deviceid = device->id; - xv->device_state = 0; - /* if the device is in the relative mode we don't have to send valuators */ - xv->num_valuators = is_absolute ? (loop % 6) + 1 : 0; - xv->first_valuator = first_valuator + (loop / 6) * 6; - xf86eqEnqueue(xE); - /* if the device is in the relative mode only one event is needed */ - if (!is_absolute) break; - } - if (is_core_pointer && loop == 1) { - int cx, cy; + if (!is_core) { + xev->type = is_down ? DeviceButtonPress : DeviceButtonRelease; + xev->detail = button; + xev->deviceid = device->id | MORE_EVENTS; - GetSpritePosition(&cx, &cy); - - /* Try to find the index in the core buttons map - * which corresponds to the extended button for - * an AlwaysCore device. - */ - if (xf86IsAlwaysCore(device)) { - int loop; + xv->type = DeviceValuator; + xv->deviceid = device->id; + xv->device_state = 0; - button = device->button->map[button]; - - for(loop=1; loop<=inputInfo.pointer->button->numButtons; loop++) { - if (inputInfo.pointer->button->map[loop] == button) { - button = loop; - break; - } + if (num_valuators != 0) { + int *axisvals = val->axisVal; + + va_start(var, num_valuators); + + for(loop=0; loop<num_valuators; loop++) { + switch (loop % 6) { + case 0: + xv->valuator0 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 1: + xv->valuator1 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 2: + xv->valuator2 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 3: + xv->valuator3 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 4: + xv->valuator4 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + case 5: + xv->valuator5 = is_absolute ? va_arg(var, int) : axisvals[loop]; + break; + } + if ((loop % 6 == 5) || (loop == num_valuators - 1)) { + xf86Info.lastEventTime = xev->time = GetTimeInMillis(); + xv->num_valuators = (loop % 6) + 1; + xv->first_valuator = first_valuator + (loop / 6) * 6; + ENQUEUE(xE); + } } - - xE->u.u.type = is_down ? ButtonPress : ButtonRelease; - xE->u.u.detail = button; - xE->u.keyButtonPointer.rootY = cx; - xE->u.keyButtonPointer.rootX = cy; - xf86Info.lastEventTime = xE->u.keyButtonPointer.time = GetTimeInMillis(); - xf86eqEnqueue(xE); - break; + va_end(var); + } + else { + /* no valuator */ + xf86Info.lastEventTime = xev->time = GetTimeInMillis(); + xv->num_valuators = 0; + xv->first_valuator = 0; + ENQUEUE(xE); } } - va_end(var); + + /* removed rootX/rootY as DIX sets these fields */ + if (is_core || is_shared) { + xE->u.u.type = is_down ? ButtonPress : ButtonRelease; + xE->u.u.detail = device->button->map[button]; + xf86Info.lastEventTime = xE->u.keyButtonPointer.time = GetTimeInMillis(); + +#ifdef XFreeXDGA + if (!DGAStealMouseEvent(xf86EventQueue.pEnqueueScreen->myNum, xE, 0, 0)) +#endif + ENQUEUE(xE); + } + DBG(5, ErrorF("xf86PostButtonEvent END\n")); } void @@ -1166,7 +1263,6 @@ xf86PostKeyEvent(DeviceIntPtr device, va_start(var, num_valuators); - for(loop=0; loop<num_valuators; loop++) { switch (loop % 6) { case 0: @@ -1202,7 +1298,7 @@ xf86PostKeyEvent(DeviceIntPtr device, xv->num_valuators = is_absolute ? (loop % 6) + 1 : 0; xv->first_valuator = first_valuator + (loop / 6) * 6; - xf86eqEnqueue(xE); + ENQUEUE(xE); /* if the device is in the relative mode only one event is needed */ if (!is_absolute) break; } @@ -1210,6 +1306,28 @@ xf86PostKeyEvent(DeviceIntPtr device, va_end(var); } +void +xf86PostKeyboardEvent(DeviceIntPtr device, + unsigned int key_code, + int is_down) +{ + xEvent xE[2]; + deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE; + + if (xf86IsCoreKeyboard(device)) { + xev->type = is_down ? KeyPress : KeyRelease; + } else { + xev->type = is_down ? DeviceKeyPress : DeviceKeyRelease; + } + xev->detail = key_code; + xf86Info.lastEventTime = xev->time = GetTimeInMillis(); + +#ifdef XFreeXDGA + /* if(!DGAStealKeyEvent(xf86EventQueue.pEnqueueScreen->myNum, xE)) */ +#endif + ENQUEUE(xE); +} + /* * Motion history management. */ @@ -1221,7 +1339,7 @@ xf86MotionHistoryAllocate(LocalDevicePtr local) if (!HAS_MOTION_HISTORY(local)) return; - + if (local->motion_history) xfree(local->motion_history); local->motion_history = xalloc((sizeof(INT32) * valuator->numAxes + sizeof(Time)) * valuator->numMotionEvents); local->first = 0; @@ -1261,4 +1379,102 @@ xf86GetMotionEvents(DeviceIntPtr dev, return num; } +LocalDevicePtr +xf86FirstLocalDevice() +{ + return xf86InputDevs; +} + +/* + * Cx - raw data from touch screen + * Sxhigh - scaled highest dimension + * (remember, this is of rows - 1 because of 0 origin) + * Sxlow - scaled lowest dimension + * Rxhigh - highest raw value from touch screen calibration + * Rxlow - lowest raw value from touch screen calibration + * + * This function is the same for X or Y coordinates. + * You may have to reverse the high and low values to compensate for + * different orgins on the touch screen vs X. + */ + +int +xf86ScaleAxis(int Cx, + int Sxhigh, + int Sxlow, + int Rxhigh, + int Rxlow ) +{ + int X; + int dSx = Sxhigh - Sxlow; + int dRx = Rxhigh - Rxlow; + + dSx = Sxhigh - Sxlow; + if (dRx) { + X = ((dSx * (Cx - Rxlow)) / dRx) + Sxlow; + } + else { + X = 0; + ErrorF ("Divide by Zero in xf86ScaleAxis"); + } + + if (X > Sxlow) + X = Sxlow; + if (X < Sxhigh) + X = Sxhigh; + + return (X); +} + +/* + * This function checks the given screen against the current screen and + * makes changes if appropriate. It should be called from an XInput driver's + * ReadInput function before any events are posted, if the device is screen + * specific like a touch screen. + */ +void +xf86XInputSetScreen(LocalDevicePtr local, + int screen_number, + int x, + int y) +{ + if ((xf86IsCorePointer(local->dev) || xf86ShareCorePointer(local->dev)) && + (miPointerCurrentScreen() != screenInfo.screens[screen_number])) { + miPointerSetNewScreen (screen_number, x, y); + } +} + + +void +xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval, int maxval, + int resolution, int min_res, int max_res) +{ +#ifdef XINPUT + if (maxval == -1) { + if (axnum == 0) + maxval = screenInfo.screens[0]->width - 1; + else if (axnum == 1) + maxval = screenInfo.screens[0]->height - 1; + /* else? */ + } + InitValuatorAxisStruct(dev, axnum, minval, maxval, resolution, min_res, + max_res); +#endif +} + +/* + * Set the valuator values to be in synch with dix/event.c + * DefineInitialRootWindow(). + */ +void +xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum) +{ +#ifdef XINPUT + if (axnum == 0) + dev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2; + else if (axnum == 1) + dev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2; +#endif +} + /* end of xf86Xinput.c */ diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h index b2bb8832f..1e9694402 100644 --- a/hw/xfree86/common/xf86Xinput.h +++ b/hw/xfree86/common/xf86Xinput.h @@ -1,6 +1,6 @@ -/* $Xorg: xf86Xinput.h,v 1.3 2000/08/17 19:50:31 cpqbld Exp $ */ +/* $XConsortium: xf86Xinput.h /main/11 1996/10/27 11:05:29 kaleb $ */ /* - * Copyright 1995,1996 by Frederic Lepied, France. <fred@sugix.frmug.fr.net> + * Copyright 1995-1999 by Frederic Lepied, France. <Lepied@XFree86.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -22,7 +22,7 @@ * */ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Xinput.h,v 3.14.2.1 1997/05/12 12:52:29 hohndel Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Xinput.h,v 3.35 2002/10/11 01:40:31 dawes Exp $ */ #ifndef _xf86Xinput_h #define _xf86Xinput_h @@ -30,251 +30,164 @@ #ifndef NEED_EVENTS #define NEED_EVENTS #endif -#include "X.h" -#include "Xproto.h" +#include "xf86str.h" #include "inputstr.h" -#include "XI.h" -#include "XIproto.h" +#ifdef XINPUT +#include "extensions/XI.h" +#include "extensions/XIproto.h" #include "XIstubs.h" +#endif + +/* Input device flags */ +#define XI86_OPEN_ON_INIT 0x01 /* open the device at startup time */ +#define XI86_CONFIGURED 0x02 /* the device has been configured */ +#define XI86_ALWAYS_CORE 0x04 /* device always controls the pointer */ +/* the device sends Xinput and core pointer events */ +#define XI86_SEND_CORE_EVENTS XI86_ALWAYS_CORE +/* if the device is the core pointer or is sending core events, and + * SEND_DRAG_EVENTS is false, and a buttons is done, then no motion events + * (mouse drag action) are sent. This is mainly to allow a touch screen to be + * used with netscape and other browsers which do strange things if the mouse + * moves between button down and button up. With a touch screen, this motion + * is common due to the user's finger moving slightly. + */ +#define XI86_SEND_DRAG_EVENTS 0x08 +#define XI86_CORE_POINTER 0x10 /* device is the core pointer */ +#define XI86_CORE_KEYBOARD 0x20 /* device is the core keyboard */ +#define XI86_POINTER_CAPABLE 0x40 /* capable of being a core pointer */ +#define XI86_KEYBOARD_CAPABLE 0x80 /* capable of being a core keyboard */ -#define XI86_NO_OPEN_ON_INIT 1 /* open the device only when needed */ -#define XI86_CONFIGURED 2 /* the device has been configured */ -#define XI86_ALWAYS_CORE 4 /* the device always controls the pointer */ +#define XI_PRIVATE(dev) \ + (((LocalDevicePtr)((dev)->public.devicePrivate))->private) -#ifdef PRIVATE -#undef PRIVATE +#ifdef DBG +#undef DBG #endif -#define PRIVATE(dev) (((LocalDevicePtr)((dev)->public.devicePrivate))->private) +#define DBG(lvl, f) {if ((lvl) <= xf86GetVerbosity()) f;} #ifdef HAS_MOTION_HISTORY #undef HAS_MOTION_HISTORY #endif #define HAS_MOTION_HISTORY(local) ((local)->dev->valuator && (local)->dev->valuator->numMotionEvents) -typedef struct _LocalDeviceRec { - char *name; - int flags; - Bool (*device_config)( -#if NeedNestedPrototypes - struct _LocalDeviceRec** /*array*/, - int /*index*/, - int /*max*/, - LexPtr /*val*/ -#endif - ); - Bool (*device_control)( -#if NeedNestedPrototypes - DeviceIntPtr /*device*/, - int /*what*/ -#endif - ); - void (*read_input)( -#if NeedNestedPrototypes - struct _LocalDeviceRec* /*local*/ -#endif - ); - int (*control_proc)( -#if NeedNestedPrototypes - struct _LocalDeviceRec* /*local*/, - xDeviceCtl* /* control */ -#endif - ); - void (*close_proc)( -#if NeedNestedPrototypes - struct _LocalDeviceRec* /*local*/ -#endif - ); - int (*switch_mode)( -#if NeedNestedPrototypes - ClientPtr /*client*/, - DeviceIntPtr /*dev*/, - int /*mode*/ -#endif - ); - int fd; - Atom atom; - DeviceIntPtr dev; - pointer private; - int private_flags; - pointer motion_history; - ValuatorMotionProcPtr motion_history_proc; - unsigned int history_size; /* only for configuration purpose */ - unsigned int first; - unsigned int last; - char *type_name; - IntegerFeedbackPtr always_core_feedback; -} LocalDeviceRec, *LocalDevicePtr; +#ifdef XINPUT +/* This holds the input driver entry and module information. */ +typedef struct _InputDriverRec { + int driverVersion; + char * driverName; + void (*Identify)(int flags); + struct _LocalDeviceRec *(*PreInit)(struct _InputDriverRec *drv, + IDevPtr dev, int flags); + void (*UnInit)(struct _InputDriverRec *drv, + struct _LocalDeviceRec *pInfo, + int flags); + pointer module; + int refCount; +} InputDriverRec, *InputDriverPtr; +#endif + +/* This is to input devices what the ScrnInfoRec is to screens. */ + +typedef struct _LocalDeviceRec { + struct _LocalDeviceRec *next; + char * name; + int flags; + + Bool (*device_control)(DeviceIntPtr device, int what); + void (*read_input)(struct _LocalDeviceRec *local); + int (*control_proc)(struct _LocalDeviceRec *local, + xDeviceCtl *control); + void (*close_proc)(struct _LocalDeviceRec *local); + int (*switch_mode)(ClientPtr client, DeviceIntPtr dev, + int mode); + Bool (*conversion_proc)(struct _LocalDeviceRec *local, + int first, int num, int v0, + int v1, int v2, int v3, int v4, + int v5, int *x, int *y); + Bool (*reverse_conversion_proc)( + struct _LocalDeviceRec *local, + int x, int y, int *valuators); + + int fd; + Atom atom; + DeviceIntPtr dev; + pointer private; + int private_flags; + pointer motion_history; + ValuatorMotionProcPtr motion_history_proc; + unsigned int history_size; /* only for configuration purpose */ + unsigned int first; + unsigned int last; + int old_x; + int old_y; + float dxremaind; + float dyremaind; + char * type_name; + IntegerFeedbackPtr always_core_feedback; + IDevPtr conf_idev; + InputDriverPtr drv; + pointer module; + pointer options; +} LocalDeviceRec, *LocalDevicePtr, InputInfoRec, *InputInfoPtr; typedef struct _DeviceAssocRec { - char *config_section_name; - LocalDevicePtr (*device_allocate)( -#if NeedNestedPrototypes - void -#endif -); + char * config_section_name; + LocalDevicePtr (*device_allocate)(void); } DeviceAssocRec, *DeviceAssocPtr; -extern int DeviceKeyPress; -extern int DeviceKeyRelease; -extern int DeviceButtonPress; -extern int DeviceButtonRelease; -extern int DeviceMotionNotify; -extern int DeviceValuator; -extern int ProximityIn; -extern int ProximityOut; - -extern int -xf86IsCorePointer( -#if NeedFunctionPrototypes - DeviceIntPtr /*dev*/ -#endif -); - -extern int -xf86IsCoreKeyboard( -#if NeedFunctionPrototypes - DeviceIntPtr /*dev*/ -#endif -); - -extern void -xf86AlwaysCore( -#if NeedFunctionPrototypes - LocalDevicePtr /*local*/, - Bool /*always*/ -#endif -); - -void -xf86configExtendedInputSection( -#ifdef NeedFunctionPrototypes - LexPtr /* val */ -#endif -); - -void -xf86AddDeviceAssoc( -#ifdef NeedFunctionPrototypes - DeviceAssocPtr /* assoc */ -#endif -); - -void -InitExtInput( -#ifdef NeedFunctionPrototypes - void -#endif -); - -Bool -xf86eqInit ( -#ifdef NeedFunctionPrototypes - DevicePtr /* pKbd */, - DevicePtr /* pPtr */ -#endif -); - -void -xf86eqEnqueue ( -#ifdef NeedFunctionPrototypes - struct _xEvent * /*event */ -#endif -); - -void -xf86eqProcessInputEvents ( -#ifdef NeedFunctionPrototypes - void -#endif -); - -void -xf86PostMotionEvent( -#if NeedVarargsPrototypes - DeviceIntPtr /*device*/, - int /*is_absolute*/, - int /*first_valuator*/, - int /*num_valuators*/, - ... -#endif -); - -void -xf86PostProximityEvent( -#if NeedVarargsPrototypes - DeviceIntPtr /*device*/, - int /*is_in*/, - int /*first_valuator*/, - int /*num_valuators*/, - ... -#endif -); - -void -xf86PostButtonEvent( -#if NeedVarargsPrototypes - DeviceIntPtr /*device*/, - int /*is_absolute*/, - int /*button*/, - int /*is_down*/, - int /*first_valuator*/, - int /*num_valuators*/, - ... -#endif -); - -void -xf86PostKeyEvent( -#if NeedVarargsPrototypes - DeviceIntPtr device, - unsigned int key_code, - int is_down, - int is_absolute, - int first_valuator, - int num_valuators, - ... -#endif -); - -void -xf86AddDeviceAssoc( -#if NeedFunctionPrototypes - DeviceAssocPtr /*assoc*/ -#endif -); - -void -xf86MotionHistoryAllocate( -#if NeedFunctionPrototypes - LocalDevicePtr local -#endif -); - -int -xf86GetMotionEvents( -#if NeedFunctionPrototypes - DeviceIntPtr dev, - xTimecoord *buff, - unsigned long start, - unsigned long stop, - ScreenPtr pScreen -#endif -); - -void -xf86XinputFinalizeInit( -#if NeedFunctionPrototypes - DeviceIntPtr dev -#endif -); - -Bool -xf86CheckButton( -#if NeedFunctionPrototypes - int button, - int down -#endif -); +/* xf86Globals.c */ +extern InputInfoPtr xf86InputDevs; + +/* xf86Xinput.c */ +int xf86IsCorePointer(DeviceIntPtr dev); +int xf86IsCoreKeyboard(DeviceIntPtr dev); +void xf86XInputSetSendCoreEvents(LocalDevicePtr local, Bool always); +#define xf86AlwaysCore(a,b) xf86XInputSetSendCoreEvents(a,b) + +void InitExtInput(void); +Bool xf86eqInit(DevicePtr pKbd, DevicePtr pPtr); +void xf86eqEnqueue(struct _xEvent *event); +void xf86eqProcessInputEvents (void); +void xf86eqSwitchScreen(ScreenPtr pScreen, Bool fromDIX); +void xf86PostMotionEvent(DeviceIntPtr device, int is_absolute, + int first_valuator, int num_valuators, ...); +void xf86PostProximityEvent(DeviceIntPtr device, int is_in, + int first_valuator, int num_valuators, ...); +void xf86PostButtonEvent(DeviceIntPtr device, int is_absolute, int button, + int is_down, int first_valuator, int num_valuators, + ...); +void xf86PostKeyEvent(DeviceIntPtr device, unsigned int key_code, int is_down, + int is_absolute, int first_valuator, int num_valuators, + ...); +void xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int key_code, + int is_down); +void xf86MotionHistoryAllocate(LocalDevicePtr local); +int xf86GetMotionEvents(DeviceIntPtr dev, xTimecoord *buff, + unsigned long start, unsigned long stop, + ScreenPtr pScreen); +void xf86XinputFinalizeInit(DeviceIntPtr dev); +Bool xf86CheckButton(int button, int down); +void xf86SwitchCoreDevice(LocalDevicePtr device, DeviceIntPtr core); +LocalDevicePtr xf86FirstLocalDevice(void); +int xf86ScaleAxis(int Cx, int Sxhigh, int Sxlow, int Rxhigh, int Rxlow); +void xf86XInputSetScreen(LocalDevicePtr local, int screen_number, int x, int y); +void xf86ProcessCommonOptions(InputInfoPtr pInfo, pointer options); +void xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval, + int maxval, int resolution, int min_res, + int max_res); +void xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum); +void xf86AddEnabledDevice(InputInfoPtr pInfo); +void xf86RemoveEnabledDevice(InputInfoPtr pInfo); + +/* xf86Helper.c */ +void xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags); +void xf86DeleteInputDriver(int drvIndex); +InputInfoPtr xf86AllocateInput(InputDriverPtr drv, int flags); +void xf86DeleteInput(InputInfoPtr pInp, int flags); + +/* xf86Option.c */ +void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts, + pointer extraOpts); #endif /* _xf86Xinput_h */ |