First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / doc / sgml / DESIGN.sgml
blob5beff653f9d1899a6a4343dfd207df4ec17910a5
1 <!DOCTYPE linuxdoc PUBLIC "-//Xorg//DTD linuxdoc//EN" [
2 <!ENTITY % defs SYSTEM "defs.ent"> %defs;
3 <!-- config file keyword markup -->
4 <!ENTITY s.key STARTTAG "bf">
5 <!ENTITY e.key ENDTAG "bf">
6 <!-- specific config file keywords -->
7 <!ENTITY k.device "&s.key;Device&e.key;">
8 <!ENTITY k.monitor "&s.key;Monitor&e.key;">
9 <!ENTITY k.display "&s.key;Display&e.key;">
10 <!ENTITY k.inputdevice "&s.key;InputDevice&e.key;">
11 <!ENTITY k.screen "&s.key;Screen&e.key;">
12 <!ENTITY k.serverlayout "&s.key;ServerLayout&e.key;">
13 <!ENTITY k.driver "&s.key;Driver&e.key;">
14 <!ENTITY k.module "&s.key;Module&e.key;">
15 <!ENTITY k.identifier "&s.key;Identifier&e.key;">
16 <!ENTITY k.serverflags "&s.key;ServerFlags&e.key;">
17 <!-- command line markup -->
18 <!ENTITY s.cmd STARTTAG "tt">
19 <!ENTITY e.cmd ENDTAG "tt">
20 <!-- inline code markup -->
21 <!ENTITY s.code STARTTAG "tt">
22 <!ENTITY e.code ENDTAG "tt">
23 <!-- function indent -->
24 <!ENTITY f.indent "&nl&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp">
25 ] >
27 <article>
29 <title>XFree86 server 4.x Design (DRAFT)
30 <author>The XFree86 Project, Inc
31 <and>Updates for X11R&relvers; by Jim Gettys
32 <date>19 December 2003
40 <ident>
41 $XFree86: xc/programs/Xserver/hw/xfree86/doc/sgml/DESIGN.sgml,v 1.53 2003/08/23 14:10:14 dawes Exp $
42 </ident>
45 <p>
46 <bf>NOTE</bf>: This is a DRAFT document, and the interfaces described here
47 are subject to change without notice.
50 <sect>Preface
51 <p>
53 The broad design principles are:
54 <itemize>
55 <item>keep it reasonable
56 <itemize>
57 <item>We cannot rewrite the complete server
58 <item>We don't want to re-invent the wheel
59 </itemize>
60 <item>keep it modular
61 <itemize>
62 <item>As many things as possible should go into modules
63 <item>The basic loader binary should be minimal
64 <item>A clean design with well defined layering is important
65 <item>DDX specific global variables are a nono
66 <item>The structure should be flexible enough to allow
67 future extensions
68 <item> The structure should minimize duplication of common code
69 </itemize>
70 <item>keep important features in mind
71 <itemize>
72 <item>multiple screens, including multiple instances of drivers
73 <item>mixing different color depths and visuals on different
74 and ideally even on the same screen
75 <item>better control of the PCI device used
76 <item>better config file parser
77 <item>get rid of all VGA compatibility assumptions
78 </itemize>
79 </itemize>
81 Unless we find major deficiencies in the DIX layer, we should avoid
82 making changes there.
84 <sect>The xorg.conf File
85 <p>
87 The xorg.conf file format is similar to the old format, with the following
88 changes:
90 <sect1>&k.device; section
91 <p>
93 The &k.device; sections are similar to what they used to be, and
94 describe hardware-specific information for a single video card.
95 &k.device;
96 Some new keywords are added:
99 <descrip>
100 <tag>Driver "drivername"</tag>
101 Specifies the name of the driver to be used for the card. This
102 is mandatory.
103 <tag>BusID "busslot"</tag>
104 Specifies uniquely the location of the card on the bus. The
105 purpose is to identify particular cards in a multi-headed
106 configuration. The format of the argument is intentionally
107 vague, and may be architecture dependent. For a PCI bus, it
108 is something like "bus:slot:func".
109 </descrip>
111 A &k.device; section is considered ``active'' if there is a reference
112 to it in an active &k.screen; section.
114 <sect1>&k.screen; section
117 The &k.screen; sections are similar to what they used to be. They
118 no longer have a &k.driver; keyword, but an &k.identifier; keyword
119 is added. (The &k.driver; keyword may be accepted in place of the
120 &k.identifier; keyword for compatibility purposes.) The identifier
121 can be used to identify which screen is to be active when multiple
122 &k.screen sections are present. It is possible to specify the active
123 screen from the command line. A default is chosen in the absence
124 of one being specified. A &k.screen; section is considered ``active''
125 if there is a reference to it either from the command line, or from
126 an active &k.serverlayout; section.
128 <sect1>&k.inputdevice; section
131 The &k.inputdevice; section is a new section that describes
132 configuration information for input devices. It replaces the old
133 &s.key;Keyboard&e.key;, &s.key;Pointer&e.key; and &s.key;XInput&e.key;
134 sections. Like the &k.device; section, it has two mandatory keywords:
135 &k.identifier; and &k.driver;. For compatibility purposes the old
136 &s.key;Keyboard&e.key; and &s.key;Pointer&e.key; sections are
137 converted by the parser into &k.inputdevice; sections as follows:
139 <descrip>
140 <tag>&s.key;Keyboard&e.key;</tag>
141 &k.identifier; "Implicit Core Keyboard"<newline>
142 &k.driver; "keyboard"
143 <tag>&s.key;Pointer&e.key;</tag>
144 &k.identifier; "Implicit Core Pointer"<newline>
145 &k.driver; "mouse"
146 </descrip>
148 An &k.inputdevice; section is considered active if there is a
149 reference to it in an active &k.serverlayout; section. An
150 &k.inputdevice; section may also be referenced implicitly if there
151 is no &k.serverlayout; section, if the &s.cmd;-screen&e.cmd; command
152 line options is used, or if the &k.serverlayout; section doesn't
153 reference any &k.inputdevice; sections. In this case, the first
154 sections with drivers "keyboard" and "mouse" are used as the core
155 keyboard and pointer respectively.
157 <sect1>&k.serverlayout; section
160 The &k.serverlayout; section is a new section that is used to identify
161 which &k.screen; sections are to be used in a multi-headed configuration,
162 and the relative layout of those screens. It also identifies which
163 &k.inputdevice; sections are to be used. Each &k.serverlayout section
164 has an identifier, a list of &k.screen; section identifiers, and a list of
165 &k.inputdevice; section identifiers. &k.serverflags; options may also be
166 included in a &k.serverlayout; section, making it possible to override
167 the global values in the &k.serverflags; section.
169 A &k.serverlayout; section can be made active by being referenced on
170 the command line. In the absence of this, a default will be chosen
171 (the first one found). The screen names may optionally be followed
172 by a number specifying the preferred screen number, and optionally
173 by information specifying the physical positioning of the screen,
174 either in absolute terms or relative to another screen (or screens).
175 When no screen number is specified, they are numbered according to
176 the order in which they are listed. The old (now obsolete) method
177 of providing the positioning information is to give the names of
178 the four adjacent screens. The order of these is top, bottom, left,
179 right. Here is an example of a &k.serverlayout; section for two
180 screens using the old method, with the second located to the right
181 of the first:
183 <code>
184 Section "ServerLayout"
185 Identifier "Main Layout"
186 Screen 0 "Screen 1" "" "" "" "Screen 2"
187 Screen 1 "Screen 2"
188 Screen "Screen 3"
189 EndSection
190 </code>
192 The preferred way of specifying the layout is to explicitly specify
193 the screen's location in absolute terms or relative to another
194 screen.
196 In the absolute case, the upper left corner's coordinates are given
197 after the &s.key;Absolute&e.key; keyword. If the coordinates are
198 omitted, a value of &s.code;(0,0)&e.code; is assumed. An example
199 of absolute positioning follows:
201 <code>
202 Section "ServerLayout"
203 Identifier "Main Layout"
204 Screen 0 "Screen 1" Absolute 0 0
205 Screen 1 "Screen 2" Absolute 1024 0
206 Screen "Screen 3" Absolute 2048 0
207 EndSection
208 </code>
210 In the relative case, the position is specified by either using one of
211 the following keywords followed by the name of the reference screen:
213 <quote>
214 &s.key;RightOf&nl;
215 LeftOf&nl;
216 Above&nl;
217 Below&nl;
218 Relative&e.key;
219 </quote>
221 When the &s.key;Relative&e.key; keyword is used, the reference screen
222 name is followed by the coordinates of the new screen's origin
223 relative to reference screen. The following example shows how to use
224 some of the relative positioning options.
226 <code>
227 Section "ServerLayout"
228 Identifier "Main Layout"
229 Screen 0 "Screen 1"
230 Screen 1 "Screen 2" RightOf "Screen 1"
231 Screen "Screen 3" Relative "Screen 1" 2048 0
232 EndSection
233 </code>
235 <sect1>Options
238 Options are used more extensively. They may appear in most sections
239 now. Options related to drivers can be present in the &k.screen;,
240 &k.device; and &k.monitor; sections and the &k.display; subsections.
241 The order of precedence is &k.display;, &k.screen;, &k.monitor;,
242 &k.device;. Options have been extended to allow an optional value
243 to be specified in addition to the option name. For more details
244 about options, see the <ref id="options" name="Options"> section
245 for details.
247 <sect>Driver Interface
250 The driver interface consists of a minimal set of entry points that are
251 required based on the external events that the driver must react to.
252 No non-essential structure is imposed on the way they are used beyond
253 that. This is a significant difference compared with the old design.
255 The entry points for drawing operations are already taken care of by
256 the framebuffer code (including, XAA). Extensions and enhancements to
257 framebuffer code are outside the scope of this document.
259 This approach to the driver interface provides good flexibility, but does
260 increase the complexity of drivers. To help address this, the XFree86
261 common layer provides a set of ``helper'' functions to take care of things
262 that most drivers need. These helpers help minimise the amount of code
263 duplication between drivers. The use of helper functions by drivers is
264 however optional, though encouraged. The basic philosophy behind the
265 helper functions is that they should be useful to many drivers, that
266 they should balance this against the complexity of their interface. It
267 is inevitable that some drivers may find some helpers unsuitable and
268 need to provide their own code.
270 Events that a driver needs to react to are:
272 <descrip>
273 <tag>ScreenInit</tag>
275 An initialisation function is called from the DIX layer for each
276 screen at the start of each server generation.
278 <tag>Enter VT</tag>
280 The server takes control of the console.
282 <tag>Leave VT</tag>
284 The server releases control of the console.
286 <tag>Mode Switch</tag>
288 Change video mode.
290 <tag>ViewPort change</tag>
292 Change the origin of the physical view port.
294 <tag>ScreenSaver state change</tag>
296 Screen saver activation/deactivation.
298 <tag>CloseScreen</tag>
300 A close screen function is called from the DIX layer for each screen
301 at the end of each server generation.
302 </descrip>
305 In addition to these events, the following functions are required by
306 the XFree86 common layer:
308 <descrip>
309 <tag>Identify</tag>
311 Print a driver identifying message.
313 <tag>Probe</tag>
315 This is how a driver identifies if there is any hardware present that
316 it knows how to drive.
318 <tag>PreInit</tag>
320 Process information from the xorg.conf file, determine the
321 full characteristics of the hardware, and determine if a valid
322 configuration is present.
323 </descrip>
325 The VidMode extension also requires:
327 <descrip>
328 <tag>ValidMode</tag>
330 Identify if a new mode is usable with the current configuration.
331 The PreInit function (and/or helpers it calls) may also make use
332 of the ValidMode function or something similar.
333 </descrip>
336 Other extensions may require other entry points. The drivers will
337 inform the common layer of these in such cases.
339 <sect>Resource Access Control Introduction
342 Graphics devices are accessed through ranges in I/O or memory space.
343 While most modern graphics devices allow relocation of such ranges many
344 of them still require the use of well established interfaces such as
345 VGA memory and IO ranges or 8514/A IO ranges. With modern buses (like
346 PCI) it is possible for multiple video devices to share access to these
347 resources. The RAC (Resource Access Control) subsystem provides a
348 mechanism for this.
350 <sect1>Terms and Definitions
353 <sect2>Bus
356 ``Bus'' is ambiguous as it is used for different things: it may refer
357 to physical incompatible extension connectors in a computer system.
358 The RAC system knows two such systems: The ISA bus and the PCI bus.
359 (On the software level EISA, MCA and VL buses are currently treated
360 like ISA buses). ``Bus'' may also refer to logically different
361 entities on a single bus system which are connected via bridges. A
362 PCI system may have several distinct PCI buses connecting each other
363 by PCI-PCI bridges or to the host CPU by HOST-PCI bridges.
365 Systems that host more than one bus system link these together using
366 bridges. Bridges are a concern to RAC as they might block or pass
367 specific resources. PCI-PCI bridges may be set up to pass VGA
368 resources to the secondary bus. PCI-ISA buses pass any resources not
369 decoded on the primary PCI bus to the ISA bus. This way VGA resources
370 (although exclusive on the ISA bus) can be shared by ISA and PCI
371 cards. Currently HOST-PCI bridges are not yet handled by RAC as they
372 require specific drivers.
374 <sect2>Entity
377 The smallest independently addressable unit on a system bus is
378 referred to as an entity. So far we know ISA and PCI entities. PCI
379 entities can be located on the PCI bus by an unique ID consisting of
380 the bus, card and function number.
382 <sect2>Resource
385 ``Resource'' refers to a range of memory or I/O addresses an entity
386 can decode.
388 If a device is capable of disabling this decoding the resource is
389 called sharable. For PCI devices a generic method is provided to
390 control resource decoding. Other devices will have to provide a
391 device specific function to control decoding.
393 If the entity is capable of decoding this range at a different
394 location this resource is considered relocatable.
396 Resources which start at a specific address and occupy a single
397 continuous range are called block resources.
399 Alternatively resource addresses can be decoded in a way that they
400 satisfy the conditions:
401 <quote><verb>
402 address & mask == base
403 </verb></quote>
405 <quote><verb>
406 base & mask == base
407 </verb></quote>
408 Resources addressed in such a way are called sparse resources.
410 <sect2>Server States
413 The resource access control system knows two server states: the
414 SETUP and the OPERATING state. The SETUP state is entered whenever
415 a mode change takes place or the server exits or does VT switching.
416 During this state all entity resources are under resource access
417 control. During OPERATING state only those entities are controlled
418 which actually have shared resources that conflict with others.
420 <sect>Control Flow in the Server and Mandatory Driver Functions
423 At the start of each server generation, &s.code;main()&e.code;
424 (&s.code;dix/main.c&e.code;) calls the DDX function
425 &s.code;InitOutput()&e.code;. This is the first place that the DDX gets
426 control. &s.code;InitOutput()&e.code; is expected to fill in the global
427 &s.code;screenInfo&e.code; struct, and one
428 &s.code;screenInfo.screen[]&e.code; entry for each screen present. Here
429 is what &s.code;InitOutput()&e.code; does:
431 <sect1>Parse the xorg.conf file
434 This is done at the start of the first server generation only.
436 The xorg.conf file is read in full, and the resulting information
437 stored in data structures. None of the parsed information is
438 processed at this point. The parser data structures are opaque to
439 the video drivers and to most of the common layer code.
441 The entire file is parsed first to remove any section ordering
442 requirements.
445 <sect1>Initial processing of parsed information and command line options
448 This is done at the start of the first server generation only.
450 The initial processing is to determine paths like the
451 &s.key;ModulePath&e.key;, etc, and to determine which &k.serverlayout;,
452 &k.screen; and &k.device; sections are active.
455 <sect1>Enable port I/O access
458 Port I/O access is controlled from the XFree86 common layer, and is
459 ``all or nothing''. It is enabled prior to calling driver probes, at
460 the start of subsequent server generations, and when VT switching
461 back to the Xserver. It is disabled at the end of server generations,
462 and when VT switching away from the Xserver.
464 The implementation details of this may vary on different platforms.
467 <sect1>General bus probe
470 This is done at the start of the first server generation only.
472 In the case of ix86 machines, this will be a general PCI probe.
473 The full information obtained here will be available to the drivers.
474 This information persists for the life of the Xserver. In the PCI
475 case, the PCI information for all video cards found is available by
476 calling &s.code;xf86GetPciVideoInfo()&e.code;.
478 <quote>
479 &s.code;pciVideoPtr *xf86GetPciVideoInfo(void)&e.code;
480 <quote><p>
481 returns a pointer to a list of pointers to
482 &s.code;pciVideoRec&e.code; entries, of which there is one for
483 each detected PCI video card. The list is terminated with a
484 &s.code;NULL&e.code; pointer. If no PCI video cards were
485 detected, the return value is &s.code;NULL&e.code;.
487 </quote>
488 </quote>
490 After the bus probe, the resource broker is initialised.
493 <sect1>Load initial set of modules
496 This is done at the start of the first server generation only.
498 The core server contains a list of mandatory modules. These are loaded
499 first. Currently the only module on this list is the bitmap font module.
501 The next set of modules loaded are those specified explicitly in the
502 &k.module; section of the config file.
504 The final set of initial modules are the driver modules referenced
505 by the active &k.device; and &k.inputdevice; sections in the config
506 file. Each of these modules is loaded exactly once.
509 <sect1>Register Video and Input Drivers
512 This is done at the start of the first server generation only.
514 When a driver module is loaded, the loader calls its
515 &s.code;Setup&e.code; function. For video drivers, this function
516 calls &s.code;xf86AddDriver()&e.code; to register the driver's
517 &s.code;DriverRec&e.code;, which contains a small set of essential
518 details and driver entry points required during the early phase of
519 &s.code;InitOutput()&e.code;. &s.code;xf86AddDriver()&e.code; adds
520 it to the global &s.code;xf86DriverList[]&e.code; array.
522 The &s.code;DriverRec&e.code; contains the driver canonical name,
523 the &s.code;Identify()&e.code;,
524 &s.code;Probe()&e.code; and &s.code;AvailableOptions()&e.code;
525 function entry points as well as a pointer
526 to the driver's module (as returned from the loader when the driver
527 was loaded) and a reference count which keeps track of how many
528 screens are using the driver. The entry driver entry points are
529 those required prior to the driver allocating and filling in its
530 &s.code;ScrnInfoRec&e.code;.
532 For a static server, the &s.code;xf86DriverList[]&e.code; array is
533 initialised at build time, and the loading of modules is not done.
535 A similar procedure is used for input drivers. The input driver's
536 &s.code;Setup&e.code; function calls
537 &s.code;xf86AddInputDriver()&e.code; to register the driver's
538 &s.code;InputDriverRec&e.code;, which contains a small set of
539 essential details and driver entry points required during the early
540 phase of &s.code;InitInput()&e.code;.
541 &s.code;xf86AddInputDriver()&e.code; adds it to the global
542 &s.code;xf86InputDriverList[]&e.code; array. For a static server,
543 the &s.code;xf86InputDriverList[]&e.code; array is initialised at
544 build time.
546 Both the &s.code;xf86DriverList[]&e.code; and
547 &s.code;xf86InputDriverList[]&e.code; arrays have been initialised
548 by the end of this stage.
550 Once all the drivers are registered, their
551 &s.code;ChipIdentify()&e.code; functions are called.
553 <quote>
554 &s.code;void ChipIdentify(int flags)&e.code;
555 <quote>
556 This is expected to print a message indicating the driver name,
557 a short summary of what it supports, and a list of the chipset
558 names that it supports. It may use the xf86PrintChipsets() helper
559 to do this.
560 </quote>
561 </quote>
563 <quote>
564 &s.code;void xf86PrintChipsets(const char *drvname, const char *drvmsg,
565 &f.indent;SymTabPtr chips)&e.code;
566 <quote>
567 This function provides an easy way for a driver's ChipIdentify
568 function to format the identification message.
569 </quote>
570 </quote>
572 <sect1>Initialise Access Control
575 This is done at the start of the first server generation only.
577 The Resource Access Control (RAC) subsystem is initialised before
578 calling any driver functions that may access hardware. All generic
579 bus information is probed and saved (for restoration later). All
580 (shared resource) video devices are disabled at the generic bus
581 level, and a probe is done to find the ``primary'' video device. These
582 devices remain disabled for the next step.
585 <sect1>Video Driver Probe<label id="probe">
587 This is done at the start of the first server generation only. The
588 &s.code;ChipProbe()&e.code; function of each registered video driver
589 is called.
591 <quote><p>
592 &s.code;Bool ChipProbe(DriverPtr drv, int flags)&e.code;
593 <quote><p>
594 The purpose of this is to identify all instances of hardware
595 supported by the driver. The flags value is currently either 0,
596 &s.code;PROBE_DEFAULT&e.code; or &s.code;PROBE_DETECT&e.code;.
597 &s.code;PROBE_DETECT&e.code; is used if "-configure" or "-probe"
598 command line arguments are given and indicates to the
599 &s.code;Probe()&e.code; function that it should not configure the
600 bus entities and that no xorg.conf information is available.
602 The probe must find the active device sections that match the
603 driver by calling &s.code;xf86MatchDevice()&e.code;. The number
604 of matches found limits the maximum number of instances for this
605 driver. If no matches are found, the function should return
606 &s.code;FALSE&e.code; immediately.
608 Devices that cannot be identified by using device-independent
609 methods should be probed at this stage (keeping in mind that access
610 to all resources that can be disabled in a device-independent way
611 are disabled during this phase). The probe must be a minimal
612 probe. It should just determine if there is a card present that
613 the driver can drive. It should use the least intrusive probe
614 methods possible. It must not do anything that is not essential,
615 like probing for other details such as the amount of memory
616 installed, etc. It is recommended that the
617 &s.code;xf86MatchPciInstances()&e.code; helper function be used
618 for identifying matching PCI devices, and similarly the
619 &s.code;xf86MatchIsaInstances()&e.code; for ISA (non-PCI) devices
620 (see the <ref id="rac" name="RAC"> section). These helpers also
621 checks and claims the appropriate entity. When not using the
622 helper, that should be done with &s.code;xf86CheckPciSlot()&e.code;
623 and &s.code;xf86ClaimPciSlot()&e.code; for PCI devices and
624 &s.code;xf86ClaimIsaSlot()&e.code; for ISA devices (see the
625 <ref id="rac" name="RAC"> section).
627 The probe must register all non-relocatable resources at this
628 stage. If a resource conflict is found between exclusive resources
629 the driver will fail immediately. This is usually best done with
630 the &s.code;xf86ConfigPciEntity()&e.code; helper function
631 for PCI and &s.code;xf86ConfigIsaEntity()&e.code; for ISA
632 (see the <ref id="rac" name="RAC"> section). It is possible to
633 register some entity specific functions with those helpers. When
634 not using the helpers, the &s.code;xf86AddEntityToScreen()&e.code;
635 &s.code;xf86ClaimFixedResources()&e.code; and
636 &s.code;xf86SetEntityFuncs()&e.code; should be used instead (see
637 the <ref id="rac" name="RAC"> section).
639 If a chipset is specified in an active device section which the
640 driver considers relevant (ie it has no driver specified, or the
641 driver specified matches the driver doing the probe), the Probe
642 must return &s.code;FALSE&e.code; if the chipset doesn't match
643 one supported by the driver.
645 If there are no active device sections that the driver considers
646 relevant, it must return &s.code;FALSE&e.code;.
648 Allocate a &s.code;ScrnInfoRec&e.code; for each active instance of the
649 hardware found, and fill in the basic information, including the
650 other driver entry points. This is best done with the
651 &s.code;xf86ConfigIsaEntity()&e.code; helper function for ISA
652 instances or &s.code;xf86ConfigPciEntity()&e.code; for PCI instances.
653 These functions allocate a &s.code;ScrnInfoRec&e.code; for active
654 entities. Optionally &s.code;xf86AllocateScreen()&e.code;
655 function may also be used to allocate the &s.code;ScrnInfoRec&e.code;.
656 Any of these functions take care of initialising fields to defined
657 ``unused'' values.
659 Claim the entities for each instance of the hardware found. This
660 prevents other drivers from claiming the same hardware.
662 Must leave hardware in the same state it found it in, and must not
663 do any hardware initialisation.
665 All detection can be overridden via the config file, and that
666 parsed information is available to the driver at this stage.
668 Returns &s.code;TRUE&e.code; if one or more instances are found,
669 and &s.code;FALSE&e.code; otherwise.
671 </quote>
673 &s.code;int xf86MatchDevice(const char *drivername,
674 &f.indent;GDevPtr **driversectlist)&e.code;
675 <quote><p>
677 This function takes the name of the driver and returns via
678 &s.code;driversectlist&e.code; a list of device sections that
679 match the driver name. The function return value is the number
680 of matches found. If a fatal error is encountered the return
681 value is &s.code;-1&e.code;.
683 The caller should use &s.code;xfree()&e.code; to free
684 &s.code;*driversectlist&e.code; when it is no longer needed.
686 </quote>
688 &s.code;ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags)&e.code;
689 <quote><p>
690 This function allocates a new &s.code;ScrnInfoRec&e.code; in the
691 &s.code;xf86Screens[]&e.code; array. This function is normally
692 called by the video driver &s.code;ChipProbe()&e.code; functions.
693 The return value is a pointer to the newly allocated
694 &s.code;ScrnInfoRec&e.code;. The &s.code;scrnIndex&e.code;,
695 &s.code;origIndex&e.code;, &s.code;module&e.code; and
696 &s.code;drv&e.code; fields are initialised. The reference count
697 in &s.code;drv&e.code; is incremented. The storage for any
698 currently allocated ``privates'' pointers is also allocated and
699 the &s.code;privates&e.code; field initialised (the privates data
700 is of course not allocated or initialised). This function never
701 returns on failure. If the allocation fails, the server exits
702 with a fatal error. The flags value is not currently used, and
703 should be set to zero.
704 </quote>
705 </quote>
707 At the completion of this, a list of &s.code;ScrnInfoRecs&e.code;
708 have been allocated in the &s.code;xf86Screens[]&e.code; array, and
709 the associated entities and fixed resources have been claimed. The
710 following &s.code;ScrnInfoRec&e.code; fields must be initialised at
711 this point:
713 <quote><verb>
714 driverVersion
715 driverName
716 scrnIndex(*)
717 origIndex(*)
718 drv(*)
719 module(*)
720 name
721 Probe
722 PreInit
723 ScreenInit
724 EnterVT
725 LeaveVT
726 numEntities
727 entityList
728 access
729 </verb></quote>
731 <tt>(*)</tt> These are initialised when the &s.code;ScrnInfoRec&e.code;
732 is allocated, and not explicitly by the driver.
734 The following &s.code;ScrnInfoRec&e.code; fields must be initialised
735 if the driver is going to use them:
737 <quote><verb>
738 SwitchMode
739 AdjustFrame
740 FreeScreen
741 ValidMode
742 </verb></quote>
744 <sect1>Matching Screens
747 This is done at the start of the first server generation only.
749 After the Probe phase is finished, there will be some number of
750 &s.code;ScrnInfoRecs&e.code;. These are then matched with the active
751 &k.screen; sections in the xorg.conf, and those not having an active
752 &k.screen; section are deleted. If the number of remaining screens
753 is 0, &s.code;InitOutput()&e.code; sets
754 &s.code;screenInfo.numScreens&e.code; to &s.code;0&e.code; and
755 returns.
757 At this point the following fields of the &s.code;ScrnInfoRecs&e.code;
758 must be initialised:
760 <quote><verb>
761 confScreen
762 </verb></quote>
765 <sect1>Allocate non-conflicting resources
768 This is done at the start of the first server generation only.
770 Before calling the drivers again, the resource information collected
771 from the Probe phase is processed. This includes checking the extent
772 of PCI resources for the probed devices, and resolving any conflicts
773 in the relocatable PCI resources. It also reports conflicts, checks
774 bus routing issues, and anything else that is needed to enable the
775 entities for the next phase.
777 If any drivers registered an &s.code;EntityInit()&e.code; function
778 during the Probe phase, then they are called here.
781 <sect1>Sort the Screens and pre-check Monitor Information
784 This is done at the start of the first server generation only.
786 The list of screens is sorted to match the ordering requested in the
787 config file.
789 The list of modes for each active monitor is checked against the
790 monitor's parameters. Invalid modes are pruned.
793 <sect1>PreInit
796 This is done at the start of the first server generation only.
798 For each &s.code;ScrnInfoRec&e.code;, enable access to the screens entities and call
799 the &s.code;ChipPreInit()&e.code; function.
801 <quote><p>
802 &s.code;Bool ChipPreInit(ScrnInfoRec screen, int flags)&e.code;
803 <quote><p>
804 The purpose of this function is to find out all the information
805 required to determine if the configuration is usable, and to
806 initialise those parts of the &s.code;ScrnInfoRec&e.code; that
807 can be set once at the beginning of the first server generation.
809 The number of entities registered for the screen should be checked
810 against the expected number (most drivers expect only one). The
811 entity information for each of them should be retrieved (with
812 &s.code;xf86GetEntityInfo()&e.code;) and checked for the correct
813 bus type and that none of the sharable resources registered during
814 the Probe phase was rejected.
816 Access to resources for the entities that can be controlled in a
817 device-independent way are enabled before this function is called.
818 If the driver needs to access any resources that it has disabled
819 in an &s.code;EntityInit()&e.code; function that it registered,
820 then it may enable them here providing that it disables them before
821 this function returns.
823 This includes probing for video memory, clocks, ramdac, and all
824 other HW info that is needed. It includes determining the
825 depth/bpp/visual and related info. It includes validating and
826 determining the set of video modes that will be used (and anything
827 that is required to determine that).
829 This information should be determined in the least intrusive way
830 possible. The state of the HW must remain unchanged by this
831 function. Although video memory (including MMIO) may be mapped
832 within this function, it must be unmapped before returning. Driver
833 specific information should be stored in a structure hooked into
834 the &s.code;ScrnInfoRec&e.code;'s &s.code;driverPrivate&e.code;
835 field. Any other modules which require persistent data (ie data
836 that persists across server generations) should be initialised in
837 this function, and they should allocate a ``privates'' index to
838 hook their data into by calling
839 &s.code;xf86AllocateScrnInfoPrivateIndex().&e.code; The ``privates''
840 data is persistent.
842 Helper functions for some of these things are provided at the
843 XFree86 common level, and the driver can choose to make use of
844 them.
846 All additional resources that the screen needs must be registered
847 here. This should be done with
848 &s.code;xf86RegisterResources()&e.code;. If some of the fixed
849 resources registered in the Probe phase are not needed or not
850 decoded by the hardware when in the OPERATING server state, their
851 status should be updated with
852 &s.code;xf86SetOperatingState()&e.code;.
854 Modules may be loaded at any point in this function, and all
855 modules that the driver will need must be loaded before the end
856 of this function. Either the &s.code;xf86LoadSubModule()&e.code;
857 or the &s.code;xf86LoadDrvSubModule()&e.code; function should be
858 used to load modules depending on whether a
859 &s.code;ScrnInfoRec&e.code; has been set up. A driver may unload
860 a module within this function if it was only needed temporarily,
861 and the &s.code;xf86UnloadSubModule()&e.code; function should be used
862 to do that. Otherwise there is no need to explicitly unload modules
863 because the loader takes care of module dependencies and will
864 unload submodules automatically if/when the driver module is
865 unloaded.
867 The bulk of the &s.code;ScrnInfoRec&e.code; fields should be filled
868 out in this function.
870 &s.code;ChipPreInit()&e.code; returns &s.code;FALSE&e.code; when
871 the configuration is unusable in some way (unsupported depth, no
872 valid modes, not enough video memory, etc), and &s.code;TRUE&e.code;
873 if it is usable.
875 It is expected that if the &s.code;ChipPreInit()&e.code; function
876 returns &s.code;TRUE&e.code;, then the only reasons that subsequent
877 stages in the driver might fail are lack or resources (like xalloc
878 failures). All other possible reasons for failure should be
879 determined by the &s.code;ChipPreInit()&e.code; function.
881 </quote>
882 </quote>
884 The &s.code;ScrnInfoRecs&e.code; for screens where the &s.code;ChipPreInit()&e.code; fails are removed.
885 If none remain, &s.code;InitOutput()&e.code; sets &s.code;screenInfo.numScreens&e.code; to &s.code;0&e.code; and returns.
887 At this point, further fields of the &s.code;ScrnInfoRecs&e.code; would normally be
888 filled in. Most are not strictly mandatory, but many are required
889 by other layers and/or helper functions that the driver may choose
890 to use. The documentation for those layers and helper functions
891 indicates which they require.
893 The following fields of the &s.code;ScrnInfoRecs&e.code; should be filled in if the
894 driver is going to use them:
896 <quote><verb>
897 monitor
898 display
899 depth
900 pixmapBPP
901 bitsPerPixel
902 weight (>8bpp only)
903 mask (>8bpp only)
904 offset (>8bpp only)
905 rgbBits (8bpp only)
906 gamma
907 defaultVisual
908 maxHValue
909 maxVValue
910 virtualX
911 virtualY
912 displayWidth
913 frameX0
914 frameY0
915 frameX1
916 frameY1
917 zoomLocked
918 modePool
919 modes
920 currentMode
921 progClock (TRUE if clock is programmable)
922 chipset
923 ramdac
924 clockchip
925 numClocks (if not programmable)
926 clock[] (if not programmable)
927 videoRam
928 biosBase
929 memBase
930 memClk
931 driverPrivate
932 chipID
933 chipRev
934 </verb></quote>
936 <quote><p>
937 &s.code;pointer xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name)&e.code:
939 &s.code;pointer xf86LoadDrvSubModule(DriverPtr drv, const char *name)&e.code:
940 <quote><p>
941 Load a module that a driver depends on. This function loads the
942 module &s.code;name&e.code; as a sub module of the driver. The
943 return value is a handle identifying the new module. If the load
944 fails, the return value will be &s.code;NULL&e.code;. If a driver
945 needs to explicitly unload a module it has loaded in this way,
946 the return value must be saved and passed to
947 &s.code;xf86UnloadSubModule()&e.code; when unloading.
949 </quote>
951 &s.code;void xf86UnloadSubModule(pointer module)&e.code;
952 <quote><p>
953 Unloads the module referenced by &s.code;module&e.code;.
954 &s.code;module&e.code; should be a pointer returned previously
955 by &s.code;xf86LoadSubModule()&e.code; or
956 &s.code;xf86LoadDrvSubModule()&e.code; .
958 </quote>
959 </quote>
961 <sect1>Cleaning up Unused Drivers
964 At this point it is known which screens will be in use, and which
965 drivers are being used. Unreferenced drivers (and modules they
966 may have loaded) are unloaded here.
969 <sect1>Consistency Checks
972 The parameters that must be global to the server, like pixmap formats,
973 bitmap bit order, bitmap scanline unit and image byte order are
974 compared for each of the screens. If a mismatch is found, the server
975 exits with an appropriate message.
978 <sect1>Check if Resource Control is Needed
981 Determine if resource access control is needed. This is the case
982 if more than one screen is used. If necessary the RAC wrapper module
983 is loaded.
985 <sect1>AddScreen (ScreenInit)
988 At this point, the valid screens are known.
989 &s.code;AddScreen()&e.code; is called for each of them, passing
990 &s.code;ChipScreenInit()&e.code; as the argument.
991 &s.code;AddScreen()&e.code; is a DIX function that allocates a new
992 &s.code;screenInfo.screen[]&e.code; entry (aka
993 &s.code;pScreen&e.code;), and does some basic initialisation of it.
994 It then calls the &s.code;ChipScreenInit()&e.code; function, with
995 &s.code;pScreen&e.code; as one of its arguments. If
996 &s.code;ChipScreenInit()&e.code; returns &s.code;FALSE&e.code;,
997 &s.code;AddScreen()&e.code; returns &s.code;-1&e.code;. Otherwise
998 it returns the index of the screen. &s.code;AddScreen()&e.code;
999 should only fail because of programming errors or failure to allocate
1000 resources (like memory). All configuration problems should be
1001 detected BEFORE this point.
1003 <quote><p>
1004 &s.code;Bool ChipScreenInit(int index, ScreenPtr pScreen,
1005 &f.indent;int argc, char **argv)&e.code;
1006 <quote><p>
1007 This is called at the start of each server generation.
1009 Fill in all of &s.code;pScreen&e.code;, possibly doing some of
1010 this by calling ScreenInit functions from other layers like mi,
1011 framebuffers (cfb, etc), and extensions.
1013 Decide which operations need to be placed under resource access
1014 control. The classes of operations are the frame buffer operations
1015 (&s.code;RAC_FB&e.code;), the pointer operations
1016 (&s.code;RAC_CURSOR&e.code;), the viewport change operations
1017 (&s.code;RAC_VIEWPORT&e.code;) and the colormap operations
1018 (&s.code;RAC_COLORMAP&e.code;). Any operation that requires
1019 resources which might be disabled during OPERATING state should
1020 be set to use RAC. This can be specified separately for memory
1021 and IO resources (the &s.code;racMemFlags&e.code; and
1022 &s.code;racIoFlags&e.code; fields of the &s.code;ScrnInfoRec&e.code;
1023 respectively).
1025 Map any video memory or other memory regions.
1027 Save the video card state. Enough state must be saved so that
1028 the original state can later be restored.
1030 Initialise the initial video mode. The &s.code;ScrnInfoRec&e.code;'s
1031 &s.code;vtSema&e.code; field should be set to &s.code;TRUE&e.code;
1032 just prior to changing the video hardware's state.
1034 </quote>
1035 </quote>
1038 The &s.code;ChipScreenInit()&e.code; function (or functions from other
1039 layers that it calls) should allocate entries in the
1040 &s.code;ScreenRec&e.code;'s &s.code;devPrivates&e.code; area by
1041 calling &s.code;AllocateScreenPrivateIndex()&e.code; if it needs
1042 per-generation storage. Since the &s.code;ScreenRec&e.code;'s
1043 &s.code;devPrivates&e.code; information is cleared for each server
1044 generation, this is the correct place to initialise it.
1046 After &s.code;AddScreen()&e.code; has successfully returned, the
1047 following &s.code;ScrnInfoRec&e.code; fields are initialised:
1049 <quote><verb>
1050 pScreen
1051 racMemFlags
1052 racIoFlags
1053 </verb></quote>
1055 The &s.code;ChipScreenInit()&e.code; function should initialise the
1056 &s.code;CloseScreen&e.code; and &s.code;SaveScreen&e.code; fields
1057 of &s.code;pScreen&e.code;. The old value of
1058 &s.code;pScreen-&gt;CloseScreen&e.code; should be saved as part of
1059 the driver's per-screen private data, allowing it to be called from
1060 &s.code;ChipCloseScreen()&e.code;. This means that the existing
1061 &s.code;CloseScreen()&e.code; function is wrapped.
1063 <sect1>Finalising RAC Initialisation
1066 After all the &s.code;ChipScreenInit()&e.code; functions have been
1067 called, each screen has registered its RAC requirements. This
1068 information is used to determine which shared resources are requested
1069 by more than one driver and set the access functions accordingly.
1070 This is done following these rules:
1072 <enum>
1073 <item>The sharable resources registered by each entity are compared.
1074 If a resource is registered by more than one entity the entity
1075 will be marked to indicate that it needs to share this resources
1076 type (IO or MEM).
1078 <item>A resource marked ``disabled'' during OPERATING state will be
1079 ignored entirely.
1081 <item>A resource marked ``unused'' will only conflict with an overlapping
1082 resource of an other entity if the second is actually in use
1083 during OPERATING state.
1085 <item>If an ``unused'' resource was found to conflict but the entity
1086 does not use any other resource of this type the entire resource
1087 type will be disabled for that entity.
1088 </enum>
1091 <sect1>Finishing InitOutput()
1094 At this point &s.code;InitOutput()&e.code; is finished, and all the
1095 screens have been setup in their initial video mode.
1098 <sect1>Mode Switching
1101 When a SwitchMode event is received, &s.code;ChipSwitchMode()&e.code;
1102 is called (when it exists):
1104 <quote><p>
1105 &s.code;Bool ChipSwitchMode(int index, DisplayModePtr mode, int flags)&e.code;
1106 <quote><p>
1107 Initialises the new mode for the screen identified by
1108 &s.code;index;&e.code;. The viewport may need to be adjusted
1109 also.
1111 </quote>
1112 </quote>
1115 <sect1>Changing Viewport
1118 When a Change Viewport event is received,
1119 &s.code;ChipAdjustFrame()&e.code; is called (when it exists):
1121 <quote><p>
1122 &s.code;void ChipAdjustFrame(int index, int x, int y, int flags)&e.code;
1123 <quote><p>
1124 Changes the viewport for the screen identified by
1125 &s.code;index;&e.code;.
1127 It should be noted that many chipsets impose restrictions on where the
1128 viewport may be placed in the virtual resolution, either for alignment
1129 reasons, or to prevent the start of the viewport from being positioned
1130 within a pixel (as can happen in a 24bpp mode). After calculating the
1131 value the chipset's panning registers need to be set to for non-DGA
1132 modes, this function should recalculate the ScrnInfoRec's
1133 &s.code;frameX0&e.code;, &s.code;frameY0&e.code, &s.code;frameX1&e.code;
1134 and &s.code;frameY1&e.code; fields to correspond to that value. If
1135 this is not done, switching to another mode might cause the position
1136 of a hardware cursor to change.
1138 </quote>
1139 </quote>
1142 <sect1>VT Switching
1145 When a VT switch event is received, &s.code;xf86VTSwitch()&e.code;
1146 is called. &s.code;xf86VTSwitch()&e.code; does the following:
1148 <descrip>
1149 <tag>On ENTER:</tag>
1150 <itemize>
1151 <item>enable port I/O access
1153 <item>save and initialise the bus/resource state
1155 <item>enter the SETUP server state
1157 <item>calls &s.code;ChipEnterVT()&e.code; for each screen
1159 <item>enter the OPERATING server state
1161 <item>validate GCs
1163 <item>Restore fb from saved pixmap for each screen
1165 <item>Enable all input devices
1166 </itemize>
1167 <tag>On LEAVE:</tag>
1168 <itemize>
1169 <item>Save fb to pixmap for each screen
1171 <item>validate GCs
1173 <item>enter the SETUP server state
1175 <item>calls &s.code;ChipLeaveVT()&e.code; for each screen
1177 <item>disable all input devices
1179 <item>restore bus/resource state
1181 <item>disables port I/O access
1182 </itemize>
1183 </descrip>
1185 <quote><p>
1186 &s.code;Bool ChipEnterVT(int index, int flags)&e.code;
1187 <quote><p>
1188 This function should initialise the current video mode and
1189 initialise the viewport, turn on the HW cursor if appropriate,
1190 etc.
1192 Should it re-save the video state before initialising the video
1193 mode?
1195 </quote>
1197 &s.code;void ChipLeaveVT(int index, int flags)&e.code;
1198 <quote><p>
1199 This function should restore the saved video state. If
1200 appropriate it should also turn off the HW cursor, and invalidate
1201 any pixmap/font caches.
1203 </quote>
1205 Optionally, &s.code;ChipLeaveVT()&e.code; may also unmap memory
1206 regions. If so, &s.code;ChipEnterVT()&e.code; will need to remap
1207 them. Additionally, if an aperture used to access video memory is
1208 unmapped and remapped in this fashion, &s.code;ChipEnterVT()&e.code;
1209 will also need to notify the framebuffer layers of the aperture's new
1210 location in virtual memory. This is done with a call to the screen's
1211 &s.code;ModifyPixmapHeader()&e.code; function, as follows
1213 <quote><p>
1214 &s.code;(*pScreen->ModifyPixmapHeader)(pScrn->ppix,
1215 &f.indent;-1, -1, -1, -1, -1, <it>NewApertureAddress</it>);&e.code;
1216 <quote><p>
1217 where the &s.code``ppix''&e.code; field in a ScrnInfoRec
1218 points to the pixmap used by the screen's
1219 &s.code;SaveRestoreImage()&e.code; function to hold the screen's
1220 contents while switched out.
1222 </quote>
1223 </quote>
1225 Currently, aperture remapping, as described here, should not be
1226 attempted if the driver uses the &s.code;xf8_16bpp&e.code; or
1227 &s.code;xf8_32bpp&e.code; framebuffer layers. A pending
1228 restructuring of VT switching will address this restriction in
1229 the near future.
1231 </quote>
1233 Other layers may wrap the &s.code;ChipEnterVT()&e.code; and
1234 &s.code;ChipLeaveVT()&e.code; functions if they need to take some
1235 action when these events are received.
1237 <sect1>End of server generation
1240 At the end of each server generation, the DIX layer calls
1241 &s.code;ChipCloseScreen()&e.code; for each screen:
1243 <quote><p>
1244 &s.code;Bool ChipCloseScreen(int index, ScreenPtr pScreen)&e.code;
1245 <quote><p>
1246 This function should restore the saved video state and unmap the
1247 memory regions.
1249 It should also free per-screen data structures allocated by the
1250 driver. Note that the persistent data held in the
1251 &s.code;ScrnInfoRec&e.code;'s &s.code;driverPrivate&e.code; field
1252 should not be freed here because it is needed by subsequent server
1253 generations.
1255 The &s.code;ScrnInfoRec&e.code;'s &s.code;vtSema&e.code; field
1256 should be set to &s.code;FALSE&e.code; once the video HW state
1257 has been restored.
1259 Before freeing the per-screen driver data the saved
1260 &s.code;CloseScreen&e.code; value should be restored to
1261 &s.code;pScreen-&gt;CloseScreen&e.code;, and that function should
1262 be called after freeing the data.
1264 </quote>
1265 </quote>
1267 <sect>Optional Driver Functions
1270 The functions outlined here can be called from the XFree86 common layer,
1271 but their presence is optional.
1273 <sect1>Mode Validation
1276 When a mode validation helper supplied by the XFree86-common layer is
1277 being used, it can be useful to provide a function to check for hw
1278 specific mode constraints:
1280 <quote><p>
1281 &s.code;ModeStatus ChipValidMode(int index, DisplayModePtr mode,
1282 &f.indent;Bool verbose, int flags)&e.code;
1283 <quote><p>
1284 Check the passed mode for hw-specific constraints, and return the
1285 appropriate status value.
1287 </quote>
1288 </quote>
1291 This function may also modify the effective timings and clock of the passed
1292 mode. These have been stored in the mode's &s.code;Crtc*&e.code; and
1293 &s.code;SynthClock&e.code; elements, and have already been adjusted for
1294 interlacing, doublescanning, multiscanning and clock multipliers and dividers.
1295 The function should not modify any other mode field, unless it wants to modify
1296 the mode timings reported to the user by &s.code;xf86PrintModes()&e.code;.
1299 The function is called once for every mode in the xorg.conf Monitor section
1300 assigned to the screen, with &s.code;flags&e.code; set to
1301 &s.code;MODECHECK_INITIAL&e.code;. It is subsequently called for every mode
1302 in the xorg.conf Display subsection assigned to the screen, with
1303 &s.code;flags&e.code; set to &s.code;MODECHECK_FINAL&e.code;. In the second
1304 case, the mode will have successfully passed all other tests. In addition,
1305 the &s.code;ScrnInfoRec&e.code;'s &s.code;virtualX&e.code;,
1306 &s.code;virtualY&e.code; and &s.code;displayWidth&e.code; fields will have been
1307 set as if the mode to be validated were to be the last mode accepted.
1310 In effect, calls with MODECHECK_INITIAL are intended for checks that do not
1311 depend on any mode other than the one being validated, while calls with
1312 MODECHECK_FINAL are intended for checks that may involve more than one mode.
1314 <sect1>Free screen data
1317 When a screen is deleted prior to the completion of the ScreenInit
1318 phase the &s.code;ChipFreeScreen()&e.code; function is called when defined.
1320 <quote><p>
1321 &s.code;void ChipFreeScreen(int scrnindex, int flags)&e.code;
1322 <quote><p>
1323 Free any driver-allocated data that may have been allocated up to
1324 and including an unsuccessful &s.code;ChipScreenInit()&e.code;
1325 call. This would predominantly be data allocated by
1326 &s.code;ChipPreInit()&e.code; that persists across server
1327 generations. It would include the &s.code;driverPrivate&e.code;,
1328 and any ``privates'' entries that modules may have allocated.
1330 </quote>
1331 </quote>
1334 <sect>Recommended driver functions
1337 The functions outlined here are for internal use by the driver only.
1338 They are entirely optional, and are never accessed directly from higher
1339 layers. The sample function declarations shown here are just examples.
1340 The interface (if any) used is up to the driver.
1342 <sect1>Save
1345 Save the video state. This could be called from &s.code;ChipScreenInit()&e.code; and
1346 (possibly) &s.code;ChipEnterVT()&e.code;.
1348 <quote><p>
1349 &s.code;void ChipSave(ScrnInfoPtr pScrn)&e.code;
1350 <quote><p>
1351 Saves the current state. This will only be saving pre-server
1352 states or states before returning to the server. There is only
1353 one current saved state per screen and it is stored in private
1354 storage in the screen.
1356 </quote>
1357 </quote>
1359 <sect1>Restore
1362 Restore the original video state. This could be called from the
1363 &s.code;ChipLeaveVT()&e.code; and &s.code;ChipCloseScreen()&e.code;
1364 functions.
1366 <quote><p>
1367 &s.code;void ChipRestore(ScrnInfoPtr pScrn)&e.code;
1368 <quote><p>
1369 Restores the saved state from the private storage. Usually only
1370 used for restoring text modes.
1372 </quote>
1373 </quote>
1376 <sect1>Initialise Mode
1379 Initialise a video mode. This could be called from the
1380 &s.code;ChipScreenInit()&e.code;, &s.code;ChipSwitchMode()&e.code;
1381 and &s.code;ChipEnterVT()&e.code; functions.
1383 <quote><p>
1384 &s.code;Bool ChipModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)&e.code;
1385 <quote><p>
1386 Programs the hardware for the given video mode.
1388 </quote>
1389 </quote>
1392 <sect>Data and Data Structures
1395 <sect1>Command line data
1398 Command line options are typically global, and are stored in global
1399 variables. These variables are read-only and are available to drivers
1400 via a function call interface. Most of these command line values are
1401 processed via helper functions to ensure that they are treated consistently
1402 by all drivers. The other means of access is provided for cases where
1403 the supplied helper functions might not be appropriate.
1405 Some of them are:
1407 <quote><verb>
1408 xf86Verbose verbosity level
1409 xf86Bpp -bpp from the command line
1410 xf86Depth -depth from the command line
1411 xf86Weight -weight from the command line
1412 xf86Gamma -{r,g,b,}gamma from the command line
1413 xf86FlipPixels -flippixels from the command line
1414 xf86ProbeOnly -probeonly from the command line
1415 defaultColorVisualClass -cc from the command line
1416 </verb></quote>
1418 If we ever do allow for screen-specific command line options, we may
1419 need to rethink this.
1421 These can be accessed in a read-only manner by drivers with the following
1422 functions:
1424 <quote><p>
1425 &s.code;int xf86GetVerbosity()&e.code;
1426 <quote><p>
1427 Returns the value of &s.code;xf86Verbose&e.code;.
1429 </quote>
1431 &s.code;int xf86GetDepth()&e.code;
1432 <quote><p>
1433 Returns the &s.cmd;-depth&e.cmd; command line setting. If not
1434 set on the command line, &s.code;-1&e.code; is returned.
1436 </quote>
1438 &s.code;rgb xf86GetWeight()&e.code;
1439 <quote><p>
1440 Returns the &s.cmd;-weight&e.cmd; command line setting. If not
1441 set on the command line, &s.code;{0, 0, 0}&e.code; is returned.
1443 </quote>
1445 &s.code;Gamma xf86GetGamma()&e.code;
1446 <quote><p>
1447 Returns the &s.cmd;-gamma&e.cmd; or &s.cmd;-rgamma&e.cmd;,
1448 &s.cmd;-ggamma&e.cmd;, &s.cmd;-bgamma&e.cmd; command line settings.
1449 If not set on the command line, &s.code;{0.0, 0.0, 0.0}&e.code;
1450 is returned.
1452 </quote>
1454 &s.code;Bool xf86GetFlipPixels()&e.code;
1455 <quote><p>
1456 Returns &s.code;TRUE&e.code; if &s.cmd;-flippixels&e.cmd; is
1457 present on the command line, and &s.code;FALSE&e.code; otherwise.
1459 </quote>
1461 &s.code;const char *xf86GetServerName()&e.code;
1462 <quote><p>
1463 Returns the name of the X server from the command line.
1465 </quote>
1466 </quote>
1468 <sect1>Data handling
1471 Config file data contains parts that are global, and parts that are
1472 Screen specific. All of it is parsed into data structures that neither
1473 the drivers or most other parts of the server need to know about.
1475 The global data is typically not required by drivers, and as such, most
1476 of it is stored in the private &s.code;xf86InfoRec&e.code;.
1478 The screen-specific data collected from the config file is stored in
1479 screen, device, display, monitor-specific data structures that are separate
1480 from the &s.code;ScrnInfoRecs&e.code;, with the appropriate elements/fields
1481 hooked into the &s.code;ScrnInfoRecs&e.code; as required. The screen
1482 config data is held in &s.code;confScreenRec&e.code;, device data in
1483 the &s.code;GDevRec&e.code;, monitor data in the &s.code;MonRec&e.code;,
1484 and display data in the &s.code;DispRec&e.code;.
1486 The XFree86 common layer's screen specific data (the actual data in use
1487 for each screen) is held in the &s.code;ScrnInfoRecs&e.code;. As has
1488 been outlined above, the &s.code;ScrnInfoRecs&e.code; are allocated at probe
1489 time, and it is the responsibility of the Drivers' &s.code;Probe()&e.code;
1490 and &s.code;PreInit()&e.code; functions to finish filling them in based
1491 on both data provided on the command line and data provided from the
1492 Config file. The precedence for this is:
1494 <quote>
1495 command line -&gt; config file -&gt; probed/default data
1496 </quote>
1498 For most things in this category there are helper functions that the
1499 drivers can use to ensure that the above precedence is consistently
1500 used.
1502 As well as containing screen-specific data that the XFree86 common layer
1503 (including essential parts of the server infrastructure as well as helper
1504 functions) needs to access, it also contains some data that drivers use
1505 internally. When considering whether to add a new field to the
1506 &s.code;ScrnInfoRec&e.code;, consider the balance between the convenience
1507 of things that lots of drivers need and the size/obscurity of the
1508 &s.code;ScrnInfoRec&e.code;.
1510 Per-screen driver specific data that cannot be accommodated with the
1511 static &s.code;ScrnInfoRec&e.code; fields is held in a driver-defined
1512 data structure, a pointer to which is assigned to the
1513 &s.code;ScrnInfoRec&e.code;'s &s.code;driverPrivate&e.code; field. This
1514 is per-screen data that persists across server generations (as does the
1515 bulk of the static &s.code;ScrnInfoRec&e.code; data). It would typically
1516 also include the video card's saved state.
1518 Per-screen data for other modules that the driver uses (for example,
1519 the XAA module) that is reset for each server generation is hooked into
1520 the &s.code;ScrnInfoRec&e.code; through it's &s.code;privates&e.code;
1521 field.
1523 Once it has stabilised, the data structures and variables accessible to
1524 video drivers will be documented here. In the meantime, those things
1525 defined in the &s.code;xf86.h&e.code; and &s.code;xf86str.h&e.code;
1526 files are visible to video drivers. Things defined in
1527 &s.code;xf86Priv.h&e.code; and &s.code;xf86Privstr.h&e.code; are NOT
1528 intended to be visible to video drivers, and it is an error for a driver
1529 to include those files.
1532 <sect1>Accessing global data
1535 Some other global state information that the drivers may access via
1536 functions is as follows:
1538 <quote><p>
1539 &s.code;Bool xf86ServerIsExiting()&e.code;
1540 <quote><p>
1541 Returns &s.code;TRUE&e.code; if the server is at the end of a
1542 generation and is in the process of exiting, and
1543 &s.code;FALSE&e.code; otherwise.
1545 </quote>
1547 &s.code;Bool xf86ServerIsResetting()&e.code;
1548 <quote><p>
1549 Returns &s.code;TRUE&e.code; if the server is at the end of a
1550 generation and is in the process of resetting, and
1551 &s.code;FALSE&e.code; otherwise.
1553 </quote>
1555 &s.code;Bool xf86ServerIsInitialising()&e.code;
1556 <quote><p>
1557 Returns &s.code;TRUE&e.code; if the server is at the beginning of
1558 a generation and is in the process of initialising, and
1559 &s.code;FALSE&e.code; otherwise.
1561 </quote>
1563 &s.code;Bool xf86ServerIsOnlyProbing()&e.code;
1564 <quote><p>
1565 Returns &s.code;TRUE&e.code; if the -probeonly command line flag
1566 was specified, and &s.code;FALSE&e.code; otherwise.
1568 </quote>
1570 &s.code;Bool xf86CaughtSignal()&e.code;
1571 <quote><p>
1572 Returns &s.code;TRUE&e.code; if the server has caught a signal,
1573 and &s.code;FALSE&e.code; otherwise.
1575 </quote>
1576 </quote>
1578 <sect1>Allocating private data
1581 A driver and any module it uses may allocate per-screen private storage
1582 in either the &s.code;ScreenRec&e.code; (DIX level) or
1583 &s.code;ScrnInfoRec&e.code; (XFree86 common layer level).
1584 &s.code;ScreenRec&e.code; storage persists only for a single server
1585 generation, and &s.code;ScrnInfoRec&e.code; storage persists across
1586 generations for the lifetime of the server.
1588 The &s.code;ScreenRec&e.code; &s.code;devPrivates&e.code; data must be
1589 reallocated/initialised at the start of each new generation. This is
1590 normally done from the &s.code;ChipScreenInit()&e.code; function, and
1591 Init functions for other modules that it calls. Data allocated in this
1592 way should be freed by the driver's &s.code;ChipCloseScreen()&e.code;
1593 functions, and Close functions for other modules that it calls. A new
1594 &s.code;devPrivates&e.code; entry is allocated by calling the
1595 &s.code;AllocateScreenPrivateIndex()&e.code; function.
1597 <quote><p>
1598 &s.code;int AllocateScreenPrivateIndex()&e.code;
1599 <quote><p>
1600 This function allocates a new element in the
1601 &s.code;devPrivates&e.code; field of all currently existing
1602 &s.code;ScreenRecs&e.code;. The return value is the index of this
1603 new element in the &s.code;devPrivates&e.code; array. The
1604 &s.code;devPrivates&e.code; field is of type
1605 &s.code;DevUnion&e.code;:
1607 <verb>
1608 typedef union _DevUnion {
1609 pointer ptr;
1610 long val;
1611 unsigned long uval;
1612 pointer (*fptr)(void);
1613 } DevUnion;
1614 </verb>
1616 which allows the element to be used for any of the above types.
1617 It is commonly used as a pointer to data that the caller allocates
1618 after the new index has been allocated.
1620 This function will return &s.code;-1&e.code; when there is an
1621 error allocating the new index.
1623 </quote>
1624 </quote>
1626 The &s.code;ScrnInfoRec&e.code; &s.code;privates&e.code; data persists
1627 for the life of the server, so only needs to be allocated once. This
1628 should be done from the &s.code;ChipPreInit()&e.code; function, and Init
1629 functions for other modules that it calls. Data allocated in this way
1630 should be freed by the driver's &s.code;ChipFreeScreen()&e.code; functions,
1631 and Free functions for other modules that it calls. A new
1632 &s.code;privates&e.code; entry is allocated by calling the
1633 &s.code;xf86AllocateScrnInfoPrivateIndex()&e.code; function.
1636 <quote><p>
1637 &s.code;int xf86AllocateScrnInfoPrivateIndex()&e.code;
1638 <quote><p>
1639 This function allocates a new element in the &s.code;privates&e.code;
1640 field of all currently existing &s.code;ScrnInfoRecs&e.code;.
1641 The return value is the index of this new element in the
1642 &s.code;privates&e.code; array. The &s.code;privates&e.code;
1643 field is of type &s.code;DevUnion&e.code;:
1645 <verb>
1646 typedef union _DevUnion {
1647 pointer ptr;
1648 long val;
1649 unsigned long uval;
1650 pointer (*fptr)(void);
1651 } DevUnion;
1652 </verb>
1654 which allows the element to be used for any of the above types.
1655 It is commonly used as a pointer to data that the caller allocates
1656 after the new index has been allocated.
1658 This function will not return when there is an error allocating
1659 the new index. When there is an error it will cause the server
1660 to exit with a fatal error. The similar function for allocation
1661 privates in the &s.code;ScreenRec&e.code;
1662 (&s.code;AllocateScreenPrivateIndex()&e.code;) differs in this
1663 respect by returning &s.code;-1&e.code; when the allocation fails.
1665 </quote>
1666 </quote>
1668 <sect>Keeping Track of Bus Resources<label id="rac">
1671 <sect1>Theory of Operation
1674 The XFree86 common layer has knowledge of generic access control mechanisms
1675 for devices on certain bus systems (currently the PCI bus) as well as
1676 of methods to enable or disable access to the buses itself. Furthermore
1677 it can access information on resources decoded by these devices and if
1678 necessary modify it.
1680 When first starting the Xserver collects all this information, saves it
1681 for restoration, checks it for consistency, and if necessary, corrects
1682 it. Finally it disables all resources on a generic level prior to
1683 calling any driver function.
1685 When the &s.code;Probe()&e.code; function of each driver is called the
1686 device sections are matched against the devices found in the system.
1687 The driver may probe devices at this stage that cannot be identified by
1688 using device independent methods. Access to all resources that can be
1689 controlled in a device independent way is disabled. The
1690 &s.code;Probe()&e.code; function should register all non-relocatable
1691 resources at this stage. If a resource conflict is found between
1692 exclusive resources the driver will fail immediately. Optionally the
1693 driver might specify an &s.code;EntityInit()&e.code;,
1694 &s.code;EntityLeave()&e.code; and &s.code;EntityEnter()&e.code; function.
1696 &s.code;EntityInit()&e.code; can be used to disable any shared resources
1697 that are not controlled by the generic access control functions. It is
1698 called prior to the PreInit phase regardless if an entity is active or
1699 not. When calling the &s.code;EntityInit()&e.code;,
1700 &s.code;EntityEnter()&e.code; and &s.code;EntityLeave()&e.code; functions
1701 the common level will disable access to all other entities on a generic
1702 level. Since the common level has no knowledge of device specific
1703 methods to disable access to resources it cannot be guaranteed that
1704 certain resources are not decoded by any other entity until the
1705 &s.code;EntityInit()&e.code; or &s.code;EntityEnter()&e.code; phase is
1706 finished. Device drivers should therefore register all those resources
1707 which they are going to disable. If these resources are never to be
1708 used by any driver function they may be flagged &s.code;ResInit&e.code;
1709 so that they can be removed from the resource list after processing all
1710 &s.code;EntityInit()&e.code; functions. &s.code;EntityEnter()&e.code;
1711 should disable decoding of all resources which are not registered as
1712 exclusive and which are not handled by the generic access control in
1713 the common level. The difference to &s.code;EntityInit()&e.code; is
1714 that the latter one is only called once during lifetime of the server.
1715 It can therefore be used to set up variables prior to disabling resources.
1716 &s.code;EntityLeave()&e.code; should restore the original state when
1717 exiting the server or switching to a different VT. It also needs to
1718 disable device specific access functions if they need to be disabled on
1719 server exit or VT switch. The default state is to enable them before
1720 giving up the VT.
1722 In &s.code;PreInit()&e.code; phase each driver should check if any
1723 sharable resources it has registered during &s.code;Probe()&e.code; has
1724 been denied and take appropriate action which could simply be to fail.
1725 If it needs to access resources it has disabled during
1726 &s.code;EntitySetup()&e.code; it can do so provided it has registered
1727 these and will disable them before returning from
1728 &s.code;PreInit()&e.code;. This also applies to all other driver
1729 functions. Several functions are provided to request resource ranges,
1730 register these, correct PCI config space and add replacements for the
1731 generic access functions. Resources may be marked ``disabled'' or
1732 ``unused'' during OPERATING stage. Although these steps could also be
1733 performed in &s.code;ScreenInit()&e.code;, this is not desirable.
1735 Following &s.code;PreInit()&e.code; phase the common level determines
1736 if resource access control is needed. This is the case if more than
1737 one screen is used. If necessary the RAC wrapper module is loaded. In
1738 &s.code;ScreenInit()&e.code; the drivers can decide which operations
1739 need to be placed under RAC. Available are the frame buffer operations,
1740 the pointer operations and the colormap operations. Any operation that
1741 requires resources which might be disabled during OPERATING state should
1742 be set to use RAC. This can be specified separately for memory and IO
1743 resources.
1745 When &s.code;ScreenInit()&e.code; phase is done the common level will
1746 determine which shared resources are requested by more than one driver
1747 and set the access functions accordingly. This is done following these
1748 rules:
1750 <enum>
1751 <item>The sharable resources registered by each entity are compared. If
1752 a resource is registered by more than one entity the entity will be
1753 marked to need to share this resources type (&s.code;IO&e.code; or
1754 &s.code;MEM&e.code;).
1756 <item>A resource marked ``disabled'' during OPERATING state will be ignored
1757 entirely.
1759 <item>A resource marked ``unused'' will only conflicts with an overlapping
1760 resource of an other entity if the second is actually in use during
1761 OPERATING state.
1763 <item>If an ``unused'' resource was found to conflict however the entity
1764 does not use any other resource of this type the entire resource type
1765 will be disabled for that entity.
1766 </enum>
1768 The driver has the choice among different ways to control access to
1769 certain resources:
1771 <enum>
1772 <item>It can rely on the generic access functions. This is probably the
1773 most common case. Here the driver only needs to register any resource
1774 it is going to use.
1776 <item>It can replace the generic access functions by driver specific
1777 ones. This will mostly be used in cases where no generic access
1778 functions are available. In this case the driver has to make sure
1779 these resources are disabled when entering the &s.code;PreInit()&e.code;
1780 stage. Since the replacement functions are registered in
1781 &s.code;PreInit()&e.code; the driver will have to enable these
1782 resources itself if it needs to access them during this state. The
1783 driver can specify if the replacement functions can control memory
1784 and/or I/O resources separately.
1786 <item>The driver can enable resources itself when it needs them. Each
1787 driver function enabling them needs to disable them before it will
1788 return. This should be used if a resource which can be controlled
1789 in a device dependent way is only required during SETUP state. This
1790 way it can be marked ``unused'' during OPERATING state.
1791 </enum>
1793 A resource which is decoded during OPERATING state however never accessed
1794 by the driver should be marked unused.
1796 Since access switching latencies are an issue during Xserver operation,
1797 the common level attempts to minimize the number of entities that need
1798 to be placed under RAC control. When a wrapped operation is called,
1799 the &s.code;EnableAccess()&e.code; function is called before control is
1800 passed on. &s.code;EnableAccess()&e.code; checks if a screen is under
1801 access control. If not it just establishes bus routing and returns.
1802 If the screen needs to be under access control,
1803 &s.code;EnableAccess()&e.code; determines which resource types
1804 (&s.code;MEM&e.code;, &s.code;IO&e.code;) are required. Then it tests
1805 if this access is already established. If so it simply returns. If
1806 not it disables the currently established access, fixes bus routing and
1807 enables access to all entities registered for this screen.
1809 Whenever a mode switch or a VT-switch is performed the common level will
1810 return to SETUP state.
1812 <sect1>Resource Types
1815 Resource have certain properties. When registering resources each range
1816 is accompanied by a flag consisting of the ORed flags of the different
1817 properties the resource has. Each resource range may be classified
1818 according to
1820 <itemize>
1821 <item>its physical properties i.e., if it addresses
1822 memory (&s.code;ResMem&e.code;) or
1823 I/O space (&s.code;ResIo&e.code;),
1824 <item>if it addresses a
1825 block (&s.code;ResBlock&e.code;) or
1826 sparse (&s.code;ResSparse&e.code;)
1827 range,
1828 <item>its access properties.
1829 </itemize>
1831 There are two known access properties:
1833 <itemize>
1834 <item>&s.code;ResExclusive&e.code;
1835 for resources which may not be shared with any other device and
1836 <item>&s.code;ResShared&e.code;
1837 for resources which can be disabled and therefore can be shared.
1838 </itemize>
1840 If it is necessary to test a resource against any type a generic access
1841 type &s.code;ResAny&e.code; is provided. If this is set the resource
1842 will conflict with any resource of a different entity intersecting its
1843 range. Further it can be specified that a resource is decoded however
1844 never used during any stage (&s.code;ResUnused&e.code;) or during
1845 OPERATING state (&s.code;ResUnusedOpr&e.code;). A resource only visible
1846 during the init functions (ie. &s.code;EntityInit()&e.code;,
1847 &s.code;EntityEnter()&e.code; and &s.code;EntityLeave()&e.code; should
1848 be registered with the flag &s.code;ResInit&e.code;. A resource that
1849 might conflict with background resource ranges may be flagged with
1850 &s.code;ResBios&e.code;. This might be useful when registering resources
1851 ranges that were assigned by the system Bios.
1853 Several predefined resource lists are available for VGA and 8514/A
1854 resources in &s.code;common/xf86Resources.h&e.code;.
1856 <sect1>Available Functions<label id="avail">
1859 The functions provided for resource management are listed in their order
1860 of use in the driver.
1863 <sect2>Probe Phase
1866 In this phase each driver detects those resources it is able to drive,
1867 creates an entity record for each of them, registers non-relocatable
1868 resources and allocates screens and adds the resources to screens.
1870 Two helper functions are provided for matching device sections in the
1871 xorg.conf file to the devices:
1873 <quote><p>
1874 &s.code;int xf86MatchPciInstances(const char *driverName, int vendorID,
1875 &f.indent;SymTabPtr chipsets, PciChipsets *PCIchipsets,
1876 &f.indent;GDevPtr *devList, int numDevs, DriverPtr drvp,
1877 &f.indent;int **foundEntities)&e.code;
1878 <quote><p>
1879 This function finds matches between PCI cards that a driver supports
1880 and config file device sections. It is intended for use in the
1881 &s.code;ChipProbe()&e.code; function of drivers for PCI cards.
1882 Only probed PCI devices with a vendor ID matching
1883 &s.code;vendorID&e.code; are considered. &s.code;devList&e.code;
1884 and &s.code;numDevs&e.code; are typically those found from
1885 calling &s.code;xf86MatchDevice()&e.code;, and represent the active
1886 config file device sections relevant to the driver.
1887 &s.code;PCIchipsets&e.code; is a table that provides a mapping
1888 between the PCI device IDs, the driver's internal chipset tokens
1889 and a list of fixed resources.
1891 When a device section doesn't have a &s.key;BusID&e.key; entry it
1892 can only match the primary video device. Secondary devices are
1893 only matched with device sections that have a matching
1894 &s.key;BusID&e.key; entry.
1896 Once the preliminary matches have been found, a final match is
1897 confirmed by checking if the chipset override, ChipID override or
1898 probed PCI chipset type match one of those given in the
1899 &s.code;chipsets&e.code; and &s.code;PCIchipsets&e.code; lists.
1900 The &s.code;PCIchipsets&e.code; list includes a list of the PCI
1901 device IDs supported by the driver. The list should be terminated
1902 with an entry with PCI ID &s.code;-1&e.code;". The
1903 &s.code;chipsets&e.code; list is a table mapping the driver's
1904 internal chipset tokens to names, and should be terminated with
1905 a &s.code;NULL&e.code; entry. Only those entries with a
1906 corresponding entry in the &s.code;PCIchipsets&e.code; list are
1907 considered. The order of precedence is: config file chipset,
1908 config file ChipID, probed PCI device ID.
1910 In cases where a driver handles PCI chipsets with more than one
1911 vendor ID, it may set &s.code;vendorID&e.code; to
1912 &s.code;0&e.code;, and OR each devID in the list with (the
1913 vendor&nbsp;ID&nbsp;&lt;&lt;&nbsp;16).
1915 Entity index numbers for confirmed matches are returned as an
1916 array via &s.code;foundEntities&e.code;. The PCI information,
1917 chipset token and device section for each match are found in the
1918 &s.code;EntityInfoRec&e.code; referenced by the indices.
1920 The function return value is the number of confirmed matches. A
1921 return value of &s.code;-1&e.code; indicates an internal error.
1922 The returned &s.code;foundEntities&e.code; array should be freed
1923 by the driver with &s.code;xfree()&e.code; when it is no longer
1924 needed in cases where the return value is greater than zero.
1926 </quote>
1928 &s.code;int xf86MatchIsaInstances(const char *driverName,
1929 &f.indent;SymTabPtr chipsets, IsaChipsets *ISAchipsets,
1930 &f.indent;DriverPtr drvp, FindIsaDevProc FindIsaDevice,
1931 &f.indent;GDevPtr *devList, int numDevs,
1932 int **foundEntities)&e.code;
1933 <quote><p>
1934 This function finds matches between ISA cards that a driver supports
1935 and config file device sections. It is intended for use in the
1936 &s.code;ChipProbe()&e.code; function of drivers for ISA cards.
1937 &s.code;devList&e.code; and &s.code;numDevs&e.code; are
1938 typically those found from calling &s.code;xf86MatchDevice()&e.code;,
1939 and represent the active config file device sections relevant to
1940 the driver. &s.code;ISAchipsets&e.code; is a table that provides
1941 a mapping between the driver's internal chipset tokens and the
1942 resource classes. &s.code;FindIsaDevice&e.code; is a
1943 driver-provided function that probes the hardware and returns the
1944 chipset token corresponding to what was detected, and
1945 &s.code;-1&e.code; if nothing was detected.
1947 If the config file device section contains a chipset entry, then
1948 it is checked against the &s.code;chipsets&e.code; list. When
1949 no chipset entry is present, the &s.code;FindIsaDevice&e.code;
1950 function is called instead.
1952 Entity index numbers for confirmed matches are returned as an
1953 array via &s.code;foundEntities&e.code;. The chipset token and
1954 device section for each match are found in the
1955 &s.code;EntityInfoRec&e.code; referenced by the indices.
1957 The function return value is the number of confirmed matches. A
1958 return value of &s.code;-1&e.code; indicates an internal error.
1959 The returned &s.code;foundEntities&e.code; array should be freed
1960 by the driver with &s.code;xfree()&e.code; when it is no longer
1961 needed in cases where the return value is greater than zero.
1963 </quote>
1964 </quote>
1966 These two helper functions make use of several core functions that are
1967 available at the driver level:
1969 <quote><p>
1970 &s.code;Bool xf86ParsePciBusString(const char *busID, int *bus,
1971 &f.indent;int *device, int *func)&e.code;
1972 <quote><p>
1973 Takes a &s.code;BusID&e.code; string, and if it is in the correct
1974 format, returns the PCI &s.code;bus&e.code;, &s.code;device&e.code;,
1975 &s.code;func&e.code; values that it indicates. The format of the
1976 string is expected to be "PCI:bus:device:func" where each of `bus',
1977 `device' and `func' are decimal integers. The ":func" part may
1978 be omitted, and the func value assumed to be zero, but this isn't
1979 encouraged. The "PCI" prefix may also be omitted. The prefix
1980 "AGP" is currently equivalent to the "PCI" prefix. If the string
1981 isn't a valid PCI BusID, the return value is &s.code;FALSE&e.code;.
1983 </quote>
1986 &s.code;Bool xf86ComparePciBusString(const char *busID, int bus,
1987 &f.indent;int device, int func)&e.code;
1988 <quote><p>
1989 Compares a &s.code;BusID&e.code; string with PCI &s.code;bus&e.code;,
1990 &s.code;device&e.code;, &s.code;func&e.code; values. If they
1991 match &s.code;TRUE&e.code; is returned, and &s.code;FALSE&e.code;
1992 if they don't.
1994 </quote>
1996 &s.code;Bool xf86ParseIsaBusString(const char *busID)&e.code;
1997 <quote><p>
1998 Compares a &s.code;BusID&e.code; string with the ISA bus ID string
1999 ("ISA" or "ISA:"). If they match &s.code;TRUE&e.code; is returned,
2000 and &s.code;FALSE&e.code; if they don't.
2002 </quote>
2004 &s.code;Bool xf86CheckPciSlot(int bus, int device, int func)&e.code;
2005 <quote><p>
2006 Checks if the PCI slot &s.code;bus:device:func&e.code; has been
2007 claimed. If so, it returns &s.code;FALSE&e.code;, and otherwise
2008 &s.code;TRUE&e.code;.
2010 </quote>
2012 &s.code;int xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp,
2013 &f.indent;int chipset, GDevPtr dev, Bool active)&e.code;
2014 <quote><p>
2015 This function is used to claim a PCI slot, allocate the associated
2016 entity record and initialise their data structures. The return
2017 value is the index of the newly allocated entity record, or
2018 &s.code;-1&e.code; if the claim fails. This function should always
2019 succeed if &s.code;xf86CheckPciSlot()&e.code; returned
2020 &s.code;TRUE&e.code; for the same PCI slot.
2022 </quote>
2024 &s.code;Bool xf86IsPrimaryPci(void)&e.code;
2025 <quote><p>
2026 This function returns &s.code;TRUE&e.code; if the primary card is
2027 a PCI device, and &s.code;FALSE&e.code; otherwise.
2029 </quote>
2031 &s.code;int xf86ClaimIsaSlot(DriverPtr drvp, int chipset,
2032 &f.indent;GDevPtr dev, Bool active)&e.code;
2033 <quote><p>
2034 This allocates an entity record entity and initialise the data
2035 structures. The return value is the index of the newly allocated
2036 entity record.
2038 </quote>
2040 &s.code;Bool xf86IsPrimaryIsa(void)&e.code;
2041 <quote><p>
2042 This function returns &s.code;TRUE&e.code; if the primary card is
2043 an ISA (non-PCI) device, and &s.code;FALSE&e.code; otherwise.
2045 </quote>
2046 </quote>
2048 Two helper functions are provided to aid configuring entities:
2049 <quote><p>
2050 &s.code;ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn,
2051 &f.indent;int scrnFlag, int entityIndex,
2052 &f.indent;PciChipsets *p_chip,
2053 &f.indent;resList res, EntityProc init,
2054 &f.indent;EntityProc enter, EntityProc leave,
2055 &f.indent;pointer private)&e.code;
2057 &s.code;ScrnInfoPtr xf86ConfigIsaEntity(ScrnInfoPtr pScrn,
2058 &f.indent;int scrnFlag, int entityIndex,
2059 &f.indent;IsaChipsets *i_chip,
2060 &f.indent;resList res, EntityProc init,
2061 &f.indent;EntityProc enter, EntityProc leave,
2062 &f.indent;pointer private)&e.code;
2063 <quote><p>
2064 These functions are used to register the non-relocatable resources
2065 for an entity, and the optional entity-specific &s.code;Init&e.code;, &s.code;Enter&e.code; and
2066 &s.code;Leave&e.code; functions. Usually the list of fixed resources is obtained
2067 from the Isa/PciChipsets lists. However an additional list of
2068 resources may be passed. Generally this is not required.
2069 For active entities a &s.code;ScrnInfoRec&e.code; is allocated
2070 if the &s.code;pScrn&e.code; argument is &s.code;NULL&e.code;.
2072 return value is &s.code;TRUE&e.code; when successful. The init, enter, leave
2073 functions are defined as follows:
2075 <quote>
2076 &s.code;typedef void (*EntityProc)(int entityIndex,
2077 &f.indent;pointer private)&e.code;
2078 </quote>
2080 They are passed the entity index and a pointer to a private scratch
2081 area. This can be set up during &s.code;Probe()&e.code; and
2082 its address can be passed to
2083 &s.code;xf86ConfigIsaEntity()&e.code; and
2084 &s.code;xf86ConfigPciEntity()&e.code; as the last argument.
2086 </quote>
2087 </quote>
2089 These two helper functions make use of several core functions that are
2090 available at the driver level:
2091 <quote><p>
2092 &s.code;void xf86ClaimFixedResources(resList list, int entityIndex)&e.code;
2093 <quote><p>
2094 This function registers the non-relocatable resources which cannot
2095 be disabled and which therefore would cause the server to fail
2096 immediately if they were found to conflict. It also records
2097 non-relocatable but sharable resources for processing after the
2098 &s.code;Probe()&e.code; phase.
2100 </quote>
2102 &s.code;Bool xf86SetEntityFuncs(int entityIndex, EntityProc init,
2103 &f.indent;EntityProc enter, EntityProc leave, pointer)&e.code;
2104 <quote><p>
2105 This function registers with an entity the &s.code;init&e.code;,
2106 &s.code;enter&e.code;, &s.code;leave&e.code; functions along
2107 with the pointer to their private area.
2109 </quote>
2111 &s.code;void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex)&e.code;
2112 <quote><p>
2113 This function associates the entity referenced by
2114 &s.code;entityIndex&e.code; with the screen.
2116 </quote>
2117 </quote>
2119 <sect2>PreInit Phase
2122 During this phase the remaining resources should be registered.
2123 &s.code;PreInit()&e.code; should call &s.code;xf86GetEntityInfo()&e.code;
2124 to obtain a pointer to an &s.code;EntityInfoRec&e.code; for each entity
2125 it is able to drive and check if any resource are listed in its
2126 &s.code;resources&e.code; field. If resources registered in the Probe
2127 phase have been rejected in the post-Probe phase
2128 (&s.code;resources&e.code; is non-&s.code;NULL&e.code;), then the driver should
2129 decide if it can continue without using these or if it should fail.
2131 <quote><p>
2132 &s.code;EntityInfoPtr xf86GetEntityInfo(int entityIndex)&e.code;
2133 <quote><p>
2134 This function returns a pointer to the &s.code;EntityInfoRec&e.code;
2135 referenced by &s.code;entityIndex&e.code;. The returned
2136 &s.code;EntityInfoRec&e.code; should be freed with
2137 &s.code;xfree()&e.code; when no longer needed.
2139 </quote>
2140 </quote>
2141 Several functions are provided to simplify resource registration:
2142 <quote><p>
2143 &s.code;Bool xf86IsEntityPrimary(int entityIndex)&e.code;
2144 <quote><p>
2145 This function returns &s.code;TRUE&e.code; if the entity referenced
2146 by &s.code;entityIndex&e.code; is the primary display device (i.e.,
2147 the one initialised at boot time and used in text mode).
2149 </quote>
2151 &s.code;Bool xf86IsScreenPrimary(int scrnIndex)&e.code;
2152 <quote><p>
2153 This function returns &s.code;TRUE&e.code; if the primary entity
2154 is registered with the screen referenced by
2155 &s.code;scrnIndex&e.code;.
2157 </quote>
2159 &s.code;pciVideoPtr xf86GetPciInfoForEntity(int entityIndex)&e.code;
2160 <quote><p>
2161 This function returns a pointer to the &s.code;pciVideoRec&e.code;
2162 for the specified entity. If the entity is not a PCI device,
2163 &s.code;NULL&e.code; is returned.
2165 </quote>
2166 </quote>
2168 The primary function for registration of resources is:
2169 <quote><p>
2170 &s.code;resPtr xf86RegisterResources(int entityIndex, resList list,
2171 &f.indent;int access)&e.code;
2172 <quote><p>
2173 This function tries to register the resources in
2174 &s.code;list&e.code;. If list is &s.code;NULL&e.code; it tries
2175 to determine the resources automatically. This only works for
2176 entities that provide a generic way to read out the resource ranges
2177 they decode. So far this is only the case for PCI devices. By
2178 default the PCI resources are registered as shared
2179 (&s.code;ResShared&e.code;) if the driver wants to set a different
2180 access type it can do so by specifying the access flags in the
2181 third argument. A value of &s.code;0&e.code; means to use the
2182 default settings. If for any reason the resource broker is not
2183 able to register some of the requested resources the function will
2184 return a pointer to a list of the failed ones. In this case the
2185 driver may be able to move the resource to different locations.
2186 In case of PCI bus entities this is done by passing the list of
2187 failed resources to &s.code;xf86ReallocatePciResources()&e.code;.
2188 When the registration succeeds, the return value is
2189 &s.code;NULL&e.code;.
2191 </quote>
2193 &s.code;resPtr xf86ReallocatePciResources(int entityIndex, resPtr pRes)&e.code;
2194 <quote><p>
2195 This function takes a list of PCI resources that need to be
2196 reallocated and returns &s.code;NULL&e.code when all relocations are
2197 successful.
2198 &s.code;xf86RegisterResources()&e.code; should be called again to
2199 register the relocated resources with the broker.
2200 If the reallocation fails, a list of the resources that could not be
2201 relocated is returned.
2203 </quote>
2204 </quote>
2206 Two functions are provided to obtain a resource range of a given type:
2207 <quote><p>
2208 &s.code;resRange xf86GetBlock(long type, memType size,
2209 &f.indent;memType window_start, memType window_end,
2210 &f.indent;memType align_mask, resPtr avoid)&e.code;
2211 <quote><p>
2212 This function tries to find a block range of size
2213 &s.code;size&e.code; and type &s.code;type&e.code; in a window
2214 bound by &s.code;window_start&e.code; and &s.code;window_end&e.code;
2215 with the alignment specified in &s.code;align_mask&e.code;.
2216 Optionally a list of resource ranges which should be avoided within
2217 the window can be supplied. On failure a zero-length range of
2218 type &s.code;ResEnd&e.code; will be returned.
2220 </quote>
2221 &s.code;resRange xf86GetSparse(long type, memType fixed_bits,
2222 &f.indent;memType decode_mask, memType address_mask,
2223 &f.indent;resPtr avoid)&e.code;
2224 <quote><p>
2225 This function is like the previous one, but attempts to find a
2226 sparse range instead of a block range. Here three values have to
2227 be specified: the &s.code;address_mask&e.code; which marks all
2228 bits of the mask part of the address, the &s.code;decode_mask&e.code;
2229 which masks out the bits which are hardcoded and are therefore
2230 not available for relocation and the values of the fixed bits.
2231 The function tries to find a base that satisfies the given condition.
2232 If the function fails it will return a zero range of type
2233 &s.code;ResEnd&e.code;. Optionally it might be passed a list of
2234 resource ranges to avoid.
2236 </quote>
2237 </quote>
2239 Some PCI devices are broken in the sense that they return invalid size
2240 information for a certain resource. In this case the driver can supply
2241 the correct size and make sure that the resource range allocated for
2242 the card is large enough to hold the address range decoded by the card.
2243 The function &s.code;xf86FixPciResource()&e.code; can be used to do this:
2244 <quote><p>
2245 &s.code;Bool xf86FixPciResource(int entityIndex, unsigned int prt,
2246 &f.indent;CARD32 alignment, long type)&e.code;
2247 <quote><p>
2248 This function fixes a PCI resource allocation. The
2249 &s.code;prt&e.code; parameter contains the number of the PCI base
2250 register that needs to be fixed (&s.code;0-5&e.code;, and
2251 &s.code;6&e.code; for the BIOS base register). The size is
2252 specified by the alignment. Since PCI resources need to span an
2253 integral range of size &s.code;2^n&e.code;, the alignment also
2254 specifies the number of addresses that will be decoded. If the
2255 driver specifies a type mask it can override the default type for
2256 PCI resources which is &s.code;ResShared&e.code;. The resource
2257 broker needs to know that to find a matching resource range. This
2258 function should be called before calling
2259 &s.code;xf86RegisterResources()&e.code;. The return value is
2260 &s.code;TRUE&e.code; when the function succeeds.
2262 </quote>
2264 &s.code;Bool xf86CheckPciMemBase(pciVideoPtr pPci, memType base)&e.code;
2265 <quote><p>
2266 This function checks that the memory base address specified matches
2267 one of the PCI base address register values for the given PCI
2268 device. This is mostly used to check that an externally provided
2269 base address (e.g., from a config file) matches an actual value
2270 allocated to a device.
2272 </quote>
2273 </quote>
2275 The driver may replace the generic access control functions for an entity.
2276 This is done with the &s.code;xf86SetAccessFuncs()&e.code;:
2277 <quote><p>
2278 &s.code;void xf86SetAccessFuncs(EntityInfoPtr pEnt,
2279 &f.indent;xf86SetAccessFuncPtr funcs,
2280 &f.indent;xf86SetAccessFuncPtr oldFuncs)&e.code;
2281 <quote><p>
2282 with:
2283 </quote>
2285 <verb>
2286 typedef struct {
2287 xf86AccessPtr mem;
2288 xf86AccessPtr io;
2289 xf86AccessPtr io_mem;
2290 } xf86SetAccessFuncRec, *xf86SetAccessFuncPtr;
2291 </verb>
2293 <quote><p>
2294 The driver can pass three functions: one for I/O access, one for
2295 memory access and one for combined memory and I/O access. If the
2296 memory access and combined access functions are identical the
2297 common level assumes that the memory access cannot be controlled
2298 independently of I/O access, if the I/O access function and the
2299 combined access functions are the same it is assumed that I/O can
2300 not be controlled independently. If memory and I/O have to be
2301 controlled together all three values should be the same. If a
2302 non &s.code;NULL&e.code; value is passed as third argument it is
2303 interpreted as an address where to store the old access record.
2304 If the third argument is &s.code;NULL&e.code; it will be assumed
2305 that the generic access should be enabled before replacing the
2306 access functions. Otherwise it will be disabled. The driver may
2307 enable them itself using the returned values. It should do this
2308 from its replacement access functions as the generic access may
2309 be disabled by the common level on certain occasions. If replacement
2310 functions are specified they must control all resources of the
2311 specific type registered for the entity.
2313 </quote>
2314 </quote>
2316 To find out if a specific resource range conflicts with another
2317 resource the &s.code;xf86ChkConflict()&e.code; function may be used:
2318 <quote><p>
2319 &s.code;memType xf86ChkConflict(resRange *rgp, int entityIndex)&e.code;
2320 <quote><p>
2321 This function checks if the resource range &s.code;rgp&e.code; of
2322 for the specified entity conflicts with with another resource.
2323 If a conflict is found, the address of the start of the conflict
2324 is returned. The return value is zero when there is no conflict.
2326 </quote>
2327 </quote>
2329 The OPERATING state properties of previously registered fixed resources
2330 can be set with the &s.code;xf86SetOperatingState()&e.code; function:
2331 <quote><p>
2332 &s.code;resPtr xf86SetOperatingState(resList list, int entityIndex,
2333 &f.indent;int mask)&e.code;
2334 <quote><p>
2335 This function is used to set the status of a resource during
2336 OPERATING state. &s.code;list&e.code; holds a list to which
2337 &s.code;mask&e.code; is to be applied. The parameter
2338 &s.code;mask&e.code; may have the value &s.code;ResUnusedOpr&e.code;
2339 and &s.code;ResDisableOpr&e.code;. The first one should be used
2340 if a resource isn't used by the driver during OPERATING state
2341 although it is decoded by the device, while the latter one indicates
2342 that the resource is not decoded during OPERATING state. Note
2343 that the resource ranges have to match those specified during
2344 registration. If a range has been specified starting at
2345 &s.code;A&e.code; and ending at &s.code;B&e.code; and suppose
2346 &s.code;C&e.code; us a value satisfying
2347 &s.code;A&nbsp;&lt;&nbsp;C&nbsp;&lt;&nbsp;B&e.code; one may not
2348 specify the resource range &s.code;(A,B)&e.code; by splitting it
2349 into two ranges &s.code;(A,C)&e.code; and &s.code;(C,B)&e.code;.
2351 </quote>
2352 </quote>
2354 The following two functions are provided for special cases:
2355 <quote><p>
2356 &s.code;void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex)&e.code;
2357 <quote><p>
2358 This function may be used to remove an entity from a screen. This
2359 only makes sense if a screen has more than one entity assigned or
2360 the screen is to be deleted. No test is made if the screen has
2361 any entities left.
2363 </quote>
2365 &s.code;void xf86DeallocateResourcesForEntity(int entityIndex, long type)&e.code;
2366 <quote><p>
2367 This function deallocates all resources of a given type registered
2368 for a certain entity from the resource broker list.
2370 </quote>
2371 </quote>
2373 <sect2>ScreenInit Phase
2376 All that is required in this phase is to setup the RAC flags. Note that
2377 it is also permissible to set these flags up in the PreInit phase. The
2378 RAC flags are held in the &s.code;racIoFlags&e.code; and &s.code;racMemFlags&e.code; fields of the
2379 &s.code;ScrnInfoRec&e.code; for each screen. They specify which graphics operations
2380 might require the use of shared resources. This can be specified
2381 separately for memory and I/O resources. The available flags are defined
2382 in &s.code;rac/xf86RAC.h&e.code;. They are:
2384 &s.code;RAC_FB&e.code;
2385 <quote>
2386 for framebuffer operations (including hw acceleration)
2387 </quote>
2388 &s.code;RAC_CURSOR&e.code;
2389 <quote>
2390 for Cursor operations
2391 (??? I'm not sure if we need this for SW cursor it depends
2392 on which level the sw cursor is drawn)
2393 </quote>
2394 &s.code;RAC_COLORMAP&e.code;
2395 <quote>
2396 for colormap operations
2397 </quote>
2398 &s.code;RAC_VIEWPORT&e.code;
2399 <quote>
2400 for the call to &s.code;ChipAdjustFrame()&e.code; </quote>
2403 The flags are ORed together.
2405 <sect>Config file ``Option'' entries<label id="options">
2408 Option entries are permitted in most sections and subsections of the
2409 config file. There are two forms of option entries:
2411 <descrip>
2412 <tag>Option "option-name"</tag>
2413 A boolean option.
2414 <tag>Option "option-name" "option-value"</tag>
2415 An option with an arbitrary value.
2416 </descrip>
2418 The option entries are handled by the parser, and a list of the parsed
2419 options is included with each of the appropriate data structures that
2420 the drivers have access to. The data structures used to hold the option
2421 information are opaque to the driver, and a driver must not access the
2422 option data directly. Instead, the common layer provides a set of
2423 functions that may be used to access, check and manipulate the option
2424 data.
2426 First, the low level option handling functions. In most cases drivers
2427 would not need to use these directly.
2429 <quote><p>
2430 &s.code;pointer xf86FindOption(pointer options, const char *name)&e.code;
2431 <quote><p>
2432 Takes a list of options and an option name, and returns a handle
2433 for the first option entry in the list matching the name. Returns
2434 &s.code;NULL&e.code; if no match is found.
2436 </quote>
2438 &s.code;char *xf86FindOptionValue(pointer options, const char *name)&e.code;
2439 <quote><p>
2440 Takes a list of options and an option name, and returns the value
2441 associated with the first option entry in the list matching the
2442 name. If the matching option has no value, an empty string
2443 (&s.code;""&e.code;) is returned. Returns &s.code;NULL&e.code;
2444 if no match is found.
2446 </quote>
2448 &s.code;void xf86MarkOptionUsed(pointer option)&e.code;
2449 <quote><p>
2450 Takes a handle for an option, and marks that option as used.
2452 </quote>
2454 &s.code;void xf86MarkOptionUsedByName(pointer options, const char *name)&e.code;
2455 <quote><p>
2456 Takes a list of options and an option name and marks the first
2457 option entry in the list matching the name as used.
2459 </quote>
2460 </quote>
2463 Next, the higher level functions that most drivers would use.
2464 <quote><p>
2465 &s.code;void xf86CollectOptions(ScrnInfoPtr pScrn, pointer extraOpts)&e.code;
2466 <quote><p>
2467 Collect the options from each of the config file sections used by
2468 the screen (&s.code;pScrn&e.code;) and return the merged list as
2469 &s.code;pScrn-&gt;options&e.code;. This function requires that
2470 &s.code;pScrn-&gt;confScreen&e.code;, &s.code;pScrn-&gt;display&e.code;,
2471 &s.code;pScrn-&gt;monitor&e.code;,
2472 &s.code;pScrn-&gt;numEntities&e.code;, and
2473 &s.code;pScrn-&gt;entityList&e.code; are initialised.
2474 &s.code;extraOpts&e.code; may optionally be set to an additional
2475 list of options to be combined with the others. The order of
2476 precedence for options is &s.code;extraOpts&e.code;, display,
2477 confScreen, monitor, device.
2479 </quote>
2481 &s.code;void xf86ProcessOptions(int scrnIndex, pointer options,
2482 &f.indent;OptionInfoPtr optinfo)&e.code;
2483 <quote><p>
2484 Processes a list of options according to the information in the
2485 array of &s.code;OptionInfoRecs&e.code; (&s.code;optinfo&e.code;).
2486 The resulting information is stored in the &s.code;value&e.code;
2487 fields of the appropriate &s.code;optinfo&e.code; entries. The
2488 &s.code;found&e.code; fields are set to &s.code;TRUE&e.code;
2489 when an option with a value of the correct type if found, and
2490 &s.code;FALSE&e.code; otherwise. The &s.code;type&e.code; field
2491 is used to determine the expected value type for each option.
2492 Each option in the list of options for which there is a name match
2493 (but not necessarily a value type match) is marked as used.
2494 Warning messages are printed when option values don't match the
2495 types specified in the optinfo data.
2497 NOTE: If this function is called before a driver's screen number
2498 is known (e.g., from the &s.code;ChipProbe()&e.code; function) a
2499 &s.code;scrnIndex&e.code; value of &s.code;-1&e.code; should be
2500 used.
2502 NOTE 2: Given that this function stores into the
2503 &s.code;OptionInfoRecs&e.code; pointed to by &s.code;optinfo&e.code,
2504 the caller should ensure the &s.code;OptionInfoRecs&e.code; are
2505 (re-)initialised before the call, especially if the caller expects
2506 to use the predefined option values as defaults.
2508 The &s.code;OptionInfoRec&e.code; is defined as follows:
2510 <verb>
2511 typedef struct {
2512 double freq;
2513 int units;
2514 } OptFrequency;
2516 typedef union {
2517 unsigned long num;
2518 char * str;
2519 double realnum;
2520 Bool bool;
2521 OptFrequency freq;
2522 } ValueUnion;
2524 typedef enum {
2525 OPTV_NONE = 0,
2526 OPTV_INTEGER,
2527 OPTV_STRING, /* a non-empty string */
2528 OPTV_ANYSTR, /* Any string, including an empty one */
2529 OPTV_REAL,
2530 OPTV_BOOLEAN,
2531 OPTV_FREQ
2532 } OptionValueType;
2534 typedef enum {
2535 OPTUNITS_HZ = 1,
2536 OPTUNITS_KHZ,
2537 OPTUNITS_MHZ
2538 } OptFreqUnits;
2540 typedef struct {
2541 int token;
2542 const char* name;
2543 OptionValueType type;
2544 ValueUnion value;
2545 Bool found;
2546 } OptionInfoRec, *OptionInfoPtr;
2547 </verb>
2549 &s.code;OPTV_FREQ&e.code; can be used for options values that are
2550 frequencies. These values are a floating point number with an
2551 optional unit name appended. The unit name can be one of "Hz",
2552 "kHz", "k", "MHz", "M". The multiplier associated with the unit
2553 is stored in &s.code;freq.units&e.code;, and the scaled frequency
2554 is stored in &s.code;freq.freq&e.code;. When no unit is specified,
2555 &s.code;freq.units&e.code; is set to &s.code;0&e.code;, and
2556 &s.code;freq.freq&e.code; is unscaled.
2558 Typical usage is to setup an array of
2559 &s.code;OptionInfoRecs&e.code; with all fields initialised.
2560 The &s.code;value&e.code; and &s.code;found&e.code; fields get
2561 set by &s.code;xf86ProcessOptions()&e.code;. For cases where the
2562 value parsing is more complex, the driver should specify
2563 &s.code;OPTV_STRING&e.code;, and parse the string itself. An
2564 example of using this option handling is included in the
2565 <ref id="sample" name="Sample Driver"> section.
2567 </quote>
2569 &s.code;void xf86ShowUnusedOptions(int scrnIndex, pointer options)&e.code;
2570 <quote><p>
2571 Prints out warning messages for each option in the list of options
2572 that isn't marked as used. This is intended to show options that
2573 the driver hasn't recognised. It would normally be called near
2574 the end of the &s.code;ChipScreenInit()&e.code; function, but only
2575 when &s.code;serverGeneration&nbsp;==&nbsp;1&e.code;.
2577 </quote>
2579 &s.code;OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table,
2580 &f.indent;int token)&e.code;
2582 <quote><p>
2583 Returns a pointer to the &s.code;OptionInfoRec&e.code; in
2584 &s.code;table&e.code; with a token field matching
2585 &s.code;token&e.code;. Returns &s.code;NULL&e.code; if no match
2586 is found.
2588 </quote>
2590 &s.code;Bool xf86IsOptionSet(const OptionInfoRec *table, int token)&e.code;
2591 <quote><p>
2592 Returns the &s.code;found&e.code; field of the
2593 &s.code;OptionInfoRec&e.code; in &s.code;table&e.code; with a
2594 &s.code;token&e.code; field matching &s.code;token&e.code;. This
2595 can be used for options of all types. Note that for options of
2596 type &s.code;OPTV_BOOLEAN&e.code;, it isn't sufficient to check
2597 this to determine the value of the option. Returns
2598 &s.code;FALSE&e.code; if no match is found.
2600 </quote>
2602 &s.code;char *xf86GetOptValString(const OptionInfoRec *table, int token)&e.code;
2603 <quote><p>
2604 Returns the &s.code;value.str&e.code; field of the
2605 &s.code;OptionInfoRec&e.code; in &s.code;table&e.code; with a
2606 token field matching &s.code;token&e.code;. Returns
2607 &s.code;NULL&e.code; if no match is found.
2609 </quote>
2611 &s.code;Bool xf86GetOptValInteger(const OptionInfoRec *table, int token,
2612 &f.indent;int *value)&e.code;
2613 <quote><p>
2614 Returns via &s.code;*value&e.code; the &s.code;value.num&e.code;
2615 field of the &s.code;OptionInfoRec&e.code; in &s.code;table&e.code;
2616 with a &s.code;token&e.code; field matching &s.code;token&e.code;.
2617 &s.code;*value&e.code; is only changed when a match is found so
2618 it can be safely initialised with a default prior to calling this
2619 function. The function return value is as for
2620 &s.code;xf86IsOptionSet()&e.code;.
2622 </quote>
2624 &s.code;Bool xf86GetOptValULong(const OptionInfoRec *table, int token,
2625 &f.indent;unsigned long *value)&e.code;
2626 <quote><p>
2627 Like &s.code;xf86GetOptValInteger()&e.code;, except the value is
2628 treated as an &s.code;unsigned long&e.code;.
2630 </quote>
2632 &s.code;Bool xf86GetOptValReal(const OptionInfoRec *table, int token,
2633 &f.indent;double *value)&e.code;
2634 <quote><p>
2635 Like &s.code;xf86GetOptValInteger()&e.code;, except that
2636 &s.code;value.realnum&e.code; is used.
2638 </quote>
2640 &s.code;Bool xf86GetOptValFreq(const OptionInfoRec *table, int token,
2641 &f.indent;OptFreqUnits expectedUnits, double *value)&e.code;
2642 <quote><p>
2643 Like &s.code;xf86GetOptValInteger()&e.code;, except that the
2644 &s.code;value.freq&e.code; data is returned. The frequency value
2645 is scaled to the units indicated by &s.code;expectedUnits&e.code;.
2646 The scaling is exact when the units were specified explicitly in
2647 the option's value. Otherwise, the &s.code;expectedUnits&e.code;
2648 field is used as a hint when doing the scaling. In this case,
2649 values larger than &s.code;1000&e.code; are assumed to have be
2650 specified in the next smallest units. For example, if the Option
2651 value is "10000" and expectedUnits is &s.code;OPTUNITS_MHZ&e.code;,
2652 the value returned is &s.code;10&e.code;.
2654 </quote>
2656 &s.code;Bool xf86GetOptValBool(const OptionInfoRec *table, int token, Bool *value)&e.code;
2657 <quote><p>
2658 This function is used to check boolean options
2659 (&s.code;OPTV_BOOLEAN&e.code;). If the function return value is
2660 &s.code;FALSE&e.code;, it means the option wasn't set. Otherwise
2661 &s.code;*value&e.code; is set to the boolean value indicated by
2662 the option's value. No option &s.code;value&e.code; is interpreted
2663 as &s.code;TRUE&e.code;. Option values meaning &s.code;TRUE&e.code;
2664 are "1", "yes", "on", "true", and option values meaning
2665 &s.code;FALSE&e.code; are "0", "no", "off", "false". Option names
2666 both with the "no" prefix in their names, and with that prefix
2667 removed are also checked and handled in the obvious way.
2668 &s.code;*value&e.code; is not changed when the option isn't present.
2669 It should normally be set to a default value before calling this
2670 function.
2672 </quote>
2674 &s.code;Bool xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def)&e.code;
2675 <quote><p>
2676 This function is used to check boolean options
2677 (&s.code;OPTV_BOOLEAN&e.code;). If the option is set, its value
2678 is returned. If the options is not set, the default value specified
2679 by &s.code;def&e.code; is returned. The option interpretation is
2680 the same as for &s.code;xf86GetOptValBool()&e.code;.
2682 </quote>
2684 &s.code;int xf86NameCmp(const char *s1, const char *s2)&e.code;
2685 <quote><p>
2686 This function should be used when comparing strings from the config
2687 file with expected values. It works like &s.code;strcmp()&e.code;,
2688 but is not case sensitive and space, tab, and `<tt>_</tt>' characters
2689 are ignored in the comparison. The use of this function isn't
2690 restricted to parsing option values. It may be used anywhere
2691 where this functionality required.
2693 </quote>
2694 </quote>
2696 <sect>Modules, Drivers, Include Files and Interface Issues
2699 NOTE: this section is incomplete.
2702 <sect1>Include files
2705 The following include files are typically required by video drivers:
2707 <quote><p>
2708 All drivers should include these:
2709 <quote>
2710 &s.code;"xf86.h"&nl;
2711 "xf86_OSproc.h"&nl;
2712 "xf86_ansic.h"&nl;
2713 "xf86Resources.h"&e.code;
2714 </quote>
2715 Wherever inb/outb (and related things) are used the following should be
2716 included:
2717 <quote>
2718 &s.code;"compiler.h"&e.code;
2719 </quote>
2720 Note: in drivers, this must be included after &s.code;"xf86_ansic.h"&e.code;.
2722 Drivers that need to access PCI vendor/device definitions need this:
2723 <quote>
2724 &s.code;"xf86PciInfo.h"&e.code;
2725 </quote>
2727 Drivers that need to access the PCI config space need this:
2728 <quote>
2729 &s.code;"xf86Pci.h"&e.code;
2730 </quote>
2732 Drivers that initialise a SW cursor need this:
2733 <quote>
2734 &s.code;"mipointer.h"&e.code;
2735 </quote>
2737 All drivers implementing backing store need this:
2738 <quote>
2739 &s.code;"mibstore.h"&e.code;
2740 </quote>
2742 All drivers using the mi colourmap code need this:
2743 <quote>
2744 &s.code;"micmap.h"&e.code;
2745 </quote>
2747 If a driver uses the vgahw module, it needs this:
2748 <quote>
2749 &s.code;"vgaHW.h"&e.code;
2750 </quote>
2752 Drivers supporting VGA or Hercules monochrome screens need:
2753 <quote>
2754 &s.code;"xf1bpp.h"&e.code;
2755 </quote>
2757 Drivers supporting VGA or EGC 16-colour screens need:
2758 <quote>
2759 &s.code;"xf4bpp.h"&e.code;
2760 </quote>
2762 Drivers using cfb need:
2763 <quote>
2764 &s.code;#define PSZ 8&nl;
2765 #include "cfb.h"&nl;
2766 #undef PSZ&e.code;
2767 </quote>
2769 Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
2770 <quote>
2771 &s.code;"cfb16.h"&nl;
2772 "cfb24.h"&nl;
2773 "cfb32.h"&e.code;
2774 </quote>
2776 If a driver uses XAA, it needs these:
2777 <quote>
2778 &s.code;"xaa.h"&nl;
2779 "xaalocal.h"&e.code;
2780 </quote>
2782 If a driver uses the fb manager, it needs this:
2783 <quote>
2784 &s.code;"xf86fbman.h"&e.code;
2785 </quote>
2786 </quote>
2788 Non-driver modules should include &s.code;"xf86_ansic.h"&e.code; to get the correct
2789 wrapping of ANSI C/libc functions.
2791 All modules must NOT include any system include files, or the following:
2793 <quote>
2794 &s.code;"xf86Priv.h"&nl;
2795 "xf86Privstr.h"&nl;
2796 "xf86_OSlib.h"&nl;
2797 "Xos.h"&e.code;
2798 </quote>
2800 In addition, "xf86_libc.h" must not be included explicitly. It is
2801 included implicitly by "xf86_ansic.h".
2804 <sect>Offscreen Memory Manager
2807 Management of offscreen video memory may be handled by the XFree86
2808 framebuffer manager. Once the offscreen memory manager is running,
2809 drivers or extensions may allocate, free or resize areas of offscreen
2810 video memory using the following functions (definitions taken from
2811 &s.code;xf86fbman.h&e.code;):
2813 <code>
2814 typedef struct _FBArea {
2815 ScreenPtr pScreen;
2816 BoxRec box;
2817 int granularity;
2818 void (*MoveAreaCallback)(struct _FBArea*, struct _FBArea*)
2819 void (*RemoveAreaCallback)(struct _FBArea*)
2820 DevUnion devPrivate;
2821 } FBArea, *FBAreaPtr;
2823 typedef void (*MoveAreaCallbackProcPtr)(FBAreaPtr from, FBAreaPtr to)
2824 typedef void (*RemoveAreaCallbackProcPtr)(FBAreaPtr)
2826 FBAreaPtr xf86AllocateOffscreenArea (
2827 ScreenPtr pScreen,
2828 int width, int height,
2829 int granularity,
2830 MoveAreaCallbackProcPtr MoveAreaCallback,
2831 RemoveAreaCallbackProcPtr RemoveAreaCallback,
2832 pointer privData
2835 void xf86FreeOffscreenArea (FBAreaPtr area)
2837 Bool xf86ResizeOffscreenArea (
2838 FBAreaPtr area
2839 int w, int h
2841 </code>
2843 The function:
2844 <quote>
2845 &s.code;Bool xf86FBManagerRunning(ScreenPtr pScreen)&e.code;
2846 </quote>
2848 can be used by an extension to check if the driver has initialized
2849 the memory manager. The manager is not available if this returns
2850 &s.code;FALSE&e.code; and the functions above will all fail.
2853 &s.code;xf86AllocateOffscreenArea()&e.code; can be used to request a
2854 rectangle of dimensions &s.code;width&e.code; x &s.code;height&e.code;
2855 (in pixels) from unused offscreen memory. &s.code;granularity&e.code;
2856 specifies that the leftmost edge of the rectangle must lie on some
2857 multiple of &s.code;granularity&e.code; pixels. A granularity of zero
2858 means the same thing as a granularity of one - no alignment preference.
2859 A &s.code;MoveAreaCallback&e.code; can be provided to notify the requester
2860 when the offscreen area is moved. If no &s.code;MoveAreaCallback&e.code;
2861 is supplied then the area is considered to be immovable. The
2862 &s.code;privData&e.code; field will be stored in the manager's internal
2863 structure for that allocated area and will be returned to the requester
2864 in the &s.code;FBArea&e.code; passed via the
2865 &s.code;MoveAreaCallback&e.code;. An optional
2866 &s.code;RemoveAreaCallback&e.code; is provided. If the driver provides
2867 this it indicates that the area should be allocated with a lower priority.
2868 Such an area may be removed when a higher priority request (one that
2869 doesn't have a &s.code;RemoveAreaCallback&e.code;) is made. When this
2870 function is called, the driver will have an opportunity to do whatever
2871 cleanup it needs to do to deal with the loss of the area, but it must
2872 finish its cleanup before the function exits since the offscreen memory
2873 manager will free the area immediately after.
2875 &s.code;xf86AllocateOffscreenArea()&e.code; returns &s.code;NULL&e.code;
2876 if it was unable to allocate the requested area. When no longer needed,
2877 areas should be freed with &s.code;xf86FreeOffscreenArea()&e.code;.
2879 &s.code;xf86ResizeOffscreenArea()&e.code; resizes an existing
2880 &s.code;FBArea&e.code;. &s.code;xf86ResizeOffscreenArea()&e.code;
2881 returns &s.code;TRUE&e.code; if the resize was successful. If
2882 &s.code;xf86ResizeOffscreenArea()&e.code; returns &s.code;FALSE&e.code;,
2883 the original &s.code;FBArea&e.code; is left unmodified. Resizing an
2884 area maintains the area's original &s.code;granularity&e.code;,
2885 &s.code;devPrivate&e.code;, and &s.code;MoveAreaCallback&e.code;.
2886 &s.code;xf86ResizeOffscreenArea()&e.code; has considerably less overhead
2887 than freeing the old area then reallocating the new size, so it should
2888 be used whenever possible.
2890 The function:
2891 <quote>
2892 &s.code;Bool xf86QueryLargestOffscreenArea(
2893 &f.indent;ScreenPtr pScreen,
2894 &f.indent;int *width, int *height,
2895 &f.indent;int granularity,
2896 &f.indent;int preferences,
2897 &f.indent;int priority
2898 &nl)&e.code;
2899 </quote>
2901 is provided to query the width and height of the largest single
2902 &s.code;FBArea&e.code; allocatable given a particular priority.
2903 &s.code;preferences&e.code; can be one of the following to indicate
2904 whether width, height or area should be considered when determining
2905 which is the largest single &s.code;FBArea&e.code; available.
2907 <quote>
2908 &s.code;FAVOR_AREA_THEN_WIDTH&nl;
2909 FAVOR_AREA_THEN_HEIGHT&nl;
2910 FAVOR_WIDTH_THEN_AREA&nl;
2911 FAVOR_HEIGHT_THEN_AREA&e.code;
2912 </quote>
2914 &s.code;priority&e.code; is one of the following:
2916 <quote><p>
2917 &s.code;PRIORITY_LOW&e.code;
2918 <quote><p>
2919 Return the largest block available without stealing anyone else's
2920 space. This corresponds to the priority of allocating a
2921 &s.code;FBArea&e.code; when a &s.code;RemoveAreaCallback&e.code;
2922 is provided.
2924 </quote>
2925 &s.code;PRIORITY_NORMAL&e.code;
2926 <quote><p>
2927 Return the largest block available if it is acceptable to steal a
2928 lower priority area from someone. This corresponds to the priority
2929 of allocating a &s.code;FBArea&e.code; without providing a
2930 &s.code;RemoveAreaCallback&e.code;.
2932 </quote>
2933 &s.code;PRIORITY_EXTREME&e.code;
2934 <quote><p>
2935 Return the largest block available if all &s.code;FBAreas&e.code;
2936 that aren't locked down were expunged from memory first. This
2937 corresponds to any allocation made directly after a call to
2938 &s.code;xf86PurgeUnlockedOffscreenAreas()&e.code;.
2940 </quote>
2941 </quote>
2944 The function:
2946 <quote>
2947 &s.code;Bool xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen)&e.code;
2948 </quote>
2950 is provided as an extreme method to free up offscreen memory. This
2951 will remove all removable &s.code;FBArea&e.code; allocations.
2954 Initialization of the XFree86 framebuffer manager is done via
2956 <quote>
2957 &s.code;Bool xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox)&e.code;
2958 </quote>
2960 &s.code;FullBox&e.code; represents the area of the framebuffer that the
2961 manager is allowed to manage. This is typically a box with a width of
2962 &s.code;pScrn-&gt;displayWidth&e.code; and a height of as many lines as
2963 can be fit within the total video memory, however, the driver can reserve
2964 areas at the extremities by passing a smaller area to the manager.
2966 &s.code;xf86InitFBManager()&e.code; must be called before XAA is
2967 initialized since XAA uses the manager for it's pixmap cache.
2969 An alternative function is provided to allow the driver to initialize
2970 the framebuffer manager with a Region rather than a box.
2972 <quote>
2973 &s.code;Bool xf86InitFBManagerRegion(ScreenPtr pScreen,
2974 &f.indent;RegionPtr FullRegion)&e.code;
2975 </quote>
2977 &s.code;xf86InitFBManagerRegion()&e.code;, unlike
2978 &s.code;xf86InitFBManager()&e.code;, does not remove the area used for
2979 the visible screen so that area should not be included in the region
2980 passed to the function. &s.code;xf86InitFBManagerRegion()&e.code; is
2981 useful when non-contiguous areas are available to be managed, and is
2982 required when multiple framebuffers are stored in video memory (as in
2983 the case where an overlay of a different depth is stored as a second
2984 framebuffer in offscreen memory).
2987 <sect>Colormap Handling<label id="cmap">
2990 A generic colormap handling layer is provided within the XFree86 common
2991 layer. This layer takes care of most of the details, and only requires
2992 a function from the driver that loads the hardware palette when required.
2993 To use the colormap layer, a driver calls the
2994 &s.code;xf86HandleColormaps()&e.code; function.
2996 <quote><p>
2997 &s.code;Bool xf86HandleColormaps(ScreenPtr pScreen, int maxColors,
2998 &f.indent;int sigRGBbits, LoadPaletteFuncPtr loadPalette,
2999 &f.indent;SetOverscanFuncPtr setOverscan,
3000 unsigned int flags)&e.code;
3001 <quote><p>
3002 This function must be called after the default colormap has been
3003 initialised. The &s.code;pScrn-&gt;gamma&e.code; field must also
3004 be initialised, preferably by calling &s.code;xf86SetGamma()&e.code;.
3005 &s.code;maxColors&e.code; is the number of entries in the palette.
3006 &s.code;sigRGBbits&e.code; is the size in bits of each color
3007 component in the DAC's palette. &s.code;loadPalette&e.code;
3008 is a driver-provided function for loading a colormap into the
3009 hardware, and is described below. &s.code;setOverscan&e.code; is
3010 an optional function that may be provided when the overscan color
3011 is an index from the standard LUT and when it needs to be adjusted
3012 to keep it as close to black as possible. The
3013 &s.code;setOverscan&e.code; function programs the overscan index.
3014 It shouldn't normally be used for depths other than 8.
3015 &s.code;setOverscan&e.code; should be set to &s.code;NULL&e.code;
3016 when it isn't needed. &s.code;flags&e.code; may be set to the
3017 following (which may be ORed together):
3019 &s.code;CMAP_PALETTED_TRUECOLOR&e.code;
3020 <quote><p>
3021 the TrueColor visual is paletted and is
3022 just a special case of DirectColor.
3023 This flag is only valid for
3024 &s.code;bpp&nbsp;&gt;&nbsp;8&e.code;.
3026 </quote>
3028 &s.code;CMAP_RELOAD_ON_MODE_SWITCH&e.code;
3029 <quote><p>
3030 reload the colormap automatically
3031 after mode switches. This is useful
3032 for when the driver is resetting the
3033 hardware during mode switches and
3034 corrupting or erasing the hardware
3035 palette.
3037 </quote>
3039 &s.code;CMAP_LOAD_EVEN_IF_OFFSCREEN&e.code;
3040 <quote><p>
3041 reload the colormap even if the screen
3042 is switched out of the server's VC.
3043 The palette is <it>not</it> reloaded when
3044 the screen is switched back in, nor after
3045 mode switches. This is useful when the
3046 driver needs to keep track of palette
3047 changes.
3049 </quote>
3051 The colormap layer normally reloads the palette after VT enters so it
3052 is not necessary for the driver to save and restore the palette
3053 when switching VTs. The driver must, however, still save the
3054 initial palette during server start up and restore it during
3055 server exit.
3057 </quote>
3059 &s.code;void LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
3060 &f.indent;LOCO *colors, VisualPtr pVisual)&e.code;
3061 <quote><p>
3062 &s.code;LoadPalette()&e.code; is a driver-provided function for
3063 loading a colormap into hardware. &s.code;colors&e.code; is the
3064 array of RGB values that represent the full colormap.
3065 &s.code;indices&e.code; is a list of index values into the colors
3066 array. These indices indicate the entries that need to be updated.
3067 &s.code;numColors&e.code; is the number of the indices to be
3068 updated.
3070 </quote>
3072 &s.code;void SetOverscan(ScrnInfoPtr pScrn, int overscan)&e.code;
3073 <quote><p>
3074 &s.code;SetOverscan()&e.code; is a driver-provided function for
3075 programming the &s.code;overscan&e.code; index. As described
3076 above, it is normally only appropriate for LUT modes where all
3077 colormap entries are available for the display, but where one of
3078 them is also used for the overscan (typically 8bpp for VGA compatible
3079 LUTs). It isn't required in cases where the overscan area is
3080 never visible.
3082 </quote>
3083 </quote>
3086 <sect>DPMS Extension
3089 Support code for the DPMS extension is included in the XFree86 common layer.
3090 This code provides an interface between the main extension code, and a means
3091 for drivers to initialise DPMS when they support it. One function is
3092 available to drivers to do this initialisation, and it is always available,
3093 even when the DPMS extension is not supported by the core server (in
3094 which case it returns a failure result).
3097 <quote><p>
3098 &s.code;Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)&e.code;
3099 <quote><p>
3100 This function registers a driver's DPMS level programming function
3101 &s.code;set&e.code;. It also checks
3102 &s.code;pScrn-&gt;options&e.code; for the "dpms" option, and when
3103 present marks DPMS as being enabled for that screen. The
3104 &s.code;set&e.code; function is called whenever the DPMS level
3105 changes, and is used to program the requested level.
3106 &s.code;flags&e.code; is currently not used, and should be
3107 &s.code;0&e.code;. If the initialisation fails for any reason,
3108 including when there is no DPMS support in the core server, the
3109 function returns &s.code;FALSE&e.code;.
3111 </quote>
3112 </quote>
3115 Drivers that implement DPMS support must provide the following function,
3116 that gets called when the DPMS level is changed:
3119 <quote><p>
3120 &s.code;void ChipDPMSSet(ScrnInfoPtr pScrn, int level, int flags)&e.code;
3121 <quote><p>
3122 Program the DPMS level specified by &s.code;level&e.code;. Valid
3123 values of &s.code;level&e.code; are &s.code;DPMSModeOn&e.code;,
3124 &s.code;DPMSModeStandby&e.code;, &s.code;DPMSModeSuspend&e.code;,
3125 &s.code;DPMSModeOff&e.code;. These values are defined in
3126 &s.code;"extensions/dpms.h"&e.code;.
3128 </quote>
3129 </quote>
3132 <sect>DGA Extension
3135 Drivers can support the XFree86 Direct Graphics Architecture (DGA) by
3136 filling out a structure of function pointers and a list of modes and
3137 passing them to DGAInit.
3139 <quote><p>
3140 &s.code;Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs,
3141 &f.indent;DGAModePtr modes, int num)&e.code;
3142 <quote><p>
3143 <verb>
3144 /** The DGAModeRec **/
3146 typedef struct {
3147 int num;
3148 DisplayModePtr mode;
3149 int flags;
3150 int imageWidth;
3151 int imageHeight;
3152 int pixmapWidth;
3153 int pixmapHeight;
3154 int bytesPerScanline;
3155 int byteOrder;
3156 int depth;
3157 int bitsPerPixel;
3158 unsigned long red_mask;
3159 unsigned long green_mask;
3160 unsigned long blue_mask;
3161 int viewportWidth;
3162 int viewportHeight;
3163 int xViewportStep;
3164 int yViewportStep;
3165 int maxViewportX;
3166 int maxViewportY;
3167 int viewportFlags;
3168 int offset;
3169 unsigned char *address;
3170 int reserved1;
3171 int reserved2;
3172 } DGAModeRec, *DGAModePtr;
3173 </verb>
3175 &s.code;num&e.code;
3176 <quote>
3177 Can be ignored. The DGA DDX will assign these numbers.
3178 </quote>
3180 &s.code;mode&e.code;
3181 <quote>
3182 A pointer to the &s.code;DisplayModeRec&e.code; for this mode.
3183 </quote>
3185 &s.code;flags&e.code;
3186 <quote><p>
3187 The following flags are defined and may be OR'd together:
3189 &s.code;DGA_CONCURRENT_ACCESS&e.code;
3190 <quote><p>
3191 Indicates that the driver supports concurrent graphics
3192 accelerator and linear framebuffer access.
3194 </quote>
3196 &s.code;DGA_FILL_RECT&nl;
3197 DGA_BLIT_RECT&nl;
3198 DGA_BLIT_RECT_TRANS&e.code;
3199 <quote><p>
3200 Indicates that the driver supports the FillRect, BlitRect
3201 or BlitTransRect functions in this mode.
3203 </quote>
3205 &s.code;DGA_PIXMAP_AVAILABLE&e.code;
3206 <quote><p>
3207 Indicates that Xlib may be used on the framebuffer.
3208 This flag will usually be set unless the driver wishes
3209 to prohibit this for some reason.
3211 </quote>
3213 &s.code;DGA_INTERLACED&nl;
3214 DGA_DOUBLESCAN&e.code;
3215 <quote><p>
3216 Indicates that these are interlaced or double scan modes.
3218 </quote>
3219 </quote>
3221 &s.code;imageWidth&nl;
3222 imageHeight&e.code;
3223 <quote><p>
3224 These are the dimensions of the linear framebuffer
3225 accessible by the client.
3227 </quote>
3229 &s.code;pixmapWidth&nl;
3230 pixmapHeight&e.code;
3231 <quote><p>
3232 These are the dimensions of the area of the
3233 framebuffer accessible by the graphics accelerator.
3235 </quote>
3237 &s.code;bytesPerScanline&e.code;
3238 <quote><p>
3239 Pitch of the framebuffer in bytes.
3241 </quote>
3243 &s.code;byteOrder&e.code;
3244 <quote><p>
3245 Usually the same as
3246 &s.code;pScrn-&gt;imageByteOrder&e.code;.
3248 </quote>
3250 &s.code;depth&e.code;
3251 <quote><p>
3252 The depth of the framebuffer in this mode.
3254 </quote>
3256 &s.code;bitsPerPixel&e.code;
3257 <quote><p>
3258 The number of bits per pixel in this mode.
3260 </quote>
3262 &s.code;red_mask&nl;
3263 green_mask&nl;
3264 blue_mask&e.code;
3265 <quote><p>
3266 The RGB masks for this mode, if applicable.
3268 </quote>
3270 &s.code;viewportWidth&nl;
3271 viewportHeight&e.code;
3272 <quote><p>
3273 Dimensions of the visible part of the framebuffer.
3274 Usually &s.code;mode-&gt;HDisplay&e.code; and
3275 &s.code;mode-&gt;VDisplay&e.code;.
3277 </quote>
3279 &s.code;xViewportStep&nl;
3280 yViewportStep&e.code;
3281 <quote><p>
3282 The granularity of x and y viewport positions that
3283 the driver supports in this mode.
3285 </quote>
3287 &s.code;maxViewportX&nl;
3288 maxViewportY&e.code;
3289 <quote><p>
3290 The maximum viewport position supported by the
3291 driver in this mode.
3293 </quote>
3295 &s.code;viewportFlags&e.code;
3296 <quote><p>
3297 The following may be OR'd together:
3299 &s.code;DGA_FLIP_IMMEDIATE&e.code;
3300 <quote><p>
3301 The driver supports immediate viewport changes.
3303 </quote>
3304 &s.code;DGA_FLIP_RETRACE&e.code;
3305 <quote<p>
3306 The driver supports viewport changes at retrace.
3308 </quote>
3309 </quote>
3311 &s.code;offset&e.code;
3312 <quote><p>
3313 The offset into the linear framebuffer that corresponds to
3314 pixel (0,0) for this mode.
3316 </quote>
3318 &s.code;address&e.code;
3319 <quote><p>
3320 The virtual address of the framebuffer as mapped by the driver.
3321 This is needed when DGA_PIXMAP_AVAILABLE is set.
3323 </quote>
3325 <verb>
3326 /** The DGAFunctionRec **/
3328 typedef struct {
3329 Bool (*OpenFramebuffer)(
3330 ScrnInfoPtr pScrn,
3331 char **name,
3332 unsigned char **mem,
3333 int *size,
3334 int *offset,
3335 int *extra
3337 void (*CloseFramebuffer)(ScrnInfoPtr pScrn);
3338 Bool (*SetMode)(ScrnInfoPtr pScrn, DGAModePtr pMode);
3339 void (*SetViewport)(ScrnInfoPtr pScrn, int x, int y, int flags);
3340 int (*GetViewport)(ScrnInfoPtr pScrn);
3341 void (*Sync)(ScrnInfoPtr);
3342 void (*FillRect)(
3343 ScrnInfoPtr pScrn,
3344 int x, int y, int w, int h,
3345 unsigned long color
3347 void (*BlitRect)(
3348 ScrnInfoPtr pScrn,
3349 int srcx, int srcy,
3350 int w, int h,
3351 int dstx, int dsty
3353 void (*BlitTransRect)(
3354 ScrnInfoPtr pScrn,
3355 int srcx, int srcy,
3356 int w, int h,
3357 int dstx, int dsty,
3358 unsigned long color
3360 } DGAFunctionRec, *DGAFunctionPtr;
3361 </verb>
3363 </quote>
3365 &s.code;Bool OpenFramebuffer (pScrn, name, mem, size, offset, extra)&e.code;
3366 <quote><p>
3367 &s.code;OpenFramebuffer()&e.code; should pass the client everything
3368 it needs to know to be able to open the framebuffer. These
3369 parameters are OS specific and their meanings are to be interpreted
3370 by an OS specific client library.
3372 &s.code;name&e.code;
3373 <quote><p>
3374 The name of the device to open or &s.code;NULL&e.code; if
3375 there is no special device to open. A &s.code;NULL&e.code;
3376 name tells the client that it should open whatever device
3377 one would usually open to access physical memory.
3379 </quote>
3380 &s.code;mem&e.code;
3381 <quote><p>
3382 The physical address of the start of the framebuffer.
3384 </quote>
3385 &s.code;size&e.code;
3386 <quote><p>
3387 The size of the framebuffer in bytes.
3389 </quote>
3390 &s.code;offset&e.code;
3391 <quote><p>
3392 Any offset into the device, if applicable.
3394 </quote>
3395 &s.code;flags&e.code;
3396 <quote><p>
3397 Any additional information that the client may need.
3398 Currently, only the &s.code;DGA_NEED_ROOT&e.code; flag is
3399 defined.
3401 </quote>
3402 </quote>
3404 &s.code;void CloseFramebuffer (pScrn)&e.code;
3405 <quote><p>
3406 &s.code;CloseFramebuffer()&e.code; merely informs the driver (if it
3407 even cares) that client no longer needs to access the framebuffer
3408 directly. This function is optional.
3410 </quote>
3412 &s.code;Bool SetMode (pScrn, pMode)&e.code;
3413 <quote><p>
3414 &s.code;SetMode()&e.code; tells the driver to initialize the mode
3415 passed to it. If &s.code;pMode&e.code; is &s.code;NULL&e.code;,
3416 then the driver should restore the original pre-DGA mode.
3418 </quote>
3420 &s.code;void SetViewport (pScrn, x, y, flags)&e.code;
3421 <quote><p>
3422 &s.code;SetViewport()&e.code; tells the driver to make the upper
3423 left-hand corner of the visible screen correspond to coordinate
3424 &s.code;(x,y)&e.code; on the framebuffer. &s.code;Flags&e.code;
3425 currently defined are:
3427 &s.code;DGA_FLIP_IMMEDIATE&e.code;
3428 <quote><p>
3429 The viewport change should occur immediately.
3431 </quote>
3432 &s.code;DGA_FLIP_RETRACE&e.code;
3433 <quote><p>
3434 The viewport change should occur at the
3435 vertical retrace, but this function should
3436 return sooner if possible.
3438 </quote>
3439 The &s.code;(x,y)&e.code; locations will be passed as the client
3440 specified them, however, the driver is expected to round these
3441 locations down to the next supported location as specified by the
3442 &s.code;xViewportStep&e.code; and &s.code;yViewportStep&e.code;
3443 for the current mode.
3445 </quote>
3447 &s.code;int GetViewport (pScrn)&e.code;
3448 <quote><p>
3449 &s.code;GetViewport()&e.code; gets the current page flip status.
3450 Set bits in the returned int correspond to viewport change requests
3451 still pending. For instance, set bit zero if the last SetViewport
3452 request is still pending, bit one if the one before that is still
3453 pending, etc.
3455 </quote>
3457 &s.code;void Sync (pScrn)&e.code;
3458 <quote><p>
3459 This function should ensure that any graphics accelerator operations
3460 have finished. This function should not return until the graphics
3461 accelerator is idle.
3463 </quote>
3465 &s.code;void FillRect (pScrn, x, y, w, h, color)&e.code;
3466 <quote><p>
3467 This optional function should fill a rectangle
3468 &s.code;w&nbsp;&times;&nbsp;h&e.code; located at
3469 &s.code;(x,y)&e.code; in the given color.
3471 </quote>
3473 &s.code;void BlitRect (pScrn, srcx, srcy, w, h, dstx, dsty)&e.code;
3474 <quote><p>
3475 This optional function should copy an area
3476 &s.code;w&nbsp;&times;&nbsp;h&e.code; located at
3477 &s.code;(srcx,srcy)&e.code; to location &s.code;(dstx,dsty)&e.code;.
3478 This function will need to handle copy directions as appropriate.
3480 </quote>
3482 &s.code;void BlitTransRect (pScrn, srcx, srcy, w, h, dstx, dsty, color)&e.code;
3483 <quote><p>
3484 This optional function is the same as BlitRect except that pixels
3485 in the source corresponding to the color key &s.code;color&e.code;
3486 should be skipped.
3488 </quote>
3489 </quote>
3491 <sect>The XFree86 X Video Extension (Xv) Device Dependent Layer
3494 XFree86 offers the X Video Extension which allows clients to treat video
3495 as any another primitive and ``Put'' video into drawables. By default,
3496 the extension reports no video adaptors as being available since the
3497 DDX layer has not been initialized. The driver can initialize the DDX
3498 layer by filling out one or more &s.code;XF86VideoAdaptorRecs&e.code;
3499 as described later in this document and passing a list of
3500 &s.code;XF86VideoAdaptorPtr&e.code; pointers to the following function:
3502 <quote>
3503 &s.code;Bool xf86XVScreenInit(
3504 &f.indent;ScreenPtr pScreen,
3505 &f.indent;XF86VideoAdaptorPtr *adaptPtrs,
3506 &f.indent;int num)&e.code;
3507 </quote>
3509 After doing this, the extension will report video adaptors as being
3510 available, providing the data in their respective
3511 &s.code;XF86VideoAdaptorRecs&e.code; was valid.
3512 &s.code;xf86XVScreenInit()&e.code; <em>copies</em> data from the structure
3513 passed to it so the driver may free it after the initialization. At
3514 the moment, the DDX only supports rendering into Window drawables.
3515 Pixmap rendering will be supported after a sufficient survey of suitable
3516 hardware is completed.
3518 The &s.code;XF86VideoAdaptorRec&e.code;:
3520 <quote><p>
3521 <verb>
3522 typedef struct {
3523 unsigned int type;
3524 int flags;
3525 char *name;
3526 int nEncodings;
3527 XF86VideoEncodingPtr pEncodings;
3528 int nFormats;
3529 XF86VideoFormatPtr pFormats;
3530 int nPorts;
3531 DevUnion *pPortPrivates;
3532 int nAttributes;
3533 XF86AttributePtr pAttributes;
3534 int nImages;
3535 XF86ImagePtr pImages;
3536 PutVideoFuncPtr PutVideo;
3537 PutStillFuncPtr PutStill;
3538 GetVideoFuncPtr GetVideo;
3539 GetStillFuncPtr GetStill;
3540 StopVideoFuncPtr StopVideo;
3541 SetPortAttributeFuncPtr SetPortAttribute;
3542 GetPortAttributeFuncPtr GetPortAttribute;
3543 QueryBestSizeFuncPtr QueryBestSize;
3544 PutImageFuncPtr PutImage;
3545 QueryImageAttributesFuncPtr QueryImageAttributes;
3546 } XF86VideoAdaptorRec, *XF86VideoAdaptorPtr;
3547 </verb>
3549 Each adaptor will have its own XF86VideoAdaptorRec. The fields are
3550 as follows:
3552 &s.code;type&e.code;
3553 <quote><p>
3554 This can be any of the following flags OR'd together.
3556 &s.code;XvInputMask&e.code;
3557 &s.code;XvOutputMask&e.code;
3558 <quote><p>
3559 These refer to the target drawable and are similar to a Window's
3560 class. &s.code;XvInputMask&e.code; indicates that the adaptor
3561 can put video into a drawable. &s.code;XvOutputMask&e.code;
3562 indicates that the adaptor can get video from a drawable.
3563 </quote>
3565 &s.code;XvVideoMask&e.code;
3566 &s.code;XvStillMask&e.code;
3567 &s.code;XvImageMask&e.code;
3568 <quote><p>
3569 These indicate that the adaptor supports video, still or
3570 image primitives respectively.
3571 </quote>
3573 &s.code;XvWindowMask&e.code;
3574 &s.code;XvPixmapMask&e.code;
3575 <quote><p>
3576 These indicate the types of drawables the adaptor is capable
3577 of rendering into. At the moment, Pixmap rendering is not
3578 supported and the &s.code;XvPixmapMask&e.code; flag is ignored.
3579 </quote>
3581 </quote>
3583 &s.code;flags&e.code;
3584 <quote><p>
3585 Currently, the following flags are defined:
3587 &s.code;VIDEO_NO_CLIPPING&e.code;
3588 <quote><p>
3589 This indicates that the video adaptor does not support
3590 clipping. The driver will never receive ``Put'' requests
3591 where less than the entire area determined by
3592 &s.code;drw_x&e.code;, &s.code;drw_y&e.code;,
3593 &s.code;drw_w&e.code; and &s.code;drw_h&e.code; is visible.
3594 This flag does not apply to ``Get'' requests. Hardware
3595 that is incapable of clipping ``Gets'' may punt or get
3596 the extents of the clipping region passed to it.
3598 </quote>
3600 &s.code;VIDEO_INVERT_CLIPLIST&e.code;
3601 <quote><p>
3602 This indicates that the video driver requires the clip
3603 list to contain the regions which are obscured rather
3604 than the regions which are are visible.
3606 </quote>
3608 &s.code;VIDEO_OVERLAID_STILLS&e.code;
3609 <quote><p>
3610 Implementing PutStill for hardware that does video as an
3611 overlay can be awkward since it's unclear how long to leave
3612 the video up for. When this flag is set, StopVideo will be
3613 called whenever the destination gets clipped or moved so that
3614 the still can be left up until then.
3616 </quote>
3618 &s.code;VIDEO_OVERLAID_IMAGES&e.code;
3619 <quote><p>
3620 Same as &s.code;VIDEO_OVERLAID_STILLS&e.code; but for images.
3621 </quote>
3623 &s.code;VIDEO_CLIP_TO_VIEWPORT&e.code;
3624 <quote><p>
3625 Indicates that the clip region passed to the driver functions
3626 should be clipped to the visible portion of the screen in the
3627 case where the viewport is smaller than the virtual desktop.
3628 </quote>
3630 </quote>
3632 &s.code;name&e.code;
3633 <quote><p>
3634 The name of the adaptor.
3636 </quote>
3638 &s.code;nEncodings&nl;
3639 pEncodings&e.code;
3640 <quote><p>
3641 The number of encodings the adaptor is capable of and pointer
3642 to the &s.code;XF86VideoEncodingRec&e.code; array. The
3643 &s.code;XF86VideoEncodingRec&e.code; is described later on.
3644 For drivers that only support XvImages there should be an encoding
3645 named "XV_IMAGE" and the width and height should specify
3646 the maximum size source image supported.
3648 </quote>
3650 &s.code;nFormats&nl;
3651 pFormats&e.code;
3652 <quote><p>
3653 The number of formats the adaptor is capable of and pointer to
3654 the &s.code;XF86VideoFormatRec&e.code; array. The
3655 &s.code;XF86VideoFormatRec&e.code; is described later on.
3657 </quote>
3659 &s.code;nPorts&nl;
3660 pPortPrivates&e.code;
3661 <quote><p>
3662 The number of ports is the number of separate data streams which
3663 the adaptor can handle simultaneously. If you have more than
3664 one port, the adaptor is expected to be able to render into more
3665 than one window at a time. &s.code;pPortPrivates&e.code; is
3666 an array of pointers or ints - one for each port. A port's
3667 private data will be passed to the driver any time the port is
3668 requested to do something like put the video or stop the video.
3669 In the case where there may be many ports, this enables the
3670 driver to know which port the request is intended for. Most
3671 commonly, this will contain a pointer to the data structure
3672 containing information about the port. In Xv, all ports on
3673 a particular adaptor are expected to be identical in their
3674 functionality.
3676 </quote>
3678 &s.code;nAttributes&nl;
3679 pAttributes&e.code;
3680 <quote><p>
3681 The number of attributes recognized by the adaptor and a pointer to
3682 the array of &s.code;XF86AttributeRecs&e.code;. The
3683 &s.code;XF86AttributeRec&e.code; is described later on.
3685 </quote>
3687 &s.code;nImages&nl;
3688 pImages&e.code;
3689 <quote><p>
3690 The number of &s.code;XF86ImageRecs&e.code; supported by the adaptor
3691 and a pointer to the array of &s.code;XF86ImageRecs&e.code;. The
3692 &s.code;XF86ImageRec&e.code; is described later on.
3694 </quote>
3697 &s.code;PutVideo PutStill GetVideo GetStill StopVideo
3698 SetPortAttribute GetPortAttribute QueryBestSize PutImage
3699 QueryImageAttributes&e.code;
3700 <quote><p>
3701 These functions define the DDX-&gt;driver interface. In each
3702 case, the pointer &s.code;data&e.code; is passed to the driver.
3703 This is the port private for that port as described above. All
3704 fields are required except under the following conditions:
3706 <enum>
3707 <item>&s.code;PutVideo&e.code;, &s.code;PutStill&e.code; and
3708 the image routines &s.code;PutImage&e.code; and
3709 &s.code;QueryImageAttributes&e.code; are not required when the
3710 adaptor type does not contain &s.code;XvInputMask&e.code;.
3712 <item>&s.code;GetVideo&e.code; and &s.code;GetStill&e.code;
3713 are not required when the adaptor type does not contain
3714 &s.code;XvOutputMask&e.code;.
3716 <item>&s.code;GetVideo&e.code; and &s.code;PutVideo&e.code;
3717 are not required when the adaptor type does not contain
3718 &s.code;XvVideoMask&e.code;.
3720 <item>&s.code;GetStill&e.code; and &s.code;PutStill&e.code;
3721 are not required when the adaptor type does not contain
3722 &s.code;XvStillMask&e.code;.
3724 <item>&s.code;PutImage&e.code; and &s.code;QueryImageAttributes&e.code;
3725 are not required when the adaptor type does not contain
3726 &s.code;XvImageMask&e.code;.
3728 </enum>
3730 With the exception of &s.code;QueryImageAttributes&e.code;, these
3731 functions should return &s.code;Success&e.code; if the operation was
3732 completed successfully. They can return &s.code;XvBadAlloc&e.code;
3733 otherwise. &s.code;QueryImageAttributes&e.code; returns the size
3734 of the XvImage queried.
3736 If the &s.code;VIDEO_NO_CLIPPING&e.code;
3737 flag is set, the &s.code;clipBoxes&e.code; may be ignored by
3738 the driver. &s.code;ClipBoxes&e.code; is an &s.code;X-Y&e.code;
3739 banded region identical to those used throughout the server.
3740 The clipBoxes represent the visible portions of the area determined
3741 by &s.code;drw_x&e.code;, &s.code;drw_y&e.code;,
3742 &s.code;drw_w&e.code; and &s.code;drw_h&e.code; in the Get/Put
3743 function. The boxes are in screen coordinates, are guaranteed
3744 not to overlap and an empty region will never be passed.
3745 If the driver has specified &s.code;VIDEO_INVERT_CLIPLIST&e.code;,
3746 &s.code;clipBoxes&e.code; will indicate the areas of the primitive
3747 which are obscured rather than the areas visible.
3749 </quote>
3751 &s.code;typedef int (* PutVideoFuncPtr)( ScrnInfoPtr pScrn,
3752 &f.indent;short vid_x, short vid_y, short drw_x, short drw_y,
3753 &f.indent;short vid_w, short vid_h, short drw_w, short drw_h,
3754 &f.indent;RegionPtr clipBoxes, pointer data )&e.code;
3755 <quote><p>
3756 This indicates that the driver should take a subsection
3757 &s.code;vid_w&e.code; by &s.code;vid_h&e.code; at location
3758 &s.code;(vid_x,vid_y)&e.code; from the video stream and direct
3759 it into the rectangle &s.code;drw_w&e.code; by &s.code;drw_h&e.code;
3760 at location &s.code;(drw_x,drw_y)&e.code; on the screen, scaling as
3761 necessary. Due to the large variations in capabilities of
3762 the various hardware expected to be used with this extension,
3763 it is not expected that all hardware will be able to do this
3764 exactly as described. In that case the driver should just do
3765 ``the best it can,'' scaling as closely to the target rectangle
3766 as it can without rendering outside of it. In the worst case,
3767 the driver can opt to just not turn on the video.
3769 </quote>
3771 &s.code;typedef int (* PutStillFuncPtr)( ScrnInfoPtr pScrn,
3772 &f.indent;short vid_x, short vid_y, short drw_x, short drw_y,
3773 &f.indent;short vid_w, short vid_h, short drw_w, short drw_h,
3774 &f.indent;RegionPtr clipBoxes, pointer data )&e.code;
3775 <quote><p>
3776 This is same as &s.code;PutVideo&e.code; except that the driver
3777 should place only one frame from the stream on the screen.
3779 </quote>
3781 &s.code;typedef int (* GetVideoFuncPtr)( ScrnInfoPtr pScrn,
3782 &f.indent;short vid_x, short vid_y, short drw_x, short drw_y,
3783 &f.indent;short vid_w, short vid_h, short drw_w, short drw_h,
3784 &f.indent;RegionPtr clipBoxes, pointer data )&e.code;
3785 <quote><p>
3786 This is same as &s.code;PutVideo&e.code; except that the driver
3787 gets video from the screen and outputs it. The driver should
3788 do the best it can to get the requested dimensions correct
3789 without reading from an area larger than requested.
3791 </quote>
3793 &s.code;typedef int (* GetStillFuncPtr)( ScrnInfoPtr pScrn,
3794 &f.indent;short vid_x, short vid_y, short drw_x, short drw_y,
3795 &f.indent;short vid_w, short vid_h, short drw_w, short drw_h,
3796 &f.indent;RegionPtr clipBoxes, pointer data )&e.code;
3797 <quote><p>
3798 This is the same as &s.code;GetVideo&e.code; except that the
3799 driver should place only one frame from the screen into the
3800 output stream.
3802 </quote>
3804 &s.code;typedef void (* StopVideoFuncPtr)(ScrnInfoPtr pScrn,
3805 &f.indent;pointer data, Bool cleanup)&e.code;
3806 <quote><p>
3807 This indicates the driver should stop displaying the video.
3808 This is used to stop both input and output video. The
3809 &s.code;cleanup&e.code; field indicates that the video is
3810 being stopped because the client requested it to stop or
3811 because the server is exiting the current VT. In that case
3812 the driver should deallocate any offscreen memory areas (if
3813 there are any) being used to put the video to the screen. If
3814 &s.code;cleanup&e.code; is not set, the video is being stopped
3815 temporarily due to clipping or moving of the window, etc...
3816 and video will likely be restarted soon so the driver should
3817 not deallocate any offscreen areas associated with that port.
3819 </quote>
3820 &s.code;typedef int (* SetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
3821 &f.indent;Atom attribute,INT32 value, pointer data)&e.code;
3823 &s.code;typedef int (* GetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
3824 &f.indent;Atom attribute,INT32 *value, pointer data)&e.code;
3826 <quote><p>
3827 A port may have particular attributes such as hue,
3828 saturation, brightness or contrast. Xv clients set and
3829 get these attribute values by sending attribute strings
3830 (Atoms) to the server. Such requests end up at these
3831 driver functions. It is recommended that the driver provide
3832 at least the following attributes mentioned in the Xv client
3833 library docs:
3834 <quote>
3835 &s.code;XV_ENCODING&nl;
3836 XV_HUE&nl;
3837 XV_SATURATION&nl;
3838 XV_BRIGHTNESS&nl;
3839 XV_CONTRAST&e.code;
3840 </quote>
3841 but the driver may recognize as many atoms as it wishes. If
3842 a requested attribute is unknown by the driver it should return
3843 &s.code;BadMatch&e.code;. &s.code;XV_ENCODING&e.code; is the
3844 attribute intended to let the client specify which video
3845 encoding the particular port should be using (see the description
3846 of &s.code;XF86VideoEncodingRec&e.code; below). If the
3847 requested encoding is unsupported, the driver should return
3848 &s.code;XvBadEncoding&e.code;. If the value lies outside the
3849 advertised range &s.code;BadValue&e.code; may be returned.
3850 &s.code;Success&e.code; should be returned otherwise.
3852 </quote>
3854 &s.code;typedef void (* QueryBestSizeFuncPtr)(ScrnInfoPtr pScrn,
3855 &f.indent;Bool motion, short vid_w, short vid_h,
3856 &f.indent;short drw_w, short drw_h,
3857 &f.indent;unsigned int *p_w, unsigned int *p_h, pointer data)&e.code;
3858 <quote><p>
3859 &s.code;QueryBestSize&e.code; provides the client with a way
3860 to query what the destination dimensions would end up being
3861 if they were to request that an area
3862 &s.code;vid_w&e.code by &s.code;vid_h&e.code; from the video
3863 stream be scaled to rectangle of
3864 &s.code;drw_w&e.code; by &s.code;drw_h&e.code; on the screen.
3865 Since it is not expected that all hardware will be able to
3866 get the target dimensions exactly, it is important that the
3867 driver provide this function.
3869 </quote>
3871 &s.code;typedef int (* PutImageFuncPtr)( ScrnInfoPtr pScrn,
3872 &f.indent;short src_x, short src_y, short drw_x, short drw_y,
3873 &f.indent;short src_w, short src_h, short drw_w, short drw_h,
3874 &f.indent;int image, char *buf, short width, short height,
3875 &f.indent;Bool sync, RegionPtr clipBoxes, pointer data )&e.code;
3876 <quote><p>
3877 This is similar to &s.code;PutStill&e.code; except that the
3878 source of the video is not a port but the data stored in a system
3879 memory buffer at &s.code;buf&e.code;. The data is in the format
3880 indicated by the &s.code;image&e.code; descriptor and represents a
3881 source of size &s.code;width&e.code; by &s.code;height&e.code;.
3882 If &s.code;sync&e.code; is TRUE the driver should not return
3883 from this function until it is through reading the data
3884 from &s.code;buf&e.code;. Returning when &s.code;sync&e.code;
3885 is TRUE indicates that it is safe for the data at &s.code;buf&e.code;
3886 to be replaced, freed, or modified.
3888 </quote>
3890 &s.code;typedef int (* QueryImageAttributesFuncPtr)( ScrnInfoPtr pScrn,
3891 &f.indent;int image, short *width, short *height,
3892 &f.indent;int *pitches, int *offsets)&e.code;
3893 <quote><p>
3894 This function is called to let the driver specify how data for
3895 a particular &s.code;image&e.code; of size &s.code;width&e.code;
3896 by &s.code;height&e.code; should be stored. Sometimes only
3897 the size and corrected width and height are needed. In that
3898 case &s.code;pitches&e.code; and &s.code;offsets&e.code; are
3899 NULL. The size of the memory required for the image is returned
3900 by this function. The &s.code;width&e.code; and
3901 &s.code;height&e.code; of the requested image can be altered by
3902 the driver to reflect format limitations (such as component
3903 sampling periods that are larger than one). If
3904 &s.code;pitches&e.code; and &s.code;offsets&e.code; are not NULL,
3905 these will be arrays with as many elements in them as there
3906 are planes in the &s.code;image&e.code; format. The driver
3907 should specify the pitch (in bytes) of each scanline in the
3908 particular plane as well as the offset to that plane (in bytes)
3909 from the beginning of the image.
3911 </quote>
3913 </quote>
3915 The XF86VideoEncodingRec:
3916 <quote><p>
3917 <verb>
3918 typedef struct {
3919 int id;
3920 char *name;
3921 unsigned short width, height;
3922 XvRationalRec rate;
3923 } XF86VideoEncodingRec, *XF86VideoEncodingPtr;
3925 </verb>
3926 The &s.code;XF86VideoEncodingRec&e.code; specifies what encodings
3927 the adaptor can support. Most of this data is just informational
3928 and for the client's benefit, and is what will be reported by
3929 &s.code;XvQueryEncodings&e.code;. The &s.code;id&e.code; field is
3930 expected to be a unique identifier to allow the client to request a
3931 certain encoding via the &s.code;XV_ENCODING&e.code; attribute string.
3933 </quote>
3935 The XF86VideoFormatRec:
3937 <quote><p>
3938 <verb>
3939 typedef struct {
3940 char depth;
3941 short class;
3942 } XF86VideoFormatRec, *XF86VideoFormatPtr;
3943 </verb>
3945 This specifies what visuals the video is viewable in.
3946 &s.code;depth&e.code; is the depth of the visual (not bpp).
3947 &s.code;class&e.code; is the visual class such as
3948 &s.code;TrueColor&e.code;, &s.code;DirectColor&e.code; or
3949 &s.code;PseudoColor&e.code;. Initialization of an adaptor will fail
3950 if none of the visuals on that screen are supported.
3952 </quote>
3954 The XF86AttributeRec:
3956 <quote><p>
3957 <verb>
3958 typedef struct {
3959 int flags;
3960 int min_value;
3961 int max_value;
3962 char *name;
3963 } XF86AttributeListRec, *XF86AttributeListPtr;
3965 </verb>
3967 Each adaptor may have an array of these advertising the attributes
3968 for its ports. Currently defined flags are &s.code;XvGettable&e.code;
3969 and &s.code;XvSettable&e.code; which may be OR'd together indicating that
3970 attribute is ``gettable'' or ``settable'' by the client. The
3971 &s.code;min&e.code; and &s.code;max&e.code; field specify the valid range
3972 for the value. &s.code;Name&e.code; is a text string describing the
3973 attribute by name.
3975 </quote>
3977 The XF86ImageRec:
3979 <quote><p>
3980 <verb>
3981 typedef struct {
3982 int id;
3983 int type;
3984 int byte_order;
3985 char guid[16];
3986 int bits_per_pixel;
3987 int format;
3988 int num_planes;
3990 /* for RGB formats */
3991 int depth;
3992 unsigned int red_mask;
3993 unsigned int green_mask;
3994 unsigned int blue_mask;
3996 /* for YUV formats */
3997 unsigned int y_sample_bits;
3998 unsigned int u_sample_bits;
3999 unsigned int v_sample_bits;
4000 unsigned int horz_y_period;
4001 unsigned int horz_u_period;
4002 unsigned int horz_v_period;
4003 unsigned int vert_y_period;
4004 unsigned int vert_u_period;
4005 unsigned int vert_v_period;
4006 char component_order[32];
4007 int scanline_order;
4008 } XF86ImageRec, *XF86ImagePtr;
4009 </verb>
4011 XF86ImageRec describes how video source data is laid out in memory.
4012 The fields are as follows:
4014 &s.code;id&e.code;
4015 <quote><p>
4016 This is a unique descriptor for the format. It is often good to
4017 set this value to the FOURCC for the format when applicable.
4018 </quote>
4020 &s.code;type&e.code;
4021 <quote><p>
4022 This is &s.code;XvRGB&e.code; or &s.code;XvYUV&e.code;.
4023 </quote>
4025 &s.code;byte_order&e.code;
4026 <quote><p>
4027 This is &s.code;LSBFirst&e.code; or &s.code;MSBFirst&e.code;.
4028 </quote>
4030 &s.code;guid&e.code;
4031 <quote><p>
4032 This is the Globally Unique IDentifier for the format. When
4033 not applicable, all characters should be NULL.
4034 </quote>
4036 &s.code;bits_per_pixel&e.code;
4037 <quote><p>
4038 The number of bits taken up (but not necessarily used) by each
4039 pixel. Note that for some planar formats which have fractional
4040 bits per pixel (such as IF09) this number may be rounded _down_.
4041 </quote>
4043 &s.code;format&e.code;
4044 <quote><p>
4045 This is &s.code;XvPlanar&e.code; or &s.code;XvPacked&e.code;.
4046 </quote>
4048 &s.code;num_planes&e.code;
4049 <quote><p>
4050 The number of planes in planar formats. This should be set to
4051 one for packed formats.
4052 </quote>
4054 &s.code;depth&e.code;
4055 <quote><p>
4056 The significant bits per pixel in RGB formats (analgous to the
4057 depth of a pixmap format).
4058 </quote>
4060 &s.code;red_mask&e.code;
4061 &s.code;green_mask&e.code;
4062 &s.code;blue_mask&e.code;
4063 <quote><p>
4064 The red, green and blue bitmasks for packed RGB formats.
4065 </quote>
4067 &s.code;y_sample_bits&e.code;
4068 &s.code;u_sample_bits&e.code;
4069 &s.code;v_sample_bits&e.code;
4070 <quote><p>
4071 The y, u and v sample sizes (in bits).
4072 </quote>
4074 &s.code;horz_y_period&e.code;
4075 &s.code;horz_u_period&e.code;
4076 &s.code;horz_v_period&e.code;
4077 <quote><p>
4078 The y, u and v sampling periods in the horizontal direction.
4079 </quote>
4081 &s.code;vert_y_period&e.code;
4082 &s.code;vert_u_period&e.code;
4083 &s.code;vert_v_period&e.code;
4084 <quote><p>
4085 The y, u and v sampling periods in the vertical direction.
4086 </quote>
4088 &s.code;component_order&e.code;
4089 <quote><p>
4090 Uppercase ascii characters representing the order that
4091 samples are stored within packed formats. For planar formats
4092 this represents the ordering of the planes. Unused characters
4093 in the 32 byte string should be set to NULL.
4094 </quote>
4096 &s.code;scanline_order&e.code;
4097 <quote><p>
4098 This is &s.code;XvTopToBottom&e.code; or &s.code;XvBottomToTop&e.code;.
4099 </quote>
4101 Since some formats (particular some planar YUV formats) may not
4102 be completely defined by the parameters above, the guid, when
4103 available, should provide the most accurate description of the
4104 format.
4106 </quote>
4108 <sect>The Loader
4111 This section describes the interfaces to the module loader. The loader
4112 interfaces can be divided into two groups: those that are only available to
4113 the XFree86 common layer, and those that are also available to modules.
4115 <sect1>Loader Overview
4118 The loader is capable of loading modules in a range of object formats,
4119 and knowledge of these formats is built in to the loader. Knowledge of
4120 new object formats can be added to the loader in a straightforward
4121 manner. This makes it possible to provide OS-independent modules (for
4122 a given CPU architecture type). In addition to this, the loader can
4123 load modules via the OS-provided &s.code;dlopen(3)&e.code; service where
4124 available. Such modules are not platform independent, and the semantics
4125 of &s.code;dlopen()&e.code; on most systems results in significant
4126 limitations in the use of modules of this type. Support for
4127 &s.code;dlopen()&e.code; modules in the loader is primarily for
4128 experimental and development purposes.
4130 Symbols exported by the loader (on behalf of the core X server) to
4131 modules are determined at compile time. Only those symbols explicitly
4132 exported are available to modules. All external symbols of loaded
4133 modules are exported to other modules, and to the core X server. The
4134 loader can be requested to check for unresolved symbols at any time,
4135 and the action to be taken for unresolved symbols can be controlled by
4136 the caller of the loader. Typically the caller identifies which symbols
4137 can safely remain unresolved and which cannot.
4139 NOTE: Now that ISO-C allows pointers to functions and pointers to data to
4140 have different internal representations, some of the following interfaces
4141 will need to be revisited.
4143 <sect1>Semi-private Loader Interface
4146 The following is the semi-private loader interface that is available to the
4147 XFree86 common layer.
4149 <quote><p>
4150 &s.code;void LoaderInit(void)&e.code;
4151 <quote><p>
4152 The &s.code;LoaderInit()&e.code; function initialises the loader,
4153 and it must be called once before calling any other loader functions.
4154 This function initialises the tables of exported symbols, and anything
4155 else that might need to be initialised.
4157 </quote>
4159 &s.code;void LoaderSetPath(const char *path)&e.code;
4160 <quote><p>
4161 The &s.code;LoaderSetPath()&e.code; function initialises a default
4162 module search path. This must be called if calls to other functions
4163 are to be made without explicitly specifying a module search path.
4164 The search path &s.code;path&e.code; must be a string of one or more
4165 comma separated absolute paths. Modules are expected to be located
4166 below these paths, possibly in subdirectories of these paths.
4168 </quote>
4170 &s.code;pointer LoadModule(const char *module, const char *path,
4171 &f.indent;const char **subdirlist, const char **patternlist,
4172 &f.indent;pointer options, const XF86ModReqInfo * modreq,
4173 &f.indent;int *errmaj, int *errmin)&e.code;
4174 <quote><p>
4175 The &s.code;LoadModule()&e.code; function loads the module called
4176 &s.code;module&e.code;. The return value is a module handle, and
4177 may be used in future calls to the loader that require a reference
4178 to a loaded module. The module name &s.code;module&e.code; is
4179 normally the module's canonical name, which doesn't contain any
4180 directory path information, or any object/library file prefixes of
4181 suffixes. Currently a full pathname and/or filename is also accepted.
4182 This might change. The other parameters are:
4184 &s.code;path&e.code;
4185 <quote><p>
4186 An optional comma-separated list of module search paths.
4187 When &s.code;NULL&e.code;, the default search path is used.
4189 </quote>
4191 &s.code;subdirlist&e.code;
4192 <quote><p>
4193 An optional &s.code;NULL&e.code; terminated list of
4194 subdirectories to search. When &s.code;NULL&e.code;,
4195 the default built-in list is used (refer to
4196 &s.code;stdSubdirs&e.code; in &s.code;loadmod.c&e.code;).
4197 The default list is also substituted for entries in
4198 &s.code;subdirlist&e.code; with the value
4199 &s.code;DEFAULT_LIST&e.code;. This makes is possible
4200 to augment the default list instead of replacing it.
4201 Subdir elements must be relative, and must not contain
4202 &s.code;".."&e.code;. If any violate this requirement,
4203 the load fails.
4205 </quote>
4207 &s.code;patternlist&e.code;
4208 <quote><p>
4209 An optional &s.code;NULL&e.code; terminated list of
4210 POSIX regular expressions used to connect module
4211 filenames with canonical module names. Each regex
4212 should contain exactly one subexpression that corresponds
4213 to the canonical module name. When &s.code;NULL&e.code;,
4214 the default built-in list is used (refer to
4215 &s.code;stdPatterns&e.code; in
4216 &s.code;loadmod.c&e.code;). The default list is also
4217 substituted for entries in &s.code;patternlist&e.code;
4218 with the value &s.code;DEFAULT_LIST&e.code;. This
4219 makes it possible to augment the default list instead
4220 of replacing it.
4222 </quote>
4224 &s.code;options&e.code;
4225 <quote><p>
4226 An optional parameter that is passed to the newly
4227 loaded module's &s.code;SetupProc&e.code; function
4228 (if it has one). This argument is normally a
4229 &s.code;NULL&e.code; terminated list of
4230 &s.code;Options&e.code;, and must be interpreted that
4231 way by modules loaded directly by the XFree86 common
4232 layer. However, it may be used for application-specific
4233 parameter passing in other situations.
4235 When loading ``external'' modules (modules that don't
4236 have the standard entry point, for example a
4237 special shared library) the options parameter can be
4238 set to &s.code;EXTERN_MODULE&e.code; to tell the
4239 loader not to reject the module when it doesn't find
4240 the standard entry point.
4242 </quote>
4244 &s.code;modreq&e.code;
4245 <quote><p>
4246 An optional &s.code;XF86ModReqInfo*&e.code; containing
4247 version/ABI/vendor information to requirements to
4248 check the newly loaded module against. The main
4249 purpose of this is to allow the loader to verify that
4250 a module of the correct type/version before running
4251 its &s.code;SetupProc&e.code; function.
4253 The &s.code;XF86ModReqInfo&e.code; struct is defined
4254 as follows:
4255 <verb>
4256 typedef struct {
4257 CARD8 majorversion; /* MAJOR_UNSPEC */
4258 CARD8 minorversion; /* MINOR_UNSPEC */
4259 CARD16 patchlevel; /* PATCH_UNSPEC */
4260 const char * abiclass; /* ABI_CLASS_NONE */
4261 CARD32 abiversion; /* ABI_VERS_UNSPEC */
4262 const char * moduleclass; /* MOD_CLASS_NONE */
4263 } XF86ModReqInfo;
4264 </verb>
4266 The information here is compared against the equivalent
4267 information in the module's
4268 &s.code;XF86ModuleVersionInfo&e.code; record (which
4269 is described below). The values in comments above
4270 indicate ``don't care'' settings for each of the fields.
4271 The comparisons made are as follows:
4273 &s.code;majorversion&e.code;
4274 <quote><p>
4275 Must match the module's majorversion
4276 exactly.
4278 </quote>
4279 &s.code;minorversion&e.code;
4280 <quote><p>
4281 The module's minor version must be
4282 no less than this value. This
4283 comparison is only made if
4284 &s.code;majorversion&e.code; is
4285 specified and matches.
4287 </quote>
4288 &s.code;patchlevel&e.code;
4289 <quote><p>
4290 The module's patchlevel must be no
4291 less than this value. This comparison
4292 is only made if
4293 &s.code;minorversion&e.code; is
4294 specified and matches.
4296 </quote>
4297 &s.code;abiclass&e.code;
4298 <quote><p>
4299 String must match the module's abiclass
4300 string.
4302 </quote>
4303 &s.code;abiversion&e.code;
4304 <quote><p>
4305 Must be consistent with the module's
4306 abiversion (major equal, minor no
4307 older).
4309 </quote>
4310 &s.code;moduleclass&e.code;
4311 <quote><p>
4312 String must match the module's
4313 moduleclass string.
4315 </quote>
4317 </quote>
4319 &s.code;errmaj&e.code;
4320 <quote><p>
4321 An optional pointer to a variable holding the major
4322 part or the error code. When provided,
4323 &s.code;*errmaj&e.code; is filled in when
4324 &s.code;LoadModule()&e.code; fails.
4326 </quote>
4328 &s.code;errmin&e.code;
4329 <quote><p>
4330 Like &s.code;errmaj&e.code;, but for the minor part
4331 of the error code.
4333 </quote>
4335 </quote>
4337 &s.code;void UnloadModule(pointer mod)&e.code;
4338 <quote><p>
4339 This function unloads the module referred to by the handle mod.
4340 All child modules are also unloaded recursively. This function must
4341 not be used to directly unload modules that are child modules (i.e.,
4342 those that have been loaded with the &s.code;LoadSubModule()&e.code;
4343 described below).
4345 </quote>
4346 </quote>
4348 <sect1>Module Requirements
4351 Modules must provide information about themselves to the loader, and
4352 may optionally provide entry points for "setup" and "teardown" functions
4353 (those two functions are referred to here as &s.code;SetupProc&e.code;
4354 and &s.code;TearDownProc&e.code;).
4356 The module information is contained in the
4357 &s.code;XF86ModuleVersionInfo&e.code; struct, which is defined as follows:
4359 <quote><p><verb>
4360 typedef struct {
4361 const char * modname; /* name of module, e.g. "foo" */
4362 const char * vendor; /* vendor specific string */
4363 CARD32 _modinfo1_; /* constant MODINFOSTRING1/2 to find */
4364 CARD32 _modinfo2_; /* infoarea with a binary editor/sign tool */
4365 CARD32 xf86version; /* contains XF86_VERSION_CURRENT */
4366 CARD8 majorversion; /* module-specific major version */
4367 CARD8 minorversion; /* module-specific minor version */
4368 CARD16 patchlevel; /* module-specific patch level */
4369 const char * abiclass; /* ABI class that the module uses */
4370 CARD32 abiversion; /* ABI version */
4371 const char * moduleclass; /* module class */
4372 CARD32 checksum[4]; /* contains a digital signature of the */
4373 /* version info structure */
4374 } XF86ModuleVersionInfo;
4375 </verb>
4377 The fields are used as follows:
4379 &s.code;modname&e.code;
4380 <quote><p>
4381 The module's name. This field is currently only for
4382 informational purposes, but the loader may be modified
4383 in future to require it to match the module's canonical
4384 name.
4386 </quote>
4388 &s.code;vendor&e.code;
4389 <quote><p>
4390 The module vendor. This field is for informational purposes
4391 only.
4393 </quote>
4395 &s.code;_modinfo1_&e.code;
4396 <quote><p>
4397 This field holds the first part of a signature that can
4398 be used to locate this structure in the binary. It should
4399 always be initialised to &s.code;MODINFOSTRING1&e.code;.
4401 </quote>
4403 &s.code;_modinfo2_&e.code;
4404 <quote><p>
4405 This field holds the second part of a signature that can
4406 be used to locate this structure in the binary. It should
4407 always be initialised to &s.code;MODINFOSTRING2&e.code;.
4409 </quote>
4411 &s.code;xf86version&e.code;
4412 <quote><p>
4413 The XFree86 version against which the module was compiled.
4414 This is mostly for informational/diagnostic purposes. It
4415 should be initialised to &s.code;XF86_VERSION_CURRENT&e.code;, which is
4416 defined in &s.code;xf86Version.h&e.code;.
4418 </quote>
4420 &s.code;majorversion&e.code;
4421 <quote><p>
4422 The module-specific major version. For modules where this
4423 version is used for more than simply informational
4424 purposes, the major version should only change (be
4425 incremented) when ABI incompatibilities are introduced,
4426 or ABI components are removed.
4428 </quote>
4430 &s.code;minorversion&e.code;
4431 <quote><p>
4432 The module-specific minor version. For modules where this
4433 version is used for more than simply informational
4434 purposes, the minor version should only change (be
4435 incremented) when ABI additions are made in a backward
4436 compatible way. It should be reset to zero when the major
4437 version is increased.
4439 </quote>
4441 &s.code;patchlevel&e.code;
4442 <quote><p>
4443 The module-specific patch level. The patch level should
4444 increase with new revisions of the module where there
4445 are no ABI changes, and it should be reset to zero when
4446 the minor version is increased.
4448 </quote>
4450 &s.code;abiclass&e.code;
4451 <quote><p>
4452 The ABI class that the module requires. The class is
4453 specified as a string for easy extensibility. It should
4454 indicate which (if any) of the X server's built-in ABI
4455 classes that the module relies on, or a third-party ABI
4456 if appropriate. Built-in ABI classes currently defined are:
4458 <quote>
4459 &s.code;ABI_CLASS_NONE&e.code;
4460 <quote>no class</quote>
4461 &s.code;ABI_CLASS_ANSIC&e.code;
4462 <quote>only requires the ANSI C interfaces</quote>
4463 &s.code;ABI_CLASS_VIDEODRV&e.code;
4464 <quote>requires the video driver ABI</quote>
4465 &s.code;ABI_CLASS_XINPUT&e.code;
4466 <quote>requires the XInput driver ABI</quote>
4467 &s.code;ABI_CLASS_EXTENSION&e.code;
4468 <quote>requires the extension module ABI</quote>
4469 &s.code;ABI_CLASS_FONT&e.code;
4470 <quote>requires the font module ABI</quote>
4471 </quote>
4473 </quote>
4475 &s.code;abiversion&e.code;
4476 <quote><p>
4477 The version of abiclass that the module requires. The
4478 version consists of major and minor components. The
4479 major version must match and the minor version must be
4480 no newer than that provided by the server or parent
4481 module. Version identifiers for the built-in classes
4482 currently defined are:
4484 <quote>
4485 &s.code;ABI_ANSIC_VERSION&nl;
4486 ABI_VIDEODRV_VERSION&nl;
4487 ABI_XINPUT_VERSION&nl;
4488 ABI_EXTENSION_VERSION&nl;
4489 ABI_FONT_VERSION&e.code;
4490 </quote>
4492 </quote>
4494 &s.code;moduleclass&e.code;
4495 <quote><p>
4496 This is similar to the abiclass field, except that it
4497 defines the type of module rather than the ABI it
4498 requires. For example, although all video drivers require
4499 the video driver ABI, not all modules that require the
4500 video driver ABI are video drivers. This distinction
4501 can be made with the moduleclass. Currently pre-defined
4502 module classes are:
4504 <quote>
4505 &s.code;MOD_CLASS_NONE&nl;
4506 MOD_CLASS_VIDEODRV&nl;
4507 MOD_CLASS_XINPUT&nl;
4508 MOD_CLASS_FONT&nl;
4509 MOD_CLASS_EXTENSION&e.code;
4510 </quote>
4512 </quote>
4514 &s.code;checksum&e.code;
4515 <quote><p>
4516 Not currently used.
4518 </quote>
4520 </quote>
4522 The module version information, and the optional &s.code;SetupProc&e.code;
4523 and &s.code;TearDownProc&e.code; entry points are found by the loader
4524 by locating a data object in the module called "modnameModuleData",
4525 where "modname" is the canonical name of the module. Modules must
4526 contain such a data object, and it must be declared with global scope,
4527 be compile-time initialised, and is of the following type:
4529 <quote>
4530 <verb>
4531 typedef struct {
4532 XF86ModuleVersionInfo * vers;
4533 ModuleSetupProc setup;
4534 ModuleTearDownProc teardown;
4535 } XF86ModuleData;
4536 </verb>
4537 </quote>
4539 The vers parameter must be initialised to a pointer to a correctly
4540 initialised &s.code;XF86ModuleVersionInfo&e.code; struct. The other
4541 two parameter are optional, and should be initialised to
4542 &s.code;NULL&e.code; when not required. The other parameters are defined
4545 <quote><p>
4546 &s.code;typedef pointer (*ModuleSetupProc)(pointer, pointer, int *, int *)&e.code;
4548 &s.code;typedef void (*ModuleTearDownProc)(pointer)&e.code;
4551 &s.code;pointer SetupProc(pointer module, pointer options,
4552 &f.indent;int *errmaj, int *errmin)&e.code;
4553 <quote><p>
4554 When defined, this function is called by the loader after successfully
4555 loading a module. module is a handle for the newly loaded module,
4556 and maybe used by the &s.code;SetupProc&e.code; if it calls other
4557 loader functions that require a reference to it. The remaining
4558 arguments are those that were passed to the
4559 &s.code;LoadModule()&e.code; (or &s.code;LoadSubModule()&e.code;),
4560 and are described above. When the &s.code;SetupProc&e.code; is
4561 successful it must return a non-&s.code;NULL&e.code; value. The
4562 loader checks this, and if it is &s.code;NULL&e.code; it unloads
4563 the module and reports the failure to the caller of
4564 &s.code;LoadModule()&e.code;. If the &s.code;SetupProc&e.code;
4565 does things that need to be undone when the module is unloaded,
4566 it should define a &s.code;TearDownProc&e.code;, and return a
4567 pointer that the &s.code;TearDownProc&e.code; can use to undo what
4568 has been done.
4570 When a module is loaded multiple times, the &s.code;SetupProc&e.code;
4571 is called once for each time it is loaded.
4573 </quote>
4575 &s.code;void TearDownProc(pointer tearDownData)&e.code;
4576 <quote><p>
4577 When defined, this function is called when the loader unloads a
4578 module. The &s.code;tearDownData&e.code; parameter is the return
4579 value of the &s.code;SetupProc()&e.code; that was called when the
4580 module was loaded. The purpose of this function is to clean up
4581 before the module is unloaded (for example, by freeing allocated
4582 resources).
4584 </quote>
4585 </quote>
4587 <sect1>Public Loader Interface
4590 The following is the Loader interface that is available to any part of
4591 the server, and may also be used from within modules.
4593 <quote><p>
4594 &s.code;pointer LoadSubModule(pointer parent, const char *module,
4595 &f.indent;const char **subdirlist, const char **patternlist,
4596 &f.indent;pointer options, const XF86ModReqInfo * modreq,
4597 &f.indent;int *errmaj, int *errmin)&e.code;
4598 <quote><p>
4599 This function is like the &s.code;LoadModule()&e.code; function
4600 described above, except that the module loaded is registered as a
4601 child of the calling module. The &s.code;parent&e.code; parameter
4602 is the calling module's handle. Modules loaded with this function
4603 are automatically unloaded when the parent module is unloaded. The
4604 other difference is that the path parameter may not be specified.
4605 The module search path used for modules loaded with this function
4606 is the default search path as initialised with
4607 &s.code;LoaderSetPath()&e.code;.
4609 </quote>
4611 &s.code;void UnloadSubModule(pointer module)&e.code;
4612 <quote><p>
4613 This function unloads the module with handle &s.code;module&e.code;.
4614 If that module itself has children, they are also unloaded. It is
4615 like &s.code;UnloadModule()&e.code;, except that it is safe to use
4616 for unloading child modules.
4618 </quote>
4620 &s.code;pointer LoaderSymbol(const char *symbol)&e.code;
4621 <quote><p>
4622 This function returns the address of the symbol with name
4623 &s.code;symbol&e.code;. This may be used to locate a module entry
4624 point with a known name.
4626 </quote>
4628 &s.code;char **LoaderlistDirs(const char **subdirlist,
4629 &f.indent;const char **patternlist)&e.code;
4630 <quote><p>
4631 This function returns a &s.code;NULL&e.code; terminated list of
4632 canonical modules names for modules found in the default module
4633 search path. The &s.code;subdirlist&e.code; and
4634 &s.code;patternlist&e.code; parameters are as described above, and
4635 can be used to control the locations and names that are searched.
4636 If no modules are found, the return value is &s.code;NULL&e.code;.
4637 The returned list should be freed by calling
4638 &s.code;LoaderFreeDirList()&e.code; when it is no longer needed.
4640 </quote>
4642 &s.code;void LoaderFreeDirList(char **list)&e.code;
4643 <quote><p>
4644 This function frees a module list created by
4645 &s.code;LoaderlistDirs()&e.code;.
4647 </quote>
4649 &s.code;void LoaderReqSymLists(const char **list0, ...)&e.code;
4650 <quote><p>
4651 This function allows the registration of required symbols with the
4652 loader. It is normally used by a caller of
4653 &s.code;LoadSubModule()&e.code;. If any symbols registered in this
4654 way are found to be unresolved when
4655 &s.code;LoaderCheckUnresolved()&e.code; is called then
4656 &s.code;LoaderCheckUnresolved()&e.code; will report a failure.
4657 The function takes one or more &s.code;NULL&e.code; terminated
4658 lists of symbols. The end of the argument list is indicated by a
4659 &s.code;NULL&e.code; argument.
4661 </quote>
4663 &s.code;void LoaderReqSymbols(const char *sym0, ...)&e.code;
4664 <quote><p>
4665 This function is like &s.code;LoaderReqSymLists()&e.code; except
4666 that its arguments are symbols rather than lists of symbols. This
4667 function is more convenient when single functions are to be registered,
4668 especially when the single function might depend on runtime factors.
4669 The end of the argument list is indicated by a &s.code;NULL&e.code;
4670 argument.
4672 </quote>
4674 &s.code;void LoaderRefSymLists(const char **list0, ...)&e.code;
4675 <quote><p>
4676 This function allows the registration of possibly unresolved symbols
4677 with the loader. When &s.code;LoaderCheckUnresolved()&e.code; is
4678 run it won't generate warnings for symbols registered in this way
4679 unless they were also registered as required symbols.
4680 The function takes one or more &s.code;NULL&e.code; terminated
4681 lists of symbols. The end of the argument list is indicated by a
4682 &s.code;NULL&e.code; argument.
4684 </quote>
4686 &s.code;void LoaderRefSymbols(const char *sym0, ...)&e.code;
4687 <quote><p>
4688 This function is like &s.code;LoaderRefSymLists()&e.code; except
4689 that its arguments are symbols rather than lists of symbols. This
4690 function is more convenient when single functions are to be registered,
4691 especially when the single function might depend on runtime factors.
4692 The end of the argument list is indicated by a &s.code;NULL&e.code;
4693 argument.
4695 </quote>
4697 &s.code;int LoaderCheckUnresolved(int delayflag)&e.code;
4698 <quote><p>
4699 This function checks for unresolved symbols. It generates warnings
4700 for unresolved symbols that have not been registered with
4701 &s.code;LoaderRefSymLists()&e.code;, and maps them to a dummy
4702 function. This behaviour may change in future. If unresolved
4703 symbols are found that have been registered with
4704 &s.code;LoaderReqSymLists()&e.code; or
4705 &s.code;LoaderReqSymbols()&e.code; then this function returns a
4706 non-zero value. If none of these symbols are unresolved the return
4707 value is zero, indicating success.
4709 The &s.code;delayflag&e.code; parameter should normally be set to
4710 &s.code;LD_RESOLV_IFDONE&e.code;.
4712 </quote>
4714 &s.code;LoaderErrorMsg(const char *name, const char *modname,
4715 &f.indent;int errmaj, int errmin)&e.code;
4716 <quote><p>
4717 This function prints an error message that includes the text ``Failed
4718 to load module'', the module name &s.code;modname&e.code;, a message
4719 specific to the &s.code;errmaj&e.code; value, and the value if
4720 &s.code;errmin&e.code;. If &s.code;name&e.code; is
4721 non-&s.code;NULL&e.code;, it is printed as an identifying prefix
4722 to the message (followed by a `:').
4724 </quote>
4725 </quote>
4727 <sect1>Special Registration Functions
4730 The loader contains some functions for registering some classes of modules.
4731 These may be moved out of the loader at some point.
4733 <quote><p>
4734 &s.code;void LoadExtension(ExtensionModule *ext)&e.code;
4735 <quote><p>
4736 This registers the entry points for the extension identified by
4737 &s.code;ext&e.code;. The &s.code;ExtensionModule&e.code; struct is
4738 defined as:
4740 <quote>
4741 <verb>
4742 typedef struct {
4743 InitExtension initFunc;
4744 char * name;
4745 Bool *disablePtr;
4746 InitExtension setupFunc;
4747 } ExtensionModule;
4748 </verb>
4749 </quote>
4751 </quote>
4753 &s.code;void LoadFont(FontModule *font)&e.code;
4754 <quote><p>
4755 This registers the entry points for the font rasteriser module
4756 identified by &s.code;font&e.code;. The &s.code;FontModule&e.code;
4757 struct is defined as:
4759 <quote>
4760 <verb>
4761 typedef struct {
4762 InitFont initFunc;
4763 char * name;
4764 pointer module;
4765 } FontModule;
4766 </verb>
4767 </quote>
4769 </quote>
4770 </quote>
4772 </sect>
4775 <sect>Helper Functions
4778 This section describe ``helper'' functions that video driver
4779 might find useful. While video drivers are not required to use any of
4780 these to be considered ``compliant'', the use of appropriate helpers is
4781 strongly encouraged to improve the consistency of driver behaviour.
4783 <sect1>Functions for printing messages
4786 <quote><p>
4787 &s.code;ErrorF(const char *format, ...)&e.code;
4788 <quote><p>
4789 This is the basic function for writing to the error log (typically
4790 stderr and/or a log file). Video drivers should usually avoid
4791 using this directly in favour of the more specialised functions
4792 described below. This function is useful for printing messages
4793 while debugging a driver.
4795 </quote>
4797 &s.code;FatalError(const char *format, ...)&e.code;
4798 <quote><p>
4799 This prints a message and causes the Xserver to abort. It should
4800 rarely be used within a video driver, as most error conditions
4801 should be flagged by the return values of the driver functions.
4802 This allows the higher layers to decide how to proceed. In rare
4803 cases, this can be used within a driver if a fatal unexpected
4804 condition is found.
4806 </quote>
4808 &s.code;xf86ErrorF(const char *format, ...)&e.code;
4809 <quote><p>
4810 This is like &s.code;ErrorF()&e.code;, except that the message is
4811 only printed when the Xserver's verbosity level is set to the
4812 default (&s.code;1&e.code;) or higher. It means that the messages
4813 are not printed when the server is started with the
4814 &s.cmd;-quiet&e.cmd; flag. Typically this function would only be
4815 used for continuing messages started with one of the more specialised
4816 functions described below.
4818 </quote>
4820 &s.code;xf86ErrorFVerb(int verb, const char *format, ...)&e.code;
4821 <quote><p>
4822 Like &s.code;xf86ErrorF()&e.code;, except the minimum verbosity
4823 level for which the message is to be printed is given explicitly.
4824 Passing a &s.code;verb&e.code; value of zero means the message
4825 is always printed. A value higher than &s.code;1&e.code; can be
4826 used for information would normally not be needed, but which might
4827 be useful when diagnosing problems.
4829 </quote>
4831 &s.code;xf86Msg(MessageType type, const char *format, ...)&e.code;
4832 <quote><p>
4833 This is like &s.code;xf86ErrorF()&e.code;, except that the message
4834 is prefixed with a marker determined by the value of
4835 &s.code;type&e.code;. The marker is used to indicate the type of
4836 message (warning, error, probed value, config value, etc). Note
4837 the &s.code;xf86Verbose&e.code; value is ignored for messages of
4838 type &s.code;X_ERROR&e.code;.
4840 The marker values are:
4842 <quote>
4843 &s.code;X_PROBED&e.code;
4844 <quote>Value was probed.</quote>
4845 &s.code;X_CONFIG&e.code;
4846 <quote>Value was given in the config file.</quote>
4847 &s.code;X_DEFAULT&e.code;
4848 <quote>Value is a default.</quote>
4849 &s.code;X_CMDLINE&e.code;
4850 <quote>Value was given on the command line.</quote>
4851 &s.code;X_NOTICE&e.code;
4852 <quote>Notice.</quote>
4853 &s.code;X_ERROR&e.code;
4854 <quote>Error message.</quote>
4855 &s.code;X_WARNING&e.code;
4856 <quote>Warning message.</quote>
4857 &s.code;X_INFO&e.code;
4858 <quote>Informational message.</quote>
4859 &s.code;X_NONE&e.code;
4860 <quote>No prefix.</quote>
4861 &s.code;X_NOT_IMPLEMENTED&e.code;
4862 <quote>The message relates to functionality that is not yet
4863 implemented.</quote>
4864 </quote>
4867 </quote>
4869 &s.code;xf86MsgVerb(MessageType type, int verb, const char *format, ...)&e.code;
4870 <quote><p>
4871 Like &s.code;xf86Msg()&e.code;, but with the verbosity level given
4872 explicitly.
4874 </quote>
4876 &s.code;xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...)&e.code;
4877 <quote><p>
4878 This is like &s.code;xf86Msg()&e.code; except that the driver's
4879 name (the &s.code;name&e.code; field of the
4880 &s.code;ScrnInfoRec&e.code;) followed by the
4881 &s.code;scrnIndex&e.code; in parentheses is printed following the
4882 prefix. This should be used by video drivers in most cases as it
4883 clearly indicates which driver/screen the message is for. If
4884 &s.code;scrnIndex&e.code; is negative, this function behaves
4885 exactly like &s.code;xf86Msg()&e.code;.
4887 NOTE: This function can only be used after the
4888 &s.code;ScrnInfoRec&e.code; and its &s.code;name&e.code; field
4889 have been allocated. Normally, this means that it can not be
4890 used before the END of the &s.code;ChipProbe()&e.code; function.
4891 Prior to that, use &s.code;xf86Msg()&e.code;, providing the
4892 driver's name explicitly. No screen number can be supplied at
4893 that point.
4895 </quote>
4897 &s.code;xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb,
4898 &f.indent;const char *format, ...)&e.code;
4899 <quote><p>
4900 Like &s.code;xf86DrvMsg()&e.code;, but with the verbosity level
4901 given explicitly.
4903 </quote>
4904 </quote>
4907 <sect1>Functions for setting values based on command line and config file
4910 <quote><p>
4911 &s.code;Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp,
4912 &f.indent;int fbbpp, int depth24flags)&e.code;
4913 <quote><p>
4914 This function sets the &s.code;depth&e.code;, &s.code;pixmapBPP&e.code; and &s.code;bitsPerPixel&e.code; fields
4915 of the &s.code;ScrnInfoRec&e.code;. It also determines the defaults for display-wide
4916 attributes and pixmap formats the screen will support, and finds
4917 the Display subsection that matches the depth/bpp. This function
4918 should normally be called very early from the
4919 &s.code;ChipPreInit()&e.code; function.
4921 It requires that the &s.code;confScreen&e.code; field of the &s.code;ScrnInfoRec&e.code; be
4922 initialised prior to calling it. This is done by the XFree86
4923 common layer prior to calling &s.code;ChipPreInit()&e.code;.
4925 The parameters passed are:
4927 &s.code;depth&e.code;
4928 <quote><p>
4929 driver's preferred default depth if no other is given.
4930 If zero, use the overall server default.
4932 </quote>
4933 &s.code;bpp&e.code;
4934 <quote><p>
4935 Same, but for the pixmap bpp.
4937 </quote>
4938 &s.code;fbbpp&e.code;
4939 <quote><p>
4940 Same, but for the framebuffer bpp.
4942 </quote>
4943 &s.code;depth24flags&e.code;
4944 <quote><p>
4945 Flags that indicate the level of 24/32bpp support
4946 and whether conversion between different framebuffer
4947 and pixmap formats is supported. The flags for this
4948 argument are defined as follows, and multiple flags
4949 may be ORed together:
4951 &s.code;NoDepth24Support&e.code;
4952 <quote>No depth 24 formats supported</quote>
4953 &s.code;Support24bppFb&e.code;
4954 <quote>24bpp framebuffer supported</quote>
4955 &s.code;Support32bppFb&e.code;
4956 <quote>32bpp framebuffer supported</quote>
4957 &s.code;SupportConvert24to32&e.code;
4958 <quote>Can convert 24bpp pixmap to 32bpp fb</quote>
4959 &s.code;SupportConvert32to24&e.code;
4960 <quote>Can convert 32bpp pixmap to 24bpp fb</quote>
4961 &s.code;ForceConvert24to32&e.code;
4962 <quote>Force 24bpp pixmap to 32bpp fb conversion</quote>
4963 &s.code;ForceConvert32to24&e.code;
4964 <quote>Force 32bpp pixmap to 24bpp fb conversion</quote>
4966 </quote>
4968 It uses the command line, config file, and default values in the
4969 correct order of precedence to determine the depth and bpp values.
4970 It is up to the driver to check the results to see that it supports
4971 them. If not the &s.code;ChipPreInit()&e.code; function should
4972 return &s.code;FALSE&e.code;.
4974 If only one of depth/bpp is given, the other is set to a reasonable
4975 (and consistent) default.
4977 If a driver finds that the initial &s.code;depth24flags&e.code;
4978 it uses later results in a fb format that requires more video
4979 memory than is available it may call this function a second time
4980 with a different &s.code;depth24flags&e.code; setting.
4982 On success, the return value is &s.code;TRUE&e.code;. On failure
4983 it prints an error message and returns &s.code;FALSE&e.code;.
4985 The following fields of the &s.code;ScrnInfoRec&e.code; are
4986 initialised by this function:
4988 <quote>
4989 &s.code;depth&e.code;, &s.code;bitsPerPixel&e.code;,
4990 &s.code;display&e.code;, &s.code;imageByteOrder&e.code;,
4991 &s.code;bitmapScanlinePad&e.code;,
4992 &s.code;bitmapScanlineUnit&e.code;, &s.code;bitmapBitOrder&e.code;,
4993 &s.code;numFormats&e.code;, &s.code;formats&e.code;,
4994 &s.code;fbFormat&e.code;.
4995 </quote>
4997 </quote>
4999 &s.code;void xf86PrintDepthBpp(scrnInfoPtr scrp)&e.code;
5000 <quote><p>
5001 This function can be used to print out the depth and bpp settings.
5002 It should be called after the final call to
5003 &s.code;xf86SetDepthBpp()&e.code;.
5005 </quote>
5007 &s.code;Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask)&e.code;
5008 <quote><p>
5009 This function sets the &s.code;weight&e.code;, &s.code;mask&e.code;,
5010 &s.code;offset&e.code; and &s.code;rgbBits&e.code; fields of the
5011 &s.code;ScrnInfoRec&e.code;. It would normally be called fairly
5012 early in the &s.code;ChipPreInit()&e.code; function for
5013 depths&nbsp;>&nbsp;8bpp.
5015 It requires that the &s.code;depth&e.code; and
5016 &s.code;display&e.code; fields of the &s.code;ScrnInfoRec&e.code;
5017 be initialised prior to calling it.
5019 The parameters passed are:
5021 &s.code;weight&e.code;
5022 <quote><p>
5023 driver's preferred default weight if no other is given.
5024 If zero, use the overall server default.
5026 </quote>
5028 &s.code;mask&e.code;
5029 <quote><p>
5030 Same, but for mask.
5032 </quote>
5034 It uses the command line, config file, and default values in the
5035 correct order of precedence to determine the weight value. It
5036 derives the mask and offset values from the weight and the defaults.
5037 It is up to the driver to check the results to see that it supports
5038 them. If not the &s.code;ChipPreInit()&e.code; function should
5039 return &s.code;FALSE&e.code;.
5041 On success, this function prints a message showing the weight
5042 values selected, and returns &s.code;TRUE&e.code;.
5044 On failure it prints an error message and returns &s.code;FALSE&e.code;.
5046 The following fields of the &s.code;ScrnInfoRec&e.code; are
5047 initialised by this function:
5049 <quote>
5050 &s.code;weight&e.code;, &s.code;mask&e.code;, &s.code;offset&e.code;.
5051 </quote>
5053 </quote>
5055 &s.code;Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual)&e.code;
5056 <quote><p>
5057 This function sets the &s.code;defaultVisual&e.code; field of the
5058 &s.code;ScrnInfoRec&e.code;. It would normally be called fairly
5059 early from the &s.code;ChipPreInit()&e.code; function.
5061 It requires that the &s.code;depth&e.code; and
5062 &s.code;display&e.code; fields of the &s.code;ScrnInfoRec&e.code;
5063 be initialised prior to calling it.
5065 The parameters passed are:
5067 &s.code;visual&e.code;
5068 <quote><p>
5069 driver's preferred default visual if no other is given.
5070 If &s.code;-1&e.code;, use the overall server default.
5072 </quote>
5074 It uses the command line, config file, and default values in the
5075 correct order of precedence to determine the default visual value.
5076 It is up to the driver to check the result to see that it supports
5077 it. If not the &s.code;ChipPreInit()&e.code; function should
5078 return &s.code;FALSE&e.code;.
5080 On success, this function prints a message showing the default visual
5081 selected, and returns &s.code;TRUE&e.code;.
5083 On failure it prints an error message and returns &s.code;FALSE&e.code;.
5085 </quote>
5087 &s.code;Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma)&e.code;
5088 <quote><p>
5089 This function sets the &s.code;gamma&e.code; field of the
5090 &s.code;ScrnInfoRec&e.code;. It would normally be called fairly
5091 early from the &s.code;ChipPreInit()&e.code; function in cases
5092 where the driver supports gamma correction.
5094 It requires that the &s.code;monitor&e.code; field of the
5095 &s.code;ScrnInfoRec&e.code; be initialised prior to calling it.
5097 The parameters passed are:
5099 &s.code;gamma&e.code;
5100 <quote><p>
5101 driver's preferred default gamma if no other is given.
5102 If zero (&s.code;< 0.01&e.code;), use the overall server
5103 default.
5105 </quote>
5107 It uses the command line, config file, and default values in the
5108 correct order of precedence to determine the gamma value. It is
5109 up to the driver to check the results to see that it supports
5110 them. If not the &s.code;ChipPreInit()&e.code; function should
5111 return &s.code;FALSE&e.code;.
5113 On success, this function prints a message showing the gamma
5114 value selected, and returns &s.code;TRUE&e.code;.
5116 On failure it prints an error message and returns &s.code;FALSE&e.code;.
5118 </quote>
5120 &s.code;void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y)&e.code;
5121 <quote><p>
5122 This function sets the &s.code;xDpi&e.code; and &s.code;yDpi&e.code;
5123 fields of the &s.code;ScrnInfoRec&e.code;. The driver can specify
5124 preferred defaults by setting &s.code;x&e.code; and &s.code;y&e.code;
5125 to non-zero values. The &s.cmd;-dpi&e.cmd; command line option
5126 overrides all other settings. Otherwise, if the
5127 &s.key;DisplaySize&e.key; entry is present in the screen's &k.monitor;
5128 config file section, it is used together with the virtual size to
5129 calculate the dpi values. This function should be called after
5130 all the mode resolution has been done.
5132 </quote>
5134 &s.code;void xf86SetBlackWhitePixels(ScrnInfoPtr pScrn)&e.code;
5135 <quote><p>
5136 This functions sets the &s.code;blackPixel&e.code; and
5137 &s.code;whitePixel&e.code; fields of the &s.code;ScrnInfoRec&e.code;
5138 according to whether or not the &s.cmd;-flipPixels&e.cmd; command
5139 line options is present.
5141 </quote>
5143 &s.code;const char *xf86GetVisualName(int visual)&e.code;
5144 <quote><p>
5145 Returns a printable string with the visual name matching the
5146 numerical visual class provided. If the value is outside the
5147 range of valid visual classes, &s.code;NULL&e.code; is returned.
5149 </quote>
5150 </quote>
5153 <sect1>Primary Mode functions
5156 The primary mode helper functions are those which would normally be
5157 used by a driver, unless it has unusual requirements which cannot
5158 be catered for the by the helpers.
5160 <quote><p>
5161 &s.code;int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
5162 &f.indent;char **modeNames, ClockRangePtr clockRanges,
5163 &f.indent;int *linePitches, int minPitch, int maxPitch,
5164 &f.indent;int pitchInc, int minHeight, int maxHeight,
5165 &f.indent;int virtualX, int virtualY,
5166 &f.indent;unsigned long apertureSize,
5167 &f.indent;LookupModeFlags strategy)&e.code;
5168 <quote><p>
5169 This function basically selects the set of modes to use based on
5170 those available and the various constraints. It also sets some
5171 other related parameters. It is normally called near the end of
5172 the &s.code;ChipPreInit()&e.code; function.
5174 The parameters passed to the function are:
5176 &s.code;availModes&e.code;
5177 <quote><p>
5178 List of modes available for the monitor.
5180 </quote>
5181 &s.code;modeNames&e.code;
5182 <quote><p>
5183 List of mode names that the screen is requesting.
5185 </quote>
5186 &s.code;clockRanges&e.code;
5187 <quote><p>
5188 A list of clock ranges allowed by the driver. Each
5189 range includes whether interlaced or multiscan modes
5190 are supported for that range. See below for more on
5191 &s.code;clockRanges&e.code;.
5193 </quote>
5194 &s.code;linePitches&e.code;
5195 <quote><p>
5196 List of line pitches supported by the driver.
5197 This is optional and should be &s.code;NULL&e.code; when
5198 not used.
5200 </quote>
5201 &s.code;minPitch&e.code;
5202 <quote><p>
5203 Minimum line pitch supported by the driver. This must
5204 be supplied when &s.code;linePitches&e.code; is
5205 &s.code;NULL&e.code;, and is ignored otherwise.
5207 </quote>
5208 &s.code;maxPitch&e.code;
5209 <quote><p>
5210 Maximum line pitch supported by the driver. This is
5211 required when &s.code;minPitch&e.code; is required.
5213 </quote>
5214 &s.code;pitchInc&e.code;
5215 <quote><p>
5216 Granularity of horizontal pitch values as supported by
5217 the chipset. This is expressed in bits. This must be
5218 supplied.
5220 </quote>
5221 &s.code;minHeight&e.code;
5222 <quote><p>
5223 minimum virtual height allowed. If zero, no limit is
5224 imposed.
5226 </quote>
5227 &s.code;maxHeight&e.code;
5228 <quote><p>
5229 maximum virtual height allowed. If zero, no limit is
5230 imposed.
5232 </quote>
5233 &s.code;virtualX&e.code;
5234 <quote><p>
5235 If greater than zero, this is the virtual width value
5236 that will be used. Otherwise, the virtual width is
5237 chosen to be the smallest that can accommodate the modes
5238 selected.
5240 </quote>
5241 &s.code;virtualY&e.code;
5242 <quote><p>
5243 If greater than zero, this is the virtual height value
5244 that will be used. Otherwise, the virtual height is
5245 chosen to be the smallest that can accommodate the modes
5246 selected.
5248 </quote>
5249 &s.code;apertureSize&e.code;
5250 <quote><p>
5251 The size (in bytes) of the aperture used to access video
5252 memory.
5254 </quote>
5255 &s.code;strategy&e.code;
5256 <quote><p>
5257 The strategy to use when choosing from multiple modes
5258 with the same name. The options are:
5260 &s.code;LOOKUP_DEFAULT&e.code;
5261 <quote>???</quote>
5262 &s.code;LOOKUP_BEST_REFRESH&e.code;
5263 <quote>mode with best refresh rate</quote>
5264 &s.code;LOOKUP_CLOSEST_CLOCK&e.code;
5265 <quote>mode with closest matching clock</quote>
5266 &s.code;LOOKUP_LIST_ORDER&e.code;
5267 <quote>first usable mode in list</quote>
5269 The following options can also be combined (OR'ed) with
5270 one of the above:
5272 &s.code;LOOKUP_CLKDIV2&e.code;
5273 <quote>Allow halved clocks</quote>
5274 &s.code;LOOKUP_OPTIONAL_TOLERANCES&e.code;
5275 <quote>Allow missing horizontal sync and/or vertical refresh
5276 ranges in the xorg.conf Monitor section</quote>
5278 &s.code;LOOKUP_OPTIONAL_TOLERANCES&e.code; should only be
5279 specified when the driver can ensure all modes it generates
5280 can sync on, or at least not damage, the monitor or digital
5281 flat panel. Horizontal sync and/or vertical refresh ranges
5282 specified by the user will still be honoured (and acted upon).
5284 </quote>
5286 This function requires that the following fields of the
5287 &s.code;ScrnInfoRec&e.code; are initialised prior to calling it:
5289 &s.code;clock[]&e.code;
5290 <quote>List of discrete clocks (when non-programmable)</quote>
5291 &s.code;numClocks&e.code;
5292 <quote>Number of discrete clocks (when non-programmable)</quote>
5293 &s.code;progClock&e.code;
5294 <quote>Whether the clock is programmable or not</quote>
5295 &s.code;monitor&e.code;
5296 <quote>Pointer to the applicable xorg.conf monitor section</quote>
5297 &s.code;fdFormat&e.code;
5298 <quote>Format of the screen buffer</quote>
5299 &s.code;videoRam&e.code;
5300 <quote>total video memory size (in bytes)</quote>
5301 &s.code;maxHValue&e.code;
5302 <quote>Maximum horizontal timing value allowed</quote>
5303 &s.code;maxVValue&e.code;
5304 <quote>Maximum vertical timing value allowed</quote>
5305 &s.code;xInc&e.code;
5306 <quote>Horizontal timing increment in pixels (defaults to 8)</quote>
5308 This function fills in the following &s.code;ScrnInfoRec&e.code;
5309 fields:
5311 &s.code;modePool&e.code;
5312 <quote><p>
5313 A subset of the modes available to the monitor which
5314 are compatible with the driver.
5316 </quote>
5317 &s.code;modes&e.code;
5318 <quote><p>
5319 One mode entry for each of the requested modes, with
5320 the status field of each filled in to indicate if
5321 the mode has been accepted or not. This list of
5322 modes is a circular list.
5324 </quote>
5325 &s.code;virtualX&e.code;
5326 <quote><p>
5327 The resulting virtual width.
5329 </quote>
5330 &s.code;virtualY&e.code;
5331 <quote><p>
5332 The resulting virtual height.
5334 </quote>
5335 &s.code;displayWidth&e.code;
5336 <quote><p>
5337 The resulting line pitch.
5339 </quote>
5340 &s.code;virtualFrom&e.code;
5341 <quote><p>
5342 Where the virtual size was determined from.
5344 </quote>
5346 The first stage of this function checks that the
5347 &s.code;virtualX&e.code; and &s.code;virtualY&e.code; values
5348 supplied (if greater than zero) are consistent with the line pitch
5349 and &s.code;maxHeight&e.code; limitations. If not, an error
5350 message is printed, and the return value is &s.code;-1&e.code;.
5352 The second stage sets up the mode pool, eliminating immediately
5353 any modes that exceed the driver's line pitch limits, and also
5354 the virtual width and height limits (if greater than zero). For
5355 each mode removed an informational message is printed at verbosity
5356 level &s.code;2&e.code;. If the mode pool ends up being empty,
5357 a warning message is printed, and the return value is
5358 &s.code;0&e.code;.
5360 The final stage is to lookup each mode name, and fill in the remaining
5361 parameters. If an error condition is encountered, a message is
5362 printed, and the return value is &s.code;-1&e.code;. Otherwise,
5363 the return value is the number of valid modes found
5364 (&s.code;0&e.code; if none are found).
5366 Even if the supplied mode names include duplicates, no two names will
5367 ever match the same mode. Furthermore, if the supplied mode names do not
5368 yield a valid mode (including the case where no names are passed at all),
5369 the function will continue looking through the mode pool until it finds
5370 a mode that survives all checks, or until the mode pool is exhausted.
5372 A message is only printed by this function when a fundamental
5373 problem is found. It is intended that this function may be called
5374 more than once if there is more than one set of constraints that
5375 the driver can work within.
5377 If this function returns &s.code;-1&e.code;, the
5378 &s.code;ChipPreInit()&e.code; function should return
5379 &s.code;FALSE&e.code;.
5381 &s.code;clockRanges&e.code; is a linked list of clock ranges
5382 allowed by the driver. If a mode doesn't fit in any of the defined
5383 &s.code;clockRanges&e.code;, it is rejected. The first
5384 &s.code;clockRange&e.code; that matches all requirements is used.
5385 This structure needs to be initialized to NULL when allocated.
5387 &s.code;clockRanges&e.code; contains the following fields:
5389 &s.code;minClock&nl;
5390 maxClock&e.code;
5391 <quote><p>
5392 The lower and upper mode clock bounds for which the rest
5393 of the &s.code;clockRange&e.code; parameters apply.
5394 Since these are the mode clocks, they are not scaled
5395 with the &s.code;ClockMulFactor&e.code; and
5396 &s.code;ClockDivFactor&e.code;. It is up to the driver
5397 to adjust these values if they depend on the clock
5398 scaling factors.
5400 </quote>
5401 &s.code;clockIndex&e.code;
5402 <quote><p>
5403 (not used yet) &s.code;-1&e.code; for programmable clocks
5405 </quote>
5406 &s.code;interlaceAllowed&e.code;
5407 <quote><p>
5408 &s.code;TRUE&e.code; if interlacing is allowed for this
5409 range
5411 </quote>
5412 &s.code;doubleScanAllowed&e.code;
5413 <quote><p>
5414 &s.code;TRUE&e.code; if doublescan or multiscan is allowed
5415 for this range
5417 </quote>
5418 &s.code;ClockMulFactor&nl;
5419 ClockDivFactor&e.code;
5420 <quote><p>
5421 Scaling factors that are applied to the mode clocks ONLY
5422 before selecting a clock index (when there is no
5423 programmable clock) or a &s.code;SynthClock&e.code;
5424 value. This is useful for drivers that support pixel
5425 multiplexing or that need to scale the clocks because
5426 of hardware restrictions (like sending 24bpp data to an
5427 8 bit RAMDAC using a tripled clock).
5429 Note that these parameters describe what must be done
5430 to the mode clock to achieve the data transport clock
5431 between graphics controller and RAMDAC. For example
5432 for &s.code;2:1&e.code; pixel multiplexing, two pixels
5433 are sent to the RAMDAC on each clock. This allows the
5434 RAMDAC clock to be half of the actual pixel clock.
5435 Hence, &s.code;ClockMulFactor=1&e.code; and
5436 &s.code;ClockDivFactor=2&e.code;. This means that the
5437 clock used for clock selection (ie, determining the
5438 correct clock index from the list of discrete clocks)
5439 or for the &s.code;SynthClock&e.code; field in case of
5440 a programmable clock is: (&s.code;mode-&gt;Clock *
5441 ClockMulFactor) / ClockDivFactor&e.code;.
5443 </quote>
5444 &s.code;PrivFlags&e.code;
5445 <quote><p>
5446 This field is copied into the
5447 &s.code;mode-&gt;PrivFlags&e.code; field when this
5448 &s.code;clockRange&e.code; is selected by
5449 &s.code;xf86ValidateModes()&e.code;. It allows the
5450 driver to find out what clock range was selected, so it
5451 knows it needs to set up pixel multiplexing or any other
5452 range-dependent feature. This field is purely
5453 driver-defined: it may contain flag bits, an index or
5454 anything else (as long as it is an &s.code;INT&e.code;).
5455 </quote>
5457 Note that the &s.code;mode-&gt;SynthClock&e.code; field is always
5458 filled in by &s.code;xf86ValidateModes()&e.code;: it will contain
5459 the ``data transport clock'', which is the clock that will have
5460 to be programmed in the chip when it has a programmable clock, or
5461 the clock that will be picked from the clocks list when it is not
5462 a programmable one. Thus:
5464 &s.code;mode-&gt;SynthClock =
5465 &f.indent;(mode-&gt;Clock * ClockMulFactor) / ClockDivFactor&e.code;
5467 </quote>
5469 &s.code;void xf86PruneDriverModes(ScrnInfoPtr scrp)&e.code;
5470 <quote><p>
5471 This function deletes modes in the modes field of the
5472 &s.code;ScrnInfoRec&e.code; that have been marked as invalid.
5473 This is normally run after having run
5474 &s.code;xf86ValidateModes()&e.code; for the last time. For each
5475 mode that is deleted, a warning message is printed out indicating
5476 the reason for it being deleted.
5478 </quote>
5480 &s.code;void xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags)&e.code;
5481 <quote><p>
5482 This function fills in the &s.code;Crtc*&e.code; fields for all
5483 the modes in the &s.code;modes&e.code; field of the
5484 &s.code;ScrnInfoRec&e.code;. The &s.code;adjustFlags&e.code;
5485 parameter determines how the vertical CRTC values are scaled for
5486 interlaced modes. They are halved if it is
5487 &s.code;INTERLACE_HALVE_V&e.code;. The vertical CRTC values are
5488 doubled for doublescan modes, and are further multiplied by the
5489 &s.code;VScan&e.code; value.
5491 This function is normally called after calling
5492 &s.code;xf86PruneDriverModes()&e.code;.
5494 </quote>
5496 &s.code;void xf86PrintModes(ScrnInfoPtr scrp)&e.code;
5497 <quote><p>
5498 This function prints out the virtual size setting, and the line
5499 pitch being used. It also prints out two lines for each mode being
5500 used. The first line includes the mode's pixel clock, horizontal sync
5501 rate, refresh rate, and whether it is interlaced, doublescanned and/or
5502 multi-scanned. The second line is the mode's Modeline.
5504 This function is normally called after calling
5505 &s.code;xf86SetCrtcForModes()&e.code;.
5507 </quote>
5508 </quote>
5511 <sect1>Secondary Mode functions
5514 The secondary mode helper functions are functions which are normally
5515 used by the primary mode helper functions, and which are not normally
5516 called directly by a driver. If a driver has unusual requirements
5517 and needs to do its own mode validation, it might be able to make
5518 use of some of these secondary mode helper functions.
5520 <quote><p>
5521 &s.code;int xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
5522 &f.indent;int *divider)&e.code;
5523 <quote><p>
5524 This function returns the index of the closest clock to the
5525 frequency &s.code;freq&e.code; given (in kHz). It assumes that
5526 the number of clocks is greater than zero. It requires that the
5527 &s.code;numClocks&e.code; and &s.code;clock&e.code; fields of the
5528 &s.code;ScrnInfoRec&e.code; are initialised. The
5529 &s.code;allowDiv2&e.code; field determines if the clocks can be
5530 halved. The &s.code;*divider&e.code; return value indicates
5531 whether clock division is used when determining the clock returned.
5533 This function is only for non-programmable clocks.
5535 </quote>
5537 &s.code;const char *xf86ModeStatusToString(ModeStatus status)&e.code;
5538 <quote><p>
5539 This function converts the &s.code;status&e.code; value to a
5540 descriptive printable string.
5542 </quote>
5544 &s.code;ModeStatus xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
5545 &f.indent;ClockRangePtr clockRanges, LookupModeFlags strategy)&e.code;
5546 <quote><p>
5547 This function takes a pointer to a mode with the name filled in,
5548 and looks for a mode in the &s.code;modePool&e.code; list which
5549 matches. The parameters of the matching mode are filled in to
5550 &s.code;*modep&e.code;. The &s.code;clockRanges&e.code; and
5551 &s.code;strategy&e.code; parameters are as for the
5552 &s.code;xf86ValidateModes()&e.code; function above.
5554 This function requires the &s.code;modePool&e.code;,
5555 &s.code;clock[]&e.code;, &s.code;numClocks&e.code; and
5556 &s.code;progClock&e.code; fields of the &s.code;ScrnInfoRec&e.code;
5557 to be initialised before being called.
5559 The return value is &s.code;MODE_OK&e.code; if a mode was found.
5560 Otherwise it indicates why a matching mode could not be found.
5562 </quote>
5564 &s.code;ModeStatus xf86InitialCheckModeForDriver(ScrnInfoPtr scrp,
5565 &f.indent;DisplayModePtr mode, ClockRangePtr clockRanges,
5566 &f.indent;LookupModeFlags strategy, int maxPitch,
5567 &f.indent;int virtualX, int virtualY)&e.code;
5568 <quote><p>
5569 This function checks the passed mode against some basic driver
5570 constraints. Apart from the ones passed explicitly, the
5571 &s.code;maxHValue&e.code; and &s.code;maxVValue&e.code; fields of
5572 the &s.code;ScrnInfoRec&e.code; are also used. If the
5573 &s.code;ValidMode&e.code; field of the &s.code;ScrnInfoRec&e.code;
5574 is set, that function is also called to check the mode. Next, the
5575 mode is checked against the monitor's constraints.
5577 If the mode is consistent with all constraints, the return value
5578 is &s.code;MODE_OK&e.code;. Otherwise the return value indicates
5579 which constraint wasn't met.
5581 </quote>
5583 &s.code;void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode)&e.code;
5584 <quote><p>
5585 This function deletes the &s.code;mode&e.code; given from the
5586 &s.code;modeList&e.code;. It never prints any messages, so it is
5587 up to the caller to print a message if required.
5589 </quote>
5590 </quote>
5592 <sect1>Functions for handling strings and tokens
5595 Tables associating strings and numerical tokens combined with the
5596 following functions provide a compact way of handling strings from
5597 the config file, and for converting tokens into printable strings.
5598 The table data structure is:
5600 <quote><verb>
5601 typedef struct {
5602 int token;
5603 const char * name;
5604 } SymTabRec, *SymTabPtr;
5605 </verb></quote>
5607 A table is an initialised array of &s.code;SymTabRec&e.code;. The
5608 tokens must be non-negative integers. Multiple names may be mapped
5609 to a single token. The table is terminated with an element with a
5610 &s.code;token&e.code; value of &s.code;-1&e.code; and
5611 &s.code;NULL&e.code; for the &s.code;name&e.code;.
5614 <quote><p>
5615 &s.code;const char *xf86TokenToString(SymTabPtr table, int token)&e.code;
5616 <quote><p>
5617 This function returns the first string in &s.code;table&e.code;
5618 that matches &s.code;token&e.code;. If no match is found,
5619 &s.code;NULL&e.code; is returned (NOTE, older versions of this
5620 function would return the string "unknown" when no match is found).
5622 </quote>
5624 &s.code;int xf86StringToToken(SymTabPtr table, const char *string)&e.code;
5625 <quote><p>
5626 This function returns the first token in &s.code;table&e.code;
5627 that matches &s.code;string&e.code;. The
5628 &s.code;xf86NameCmp()&e.code; function is used to determine the
5629 match. If no match is found, &s.code;-1&e.code; is returned.
5631 </quote>
5632 </quote>
5635 <sect1>Functions for finding which config file entries to use
5638 These functions can be used to select the appropriate config file
5639 entries that match the detected hardware. They are described above
5640 in the <ref id="probe" name="Probe"> and
5641 <ref id="avail" name="Available Functions"> sections.
5644 <sect1>Probing discrete clocks on old hardware
5647 The &s.code;xf86GetClocks()&e.code; function may be used to assist
5648 in finding the discrete pixel clock values on older hardware.
5651 <quote><p>
5652 &s.code;void xf86GetClocks(ScrnInfoPtr pScrn, int num,
5653 &f.indent;Bool (*ClockFunc)(ScrnInfoPtr, int),
5654 &f.indent;void (*ProtectRegs)(ScrnInfoPtr, Bool),
5655 &f.indent;void (*BlankScreen)(ScrnInfoPtr, Bool),
5656 &f.indent;int vertsyncreg, int maskval, int knownclkindex,
5657 &f.indent;int knownclkvalue)&e.code;
5658 <quote><p>
5659 This function uses a comparative sampling method to measure the
5660 discrete pixel clock values. The number of discrete clocks to
5661 measure is given by &s.code;num&e.code;. &s.code;clockFunc&e.code;
5662 is a function that selects the &s.code;n&e.code;'th clock. It
5663 should also save or restore any state affected by programming the
5664 clocks when the index passed is &s.code;CLK_REG_SAVE&e.code; or
5665 &s.code;CLK_REG_RESTORE&e.code;. &s.code;ProtectRegs&e.code; is
5666 a function that does whatever is required to protect the hardware
5667 state while selecting a new clock. &s.code;BlankScreen&e.code;
5668 is a function that blanks the screen. &s.code;vertsyncreg&e.code;
5669 and &s.code;maskval&e.code; are the register and bitmask to
5670 check for the presence of vertical sync pulses.
5671 &s.code;knownclkindex&e.code; and &s.code;knownclkvalue&e.code;
5672 are the index and value of a known clock. These are the known
5673 references on which the comparative measurements are based. The
5674 number of clocks probed is set in &s.code;pScrn-&gt;numClocks&e.code;,
5675 and the probed clocks are set in the &s.code;pScrn-&gt;clock[]&e.code;
5676 array. All of the clock values are in units of kHz.
5678 </quote>
5680 &s.code;void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from)&e.code;
5681 <quote><p>
5682 Print out the pixel clocks &s.code;scrp-&gt;clock[]&e.code;.
5683 &s.code;from&e.code; indicates whether the clocks were probed
5684 or from the config file.
5686 </quote>
5687 </quote>
5689 <sect1>Other helper functions
5691 <quote><p>
5692 &s.code;Bool xf86IsUnblank(int mode)&e.code;
5693 <quote><p>
5694 Returns &s.code;TRUE&e.code; when the screen saver mode specified
5695 by &s.code;mode&e.code; requires the screen be unblanked,
5696 and &s.code;FALSE&e.code; otherwise. The screen saver modes that
5697 require blanking are &s.code;SCREEN_SAVER_ON&e.code; and
5698 &s.code;SCREEN_SAVER_CYCLE&e.code;, and the screen saver modes that
5699 require unblanking are &s.code;SCREEN_SAVER_OFF&e.code; and
5700 &s.code;SCREEN_SAVER_FORCER&e.code;. Drivers may call this helper
5701 from their &s.code;SaveScreen()&e.code; function to interpret the
5702 screen saver modes.
5704 </quote>
5705 </quote>
5707 <sect>The vgahw module
5710 The vgahw modules provides an interface for saving, restoring and
5711 programming the standard VGA registers, and for handling VGA colourmaps.
5713 <sect1>Data Structures
5716 The public data structures used by the vgahw module are
5717 &s.code;vgaRegRec&e.code; and &s.code;vgaHWRec&e.code;. They are
5718 defined in &s.code;vgaHW.h.&e.code;
5721 <sect1>General vgahw Functions
5724 <quote><p>
5725 &s.code;Bool vgaHWGetHWRec(ScrnInfoPtr pScrn)&e.code;
5726 <quote><p>
5727 This function allocates a &s.code;vgaHWRec&e.code; structure, and
5728 hooks it into the &s.code;ScrnInfoRec&e.code;'s
5729 &s.code;privates&e.code;. Like all information hooked into the
5730 &s.code;privates&e.code;, it is persistent, and only needs to be
5731 allocated once per screen. This function should normally be called
5732 from the driver's &s.code;ChipPreInit()&e.code; function. The
5733 &s.code;vgaHWRec&e.code; is zero-allocated, and the following
5734 fields are explicitly initialised:
5736 &s.code;ModeReg.DAC[]&e.code;
5737 <quote>initialised with a default colourmap</quote>
5738 &s.code;ModeReg.Attribute[0x11]&e.code;
5739 <quote>initialised with the default overscan index</quote>
5740 &s.code;ShowOverscan&e.code;
5741 <quote>initialised according to the "ShowOverscan" option</quote>
5742 &s.code;paletteEnabled&e.code;
5743 <quote>initialised to FALSE</quote>
5744 &s.code;cmapSaved&e.code;
5745 <quote>initialised to FALSE</quote>
5746 &s.code;pScrn&e.code;
5747 <quote>initialised to pScrn</quote>
5749 In addition to the above, &s.code;vgaHWSetStdFuncs()&e.code; is
5750 called to initialise the register access function fields with the
5751 standard VGA set of functions.
5753 Once allocated, a pointer to the &s.code;vgaHWRec&e.code; can be
5754 obtained from the &s.code;ScrnInfoPtr&e.code; with the
5755 &s.code;VGAHWPTR(pScrn)&e.code; macro.
5757 </quote>
5759 &s.code;void vgaHWFreeHWRec(ScrnInfoPtr pScrn)&e.code;
5760 <quote><p>
5761 This function frees a &s.code;vgaHWRec&e.code; structure. It
5762 should be called from a driver's &s.code;ChipFreeScreen()&e.code;
5763 function.
5765 </quote>
5767 &s.code;Bool vgaHWSetRegCounts(ScrnInfoPtr pScrn, int numCRTC,
5768 &f.indent;int numSequencer, int numGraphics, int numAttribute)&e.code;
5769 <quote><p>
5770 This function allows the number of CRTC, Sequencer, Graphics and
5771 Attribute registers to be changed. This makes it possible for
5772 extended registers to be saved and restored with
5773 &s.code;vgaHWSave()&e.code; and &s.code;vgaHWRestore()&e.code;.
5774 This function should be called after a &s.code;vgaHWRec&e.code;
5775 has been allocated with &s.code;vgaHWGetHWRec()&e.code;. The
5776 default values are defined in &s.code;vgaHW.h&e.code; as follows:
5778 <quote><verb>
5779 #define VGA_NUM_CRTC 25
5780 #define VGA_NUM_SEQ 5
5781 #define VGA_NUM_GFX 9
5782 #define VGA_NUM_ATTR 21
5783 </verb></quote>
5785 </quote>
5787 &s.code;Bool vgaHWCopyReg(vgaRegPtr dst, vgaRegPtr src)&e.code;
5788 <quote><p>
5789 This function copies the contents of the VGA saved registers in
5790 &s.code;src&e.code; to &s.code;dst&e.code;. Note that it isn't
5791 possible to simply do this with &s.code;memcpy()&e.code; (or
5792 similar). This function returns &s.code;TRUE&e.code; unless there
5793 is a problem allocating space for the &s.code;CRTC&e.code and
5794 related fields in &s.code;dst&e.code;.
5796 </quote>
5798 &s.code;void vgaHWSetStdFuncs(vgaHWPtr hwp)&e.code;
5799 <quote><p>
5800 This function initialises the register access function fields of
5801 &s.code;hwp&e.code; with the standard VGA set of functions. This
5802 is called by &s.code;vgaHWGetHWRec()&e.code;, so there is usually
5803 no need to call this explicitly. The register access functions
5804 are described below. If the registers are shadowed in some other
5805 port I/O space (for example a PCI I/O region), these functions
5806 can be used to access the shadowed registers if
5807 &s.code;hwp-&gt;PIOOffset&e.code; is initialised with
5808 &s.code;offset&e.code;, calculated in such a way that when the
5809 standard VGA I/O port value is added to it the correct offset into
5810 the PIO area results. This value is initialised to zero in
5811 &s.code;vgaHWGetHWRec()&e.code;. (Note: the PIOOffset functionality
5812 is present in XFree86 4.1.0 and later.)
5814 </quote>
5816 &s.code;void vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset)&e.code;
5817 <quote><p>
5818 This function initialised the register access function fields of
5819 hwp with a generic MMIO set of functions.
5820 &s.code;hwp-&gt;MMIOBase&e.code; is initialised with
5821 &s.code;base&e.code;, which must be the virtual address that the
5822 start of MMIO area is mapped to. &s.code;hwp-&gt;MMIOOffset&e.code;
5823 is initialised with &s.code;offset&e.code;, which must be calculated
5824 in such a way that when the standard VGA I/O port value is added
5825 to it the correct offset into the MMIO area results. That means
5826 that these functions are only suitable when the VGA I/O ports are
5827 made available in a direct mapping to the MMIO space. If that is
5828 not the case, the driver will need to provide its own register
5829 access functions. The register access functions are described
5830 below.
5832 </quote>
5834 &s.code;Bool vgaHWMapMem(ScrnInfoPtr pScrn)&e.code;
5835 <quote><p>
5836 This function maps the VGA memory window. It requires that the
5837 &s.code;vgaHWRec&e.code; be allocated. If a driver requires
5838 non-default &s.code;MapPhys&e.code; or &s.code;MapSize&e.code;
5839 settings (the physical location and size of the VGA memory window)
5840 then those fields of the &s.code;vgaHWRec&e.code; must be initialised
5841 before calling this function. Otherwise, this function initialiases
5842 the default values of &s.code;0xA0000&e.code; for
5843 &s.code;MapPhys&e.code; and &s.code;(64&nbsp;*&nbsp;1024)&e.code; for
5844 &s.code;MapSize&e.code;. This function must be called before
5845 attempting to save or restore the VGA state. If the driver doesn't
5846 call it explicitly, the &s.code;vgaHWSave()&e.code; and
5847 &s.code;vgaHWRestore()&e.code; functions may call it if they need
5848 to access the VGA memory (in which case they will also call
5849 &s.code;vgaHWUnmapMem()&e.code; to unmap the VGA memory before
5850 exiting).
5852 </quote>
5854 &s.code;void vgaHWUnmapMem(ScrnInfoPtr pScrn)&e.code;
5855 <quote><p>
5856 This function unmaps the VGA memory window. It must only be called
5857 after the memory has been mapped. The &s.code;Base&e.code; field
5858 of the &s.code;vgaHWRec&e.code; field is set to &s.code;NULL&e.code;
5859 to indicate that the memory is no longer mapped.
5861 </quote>
5863 &s.code;void vgaHWGetIOBase(vgaHWPtr hwp)&e.code;
5864 <quote><p>
5865 This function initialises the &s.code;IOBase&e.code; field of the
5866 &s.code;vgaHWRec&e.code;. This function must be called before
5867 using any other functions that access the video hardware.
5869 A macro &s.code;VGAHW_GET_IOBASE()&e.code; is also available in
5870 &s.code;vgaHW.h&e.code; that returns the I/O base, and this may
5871 be used when the vgahw module is not loaded (for example, in the
5872 &s.code;ChipProbe()&e.code; function).
5874 </quote>
5876 &s.code;void vgaHWUnlock(vgaHWPtr hwp)&e.code;
5877 <quote><p>
5878 This function unlocks the VGA &s.code;CRTC[0-7]&e.code; registers,
5879 and must be called before attempting to write to those registers.
5881 </quote>
5883 &s.code;void vgaHWLock(vgaHWPtr hwp)&e.code;
5884 <quote><p>
5885 This function locks the VGA &s.code;CRTC[0-7]&e.code; registers.
5887 </quote>
5889 &s.code;void vgaHWEnable(vgaHWPtr hwp)&e.code;
5890 <quote><p>
5891 This function enables the VGA subsystem. (Note, this function is
5892 present in XFree86 4.1.0 and later.).
5894 </quote>
5896 &s.code;void vgaHWDisable(vgaHWPtr hwp)&e.code;
5897 <quote><p>
5898 This function disables the VGA subsystem. (Note, this function is
5899 present in XFree86 4.1.0 and later.).
5901 </quote>
5903 &s.code;void vgaHWSave(ScrnInfoPtr pScrn, vgaRegPtr save, int flags)&e.code;
5904 <quote><p>
5905 This function saves the VGA state. The state is written to the
5906 &s.code;vgaRegRec&e.code; pointed to by &s.code;save&e.code;.
5907 &s.code;flags&e.code; is set to one or more of the following flags
5908 ORed together:
5910 &s.code;VGA_SR_MODE&e.code;
5911 <quote>the mode setting registers are saved</quote>
5912 &s.code;VGA_SR_FONTS&e.code;
5913 <quote>the text mode font/text data is saved</quote>
5914 &s.code;VGA_SR_CMAP&e.code;
5915 <quote>the colourmap (LUT) is saved</quote>
5916 &s.code;VGA_SR_ALL&e.code;
5917 <quote>all of the above are saved</quote>
5919 The &s.code;vgaHWRec&e.code; and its &s.code;IOBase&e.code; fields
5920 must be initialised before this function is called. If
5921 &s.code;VGA_SR_FONTS&e.code; is set in &s.code;flags&e.code;, the
5922 VGA memory window must be mapped. If it isn't then
5923 &s.code;vgaHWMapMem()&e.code; will be called to map it, and
5924 &s.code;vgaHWUnmapMem()&e.code; will be called to unmap it
5925 afterwards. &s.code;vgaHWSave()&e.code; uses the three functions
5926 below in the order &s.code;vgaHWSaveColormap()&e.code;,
5927 &s.code;vgaHWSaveMode()&e.code;, &s.code;vgaHWSaveFonts()&e.code; to
5928 carry out the different save phases. It is undecided at this
5929 stage whether they will remain part of the vgahw module's public
5930 interface or not.
5932 </quote>
5934 &s.code;void vgaHWSaveMode(ScrnInfoPtr pScrn, vgaRegPtr save)&e.code;
5935 <quote><p>
5936 This function saves the VGA mode registers. They are saved to
5937 the &s.code;vgaRegRec&e.code; pointed to by &s.code;save&e.code;.
5938 The registers saved are:
5940 <quote>
5941 &s.code;MiscOut&nl;
5942 CRTC[0-0x18]&nl;
5943 Attribute[0-0x14]&nl;
5944 Graphics[0-8]&nl;
5945 Sequencer[0-4]&e.code;
5946 </quote>
5948 The number of registers actually saved may be modified by a prior call
5949 to &s.code;vgaHWSetRegCounts()&e.code;.
5951 </quote>
5953 &s.code;void vgaHWSaveFonts(ScrnInfoPtr pScrn, vgaRegPtr save)&e.code;
5954 <quote><p>
5955 This function saves the text mode font and text data held in the
5956 video memory. If called while in a graphics mode, no save is
5957 done. The VGA memory window must be mapped with
5958 &s.code;vgaHWMapMem()&e.code; before to calling this function.
5960 On some platforms, one or more of the font/text plane saves may be
5961 no-ops. This is the case when the platform's VC driver already
5962 takes care of this.
5964 </quote>
5966 &s.code;void vgaHWSaveColormap(ScrnInfoPtr pScrn, vgaRegPtr save)&e.code;
5967 <quote><p>
5968 This function saves the VGA colourmap (LUT). Before saving it, it
5969 attempts to verify that the colourmap is readable. In rare cases
5970 where it isn't readable, a default colourmap is saved instead.
5972 </quote>
5974 &s.code;void vgaHWRestore(ScrnInfoPtr pScrn, vgaRegPtr restore, int flags)&e.code;
5975 <quote><p>
5976 This function programs the VGA state. The state programmed is
5977 that contained in the &s.code;vgaRegRec&e.code; pointed to by
5978 &s.code;restore&e.code;. &s.code;flags&e.code; is the same
5979 as described above for the &s.code;vgaHWSave()&e.code; function.
5981 The &s.code;vgaHWRec&e.code; and its &s.code;IOBase&e.code; fields
5982 must be initialised before this function is called. If
5983 &s.code;VGA_SR_FONTS&e.code; is set in &s.code;flags&e.code;, the
5984 VGA memory window must be mapped. If it isn't then
5985 &s.code;vgaHWMapMem()&e.code; will be called to map it, and
5986 &s.code;vgaHWUnmapMem()&e.code; will be called to unmap it
5987 afterwards. &s.code;vgaHWRestore()&e.code; uses the three functions
5988 below in the order &s.code;vgaHWRestoreFonts()&e.code;,
5989 &s.code;vgaHWRestoreMode()&e.code;,
5990 &s.code;vgaHWRestoreColormap()&e.code; to carry out the different
5991 restore phases. It is undecided at this stage whether they will
5992 remain part of the vgahw module's public interface or not.
5994 </quote>
5996 &s.code;void vgaHWRestoreMode(ScrnInfoPtr pScrn, vgaRegPtr restore)&e.code;
5997 <quote><p>
5998 This function restores the VGA mode registers. They are restored
5999 from the data in the &s.code;vgaRegRec&e.code; pointed to by
6000 &s.code;restore&e.code;. The registers restored are:
6002 <quote>
6003 &s.code;MiscOut&nl;
6004 CRTC[0-0x18]&nl;
6005 Attribute[0-0x14]&nl;
6006 Graphics[0-8]&nl;
6007 Sequencer[0-4]&e.code;
6008 </quote>
6010 The number of registers actually restored may be modified by a prior call
6011 to &s.code;vgaHWSetRegCounts()&e.code;.
6013 </quote>
6015 &s.code;void vgaHWRestoreFonts(ScrnInfoPtr pScrn, vgaRegPtr restore)&e.code;
6016 <quote><p>
6017 This function restores the text mode font and text data to the
6018 video memory. The VGA memory window must be mapped with
6019 &s.code;vgaHWMapMem()&e.code; before to calling this function.
6021 On some platforms, one or more of the font/text plane restores
6022 may be no-ops. This is the case when the platform's VC driver
6023 already takes care of this.
6025 </quote>
6027 &s.code;void vgaHWRestoreColormap(ScrnInfoPtr pScrn, vgaRegPtr restore)&e.code;
6028 <quote><p>
6029 This function restores the VGA colourmap (LUT).
6031 </quote>
6033 &s.code;void vgaHWInit(ScrnInfoPtr pScrn, DisplayModePtr mode)&e.code;
6034 <quote><p>
6035 This function fills in the &s.code;vgaHWRec&e.code;'s
6036 &s.code;ModeReg&e.code; field with the values appropriate for
6037 programming the given video mode. It requires that the
6038 &s.code;ScrnInfoRec&e.code;'s &s.code;depth&e.code; field is
6039 initialised, which determines how the registers are programmed.
6041 </quote>
6043 &s.code;void vgaHWSeqReset(vgaHWPtr hwp, Bool start)&e.code;
6044 <quote><p>
6045 Do a VGA sequencer reset. If start is &s.code;TRUE&e.code;, the
6046 reset is started. If start is &s.code;FALSE&e.code;, the reset
6047 is ended.
6049 </quote>
6051 &s.code;void vgaHWProtect(ScrnInfoPtr pScrn, Bool on)&e.code;
6052 <quote><p>
6053 This function protects VGA registers and memory from corruption
6054 during loads. It is typically called with on set to
6055 &s.code;TRUE&e.code; before programming, and with on set to
6056 &s.code;FALSE&e.code; after programming.
6058 </quote>
6060 &s.code;Bool vgaHWSaveScreen(ScreenPtr pScreen, int mode)&e.code;
6061 <quote><p>
6062 This function blanks and unblanks the screen. It is blanked when
6063 &s.code;mode&e.code; is &s.code;SCREEN_SAVER_ON&e.code; or
6064 &s.code;SCREEN_SAVER_CYCLE&e.code;, and unblanked when
6065 &s.code;mode&e.code; is &s.code;SCREEN_SAVER_OFF&e.code; or
6066 &s.code;SCREEN_SAVER_FORCER&e.code;.
6068 </quote>
6070 &s.code;void vgaHWBlankScreen(ScrnInfoPtr pScrn, Bool on)&e.code;
6071 <quote><p>
6072 This function blanks and unblanks the screen. It is blanked when
6073 &s.code;on&e.code; is &s.code;FALSE&e.code;, and unblanked when
6074 &s.code;on&e.code; is &s.code;TRUE&e.code;. This function is
6075 provided for use in cases where the &s.code;ScrnInfoRec&e.code;
6076 can't be derived from the &s.code;ScreenRec&e.code; (while probing
6077 for clocks, for example).
6079 </quote>
6080 </quote>
6082 <sect1>VGA Colormap Functions
6085 The vgahw module uses the standard colormap support (see the
6086 <ref id="cmap" name="Colormap Handling"> section. This is initialised
6087 with the following function:
6089 <quote>
6090 &s.code;Bool vgaHWHandleColormaps(ScreenPtr pScreen)&e.code;
6091 </quote>
6094 <sect1>VGA Register Access Functions
6097 The vgahw module abstracts access to the standard VGA registers by
6098 using a set of functions held in the &s.code;vgaHWRec&e.code;. When
6099 the &s.code;vgaHWRec&e.code; is created these function pointers are
6100 initialised with the set of standard VGA I/O register access functions.
6101 In addition to these, the vgahw module includes a basic set of MMIO
6102 register access functions, and the &s.code;vgaHWRec&e.code; function
6103 pointers can be initialised to these by calling the
6104 &s.code;vgaHWSetMmioFuncs()&e.code; function described above. Some
6105 drivers/platforms may require a different set of functions for VGA
6106 access. The access functions are described here.
6109 <quote><p>
6110 &s.code;void writeCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value)&e.code;
6111 <quote><p>
6112 Write &s.code;value&e.code; to CRTC register &s.code;index&e.code;.
6114 </quote>
6116 &s.code;CARD8 readCrtc(vgaHWPtr hwp, CARD8 index)&e.code;
6117 <quote><p>
6118 Return the value read from CRTC register &s.code;index&e.code;.
6120 </quote>
6122 &s.code;void writeGr(vgaHWPtr hwp, CARD8 index, CARD8 value)&e.code;
6123 <quote><p>
6124 Write &s.code;value&e.code; to Graphics Controller register
6125 &s.code;index&e.code;.
6127 </quote>
6129 &s.code;CARD8 readGR(vgaHWPtr hwp, CARD8 index)&e.code;
6130 <quote><p>
6131 Return the value read from Graphics Controller register
6132 &s.code;index&e.code;.
6134 </quote>
6136 &s.code;void writeSeq(vgaHWPtr hwp, CARD8 index, CARD8, value)&e.code;
6137 <quote><p>
6138 Write &s.code;value&e.code; to Sequencer register
6139 &s.code;index&e.code;.
6141 </quote>
6143 &s.code;CARD8 readSeq(vgaHWPtr hwp, CARD8 index)&e.code;
6144 <quote><p>
6145 Return the value read from Sequencer register &s.code;index&e.code;.
6147 </quote>
6149 &s.code;void writeAttr(vgaHWPtr hwp, CARD8 index, CARD8, value)&e.code;
6150 <quote><p>
6151 Write &s.code;value&e.code; to Attribute Controller register
6152 &s.code;index&e.code;. When writing out the index value this
6153 function should set bit 5 (&s.code;0x20&e.code;) according to the
6154 setting of &s.code;hwp-&gt;paletteEnabled&e.code; in order to
6155 preserve the palette access state. It should be cleared when
6156 &s.code;hwp-&gt;paletteEnabled&e.code; is &s.code;TRUE&e.code;
6157 and set when it is &s.code;FALSE&e.code;.
6159 </quote>
6161 &s.code;CARD8 readAttr(vgaHWPtr hwp, CARD8 index)&e.code;
6162 <quote><p>
6163 Return the value read from Attribute Controller register
6164 &s.code;index&e.code;. When writing out the index value this
6165 function should set bit 5 (&s.code;0x20&e.code;) according to the
6166 setting of &s.code;hwp-&gt;paletteEnabled&e.code; in order to
6167 preserve the palette access state. It should be cleared when
6168 &s.code;hwp-&gt;paletteEnabled&e.code; is &s.code;TRUE&e.code;
6169 and set when it is &s.code;FALSE&e.code;.
6171 </quote>
6173 &s.code;void writeMiscOut(vgaHWPtr hwp, CARD8 value)&e.code;
6174 <quote><p>
6175 Write `&s.code;value&e.code;' to the Miscellaneous Output register.
6177 </quote>
6179 &s.code;CARD8 readMiscOut(vgwHWPtr hwp)&e.code;
6180 <quote><p>
6181 Return the value read from the Miscellaneous Output register.
6183 </quote>
6185 &s.code;void enablePalette(vgaHWPtr hwp)&e.code;
6186 <quote><p>
6187 Clear the palette address source bit in the Attribute Controller
6188 index register and set &s.code;hwp-&gt;paletteEnabled&e.code; to
6189 &s.code;TRUE&e.code;.
6191 </quote>
6193 &s.code;void disablePalette(vgaHWPtr hwp)&e.code;
6194 <quote><p>
6195 Set the palette address source bit in the Attribute Controller
6196 index register and set &s.code;hwp-&gt;paletteEnabled&e.code; to
6197 &s.code;FALSE&e.code;.
6199 </quote>
6201 &s.code;void writeDacMask(vgaHWPtr hwp, CARD8 value)&e.code;
6202 <quote><p>
6203 Write &s.code;value&e.code; to the DAC Mask register.
6205 </quote>
6207 &s.code;CARD8 readDacMask(vgaHWptr hwp)&e.code;
6208 <quote><p>
6209 Return the value read from the DAC Mask register.
6211 </quote>
6213 &s.code;void writeDacReadAddress(vgaHWPtr hwp, CARD8 value)&e.code;
6214 <quote><p>
6215 Write &s.code;value&e.code; to the DAC Read Address register.
6217 </quote>
6219 &s.code;void writeDacWriteAddress(vgaHWPtr hwp, CARD8 value)&e.code;
6220 <quote><p>
6221 Write &s.code;value&e.code; to the DAC Write Address register.
6223 </quote>
6225 &s.code;void writeDacData(vgaHWPtr hwp, CARD8 value)&e.code;
6226 <quote><p>
6227 Write &s.code;value&e.code; to the DAC Data register.
6229 </quote>
6231 &s.code;CARD8 readDacData(vgaHWptr hwp)&e.code;
6232 <quote><p>
6233 Return the value read from the DAC Data register.
6235 </quote>
6237 &s.code;CARD8 readEnable(vgaHWptr hwp)&e.code;
6238 <quote><p>
6239 Return the value read from the VGA Enable register. (Note: This
6240 function is present in XFree86 4.1.0 and later.)
6242 </quote>
6244 &s.code;void writeEnable(vgaHWPtr hwp, CARD8 value)&e.code;
6245 <quote><p>
6246 Write &s.code;value&e.code; to the VGA Enable register. (Note: This
6247 function is present in XFree86 4.1.0 and later.)
6249 </quote>
6250 </quote>
6252 <sect>Some notes about writing a driver<label id="sample">
6255 <em>NOTE: some parts of this are not up to date</em>
6257 The following is an outline for writing a basic unaccelerated driver
6258 for a PCI video card with a linear mapped framebuffer, and which has a
6259 VGA core. It is includes some general information that is relevant to
6260 most drivers (even those which don't fit that basic description).
6262 The information here is based on the initial conversion of the Matrox
6263 Millennium driver to the ``new design''. For a fleshing out and sample
6264 implementation of some of the bits outlined here, refer to that driver.
6265 Note that this is an example only. The approach used here will not be
6266 appropriate for all drivers.
6268 Each driver must reserve a unique driver name, and a string that is used
6269 to prefix all of its externally visible symbols. This is to avoid name
6270 space clashes when loading multiple drivers. The examples here are for
6271 the ``ZZZ'' driver, which uses the ``ZZZ'' or ``zzz'' prefix for its externally
6272 visible symbols.
6275 <sect1>Include files
6278 All drivers normally include the following headers:
6279 <quote>
6280 &s.code;"xf86.h"&nl;
6281 "xf86_OSproc.h"&nl;
6282 "xf86_ansic.h"&nl;
6283 "xf86Resources.h"&e.code;
6284 </quote>
6285 Wherever inb/outb (and related things) are used the following should be
6286 included:
6287 <quote>
6288 &s.code;"compiler.h"&e.code;
6289 </quote>
6290 Note: in drivers, this must be included after &s.code;"xf86_ansic.h"&e.code;.
6292 Drivers that need to access PCI vendor/device definitions need this:
6293 <quote>
6294 &s.code;"xf86PciInfo.h"&e.code;
6295 </quote>
6297 Drivers that need to access the PCI config space need this:
6298 <quote>
6299 &s.code;"xf86Pci.h"&e.code;
6300 </quote>
6302 Drivers using the mi banking wrapper need:
6304 <quote>
6305 &s.code;"mibank.h"&e.code;
6306 </quote>
6308 Drivers that initialise a SW cursor need this:
6309 <quote>
6310 &s.code;"mipointer.h"&e.code;
6311 </quote>
6313 All drivers implementing backing store need this:
6314 <quote>
6315 &s.code;"mibstore.h"&e.code;
6316 </quote>
6318 All drivers using the mi colourmap code need this:
6319 <quote>
6320 &s.code;"micmap.h"&e.code;
6321 </quote>
6323 If a driver uses the vgahw module, it needs this:
6324 <quote>
6325 &s.code;"vgaHW.h"&e.code;
6326 </quote>
6328 Drivers supporting VGA or Hercules monochrome screens need:
6329 <quote>
6330 &s.code;"xf1bpp.h"&e.code;
6331 </quote>
6333 Drivers supporting VGA or EGC 16-colour screens need:
6334 <quote>
6335 &s.code;"xf4bpp.h"&e.code;
6336 </quote>
6338 Drivers using cfb need:
6339 <quote>
6340 &s.code;#define PSZ 8&nl;
6341 #include "cfb.h"&nl;
6342 #undef PSZ&e.code;
6343 </quote>
6345 Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
6346 <quote>
6347 &s.code;"cfb16.h"&nl;
6348 "cfb24.h"&nl;
6349 "cfb32.h"&e.code;
6350 </quote>
6352 The driver's own header file:
6353 <quote>
6354 &s.code;"zzz.h"&e.code;
6355 </quote>
6357 Drivers must NOT include the following:
6359 <quote>
6360 &s.code;"xf86Priv.h"&nl;
6361 "xf86Privstr.h"&nl;
6362 "xf86_libc.h"&nl;
6363 "xf86_OSlib.h"&nl;
6364 "Xos.h"&e.code;&nl;
6365 any OS header
6366 </quote>
6369 <sect1>Data structures and initialisation
6372 <itemize>
6373 <item>The following macros should be defined:
6374 <code>
6375 #define VERSION <version-as-an-int>
6376 #define ZZZ_NAME "ZZZ" /* the name used to prefix messages */
6377 #define ZZZ_DRIVER_NAME "zzz" /* the driver name as used in config file */
6378 #define ZZZ_MAJOR_VERSION <int>
6379 #define ZZZ_MINOR_VERSION <int>
6380 #define ZZZ_PATCHLEVEL <int>
6381 </code>
6383 NOTE: &s.code;ZZZ_DRIVER_NAME&e.code; should match the name of the
6384 driver module without things like the "lib" prefix, the "_drv" suffix
6385 or filename extensions.
6388 <item>A DriverRec must be defined, which includes the functions required
6389 at the pre-probe phase. The name of this DriverRec must be an
6390 upper-case version of ZZZ_DRIVER_NAME (for the purposes of static
6391 linking).
6393 <code>
6394 DriverRec ZZZ = {
6395 VERSION,
6396 ZZZ_DRIVER_NAME,
6397 ZZZIdentify,
6398 ZZZProbe,
6399 ZZZAvailableOptions,
6400 NULL,
6403 </code>
6405 <item>Define list of supported chips and their matching ID:
6407 <code>
6408 static SymTabRec ZZZChipsets[] = {
6409 { PCI_CHIP_ZZZ1234, "zzz1234a" },
6410 { PCI_CHIP_ZZZ5678, "zzz5678a" },
6411 { -1, NULL }
6413 </code>
6415 The token field may be any integer value that the driver may use to
6416 uniquely identify the supported chipsets. For drivers that support
6417 only PCI devices using the PCI device IDs might be a natural choice,
6418 but this isn't mandatory. For drivers that support both PCI and other
6419 devices (like ISA), some other ID should probably used. When other
6420 IDs are used as the tokens it is recommended that the names be
6421 defined as an &s.code;enum&e.code; type.
6423 <item>If the driver uses the &s.code;xf86MatchPciInstances(&e.code;)
6424 helper (recommended for drivers that support PCI cards) a list that
6425 maps PCI IDs to chip IDs and fixed resources must be defined:
6427 <code>
6428 static PciChipsets ZZZPciChipsets[] = {
6429 { PCI_CHIP_ZZZ1234, PCI_CHIP_ZZZ1234, RES_SHARED_VGA },
6430 { PCI_CHIP_ZZZ5678, PCI_CHIP_ZZZ5678, RES_SHARED_VGA },
6431 { -1, -1, RES_UNDEFINED }
6433 </code>
6435 <item>Define the &s.code;XF86ModuleVersionInfo&e.code; struct for the
6436 driver. This is required for the dynamically loaded version:
6438 <code>
6439 static XF86ModuleVersionInfo zzzVersRec =
6441 "zzz",
6442 MODULEVENDORSTRING,
6443 MODINFOSTRING1,
6444 MODINFOSTRING2,
6445 XF86_VERSION_CURRENT,
6446 ZZZ_MAJOR_VERSION, ZZZ_MINOR_VERSION, ZZZ_PATCHLEVEL,
6447 ABI_CLASS_VIDEODRV,
6448 ABI_VIDEODRV_VERSION,
6449 MOD_CLASS_VIDEODRV,
6450 {0,0,0,0}
6452 </code>
6454 <item>Define a data structure to hold the driver's screen-specific data.
6455 This must be used instead of global variables. This would be defined
6456 in the &s.code;"zzz.h"&e.code; file, something like:
6458 <code>
6459 typedef struct {
6460 type1 field1;
6461 type2 field2;
6462 int fooHack;
6463 Bool pciRetry;
6464 Bool noAccel;
6465 Bool hwCursor;
6466 CloseScreenProcPtr CloseScreen;
6467 OptionInfoPtr Options;
6469 } ZZZRec, *ZZZPtr;
6470 </code>
6472 <item>Define the list of config file Options that the driver accepts. For
6473 consistency between drivers those in the list of ``standard'' options
6474 should be used where appropriate before inventing new options.
6476 <code>
6477 typedef enum {
6478 OPTION_FOO_HACK,
6479 OPTION_PCI_RETRY,
6480 OPTION_HW_CURSOR,
6481 OPTION_NOACCEL
6482 } ZZZOpts;
6484 static const OptionInfoRec ZZZOptions[] = {
6485 { OPTION_FOO_HACK, "FooHack", OPTV_INTEGER, {0}, FALSE },
6486 { OPTION_PCI_RETRY, "PciRetry", OPTV_BOOLEAN, {0}, FALSE },
6487 { OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, FALSE },
6488 { OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE },
6489 { -1, NULL, OPTV_NONE, {0}, FALSE }
6491 </code>
6493 </itemize>
6495 <sect1>Functions
6499 <sect2>SetupProc
6502 For dynamically loaded modules, a &s.code;ModuleData&e.code;
6503 variable is required. It is should be the name of the driver
6504 prepended to "ModuleData". A &s.code;Setup()&e.code; function is
6505 also required, which calls &s.code;xf86AddDriver()&e.code; to add
6506 the driver to the main list of drivers.
6508 <code>
6509 static MODULESETUPPROTO(zzzSetup);
6511 XF86ModuleData zzzModuleData = { &amp;zzzVersRec, zzzSetup, NULL };
6513 static pointer
6514 zzzSetup(pointer module, pointer opts, int *errmaj, int *errmin)
6516 static Bool setupDone = FALSE;
6518 /* This module should be loaded only once, but check to be sure. */
6520 if (!setupDone) {
6522 * Modules that this driver always requires may be loaded
6523 * here by calling LoadSubModule().
6526 setupDone = TRUE;
6527 xf86AddDriver(&amp;MGA, module, 0);
6530 * The return value must be non-NULL on success even though
6531 * there is no TearDownProc.
6533 return (pointer)1;
6534 } else {
6535 if (errmaj) *errmaj = LDR_ONCEONLY;
6536 return NULL;
6539 </code>
6541 <sect2>GetRec, FreeRec
6544 A function is usually required to allocate the driver's
6545 screen-specific data structure and hook it into the
6546 &s.code;ScrnInfoRec&e.code;'s &s.code;driverPrivate&e.code; field.
6547 The &s.code;ScrnInfoRec&e.code;'s &s.code;driverPrivate&e.code; is
6548 initialised to &s.code;NULL&e.code;, so it is easy to check if the
6549 initialisation has already been done. After allocating it, initialise
6550 the fields. By using &s.code;xnfcalloc()&e.code; to do the allocation
6551 it is zeroed, and if the allocation fails the server exits.
6553 NOTE:
6554 When allocating structures from inside the driver which are defined
6555 on the common level it is important to initialize the structure to
6556 zero.
6557 Only this guarantees that the server remains source compatible to
6558 future changes in common level structures.
6560 <code>
6561 static Bool
6562 ZZZGetRec(ScrnInfoPtr pScrn)
6564 if (pScrn->driverPrivate != NULL)
6565 return TRUE;
6566 pScrn->driverPrivate = xnfcalloc(sizeof(ZZZRec), 1);
6567 /* Initialise as required */
6569 return TRUE;
6571 </code>
6573 Define a macro in &s.code;"zzz.h"&e.code; which gets a pointer to
6574 the &s.code;ZZZRec&e.code; when given &s.code;pScrn&e.code;:
6576 <code>
6577 #define ZZZPTR(p) ((ZZZPtr)((p)->driverPrivate))
6578 </code>
6580 Define a function to free the above, setting it to &s.code;NULL&e.code;
6581 once it has been freed:
6583 <code>
6584 static void
6585 ZZZFreeRec(ScrnInfoPtr pScrn)
6587 if (pScrn->driverPrivate == NULL)
6588 return;
6589 xfree(pScrn->driverPrivate);
6590 pScrn->driverPrivate = NULL;
6592 </code>
6594 <sect2>Identify
6597 Define the &s.code;Identify()&e.code; function. It is run before
6598 the Probe, and typically prints out an identifying message, which
6599 might include the chipsets it supports. This function is mandatory:
6601 <code>
6602 static void
6603 ZZZIdentify(int flags)
6605 xf86PrintChipsets(ZZZ_NAME, "driver for ZZZ Tech chipsets",
6606 ZZZChipsets);
6608 </code>
6610 <sect2>Probe
6613 Define the &s.code;Probe()&e.code; function. The purpose of this
6614 is to find all instances of the hardware that the driver supports,
6615 and for the ones not already claimed by another driver, claim the
6616 slot, and allocate a &s.code;ScrnInfoRec&e.code;. This should be
6617 a minimal probe, and it should under no circumstances leave the
6618 state of the hardware changed. Because a device is found, don't
6619 assume that it will be used. Don't do any initialisations other
6620 than the required &s.code;ScrnInfoRec&e.code; initialisations.
6621 Don't allocate any new data structures.
6623 This function is mandatory.
6625 NOTE: The &s.code;xf86DrvMsg()&e.code; functions cannot be used from
6626 the Probe.
6628 <code>
6629 static Bool
6630 ZZZProbe(DriverPtr drv, int flags)
6632 Bool foundScreen = FALSE;
6633 int numDevSections, numUsed;
6634 GDevPtr *devSections;
6635 int *usedChips;
6636 int i;
6639 * Find the config file Device sections that match this
6640 * driver, and return if there are none.
6642 if ((numDevSections = xf86MatchDevice(ZZZ_DRIVER_NAME,
6643 &amp;devSections)) <= 0) {
6644 return FALSE;
6648 * Since this is a PCI card, "probing" just amounts to checking
6649 * the PCI data that the server has already collected. If there
6650 * is none, return.
6652 * Although the config file is allowed to override things, it
6653 * is reasonable to not allow it to override the detection
6654 * of no PCI video cards.
6656 * The provided xf86MatchPciInstances() helper takes care of
6657 * the details.
6659 /* test if PCI bus present */
6660 if (xf86GetPciVideoInfo()) {
6662 numUsed = xf86MatchPciInstances(ZZZ_NAME, PCI_VENDOR_ZZZ,
6663 ZZZChipsets, ZZZPciChipsets, devSections,
6664 numDevSections, drv, &amp;usedChips);
6666 for (i = 0; i < numUsed; i++) {
6667 ScrnInfoPtr pScrn = NULL;
6668 if ((pScrn = xf86ConfigPciEntity(pScrn, flags, usedChips[i],
6669 ZZZPciChipsets, NULL, NULL,
6670 NULL, NULL, NULL))) {
6671 /* Allocate a ScrnInfoRec */
6672 pScrn->driverVersion = VERSION;
6673 pScrn->driverName = ZZZ_DRIVER_NAME;
6674 pScrn->name = ZZZ_NAME;
6675 pScrn->Probe = ZZZProbe;
6676 pScrn->PreInit = ZZZPreInit;
6677 pScrn->ScreenInit = ZZZScreenInit;
6678 pScrn->SwitchMode = ZZZSwitchMode;
6679 pScrn->AdjustFrame = ZZZAdjustFrame;
6680 pScrn->EnterVT = ZZZEnterVT;
6681 pScrn->LeaveVT = ZZZLeaveVT;
6682 pScrn->FreeScreen = ZZZFreeScreen;
6683 pScrn->ValidMode = ZZZValidMode;
6684 foundScreen = TRUE;
6685 /* add screen to entity */
6688 xfree(usedChips);
6691 #ifdef HAS_ISA_DEVS
6693 * If the driver supports ISA hardware, the following block
6694 * can be included too.
6696 numUsed = xf86MatchIsaInstances(ZZZ_NAME, ZZZChipsets,
6697 ZZZIsaChipsets, drv, ZZZFindIsaDevice,
6698 devSections, numDevSections, &amp;usedChips);
6699 for (i = 0; i < numUsed; i++) {
6700 ScrnInfoPtr pScrn = NULL;
6701 if ((pScrn = xf86ConfigIsaEntity(pScrn, flags, usedChips[i],
6702 ZZZIsaChipsets, NULL, NULL, NULL,
6703 NULL, NULL))) {
6704 pScrn->driverVersion = VERSION;
6705 pScrn->driverName = ZZZ_DRIVER_NAME;
6706 pScrn->name = ZZZ_NAME;
6707 pScrn->Probe = ZZZProbe;
6708 pScrn->PreInit = ZZZPreInit;
6709 pScrn->ScreenInit = ZZZScreenInit;
6710 pScrn->SwitchMode = ZZZSwitchMode;
6711 pScrn->AdjustFrame = ZZZAdjustFrame;
6712 pScrn->EnterVT = ZZZEnterVT;
6713 pScrn->LeaveVT = ZZZLeaveVT;
6714 pScrn->FreeScreen = ZZZFreeScreen;
6715 pScrn->ValidMode = ZZZValidMode;
6716 foundScreen = TRUE;
6719 xfree(usedChips);
6720 #endif /* HAS_ISA_DEVS */
6722 xfree(devSections);
6723 return foundScreen;
6724 </code>
6726 <sect2>AvailableOptions
6729 Define the &s.code;AvailableOptions()&e.code; function. The purpose
6730 of this is to return the available driver options back to the
6731 -configure option, so that an xorg.conf file can be built and the
6732 user can see which options are available for them to use.
6734 <sect2>PreInit
6737 Define the &s.code;PreInit()&e.code; function. The purpose of
6738 this is to find all the information required to determine if the
6739 configuration is usable, and to initialise those parts of the
6740 &s.code;ScrnInfoRec&e.code; that can be set once at the beginning
6741 of the first server generation. The information should be found in
6742 the least intrusive way possible.
6744 This function is mandatory.
6746 NOTES:
6747 <enum>
6748 <item>The &s.code;PreInit()&e.code; function is only called once
6749 during the life of the X server (at the start of the first
6750 generation).
6752 <item>Data allocated here must be of the type that persists for
6753 the life of the X server. This means that data that hooks into
6754 the &s.code;ScrnInfoRec&e.code;'s &s.code;privates&e.code;
6755 field should be allocated here, but data that hooks into the
6756 &s.code;ScreenRec&e.code;'s &s.code;devPrivates&e.code; field
6757 should not be allocated here. The &s.code;driverPrivate&e.code;
6758 field should also be allocated here.
6760 <item>Although the &s.code;ScrnInfoRec&e.code; has been allocated
6761 before this function is called, the &s.code;ScreenRec&e.code;
6762 has not been allocated. That means that things requiring it
6763 cannot be used in this function.
6765 <item>Very little of the &s.code;ScrnInfoRec&e.code; has been
6766 initialised when this function is called. It is important to
6767 get the order of doing things right in this function.
6769 </enum>
6771 <code>
6772 static Bool
6773 ZZZPreInit(ScrnInfoPtr pScrn, int flags)
6775 /* Fill in the monitor field */
6776 pScrn->monitor = pScrn->confScreen->monitor;
6779 * If using the vgahw module, it will typically be loaded
6780 * here by calling xf86LoadSubModule(pScrn, "vgahw");
6784 * Set the depth/bpp. Use the globally preferred depth/bpp. If the
6785 * driver has special default depth/bpp requirements, the defaults should
6786 * be specified here explicitly.
6787 * We support both 24bpp and 32bpp framebuffer layouts.
6788 * This sets pScrn->display also.
6790 if (!xf86SetDepthBpp(pScrn, 0, 0, 0,
6791 Support24bppFb | Support32bppFb)) {
6792 return FALSE;
6793 } else {
6794 if (depth/bpp isn't one we support) {
6795 print error message;
6796 return FALSE;
6799 /* Print out the depth/bpp that was set */
6800 xf86PrintDepthBpp(pScrn);
6802 /* Set bits per RGB for 8bpp */
6803 if (pScrn->depth <= 8) {
6804 /* Take into account a dac_6_bit option here */
6805 pScrn->rgbBits = 6 or 8;
6809 * xf86SetWeight() and xf86SetDefaultVisual() must be called
6810 * after pScrn->display is initialised.
6813 /* Set weight/mask/offset for depth > 8 */
6814 if (pScrn->depth > 8) {
6815 if (!xf86SetWeight(pScrn, defaultWeight, defaultMask)) {
6816 return FALSE;
6817 } else {
6818 if (weight isn't one we support) {
6819 print error message;
6820 return FALSE;
6825 /* Set the default visual. */
6826 if (!xf86SetDefaultVisual(pScrn, -1)) {
6827 return FALSE;
6828 } else {
6829 if (visual isn't one we support) {
6830 print error message;
6831 return FALSE;
6835 /* If the driver supports gamma correction, set the gamma. */
6836 if (!xf86SetGamma(pScrn, default_gamma)) {
6837 return FALSE;
6840 /* This driver uses a programmable clock */
6841 pScrn->progClock = TRUE;
6843 /* Allocate the ZZZRec driverPrivate */
6844 if (!ZZZGetRec(pScrn)) {
6845 return FALSE;
6848 pZzz = ZZZPTR(pScrn);
6850 /* Collect all of the option flags (fill in pScrn->options) */
6851 xf86CollectOptions(pScrn, NULL);
6854 * Process the options based on the information in ZZZOptions.
6855 * The results are written to pZzz->Options. If all of the options
6856 * processing is done within this function a local variable "options"
6857 * can be used instead of pZzz->Options.
6859 if (!(pZzz->Options = xalloc(sizeof(ZZZOptions))))
6860 return FALSE;
6861 (void)memcpy(pZzz->Options, ZZZOptions, sizeof(ZZZOptions));
6862 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pZzz->Options);
6865 * Set various fields of ScrnInfoRec and/or ZZZRec based on
6866 * the options found.
6868 from = X_DEFAULT;
6869 pZzz->hwCursor = FALSE;
6870 if (xf86IsOptionSet(pZzz->Options, OPTION_HW_CURSOR)) {
6871 from = X_CONFIG;
6872 pZzz->hwCursor = TRUE;
6874 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
6875 pZzz->hwCursor ? "HW" : "SW");
6876 if (xf86IsOptionSet(pZzz->Options, OPTION_NOACCEL)) {
6877 pZzz->noAccel = TRUE;
6878 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
6879 "Acceleration disabled\n");
6880 } else {
6881 pZzz->noAccel = FALSE;
6883 if (xf86IsOptionSet(pZzz->Options, OPTION_PCI_RETRY)) {
6884 pZzz->UsePCIRetry = TRUE;
6885 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "PCI retry enabled\n");
6887 pZzz->fooHack = 0;
6888 if (xf86GetOptValInteger(pZzz->Options, OPTION_FOO_HACK,
6889 &amp;pZzz->fooHack)) {
6890 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Foo Hack set to %d\n",
6891 pZzz->fooHack);
6895 * Find the PCI slot(s) that this screen claimed in the probe.
6896 * In this case, exactly one is expected, so complain otherwise.
6897 * Note in this case we're not interested in the card types so
6898 * that parameter is set to NULL.
6900 if ((i = xf86GetPciInfoForScreen(pScrn->scrnIndex, &amp;pciList, NULL))
6901 != 1) {
6902 print error message;
6903 ZZZFreeRec(pScrn);
6904 if (i > 0)
6905 xfree(pciList);
6906 return FALSE;
6908 /* Note that pciList should be freed below when no longer needed */
6911 * Determine the chipset, allowing config file chipset and
6912 * chipid values to override the probed information. The config
6913 * chipset value has precedence over its chipid value if both
6914 * are present.
6916 * It isn't necessary to fill in pScrn->chipset if the driver
6917 * keeps track of the chipset in its ZZZRec.
6923 * Determine video memory, fb base address, I/O addresses, etc,
6924 * allowing the config file to override probed values.
6926 * Set the appropriate pScrn fields (videoRam is probably the
6927 * most important one that other code might require), and
6928 * print out the settings.
6933 /* Initialise a clockRanges list. */
6937 /* Set any other chipset specific things in the ZZZRec */
6941 /* Select valid modes from those available */
6943 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
6944 pScrn->display->modes, clockRanges,
6945 NULL, minPitch, maxPitch, rounding,
6946 minHeight, maxHeight,
6947 pScrn->display->virtualX,
6948 pScrn->display->virtualY,
6949 pScrn->videoRam * 1024,
6950 LOOKUP_BEST_REFRESH);
6951 if (i == -1) {
6952 ZZZFreeRec(pScrn);
6953 return FALSE;
6956 /* Prune the modes marked as invalid */
6958 xf86PruneDriverModes(pScrn);
6960 /* If no valid modes, return */
6962 if (i == 0 || pScrn->modes == NULL) {
6963 print error message;
6964 ZZZFreeRec(pScrn);
6965 return FALSE;
6969 * Initialise the CRTC fields for the modes. This driver expects
6970 * vertical values to be halved for interlaced modes.
6972 xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V);
6974 /* Set the current mode to the first in the list. */
6975 pScrn->currentMode = pScrn->modes;
6977 /* Print the list of modes being used. */
6978 xf86PrintModes(pScrn);
6980 /* Set the DPI */
6981 xf86SetDpi(pScrn, 0, 0);
6983 /* Load bpp-specific modules */
6984 switch (pScrn->bitsPerPixel) {
6985 case 1:
6986 mod = "xf1bpp";
6987 break;
6988 case 4:
6989 mod = "xf4bpp";
6990 break;
6991 case 8:
6992 mod = "cfb";
6993 break;
6994 case 16:
6995 mod = "cfb16";
6996 break;
6997 case 24:
6998 mod = "cfb24";
6999 break;
7000 case 32:
7001 mod = "cfb32";
7002 break;
7004 if (mod && !xf86LoadSubModule(pScrn, mod))
7005 ZZZFreeRec(pScrn);
7006 return FALSE;
7008 /* Load XAA if needed */
7009 if (!pZzz->noAccel || pZzz->hwCursor)
7010 if (!xf86LoadSubModule(pScrn, "xaa")) {
7011 ZZZFreeRec(pScrn);
7012 return FALSE;
7015 /* Done */
7016 return TRUE;
7018 </code>
7020 <sect2>MapMem, UnmapMem
7023 Define functions to map and unmap the video memory and any other
7024 memory apertures required. These functions are not mandatory, but
7025 it is often useful to have such functions.
7027 <code>
7028 static Bool
7029 ZZZMapMem(ScrnInfoPtr pScrn)
7031 /* Call xf86MapPciMem() to map each PCI memory area */
7033 return TRUE or FALSE;
7036 static Bool
7037 ZZZUnmapMem(ScrnInfoPtr pScrn)
7039 /* Call xf86UnMapVidMem() to unmap each memory area */
7041 return TRUE or FALSE;
7043 </code>
7045 <sect2>Save, Restore
7048 Define functions to save and restore the original video state. These
7049 functions are not mandatory, but are often useful.
7051 <code>
7052 static void
7053 ZZZSave(ScrnInfoPtr pScrn)
7056 * Save state into per-screen data structures.
7057 * If using the vgahw module, vgaHWSave will typically be
7058 * called here.
7063 static void
7064 ZZZRestore(ScrnInfoPtr pScrn)
7067 * Restore state from per-screen data structures.
7068 * If using the vgahw module, vgaHWRestore will typically be
7069 * called here.
7073 </code>
7075 <sect2>ModeInit
7078 Define a function to initialise a new video mode. This function isn't
7079 mandatory, but is often useful.
7081 <code>
7082 static Bool
7083 ZZZModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
7086 * Program a video mode. If using the vgahw module,
7087 * vgaHWInit and vgaRestore will typically be called here.
7088 * Once up to the point where there can't be a failure
7089 * set pScrn->vtSema to TRUE.
7093 </code>
7095 <sect2>ScreenInit
7098 Define the &s.code;ScreenInit()&e.code; function. This is called
7099 at the start of each server generation, and should fill in as much
7100 of the &s.code;ScreenRec&e.code; as possible as well as any other
7101 data that is initialised once per generation. It should initialise
7102 the framebuffer layers it is using, and initialise the initial video
7103 mode.
7105 This function is mandatory.
7107 NOTE: The &s.code;ScreenRec&e.code; (&s.code;pScreen&e.code;) is
7108 passed to this driver, but it and the
7109 &s.code;ScrnInfoRecs&e.code; are not yet hooked into each
7110 other. This means that in this function, and functions it
7111 calls, one cannot be found from the other.
7113 <code>
7114 static Bool
7115 ZZZScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
7117 /* Get the ScrnInfoRec */
7118 pScrn = xf86Screens[pScreen->myNum];
7121 * If using the vgahw module, its data structures and related
7122 * things are typically initialised/mapped here.
7125 /* Save the current video state */
7126 ZZZSave(pScrn);
7128 /* Initialise the first mode */
7129 ZZZModeInit(pScrn, pScrn->currentMode);
7131 /* Set the viewport if supported */
7133 ZZZAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
7136 * Setup the screen's visuals, and initialise the framebuffer
7137 * code.
7140 /* Reset the visual list */
7141 miClearVisualTypes();
7144 * Setup the visuals supported. This driver only supports
7145 * TrueColor for bpp > 8, so the default set of visuals isn't
7146 * acceptable. To deal with this, call miSetVisualTypes with
7147 * the appropriate visual mask.
7150 if (pScrn->bitsPerPixel > 8) {
7151 if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
7152 pScrn->rgbBits, pScrn->defaultVisual))
7153 return FALSE;
7154 } else {
7155 if (!miSetVisualTypes(pScrn->depth,
7156 miGetDefaultVisualMask(pScrn->depth),
7157 pScrn->rgbBits, pScrn->defaultVisual))
7158 return FALSE;
7162 * Initialise the framebuffer.
7165 switch (pScrn->bitsPerPixel) {
7166 case 1:
7167 ret = xf1bppScreenInit(pScreen, FbBase,
7168 pScrn->virtualX, pScrn->virtualY,
7169 pScrn->xDpi, pScrn->yDpi,
7170 pScrn->displayWidth);
7171 break;
7172 case 4:
7173 ret = xf4bppScreenInit(pScreen, FbBase,
7174 pScrn->virtualX, pScrn->virtualY,
7175 pScrn->xDpi, pScrn->yDpi,
7176 pScrn->displayWidth);
7177 break;
7178 case 8:
7179 ret = cfbScreenInit(pScreen, FbBase,
7180 pScrn->virtualX, pScrn->virtualY,
7181 pScrn->xDpi, pScrn->yDpi,
7182 pScrn->displayWidth);
7183 break;
7184 case 16:
7185 ret = cfb16ScreenInit(pScreen, FbBase,
7186 pScrn->virtualX, pScrn->virtualY,
7187 pScrn->xDpi, pScrn->yDpi,
7188 pScrn->displayWidth);
7189 break;
7190 case 24:
7191 ret = cfb24ScreenInit(pScreen, FbBase,
7192 pScrn->virtualX, pScrn->virtualY,
7193 pScrn->xDpi, pScrn->yDpi,
7194 pScrn->displayWidth);
7195 break;
7196 case 32:
7197 ret = cfb32ScreenInit(pScreen, FbBase,
7198 pScrn->virtualX, pScrn->virtualY,
7199 pScrn->xDpi, pScrn->yDpi,
7200 pScrn->displayWidth);
7201 break;
7202 default:
7203 print a message about an internal error;
7204 ret = FALSE;
7205 break;
7208 if (!ret)
7209 return FALSE;
7211 /* Override the default mask/offset settings */
7212 if (pScrn->bitsPerPixel > 8) {
7213 for (i = 0, visual = pScreen->visuals;
7214 i < pScreen->numVisuals; i++, visual++) {
7215 if ((visual->class | DynamicClass) == DirectColor) {
7216 visual->offsetRed = pScrn->offset.red;
7217 visual->offsetGreen = pScrn->offset.green;
7218 visual->offsetBlue = pScrn->offset.blue;
7219 visual->redMask = pScrn->mask.red;
7220 visual->greenMask = pScrn->mask.green;
7221 visual->blueMask = pScrn->mask.blue;
7227 * If banking is needed, initialise an miBankInfoRec (defined in
7228 * "mibank.h"), and call miInitializeBanking().
7230 if (!miInitializeBanking(pScreen, pScrn->virtualX, pScrn->virtualY,
7231 pScrn->displayWidth, pBankInfo))
7232 return FALSE;
7235 * If backing store is to be supported (as is usually the case),
7236 * initialise it.
7238 miInitializeBackingStore(pScreen);
7241 * Set initial black & white colourmap indices.
7243 xf86SetBlackWhitePixels(pScreen);
7246 * Install colourmap functions. If using the vgahw module,
7247 * vgaHandleColormaps would usually be called here.
7253 * Initialise cursor functions. This example is for the mi
7254 * software cursor.
7256 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
7258 /* Initialise the default colourmap */
7259 switch (pScrn->depth) {
7260 case 1:
7261 if (!xf1bppCreateDefColormap(pScreen))
7262 return FALSE;
7263 break;
7264 case 4:
7265 if (!xf4bppCreateDefColormap(pScreen))
7266 return FALSE;
7267 break;
7268 default:
7269 if (!cfbCreateDefColormap(pScreen))
7270 return FALSE;
7271 break;
7275 * Wrap the CloseScreen vector and set SaveScreen.
7277 ZZZPTR(pScrn)->CloseScreen = pScreen->CloseScreen;
7278 pScreen->CloseScreen = ZZZCloseScreen;
7279 pScreen->SaveScreen = ZZZSaveScreen;
7281 /* Report any unused options (only for the first generation) */
7282 if (serverGeneration == 1) {
7283 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
7286 /* Done */
7287 return TRUE;
7289 </code>
7292 <sect2>SwitchMode
7295 Define the &s.code;SwitchMode()&e.code; function if mode switching
7296 is supported by the driver.
7298 <code>
7299 static Bool
7300 ZZZSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
7302 return ZZZModeInit(xf86Screens[scrnIndex], mode);
7304 </code>
7307 <sect2>AdjustFrame
7310 Define the &s.code;AdjustFrame()&e.code; function if the driver
7311 supports this.
7313 <code>
7314 static void
7315 ZZZAdjustFrame(int scrnIndex, int x, int y, int flags)
7317 /* Adjust the viewport */
7319 </code>
7322 <sect2>EnterVT, LeaveVT
7325 Define the &s.code;EnterVT()&e.code; and &s.code;LeaveVT()&e.code;
7326 functions.
7328 These functions are mandatory.
7330 <code>
7331 static Bool
7332 ZZZEnterVT(int scrnIndex, int flags)
7334 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
7335 return ZZZModeInit(pScrn, pScrn->currentMode);
7338 static void
7339 ZZZLeaveVT(int scrnIndex, int flags)
7341 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
7342 ZZZRestore(pScrn);
7344 </code>
7346 <sect2>CloseScreen
7349 Define the &s.code;CloseScreen()&e.code; function:
7351 This function is mandatory. Note that it unwraps the previously
7352 wrapped &s.code;pScreen-&gt;CloseScreen&e.code;, and finishes by
7353 calling it.
7355 <code>
7356 static Bool
7357 ZZZCloseScreen(int scrnIndex, ScreenPtr pScreen)
7359 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
7360 if (pScrn->vtSema) {
7361 ZZZRestore(pScrn);
7362 ZZZUnmapMem(pScrn);
7364 pScrn->vtSema = FALSE;
7365 pScreen->CloseScreen = ZZZPTR(pScrn)->CloseScreen;
7366 return (*pScreen->CloseScreen)(scrnIndex, pScreen);
7368 </code>
7370 <sect2>SaveScreen
7373 Define the &s.code;SaveScreen()&e.code; function (the screen
7374 blanking function). When using the vgahw module, this will typically
7377 <code>
7378 static Bool
7379 ZZZSaveScreen(ScreenPtr pScreen, int mode)
7381 return vgaHWSaveScreen(pScreen, mode);
7383 </code>
7385 This function is mandatory. Before modifying any hardware register
7386 directly this function needs to make sure that the Xserver is active
7387 by checking if &s.code;pScrn&e.code; is non-NULL and for
7388 &s.code;pScrn->vtSema == TRUE&e.code;.
7390 <sect2>FreeScreen
7393 Define the &s.code;FreeScreen()&e.code; function. This function
7394 is optional. It should be defined if the &s.code;ScrnInfoRec&e.code;
7395 &s.code;driverPrivate&e.code; field is used so that it can be freed
7396 when a screen is deleted by the common layer for reasons possibly
7397 beyond the driver's control. This function is not used in during
7398 normal (error free) operation. The per-generation data is freed by
7399 the &s.code;CloseScreen()&e.code; function.
7401 <code>
7402 static void
7403 ZZZFreeScreen(int scrnIndex, int flags)
7406 * If the vgahw module is used vgaHWFreeHWRec() would be called
7407 * here.
7409 ZZZFreeRec(xf86Screens[scrnIndex]);
7411 </code>
7414 </article>