2 * Copyright 2003 by David H. Dawes.
3 * Copyright 2003 by X-Oz Technologies.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 * Except as contained in this notice, the name of the copyright holder(s)
25 * and author(s) shall not be used in advertising or otherwise to promote
26 * the sale, use or other dealings in this Software without prior written
27 * authorization from the copyright holder(s) and author(s).
29 * Author: David Dawes <dawes@XFree86.Org>.
32 #ifdef HAVE_XORG_CONFIG_H
33 #include <xorg-config.h>
37 #include "xf86Parser.h"
38 #include "xf86tokens.h"
39 #include "xf86Config.h"
41 #include "xf86_OSlib.h"
43 /* Sections for the default built-in configuration. */
45 #define BUILTIN_MODULE_SECTION \
46 "Section \"Module\"\n" \
47 "\tLoad\t\"extmod\"\n" \
50 "\tLoad\t\"freetype\"\n" \
51 "\tLoad\t\"type1\"\n" \
52 "\tLoad\t\"record\"\n" \
56 #define BUILTIN_DEVICE_NAME \
57 "\"Builtin Default %s Device %d\""
59 #define BUILTIN_DEVICE_SECTION_PRE \
60 "Section \"Device\"\n" \
61 "\tIdentifier\t" BUILTIN_DEVICE_NAME "\n" \
64 #define BUILTIN_DEVICE_SECTION_POST \
67 #define BUILTIN_DEVICE_SECTION \
68 BUILTIN_DEVICE_SECTION_PRE \
69 BUILTIN_DEVICE_SECTION_POST
71 #define BUILTIN_MONITOR_NAME \
72 "\"Builtin Default Monitor\""
74 #define BUILTIN_MONITOR_SECTION \
75 "Section \"Monitor\"\n" \
76 "\tIdentifier\t" BUILTIN_MONITOR_NAME "\n" \
79 #define BUILTIN_SCREEN_NAME \
80 "\"Builtin Default %s Screen %d\""
82 #define BUILTIN_SCREEN_SECTION \
83 "Section \"Screen\"\n" \
84 "\tIdentifier\t" BUILTIN_SCREEN_NAME "\n" \
85 "\tDevice\t" BUILTIN_DEVICE_NAME "\n" \
86 "\tMonitor\t" BUILTIN_MONITOR_NAME "\n" \
89 #define BUILTIN_LAYOUT_SECTION_PRE \
90 "Section \"ServerLayout\"\n" \
91 "\tIdentifier\t\"Builtin Default Layout\"\n"
93 #define BUILTIN_LAYOUT_SCREEN_LINE \
94 "\tScreen\t" BUILTIN_SCREEN_NAME "\n"
96 #define BUILTIN_LAYOUT_SECTION_POST \
99 static const char **builtinConfig
= NULL
;
100 static int builtinLines
= 0;
101 static const char *deviceList
[] = {
109 * A built-in config file is stored as an array of strings, with each string
110 * representing a single line. AppendToConfig() breaks up the string "s"
111 * into lines, and appends those lines it to builtinConfig.
115 AppendToList(const char *s
, const char ***list
, int *lines
)
117 char *str
, *newstr
, *p
;
120 for (p
= strtok(str
, "\n"); p
; p
= strtok(NULL
, "\n")) {
122 *list
= xnfrealloc(*list
, (*lines
+ 1) * sizeof(**list
));
123 newstr
= xnfalloc(strlen(p
) + 2);
125 strcat(newstr
, "\n");
126 (*list
)[*lines
- 1] = newstr
;
127 (*list
)[*lines
] = NULL
;
133 FreeList(const char ***list
, int *lines
)
137 for (i
= 0; i
< *lines
; i
++) {
149 FreeList(&builtinConfig
, &builtinLines
);
153 AppendToConfig(const char *s
)
155 AppendToList(s
, &builtinConfig
, &builtinLines
);
159 videoPtrToDriverName(pciVideoPtr info
)
162 * things not handled yet:
167 switch (info
->vendor
)
169 case 0x1142: return "apm";
170 case 0xedd8: return "ark";
171 case 0x1a03: return "ast";
172 case 0x1002: return "ati";
173 case 0x102c: return "chips";
174 case 0x1013: return "cirrus";
176 if ((info
->chipType
== 0x00d1) || (info
->chipType
== 0x7800))
179 case 0x102b: return "mga";
180 case 0x10c8: return "neomagic";
181 case 0x105d: return "i128";
182 case 0x10de: case 0x12d2: return "nv";
183 case 0x1163: return "rendition";
185 switch (info
->chipType
)
187 case 0x88d0: case 0x88d1: case 0x88f0: case 0x8811:
188 case 0x8812: case 0x8814: case 0x8901:
190 case 0x5631: case 0x883d: case 0x8a01: case 0x8a10:
191 case 0x8c01: case 0x8c03: case 0x8904: case 0x8a13:
196 case 0x1039: return "sis";
197 case 0x126f: return "siliconmotion";
199 if (info
->chipType
< 0x0003)
203 case 0x3d3d: return "glint";
204 case 0x1023: return "trident";
205 case 0x100c: return "tseng";
206 case 0x1106: return "via";
207 case 0x15ad: return "vmware";
218 pciVideoPtr
*pciptr
, info
= NULL
;
222 /* Find the primary device, and get some information about it. */
223 if (xf86PciVideoInfo
) {
224 for (pciptr
= xf86PciVideoInfo
; (info
= *pciptr
); pciptr
++) {
225 if (xf86IsPrimaryPci(info
)) {
230 ErrorF("Primary device is not PCI\n");
233 ErrorF("xf86PciVideoInfo is not set\n");
237 driver
= videoPtrToDriverName(info
);
239 AppendToConfig(BUILTIN_MODULE_SECTION
);
240 AppendToConfig(BUILTIN_MONITOR_SECTION
);
243 snprintf(buf
, sizeof(buf
), BUILTIN_DEVICE_SECTION_PRE
,
246 ErrorF("New driver is \"%s\"\n", driver
);
248 AppendToConfig(BUILTIN_DEVICE_SECTION_POST
);
249 snprintf(buf
, sizeof(buf
), BUILTIN_SCREEN_SECTION
,
250 driver
, 0, driver
, 0);
254 for (p
= deviceList
; *p
; p
++) {
255 snprintf(buf
, sizeof(buf
), BUILTIN_DEVICE_SECTION
, *p
, 0, *p
);
257 snprintf(buf
, sizeof(buf
), BUILTIN_SCREEN_SECTION
, *p
, 0, *p
, 0);
261 AppendToConfig(BUILTIN_LAYOUT_SECTION_PRE
);
263 snprintf(buf
, sizeof(buf
), BUILTIN_LAYOUT_SCREEN_LINE
, driver
, 0);
266 for (p
= deviceList
; *p
; p
++) {
267 snprintf(buf
, sizeof(buf
), BUILTIN_LAYOUT_SCREEN_LINE
, *p
, 0);
270 AppendToConfig(BUILTIN_LAYOUT_SECTION_POST
);
272 xf86MsgVerb(X_DEFAULT
, 0,
273 "Using default built-in configuration (%d lines)\n",
276 xf86MsgVerb(X_DEFAULT
, 3, "--- Start of built-in configuration ---\n");
277 for (p
= builtinConfig
; *p
; p
++)
278 xf86ErrorFVerb(3, "\t%s", *p
);
279 xf86MsgVerb(X_DEFAULT
, 3, "--- End of built-in configuration ---\n");
281 xf86setBuiltinConfig(builtinConfig
);
282 ret
= xf86HandleConfigFile(TRUE
);
285 if (ret
!= CONFIG_OK
)
286 xf86Msg(X_ERROR
, "Error parsing the built-in default configuration.\n");
288 return (ret
== CONFIG_OK
);