First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / os-support / linux / lnx_axp.c
blobe255118ccdcbc62c08f54114706cd87e470f27ea
2 #ifdef HAVE_XORG_CONFIG_H
3 #include <xorg-config.h>
4 #endif
6 #include <stdio.h>
7 #include <X11/X.h>
8 #include "os.h"
9 #include "xf86.h"
10 #include "xf86Priv.h"
11 #include "shared/xf86Axp.h"
13 axpDevice lnxGetAXP(void);
15 typedef struct
16 { char* sysName;
17 char* sysVari;
18 char* cpu;
19 axpDevice sys; }
20 AXP;
22 static AXP axpList[] = {
23 { "Tsunami", NULL, NULL, TSUNAMI },
24 { "Eiger", NULL, NULL, TSUNAMI },
25 {"Noname", NULL, NULL, LCA },
26 { "AlphaBook1", NULL, NULL, LCA },
27 {"EB66", NULL, NULL, LCA},
28 {"EB64+",NULL,NULL, APECS},
29 {"Noritake",NULL,"EV5",CIA},
30 {"Noritake",NULL,"EV56",CIA},
31 {"Noritake",NULL,NULL,APECS},
32 {"XL",NULL,NULL,APECS},
33 {"Avanti",NULL,NULL,APECS},
34 {"Mikasa",NULL,"EV5",CIA},
35 {"Mikasa",NULL,"EV56",CIA},
36 {"Mikasa",NULL,NULL,APECS},
37 {"EB164","EB164",NULL,CIA},
38 {"EB164","PC164", NULL,CIA},
39 {"EB164","LX164",NULL, PYXIS},
40 {"EB164","SX164",NULL, PYXIS},
41 {"EB164","RX164",NULL, POLARIS},
42 {"Alcor",NULL,NULL,CIA},
43 {"Takara",NULL,NULL,CIA},
44 {"Sable",NULL, "EV5",T2_GAMMA},
45 {"Sable",NULL,"EV56",T2_GAMMA},
46 {"Sable",NULL,NULL,T2},
47 {"Rawhide",NULL,NULL,MCPCIA},
48 {"Jensen",NULL,NULL,JENSEN},
49 {"Miata",NULL,NULL,PYXIS_CIA},
50 {"Ruffian",NULL,NULL,PYXIS_CIA},
51 {"Nautilus",NULL,NULL,IRONGATE},
52 {NULL,NULL,NULL,NONE}
56 axpDevice
57 lnxGetAXP(void)
59 FILE *file;
60 int count = 0;
61 char res[256];
62 char cpu[255];
63 char systype[255];
64 char sysvari[255];
65 if (!(file = fopen("/proc/cpuinfo","r")))
66 return SYS_NONE;
67 do {
68 if (!fgets(res,0xff,file)) return SYS_NONE;
69 switch (count) {
70 case 1:
71 sscanf(res, "cpu model : %s",cpu);
72 #ifdef DEBUG
73 ErrorF("CPU %s\n",cpu);
74 #endif
75 break;
76 case 5:
77 sscanf(res, "system type : %s",systype);
78 #ifdef DEBUG
79 ErrorF("system type : %s\n",systype);
80 #endif
81 break;
82 case 6:
83 sscanf(res, "system variation : %s",sysvari);
84 #ifdef DEBUG
85 ErrorF("system variation: %s\n",sysvari);
86 #endif
87 break;
89 count++;
90 } while (count < 8);
92 fclose(file);
94 count = 0;
96 do {
97 if (!axpList[count].sysName || !strcmp(axpList[count].sysName,systype)) {
98 if (axpList[count].sysVari && strcmp(axpList[count].sysVari,sysvari)) {
99 count++;
100 continue;
102 if (axpList[count].cpu && strcmp(axpList[count].cpu,cpu)) {
103 count++;
104 continue;
106 return axpList[count].sys;
108 count++;
109 } while (1);
113 * pciconfig_iobase wrappers and dynamic i/o selection
115 #include "lnx.h"
116 #include <unistd.h>
117 #include <errno.h>
119 /* glibc versions (single hose only) */
120 extern void _outb(char val, unsigned long port);
121 extern void _outw(short val, unsigned long port);
122 extern void _outl(int val, unsigned long port);
123 extern unsigned int _inb(unsigned long port);
124 extern unsigned int _inw(unsigned long port);
125 extern unsigned int _inl(unsigned long port);
127 extern void _dense_outb(char, unsigned long);
128 extern void _dense_outw(short, unsigned long);
129 extern void _dense_outl(int, unsigned long);
130 extern unsigned int _dense_inb(unsigned long);
131 extern unsigned int _dense_inw(unsigned long);
132 extern unsigned int _dense_inl(unsigned long);
134 _X_EXPORT void (*_alpha_outb)(char, unsigned long) = _outb;
135 _X_EXPORT void (*_alpha_outw)(short, unsigned long) = _outw;
136 _X_EXPORT void (*_alpha_outl)(int, unsigned long) = _outl;
137 _X_EXPORT unsigned int (*_alpha_inb)(unsigned long) = _inb;
138 _X_EXPORT unsigned int (*_alpha_inw)(unsigned long) = _inw;
139 _X_EXPORT unsigned int (*_alpha_inl)(unsigned long) = _inl;
141 static long _alpha_iobase_query(unsigned, int, int, int);
142 long (*_iobase)(unsigned, int, int, int) = _alpha_iobase_query;
144 static long
145 _alpha_iobase(unsigned flags, int hose, int bus, int devfn)
147 #ifdef __NR_pciconfig_iobase
148 if (bus < 0) {
149 bus = hose;
150 flags |= IOBASE_FROM_HOSE;
153 return syscall(__NR_pciconfig_iobase, flags, bus, devfn);
154 #else
155 return -ENOSYS
156 #endif
159 static long
160 _alpha_iobase_legacy(unsigned flags, int hose, int bus, int devfn)
162 if (hose > 0) return -ENODEV;
163 if (flags & IOBASE_DENSE_MEM) return _bus_base();
164 if (flags & IOBASE_SPARSE_MEM) return _bus_base_sparse();
165 return 0;
168 static long
169 _alpha_iobase_query(unsigned flags, int hose, int bus, int devfn)
172 * Only use iobase if the syscall is supported *and* it's
173 * a dense io system
175 if (_alpha_iobase(IOBASE_DENSE_IO, 0, 0, 0) > 0) {
177 * The syscall worked and it's a dense io system - take over the
178 * io subsystem
180 _iobase = _alpha_iobase;
182 #ifndef INCLUDE_XF86_NO_DOMAIN
184 * Only take over the inx/outx functions if this is a dense I/O
185 * system *and* addressing domains are being used. The dense I/O
186 * routines expect I/O to be mapped (as done in xf86MapDomainIO)
188 _alpha_outb = _dense_outb;
189 _alpha_outw = _dense_outw;
190 _alpha_outl = _dense_outl;
191 _alpha_inb = _dense_inb;
192 _alpha_inw = _dense_inw;
193 _alpha_inl = _dense_inl;
194 #endif /* !INCLUDE_XF86_NO_DOMAIN */
195 } else _iobase = _alpha_iobase_legacy;
197 return _iobase(flags, hose, bus, devfn);