1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
4 <!ENTITY % xorg-defs SYSTEM "defs.ent"> %xorg-defs;
5 <!ENTITY % defs SYSTEM "/xserver/doc/xml/xserver.ent"> %defs;
6 <!-- config file keyword markup -->
7 <!-- specific config file keywords -->
8 <!ENTITY k.device "<emphasis>Device</emphasis>">
9 <!ENTITY k.monitor "<emphasis>Monitor</emphasis>">
10 <!ENTITY k.display "<emphasis>Display</emphasis>">
11 <!ENTITY k.inputdevice "<emphasis>InputDevice</emphasis>">
12 <!ENTITY k.screen "<emphasis>Screen</emphasis>">
13 <!ENTITY k.serverlayout "<emphasis>ServerLayout</emphasis>">
14 <!ENTITY k.driver "<emphasis>Driver</emphasis>">
15 <!ENTITY k.module "<emphasis>Module</emphasis>">
16 <!ENTITY k.identifier "<emphasis>Identifier</emphasis>">
17 <!ENTITY k.serverflags "<emphasis>ServerFlags</emphasis>">
20 <article id="ddxDesign">
23 <title>XFree86 DDX Design</title>
26 <corpauthor>The XFree86 Project</corpauthor>
27 <corpauthor>The X.Org Foundation</corpauthor>
30 <firstname>Jim</firstname><surname>Gettys</surname>
31 <contrib>Updates for X11R6.7</contrib>
35 <pubdate>&xserver.reldate;</pubdate>
36 <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo>
37 <releaseinfo>X Server Version &xserver.version;</releaseinfo>
42 This document describes software undergoing continual evolution, and
43 the interfaces described here are subject to change without notice.
44 This document is intended to cover the interfaces as found in the
45 xorg-server-&xserver.version; release, but is probably not completely
46 in sync with the code base.
51 <title>Preface</title>
54 This document was originally the design spec for the DDX layer of the
55 XFree86 4.0 X server. The X.Org Foundation adopted the XFree86 4.4rc2
56 version of that server as the basis of the Xorg server project, and has
57 evolved the XFree86 DDX layer greatly since forking. This document thus
58 covers only the current implementation of the XFree86 DDX as found in the
59 Xorg server &xserver.version; release, and no longer matches the XFree86
64 The XFree86 Project's broad design principles for XFree86 4.0 were:
66 <listitem><para>keep it reasonable
68 <listitem><para>We cannot rewrite the complete server
70 <listitem><para>We don't want to re-invent the wheel
72 </itemizedlist></para></listitem>
73 <listitem><para>keep it modular
75 <listitem><para>As many things as possible should go into modules
77 <listitem><para>The basic loader binary should be minimal
79 <listitem><para>A clean design with well defined layering is
80 important</para></listitem>
81 <listitem><para>DDX specific global variables are a nono
83 <listitem><para>The structure should be flexible enough to allow
84 future extensions</para></listitem>
85 <listitem><para>The structure should minimize duplication of
86 common code</para></listitem>
87 </itemizedlist></para></listitem>
88 <listitem><para>keep important features in mind
90 <listitem><para>multiple screens, including multiple instances
91 of drivers</para></listitem>
92 <listitem><para>mixing different color depths and visuals on
93 different and ideally even on the same screen
95 <listitem><para>better control of the PCI device used
97 <listitem><para>better config file parser</para></listitem>
98 <listitem><para>get rid of all VGA compatibility assumptions
100 </itemizedlist></para></listitem>
105 While the XFree86 project had a goal of avoiding changes to the DIX
106 layer unless they found major deficiencies there, to avoid divergence from
107 the X.Org sample implementation they were integrating changes from, the
108 X.Org developers now maintain both sides, and make changes where they are
109 most appropriate. This document concentrates on the XFree86 DDX layer used
110 in the Xorg server itself (the code found in <filename>hw/xfree86</filename>
111 in the source tree), and developers will also want to refer to the
112 <filename>Xserver-spec</filename> documentation that covers the DIX layer
113 routines common to all the X servers in the sample implementation.
118 <title>The xorg.conf File</title>
121 The xorg.conf file format is based on the XF86Config format from XFree86 4.4,
122 which is in turn similar to the old XFree86 3.x XF86Config format, with the
127 <title>&k.device; section</title>
130 The &k.device; sections are similar to what they used to be, and
131 describe hardware-specific information for a single video card.
133 Some new keywords are added:
137 <varlistentry><term>Driver "drivername"</term>
139 Specifies the name of the driver to be used for the card. This
141 </para></listitem></varlistentry>
142 <varlistentry><term>BusID "busslot"</term>
144 Specifies uniquely the location of the card on the bus. The
145 purpose is to identify particular cards in a multi-headed
146 configuration. The format of the argument is intentionally
147 vague, and may be architecture dependent. For a PCI bus, it
148 is something like "bus:slot:func".
149 </para></listitem></varlistentry>
154 A &k.device; section is considered <quote>active</quote> if there is a reference
155 to it in an active &k.screen; section.
160 <title>&k.screen; section</title>
163 The &k.screen; sections are similar to what they used to be. They
164 no longer have a &k.driver; keyword, but an &k.identifier; keyword
165 is added. (The &k.driver; keyword may be accepted in place of the
166 &k.identifier; keyword for compatibility purposes.) The identifier
167 can be used to identify which screen is to be active when multiple
168 &k.screen; sections are present. It is possible to specify the active
169 screen from the command line. A default is chosen in the absence
170 of one being specified. A &k.screen; section is considered <quote>active</quote>
171 if there is a reference to it either from the command line, or from
172 an active &k.serverlayout; section.
177 <title>&k.inputdevice; section</title>
180 The &k.inputdevice; section is a new section that describes
181 configuration information for input devices. It replaces the old
182 <emphasis>Keyboard</emphasis>, <emphasis>Pointer</emphasis> and <emphasis>XInput</emphasis>
183 sections. Like the &k.device; section, it has two mandatory keywords:
184 &k.identifier; and &k.driver;. For compatibility purposes the old
185 <emphasis>Keyboard</emphasis> and <emphasis>Pointer</emphasis> sections are
186 converted by the parser into &k.inputdevice; sections as follows:
189 <varlistentry><term><emphasis>Keyboard</emphasis></term>
190 <listitem><literallayout>
191 &k.identifier; "Implicit Core Keyboard"
193 </literallayout></listitem></varlistentry>
194 <varlistentry><term><emphasis>Pointer</emphasis></term>
195 <listitem><literallayout>
196 &k.identifier; "Implicit Core Pointer"
198 </literallayout></listitem></varlistentry>
203 An &k.inputdevice; section is considered active if there is a
204 reference to it in an active &k.serverlayout; section. An
205 &k.inputdevice; section may also be referenced implicitly if there
206 is no &k.serverlayout; section, if the <option>-screen</option> command
207 line options is used, or if the &k.serverlayout; section doesn't
208 reference any &k.inputdevice; sections. In this case, the first
209 sections with drivers "kbd" and "mouse" are used as the core
210 keyboard and pointer respectively.
215 <title>&k.serverlayout; section</title>
218 The &k.serverlayout; section is a new section that is used to identify
219 which &k.screen; sections are to be used in a multi-headed configuration,
220 and the relative layout of those screens. It also identifies which
221 &k.inputdevice; sections are to be used. Each &k.serverlayout; section
222 has an identifier, a list of &k.screen; section identifiers, and a list of
223 &k.inputdevice; section identifiers. &k.serverflags; options may also be
224 included in a &k.serverlayout; section, making it possible to override
225 the global values in the &k.serverflags; section.
229 A &k.serverlayout; section can be made active by being referenced on
230 the command line. In the absence of this, a default will be chosen
231 (the first one found). The screen names may optionally be followed
232 by a number specifying the preferred screen number, and optionally
233 by information specifying the physical positioning of the screen,
234 either in absolute terms or relative to another screen (or screens).
235 When no screen number is specified, they are numbered according to
236 the order in which they are listed. The old (now obsolete) method
237 of providing the positioning information is to give the names of
238 the four adjacent screens. The order of these is top, bottom, left,
239 right. Here is an example of a &k.serverlayout; section for two
240 screens using the old method, with the second located to the right
244 Section "ServerLayout"
245 Identifier "Main Layout"
246 Screen 0 "Screen 1" "" "" "" "Screen 2"
254 The preferred way of specifying the layout is to explicitly specify
255 the screen's location in absolute terms or relative to another
260 In the absolute case, the upper left corner's coordinates are given
261 after the <emphasis>Absolute</emphasis> keyword. If the coordinates are
262 omitted, a value of <code>(0,0)</code> is assumed. An example
263 of absolute positioning follows:
266 Section "ServerLayout"
267 Identifier "Main Layout"
268 Screen 0 "Screen 1" Absolute 0 0
269 Screen 1 "Screen 2" Absolute 1024 0
270 Screen "Screen 3" Absolute 2048 0
276 In the relative case, the position is specified by either using one of
277 the following keywords followed by the name of the reference screen:
279 <simplelist type='vert' columns='1'>
280 <member><emphasis>RightOf</emphasis></member>
281 <member><emphasis>LeftOf</emphasis></member>
282 <member><emphasis>Above</emphasis></member>
283 <member><emphasis>Below</emphasis></member>
284 <member><emphasis>Relative</emphasis></member>
289 When the <emphasis>Relative</emphasis> keyword is used, the reference screen
290 name is followed by the coordinates of the new screen's origin
291 relative to reference screen. The following example shows how to use
292 some of the relative positioning options.
295 Section "ServerLayout"
296 Identifier "Main Layout"
298 Screen 1 "Screen 2" RightOf "Screen 1"
299 Screen "Screen 3" Relative "Screen 1" 2048 0
306 <title>Options</title>
309 Options are used more extensively. They may appear in most sections
310 now. Options related to drivers can be present in the &k.screen;,
311 &k.device; and &k.monitor; sections and the &k.display; subsections.
312 The order of precedence is &k.display;, &k.screen;, &k.monitor;,
313 &k.device;. Options have been extended to allow an optional value
314 to be specified in addition to the option name. For more details
315 about options, see the <link linkend="options">Options</link> section
322 <title>Driver Interface</title>
325 The driver interface consists of a minimal set of entry points that are
326 required based on the external events that the driver must react to.
327 No non-essential structure is imposed on the way they are used beyond
328 that. This is a significant difference compared with the old design.
332 The entry points for drawing operations are already taken care of by
333 the framebuffer code. Extensions and enhancements to framebuffer code
334 are outside the scope of this document.
338 This approach to the driver interface provides good flexibility, but does
339 increase the complexity of drivers. To help address this, the XFree86
340 common layer provides a set of <quote>helper</quote> functions to take care of things
341 that most drivers need. These helpers help minimise the amount of code
342 duplication between drivers. The use of helper functions by drivers is
343 however optional, though encouraged. The basic philosophy behind the
344 helper functions is that they should be useful to many drivers, that
345 they should balance this against the complexity of their interface. It
346 is inevitable that some drivers may find some helpers unsuitable and
347 need to provide their own code.
351 Events that a driver needs to react to are:
354 <varlistentry><term>ScreenInit</term>
357 An initialisation function is called from the DIX layer for each
358 screen at the start of each server generation.
359 </para></listitem></varlistentry>
361 <varlistentry><term>Enter VT</term>
364 The server takes control of the console.
365 </para></listitem></varlistentry>
367 <varlistentry><term>Leave VT</term>
370 The server releases control of the console.
371 </para></listitem></varlistentry>
373 <varlistentry><term>Mode Switch</term>
377 </para></listitem></varlistentry>
379 <varlistentry><term>ViewPort change</term>
382 Change the origin of the physical view port.
383 </para></listitem></varlistentry>
385 <varlistentry><term>ScreenSaver state change</term>
388 Screen saver activation/deactivation.
389 </para></listitem></varlistentry>
391 <varlistentry><term>CloseScreen</term>
394 A close screen function is called from the DIX layer for each screen
395 at the end of each server generation.
396 </para></listitem></varlistentry>
402 In addition to these events, the following functions are required by
403 the XFree86 common layer:
406 <varlistentry><term>Identify</term>
409 Print a driver identifying message.
410 </para></listitem></varlistentry>
412 <varlistentry><term>Probe</term>
415 This is how a driver identifies if there is any hardware present that
416 it knows how to drive.
417 </para></listitem></varlistentry>
419 <varlistentry><term>PreInit</term>
422 Process information from the xorg.conf file, determine the
423 full characteristics of the hardware, and determine if a valid
424 configuration is present.
425 </para></listitem></varlistentry>
430 The VidMode extension also requires:
433 <varlistentry><term>ValidMode</term>
436 Identify if a new mode is usable with the current configuration.
437 The PreInit function (and/or helpers it calls) may also make use
438 of the ValidMode function or something similar.
439 </para></listitem></varlistentry>
445 Other extensions may require other entry points. The drivers will
446 inform the common layer of these in such cases.
451 <title>Resource Access Control Introduction</title>
454 Graphics devices are accessed through ranges in I/O or memory space.
455 While most modern graphics devices allow relocation of such ranges many
456 of them still require the use of well established interfaces such as
457 VGA memory and IO ranges or 8514/A IO ranges. With modern buses (like
458 PCI) it is possible for multiple video devices to share access to these
459 resources. The RAC (Resource Access Control) subsystem provides a
464 <title>Terms and Definitions</title>
470 <quote>Bus</quote> is ambiguous as it is used for different things: it may refer
471 to physical incompatible extension connectors in a computer system.
472 The RAC system knows two such systems: The ISA bus and the PCI bus.
473 (On the software level EISA, MCA and VL buses are currently treated
474 like ISA buses). <quote>Bus</quote> may also refer to logically different
475 entities on a single bus system which are connected via bridges. A
476 PCI system may have several distinct PCI buses connecting each other
477 by PCI-PCI bridges or to the host CPU by HOST-PCI bridges.
481 Systems that host more than one bus system link these together using
482 bridges. Bridges are a concern to RAC as they might block or pass
483 specific resources. PCI-PCI bridges may be set up to pass VGA
484 resources to the secondary bus. PCI-ISA buses pass any resources not
485 decoded on the primary PCI bus to the ISA bus. This way VGA resources
486 (although exclusive on the ISA bus) can be shared by ISA and PCI
487 cards. Currently HOST-PCI bridges are not yet handled by RAC as they
488 require specific drivers.
493 <title>Entity</title>
496 The smallest independently addressable unit on a system bus is
497 referred to as an entity. So far we know ISA and PCI entities. PCI
498 entities can be located on the PCI bus by an unique ID consisting of
499 the bus, card and function number.
504 <title>Resource</title>
507 <quote>Resource</quote> refers to a range of memory or I/O addresses an entity
512 If a device is capable of disabling this decoding the resource is
513 called sharable. For PCI devices a generic method is provided to
514 control resource decoding. Other devices will have to provide a
515 device specific function to control decoding.
519 If the entity is capable of decoding this range at a different
520 location this resource is considered relocatable.
524 Resources which start at a specific address and occupy a single
525 continuous range are called block resources.
529 Alternatively resource addresses can be decoded in a way that they
530 satisfy the conditions:
532 address & mask == base
536 base & mask == base
538 Resources addressed in such a way are called sparse resources.
544 <title>Server States</title>
547 The resource access control system knows two server states: the
548 SETUP and the OPERATING state. The SETUP state is entered whenever
549 a mode change takes place or the server exits or does VT switching.
550 During this state all entity resources are under resource access
551 control. During OPERATING state only those entities are controlled
552 which actually have shared resources that conflict with others.
559 <title>Control Flow in the Server and Mandatory Driver Functions</title>
562 At the start of each server generation, <function>main()</function>
563 (<filename>dix/main.c</filename>) calls the DDX function
564 <function>InitOutput()</function>. This is the first place that the DDX gets
565 control. <function>InitOutput()</function> is expected to fill in the global
566 <structname>screenInfo</structname> struct, and one
567 <structfield>screenInfo.screen[]</structfield> entry for each screen present.
568 Here is what <function>InitOutput()</function> does:
572 <title>Parse the xorg.conf file</title>
575 This is done at the start of the first server generation only.
579 The xorg.conf file is read in full, and the resulting information
580 stored in data structures. None of the parsed information is
581 processed at this point. The parser data structures are opaque to
582 the video drivers and to most of the common layer code.
586 The entire file is parsed first to remove any section ordering
593 <title>Initial processing of parsed information and command line options
597 This is done at the start of the first server generation only.
601 The initial processing is to determine paths like the
602 <emphasis>ModulePath</emphasis>, etc, and to determine which &k.serverlayout;,
603 &k.screen; and &k.device; sections are active.
609 <title>Enable port I/O access</title>
612 Port I/O access is controlled from the XFree86 common layer, and is
613 <quote>all or nothing</quote>. It is enabled prior to calling driver probes, at
614 the start of subsequent server generations, and when VT switching
615 back to the Xserver. It is disabled at the end of server generations,
616 and when VT switching away from the Xserver.
620 The implementation details of this may vary on different platforms.
626 <title>General bus probe</title>
629 This is done at the start of the first server generation only.
633 In the case of ix86 machines, this will be a general PCI probe.
634 The full information obtained here will be available to the drivers.
635 This information persists for the life of the Xserver. In the PCI
636 case, the PCI information for all video cards found is available by
637 calling <function>xf86GetPciVideoInfo()</function>.
642 pciVideoPtr *xf86GetPciVideoInfo(void);
645 returns a pointer to a list of pointers to
646 <structname>pciVideoRec</structname> entries, of which there is one for
647 each detected PCI video card. The list is terminated with a
648 <constant>NULL</constant> pointer. If no PCI video cards were
649 detected, the return value is <constant>NULL</constant>.
655 After the bus probe, the resource broker is initialised.
661 <title>Load initial set of modules</title>
664 This is done at the start of the first server generation only.
668 The next set of modules loaded are those specified explicitly in the
669 &k.module; section of the config file.
673 The final set of initial modules are the driver modules referenced
674 by the active &k.device; and &k.inputdevice; sections in the config
675 file. Each of these modules is loaded exactly once.
681 <title>Register Video and Input Drivers</title>
684 This is done at the start of the first server generation only.
688 When a driver module is loaded, the loader calls its
689 <function>Setup</function> function. For video drivers, this function
690 calls <function>xf86AddDriver()</function> to register the driver's
691 <structname>DriverRec</structname>, which contains a small set of essential
692 details and driver entry points required during the early phase of
693 <function>InitOutput()</function>. <function>xf86AddDriver()</function>
694 adds it to the global <varname>xf86DriverList[]</varname> array.
698 The <structname>DriverRec</structname> contains the driver canonical name,
699 the <function>Identify()</function>,
700 <function>Probe()</function> and <function>AvailableOptions()</function>
701 function entry points as well as a pointer
702 to the driver's module (as returned from the loader when the driver
703 was loaded) and a reference count which keeps track of how many
704 screens are using the driver. The entry driver entry points are
705 those required prior to the driver allocating and filling in its
706 <structname>ScrnInfoRec</structname>.
710 For a static server, the <varname>xf86DriverList[]</varname> array is
711 initialised at build time, and the loading of modules is not done.
715 A similar procedure is used for input drivers. The input driver's
716 <function>Setup</function> function calls
717 <function>xf86AddInputDriver()</function> to register the driver's
718 <structname>InputDriverRec</structname>, which contains a small set of
719 essential details and driver entry points required during the early
720 phase of <function>InitInput()</function>.
721 <function>xf86AddInputDriver()</function> adds it to the global
722 <varname>xf86InputDriverList[]</varname> array. For a static server,
723 the <varname>xf86InputDriverList[]</varname> array is initialised at
728 Both the <varname>xf86DriverList[]</varname> and
729 <varname>xf86InputDriverList[]</varname> arrays have been initialised
730 by the end of this stage.
734 Once all the drivers are registered, their
735 <function>ChipIdentify()</function> functions are called.
740 void ChipIdentify(int flags);
743 This is expected to print a message indicating the driver name,
744 a short summary of what it supports, and a list of the chipset
745 names that it supports. It may use the xf86PrintChipsets() helper
752 void xf86PrintChipsets(const char *drvname, const char *drvmsg,
756 This function provides an easy way for a driver's ChipIdentify
757 function to format the identification message.
763 <title>Initialise Access Control</title>
766 This is done at the start of the first server generation only.
770 The Resource Access Control (RAC) subsystem is initialised before
771 calling any driver functions that may access hardware. All generic
772 bus information is probed and saved (for restoration later). All
773 (shared resource) video devices are disabled at the generic bus
774 level, and a probe is done to find the <quote>primary</quote> video device. These
775 devices remain disabled for the next step.
781 <title>Video Driver Probe</title>
784 This is done at the start of the first server generation only. The
785 <function>ChipProbe()</function> function of each registered video driver
791 Bool ChipProbe(DriverPtr drv, int flags);
794 The purpose of this is to identify all instances of hardware
795 supported by the driver. The flags value is currently either 0,
796 <constant>PROBE_DEFAULT</constant> or <constant>PROBE_DETECT</constant>.
797 <constant>PROBE_DETECT</constant> is used if "-configure" or "-probe"
798 command line arguments are given and indicates to the
799 <function>Probe()</function> function that it should not configure the
800 bus entities and that no xorg.conf information is available.
804 The probe must find the active device sections that match the
805 driver by calling <function>xf86MatchDevice()</function>. The number
806 of matches found limits the maximum number of instances for this
807 driver. If no matches are found, the function should return
808 <constant>FALSE</constant> immediately.
812 Devices that cannot be identified by using device-independent
813 methods should be probed at this stage (keeping in mind that access
814 to all resources that can be disabled in a device-independent way
815 are disabled during this phase). The probe must be a minimal
816 probe. It should just determine if there is a card present that
817 the driver can drive. It should use the least intrusive probe
818 methods possible. It must not do anything that is not essential,
819 like probing for other details such as the amount of memory
820 installed, etc. It is recommended that the
821 <function>xf86MatchPciInstances()</function> helper function be used
822 for identifying matching PCI devices, and similarly the
823 <function>xf86MatchIsaInstances()</function> for ISA (non-PCI) devices
824 (see the <link linkend="rac">RAC</link> section). These helpers also
825 checks and claims the appropriate entity. When not using the
826 helper, that should be done with <function>xf86CheckPciSlot()</function>
827 and <function>xf86ClaimPciSlot()</function> for PCI devices and
828 <function>xf86ClaimIsaSlot()</function> for ISA devices (see the
829 <link linkend="rac">RAC</link> section).
833 The probe must register all non-relocatable resources at this
834 stage. If a resource conflict is found between exclusive resources
835 the driver will fail immediately. This is usually best done with
836 the <function>xf86ConfigPciEntity()</function> helper function
837 for PCI and <function>xf86ConfigIsaEntity()</function> for ISA
838 (see the <link linkend="rac">RAC</link> section). It is possible to
839 register some entity specific functions with those helpers. When
840 not using the helpers, the <function>xf86AddEntityToScreen()</function>
841 <function>xf86ClaimFixedResources()</function> and
842 <function>xf86SetEntityFuncs()</function> should be used instead (see
843 the <link linkend="rac">RAC</link> section).
847 If a chipset is specified in an active device section which the
848 driver considers relevant (ie it has no driver specified, or the
849 driver specified matches the driver doing the probe), the Probe
850 must return <constant>FALSE</constant> if the chipset doesn't match
851 one supported by the driver.
855 If there are no active device sections that the driver considers
856 relevant, it must return <constant>FALSE</constant>.
860 Allocate a <structname>ScrnInfoRec</structname> for each active instance of the
861 hardware found, and fill in the basic information, including the
862 other driver entry points. This is best done with the
863 <function>xf86ConfigIsaEntity()</function> helper function for ISA
864 instances or <function>xf86ConfigPciEntity()</function> for PCI instances.
865 These functions allocate a <structname>ScrnInfoRec</structname> for active
866 entities. Optionally <function>xf86AllocateScreen()</function>
867 function may also be used to allocate the <structname>ScrnInfoRec</structname>.
868 Any of these functions take care of initialising fields to defined
869 <quote>unused</quote> values.
873 Claim the entities for each instance of the hardware found. This
874 prevents other drivers from claiming the same hardware.
878 Must leave hardware in the same state it found it in, and must not
879 do any hardware initialisation.
883 All detection can be overridden via the config file, and that
884 parsed information is available to the driver at this stage.
888 Returns <constant>TRUE</constant> if one or more instances are found,
889 and <constant>FALSE</constant> otherwise.
892 </blockquote></para></blockquote>
896 int xf86MatchDevice(const char *drivername,
897 GDevPtr **driversectlist)
900 This function takes the name of the driver and returns via
901 <parameter>driversectlist</parameter> a list of device sections that
902 match the driver name. The function return value is the number
903 of matches found. If a fatal error is encountered the return
904 value is <literal>-1</literal>.
908 The caller should use <function>xfree()</function> to free
909 <parameter>*driversectlist</parameter> when it is no longer needed.
912 </blockquote></para></blockquote>
916 ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags)
919 This function allocates a new <structname>ScrnInfoRec</structname> in the
920 <varname>xf86Screens[]</varname> array. This function is normally
921 called by the video driver <function>ChipProbe()</function> functions.
922 The return value is a pointer to the newly allocated
923 <structname>ScrnInfoRec</structname>. The <structfield>scrnIndex</structfield>,
924 <structfield>origIndex</structfield>, <structfield>module</structfield> and
925 <structfield>drv</structfield> fields are initialised. The reference count
926 in <parameter>drv</parameter> is incremented. The storage for any
927 currently allocated <quote>privates</quote> pointers is also allocated and
928 the <structfield>privates</structfield> field initialised (the privates data
929 is of course not allocated or initialised). This function never
930 returns on failure. If the allocation fails, the server exits
931 with a fatal error. The flags value is not currently used, and
932 should be set to zero.
937 At the completion of this, a list of <structname>ScrnInfoRecs</structname>
938 have been allocated in the <varname>xf86Screens[]</varname> array, and
939 the associated entities and fixed resources have been claimed. The
940 following <structname>ScrnInfoRec</structname> fields must be initialised at
961 <literal>(*)</literal> These are initialised when the <structname>ScrnInfoRec</structname>
962 is allocated, and not explicitly by the driver.
966 The following <structname>ScrnInfoRec</structname> fields must be initialised
967 if the driver is going to use them:
979 <title>Matching Screens</title>
982 This is done at the start of the first server generation only.
986 After the Probe phase is finished, there will be some number of
987 <structname>ScrnInfoRec</structname>s. These are then matched with the active
988 &k.screen; sections in the xorg.conf, and those not having an active
989 &k.screen; section are deleted. If the number of remaining screens
990 is 0, <function>InitOutput()</function> sets
991 <structfield>screenInfo.numScreens</structfield> to <constant>0</constant> and
996 At this point the following fields of the <structname>ScrnInfoRec</structname>s
1007 <title>Allocate non-conflicting resources</title>
1010 This is done at the start of the first server generation only.
1014 Before calling the drivers again, the resource information collected
1015 from the Probe phase is processed. This includes checking the extent
1016 of PCI resources for the probed devices, and resolving any conflicts
1017 in the relocatable PCI resources. It also reports conflicts, checks
1018 bus routing issues, and anything else that is needed to enable the
1019 entities for the next phase.
1023 If any drivers registered an <function>EntityInit()</function> function
1024 during the Probe phase, then they are called here.
1030 <title>Sort the Screens and pre-check Monitor Information</title>
1033 This is done at the start of the first server generation only.
1037 The list of screens is sorted to match the ordering requested in the
1042 The list of modes for each active monitor is checked against the
1043 monitor's parameters. Invalid modes are pruned.
1049 <title>PreInit</title>
1052 This is done at the start of the first server generation only.
1056 For each <structname>ScrnInfoRec</structname>, enable access to the screens entities and call
1057 the <function>ChipPreInit()</function> function.
1062 Bool ChipPreInit(ScrnInfoRec screen, int flags);
1065 The purpose of this function is to find out all the information
1066 required to determine if the configuration is usable, and to
1067 initialise those parts of the <structname>ScrnInfoRec</structname> that
1068 can be set once at the beginning of the first server generation.
1072 The number of entities registered for the screen should be checked
1073 against the expected number (most drivers expect only one). The
1074 entity information for each of them should be retrieved (with
1075 <function>xf86GetEntityInfo()</function>) and checked for the correct
1076 bus type and that none of the sharable resources registered during
1077 the Probe phase was rejected.
1081 Access to resources for the entities that can be controlled in a
1082 device-independent way are enabled before this function is called.
1083 If the driver needs to access any resources that it has disabled
1084 in an <function>EntityInit()</function> function that it registered,
1085 then it may enable them here providing that it disables them before
1086 this function returns.
1090 This includes probing for video memory, clocks, ramdac, and all
1091 other HW info that is needed. It includes determining the
1092 depth/bpp/visual and related info. It includes validating and
1093 determining the set of video modes that will be used (and anything
1094 that is required to determine that).
1098 This information should be determined in the least intrusive way
1099 possible. The state of the HW must remain unchanged by this
1100 function. Although video memory (including MMIO) may be mapped
1101 within this function, it must be unmapped before returning. Driver
1102 specific information should be stored in a structure hooked into
1103 the <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield>
1104 field. Any other modules which require persistent data (ie data
1105 that persists across server generations) should be initialised in
1106 this function, and they should allocate a <quote>privates</quote> index to
1107 hook their data into by calling
1108 <function>xf86AllocateScrnInfoPrivateIndex()</function>. The <quote>privates</quote>
1113 Helper functions for some of these things are provided at the
1114 XFree86 common level, and the driver can choose to make use of
1119 All additional resources that the screen needs must be registered
1120 here. This should be done with
1121 <function>xf86RegisterResources()</function>. If some of the fixed
1122 resources registered in the Probe phase are not needed or not
1123 decoded by the hardware when in the OPERATING server state, their
1124 status should be updated with
1125 <function>xf86SetOperatingState()</function>.
1129 Modules may be loaded at any point in this function, and all
1130 modules that the driver will need must be loaded before the end
1131 of this function. Either the <function>xf86LoadSubModule()</function>
1132 or the <function>xf86LoadDrvSubModule()</function> function should be
1133 used to load modules depending on whether a
1134 <structname>ScrnInfoRec</structname> has been set up. A driver may unload
1135 a module within this function if it was only needed temporarily,
1136 and the <function>xf86UnloadSubModule()</function> function should be used
1137 to do that. Otherwise there is no need to explicitly unload modules
1138 because the loader takes care of module dependencies and will
1139 unload submodules automatically if/when the driver module is
1144 The bulk of the <structname>ScrnInfoRec</structname> fields should be filled
1145 out in this function.
1149 <function>ChipPreInit()</function> returns <constant>FALSE</constant> when
1150 the configuration is unusable in some way (unsupported depth, no
1151 valid modes, not enough video memory, etc), and <constant>TRUE</constant>
1156 It is expected that if the <function>ChipPreInit()</function> function
1157 returns <constant>TRUE</constant>, then the only reasons that subsequent
1158 stages in the driver might fail are lack or resources (like xalloc
1159 failures). All other possible reasons for failure should be
1160 determined by the <function>ChipPreInit()</function> function.
1161 </para></blockquote>
1162 </para></blockquote>
1165 The <structname>ScrnInfoRec</structname>s for screens where the <function>ChipPreInit()</function> fails are removed.
1166 If none remain, <function>InitOutput()</function> sets <structfield>screenInfo.numScreens</structfield> to <constant>0</constant> and returns.
1170 At this point, further fields of the <structname>ScrnInfoRec</structname>s would normally be
1171 filled in. Most are not strictly mandatory, but many are required
1172 by other layers and/or helper functions that the driver may choose
1173 to use. The documentation for those layers and helper functions
1174 indicates which they require.
1178 The following fields of the <structname>ScrnInfoRec</structname>s should be filled in if the
1179 driver is going to use them:
1187 weight (>8bpp only)
1188 mask (>8bpp only)
1189 offset (>8bpp only)
1206 progClock (TRUE if clock is programmable)
1210 numClocks (if not programmable)
1211 clock[] (if not programmable)
1224 pointer xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name);
1226 pointer xf86LoadDrvSubModule(DriverPtr drv, const char *name);
1229 Load a module that a driver depends on. This function loads the
1230 module <parameter>name</parameter> as a sub module of the driver. The
1231 return value is a handle identifying the new module. If the load
1232 fails, the return value will be <constant>NULL</constant>. If a driver
1233 needs to explicitly unload a module it has loaded in this way,
1234 the return value must be saved and passed to
1235 <function>xf86UnloadSubModule()</function> when unloading.
1237 </para></blockquote>
1238 </para></blockquote>
1242 void xf86UnloadSubModule(pointer module);
1245 Unloads the module referenced by <parameter>module</parameter>.
1246 <parameter>module</parameter> should be a pointer returned previously
1247 by <function>xf86LoadSubModule()</function> or
1248 <function>xf86LoadDrvSubModule()</function> .
1250 </para></blockquote>
1251 </para></blockquote>
1255 <title>Cleaning up Unused Drivers</title>
1258 At this point it is known which screens will be in use, and which
1259 drivers are being used. Unreferenced drivers (and modules they
1260 may have loaded) are unloaded here.
1266 <title>Consistency Checks</title>
1269 The parameters that must be global to the server, like pixmap formats,
1270 bitmap bit order, bitmap scanline unit and image byte order are
1271 compared for each of the screens. If a mismatch is found, the server
1272 exits with an appropriate message.
1278 <title>Check if Resource Control is Needed</title>
1281 Determine if resource access control is needed. This is the case
1282 if more than one screen is used. If necessary the RAC wrapper module
1288 <title>AddScreen (ScreenInit)</title>
1291 At this point, the valid screens are known.
1292 <function>AddScreen()</function> is called for each of them, passing
1293 <function>ChipScreenInit()</function> as the argument.
1294 <function>AddScreen()</function> is a DIX function that allocates a new
1295 <structfield>screenInfo.screen[]</structfield> entry (aka
1296 <varname>pScreen</varname>), and does some basic initialisation of it.
1297 It then calls the <function>ChipScreenInit()</function> function, with
1298 <parameter>pScreen</parameter> as one of its arguments. If
1299 <function>ChipScreenInit()</function> returns <constant>FALSE</constant>,
1300 <function>AddScreen()</function> returns <constant>-1</constant>. Otherwise
1301 it returns the index of the screen. <function>AddScreen()</function>
1302 should only fail because of programming errors or failure to allocate
1303 resources (like memory). All configuration problems should be
1304 detected BEFORE this point.
1309 Bool ChipScreenInit(ScreenPtr pScreen,
1310 int argc, char **argv);
1313 This is called at the start of each server generation.
1317 Fill in all of <parameter>pScreen</parameter>, possibly doing some of
1318 this by calling ScreenInit functions from other layers like mi,
1319 framebuffers (cfb, etc), and extensions.
1323 Decide which operations need to be placed under resource access
1324 control. The classes of operations are the frame buffer operations
1325 (<constant>RAC_FB</constant>), the pointer operations
1326 (<constant>RAC_CURSOR</constant>), the viewport change operations
1327 (<constant>RAC_VIEWPORT</constant>) and the colormap operations
1328 (<constant>RAC_COLORMAP</constant>). Any operation that requires
1329 resources which might be disabled during OPERATING state should
1330 be set to use RAC. This can be specified separately for memory
1331 and IO resources (the <structfield>racMemFlags</structfield> and
1332 <structfield>racIoFlags</structfield> fields of the <structname>ScrnInfoRec</structname>
1337 Map any video memory or other memory regions.
1341 Save the video card state. Enough state must be saved so that
1342 the original state can later be restored.
1346 Initialise the initial video mode. The <structname>ScrnInfoRec</structname>'s
1347 <structfield>vtSema</structfield> field should be set to <constant>TRUE</constant>
1348 just prior to changing the video hardware's state.
1350 </para></blockquote>
1351 </para></blockquote>
1355 The <function>ChipScreenInit()</function> function (or functions from other
1356 layers that it calls) should allocate entries in the
1357 <structname>ScreenRec</structname>'s <structfield>devPrivates</structfield> area by
1358 calling <function>AllocateScreenPrivateIndex()</function> if it needs
1359 per-generation storage. Since the <structname>ScreenRec</structname>'s
1360 <structfield>devPrivates</structfield> information is cleared for each server
1361 generation, this is the correct place to initialise it.
1365 After <function>AddScreen()</function> has successfully returned, the
1366 following <structname>ScrnInfoRec</structname> fields are initialised:
1376 The <function>ChipScreenInit()</function> function should initialise the
1377 <structfield>CloseScreen</structfield> and <structfield>SaveScreen</structfield> fields
1378 of <parameter>pScreen</parameter>. The old value of
1379 <structfield>pScreen->CloseScreen</structfield> should be saved as part of
1380 the driver's per-screen private data, allowing it to be called from
1381 <function>ChipCloseScreen()</function>. This means that the existing
1382 <function>CloseScreen()</function> function is wrapped.
1387 <title>Finalising RAC Initialisation</title>
1390 After all the <function>ChipScreenInit()</function> functions have been
1391 called, each screen has registered its RAC requirements. This
1392 information is used to determine which shared resources are requested
1393 by more than one driver and set the access functions accordingly.
1394 This is done following these rules:
1398 The sharable resources registered by each entity are compared.
1399 If a resource is registered by more than one entity the entity
1400 will be marked to indicate that it needs to share this resources
1405 A resource marked <quote>disabled</quote> during OPERATING state will be
1410 A resource marked <quote>unused</quote> will only conflict with an overlapping
1411 resource of an other entity if the second is actually in use
1412 during OPERATING state.
1416 If an <quote>unused</quote> resource was found to conflict but the entity
1417 does not use any other resource of this type the entire resource
1418 type will be disabled for that entity.
1426 <title>Finishing InitOutput()</title>
1429 At this point <function>InitOutput()</function> is finished, and all the
1430 screens have been setup in their initial video mode.
1436 <title>Mode Switching</title>
1439 When a SwitchMode event is received, <function>ChipSwitchMode()</function>
1440 is called (when it exists):
1445 Bool ChipSwitchMode(int index, DisplayModePtr mode);
1448 Initialises the new mode for the screen identified by
1449 <parameter>index;</parameter>. The viewport may need to be adjusted
1452 </para></blockquote>
1453 </para></blockquote>
1458 <title>Changing Viewport</title>
1461 When a Change Viewport event is received,
1462 <function>ChipAdjustFrame()</function> is called (when it exists):
1467 void ChipAdjustFrame(int index, int x, int y);
1470 Changes the viewport for the screen identified by
1471 <parameter>index;</parameter>.
1475 It should be noted that many chipsets impose restrictions on where the
1476 viewport may be placed in the virtual resolution, either for alignment
1477 reasons, or to prevent the start of the viewport from being positioned
1478 within a pixel (as can happen in a 24bpp mode). After calculating the
1479 value the chipset's panning registers need to be set to for non-DGA
1480 modes, this function should recalculate the ScrnInfoRec's
1481 <structfield>frameX0</structfield>, <structfield>frameY0</structfield>, <structfield>frameX1</structfield>
1482 and <structfield>frameY1</structfield> fields to correspond to that value. If
1483 this is not done, switching to another mode might cause the position
1484 of a hardware cursor to change.
1486 </para></blockquote>
1487 </para></blockquote>
1492 <title>VT Switching</title>
1495 When a VT switch event is received, <function>xf86VTSwitch()</function>
1496 is called. <function>xf86VTSwitch()</function> does the following:
1499 <varlistentry><term>On ENTER:</term>
1503 enable port I/O access
1507 save and initialise the bus/resource state
1511 enter the SETUP server state
1515 calls <function>ChipEnterVT()</function> for each screen
1519 enter the OPERATING server state
1527 Restore fb from saved pixmap for each screen
1531 Enable all input devices
1537 <term>On LEAVE:</term>
1541 Save fb to pixmap for each screen
1549 enter the SETUP server state
1553 calls <function>ChipLeaveVT()</function> for each screen
1557 disable all input devices
1561 restore bus/resource state
1565 disables port I/O access
1575 Bool ChipEnterVT(ScrnInfoPtr pScrn);
1578 This function should initialise the current video mode and
1579 initialise the viewport, turn on the HW cursor if appropriate,
1584 Should it re-save the video state before initialising the video
1588 </blockquote></para></blockquote>
1592 void ChipLeaveVT(ScrnInfoPtr pScrn);
1595 This function should restore the saved video state. If
1596 appropriate it should also turn off the HW cursor, and invalidate
1597 any pixmap/font caches.
1600 </blockquote></para></blockquote>
1603 Optionally, <function>ChipLeaveVT()</function> may also unmap memory
1604 regions. If so, <function>ChipEnterVT()</function> will need to remap
1605 them. Additionally, if an aperture used to access video memory is
1606 unmapped and remapped in this fashion, <function>ChipEnterVT()</function>
1607 will also need to notify the framebuffer layers of the aperture's new
1608 location in virtual memory. This is done with a call to the screen's
1609 <function>ModifyPixmapHeader()</function> function, as follows
1614 (*pScreen->ModifyPixmapHeader)(pScrn->ppix,
1615 -1, -1, -1, -1, -1, NewApertureAddress);
1618 where the <structfield>ppix</structfield> field in a ScrnInfoRec
1619 points to the pixmap used by the screen's
1620 <function>SaveRestoreImage()</function> function to hold the screen's
1621 contents while switched out.
1624 </blockquote></para></blockquote>
1627 Other layers may wrap the <function>ChipEnterVT()</function> and
1628 <function>ChipLeaveVT()</function> functions if they need to take some
1629 action when these events are received.
1634 <title>End of server generation</title>
1637 At the end of each server generation, the DIX layer calls
1638 <function>ChipCloseScreen()</function> for each screen:
1643 Bool ChipCloseScreen(int index, ScreenPtr pScreen);
1646 This function should restore the saved video state and unmap the
1651 It should also free per-screen data structures allocated by the
1652 driver. Note that the persistent data held in the
1653 <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> field
1654 should not be freed here because it is needed by subsequent server
1659 The <structname>ScrnInfoRec</structname>'s <structfield>vtSema</structfield> field
1660 should be set to <constant>FALSE</constant> once the video HW state
1665 Before freeing the per-screen driver data the saved
1666 <structfield>CloseScreen</structfield> value should be restored to
1667 <structfield>pScreen->CloseScreen</structfield>, and that function should
1668 be called after freeing the data.
1670 </para></blockquote>
1671 </para></blockquote>
1676 <title>Optional Driver Functions</title>
1679 The functions outlined here can be called from the XFree86 common layer,
1680 but their presence is optional.
1684 <title>Mode Validation</title>
1687 When a mode validation helper supplied by the XFree86-common layer is
1688 being used, it can be useful to provide a function to check for hw
1689 specific mode constraints:
1694 ModeStatus ChipValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode,
1695 Bool verbose, int flags);
1698 Check the passed mode for hw-specific constraints, and return the
1699 appropriate status value.
1701 </para></blockquote>
1702 </para></blockquote>
1705 This function may also modify the effective timings and clock of the passed
1706 mode. These have been stored in the mode's <structfield>Crtc*</structfield> and
1707 <structfield>SynthClock</structfield> elements, and have already been adjusted for
1708 interlacing, doublescanning, multiscanning and clock multipliers and dividers.
1709 The function should not modify any other mode field, unless it wants to modify
1710 the mode timings reported to the user by <function>xf86PrintModes()</function>.
1714 The function is called once for every mode in the xorg.conf Monitor section
1715 assigned to the screen, with <parameter>flags</parameter> set to
1716 <constant>MODECHECK_INITIAL</constant>. It is subsequently called for every mode
1717 in the xorg.conf Display subsection assigned to the screen, with
1718 <parameter>flags</parameter> set to <constant>MODECHECK_FINAL</constant>. In the second
1719 case, the mode will have successfully passed all other tests. In addition,
1720 the <structname>ScrnInfoRec</structname>'s <structfield>virtualX</structfield>,
1721 <structfield>virtualY</structfield> and <structfield>displayWidth</structfield> fields will have been
1722 set as if the mode to be validated were to be the last mode accepted.
1726 In effect, calls with MODECHECK_INITIAL are intended for checks that do not
1727 depend on any mode other than the one being validated, while calls with
1728 MODECHECK_FINAL are intended for checks that may involve more than one mode.
1733 <title>Free screen data</title>
1736 When a screen is deleted prior to the completion of the ScreenInit
1737 phase the <function>ChipFreeScreen()</function> function is called when defined.
1742 void ChipFreeScreen(ScrnInfoPtr pScrn);
1745 Free any driver-allocated data that may have been allocated up to
1746 and including an unsuccessful <function>ChipScreenInit()</function>
1747 call. This would predominantly be data allocated by
1748 <function>ChipPreInit()</function> that persists across server
1749 generations. It would include the <structfield>driverPrivate</structfield>,
1750 and any <quote>privates</quote> entries that modules may have allocated.
1752 </para></blockquote>
1753 </para></blockquote>
1759 <title>Recommended driver functions</title>
1762 The functions outlined here are for internal use by the driver only.
1763 They are entirely optional, and are never accessed directly from higher
1764 layers. The sample function declarations shown here are just examples.
1765 The interface (if any) used is up to the driver.
1772 Save the video state. This could be called from <function>ChipScreenInit()</function> and
1773 (possibly) <function>ChipEnterVT()</function>.
1778 void ChipSave(ScrnInfoPtr pScrn);
1781 Saves the current state. This will only be saving pre-server
1782 states or states before returning to the server. There is only
1783 one current saved state per screen and it is stored in private
1784 storage in the screen.
1786 </para></blockquote>
1787 </para></blockquote>
1791 <title>Restore</title>
1794 Restore the original video state. This could be called from the
1795 <function>ChipLeaveVT()</function> and <function>ChipCloseScreen()</function>
1801 void ChipRestore(ScrnInfoPtr pScrn);
1804 Restores the saved state from the private storage. Usually only
1805 used for restoring text modes.
1807 </para></blockquote>
1808 </para></blockquote>
1813 <title>Initialise Mode</title>
1816 Initialise a video mode. This could be called from the
1817 <function>ChipScreenInit()</function>, <function>ChipSwitchMode()</function>
1818 and <function>ChipEnterVT()</function> functions.
1823 Bool ChipModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
1826 Programs the hardware for the given video mode.
1828 </para></blockquote>
1829 </para></blockquote>
1835 <title>Data and Data Structures</title>
1838 <title>Command line data</title>
1841 Command line options are typically global, and are stored in global
1842 variables. These variables are read-only and are available to drivers
1843 via a function call interface. Most of these command line values are
1844 processed via helper functions to ensure that they are treated consistently
1845 by all drivers. The other means of access is provided for cases where
1846 the supplied helper functions might not be appropriate.
1853 xf86Verbose verbosity level
1854 xf86Bpp -bpp from the command line
1855 xf86Depth -depth from the command line
1856 xf86Weight -weight from the command line
1857 xf86Gamma -{r,g,b,}gamma from the command line
1858 xf86FlipPixels -flippixels from the command line
1859 xf86ProbeOnly -probeonly from the command line
1860 defaultColorVisualClass -cc from the command line
1865 If we ever do allow for screen-specific command line options, we may
1866 need to rethink this.
1870 These can be accessed in a read-only manner by drivers with the following
1876 int xf86GetVerbosity();
1879 Returns the value of <varname>xf86Verbose</varname>.
1880 </para></blockquote>
1882 </para></blockquote>
1889 Returns the <option>-depth</option> command line setting. If not
1890 set on the command line, <constant>-1</constant> is returned.
1891 </para></blockquote>
1893 </para></blockquote>
1897 rgb xf86GetWeight();
1900 Returns the <option>-weight</option> command line setting. If not
1901 set on the command line, <literal remap="tt">{0, 0, 0}</literal> is returned.
1902 </para></blockquote>
1904 </para></blockquote>
1908 Gamma xf86GetGamma();
1911 Returns the <option>-gamma</option> or <option>-rgamma</option>,
1912 <option>-ggamma</option>, <option>-bgamma</option> command line settings.
1913 If not set on the command line, <literal remap="tt">{0.0, 0.0, 0.0}</literal>
1915 </para></blockquote>
1917 </para></blockquote>
1921 Bool xf86GetFlipPixels();
1924 Returns <constant>TRUE</constant> if <option>-flippixels</option> is
1925 present on the command line, and <constant>FALSE</constant> otherwise.
1926 </para></blockquote>
1928 </para></blockquote>
1932 const char *xf86GetServerName();
1935 Returns the name of the X server from the command line.
1936 </para></blockquote>
1938 </para></blockquote>
1942 <title>Data handling</title>
1945 Config file data contains parts that are global, and parts that are
1946 Screen specific. All of it is parsed into data structures that neither
1947 the drivers or most other parts of the server need to know about.
1951 The global data is typically not required by drivers, and as such, most
1952 of it is stored in the private <structname>xf86InfoRec</structname>.
1956 The screen-specific data collected from the config file is stored in
1957 screen, device, display, monitor-specific data structures that are separate
1958 from the <varname>ScrnInfoRecs</varname>, with the appropriate elements/fields
1959 hooked into the <varname>ScrnInfoRecs</varname> as required. The screen
1960 config data is held in <structname>confScreenRec</structname>, device data in
1961 the <structname>GDevRec</structname>, monitor data in the <structname>MonRec</structname>,
1962 and display data in the <structname>DispRec</structname>.
1966 The XFree86 common layer's screen specific data (the actual data in use
1967 for each screen) is held in the <varname>ScrnInfoRecs</varname>. As has
1968 been outlined above, the <varname>ScrnInfoRecs</varname> are allocated at probe
1969 time, and it is the responsibility of the Drivers' <function>Probe()</function>
1970 and <function>PreInit()</function> functions to finish filling them in based
1971 on both data provided on the command line and data provided from the
1972 Config file. The precedence for this is:
1975 command line -> config file -> probed/default data
1976 </para></blockquote>
1980 For most things in this category there are helper functions that the
1981 drivers can use to ensure that the above precedence is consistently
1986 As well as containing screen-specific data that the XFree86 common layer
1987 (including essential parts of the server infrastructure as well as helper
1988 functions) needs to access, it also contains some data that drivers use
1989 internally. When considering whether to add a new field to the
1990 <structname>ScrnInfoRec</structname>, consider the balance between the convenience
1991 of things that lots of drivers need and the size/obscurity of the
1992 <structname>ScrnInfoRec</structname>.
1996 Per-screen driver specific data that cannot be accommodated with the
1997 static <structname>ScrnInfoRec</structname> fields is held in a driver-defined
1998 data structure, a pointer to which is assigned to the
1999 <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> field. This
2000 is per-screen data that persists across server generations (as does the
2001 bulk of the static <structname>ScrnInfoRec</structname> data). It would typically
2002 also include the video card's saved state.
2006 Per-screen data for other modules that the driver uses that is reset for each
2007 server generation is hooked into the <structname>ScrnInfoRec</structname>
2008 through its <structfield>privates</structfield> field.
2012 Once it has stabilised, the data structures and variables accessible to
2013 video drivers will be documented here. In the meantime, those things
2014 defined in the <filename>xf86.h</filename> and <filename>xf86str.h</filename>
2015 files are visible to video drivers. Things defined in
2016 <filename>xf86Priv.h</filename> and <filename>xf86Privstr.h</filename> are NOT
2017 intended to be visible to video drivers, and it is an error for a driver
2018 to include those files.
2024 <title>Accessing global data</title>
2027 Some other global state information that the drivers may access via
2028 functions is as follows:
2033 Bool xf86ServerIsExiting();
2036 Returns <constant>TRUE</constant> if the server is at the end of a
2037 generation and is in the process of exiting, and
2038 <constant>FALSE</constant> otherwise.
2039 </para></blockquote>
2041 </para></blockquote>
2045 Bool xf86ServerIsResetting();
2048 Returns <constant>TRUE</constant> if the server is at the end of a
2049 generation and is in the process of resetting, and
2050 <constant>FALSE</constant> otherwise.
2051 </para></blockquote>
2053 </para></blockquote>
2057 Bool xf86ServerIsInitialising();
2060 Returns <constant>TRUE</constant> if the server is at the beginning of
2061 a generation and is in the process of initialising, and
2062 <constant>FALSE</constant> otherwise.
2063 </para></blockquote>
2065 </para></blockquote>
2069 Bool xf86ServerIsOnlyProbing();
2072 Returns <constant>TRUE</constant> if the -probeonly command line flag
2073 was specified, and <constant>FALSE</constant> otherwise.
2074 </para></blockquote>
2076 </para></blockquote>
2080 Bool xf86CaughtSignal();
2083 Returns <constant>TRUE</constant> if the server has caught a signal,
2084 and <constant>FALSE</constant> otherwise.
2085 </para></blockquote>
2087 </para></blockquote>
2091 <title>Allocating private data</title>
2094 A driver and any module it uses may allocate per-screen private storage
2095 in either the <structname>ScreenRec</structname> (DIX level) or
2096 <structname>ScrnInfoRec</structname> (XFree86 common layer level).
2097 <structname>ScreenRec</structname> storage persists only for a single server
2098 generation, and <structname>ScrnInfoRec</structname> storage persists across
2099 generations for the lifetime of the server.
2103 The <structname>ScreenRec</structname> <structfield>devPrivates</structfield> data must be
2104 reallocated/initialised at the start of each new generation. This is
2105 normally done from the <function>ChipScreenInit()</function> function, and
2106 Init functions for other modules that it calls. Data allocated in this
2107 way should be freed by the driver's <function>ChipCloseScreen()</function>
2108 functions, and Close functions for other modules that it calls. A new
2109 <structfield>devPrivates</structfield> entry is allocated by calling the
2110 <function>AllocateScreenPrivateIndex()</function> function.
2115 int AllocateScreenPrivateIndex();
2118 This function allocates a new element in the
2119 <structfield>devPrivates</structfield> field of all currently existing
2120 <literal remap="tt">ScreenRecs</literal>. The return value is the index of this
2121 new element in the <structfield>devPrivates</structfield> array. The
2122 <structfield>devPrivates</structfield> field is of type
2123 <structname>DevUnion</structname>:
2126 typedef union _DevUnion {
2130 pointer (*fptr)(void);
2134 which allows the element to be used for any of the above types.
2135 It is commonly used as a pointer to data that the caller allocates
2136 after the new index has been allocated.
2140 This function will return <constant>-1</constant> when there is an
2141 error allocating the new index.
2145 </para></blockquote>
2148 The <structname>ScrnInfoRec</structname> <structfield>privates</structfield> data persists
2149 for the life of the server, so only needs to be allocated once. This
2150 should be done from the <function>ChipPreInit()</function> function, and Init
2151 functions for other modules that it calls. Data allocated in this way
2152 should be freed by the driver's <function>ChipFreeScreen()</function> functions,
2153 and Free functions for other modules that it calls. A new
2154 <structfield>privates</structfield> entry is allocated by calling the
2155 <function>xf86AllocateScrnInfoPrivateIndex()</function> function.
2160 int xf86AllocateScrnInfoPrivateIndex();
2163 This function allocates a new element in the <structfield>privates</structfield>
2164 field of all currently existing <varname>ScrnInfoRecs</varname>.
2165 The return value is the index of this new element in the
2166 <structfield>privates</structfield> array. The <structfield>privates</structfield>
2167 field is of type <structfield>DevUnion</structfield>:
2170 typedef union _DevUnion {
2174 pointer (*fptr)(void);
2178 which allows the element to be used for any of the above types.
2179 It is commonly used as a pointer to data that the caller allocates
2180 after the new index has been allocated.
2184 This function will not return when there is an error allocating
2185 the new index. When there is an error it will cause the server
2186 to exit with a fatal error. The similar function for allocation
2187 privates in the <structname>ScreenRec</structname>
2188 (<function>AllocateScreenPrivateIndex()</function>) differs in this
2189 respect by returning <constant>-1</constant> when the allocation fails.
2193 </para></blockquote>
2198 <title>Keeping Track of Bus Resources</title>
2201 <title>Theory of Operation</title>
2204 The XFree86 common layer has knowledge of generic access control mechanisms
2205 for devices on certain bus systems (currently the PCI bus) as well as
2206 of methods to enable or disable access to the buses itself. Furthermore
2207 it can access information on resources decoded by these devices and if
2208 necessary modify it.
2212 When first starting the Xserver collects all this information, saves it
2213 for restoration, checks it for consistency, and if necessary, corrects
2214 it. Finally it disables all resources on a generic level prior to
2215 calling any driver function.
2219 When the <function>Probe()</function> function of each driver is called the
2220 device sections are matched against the devices found in the system.
2221 The driver may probe devices at this stage that cannot be identified by
2222 using device independent methods. Access to all resources that can be
2223 controlled in a device independent way is disabled. The
2224 <function>Probe()</function> function should register all non-relocatable
2225 resources at this stage. If a resource conflict is found between
2226 exclusive resources the driver will fail immediately. Optionally the
2227 driver might specify an <function>EntityInit()</function>,
2228 <function>EntityLeave()</function> and <function>EntityEnter()</function> function.
2232 <function>EntityInit()</function> can be used to disable any shared resources
2233 that are not controlled by the generic access control functions. It is
2234 called prior to the PreInit phase regardless if an entity is active or
2235 not. When calling the <function>EntityInit()</function>,
2236 <function>EntityEnter()</function> and <function>EntityLeave()</function> functions
2237 the common level will disable access to all other entities on a generic
2238 level. Since the common level has no knowledge of device specific
2239 methods to disable access to resources it cannot be guaranteed that
2240 certain resources are not decoded by any other entity until the
2241 <function>EntityInit()</function> or <function>EntityEnter()</function> phase is
2242 finished. Device drivers should therefore register all those resources
2243 which they are going to disable. If these resources are never to be
2244 used by any driver function they may be flagged <constant>ResInit</constant>
2245 so that they can be removed from the resource list after processing all
2246 <function>EntityInit()</function> functions. <function>EntityEnter()</function>
2247 should disable decoding of all resources which are not registered as
2248 exclusive and which are not handled by the generic access control in
2249 the common level. The difference to <function>EntityInit()</function> is
2250 that the latter one is only called once during lifetime of the server.
2251 It can therefore be used to set up variables prior to disabling resources.
2252 <function>EntityLeave()</function> should restore the original state when
2253 exiting the server or switching to a different VT. It also needs to
2254 disable device specific access functions if they need to be disabled on
2255 server exit or VT switch. The default state is to enable them before
2260 In <function>PreInit()</function> phase each driver should check if any
2261 sharable resources it has registered during <function>Probe()</function> has
2262 been denied and take appropriate action which could simply be to fail.
2263 If it needs to access resources it has disabled during
2264 <function>EntitySetup()</function> it can do so provided it has registered
2265 these and will disable them before returning from
2266 <function>PreInit()</function>. This also applies to all other driver
2267 functions. Several functions are provided to request resource ranges,
2268 register these, correct PCI config space and add replacements for the
2269 generic access functions. Resources may be marked <quote>disabled</quote> or
2270 <quote>unused</quote> during OPERATING stage. Although these steps could also be
2271 performed in <function>ScreenInit()</function>, this is not desirable.
2275 Following <function>PreInit()</function> phase the common level determines
2276 if resource access control is needed. This is the case if more than
2277 one screen is used. If necessary the RAC wrapper module is loaded. In
2278 <function>ScreenInit()</function> the drivers can decide which operations
2279 need to be placed under RAC. Available are the frame buffer operations,
2280 the pointer operations and the colormap operations. Any operation that
2281 requires resources which might be disabled during OPERATING state should
2282 be set to use RAC. This can be specified separately for memory and IO
2287 When <function>ScreenInit()</function> phase is done the common level will
2288 determine which shared resources are requested by more than one driver
2289 and set the access functions accordingly. This is done following these
2294 The sharable resources registered by each entity are compared. If
2295 a resource is registered by more than one entity the entity will be
2296 marked to need to share this resources type (<constant>IO</constant> or
2297 <constant>MEM</constant>).
2301 A resource marked <quote>disabled</quote> during OPERATING state will be ignored
2306 A resource marked <quote>unused</quote> will only conflicts with an overlapping
2307 resource of an other entity if the second is actually in use during
2312 If an <quote>unused</quote> resource was found to conflict however the entity
2313 does not use any other resource of this type the entire resource type
2314 will be disabled for that entity.
2320 The driver has the choice among different ways to control access to
2325 It can rely on the generic access functions. This is probably the
2326 most common case. Here the driver only needs to register any resource
2331 It can replace the generic access functions by driver specific
2332 ones. This will mostly be used in cases where no generic access
2333 functions are available. In this case the driver has to make sure
2334 these resources are disabled when entering the <function>PreInit()</function>
2335 stage. Since the replacement functions are registered in
2336 <function>PreInit()</function> the driver will have to enable these
2337 resources itself if it needs to access them during this state. The
2338 driver can specify if the replacement functions can control memory
2339 and/or I/O resources separately.
2343 The driver can enable resources itself when it needs them. Each
2344 driver function enabling them needs to disable them before it will
2345 return. This should be used if a resource which can be controlled
2346 in a device dependent way is only required during SETUP state. This
2347 way it can be marked <quote>unused</quote> during OPERATING state.
2353 A resource which is decoded during OPERATING state however never accessed
2354 by the driver should be marked unused.
2358 Since access switching latencies are an issue during Xserver operation,
2359 the common level attempts to minimize the number of entities that need
2360 to be placed under RAC control. When a wrapped operation is called,
2361 the <function>EnableAccess()</function> function is called before control is
2362 passed on. <function>EnableAccess()</function> checks if a screen is under
2363 access control. If not it just establishes bus routing and returns.
2364 If the screen needs to be under access control,
2365 <function>EnableAccess()</function> determines which resource types
2366 (<literal remap="tt">MEM</literal>, <literal remap="tt">IO</literal>) are required. Then it tests
2367 if this access is already established. If so it simply returns. If
2368 not it disables the currently established access, fixes bus routing and
2369 enables access to all entities registered for this screen.
2373 Whenever a mode switch or a VT-switch is performed the common level will
2374 return to SETUP state.
2379 <title>Resource Types</title>
2382 Resource have certain properties. When registering resources each range
2383 is accompanied by a flag consisting of the ORed flags of the different
2384 properties the resource has. Each resource range may be classified
2389 its physical properties i.e., if it addresses
2390 memory (<constant>ResMem</constant>) or
2391 I/O space (<constant>ResIo</constant>),
2395 block (<constant>ResBlock</constant>) or
2396 sparse (<constant>ResSparse</constant>)
2400 its access properties.
2406 There are two known access properties:
2410 <constant>ResExclusive</constant>
2411 for resources which may not be shared with any other device and
2414 <constant>ResShared</constant>
2415 for resources which can be disabled and therefore can be shared.
2421 If it is necessary to test a resource against any type a generic access
2422 type <constant>ResAny</constant> is provided. If this is set the resource
2423 will conflict with any resource of a different entity intersecting its
2424 range. Further it can be specified that a resource is decoded however
2425 never used during any stage (<constant>ResUnused</constant>) or during
2426 OPERATING state (<constant>ResUnusedOpr</constant>). A resource only visible
2427 during the init functions (ie. <function>EntityInit()</function>,
2428 <function>EntityEnter()</function> and <function>EntityLeave()</function> should
2429 be registered with the flag <constant>ResInit</constant>. A resource that
2430 might conflict with background resource ranges may be flagged with
2431 <constant>ResBios</constant>. This might be useful when registering resources
2432 ranges that were assigned by the system Bios.
2436 Several predefined resource lists are available for VGA and 8514/A
2437 resources in <filename>common/xf86Resources.h</filename>.
2442 <title>Available Functions</title>
2445 The functions provided for resource management are listed in their order
2446 of use in the driver.
2450 <title>Probe Phase</title>
2453 In this phase each driver detects those resources it is able to drive,
2454 creates an entity record for each of them, registers non-relocatable
2455 resources and allocates screens and adds the resources to screens.
2459 Two helper functions are provided for matching device sections in the
2460 xorg.conf file to the devices:
2465 int xf86MatchPciInstances(const char *driverName, int vendorID,
2466 SymTabPtr chipsets, PciChipsets *PCIchipsets,
2467 GDevPtr *devList, int numDevs, DriverPtr drvp,
2468 int **foundEntities);
2471 This function finds matches between PCI cards that a driver supports
2472 and config file device sections. It is intended for use in the
2473 <function>ChipProbe()</function> function of drivers for PCI cards.
2474 Only probed PCI devices with a vendor ID matching
2475 <parameter>vendorID</parameter> are considered. <parameter>devList</parameter>
2476 and <parameter>numDevs</parameter> are typically those found from
2477 calling <function>xf86MatchDevice()</function>, and represent the active
2478 config file device sections relevant to the driver.
2479 <parameter>PCIchipsets</parameter> is a table that provides a mapping
2480 between the PCI device IDs, the driver's internal chipset tokens
2481 and a list of fixed resources.
2485 When a device section doesn't have a <emphasis>BusID</emphasis> entry it
2486 can only match the primary video device. Secondary devices are
2487 only matched with device sections that have a matching
2488 <emphasis>BusID</emphasis> entry.
2492 Once the preliminary matches have been found, a final match is
2493 confirmed by checking if the chipset override, ChipID override or
2494 probed PCI chipset type match one of those given in the
2495 <parameter>chipsets</parameter> and <parameter>PCIchipsets</parameter> lists.
2496 The <parameter>PCIchipsets</parameter> list includes a list of the PCI
2497 device IDs supported by the driver. The list should be terminated
2498 with an entry with PCI ID <constant>-1</constant>". The
2499 <parameter>chipsets</parameter> list is a table mapping the driver's
2500 internal chipset tokens to names, and should be terminated with
2501 a <constant>NULL</constant> entry. Only those entries with a
2502 corresponding entry in the <parameter>PCIchipsets</parameter> list are
2503 considered. The order of precedence is: config file chipset,
2504 config file ChipID, probed PCI device ID.
2508 In cases where a driver handles PCI chipsets with more than one
2509 vendor ID, it may set <parameter>vendorID</parameter> to
2510 <constant>0</constant>, and OR each devID in the list with (the
2511 vendor ID << 16).
2515 Entity index numbers for confirmed matches are returned as an
2516 array via <parameter>foundEntities</parameter>. The PCI information,
2517 chipset token and device section for each match are found in the
2518 <structname>EntityInfoRec</structname> referenced by the indices.
2522 The function return value is the number of confirmed matches. A
2523 return value of <constant>-1</constant> indicates an internal error.
2524 The returned <parameter>foundEntities</parameter> array should be freed
2525 by the driver with <function>xfree()</function> when it is no longer
2526 needed in cases where the return value is greater than zero.
2529 </blockquote></para></blockquote>
2533 int xf86MatchIsaInstances(const char *driverName,
2534 SymTabPtr chipsets, IsaChipsets *ISAchipsets,
2535 DriverPtr drvp, FindIsaDevProc FindIsaDevice,
2536 GDevPtr *devList, int numDevs,
2537 int **foundEntities);
2540 This function finds matches between ISA cards that a driver supports
2541 and config file device sections. It is intended for use in the
2542 <function>ChipProbe()</function> function of drivers for ISA cards.
2543 <parameter>devList</parameter> and <parameter>numDevs</parameter> are
2544 typically those found from calling <function>xf86MatchDevice()</function>,
2545 and represent the active config file device sections relevant to
2546 the driver. <parameter>ISAchipsets</parameter> is a table that provides
2547 a mapping between the driver's internal chipset tokens and the
2548 resource classes. <parameter>FindIsaDevice</parameter> is a
2549 driver-provided function that probes the hardware and returns the
2550 chipset token corresponding to what was detected, and
2551 <constant>-1</constant> if nothing was detected.
2555 If the config file device section contains a chipset entry, then
2556 it is checked against the <parameter>chipsets</parameter> list. When
2557 no chipset entry is present, the <parameter>FindIsaDevice</parameter>
2558 function is called instead.
2562 Entity index numbers for confirmed matches are returned as an
2563 array via <parameter>foundEntities</parameter>. The chipset token and
2564 device section for each match are found in the
2565 <structname>EntityInfoRec</structname> referenced by the indices.
2569 The function return value is the number of confirmed matches. A
2570 return value of <constant>-1</constant> indicates an internal error.
2571 The returned <parameter>foundEntities</parameter> array should be freed
2572 by the driver with <function>xfree()</function> when it is no longer
2573 needed in cases where the return value is greater than zero.
2576 </blockquote></para></blockquote>
2579 These two helper functions make use of several core functions that are
2580 available at the driver level:
2585 Bool xf86ParsePciBusString(const char *busID, int *bus,
2586 int *device, int *func);
2589 Takes a <parameter>BusID</parameter> string, and if it is in the correct
2590 format, returns the PCI <parameter>bus</parameter>, <parameter>device</parameter>,
2591 <parameter>func</parameter> values that it indicates. The format of the
2592 string is expected to be "PCI:bus:device:func" where each of <quote>bus</quote>,
2593 <quote>device</quote> and <quote>func</quote> are decimal integers. The ":func" part may
2594 be omitted, and the func value assumed to be zero, but this isn't
2595 encouraged. The "PCI" prefix may also be omitted. The prefix
2596 "AGP" is currently equivalent to the "PCI" prefix. If the string
2597 isn't a valid PCI BusID, the return value is <constant>FALSE</constant>.
2600 </blockquote></para></blockquote>
2604 Bool xf86ComparePciBusString(const char *busID, int bus,
2605 int device, int func);
2608 Compares a <parameter>BusID</parameter> string with PCI <parameter>bus</parameter>,
2609 <parameter>device</parameter>, <parameter>func</parameter> values. If they
2610 match <constant>TRUE</constant> is returned, and <constant>FALSE</constant>
2614 </blockquote></para></blockquote>
2618 Bool xf86ParseIsaBusString(const char *busID);
2621 Compares a <parameter>BusID</parameter> string with the ISA bus ID string
2622 ("ISA" or "ISA:"). If they match <constant>TRUE</constant> is returned,
2623 and <constant>FALSE</constant> if they don't.
2626 </blockquote></para></blockquote>
2630 Bool xf86CheckPciSlot(int bus, int device, int func);
2633 Checks if the PCI slot <literal remap="tt">bus:device:func</literal> has been
2634 claimed. If so, it returns <constant>FALSE</constant>, and otherwise
2635 <constant>TRUE</constant>.
2638 </blockquote></para></blockquote>
2642 int xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp,
2643 int chipset, GDevPtr dev, Bool active);
2646 This function is used to claim a PCI slot, allocate the associated
2647 entity record and initialise their data structures. The return
2648 value is the index of the newly allocated entity record, or
2649 <constant>-1</constant> if the claim fails. This function should always
2650 succeed if <function>xf86CheckPciSlot()</function> returned
2651 <constant>TRUE</constant> for the same PCI slot.
2654 </blockquote></para></blockquote>
2658 Bool xf86IsPrimaryPci(void);
2661 This function returns <constant>TRUE</constant> if the primary card is
2662 a PCI device, and <constant>FALSE</constant> otherwise.
2665 </blockquote></para></blockquote>
2669 int xf86ClaimIsaSlot(DriverPtr drvp, int chipset,
2670 GDevPtr dev, Bool active);
2673 This allocates an entity record entity and initialise the data
2674 structures. The return value is the index of the newly allocated
2678 </blockquote></para></blockquote>
2682 Bool xf86IsPrimaryIsa(void);
2685 This function returns <constant>TRUE</constant> if the primary card is
2686 an ISA (non-PCI) device, and <constant>FALSE</constant> otherwise.
2689 </blockquote></para></blockquote>
2692 Two helper functions are provided to aid configuring entities:
2697 ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn,
2698 int scrnFlag, int entityIndex,
2699 PciChipsets *p_chip,
2700 resList res, EntityProc init,
2701 EntityProc enter, EntityProc leave,
2704 ScrnInfoPtr xf86ConfigIsaEntity(ScrnInfoPtr pScrn,
2705 int scrnFlag, int entityIndex,
2706 IsaChipsets *i_chip,
2707 resList res, EntityProc init,
2708 EntityProc enter, EntityProc leave,
2712 These functions are used to register the non-relocatable resources
2713 for an entity, and the optional entity-specific <parameter>Init</parameter>, <parameter>Enter</parameter> and
2714 <parameter>Leave</parameter> functions. Usually the list of fixed resources is obtained
2715 from the Isa/PciChipsets lists. However an additional list of
2716 resources may be passed. Generally this is not required.
2717 For active entities a <structname>ScrnInfoRec</structname> is allocated
2718 if the <parameter>pScrn</parameter> argument is <constant>NULL</constant>.
2720 return value is <constant>TRUE</constant> when successful. The init, enter, leave
2721 functions are defined as follows:
2725 typedef void (*EntityProc)(int entityIndex,
2728 </para></blockquote>
2730 They are passed the entity index and a pointer to a private scratch
2731 area. This can be set up during <function>Probe()</function> and
2732 its address can be passed to
2733 <function>xf86ConfigIsaEntity()</function> and
2734 <function>xf86ConfigPciEntity()</function> as the last argument.
2737 </blockquote></para></blockquote>
2740 These two helper functions make use of several core functions that are
2741 available at the driver level:
2745 void xf86ClaimFixedResources(resList list, int entityIndex);
2748 This function registers the non-relocatable resources which cannot
2749 be disabled and which therefore would cause the server to fail
2750 immediately if they were found to conflict. It also records
2751 non-relocatable but sharable resources for processing after the
2752 <function>Probe()</function> phase.
2755 </blockquote></para></blockquote>
2759 Bool xf86SetEntityFuncs(int entityIndex, EntityProc init,
2760 EntityProc enter, EntityProc leave, pointer);
2763 This function registers with an entity the <parameter>init</parameter>,
2764 <parameter>enter</parameter>, <parameter>leave</parameter> functions along
2765 with the pointer to their private area.
2768 </blockquote></para></blockquote>
2772 void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex);
2775 This function associates the entity referenced by
2776 <parameter>entityIndex</parameter> with the screen.
2779 </blockquote></para></blockquote>
2784 <title>PreInit Phase</title>
2787 During this phase the remaining resources should be registered.
2788 <function>PreInit()</function> should call <function>xf86GetEntityInfo()</function>
2789 to obtain a pointer to an <structname>EntityInfoRec</structname> for each entity
2790 it is able to drive and check if any resource are listed in its
2791 <structfield>resources</structfield> field. If resources registered in the Probe
2792 phase have been rejected in the post-Probe phase
2793 (<structfield>resources</structfield> is non-<constant>NULL</constant>), then the driver should
2794 decide if it can continue without using these or if it should fail.
2799 EntityInfoPtr xf86GetEntityInfo(int entityIndex);
2802 This function returns a pointer to the <structname>EntityInfoRec</structname>
2803 referenced by <parameter>entityIndex</parameter>. The returned
2804 <structname>EntityInfoRec</structname> should be freed with
2805 <function>xfree()</function> when no longer needed.
2808 </blockquote></para></blockquote>
2811 Several functions are provided to simplify resource registration:
2814 Bool xf86IsEntityPrimary(int entityIndex);
2817 This function returns <constant>TRUE</constant> if the entity referenced
2818 by <parameter>entityIndex</parameter> is the primary display device (i.e.,
2819 the one initialised at boot time and used in text mode).
2822 </blockquote></para></blockquote>
2826 Bool xf86IsScreenPrimary(ScrnInfoPtr pScrn);
2829 This function returns <constant>TRUE</constant> if the primary entity
2830 is registered with the screen referenced by
2831 <parameter>pScrn</parameter>.
2834 </blockquote></para></blockquote>
2838 pciVideoPtr xf86GetPciInfoForEntity(int entityIndex);
2841 This function returns a pointer to the <structname>pciVideoRec</structname>
2842 for the specified entity. If the entity is not a PCI device,
2843 <constant>NULL</constant> is returned.
2846 </blockquote></para></blockquote>
2850 The primary function for registration of resources is:
2853 resPtr xf86RegisterResources(int entityIndex, resList list,
2857 This function tries to register the resources in
2858 <parameter>list</parameter>. If list is <constant>NULL</constant> it tries
2859 to determine the resources automatically. This only works for
2860 entities that provide a generic way to read out the resource ranges
2861 they decode. So far this is only the case for PCI devices. By
2862 default the PCI resources are registered as shared
2863 (<constant>ResShared</constant>) if the driver wants to set a different
2864 access type it can do so by specifying the access flags in the
2865 third argument. A value of <constant>0</constant> means to use the
2866 default settings. If for any reason the resource broker is not
2867 able to register some of the requested resources the function will
2868 return a pointer to a list of the failed ones. In this case the
2869 driver may be able to move the resource to different locations.
2870 In case of PCI bus entities this is done by passing the list of
2871 failed resources to <function>xf86ReallocatePciResources()</function>.
2872 When the registration succeeds, the return value is
2873 <constant>NULL</constant>.
2876 </blockquote></para></blockquote>
2881 resPtr xf86ReallocatePciResources(int entityIndex, resPtr pRes);
2884 This function takes a list of PCI resources that need to be
2885 reallocated and returns <constant>NULL</constant> when all relocations are
2887 <function>xf86RegisterResources()</function> should be called again to
2888 register the relocated resources with the broker.
2889 If the reallocation fails, a list of the resources that could not be
2890 relocated is returned.
2893 </blockquote></para></blockquote>
2896 Two functions are provided to obtain a resource range of a given type:
2899 resRange xf86GetBlock(long type, memType size,
2900 memType window_start, memType window_end,
2901 memType align_mask, resPtr avoid);
2904 This function tries to find a block range of size
2905 <parameter>size</parameter> and type <parameter>type</parameter> in a window
2906 bound by <parameter>window_start</parameter> and <parameter>window_end</parameter>
2907 with the alignment specified in <parameter>align_mask</parameter>.
2908 Optionally a list of resource ranges which should be avoided within
2909 the window can be supplied. On failure a zero-length range of
2910 type <constant>ResEnd</constant> will be returned.
2912 </blockquote></para></blockquote>
2916 resRange xf86GetSparse(long type, memType fixed_bits,
2917 memType decode_mask, memType address_mask,
2921 This function is like the previous one, but attempts to find a
2922 sparse range instead of a block range. Here three values have to
2923 be specified: the <parameter>address_mask</parameter> which marks all
2924 bits of the mask part of the address, the <parameter>decode_mask</parameter>
2925 which masks out the bits which are hardcoded and are therefore
2926 not available for relocation and the values of the fixed bits.
2927 The function tries to find a base that satisfies the given condition.
2928 If the function fails it will return a zero range of type
2929 <constant>ResEnd</constant>. Optionally it might be passed a list of
2930 resource ranges to avoid.
2933 </blockquote></para></blockquote>
2937 Some PCI devices are broken in the sense that they return invalid size
2938 information for a certain resource. In this case the driver can supply
2939 the correct size and make sure that the resource range allocated for
2940 the card is large enough to hold the address range decoded by the card.
2941 The function <function>xf86FixPciResource()</function> can be used to do this:
2944 Bool xf86FixPciResource(int entityIndex, unsigned int prt,
2945 CARD32 alignment, long type);
2948 This function fixes a PCI resource allocation. The
2949 <parameter>prt</parameter> parameter contains the number of the PCI base
2950 register that needs to be fixed (<constant>0-5</constant>, and
2951 <constant>6</constant> for the BIOS base register). The size is
2952 specified by the alignment. Since PCI resources need to span an
2953 integral range of size <literal remap="tt">2ˆn</literal>, the alignm ent also
2954 specifies the number of addresses that will be decoded. If the
2955 driver specifies a type mask it can override the default type for
2956 PCI resources which is <constant>ResShared</constant>. The resource
2957 broker needs to know that to find a matching resource range. This
2958 function should be called before calling
2959 <function>xf86RegisterResources()</function>. The return value is
2960 <constant>TRUE</constant> when the function succeeds.
2963 </blockquote></para></blockquote>
2967 Bool xf86CheckPciMemBase(pciVideoPtr pPci, memType base);
2970 This function checks that the memory base address specified matches
2971 one of the PCI base address register values for the given PCI
2972 device. This is mostly used to check that an externally provided
2973 base address (e.g., from a config file) matches an actual value
2974 allocated to a device.
2977 </blockquote></para></blockquote>
2981 The driver may replace the generic access control functions for an entity.
2982 This is done with the <function>xf86SetAccessFuncs()</function>:
2985 void xf86SetAccessFuncs(EntityInfoPtr pEnt,
2986 xf86SetAccessFuncPtr funcs,
2987 xf86SetAccessFuncPtr oldFuncs);
2994 xf86AccessPtr io_mem;
2995 } xf86SetAccessFuncRec, *xf86SetAccessFuncPtr;
2998 The driver can pass three functions: one for I/O access, one for
2999 memory access and one for combined memory and I/O access. If the
3000 memory access and combined access functions are identical the
3001 common level assumes that the memory access cannot be controlled
3002 independently of I/O access, if the I/O access function and the
3003 combined access functions are the same it is assumed that I/O can
3004 not be controlled independently. If memory and I/O have to be
3005 controlled together all three values should be the same. If a
3006 non <constant>NULL</constant> value is passed as third argument it is
3007 interpreted as an address where to store the old access record.
3008 If the third argument is <constant>NULL</constant> it will be assumed
3009 that the generic access should be enabled before replacing the
3010 access functions. Otherwise it will be disabled. The driver may
3011 enable them itself using the returned values. It should do this
3012 from its replacement access functions as the generic access may
3013 be disabled by the common level on certain occasions. If replacement
3014 functions are specified they must control all resources of the
3015 specific type registered for the entity.
3018 </blockquote></para></blockquote>
3022 To find out if a specific resource range conflicts with another
3023 resource the <function>xf86ChkConflict()</function> function may be used:
3026 memType xf86ChkConflict(resRange *rgp, int entityIndex);
3029 This function checks if the resource range <parameter>rgp</parameter> of
3030 for the specified entity conflicts with with another resource.
3031 If a conflict is found, the address of the start of the conflict
3032 is returned. The return value is zero when there is no conflict.
3035 </blockquote></para></blockquote>
3039 The OPERATING state properties of previously registered fixed resources
3040 can be set with the <function>xf86SetOperatingState()</function> function:
3043 resPtr xf86SetOperatingState(resList list, int entityIndex,
3047 This function is used to set the status of a resource during
3048 OPERATING state. <parameter>list</parameter> holds a list to which
3049 <parameter>mask</parameter> is to be applied. The parameter
3050 <parameter>mask</parameter> may have the value <constant>ResUnusedOpr</constant>
3051 and <constant>ResDisableOpr</constant>. The first one should be used
3052 if a resource isn't used by the driver during OPERATING state
3053 although it is decoded by the device, while the latter one indicates
3054 that the resource is not decoded during OPERATING state. Note
3055 that the resource ranges have to match those specified during
3056 registration. If a range has been specified starting at
3057 <literal remap="tt">A</literal> and ending at <literal remap="tt">B</literal> and suppose
3058 <literal remap="tt">C</literal> us a value satisfying
3059 <literal remap="tt">A < C < B</literal> one may not
3060 specify the resource range <literal remap="tt">(A,B)</literal> by splitting it
3061 into two ranges <literal remap="tt">(A,C)</literal> and <literal remap="tt">(C,B)</literal>.
3064 </blockquote></para></blockquote>
3068 The following two functions are provided for special cases:
3071 void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex);
3074 This function may be used to remove an entity from a screen. This
3075 only makes sense if a screen has more than one entity assigned or
3076 the screen is to be deleted. No test is made if the screen has
3080 </blockquote></para></blockquote>
3084 void xf86DeallocateResourcesForEntity(int entityIndex, long type);
3087 This function deallocates all resources of a given type registered
3088 for a certain entity from the resource broker list.
3091 </blockquote></para></blockquote>
3097 <title>ScreenInit Phase</title>
3100 All that is required in this phase is to setup the RAC flags. Note that
3101 it is also permissible to set these flags up in the PreInit phase. The
3102 RAC flags are held in the <structfield>racIoFlags</structfield> and <structfield>racMemFlags</structfield> fields of the
3103 <structname>ScrnInfoRec</structname> for each screen. They specify which graphics operations
3104 might require the use of shared resources. This can be specified
3105 separately for memory and I/O resources. The available flags are defined
3106 in <filename>rac/xf86RAC.h</filename>. They are:
3109 <varlistentry><term><constant>RAC_FB</constant></term>
3111 for framebuffer operations (including hw acceleration)
3112 </para></listitem></varlistentry>
3113 <varlistentry><term><constant>RAC_CURSOR</constant></term>
3115 for Cursor operations
3116 (??? I'm not sure if we need this for SW cursor it depends
3117 on which level the sw cursor is drawn)
3118 </para></listitem></varlistentry>
3119 <varlistentry><term><constant>RAC_COLORMAP</constant></term>
3121 for colormap operations
3122 </para></listitem></varlistentry>
3123 <varlistentry><term><constant>RAC_VIEWPORT</constant></term>
3125 for the call to <function>ChipAdjustFrame()</function>
3126 </para></listitem></varlistentry>
3130 The flags are ORed together.
3136 <sect1 id="options">
3137 <title>Config file <quote>Option</quote> entries</title>
3140 Option entries are permitted in most sections and subsections of the
3141 config file. There are two forms of option entries:
3144 <varlistentry><term>Option "option-name"</term>
3147 </para></listitem></varlistentry>
3148 <varlistentry><term>Option "option-name" "option-value"</term>
3150 An option with an arbitrary value.
3151 </para></listitem></varlistentry>
3156 The option entries are handled by the parser, and a list of the parsed
3157 options is included with each of the appropriate data structures that
3158 the drivers have access to. The data structures used to hold the option
3159 information are opaque to the driver, and a driver must not access the
3160 option data directly. Instead, the common layer provides a set of
3161 functions that may be used to access, check and manipulate the option
3166 First, the low level option handling functions. In most cases drivers
3167 would not need to use these directly.
3172 XF86OptionPtr xf86FindOption(XF86OptionPtr options, const char *name);
3175 Takes a list of options and an option name, and returns a handle
3176 for the first option entry in the list matching the name. Returns
3177 <constant>NULL</constant> if no match is found.
3180 </blockquote></para></blockquote>
3184 const char *xf86FindOptionValue(XF86OptionPtr options, const char *name);
3187 Takes a list of options and an option name, and returns the value
3188 associated with the first option entry in the list matching the
3189 name. If the matching option has no value, an empty string
3190 (<constant>""</constant>) is returned. Returns <constant>NULL</constant>
3191 if no match is found.
3194 </blockquote></para></blockquote>
3198 void xf86MarkOptionUsed(XF86OptionPtr option);
3201 Takes a handle for an option, and marks that option as used.
3204 </blockquote></para></blockquote>
3208 void xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name);
3211 Takes a list of options and an option name and marks the first
3212 option entry in the list matching the name as used.
3215 </blockquote></para></blockquote>
3218 Next, the higher level functions that most drivers would use.
3222 void xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts);
3225 Collect the options from each of the config file sections used by
3226 the screen (<parameter>pScrn</parameter>) and return the merged list as
3227 <structfield>pScrn->options</structfield>. This function requires that
3228 <structfield>pScrn->confScreen</structfield>, <structfield>pScrn->display</structfield>,
3229 <structfield>pScrn->monitor</structfield>,
3230 <structfield>pScrn->numEntities</structfield>, and
3231 <structfield>pScrn->entityList</structfield> are initialised.
3232 <parameter>extraOpts</parameter> may optionally be set to an additional
3233 list of options to be combined with the others. The order of
3234 precedence for options is <parameter>extraOpts</parameter>, display,
3235 confScreen, monitor, device.
3238 </blockquote></para></blockquote>
3242 void xf86ProcessOptions(int scrnIndex, XF86OptionPtr options,
3243 OptionInfoPtr optinfo);
3246 Processes a list of options according to the information in the
3247 array of <structname>OptionInfoRecs</structname> (<parameter>optinfo</parameter>).
3248 The resulting information is stored in the <structfield>value</structfield>
3249 fields of the appropriate <parameter>optinfo</parameter> entries. The
3250 <structfield>found</structfield> fields are set to <constant>TRUE</constant>
3251 when an option with a value of the correct type if found, and
3252 <constant>FALSE</constant> otherwise. The <structfield>type</structfield> field
3253 is used to determine the expected value type for each option.
3254 Each option in the list of options for which there is a name match
3255 (but not necessarily a value type match) is marked as used.
3256 Warning messages are printed when option values don't match the
3257 types specified in the optinfo data.
3261 NOTE: If this function is called before a driver's screen number
3262 is known (e.g., from the <function>ChipProbe()</function> function) a
3263 <parameter>scrnIndex</parameter> value of <constant>-1</constant> should be
3268 NOTE 2: Given that this function stores into the
3269 <literal remap="tt">OptionInfoRecs</literal> pointed to by <parameter>optinfo</parameter>,
3270 the caller should ensure the <literal remap="tt">OptionInfoRecs</literal> are
3271 (re-)initialised before the call, especially if the caller expects
3272 to use the predefined option values as defaults.
3276 The <structname>OptionInfoRec</structname> is defined as follows:
3295 OPTV_STRING, /* a non-empty string */
3296 OPTV_ANYSTR, /* Any string, including an empty one */
3312 OptionValueType type;
3315 } OptionInfoRec, *OptionInfoPtr;
3319 <constant>OPTV_FREQ</constant> can be used for options values that are
3320 frequencies. These values are a floating point number with an
3321 optional unit name appended. The unit name can be one of "Hz",
3322 "kHz", "k", "MHz", "M". The multiplier associated with the unit
3323 is stored in <structfield>freq.units</structfield>, and the scaled frequency
3324 is stored in <structfield>freq.freq</structfield>. When no unit is specified,
3325 <structfield>freq.units</structfield> is set to <constant>0</constant>, and
3326 <structfield>freq.freq</structfield> is unscaled.
3330 <constant>OPTV_PERCENT</constant> can be used for option values that are
3331 specified in percent (e.g. "20%"). These values are a floating point
3332 number with a percent sign appended. If the percent sign is missing,
3333 the parser will fail to match the value.
3337 Typical usage is to setup an array of
3338 <structname>OptionInfoRec</structname>s with all fields initialised.
3339 The <structfield>value</structfield> and <structfield>found</structfield> fields get
3340 set by <function>xf86ProcessOptions()</function>. For cases where the
3341 value parsing is more complex, the driver should specify
3342 <constant>OPTV_STRING</constant>, and parse the string itself. An
3343 example of using this option handling is included in the
3344 <link linkend="sample">Sample Driver</link> section.
3347 </blockquote></para></blockquote>
3351 void xf86ShowUnusedOptions(int scrnIndex, XF86OptionPtr options);
3354 Prints out warning messages for each option in the list of options
3355 that isn't marked as used. This is intended to show options that
3356 the driver hasn't recognised. It would normally be called near
3357 the end of the <function>ChipScreenInit()</function> function, but only
3358 when <code>serverGeneration == 1</code>
3360 </blockquote></para></blockquote>
3364 OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table,
3368 Returns a pointer to the <structname>OptionInfoRec</structname> in
3369 <parameter>table</parameter> with a token field matching
3370 <parameter>token</parameter>. Returns <constant>NULL</constant> if no match
3374 </blockquote></para></blockquote>
3378 Bool xf86IsOptionSet(const OptionInfoRec *table, int token);
3381 Returns the <literal remap="tt">found</literal> field of the
3382 <structname>OptionInfoRec</structname> in <parameter>table</parameter> with a
3383 <structfield>token</structfield> field matching <parameter>token</parameter>. This
3384 can be used for options of all types. Note that for options of
3385 type <constant>OPTV_BOOLEAN</constant>, it isn't sufficient to check
3386 this to determine the value of the option. Returns
3387 <constant>FALSE</constant> if no match is found.
3390 </blockquote></para></blockquote>
3394 char *xf86GetOptValString(const OptionInfoRec *table, int token);
3397 Returns the <structfield>value.str</structfield> field of the
3398 <structname>OptionInfoRec</structname> in <parameter>table</parameter> with a
3399 token field matching <parameter>token</parameter>. Returns
3400 <constant>NULL</constant> if no match is found.
3403 </blockquote></para></blockquote>
3407 Bool xf86GetOptValInteger(const OptionInfoRec *table, int token,
3412 Returns via <parameter>*value</parameter> the <structfield>value.num</structfield>
3413 field of the <structname>OptionInfoRec</structname> in <parameter>table</parameter>
3414 with a <structfield>token</structfield> field matching <parameter>token</parameter>.
3415 <parameter>*value</parameter> is only changed when a match is found so
3416 it can be safely initialised with a default prior to calling this
3417 function. The function return value is as for
3418 <function>xf86IsOptionSet()</function>.
3421 </blockquote></para></blockquote>
3425 Bool xf86GetOptValULong(const OptionInfoRec *table, int token,
3426 unsigned long *value);
3429 Like <function>xf86GetOptValInteger()</function>, except the value is
3430 treated as an <type>unsigned long</type>.
3433 </blockquote></para></blockquote>
3437 Bool xf86GetOptValReal(const OptionInfoRec *table, int token,
3441 Like <function>xf86GetOptValInteger()</function>, except that
3442 <structfield>value.realnum</structfield> is used.
3445 </blockquote></para></blockquote>
3449 Bool xf86GetOptValFreq(const OptionInfoRec *table, int token,
3450 OptFreqUnits expectedUnits, double *value);
3453 Like <function>xf86GetOptValInteger()</function>, except that the
3454 <structfield>value.freq</structfield> data is returned. The frequency value
3455 is scaled to the units indicated by <parameter>expectedUnits</parameter>.
3456 The scaling is exact when the units were specified explicitly in
3457 the option's value. Otherwise, the <parameter>expectedUnits</parameter>
3458 field is used as a hint when doing the scaling. In this case,
3459 values larger than <constant>1000</constant> are assumed to have be
3460 specified in the next smallest units. For example, if the Option
3461 value is "10000" and expectedUnits is <constant>OPTUNITS_MHZ</constant>,
3462 the value returned is <constant>10</constant>.
3465 </blockquote></para></blockquote>
3469 Bool xf86GetOptValBool(const OptionInfoRec *table, int token, Bool *value);
3472 This function is used to check boolean options
3473 (<constant>OPTV_BOOLEAN</constant>). If the function return value is
3474 <constant>FALSE</constant>, it means the option wasn't set. Otherwise
3475 <parameter>*value</parameter> is set to the boolean value indicated by
3476 the option's value. No option <parameter>value</parameter> is interpreted
3477 as <constant>TRUE</constant>. Option values meaning <constant>TRUE</constant>
3478 are "1", "yes", "on", "true", and option values meaning
3479 <constant>FALSE</constant> are "0", "no", "off", "false". Option names
3480 both with the "no" prefix in their names, and with that prefix
3481 removed are also checked and handled in the obvious way.
3482 <parameter>*value</parameter> is not changed when the option isn't present.
3483 It should normally be set to a default value before calling this
3487 </blockquote></para></blockquote>
3491 Bool xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def);
3494 This function is used to check boolean options
3495 (<constant>OPTV_BOOLEAN</constant>). If the option is set, its value
3496 is returned. If the options is not set, the default value specified
3497 by <parameter>def</parameter> is returned. The option interpretation is
3498 the same as for <function>xf86GetOptValBool()</function>.
3501 </blockquote></para></blockquote>
3505 int xf86NameCmp(const char *s1, const char *s2);
3508 This function should be used when comparing strings from the config
3509 file with expected values. It works like <function>strcmp()</function>,
3510 but is not case sensitive and space, tab, and <quote><literal>_</literal></quote> characters
3511 are ignored in the comparison. The use of this function isn't
3512 restricted to parsing option values. It may be used anywhere
3513 where this functionality required.
3516 </blockquote></para></blockquote>
3520 <title>Modules, Drivers, Include Files and Interface Issues</title>
3523 NOTE: this section is incomplete.
3528 <title>Include files</title>
3531 The following include files are typically required by video drivers:
3534 All drivers should include these:
3535 <literallayout><filename>
3540 </filename></literallayout>
3541 Wherever inb/outb (and related things) are used the following should be
3543 <literallayout><filename>
3545 </filename></literallayout>
3546 Note: in drivers, this must be included after <filename>"xf86_ansic.h"</filename>.
3550 Drivers that need to access the PCI config space need this:
3551 <literallayout><filename>
3553 </filename></literallayout>
3557 Drivers that initialise a SW cursor need this:
3558 <literallayout><filename>
3560 </filename></literallayout>
3564 All drivers implementing backing store need this:
3565 <literallayout><filename>
3567 </filename></literallayout>
3571 All drivers using the mi colourmap code need this:
3572 <literallayout><filename>
3574 </filename></literallayout>
3578 If a driver uses the vgahw module, it needs this:
3579 <literallayout><filename>
3581 </filename></literallayout>
3585 Drivers supporting VGA or Hercules monochrome screens need:
3586 <literallayout><filename>
3588 </filename></literallayout>
3592 Drivers supporting VGA or EGC 16-colour screens need:
3593 <literallayout><filename>
3595 </filename></literallayout>
3599 Drivers using cfb need:
3608 Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
3609 <literallayout><filename>
3613 </filename></literallayout>
3617 If a driver uses the fb manager, it needs this:
3618 <literallayout><filename>
3620 </filename></literallayout>
3626 Non-driver modules should include <filename>"xf86_ansic.h"</filename> to get the correct
3627 wrapping of ANSI C/libc functions.
3631 All modules must NOT include any system include files, or the following:
3633 <literallayout><filename>
3638 </filename></literallayout>
3642 In addition, "xf86_libc.h" must not be included explicitly. It is
3643 included implicitly by "xf86_ansic.h".
3650 <title>Offscreen Memory Manager</title>
3653 Management of offscreen video memory may be handled by the XFree86
3654 framebuffer manager. Once the offscreen memory manager is running,
3655 drivers or extensions may allocate, free or resize areas of offscreen
3656 video memory using the following functions (definitions taken from
3657 <filename>xf86fbman.h</filename>):
3660 typedef struct _FBArea {
3664 void (*MoveAreaCallback)(struct _FBArea*, struct _FBArea*)
3665 void (*RemoveAreaCallback)(struct _FBArea*)
3666 DevUnion devPrivate;
3667 } FBArea, *FBAreaPtr;
3669 typedef void (*MoveAreaCallbackProcPtr)(FBAreaPtr from, FBAreaPtr to)
3670 typedef void (*RemoveAreaCallbackProcPtr)(FBAreaPtr)
3672 FBAreaPtr xf86AllocateOffscreenArea (
3674 int width, int height,
3676 MoveAreaCallbackProcPtr MoveAreaCallback,
3677 RemoveAreaCallbackProcPtr RemoveAreaCallback,
3681 void xf86FreeOffscreenArea (FBAreaPtr area)
3683 Bool xf86ResizeOffscreenArea (
3693 Bool xf86FBManagerRunning(ScreenPtr pScreen);
3696 can be used by an extension to check if the driver has initialized
3697 the memory manager. The manager is not available if this returns
3698 <constant>FALSE</constant> and the functions above will all fail.
3703 <function>xf86AllocateOffscreenArea()</function> can be used to request a
3704 rectangle of dimensions <parameter>width</parameter> × <parameter>height</parameter>
3705 (in pixels) from unused offscreen memory. <parameter>granularity</parameter>
3706 specifies that the leftmost edge of the rectangle must lie on some
3707 multiple of <parameter>granularity</parameter> pixels. A granularity of zero
3708 means the same thing as a granularity of one - no alignment preference.
3709 A <parameter>MoveAreaCallback</parameter> can be provided to notify the requester
3710 when the offscreen area is moved. If no <parameter>MoveAreaCallback</parameter>
3711 is supplied then the area is considered to be immovable. The
3712 <parameter>privData</parameter> field will be stored in the manager's internal
3713 structure for that allocated area and will be returned to the requester
3714 in the <parameter>FBArea</parameter> passed via the
3715 <parameter>MoveAreaCallback</parameter>. An optional
3716 <parameter>RemoveAreaCallback</parameter> is provided. If the driver provides
3717 this it indicates that the area should be allocated with a lower priority.
3718 Such an area may be removed when a higher priority request (one that
3719 doesn't have a <parameter>RemoveAreaCallback</parameter>) is made. When this
3720 function is called, the driver will have an opportunity to do whatever
3721 cleanup it needs to do to deal with the loss of the area, but it must
3722 finish its cleanup before the function exits since the offscreen memory
3723 manager will free the area immediately after.
3727 <function>xf86AllocateOffscreenArea()</function> returns <constant>NULL</constant>
3728 if it was unable to allocate the requested area. When no longer needed,
3729 areas should be freed with <function>xf86FreeOffscreenArea()</function>.
3733 <function>xf86ResizeOffscreenArea()</function> resizes an existing
3734 <literal remap="tt">FBArea</literal>. <function>xf86ResizeOffscreenArea()</function>
3735 returns <constant>TRUE</constant> if the resize was successful. If
3736 <function>xf86ResizeOffscreenArea()</function> returns <constant>FALSE</constant>,
3737 the original <literal remap="tt">FBArea</literal> is left unmodified. Resizing an
3738 area maintains the area's original <literal remap="tt">granularity</literal>,
3739 <literal remap="tt">devPrivate</literal>, and <literal remap="tt">MoveAreaCallback</literal>.
3740 <function>xf86ResizeOffscreenArea()</function> has considerably less overhead
3741 than freeing the old area then reallocating the new size, so it should
3742 be used whenever possible.
3748 Bool xf86QueryLargestOffscreenArea(
3750 int *width, int *height,
3757 is provided to query the width and height of the largest single
3758 <structname>FBArea</structname> allocatable given a particular priority.
3759 <parameter>preferences</parameter> can be one of the following to indicate
3760 whether width, height or area should be considered when determining
3761 which is the largest single <structname>FBArea</structname> available.
3764 FAVOR_AREA_THEN_WIDTH
3765 FAVOR_AREA_THEN_HEIGHT
3766 FAVOR_WIDTH_THEN_AREA
3767 FAVOR_HEIGHT_THEN_AREA
3772 <parameter>priority</parameter> is one of the following:
3776 <constant>PRIORITY_LOW</constant>
3778 Return the largest block available without stealing anyone else's
3779 space. This corresponds to the priority of allocating a
3780 <structname>FBArea</structname> when a <function>RemoveAreaCallback</function>
3782 </para></blockquote>
3786 <constant>PRIORITY_NORMAL</constant>
3788 Return the largest block available if it is acceptable to steal a
3789 lower priority area from someone. This corresponds to the priority
3790 of allocating a <structname>FBArea</structname> without providing a
3791 <function>RemoveAreaCallback</function>.
3792 </para></blockquote>
3796 <constant>PRIORITY_EXTREME</constant>
3798 Return the largest block available if all <structname>FBArea</structname>s
3799 that aren't locked down were expunged from memory first. This
3800 corresponds to any allocation made directly after a call to
3801 <function>xf86PurgeUnlockedOffscreenAreas()</function>.
3802 </para></blockquote>
3813 Bool xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen);
3816 is provided as an extreme method to free up offscreen memory. This
3817 will remove all removable <structname>FBArea</structname> allocations.
3822 Initialization of the XFree86 framebuffer manager is done via
3825 Bool xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox);
3828 <parameter>FullBox</parameter> represents the area of the framebuffer that the
3829 manager is allowed to manage. This is typically a box with a width of
3830 <structfield>pScrn->displayWidth</structfield> and a height of as many lines as
3831 can be fit within the total video memory, however, the driver can reserve
3832 areas at the extremities by passing a smaller area to the manager.
3837 <title>Colormap Handling</title>
3840 A generic colormap handling layer is provided within the XFree86 common
3841 layer. This layer takes care of most of the details, and only requires
3842 a function from the driver that loads the hardware palette when required.
3843 To use the colormap layer, a driver calls the
3844 <function>xf86HandleColormaps()</function> function.
3848 Bool xf86HandleColormaps(ScreenPtr pScreen, int maxColors,
3849 int sigRGBbits, LoadPaletteFuncPtr loadPalette,
3850 SetOverscanFuncPtr setOverscan,
3851 unsigned int flags);
3854 This function must be called after the default colormap has been
3855 initialised. The <structfield>pScrn->gamma</structfield> field must also
3856 be initialised, preferably by calling <function>xf86SetGamma()</function>.
3857 <parameter>maxColors</parameter> is the number of entries in the palette.
3858 <parameter>sigRGBbits</parameter> is the size in bits of each color
3859 component in the DAC's palette. <parameter>loadPalette</parameter>
3860 is a driver-provided function for loading a colormap into the
3861 hardware, and is described below. <parameter>setOverscan</parameter> is
3862 an optional function that may be provided when the overscan color
3863 is an index from the standard LUT and when it needs to be adjusted
3864 to keep it as close to black as possible. The
3865 <parameter>setOverscan</parameter> function programs the overscan index.
3866 It shouldn't normally be used for depths other than 8.
3867 <parameter>setOverscan</parameter> should be set to <constant>NULL</constant>
3868 when it isn't needed. <parameter>flags</parameter> may be set to the
3869 following (which may be ORed together):
3873 <term><constant>CMAP_PALETTED_TRUECOLOR</constant></term>
3875 the TrueColor visual is paletted and is
3876 just a special case of DirectColor.
3877 This flag is only valid for
3878 <code>bpp > 8</code>.
3880 </para></listitem></varlistentry>
3882 <term><constant>CMAP_RELOAD_ON_MODE_SWITCH</constant></term>
3884 reload the colormap automatically
3885 after mode switches. This is useful
3886 for when the driver is resetting the
3887 hardware during mode switches and
3888 corrupting or erasing the hardware
3891 </para></listitem></varlistentry>
3893 <term><constant>CMAP_LOAD_EVEN_IF_OFFSCREEN</constant></term>
3895 reload the colormap even if the screen
3896 is switched out of the server's VC.
3897 The palette is <emphasis>not</emphasis> reloaded when
3898 the screen is switched back in, nor after
3899 mode switches. This is useful when the
3900 driver needs to keep track of palette
3903 </para></listitem></varlistentry>
3908 The colormap layer normally reloads the palette after VT enters so it
3909 is not necessary for the driver to save and restore the palette
3910 when switching VTs. The driver must, however, still save the
3911 initial palette during server start up and restore it during
3915 </blockquote></para></blockquote>
3919 void LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
3920 LOCO *colors, VisualPtr pVisual);
3923 <function>LoadPalette()</function> is a driver-provided function for
3924 loading a colormap into hardware. <parameter>colors</parameter> is the
3925 array of RGB values that represent the full colormap.
3926 <parameter>indices</parameter> is a list of index values into the colors
3927 array. These indices indicate the entries that need to be updated.
3928 <parameter>numColors</parameter> is the number of the indices to be
3932 </blockquote></para></blockquote>
3936 void SetOverscan(ScrnInfoPtr pScrn, int overscan);
3939 <function>SetOverscan()</function> is a driver-provided function for
3940 programming the <parameter>overscan</parameter> index. As described
3941 above, it is normally only appropriate for LUT modes where all
3942 colormap entries are available for the display, but where one of
3943 them is also used for the overscan (typically 8bpp for VGA compatible
3944 LUTs). It isn't required in cases where the overscan area is
3948 </blockquote></para>
3949 </blockquote></para>
3954 <title>DPMS Extension</title>
3957 Support code for the DPMS extension is included in the XFree86 common layer.
3958 This code provides an interface between the main extension code, and a means
3959 for drivers to initialise DPMS when they support it. One function is
3960 available to drivers to do this initialisation, and it is always available,
3961 even when the DPMS extension is not supported by the core server (in
3962 which case it returns a failure result).
3967 Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags);
3970 This function registers a driver's DPMS level programming function
3971 <parameter>set</parameter>. It also checks
3972 <structfield>pScrn->options</structfield> for the "dpms" option, and when
3973 present marks DPMS as being enabled for that screen. The
3974 <parameter>set</parameter> function is called whenever the DPMS level
3975 changes, and is used to program the requested level.
3976 <parameter>flags</parameter> is currently not used, and should be
3977 <constant>0</constant>. If the initialisation fails for any reason,
3978 including when there is no DPMS support in the core server, the
3979 function returns <constant>FALSE</constant>.
3982 </blockquote></para></blockquote>
3986 Drivers that implement DPMS support must provide the following function,
3987 that gets called when the DPMS level is changed:
3992 void ChipDPMSSet(ScrnInfoPtr pScrn, int level, int flags);
3995 Program the DPMS level specified by <parameter>level</parameter>. Valid
3996 values of <parameter>level</parameter> are <constant>DPMSModeOn</constant>,
3997 <constant>DPMSModeStandby</constant>, <constant>DPMSModeSuspend</constant>,
3998 <constant>DPMSModeOff</constant>. These values are defined in
3999 <filename>"extensions/dpms.h"</filename>.
4002 </blockquote></para></blockquote>
4008 <title>DGA Extension</title>
4011 Drivers can support the XFree86 Direct Graphics Architecture (DGA) by
4012 filling out a structure of function pointers and a list of modes and
4013 passing them to DGAInit.
4018 Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs,
4019 DGAModePtr modes, int num);
4021 /** The DGAModeRec **/
4025 DisplayModePtr mode;
4031 int bytesPerScanline;
4035 unsigned long red_mask;
4036 unsigned long green_mask;
4037 unsigned long blue_mask;
4046 unsigned char *address;
4049 } DGAModeRec, *DGAModePtr;
4054 <term><structfield>num</structfield></term>
4056 Can be ignored. The DGA DDX will assign these numbers.
4057 </para></listitem></varlistentry>
4060 <term><structfield>mode</structfield></term>
4062 A pointer to the <structname>DisplayModeRec</structname> for this mode.
4063 </para></listitem></varlistentry>
4066 <term><structfield>flags</structfield></term>
4068 The following flags are defined and may be OR'd together:
4072 <term><constant>DGA_CONCURRENT_ACCESS</constant></term>
4074 Indicates that the driver supports concurrent graphics
4075 accelerator and linear framebuffer access.
4077 </para></listitem></varlistentry>
4080 <term><constant>DGA_FILL_RECT
4082 DGA_BLIT_RECT_TRANS</constant></term>
4084 Indicates that the driver supports the FillRect, BlitRect
4085 or BlitTransRect functions in this mode.
4087 </para></listitem></varlistentry>
4090 <term><constant>DGA_PIXMAP_AVAILABLE</constant></term>
4092 Indicates that Xlib may be used on the framebuffer.
4093 This flag will usually be set unless the driver wishes
4094 to prohibit this for some reason.
4096 </para></listitem></varlistentry>
4099 <term><constant>DGA_INTERLACED
4100 DGA_DOUBLESCAN</constant></term>
4102 Indicates that these are interlaced or double scan modes.
4104 </para></listitem></varlistentry>
4106 </para></listitem></varlistentry>
4109 <term><structfield>imageWidth
4110 imageHeight</structfield></term>
4112 These are the dimensions of the linear framebuffer
4113 accessible by the client.
4115 </para></listitem></varlistentry>
4118 <term><structfield>pixmapWidth
4119 pixmapHeight</structfield></term>
4121 These are the dimensions of the area of the
4122 framebuffer accessible by the graphics accelerator.
4124 </para></listitem></varlistentry>
4127 <term><structfield>bytesPerScanline</structfield></term>
4129 Pitch of the framebuffer in bytes.
4131 </para></listitem></varlistentry>
4134 <term><structfield>byteOrder</structfield></term>
4137 <structfield>pScrn->imageByteOrder</structfield>.
4139 </para></listitem></varlistentry>
4142 <term><structfield>depth</structfield></term>
4144 The depth of the framebuffer in this mode.
4146 </para></listitem></varlistentry>
4149 <term><structfield>bitsPerPixel</structfield></term>
4151 The number of bits per pixel in this mode.
4153 </para></listitem></varlistentry>
4156 <term><structfield>red_mask</structfield></term>
4157 <term><structfield>green_mask</structfield></term>
4158 <term><structfield>blue_mask</structfield></term>
4160 The RGB masks for this mode, if applicable.
4162 </para></listitem></varlistentry>
4165 <term><structfield>viewportWidth</structfield></term>
4166 <term><structfield>viewportHeight</structfield></term>
4168 Dimensions of the visible part of the framebuffer.
4169 Usually <structfield>mode->HDisplay</structfield> and
4170 <structfield>mode->VDisplay</structfield>.
4172 </para></listitem></varlistentry>
4175 <term><structfield>xViewportStep
4176 yViewportStep</structfield></term>
4178 The granularity of x and y viewport positions that
4179 the driver supports in this mode.
4181 </para></listitem></varlistentry>
4184 <term><structfield>maxViewportX
4185 maxViewportY</structfield></term>
4187 The maximum viewport position supported by the
4188 driver in this mode.
4189 </para></listitem></varlistentry>
4192 <term><structfield>viewportFlags</structfield></term>
4194 The following may be OR'd together:
4198 <term><constant>DGA_FLIP_IMMEDIATE</constant></term>
4200 The driver supports immediate viewport changes.
4201 </para></listitem></varlistentry>
4204 <term><constant>DGA_FLIP_RETRACE</constant></term>
4207 The driver supports viewport changes at retrace.
4208 </para></listitem></varlistentry>
4210 </para></listitem></varlistentry>
4213 <term><structfield>offset</structfield></term>
4215 The offset into the linear framebuffer that corresponds to
4216 pixel (0,0) for this mode.
4217 </para></listitem></varlistentry>
4220 <term><structfield>address</structfield></term>
4222 The virtual address of the framebuffer as mapped by the driver.
4223 This is needed when DGA_PIXMAP_AVAILABLE is set.
4224 </para></listitem></varlistentry>
4229 /** The DGAFunctionRec **/
4232 Bool (*OpenFramebuffer)(
4235 unsigned char **mem,
4240 void (*CloseFramebuffer)(ScrnInfoPtr pScrn);
4241 Bool (*SetMode)(ScrnInfoPtr pScrn, DGAModePtr pMode);
4242 void (*SetViewport)(ScrnInfoPtr pScrn, int x, int y, int flags);
4243 int (*GetViewport)(ScrnInfoPtr pScrn);
4244 void (*Sync)(ScrnInfoPtr);
4247 int x, int y, int w, int h,
4256 void (*BlitTransRect)(
4263 } DGAFunctionRec, *DGAFunctionPtr;
4269 Bool OpenFramebuffer (pScrn, name, mem, size, offset, extra);
4272 <function>OpenFramebuffer()</function> should pass the client everything
4273 it needs to know to be able to open the framebuffer. These
4274 parameters are OS specific and their meanings are to be interpreted
4275 by an OS specific client library.
4279 <term><parameter>name</parameter></term>
4281 The name of the device to open or <constant>NULL</constant> if
4282 there is no special device to open. A <constant>NULL</constant>
4283 name tells the client that it should open whatever device
4284 one would usually open to access physical memory.
4285 </para></listitem></varlistentry>
4288 <term><parameter>mem</parameter></term>
4290 The physical address of the start of the framebuffer.
4291 </para></listitem></varlistentry>
4294 <term><parameter>size</parameter></term>
4296 The size of the framebuffer in bytes.
4297 </para></listitem></varlistentry>
4300 <term><parameter>offset</parameter></term>
4302 Any offset into the device, if applicable.
4303 </para></listitem></varlistentry>
4306 <term><parameter>flags</parameter></term>
4308 Any additional information that the client may need.
4309 Currently, only the <constant>DGA_NEED_ROOT</constant> flag is
4311 </para></listitem></varlistentry>
4314 </para></blockquote>
4315 </para></blockquote>
4319 void CloseFramebuffer (pScrn);
4322 <function>CloseFramebuffer()</function> merely informs the driver (if it
4323 even cares) that client no longer needs to access the framebuffer
4324 directly. This function is optional.
4327 </blockquote></para></blockquote>
4331 Bool SetMode (pScrn, pMode);
4334 <function>SetMode()</function> tells the driver to initialize the mode
4335 passed to it. If <parameter>pMode</parameter> is <constant>NULL</constant>,
4336 then the driver should restore the original pre-DGA mode.
4339 </blockquote></para></blockquote>
4343 void SetViewport (pScrn, x, y, flags);
4346 <function>SetViewport()</function> tells the driver to make the upper
4347 left-hand corner of the visible screen correspond to coordinate
4348 <literal remap="tt">(x,y)</literal> on the framebuffer. <parameter>flags</parameter>
4349 currently defined are:
4353 <term><constant>DGA_FLIP_IMMEDIATE</constant></term>
4355 The viewport change should occur immediately.
4356 </para></listitem></varlistentry>
4359 <term><constant>DGA_FLIP_RETRACE</constant></term>
4361 The viewport change should occur at the
4362 vertical retrace, but this function should
4363 return sooner if possible.
4364 </para></listitem></varlistentry>
4369 The <literal remap="tt">(x,y)</literal> locations will be passed as the client
4370 specified them, however, the driver is expected to round these
4371 locations down to the next supported location as specified by the
4372 <structfield>xViewportStep</structfield> and <structfield>yViewportStep</structfield>
4373 for the current mode.
4375 </blockquote></para></blockquote>
4379 int GetViewport (pScrn);
4382 <function>GetViewport()</function> gets the current page flip status.
4383 Set bits in the returned int correspond to viewport change requests
4384 still pending. For instance, set bit zero if the last SetViewport
4385 request is still pending, bit one if the one before that is still
4389 </blockquote></para></blockquote>
4396 This function should ensure that any graphics accelerator operations
4397 have finished. This function should not return until the graphics
4398 accelerator is idle.
4401 </blockquote></para></blockquote>
4405 void FillRect (pScrn, x, y, w, h, color);
4408 This optional function should fill a rectangle
4409 <parameter>w × h</parameter> located at
4410 <parameter>(x,y)</parameter> in the given color.
4413 </blockquote></para></blockquote>
4417 void BlitRect (pScrn, srcx, srcy, w, h, dstx, dsty);
4420 This optional function should copy an area
4421 <parameter>w × h</parameter> located at
4422 <parameter>(srcx,srcy)</parameter> to location <parameter>(dstx,dsty)</parameter>.
4423 This function will need to handle copy directions as appropriate.
4426 </blockquote></para></blockquote>
4430 void BlitTransRect (pScrn, srcx, srcy, w, h, dstx, dsty, color);
4433 This optional function is the same as BlitRect except that pixels
4434 in the source corresponding to the color key <parameter>color</parameter>
4438 </blockquote></para></blockquote>
4439 </para></blockquote>
4444 <title>The XFree86 X Video Extension (Xv) Device Dependent Layer</title>
4447 XFree86 offers the X Video Extension which allows clients to treat video
4448 as any another primitive and <quote>Put</quote> video into drawables. By default,
4449 the extension reports no video adaptors as being available since the
4450 DDX layer has not been initialized. The driver can initialize the DDX
4451 layer by filling out one or more <literal remap="tt">XF86VideoAdaptorRecs</literal>
4452 as described later in this document and passing a list of
4453 <literal remap="tt">XF86VideoAdaptorPtr</literal> pointers to the following function:
4456 Bool xf86XVScreenInit(ScreenPtr pScreen,
4457 XF86VideoAdaptorPtr *adaptPtrs,
4463 After doing this, the extension will report video adaptors as being
4464 available, providing the data in their respective
4465 <literal remap="tt">XF86VideoAdaptorRecs</literal> was valid.
4466 <function>xf86XVScreenInit()</function> <emphasis>copies</emphasis> data from the structure
4467 passed to it so the driver may free it after the initialization. At
4468 the moment, the DDX only supports rendering into Window drawables.
4469 Pixmap rendering will be supported after a sufficient survey of suitable
4470 hardware is completed.
4474 The <structname>XF86VideoAdaptorRec</structname>:
4482 XF86VideoEncodingPtr pEncodings;
4484 XF86VideoFormatPtr pFormats;
4486 DevUnion *pPortPrivates;
4488 XF86AttributePtr pAttributes;
4490 XF86ImagePtr pImages;
4491 PutVideoFuncPtr PutVideo;
4492 PutStillFuncPtr PutStill;
4493 GetVideoFuncPtr GetVideo;
4494 GetStillFuncPtr GetStill;
4495 StopVideoFuncPtr StopVideo;
4496 SetPortAttributeFuncPtr SetPortAttribute;
4497 GetPortAttributeFuncPtr GetPortAttribute;
4498 QueryBestSizeFuncPtr QueryBestSize;
4499 PutImageFuncPtr PutImage;
4500 QueryImageAttributesFuncPtr QueryImageAttributes;
4501 } XF86VideoAdaptorRec, *XF86VideoAdaptorPtr;
4502 </programlisting></para>
4505 Each adaptor will have its own XF86VideoAdaptorRec. The fields are
4510 <term><structfield>type</structfield></term>
4512 This can be any of the following flags OR'd together.
4516 <term><constant>XvInputMask</constant>
4517 <constant>XvOutputMask</constant></term>
4519 These refer to the target drawable and are similar to a Window's
4520 class. <literal remap="tt">XvInputMask</literal> indicates that the adaptor
4521 can put video into a drawable. <literal remap="tt">XvOutputMask</literal>
4522 indicates that the adaptor can get video from a drawable.
4523 </para></listitem></varlistentry>
4526 <term><constant>XvVideoMask</constant>
4527 <constant>XvStillMask</constant>
4528 <constant>XvImageMask</constant></term>
4530 These indicate that the adaptor supports video, still or
4531 image primitives respectively.
4532 </para></listitem></varlistentry>
4535 <term><constant>XvWindowMask</constant>
4536 <constant>XvPixmapMask</constant></term>
4538 These indicate the types of drawables the adaptor is capable
4539 of rendering into. At the moment, Pixmap rendering is not
4540 supported and the <constant>XvPixmapMask</constant> flag is ignored.
4541 </para></listitem></varlistentry>
4544 </para></listitem></varlistentry>
4547 <term><structfield>flags</structfield></term>
4549 Currently, the following flags are defined:
4553 <term><constant>VIDEO_NO_CLIPPING</constant></term>
4555 This indicates that the video adaptor does not support
4556 clipping. The driver will never receive <quote>Put</quote> requests
4557 where less than the entire area determined by
4558 <parameter>drw_x</parameter>, <parameter>drw_y</parameter>,
4559 <parameter>drw_w</parameter> and <parameter>drw_h</parameter> is visible.
4560 This flag does not apply to <quote>Get</quote> requests. Hardware
4561 that is incapable of clipping <quote>Gets</quote> may punt or get
4562 the extents of the clipping region passed to it.
4568 <term><constant>VIDEO_INVERT_CLIPLIST</constant></term>
4570 This indicates that the video driver requires the clip
4571 list to contain the regions which are obscured rather
4572 than the regions which are are visible.
4578 <term><constant>VIDEO_OVERLAID_STILLS</constant></term>
4580 Implementing PutStill for hardware that does video as an
4581 overlay can be awkward since it's unclear how long to leave
4582 the video up for. When this flag is set, StopVideo will be
4583 called whenever the destination gets clipped or moved so that
4584 the still can be left up until then.
4590 <term><constant>VIDEO_OVERLAID_IMAGES</constant></term>
4592 Same as <constant>VIDEO_OVERLAID_STILLS</constant> but for images.
4597 <term><constant>VIDEO_CLIP_TO_VIEWPORT</constant></term>
4599 Indicates that the clip region passed to the driver functions
4600 should be clipped to the visible portion of the screen in the
4601 case where the viewport is smaller than the virtual desktop.
4602 </para></listitem></varlistentry>
4605 </para></listitem></varlistentry>
4608 <term><structfield>name</structfield></term>
4610 The name of the adaptor.
4611 </para></listitem></varlistentry>
4615 <term><structfield>nEncodings</structfield>
4616 <structfield>pEncodings</structfield></term>
4618 The number of encodings the adaptor is capable of and pointer
4619 to the <structname>XF86VideoEncodingRec</structname> array. The
4620 <structname>XF86VideoEncodingRec</structname> is described later on.
4621 For drivers that only support XvImages there should be an encoding
4622 named "XV_IMAGE" and the width and height should specify
4623 the maximum size source image supported.
4624 </para></listitem></varlistentry>
4628 <term><structfield>nFormats</structfield>
4629 <structfield>pFormats</structfield></term>
4631 The number of formats the adaptor is capable of and pointer to
4632 the <structname>XF86VideoFormatRec</structname> array. The
4633 <structname>XF86VideoFormatRec</structname> is described later on.
4634 </para></listitem></varlistentry>
4638 <term><structfield>nPorts</structfield>
4639 <structfield>pPortPrivates</structfield></term>
4641 The number of ports is the number of separate data streams which
4642 the adaptor can handle simultaneously. If you have more than
4643 one port, the adaptor is expected to be able to render into more
4644 than one window at a time. <structfield>pPortPrivates</structfield> is
4645 an array of pointers or ints - one for each port. A port's
4646 private data will be passed to the driver any time the port is
4647 requested to do something like put the video or stop the video.
4648 In the case where there may be many ports, this enables the
4649 driver to know which port the request is intended for. Most
4650 commonly, this will contain a pointer to the data structure
4651 containing information about the port. In Xv, all ports on
4652 a particular adaptor are expected to be identical in their
4654 </para></listitem></varlistentry>
4658 <term><structfield>nAttributes</structfield>
4659 <structfield>pAttributes</structfield></term>
4661 The number of attributes recognized by the adaptor and a pointer to
4662 the array of <structname>XF86AttributeRecs</structname>. The
4663 <structname>XF86AttributeRec</structname> is described later on.
4664 </para></listitem></varlistentry>
4668 <term><structfield>nImages</structfield>
4669 <structfield>pImages</structfield></term>
4671 The number of <structname>XF86ImageRecs</structname> supported by the adaptor
4672 and a pointer to the array of <structname>XF86ImageRecs</structname>. The
4673 <structname>XF86ImageRec</structname> is described later on.
4674 </para></listitem></varlistentry>
4679 PutVideo PutStill GetVideo GetStill StopVideo
4680 SetPortAttribute GetPortAttribute QueryBestSize PutImage
4681 QueryImageAttributes
4682 </structfield></term>
4684 These functions define the DDX->driver interface. In each
4685 case, the pointer <parameter>data</parameter> is passed to the driver.
4686 This is the port private for that port as described above. All
4687 fields are required except under the following conditions:
4691 <structfield>PutVideo</structfield>, <structfield>PutStill</structfield> and
4692 the image routines <structfield>PutImage</structfield> and
4693 <structfield>QueryImageAttributes</structfield> are not required when the
4694 adaptor type does not contain <constant>XvInputMask</constant>.
4698 <structfield>GetVideo</structfield> and <structfield>GetStill</structfield>
4699 are not required when the adaptor type does not contain
4700 <constant>XvOutputMask</constant>.
4704 <structfield>GetVideo</structfield> and <structfield>PutVideo</structfield>
4705 are not required when the adaptor type does not contain
4706 <constant>XvVideoMask</constant>.
4710 <structfield>GetStill</structfield> and <structfield>PutStill</structfield>
4711 are not required when the adaptor type does not contain
4712 <constant>XvStillMask</constant>.
4716 <structfield>PutImage</structfield> and <structfield>QueryImageAttributes</structfield>
4717 are not required when the adaptor type does not contain
4718 <constant>XvImageMask</constant>.
4726 With the exception of <structfield>QueryImageAttributes</structfield>, these
4727 functions should return <constant>Success</constant> if the operation was
4728 completed successfully. They can return <constant>XvBadAlloc</constant>
4729 otherwise. <structfield>QueryImageAttributes</structfield> returns the size
4730 of the XvImage queried.
4734 If the <constant>VIDEO_NO_CLIPPING</constant>
4735 flag is set, the <literal remap="tt">clipBoxes</literal> may be ignored by
4736 the driver. <literal remap="tt">ClipBoxes</literal> is an <literal remap="tt">X-Y</literal>
4737 banded region identical to those used throughout the server.
4738 The clipBoxes represent the visible portions of the area determined
4739 by <literal remap="tt">drw_x</literal>, <literal remap="tt">drw_y</literal>,
4740 <literal remap="tt">drw_w</literal> and <literal remap="tt">drw_h</literal> in the Get/Put
4741 function. The boxes are in screen coordinates, are guaranteed
4742 not to overlap and an empty region will never be passed.
4743 If the driver has specified <constant>VIDEO_INVERT_CLIPLIST</constant>,
4744 <literal remap="tt">clipBoxes</literal> will indicate the areas of the primitive
4745 which are obscured rather than the areas visible.
4747 </para></listitem></varlistentry>
4752 typedef int (* PutVideoFuncPtr)( ScrnInfoPtr pScrn,
4753 short vid_x, short vid_y, short drw_x, short drw_y,
4754 short vid_w, short vid_h, short drw_w, short drw_h,
4755 RegionPtr clipBoxes, pointer data );
4758 This indicates that the driver should take a subsection
4759 <parameter>vid_w</parameter> by <parameter>vid_h</parameter> at location
4760 <parameter>(vid_x,vid_y)</parameter> from the video stream and direct
4761 it into the rectangle <parameter>drw_w</parameter> by <parameter>drw_h</parameter>
4762 at location <parameter>(drw_x,drw_y)</parameter> on the screen, scaling as
4763 necessary. Due to the large variations in capabilities of
4764 the various hardware expected to be used with this extension,
4765 it is not expected that all hardware will be able to do this
4766 exactly as described. In that case the driver should just do
4767 <quote>the best it can,</quote> scaling as closely to the target rectangle
4768 as it can without rendering outside of it. In the worst case,
4769 the driver can opt to just not turn on the video.
4772 </blockquote></para></blockquote>
4776 typedef int (* PutStillFuncPtr)( ScrnInfoPtr pScrn,
4777 short vid_x, short vid_y, short drw_x, short drw_y,
4778 short vid_w, short vid_h, short drw_w, short drw_h,
4779 RegionPtr clipBoxes, pointer data );
4782 This is same as <structfield>PutVideo</structfield> except that the driver
4783 should place only one frame from the stream on the screen.
4786 </blockquote></para></blockquote>
4790 typedef int (* GetVideoFuncPtr)( ScrnInfoPtr pScrn,
4791 short vid_x, short vid_y, short drw_x, short drw_y,
4792 short vid_w, short vid_h, short drw_w, short drw_h,
4793 RegionPtr clipBoxes, pointer data );
4796 This is same as <structfield>PutVideo</structfield> except that the driver
4797 gets video from the screen and outputs it. The driver should
4798 do the best it can to get the requested dimensions correct
4799 without reading from an area larger than requested.
4802 </blockquote></para></blockquote>
4806 typedef int (* GetStillFuncPtr)( ScrnInfoPtr pScrn,
4807 short vid_x, short vid_y, short drw_x, short drw_y,
4808 short vid_w, short vid_h, short drw_w, short drw_h,
4809 RegionPtr clipBoxes, pointer data );
4812 This is the same as <literal remap="tt">GetVideo</literal> except that the
4813 driver should place only one frame from the screen into the
4817 </blockquote></para></blockquote>
4821 typedef void (* StopVideoFuncPtr)(ScrnInfoPtr pScrn,
4822 pointer data, Bool cleanup);
4825 This indicates the driver should stop displaying the video.
4826 This is used to stop both input and output video. The
4827 <parameter>cleanup</parameter> field indicates that the video is
4828 being stopped because the client requested it to stop or
4829 because the server is exiting the current VT. In that case
4830 the driver should deallocate any offscreen memory areas (if
4831 there are any) being used to put the video to the screen. If
4832 <parameter>cleanup</parameter> is not set, the video is being stopped
4833 temporarily due to clipping or moving of the window, etc...
4834 and video will likely be restarted soon so the driver should
4835 not deallocate any offscreen areas associated with that port.
4838 </blockquote></para></blockquote>
4841 typedef int (* SetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
4842 Atom attribute,INT32 value, pointer data);
4846 typedef int (* GetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
4847 Atom attribute,INT32 *value, pointer data);
4850 A port may have particular attributes such as hue,
4851 saturation, brightness or contrast. Xv clients set and
4852 get these attribute values by sending attribute strings
4853 (Atoms) to the server. Such requests end up at these
4854 driver functions. It is recommended that the driver provide
4855 at least the following attributes mentioned in the Xv client
4857 <literallayout><constant>
4863 </constant></literallayout>
4864 but the driver may recognize as many atoms as it wishes. If
4865 a requested attribute is unknown by the driver it should return
4866 <constant>BadMatch</constant>. <constant>XV_ENCODING</constant> is the
4867 attribute intended to let the client specify which video
4868 encoding the particular port should be using (see the description
4869 of <structname>XF86VideoEncodingRec</structname> below). If the
4870 requested encoding is unsupported, the driver should return
4871 <constant>XvBadEncoding</constant>. If the value lies outside the
4872 advertised range <constant>BadValue</constant> may be returned.
4873 <constant>Success</constant> should be returned otherwise.
4876 </blockquote></para></blockquote>
4880 typedef void (* QueryBestSizeFuncPtr)(ScrnInfoPtr pScrn,
4881 Bool motion, short vid_w, short vid_h,
4882 short drw_w, short drw_h,
4883 unsigned int *p_w, unsigned int *p_h, pointer data);
4886 <function>QueryBestSize</function> provides the client with a way
4887 to query what the destination dimensions would end up being
4888 if they were to request that an area
4889 <parameter>vid_w</parameter> by <parameter>vid_h</parameter> from the video
4890 stream be scaled to rectangle of
4891 <parameter>drw_w</parameter> by <parameter>drw_h</parameter> on the screen.
4892 Since it is not expected that all hardware will be able to
4893 get the target dimensions exactly, it is important that the
4894 driver provide this function.
4897 </blockquote></para></blockquote>
4901 typedef int (* PutImageFuncPtr)( ScrnInfoPtr pScrn,
4902 short src_x, short src_y, short drw_x, short drw_y,
4903 short src_w, short src_h, short drw_w, short drw_h,
4904 int image, char *buf, short width, short height,
4905 Bool sync, RegionPtr clipBoxes, pointer data );
4908 This is similar to <structfield>PutStill</structfield> except that the
4909 source of the video is not a port but the data stored in a system
4910 memory buffer at <parameter>buf</parameter>. The data is in the format
4911 indicated by the <parameter>image</parameter> descriptor and represents a
4912 source of size <parameter>width</parameter> by <parameter>height</parameter>.
4913 If <parameter>sync</parameter> is TRUE the driver should not return
4914 from this function until it is through reading the data
4915 from <parameter>buf</parameter>. Returning when <parameter>sync</parameter>
4916 is TRUE indicates that it is safe for the data at <parameter>buf</parameter>
4917 to be replaced, freed, or modified.
4920 </blockquote></para></blockquote>
4924 typedef int (* QueryImageAttributesFuncPtr)( ScrnInfoPtr pScrn,
4925 int image, short *width, short *height,
4926 int *pitches, int *offsets);
4929 This function is called to let the driver specify how data for
4930 a particular <parameter>image</parameter> of size <parameter>width</parameter>
4931 by <parameter>height</parameter> should be stored. Sometimes only
4932 the size and corrected width and height are needed. In that
4933 case <parameter>pitches</parameter> and <parameter>offsets</parameter> are
4934 NULL. The size of the memory required for the image is returned
4935 by this function. The <parameter>width</parameter> and
4936 <parameter>height</parameter> of the requested image can be altered by
4937 the driver to reflect format limitations (such as component
4938 sampling periods that are larger than one). If
4939 <parameter>pitches</parameter> and <parameter>offsets</parameter> are not NULL,
4940 these will be arrays with as many elements in them as there
4941 are planes in the <parameter>image</parameter> format. The driver
4942 should specify the pitch (in bytes) of each scanline in the
4943 particular plane as well as the offset to that plane (in bytes)
4944 from the beginning of the image.
4947 </blockquote></para></blockquote>
4951 The XF86VideoEncodingRec:
4958 unsigned short width, height;
4960 } XF86VideoEncodingRec, *XF86VideoEncodingPtr;
4964 The <structname>XF86VideoEncodingRec</structname> specifies what encodings
4965 the adaptor can support. Most of this data is just informational
4966 and for the client's benefit, and is what will be reported by
4967 <function>XvQueryEncodings</function>. The <parameter>id</parameter> field is
4968 expected to be a unique identifier to allow the client to request a
4969 certain encoding via the <constant>XV_ENCODING</constant> attribute string.
4972 </blockquote></para></blockquote>
4976 The XF86VideoFormatRec:
4983 } XF86VideoFormatRec, *XF86VideoFormatPtr;
4987 This specifies what visuals the video is viewable in.
4988 <parameter>depth</parameter> is the depth of the visual (not bpp).
4989 <parameter>class</parameter> is the visual class such as
4990 <constant>TrueColor</constant>, <constant>DirectColor</constant> or
4991 <constant>PseudoColor</constant>. Initialization of an adaptor will fail
4992 if none of the visuals on that screen are supported.
4995 </blockquote></para></blockquote>
4999 The XF86AttributeRec:
5008 } XF86AttributeListRec, *XF86AttributeListPtr;
5012 Each adaptor may have an array of these advertising the attributes
5013 for its ports. Currently defined flags are <literal remap="tt">XvGettable</literal>
5014 and <literal remap="tt">XvSettable</literal> which may be OR'd together indicating that
5015 attribute is <quote>gettable</quote> or <quote>settable</quote> by the client. The
5016 <literal remap="tt">min</literal> and <literal remap="tt">max</literal> field specify the valid range
5017 for the value. <literal remap="tt">Name</literal> is a text string describing the
5021 </blockquote></para></blockquote>
5039 /* for RGB formats */
5041 unsigned int red_mask;
5042 unsigned int green_mask;
5043 unsigned int blue_mask;
5045 /* for YUV formats */
5046 unsigned int y_sample_bits;
5047 unsigned int u_sample_bits;
5048 unsigned int v_sample_bits;
5049 unsigned int horz_y_period;
5050 unsigned int horz_u_period;
5051 unsigned int horz_v_period;
5052 unsigned int vert_y_period;
5053 unsigned int vert_u_period;
5054 unsigned int vert_v_period;
5055 char component_order[32];
5057 } XF86ImageRec, *XF86ImagePtr;
5061 XF86ImageRec describes how video source data is laid out in memory.
5062 The fields are as follows:
5066 <term><structfield>id</structfield></term>
5068 This is a unique descriptor for the format. It is often good to
5069 set this value to the FOURCC for the format when applicable.
5070 </para></listitem></varlistentry>
5073 <term><structfield>type</structfield></term>
5075 This is <constant>XvRGB</constant> or <constant>XvYUV</constant>.
5076 </para></listitem></varlistentry>
5079 <term><structfield>byte_order</structfield></term>
5081 This is <constant>LSBFirst</constant> or <constant>MSBFirst</constant>.
5082 </para></listitem></varlistentry>
5085 <term><structfield>guid</structfield></term>
5087 This is the Globally Unique IDentifier for the format. When
5088 not applicable, all characters should be NULL.
5089 </para></listitem></varlistentry>
5092 <term><structfield>bits_per_pixel</structfield></term>
5094 The number of bits taken up (but not necessarily used) by each
5095 pixel. Note that for some planar formats which have fractional
5096 bits per pixel (such as IF09) this number may be rounded _down_.
5097 </para></listitem></varlistentry>
5100 <term><structfield>format</structfield></term>
5102 This is <constant>XvPlanar</constant> or <constant>XvPacked</constant>.
5103 </para></listitem></varlistentry>
5106 <term><structfield>num_planes</structfield></term>
5108 The number of planes in planar formats. This should be set to
5109 one for packed formats.
5110 </para></listitem></varlistentry>
5113 <term><structfield>depth</structfield></term>
5115 The significant bits per pixel in RGB formats (analgous to the
5116 depth of a pixmap format).
5117 </para></listitem></varlistentry>
5120 <term><structfield>red_mask</structfield></term>
5121 <term><structfield>green_mask</structfield></term>
5122 <term><structfield>blue_mask</structfield></term>
5124 The red, green and blue bitmasks for packed RGB formats.
5125 </para></listitem></varlistentry>
5128 <term><structfield>y_sample_bits</structfield></term>
5129 <term><structfield>u_sample_bits</structfield></term>
5130 <term><structfield>v_sample_bits</structfield></term>
5132 The y, u and v sample sizes (in bits).
5133 </para></listitem></varlistentry>
5136 <term><structfield>horz_y_period</structfield></term>
5137 <term><structfield>horz_u_period</structfield></term>
5138 <term><structfield>horz_v_period</structfield></term>
5140 The y, u and v sampling periods in the horizontal direction.
5141 </para></listitem></varlistentry>
5144 <term><structfield>vert_y_period</structfield></term>
5145 <term><structfield>vert_u_period</structfield></term>
5146 <term><structfield>vert_v_period</structfield></term>
5148 The y, u and v sampling periods in the vertical direction.
5149 </para></listitem></varlistentry>
5152 <term><structfield>component_order</structfield></term>
5154 Uppercase ascii characters representing the order that
5155 samples are stored within packed formats. For planar formats
5156 this represents the ordering of the planes. Unused characters
5157 in the 32 byte string should be set to NULL.
5158 </para></listitem></varlistentry>
5161 <term><structfield>scanline_order</structfield></term>
5163 This is <constant>XvTopToBottom</constant> or <constant>XvBottomToTop</constant>.
5164 </para></listitem></varlistentry>
5170 Since some formats (particular some planar YUV formats) may not
5171 be completely defined by the parameters above, the guid, when
5172 available, should provide the most accurate description of the
5176 </blockquote></para></blockquote>
5181 <title>The Loader</title>
5184 This section describes the interfaces to the module loader. The loader
5185 interfaces can be divided into two groups: those that are only available to
5186 the XFree86 common layer, and those that are also available to modules.
5190 <title>Loader Overview</title>
5193 The loader is capable of loading modules in a range of object formats,
5194 and knowledge of these formats is built in to the loader. Knowledge of
5195 new object formats can be added to the loader in a straightforward
5196 manner. This makes it possible to provide OS-independent modules (for
5197 a given CPU architecture type). In addition to this, the loader can
5198 load modules via the OS-provided <function>dlopen(3)</function> service where
5199 available. Such modules are not platform independent, and the semantics
5200 of <function>dlopen()</function> on most systems results in significant
5201 limitations in the use of modules of this type. Support for
5202 <function>dlopen()</function> modules in the loader is primarily for
5203 experimental and development purposes.
5207 Symbols exported by the loader (on behalf of the core X server) to
5208 modules are determined at compile time. Only those symbols explicitly
5209 exported are available to modules. All external symbols of loaded
5210 modules are exported to other modules, and to the core X server. The
5211 loader can be requested to check for unresolved symbols at any time,
5212 and the action to be taken for unresolved symbols can be controlled by
5213 the caller of the loader. Typically the caller identifies which symbols
5214 can safely remain unresolved and which cannot.
5218 NOTE: Now that ISO-C allows pointers to functions and pointers to data to
5219 have different internal representations, some of the following interfaces
5220 will need to be revisited.
5225 <title>Semi-private Loader Interface</title>
5228 The following is the semi-private loader interface that is available to the
5229 XFree86 common layer.
5234 void LoaderInit(void);
5237 The <function>LoaderInit()</function> function initialises the loader,
5238 and it must be called once before calling any other loader functions.
5239 This function initialises the tables of exported symbols, and anything
5240 else that might need to be initialised.
5243 </blockquote></para></blockquote>
5247 void LoaderSetPath(const char *path);
5250 The <function>LoaderSetPath()</function> function initialises a default
5251 module search path. This must be called if calls to other functions
5252 are to be made without explicitly specifying a module search path.
5253 The search path <parameter>path</parameter> must be a string of one or more
5254 comma separated absolute paths. Modules are expected to be located
5255 below these paths, possibly in subdirectories of these paths.
5258 </blockquote></para></blockquote>
5262 pointer LoadModule(const char *module, const char *path,
5263 const char **subdirlist, const char **patternlist,
5264 pointer options, const XF86ModReqInfo * modreq,
5265 int *errmaj, int *errmin);
5268 The <function>LoadModule()</function> function loads the module called
5269 <parameter>module</parameter>. The return value is a module handle, and
5270 may be used in future calls to the loader that require a reference
5271 to a loaded module. The module name <parameter>module</parameter> is
5272 normally the module's canonical name, which doesn't contain any
5273 directory path information, or any object/library file prefixes of
5274 suffixes. Currently a full pathname and/or filename is also accepted.
5275 This might change. The other parameters are:
5279 <term><parameter>path</parameter></term>
5281 An optional comma-separated list of module search paths.
5282 When <constant>NULL</constant>, the default search path is used.
5283 </para></listitem></varlistentry>
5287 <term><parameter>subdirlist</parameter></term>
5289 An optional <constant>NULL</constant> terminated list of
5290 subdirectories to search. When <constant>NULL</constant>,
5291 the default built-in list is used (refer to
5292 <varname>stdSubdirs</varname> in <filename>loadmod.c</filename>).
5293 The default list is also substituted for entries in
5294 <parameter>subdirlist</parameter> with the value
5295 <constant>DEFAULT_LIST</constant>. This makes is possible
5296 to augment the default list instead of replacing it.
5297 Subdir elements must be relative, and must not contain
5298 <literal remap="tt">".."</literal>. If any violate this requirement,
5300 </para></listitem></varlistentry>
5304 <term><parameter>patternlist</parameter></term>
5306 An optional <constant>NULL</constant> terminated list of
5307 POSIX regular expressions used to connect module
5308 filenames with canonical module names. Each regex
5309 should contain exactly one subexpression that corresponds
5310 to the canonical module name. When <constant>NULL</constant>,
5311 the default built-in list is used (refer to
5312 <varname>stdPatterns</varname> in
5313 <filename>loadmod.c</filename>). The default list is also
5314 substituted for entries in <parameter>patternlist</parameter>
5315 with the value <constant>DEFAULT_LIST</constant>. This
5316 makes it possible to augment the default list instead
5318 </para></listitem></varlistentry>
5322 <term><parameter>options</parameter></term>
5324 An optional parameter that is passed to the newly
5325 loaded module's <literal remap="tt">SetupProc</literal> function
5326 (if it has one). This argument is normally a
5327 <constant>NULL</constant> terminated list of
5328 <structname>Options</structname>, and must be interpreted that
5329 way by modules loaded directly by the XFree86 common
5330 layer. However, it may be used for application-specific
5331 parameter passing in other situations.
5332 </para></listitem></varlistentry>
5336 <term><parameter>modreq</parameter></term>
5338 An optional <structname>XF86ModReqInfo*</structname> containing
5339 version/ABI/vendor information to requirements to
5340 check the newly loaded module against. The main
5341 purpose of this is to allow the loader to verify that
5342 a module of the correct type/version before running
5343 its <function>SetupProc</function> function.
5347 The <literal remap="tt">XF86ModReqInfo</literal> struct is defined
5351 CARD8 majorversion; /* MAJOR_UNSPEC */
5352 CARD8 minorversion; /* MINOR_UNSPEC */
5353 CARD16 patchlevel; /* PATCH_UNSPEC */
5354 const char * abiclass; /* ABI_CLASS_NONE */
5355 CARD32 abiversion; /* ABI_VERS_UNSPEC */
5356 const char * moduleclass; /* MOD_CLASS_NONE */
5360 The information here is compared against the equivalent
5361 information in the module's
5362 <structname>XF86ModuleVersionInfo</structname> record (which
5363 is described below). The values in comments above
5364 indicate <quote>don't care</quote> settings for each of the fields.
5365 The comparisons made are as follows:
5369 <term><structfield>majorversion</structfield></term>
5371 Must match the module's majorversion
5373 </para></listitem></varlistentry>
5376 <term><structfield>minorversion</structfield></term>
5378 The module's minor version must be
5379 no less than this value. This
5380 comparison is only made if
5381 <structfield>majorversion</structfield> is
5382 specified and matches.
5383 </para></listitem></varlistentry>
5386 <term><structfield>patchlevel</structfield></term>
5388 The module's patchlevel must be no
5389 less than this value. This comparison
5391 <structfield>minorversion</structfield> is
5392 specified and matches.
5393 </para></listitem></varlistentry>
5396 <term><structfield>abiclass</structfield></term>
5398 String must match the module's abiclass
5400 </para></listitem></varlistentry>
5403 <term><structfield>abiversion</structfield></term>
5405 Must be consistent with the module's
5406 abiversion (major equal, minor no
5408 </para></listitem></varlistentry>
5411 <term><structfield>moduleclass</structfield></term>
5413 String must match the module's
5415 </para></listitem></varlistentry>
5418 </para></listitem></varlistentry>
5421 <term><parameter>errmaj</parameter></term>
5423 An optional pointer to a variable holding the major
5424 part or the error code. When provided,
5425 <parameter>*errmaj</parameter> is filled in when
5426 <function>LoadModule()</function> fails.
5427 </para></listitem></varlistentry>
5430 <term><parameter>errmin</parameter></term>
5432 Like <parameter>errmaj</parameter>, but for the minor part
5434 </para></listitem></varlistentry>
5438 </para></blockquote>
5439 </para></blockquote>
5443 void UnloadModule(pointer mod);
5446 This function unloads the module referred to by the handle mod.
5447 All child modules are also unloaded recursively. This function must
5448 not be used to directly unload modules that are child modules (i.e.,
5449 those that have been loaded with the <function>LoadSubModule()</function>
5453 </blockquote></para></blockquote>
5457 <title>Module Requirements</title>
5460 Modules must provide information about themselves to the loader, and
5461 may optionally provide entry points for "setup" and "teardown" functions
5462 (those two functions are referred to here as <function>SetupProc</function>
5463 and <function>TearDownProc</function>).
5467 The module information is contained in the
5468 <structname>XF86ModuleVersionInfo</structname> struct, which is defined as follows:
5472 const char * modname; /* name of module, e.g. "foo" */
5473 const char * vendor; /* vendor specific string */
5474 CARD32 _modinfo1_; /* constant MODINFOSTRING1/2 to find */
5475 CARD32 _modinfo2_; /* infoarea with a binary editor/sign tool */
5476 CARD32 xf86version; /* contains XF86_VERSION_CURRENT */
5477 CARD8 majorversion; /* module-specific major version */
5478 CARD8 minorversion; /* module-specific minor version */
5479 CARD16 patchlevel; /* module-specific patch level */
5480 const char * abiclass; /* ABI class that the module uses */
5481 CARD32 abiversion; /* ABI version */
5482 const char * moduleclass; /* module class */
5483 CARD32 checksum[4]; /* contains a digital signature of the */
5484 /* version info structure */
5485 } XF86ModuleVersionInfo;
5488 The fields are used as follows:
5492 <term><structfield>modname</structfield></term>
5494 The module's name. This field is currently only for
5495 informational purposes, but the loader may be modified
5496 in future to require it to match the module's canonical
5498 </para></listitem></varlistentry>
5502 <term><structfield>vendor</structfield></term>
5504 The module vendor. This field is for informational purposes
5506 </para></listitem></varlistentry>
5510 <term><structfield>_modinfo1_</structfield></term>
5512 This field holds the first part of a signature that can
5513 be used to locate this structure in the binary. It should
5514 always be initialised to <constant>MODINFOSTRING1</constant>.
5515 </para></listitem></varlistentry>
5519 <term><structfield>_modinfo2_</structfield></term>
5521 This field holds the second part of a signature that can
5522 be used to locate this structure in the binary. It should
5523 always be initialised to <constant>MODINFOSTRING2</constant>.
5524 </para></listitem></varlistentry>
5528 <term><structfield>xf86version</structfield></term>
5530 The XFree86 version against which the module was compiled.
5531 This is mostly for informational/diagnostic purposes. It
5532 should be initialised to <constant>XF86_VERSION_CURRENT</constant>, which is
5533 defined in <filename>xf86Version.h</filename>.
5534 </para></listitem></varlistentry>
5538 <term><structfield>majorversion</structfield></term>
5540 The module-specific major version. For modules where this
5541 version is used for more than simply informational
5542 purposes, the major version should only change (be
5543 incremented) when ABI incompatibilities are introduced,
5544 or ABI components are removed.
5545 </para></listitem></varlistentry>
5549 <term><structfield>minorversion</structfield></term>
5551 The module-specific minor version. For modules where this
5552 version is used for more than simply informational
5553 purposes, the minor version should only change (be
5554 incremented) when ABI additions are made in a backward
5555 compatible way. It should be reset to zero when the major
5556 version is increased.
5557 </para></listitem></varlistentry>
5561 <term><structfield>patchlevel</structfield></term>
5563 The module-specific patch level. The patch level should
5564 increase with new revisions of the module where there
5565 are no ABI changes, and it should be reset to zero when
5566 the minor version is increased.
5567 </para></listitem></varlistentry>
5571 <term><structfield>abiclass</structfield></term>
5573 The ABI class that the module requires. The class is
5574 specified as a string for easy extensibility. It should
5575 indicate which (if any) of the X server's built-in ABI
5576 classes that the module relies on, or a third-party ABI
5577 if appropriate. Built-in ABI classes currently defined are:
5581 <term><constant>ABI_CLASS_NONE</constant></term>
5582 <listitem><para>no class
5583 </para></listitem></varlistentry>
5585 <term><constant>ABI_CLASS_ANSIC</constant></term>
5586 <listitem><para>only requires the ANSI C interfaces
5587 </para></listitem></varlistentry>
5589 <term><constant>ABI_CLASS_VIDEODRV</constant></term>
5590 <listitem><para>requires the video driver ABI
5591 </para></listitem></varlistentry>
5593 <term><constant>ABI_CLASS_XINPUT</constant></term>
5594 <listitem><para>requires the XInput driver ABI
5595 </para></listitem></varlistentry>
5597 <term><constant>ABI_CLASS_EXTENSION</constant></term>
5598 <listitem><para>requires the extension module ABI
5599 </para></listitem></varlistentry>
5601 <term><constant>ABI_CLASS_FONT</constant></term>
5602 <listitem><para>requires the font module ABI
5603 </para></listitem></varlistentry>
5606 </para></listitem></varlistentry>
5609 <term><structfield>abiversion</structfield></term>
5611 The version of abiclass that the module requires. The
5612 version consists of major and minor components. The
5613 major version must match and the minor version must be
5614 no newer than that provided by the server or parent
5615 module. Version identifiers for the built-in classes
5616 currently defined are:
5618 <literallayout><constant>
5620 ABI_VIDEODRV_VERSION
5622 ABI_EXTENSION_VERSION
5624 </constant></literallayout>
5626 </para></listitem></varlistentry>
5629 <term><structfield>moduleclass</structfield></term>
5631 This is similar to the abiclass field, except that it
5632 defines the type of module rather than the ABI it
5633 requires. For example, although all video drivers require
5634 the video driver ABI, not all modules that require the
5635 video driver ABI are video drivers. This distinction
5636 can be made with the moduleclass. Currently pre-defined
5639 <literallayout><constant>
5645 </constant></literallayout>
5647 </para></listitem></varlistentry>
5650 <term><structfield>checksum</structfield></term>
5653 </para></listitem></varlistentry>
5659 The module version information, and the optional <function>SetupProc</function>
5660 and <function>TearDownProc</function> entry points are found by the loader
5661 by locating a data object in the module called "modnameModuleData",
5662 where "modname" is the canonical name of the module. Modules must
5663 contain such a data object, and it must be declared with global scope,
5664 be compile-time initialised, and is of the following type:
5668 XF86ModuleVersionInfo * vers;
5669 ModuleSetupProc setup;
5670 ModuleTearDownProc teardown;
5676 The vers parameter must be initialised to a pointer to a correctly
5677 initialised <structname>XF86ModuleVersionInfo</structname> struct. The other
5678 two parameter are optional, and should be initialised to
5679 <constant>NULL</constant> when not required. The other parameters are defined
5684 typedef pointer (*ModuleSetupProc)(pointer, pointer, int *, int *);
5686 typedef void (*ModuleTearDownProc)(pointer);
5688 pointer SetupProc(pointer module, pointer options,
5689 int *errmaj, int *errmin);
5692 When defined, this function is called by the loader after successfully
5693 loading a module. module is a handle for the newly loaded module,
5694 and maybe used by the <function>SetupProc</function> if it calls other
5695 loader functions that require a reference to it. The remaining
5696 arguments are those that were passed to the
5697 <function>LoadModule()</function> (or <function>LoadSubModule()</function>),
5698 and are described above. When the <function>SetupProc</function> is
5699 successful it must return a non-<constant>NULL</constant> value. The
5700 loader checks this, and if it is <constant>NULL</constant> it unloads
5701 the module and reports the failure to the caller of
5702 <function>LoadModule()</function>. If the <function>SetupProc</function>
5703 does things that need to be undone when the module is unloaded,
5704 it should define a <function>TearDownProc</function>, and return a
5705 pointer that the <function>TearDownProc</function> can use to undo what
5710 When a module is loaded multiple times, the <function>SetupProc</function>
5711 is called once for each time it is loaded.
5714 </blockquote></para></blockquote>
5718 void TearDownProc(pointer tearDownData);
5721 When defined, this function is called when the loader unloads a
5722 module. The <parameter>tearDownData</parameter> parameter is the return
5723 value of the <function>SetupProc()</function> that was called when the
5724 module was loaded. The purpose of this function is to clean up
5725 before the module is unloaded (for example, by freeing allocated
5729 </blockquote></para></blockquote>
5734 <title>Public Loader Interface</title>
5737 The following is the Loader interface that is available to any part of
5738 the server, and may also be used from within modules.
5743 pointer LoadSubModule(pointer parent, const char *module,
5744 const char **subdirlist, const char **patternlist,
5745 pointer options, const XF86ModReqInfo * modreq,
5746 int *errmaj, int *errmin);
5749 This function is like the <function>LoadModule()</function> function
5750 described above, except that the module loaded is registered as a
5751 child of the calling module. The <parameter>parent</parameter> parameter
5752 is the calling module's handle. Modules loaded with this function
5753 are automatically unloaded when the parent module is unloaded. The
5754 other difference is that the path parameter may not be specified.
5755 The module search path used for modules loaded with this function
5756 is the default search path as initialised with
5757 <function>LoaderSetPath()</function>.
5760 </blockquote></para></blockquote>
5764 void UnloadSubModule(pointer module);
5767 This function unloads the module with handle <parameter>module</parameter>.
5768 If that module itself has children, they are also unloaded. It is
5769 like <function>UnloadModule()</function>, except that it is safe to use
5770 for unloading child modules.
5773 </blockquote></para></blockquote>
5777 pointer LoaderSymbol(const char *symbol);
5780 This function returns the address of the symbol with name
5781 <parameter>symbol</parameter>. This may be used to locate a module entry
5782 point with a known name.
5785 </blockquote></para></blockquote>
5789 char **LoaderlistDirs(const char **subdirlist,
5790 const char **patternlist);
5793 This function returns a <constant>NULL</constant> terminated list of
5794 canonical modules names for modules found in the default module
5795 search path. The <parameter>subdirlist</parameter> and
5796 <parameter>patternlist</parameter> parameters are as described above, and
5797 can be used to control the locations and names that are searched.
5798 If no modules are found, the return value is <constant>NULL</constant>.
5799 The returned list should be freed by calling
5800 <function>LoaderFreeDirList()</function> when it is no longer needed.
5803 </blockquote></para></blockquote>
5807 void LoaderFreeDirList(char **list);
5810 This function frees a module list created by
5811 <function>LoaderlistDirs()</function>.
5814 </blockquote></para></blockquote>
5818 void LoaderReqSymLists(const char **list0, ...);
5821 This function allows the registration of required symbols with the
5822 loader. It is normally used by a caller of
5823 <function>LoadSubModule()</function>. If any symbols registered in this
5824 way are found to be unresolved when
5825 <function>LoaderCheckUnresolved()</function> is called then
5826 <function>LoaderCheckUnresolved()</function> will report a failure.
5827 The function takes one or more <constant>NULL</constant> terminated
5828 lists of symbols. The end of the argument list is indicated by a
5829 <constant>NULL</constant> argument.
5832 </blockquote></para></blockquote>
5836 void LoaderReqSymbols(const char *sym0, ...);
5839 This function is like <function>LoaderReqSymLists()</function> except
5840 that its arguments are symbols rather than lists of symbols. This
5841 function is more convenient when single functions are to be registered,
5842 especially when the single function might depend on runtime factors.
5843 The end of the argument list is indicated by a <constant>NULL</constant>
5847 </blockquote></para></blockquote>
5851 void LoaderRefSymLists(const char **list0, ...);
5854 This function allows the registration of possibly unresolved symbols
5855 with the loader. When <function>LoaderCheckUnresolved()</function> is
5856 run it won't generate warnings for symbols registered in this way
5857 unless they were also registered as required symbols.
5858 The function takes one or more <constant>NULL</constant> terminated
5859 lists of symbols. The end of the argument list is indicated by a
5860 <constant>NULL</constant> argument.
5863 </blockquote></para></blockquote>
5867 void LoaderRefSymbols(const char *sym0, ...);
5870 This function is like <function>LoaderRefSymLists()</function> except
5871 that its arguments are symbols rather than lists of symbols. This
5872 function is more convenient when single functions are to be registered,
5873 especially when the single function might depend on runtime factors.
5874 The end of the argument list is indicated by a <constant>NULL</constant>
5878 </blockquote></para></blockquote>
5882 int LoaderCheckUnresolved(int delayflag);
5885 This function checks for unresolved symbols. It generates warnings
5886 for unresolved symbols that have not been registered with
5887 <function>LoaderRefSymLists()</function>, and maps them to a dummy
5888 function. This behaviour may change in future. If unresolved
5889 symbols are found that have been registered with
5890 <function>LoaderReqSymLists()</function> or
5891 <function>LoaderReqSymbols()</function> then this function returns a
5892 non-zero value. If none of these symbols are unresolved the return
5893 value is zero, indicating success.
5897 The <parameter>delayflag</parameter> parameter should normally be set to
5898 <constant>LD_RESOLV_IFDONE</constant>.
5901 </blockquote></para></blockquote>
5905 LoaderErrorMsg(const char *name, const char *modname,
5906 int errmaj, int errmin);
5909 This function prints an error message that includes the text <quote>Failed
5910 to load module</quote>, the module name <parameter>modname</parameter>, a message
5911 specific to the <parameter>errmaj</parameter> value, and the value if
5912 <parameter>errmin</parameter>. If <parameter>name</parameter> is
5913 non-<constant>NULL</constant>, it is printed as an identifying prefix
5914 to the message (followed by a <quote>:</quote>).
5917 </blockquote></para></blockquote>
5921 <title>Special Registration Functions</title>
5924 The loader contains some functions for registering some classes of modules.
5925 These may be moved out of the loader at some point.
5930 void LoadExtension(ExtensionModule *ext);
5933 This registers the entry points for the extension identified by
5934 <parameter>ext</parameter>. The <structname>ExtensionModule</structname> struct is
5939 InitExtension initFunc;
5946 </blockquote></para></blockquote>
5953 <title>Helper Functions</title>
5956 This section describe <quote>helper</quote> functions that video driver
5957 might find useful. While video drivers are not required to use any of
5958 these to be considered <quote>compliant</quote>, the use of appropriate helpers is
5959 strongly encouraged to improve the consistency of driver behaviour.
5963 <title>Functions for printing messages</title>
5967 ErrorF(const char *format, ...);
5970 This is the basic function for writing to the error log (typically
5971 stderr and/or a log file). Video drivers should usually avoid
5972 using this directly in favour of the more specialised functions
5973 described below. This function is useful for printing messages
5974 while debugging a driver.
5977 </blockquote></para></blockquote>
5981 FatalError(const char *format, ...);
5984 This prints a message and causes the Xserver to abort. It should
5985 rarely be used within a video driver, as most error conditions
5986 should be flagged by the return values of the driver functions.
5987 This allows the higher layers to decide how to proceed. In rare
5988 cases, this can be used within a driver if a fatal unexpected
5992 </blockquote></para></blockquote>
5996 xf86ErrorF(const char *format, ...);
5999 This is like <function>ErrorF()</function>, except that the message is
6000 only printed when the Xserver's verbosity level is set to the
6001 default (<constant>1</constant>) or higher. It means that the messages
6002 are not printed when the server is started with the
6003 <option>-quiet</option> flag. Typically this function would only be
6004 used for continuing messages started with one of the more specialised
6005 functions described below.
6008 </blockquote></para></blockquote>
6012 xf86ErrorFVerb(int verb, const char *format, ...);
6015 Like <function>xf86ErrorF()</function>, except the minimum verbosity
6016 level for which the message is to be printed is given explicitly.
6017 Passing a <parameter>verb</parameter> value of zero means the message
6018 is always printed. A value higher than <constant>1</constant> can be
6019 used for information would normally not be needed, but which might
6020 be useful when diagnosing problems.
6023 </blockquote></para></blockquote>
6028 xf86Msg(MessageType type, const char *format, ...);
6031 This is like <function>xf86ErrorF()</function>, except that the message
6032 is prefixed with a marker determined by the value of
6033 <parameter>type</parameter>. The marker is used to indicate the type of
6034 message (warning, error, probed value, config value, etc). Note
6035 the <varname>xf86Verbose</varname> value is ignored for messages of
6036 type <constant>X_ERROR</constant>.
6040 The marker values are:
6044 <term><constant>X_PROBED</constant></term>
6045 <listitem><para>Value was probed.
6046 </para></listitem></varlistentry>
6048 <term><constant>X_CONFIG</constant></term>
6049 <listitem><para>Value was given in the config file.
6050 </para></listitem></varlistentry>
6052 <term><constant>X_DEFAULT</constant></term>
6053 <listitem><para>Value is a default.
6054 </para></listitem></varlistentry>
6056 <term><constant>X_CMDLINE</constant></term>
6057 <listitem><para>Value was given on the command line.
6058 </para></listitem></varlistentry>
6060 <term><constant>X_NOTICE</constant></term>
6061 <listitem><para>Notice.
6062 </para></listitem></varlistentry>
6064 <term><constant>X_ERROR</constant></term>
6065 <listitem><para>Error message.
6066 </para></listitem></varlistentry>
6068 <term><constant>X_WARNING</constant></term>
6069 <listitem><para>Warning message.
6070 </para></listitem></varlistentry>
6072 <term><constant>X_INFO</constant></term>
6073 <listitem><para>Informational message.
6074 </para></listitem></varlistentry>
6076 <term><constant>X_NONE</constant></term>
6077 <listitem><para>No prefix.
6078 </para></listitem></varlistentry>
6080 <term><constant>X_NOT_IMPLEMENTED</constant></term>
6081 <listitem><para>The message relates to functionality
6082 that is not yetimplemented.
6083 </para></listitem></varlistentry>
6088 </blockquote></para></blockquote>
6092 xf86MsgVerb(MessageType type, int verb, const char *format, ...);
6095 Like <function>xf86Msg()</function>, but with the verbosity level given
6099 </blockquote></para></blockquote>
6103 xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...);
6106 This is like <function>xf86Msg()</function> except that the driver's
6107 name (the <structfield>name</structfield> field of the
6108 <structname>ScrnInfoRec</structname>) followed by the
6109 <parameter>scrnIndex</parameter> in parentheses is printed following the
6110 prefix. This should be used by video drivers in most cases as it
6111 clearly indicates which driver/screen the message is for. If
6112 <parameter>scrnIndex</parameter> is negative, this function behaves
6113 exactly like <function>xf86Msg()</function>.
6117 NOTE: This function can only be used after the
6118 <structname>ScrnInfoRec</structname> and its <structfield>name</structfield> field
6119 have been allocated. Normally, this means that it can not be
6120 used before the END of the <function>ChipProbe()</function> function.
6121 Prior to that, use <function>xf86Msg()</function>, providing the
6122 driver's name explicitly. No screen number can be supplied at
6126 </blockquote></para></blockquote>
6130 xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb,
6131 const char *format, ...);
6134 Like <function>xf86DrvMsg()</function>, but with the verbosity level
6138 </blockquote></para></blockquote>
6143 <title>Functions for setting values based on command line and config file</title>
6147 Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp,
6149 int fbbpp, int depth24flags);
6152 This function sets the <structfield>depth</structfield>, <structfield>pixmapBPP</structfield> and <structfield>bitsPerPixel</structfield> fields
6153 of the <structname>ScrnInfoRec</structname>. It also determines the defaults for display-wide
6154 attributes and pixmap formats the screen will support, and finds
6155 the Display subsection that matches the depth/bpp. This function
6156 should normally be called very early from the
6157 <function>ChipPreInit()</function> function.
6161 It requires that the <structfield>confScreen</structfield> field of the <structname>ScrnInfoRec</structname> be
6162 initialised prior to calling it. This is done by the XFree86
6163 common layer prior to calling <function>ChipPreInit()</function>.
6167 The parameters passed are:
6171 <term><parameter>depth</parameter></term>
6173 driver's preferred default depth if no other is given.
6174 If zero, use the overall server default.
6175 </para></listitem></varlistentry>
6178 <term><parameter>bpp</parameter></term>
6180 Same, but for the pixmap bpp.
6181 </para></listitem></varlistentry>
6184 <term><parameter>fbbpp</parameter></term>
6186 Same, but for the framebuffer bpp.
6187 </para></listitem></varlistentry>
6190 <term><parameter>depth24flags</parameter></term>
6192 Flags that indicate the level of 24/32bpp support
6193 and whether conversion between different framebuffer
6194 and pixmap formats is supported. The flags for this
6195 argument are defined as follows, and multiple flags
6196 may be ORed together:
6200 <term><constant>NoDepth24Support</constant></term>
6201 <listitem><para>No depth 24 formats supported
6202 </para></listitem></varlistentry>
6204 <term><constant>Support24bppFb</constant></term>
6205 <listitem><para>24bpp framebuffer supported
6206 </para></listitem></varlistentry>
6208 <term><constant>Support32bppFb</constant></term>
6209 <listitem><para>32bpp framebuffer supported
6210 </para></listitem></varlistentry>
6212 <term><constant>SupportConvert24to32</constant></term>
6213 <listitem><para>Can convert 24bpp pixmap to 32bpp fb
6214 </para></listitem></varlistentry>
6216 <term><constant>SupportConvert32to24</constant></term>
6217 <listitem><para>Can convert 32bpp pixmap to 24bpp fb
6218 </para></listitem></varlistentry>
6220 <term><constant>ForceConvert24to32</constant></term>
6221 <listitem><para>Force 24bpp pixmap to 32bpp fb conversion
6222 </para></listitem></varlistentry>
6224 <term><constant>ForceConvert32to24</constant></term>
6225 <listitem><para>Force 32bpp pixmap to 24bpp fb conversion
6226 </para></listitem></varlistentry>
6228 </para></listitem></varlistentry>
6234 It uses the command line, config file, and default values in the
6235 correct order of precedence to determine the depth and bpp values.
6236 It is up to the driver to check the results to see that it supports
6237 them. If not the <function>ChipPreInit()</function> function should
6238 return <constant>FALSE</constant>.
6242 If only one of depth/bpp is given, the other is set to a reasonable
6243 (and consistent) default.
6247 If a driver finds that the initial <parameter>depth24flags</parameter>
6248 it uses later results in a fb format that requires more video
6249 memory than is available it may call this function a second time
6250 with a different <parameter>depth24flags</parameter> setting.
6254 On success, the return value is <constant>TRUE</constant>. On failure
6255 it prints an error message and returns <constant>FALSE</constant>.
6259 The following fields of the <structname>ScrnInfoRec</structname> are
6260 initialised by this function:
6263 <structfield>depth</structfield>, <structfield>bitsPerPixel</structfield>,
6264 <structfield>display</structfield>, <structfield>imageByteOrder</structfield>,
6265 <structfield>bitmapScanlinePad</structfield>,
6266 <structfield>bitmapScanlineUnit</structfield>, <structfield>bitmapBitOrder</structfield>,
6267 <structfield>numFormats</structfield>, <structfield>formats</structfield>,
6268 <structfield>fbFormat</structfield>.
6269 </para></blockquote>
6272 </blockquote></para></blockquote>
6276 void xf86PrintDepthBpp(scrnInfoPtr scrp);
6279 This function can be used to print out the depth and bpp settings.
6280 It should be called after the final call to
6281 <function>xf86SetDepthBpp()</function>.
6284 </blockquote></para></blockquote>
6288 Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask);
6291 This function sets the <structfield>weight</structfield>, <structfield>mask</structfield>,
6292 <structfield>offset</structfield> and <structfield>rgbBits</structfield> fields of the
6293 <structname>ScrnInfoRec</structname>. It would normally be called fairly
6294 early in the <function>ChipPreInit()</function> function for
6295 depths > 8bpp.
6299 It requires that the <structfield>depth</structfield> and
6300 <structfield>display</structfield> fields of the <structname>ScrnInfoRec</structname>
6301 be initialised prior to calling it.
6305 The parameters passed are:
6309 <term><parameter>weight</parameter></term>
6311 driver's preferred default weight if no other is given.
6312 If zero, use the overall server default.
6314 </para></listitem></varlistentry>
6317 <term><parameter>mask</parameter></term>
6321 </para></listitem></varlistentry>
6326 It uses the command line, config file, and default values in the
6327 correct order of precedence to determine the weight value. It
6328 derives the mask and offset values from the weight and the defaults.
6329 It is up to the driver to check the results to see that it supports
6330 them. If not the <function>ChipPreInit()</function> function should
6331 return <constant>FALSE</constant>.
6335 On success, this function prints a message showing the weight
6336 values selected, and returns <constant>TRUE</constant>.
6340 On failure it prints an error message and returns <constant>FALSE</constant>.
6344 The following fields of the <structname>ScrnInfoRec</structname> are
6345 initialised by this function:
6348 <structfield>weight</structfield>,
6349 <structfield>mask</structfield>,
6350 <structfield>offset</structfield>.
6351 </para></blockquote>
6354 </blockquote></para></blockquote>
6358 Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual);
6361 This function sets the <structfield>defaultVisual</structfield> field of the
6362 <structname>ScrnInfoRec</structname>. It would normally be called fairly
6363 early from the <function>ChipPreInit()</function> function.
6367 It requires that the <structfield>depth</structfield> and
6368 <structfield>display</structfield> fields of the <structname>ScrnInfoRec</structname>
6369 be initialised prior to calling it.
6373 The parameters passed are:
6377 <term><parameter>visual</parameter></term>
6379 driver's preferred default visual if no other is given.
6380 If <constant>-1</constant>, use the overall server default.
6381 </para></listitem></varlistentry>
6387 It uses the command line, config file, and default values in the
6388 correct order of precedence to determine the default visual value.
6389 It is up to the driver to check the result to see that it supports
6390 it. If not the <function>ChipPreInit()</function> function should
6391 return <constant>FALSE</constant>.
6395 On success, this function prints a message showing the default visual
6396 selected, and returns <constant>TRUE</constant>.
6400 On failure it prints an error message and returns <constant>FALSE</constant>.
6403 </blockquote></para></blockquote>
6407 Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma);
6410 This function sets the <structfield>gamma</structfield> field of the
6411 <structname>ScrnInfoRec</structname>. It would normally be called fairly
6412 early from the <function>ChipPreInit()</function> function in cases
6413 where the driver supports gamma correction.
6417 It requires that the <structfield>monitor</structfield> field of the
6418 <structname>ScrnInfoRec</structname> be initialised prior to calling it.
6422 The parameters passed are:
6426 <term><parameter>gamma</parameter></term>
6428 driver's preferred default gamma if no other is given.
6429 If zero (<code>< 0.01</code>), use the overall server
6431 </para></listitem></varlistentry>
6437 It uses the command line, config file, and default values in the
6438 correct order of precedence to determine the gamma value. It is
6439 up to the driver to check the results to see that it supports
6440 them. If not the <function>ChipPreInit()</function> function should
6441 return <constant>FALSE</constant>.
6445 On success, this function prints a message showing the gamma
6446 value selected, and returns <constant>TRUE</constant>.
6450 On failure it prints an error message and returns <constant>FALSE</constant>.
6453 </blockquote></para></blockquote>
6458 void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y);
6461 This function sets the <structfield>xDpi</structfield> and <structfield>yDpi</structfield>
6462 fields of the <structname>ScrnInfoRec</structname>. The driver can specify
6463 preferred defaults by setting <parameter>x</parameter> and <parameter>y</parameter>
6464 to non-zero values. The <option>-dpi</option> command line option
6465 overrides all other settings. Otherwise, if the
6466 <emphasis>DisplaySize</emphasis> entry is present in the screen's &k.monitor;
6467 config file section, it is used together with the virtual size to
6468 calculate the dpi values. This function should be called after
6469 all the mode resolution has been done.
6472 </blockquote></para></blockquote>
6476 void xf86SetBlackWhitePixels(ScrnInfoPtr pScrn);
6479 This functions sets the <structfield>blackPixel</structfield> and
6480 <structfield>whitePixel</structfield> fields of the <structname>ScrnInfoRec</structname>
6481 according to whether or not the <option>-flipPixels</option> command
6482 line options is present.
6485 </blockquote></para></blockquote>
6489 const char *xf86GetVisualName(int visual);
6492 Returns a printable string with the visual name matching the
6493 numerical visual class provided. If the value is outside the
6494 range of valid visual classes, <constant>NULL</constant> is returned.
6497 </blockquote></para></blockquote>
6502 <title>Primary Mode functions</title>
6505 The primary mode helper functions are those which would normally be
6506 used by a driver, unless it has unusual requirements which cannot
6507 be catered for the by the helpers.
6512 int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
6513 char **modeNames, ClockRangePtr clockRanges,
6514 int *linePitches, int minPitch, int maxPitch,
6515 int pitchInc, int minHeight, int maxHeight,
6516 int virtualX, int virtualY,
6517 unsigned long apertureSize,
6518 LookupModeFlags strategy);
6521 This function basically selects the set of modes to use based on
6522 those available and the various constraints. It also sets some
6523 other related parameters. It is normally called near the end of
6524 the <function>ChipPreInit()</function> function.
6528 The parameters passed to the function are:
6532 <term><parameter>availModes</parameter></term>
6534 List of modes available for the monitor.
6535 </para></listitem></varlistentry>
6538 <term><parameter>modeNames</parameter></term>
6540 List of mode names that the screen is requesting.
6541 </para></listitem></varlistentry>
6544 <term><parameter>clockRanges</parameter></term>
6546 A list of clock ranges allowed by the driver. Each
6547 range includes whether interlaced or multiscan modes
6548 are supported for that range. See below for more on
6549 <parameter>clockRanges</parameter>.
6550 </para></listitem></varlistentry>
6553 <term><parameter>linePitches</parameter></term>
6555 List of line pitches supported by the driver.
6556 This is optional and should be <constant>NULL</constant> when
6558 </para></listitem></varlistentry>
6561 <term><parameter>minPitch</parameter></term>
6563 Minimum line pitch supported by the driver. This must
6564 be supplied when <parameter>linePitches</parameter> is
6565 <constant>NULL</constant>, and is ignored otherwise.
6566 </para></listitem></varlistentry>
6569 <term><parameter>maxPitch</parameter></term>
6571 Maximum line pitch supported by the driver. This is
6572 required when <parameter>minPitch</parameter> is required.
6573 </para></listitem></varlistentry>
6576 <term><parameter>pitchInc</parameter></term>
6578 Granularity of horizontal pitch values as supported by
6579 the chipset. This is expressed in bits. This must be
6581 </para></listitem></varlistentry>
6584 <term><parameter>minHeight</parameter></term>
6586 minimum virtual height allowed. If zero, no limit is
6588 </para></listitem></varlistentry>
6591 <term><parameter>maxHeight</parameter></term>
6593 maximum virtual height allowed. If zero, no limit is
6595 </para></listitem></varlistentry>
6598 <term><parameter>virtualX</parameter></term>
6600 If greater than zero, this is the virtual width value
6601 that will be used. Otherwise, the virtual width is
6602 chosen to be the smallest that can accommodate the modes
6604 </para></listitem></varlistentry>
6607 <term><parameter>virtualY</parameter></term>
6609 If greater than zero, this is the virtual height value
6610 that will be used. Otherwise, the virtual height is
6611 chosen to be the smallest that can accommodate the modes
6613 </para></listitem></varlistentry>
6616 <term><parameter>apertureSize</parameter></term>
6618 The size (in bytes) of the aperture used to access video
6620 </para></listitem></varlistentry>
6623 <term><parameter>strategy</parameter></term>
6625 The strategy to use when choosing from multiple modes
6626 with the same name. The options are:
6630 <term><constant>LOOKUP_DEFAULT</constant></term>
6632 </para></listitem></varlistentry>
6634 <term><constant>LOOKUP_BEST_REFRESH</constant></term>
6635 <listitem><para>mode with best refresh rate
6636 </para></listitem></varlistentry>
6638 <term><constant>LOOKUP_CLOSEST_CLOCK</constant></term>
6639 <listitem><para>mode with closest matching clock
6640 </para></listitem></varlistentry>
6642 <term><constant>LOOKUP_LIST_ORDER</constant></term>
6643 <listitem><para>first usable mode in list
6644 </para></listitem></varlistentry>
6647 The following options can also be combined (OR'ed) with
6652 <term><constant>LOOKUP_CLKDIV2</constant></term>
6653 <listitem><para>Allow halved clocks
6654 </para></listitem></varlistentry>
6656 <term><constant>LOOKUP_OPTIONAL_TOLERANCES</constant></term>
6658 Allow missing horizontal sync and/or vertical refresh
6659 ranges in the xorg.conf Monitor section
6660 </para></listitem></varlistentry>
6663 <constant>LOOKUP_OPTIONAL_TOLERANCES</constant> should only be
6664 specified when the driver can ensure all modes it generates
6665 can sync on, or at least not damage, the monitor or digital
6666 flat panel. Horizontal sync and/or vertical refresh ranges
6667 specified by the user will still be honoured (and acted upon).
6669 </para></listitem></varlistentry>
6674 This function requires that the following fields of the
6675 <structname>ScrnInfoRec</structname> are initialised prior to calling it:
6679 <term><structfield>clock[]</structfield></term>
6681 List of discrete clocks (when non-programmable)
6682 </para></listitem></varlistentry>
6684 <term><structfield>numClocks</structfield></term>
6686 Number of discrete clocks (when non-programmable)
6687 </para></listitem></varlistentry>
6689 <term><structfield>progClock</structfield></term>
6691 Whether the clock is programmable or not
6692 </para></listitem></varlistentry>
6694 <term><structfield>monitor</structfield></term>
6696 Pointer to the applicable xorg.conf monitor section
6697 </para></listitem></varlistentry>
6699 <term><structfield>fdFormat</structfield></term>
6701 Format of the screen buffer
6702 </para></listitem></varlistentry>
6704 <term><structfield>videoRam</structfield></term>
6706 total video memory size (in bytes)
6707 </para></listitem></varlistentry>
6709 <term><structfield>maxHValue</structfield></term>
6711 Maximum horizontal timing value allowed
6712 </para></listitem></varlistentry>
6714 <term><structfield>maxVValue</structfield></term>
6716 Maximum vertical timing value allowed
6717 </para></listitem></varlistentry>
6719 <term><structfield>xInc</structfield></term>
6721 Horizontal timing increment in pixels (defaults to 8)
6722 </para></listitem></varlistentry>
6727 This function fills in the following <structname>ScrnInfoRec</structname>
6732 <term><structfield>modePool</structfield></term>
6734 A subset of the modes available to the monitor which
6735 are compatible with the driver.
6736 </para></listitem></varlistentry>
6739 <term><structfield>modes</structfield></term>
6741 One mode entry for each of the requested modes, with
6742 the status field of each filled in to indicate if
6743 the mode has been accepted or not. This list of
6744 modes is a circular list.
6745 </para></listitem></varlistentry>
6748 <term><structfield>virtualX</structfield></term>
6750 The resulting virtual width.
6751 </para></listitem></varlistentry>
6754 <term><structfield>virtualY</structfield></term>
6756 The resulting virtual height.
6757 </para></listitem></varlistentry>
6760 <term><structfield>displayWidth</structfield></term>
6762 The resulting line pitch.
6763 </para></listitem></varlistentry>
6766 <term><structfield>virtualFrom</structfield></term>
6768 Where the virtual size was determined from.
6769 </para></listitem></varlistentry>
6775 The first stage of this function checks that the
6776 <parameter>virtualX</parameter> and <parameter>virtualY</parameter> values
6777 supplied (if greater than zero) are consistent with the line pitch
6778 and <parameter>maxHeight</parameter> limitations. If not, an error
6779 message is printed, and the return value is <constant>-1</constant>.
6783 The second stage sets up the mode pool, eliminating immediately
6784 any modes that exceed the driver's line pitch limits, and also
6785 the virtual width and height limits (if greater than zero). For
6786 each mode removed an informational message is printed at verbosity
6787 level <constant>2</constant>. If the mode pool ends up being empty,
6788 a warning message is printed, and the return value is
6789 <constant>0</constant>.
6793 The final stage is to lookup each mode name, and fill in the remaining
6794 parameters. If an error condition is encountered, a message is
6795 printed, and the return value is <constant>-1</constant>. Otherwise,
6796 the return value is the number of valid modes found
6797 (<constant>0</constant> if none are found).
6801 Even if the supplied mode names include duplicates, no two names will
6802 ever match the same mode. Furthermore, if the supplied mode names do not
6803 yield a valid mode (including the case where no names are passed at all),
6804 the function will continue looking through the mode pool until it finds
6805 a mode that survives all checks, or until the mode pool is exhausted.
6809 A message is only printed by this function when a fundamental
6810 problem is found. It is intended that this function may be called
6811 more than once if there is more than one set of constraints that
6812 the driver can work within.
6816 If this function returns <constant>-1</constant>, the
6817 <function>ChipPreInit()</function> function should return
6818 <constant>FALSE</constant>.
6822 <parameter>clockRanges</parameter> is a linked list of clock ranges
6823 allowed by the driver. If a mode doesn't fit in any of the defined
6824 <parameter>clockRanges</parameter>, it is rejected. The first
6825 <literal remap="tt">clockRange</literal> that matches all requirements is used.
6826 This structure needs to be initialized to NULL when allocated.
6830 <parameter>clockRanges</parameter> contains the following fields:
6834 <term><structfield>minClock</structfield></term>
6835 <term><structfield>maxClock</structfield></term>
6837 The lower and upper mode clock bounds for which the rest
6838 of the <structname>clockRange</structname> parameters apply.
6839 Since these are the mode clocks, they are not scaled
6840 with the <structfield>ClockMulFactor</structfield> and
6841 <structfield>ClockDivFactor</structfield>. It is up to the driver
6842 to adjust these values if they depend on the clock
6844 </para></listitem></varlistentry>
6847 <term><structfield>clockIndex</structfield></term>
6849 (not used yet) <constant>-1</constant> for programmable clocks
6850 </para></listitem></varlistentry>
6853 <term><structfield>interlaceAllowed</structfield></term>
6855 <constant>TRUE</constant> if interlacing is allowed for this
6857 </para></listitem></varlistentry>
6860 <term><structfield>doubleScanAllowed</structfield></term>
6862 <constant>TRUE</constant> if doublescan or multiscan is allowed
6864 </para></listitem></varlistentry>
6867 <term><structfield>ClockMulFactor</structfield></term>
6868 <term><structfield>ClockDivFactor</structfield></term>
6870 Scaling factors that are applied to the mode clocks ONLY
6871 before selecting a clock index (when there is no
6872 programmable clock) or a <structfield>SynthClock</structfield>
6873 value. This is useful for drivers that support pixel
6874 multiplexing or that need to scale the clocks because
6875 of hardware restrictions (like sending 24bpp data to an
6876 8 bit RAMDAC using a tripled clock).
6880 Note that these parameters describe what must be done
6881 to the mode clock to achieve the data transport clock
6882 between graphics controller and RAMDAC. For example
6883 for <literal remap="tt">2:1</literal> pixel multiplexing, two pixels
6884 are sent to the RAMDAC on each clock. This allows the
6885 RAMDAC clock to be half of the actual pixel clock.
6886 Hence, <code>ClockMulFactor=1</code> and
6887 <code>ClockDivFactor=2</code>. This means that the
6888 clock used for clock selection (ie, determining the
6889 correct clock index from the list of discrete clocks)
6890 or for the <structfield>SynthClock</structfield> field in case of
6891 a programmable clock is: (<code>mode->Clock *
6892 ClockMulFactor) / ClockDivFactor</code>.
6893 </para></listitem></varlistentry>
6896 <term><structfield>PrivFlags</structfield></term>
6898 This field is copied into the
6899 <literal remap="tt">mode->PrivFlags</literal> field when this
6900 <literal remap="tt">clockRange</literal> is selected by
6901 <function>xf86ValidateModes()</function>. It allows the
6902 driver to find out what clock range was selected, so it
6903 knows it needs to set up pixel multiplexing or any other
6904 range-dependent feature. This field is purely
6905 driver-defined: it may contain flag bits, an index or
6906 anything else (as long as it is an <literal remap="tt">INT</literal>).
6907 </para></listitem></varlistentry>
6912 Note that the <structfield>mode->SynthClock</structfield> field is always
6913 filled in by <function>xf86ValidateModes()</function>: it will contain
6914 the <quote>data transport clock</quote>, which is the clock that will have
6915 to be programmed in the chip when it has a programmable clock, or
6916 the clock that will be picked from the clocks list when it is not
6917 a programmable one. Thus:
6920 mode->SynthClock = (mode->Clock * ClockMulFactor) / ClockDivFactor
6924 </blockquote></para></blockquote>
6928 void xf86PruneDriverModes(ScrnInfoPtr scrp);
6931 This function deletes modes in the modes field of the
6932 <structname>ScrnInfoRec</structname> that have been marked as invalid.
6933 This is normally run after having run
6934 <function>xf86ValidateModes()</function> for the last time. For each
6935 mode that is deleted, a warning message is printed out indicating
6936 the reason for it being deleted.
6939 </blockquote></para></blockquote>
6943 void xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags);
6946 This function fills in the <structname>Crtc*</structname> fields for all
6947 the modes in the <structfield>modes</structfield> field of the
6948 <structname>ScrnInfoRec</structname>. The <parameter>adjustFlags</parameter>
6949 parameter determines how the vertical CRTC values are scaled for
6950 interlaced modes. They are halved if it is
6951 <constant>INTERLACE_HALVE_V</constant>. The vertical CRTC values are
6952 doubled for doublescan modes, and are further multiplied by the
6953 <literal remap="tt">VScan</literal> value.
6957 This function is normally called after calling
6958 <function>xf86PruneDriverModes()</function>.
6961 </blockquote></para></blockquote>
6965 void xf86PrintModes(ScrnInfoPtr scrp);
6968 This function prints out the virtual size setting, and the line
6969 pitch being used. It also prints out two lines for each mode being
6970 used. The first line includes the mode's pixel clock, horizontal sync
6971 rate, refresh rate, and whether it is interlaced, doublescanned and/or
6972 multi-scanned. The second line is the mode's Modeline.
6976 This function is normally called after calling
6977 <function>xf86SetCrtcForModes()</function>.
6980 </blockquote></para></blockquote>
6985 <title>Secondary Mode functions</title>
6988 The secondary mode helper functions are functions which are normally
6989 used by the primary mode helper functions, and which are not normally
6990 called directly by a driver. If a driver has unusual requirements
6991 and needs to do its own mode validation, it might be able to make
6992 use of some of these secondary mode helper functions.
6997 int xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
7001 This function returns the index of the closest clock to the
7002 frequency <parameter>freq</parameter> given (in kHz). It assumes that
7003 the number of clocks is greater than zero. It requires that the
7004 <structfield>numClocks</structfield> and <structfield>clock</structfield> fields of the
7005 <structname>ScrnInfoRec</structname> are initialised. The
7006 <structfield>allowDiv2</structfield> field determines if the clocks can be
7007 halved. The <parameter>*divider</parameter> return value indicates
7008 whether clock division is used when determining the clock returned.
7012 This function is only for non-programmable clocks.
7015 </blockquote></para></blockquote>
7019 const char *xf86ModeStatusToString(ModeStatus status);
7022 This function converts the <parameter>status</parameter> value to a
7023 descriptive printable string.
7026 </blockquote></para></blockquote>
7030 ModeStatus xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
7031 ClockRangePtr clockRanges, LookupModeFlags strategy);
7034 This function takes a pointer to a mode with the name filled in,
7035 and looks for a mode in the <structfield>modePool</structfield> list which
7036 matches. The parameters of the matching mode are filled in to
7037 <parameter>*modep</parameter>. The <parameter>clockRanges</parameter> and
7038 <parameter>strategy</parameter> parameters are as for the
7039 <function>xf86ValidateModes()</function> function above.
7043 This function requires the <structfield>modePool</structfield>,
7044 <structfield>clock[]</structfield>, <structfield>numClocks</structfield> and
7045 <structfield>progClock</structfield> fields of the <structname>ScrnInfoRec</structname>
7046 to be initialised before being called.
7050 The return value is <constant>MODE_OK</constant> if a mode was found.
7051 Otherwise it indicates why a matching mode could not be found.
7054 </blockquote></para></blockquote>
7058 ModeStatus xf86InitialCheckModeForDriver(ScrnInfoPtr scrp,
7059 DisplayModePtr mode, ClockRangePtr clockRanges,
7060 LookupModeFlags strategy, int maxPitch,
7061 int virtualX, int virtualY);
7064 This function checks the passed mode against some basic driver
7065 constraints. Apart from the ones passed explicitly, the
7066 <structfield>maxHValue</structfield> and <structfield>maxVValue</structfield> fields of
7067 the <structname>ScrnInfoRec</structname> are also used. If the
7068 <structfield>ValidMode</structfield> field of the <structname>ScrnInfoRec</structname>
7069 is set, that function is also called to check the mode. Next, the
7070 mode is checked against the monitor's constraints.
7074 If the mode is consistent with all constraints, the return value
7075 is <constant>MODE_OK</constant>. Otherwise the return value indicates
7076 which constraint wasn't met.
7079 </blockquote></para></blockquote>
7083 void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode);
7086 This function deletes the <parameter>mode</parameter> given from the
7087 <parameter>modeList</parameter>. It never prints any messages, so it is
7088 up to the caller to print a message if required.
7091 </blockquote></para></blockquote>
7095 <title>Functions for handling strings and tokens</title>
7098 Tables associating strings and numerical tokens combined with the
7099 following functions provide a compact way of handling strings from
7100 the config file, and for converting tokens into printable strings.
7101 The table data structure is:
7107 } SymTabRec, *SymTabPtr;
7112 A table is an initialised array of <structname>SymTabRec</structname>. The
7113 tokens must be non-negative integers. Multiple names may be mapped
7114 to a single token. The table is terminated with an element with a
7115 <structfield>token</structfield> value of <constant>-1</constant> and
7116 <constant>NULL</constant> for the <structfield>name</structfield>.
7121 const char *xf86TokenToString(SymTabPtr table, int token);
7124 This function returns the first string in <parameter>table</parameter>
7125 that matches <parameter>token</parameter>. If no match is found,
7126 <constant>NULL</constant> is returned (NOTE, older versions of this
7127 function would return the string "unknown" when no match is found).
7130 </blockquote></para></blockquote>
7134 int xf86StringToToken(SymTabPtr table, const char *string);
7137 This function returns the first token in <parameter>table</parameter>
7138 that matches <parameter>string</parameter>. The
7139 <function>xf86NameCmp()</function> function is used to determine the
7140 match. If no match is found, <constant>-1</constant> is returned.
7143 </blockquote></para></blockquote>
7148 <title>Functions for finding which config file entries to use</title>
7151 These functions can be used to select the appropriate config file
7152 entries that match the detected hardware. They are described above
7153 in the <link linkend="probe">Probe</link> and
7154 <link linkend="avail">Available Functions</link> sections.
7160 <title>Probing discrete clocks on old hardware</title>
7163 The <function>xf86GetClocks()</function> function may be used to assist
7164 in finding the discrete pixel clock values on older hardware.
7169 void xf86GetClocks(ScrnInfoPtr pScrn, int num,
7170 Bool (*ClockFunc)(ScrnInfoPtr, int),
7171 void (*ProtectRegs)(ScrnInfoPtr, Bool),
7172 void (*BlankScreen)(ScrnInfoPtr, Bool),
7173 int vertsyncreg, int maskval, int knownclkindex,
7177 This function uses a comparative sampling method to measure the
7178 discrete pixel clock values. The number of discrete clocks to
7179 measure is given by <parameter>num</parameter>. <parameter>clockFunc</parameter>
7180 is a function that selects the <parameter>n</parameter>'th clock. It
7181 should also save or restore any state affected by programming the
7182 clocks when the index passed is <constant>CLK_REG_SAVE</constant> or
7183 <constant>CLK_REG_RESTORE</constant>. <parameter>ProtectRegs</parameter> is
7184 a function that does whatever is required to protect the hardware
7185 state while selecting a new clock. <parameter>BlankScreen</parameter>
7186 is a function that blanks the screen. <parameter>vertsyncreg</parameter>
7187 and <parameter>maskval</parameter> are the register and bitmask to
7188 check for the presence of vertical sync pulses.
7189 <parameter>knownclkindex</parameter> and <parameter>knownclkvalue</parameter>
7190 are the index and value of a known clock. These are the known
7191 references on which the comparative measurements are based. The
7192 number of clocks probed is set in <structfield>pScrn->numClocks</structfield>,
7193 and the probed clocks are set in the <structfield>pScrn->clock[]</structfield>
7194 array. All of the clock values are in units of kHz.
7197 </blockquote></para></blockquote>
7201 void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from);
7204 Print out the pixel clocks <parameter>scrp->clock[]</parameter>.
7205 <parameter>from</parameter> indicates whether the clocks were probed
7206 or from the config file.
7209 </blockquote></para></blockquote>
7213 <title>Other helper functions</title>
7217 Bool xf86IsUnblank(int mode);
7220 Returns <constant>TRUE</constant> when the screen saver mode specified
7221 by <parameter>mode</parameter> requires the screen be unblanked,
7222 and <constant>FALSE</constant> otherwise. The screen saver modes that
7223 require blanking are <constant>SCREEN_SAVER_ON</constant> and
7224 <constant>SCREEN_SAVER_CYCLE</constant>, and the screen saver modes that
7225 require unblanking are <constant>SCREEN_SAVER_OFF</constant> and
7226 <constant>SCREEN_SAVER_FORCER</constant>. Drivers may call this helper
7227 from their <function>SaveScreen()</function> function to interpret the
7231 </blockquote></para></blockquote>
7236 <title>The vgahw module</title>
7239 The vgahw modules provides an interface for saving, restoring and
7240 programming the standard VGA registers, and for handling VGA colourmaps.
7244 <title>Data Structures</title>
7247 The public data structures used by the vgahw module are
7248 <structname>vgaRegRec</structname> and <structname>vgaHWRec</structname>. They are
7249 defined in <filename>vgaHW.h.</filename>
7255 <title>General vgahw Functions</title>
7259 Bool vgaHWGetHWRec(ScrnInfoPtr pScrn);
7262 This function allocates a <structname>vgaHWRec</structname> structure, and
7263 hooks it into the <structname>ScrnInfoRec</structname>'s
7264 <structfield>privates</structfield>. Like all information hooked into the
7265 <structfield>privates</structfield>, it is persistent, and only needs to be
7266 allocated once per screen. This function should normally be called
7267 from the driver's <function>ChipPreInit()</function> function. The
7268 <structname>vgaHWRec</structname> is zero-allocated, and the following
7269 fields are explicitly initialised:
7273 <term><structfield>ModeReg.DAC[]</structfield></term>
7274 <listitem><para>initialised with a default colourmap
7275 </para></listitem></varlistentry>
7277 <term><structfield>ModeReg.Attribute[0x11]</structfield></term>
7278 <listitem><para>initialised with the default overscan index
7279 </para></listitem></varlistentry>
7281 <term><structfield>ShowOverscan</structfield></term>
7282 <listitem><para>initialised according to the "ShowOverscan" option
7283 </para></listitem></varlistentry>
7285 <term><structfield>paletteEnabled</structfield></term>
7286 <listitem><para>initialised to FALSE
7287 </para></listitem></varlistentry>
7289 <term><structfield>cmapSaved</structfield></term>
7290 <listitem><para>initialised to FALSE
7291 </para></listitem></varlistentry>
7293 <term><structfield>pScrn</structfield></term>
7294 <listitem><para>initialised to pScrn
7295 </para></listitem></varlistentry>
7300 In addition to the above, <function>vgaHWSetStdFuncs()</function> is
7301 called to initialise the register access function fields with the
7302 standard VGA set of functions.
7306 Once allocated, a pointer to the <structname>vgaHWRec</structname> can be
7307 obtained from the <literal remap="tt">ScrnInfoPtr</literal> with the
7308 <literal remap="tt">VGAHWPTR(pScrn)</literal> macro.
7311 </blockquote></para></blockquote>
7315 void vgaHWFreeHWRec(ScrnInfoPtr pScrn);
7318 This function frees a <structname>vgaHWRec</structname> structure. It
7319 should be called from a driver's <function>ChipFreeScreen()</function>
7323 </blockquote></para></blockquote>
7327 Bool vgaHWSetRegCounts(ScrnInfoPtr pScrn, int numCRTC,
7328 int numSequencer, int numGraphics, int numAttribute);
7331 This function allows the number of CRTC, Sequencer, Graphics and
7332 Attribute registers to be changed. This makes it possible for
7333 extended registers to be saved and restored with
7334 <function>vgaHWSave()</function> and <function>vgaHWRestore()</function>.
7335 This function should be called after a <structname>vgaHWRec</structname>
7336 has been allocated with <function>vgaHWGetHWRec()</function>. The
7337 default values are defined in <filename>vgaHW.h</filename> as follows:
7340 #define VGA_NUM_CRTC 25
7341 #define VGA_NUM_SEQ 5
7342 #define VGA_NUM_GFX 9
7343 #define VGA_NUM_ATTR 21
7347 </blockquote></para></blockquote>
7351 Bool vgaHWCopyReg(vgaRegPtr dst, vgaRegPtr src);
7354 This function copies the contents of the VGA saved registers in
7355 <parameter>src</parameter> to <parameter>dst</parameter>. Note that it isn't
7356 possible to simply do this with <function>memcpy()</function> (or
7357 similar). This function returns <constant>TRUE</constant> unless there
7358 is a problem allocating space for the <structfield>CRTC</structfield> and
7359 related fields in <parameter>dst</parameter>.
7362 </blockquote></para></blockquote>
7366 void vgaHWSetStdFuncs(vgaHWPtr hwp);
7369 This function initialises the register access function fields of
7370 <parameter>hwp</parameter> with the standard VGA set of functions. This
7371 is called by <function>vgaHWGetHWRec()</function>, so there is usually
7372 no need to call this explicitly. The register access functions
7373 are described below. If the registers are shadowed in some other
7374 port I/O space (for example a PCI I/O region), these functions
7375 can be used to access the shadowed registers if
7376 <structfield>hwp->PIOOffset</structfield> is initialised with
7377 <literal remap="tt">offset</literal>, calculated in such a way that when the
7378 standard VGA I/O port value is added to it the correct offset into
7379 the PIO area results. This value is initialised to zero in
7380 <function>vgaHWGetHWRec()</function>. (Note: the PIOOffset functionality
7381 is present in XFree86 4.1.0 and later.)
7384 </blockquote></para></blockquote>
7388 void vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset);
7391 This function initialised the register access function fields of
7392 hwp with a generic MMIO set of functions.
7393 <structfield>hwp->MMIOBase</structfield> is initialised with
7394 <parameter>base</parameter>, which must be the virtual address that the
7395 start of MMIO area is mapped to. <structfield>hwp->MMIOOffset</structfield>
7396 is initialised with <parameter>offset</parameter>, which must be calculated
7397 in such a way that when the standard VGA I/O port value is added
7398 to it the correct offset into the MMIO area results. That means
7399 that these functions are only suitable when the VGA I/O ports are
7400 made available in a direct mapping to the MMIO space. If that is
7401 not the case, the driver will need to provide its own register
7402 access functions. The register access functions are described
7406 </blockquote></para></blockquote>
7410 Bool vgaHWMapMem(ScrnInfoPtr pScrn);
7413 This function maps the VGA memory window. It requires that the
7414 <structname>vgaHWRec</structname> be allocated. If a driver requires
7415 non-default <structfield>MapPhys</structfield> or <structfield>MapSize</structfield>
7416 settings (the physical location and size of the VGA memory window)
7417 then those fields of the <structname>vgaHWRec</structname> must be initialised
7418 before calling this function. Otherwise, this function initialiases
7419 the default values of <constant>0xA0000</constant> for
7420 <structfield>MapPhys</structfield> and <code>(64 * 1024)</code> for
7421 <structfield>MapSize</structfield>. This function must be called before
7422 attempting to save or restore the VGA state. If the driver doesn't
7423 call it explicitly, the <function>vgaHWSave()</function> and
7424 <function>vgaHWRestore()</function> functions may call it if they need
7425 to access the VGA memory (in which case they will also call
7426 <function>vgaHWUnmapMem()</function> to unmap the VGA memory before
7430 </blockquote></para></blockquote>
7434 void vgaHWUnmapMem(ScrnInfoPtr pScrn);
7437 This function unmaps the VGA memory window. It must only be called
7438 after the memory has been mapped. The <structfield>Base</structfield> field
7439 of the <structname>vgaHWRec</structname> field is set to <constant>NULL</constant>
7440 to indicate that the memory is no longer mapped.
7443 </blockquote></para></blockquote>
7447 void vgaHWGetIOBase(vgaHWPtr hwp);
7450 This function initialises the <structfield>IOBase</structfield> field of the
7451 <structname>vgaHWRec</structname>. This function must be called before
7452 using any other functions that access the video hardware.
7456 A macro <function>VGAHW_GET_IOBASE()</function> is also available in
7457 <filename>vgaHW.h</filename> that returns the I/O base, and this may
7458 be used when the vgahw module is not loaded (for example, in the
7459 <function>ChipProbe()</function> function).
7462 </blockquote></para></blockquote>
7466 void vgaHWUnlock(vgaHWPtr hwp);
7469 This function unlocks the VGA <literal remap="tt">CRTC[0-7]</literal> registers,
7470 and must be called before attempting to write to those registers.
7473 </blockquote></para></blockquote>
7477 void vgaHWLock(vgaHWPtr hwp);
7480 This function locks the VGA <literal remap="tt">CRTC[0-7]</literal> registers.
7483 </blockquote></para></blockquote>
7487 void vgaHWEnable(vgaHWPtr hwp);
7490 This function enables the VGA subsystem. (Note, this function is
7491 present in XFree86 4.1.0 and later.).
7494 </blockquote></para></blockquote>
7498 void vgaHWDisable(vgaHWPtr hwp);
7501 This function disables the VGA subsystem. (Note, this function is
7502 present in XFree86 4.1.0 and later.).
7505 </blockquote></para></blockquote>
7509 void vgaHWSave(ScrnInfoPtr pScrn, vgaRegPtr save, int flags);
7512 This function saves the VGA state. The state is written to the
7513 <structname>vgaRegRec</structname> pointed to by <parameter>save</parameter>.
7514 <parameter>flags</parameter> is set to one or more of the following flags
7519 <term><constant>VGA_SR_MODE</constant></term>
7520 <listitem><para>the mode setting registers are saved
7521 </para></listitem></varlistentry>
7523 <term><constant>VGA_SR_FONTS</constant></term>
7524 <listitem><para>the text mode font/text data is saved
7525 </para></listitem></varlistentry>
7527 <term><constant>VGA_SR_CMAP</constant></term>
7528 <listitem><para>the colourmap (LUT) is saved
7529 </para></listitem></varlistentry>
7531 <term><constant>VGA_SR_ALL</constant></term>
7532 <listitem><para>all of the above are saved
7533 </para></listitem></varlistentry>
7538 The <structname>vgaHWRec</structname> and its <structfield>IOBase</structfield> fields
7539 must be initialised before this function is called. If
7540 <constant>VGA_SR_FONTS</constant> is set in <parameter>flags</parameter>, the
7541 VGA memory window must be mapped. If it isn't then
7542 <function>vgaHWMapMem()</function> will be called to map it, and
7543 <function>vgaHWUnmapMem()</function> will be called to unmap it
7544 afterwards. <function>vgaHWSave()</function> uses the three functions
7545 below in the order <function>vgaHWSaveColormap()</function>,
7546 <function>vgaHWSaveMode()</function>, <function>vgaHWSaveFonts()</function> to
7547 carry out the different save phases. It is undecided at this
7548 stage whether they will remain part of the vgahw module's public
7552 </blockquote></para></blockquote>
7556 void vgaHWSaveMode(ScrnInfoPtr pScrn, vgaRegPtr save);
7559 This function saves the VGA mode registers. They are saved to
7560 the <structname>vgaRegRec</structname> pointed to by <parameter>save</parameter>.
7561 The registers saved are:
7573 The number of registers actually saved may be modified by a prior call
7574 to <function>vgaHWSetRegCounts()</function>.
7577 </blockquote></para></blockquote>
7581 void vgaHWSaveFonts(ScrnInfoPtr pScrn, vgaRegPtr save);
7584 This function saves the text mode font and text data held in the
7585 video memory. If called while in a graphics mode, no save is
7586 done. The VGA memory window must be mapped with
7587 <function>vgaHWMapMem()</function> before to calling this function.
7591 On some platforms, one or more of the font/text plane saves may be
7592 no-ops. This is the case when the platform's VC driver already
7596 </blockquote></para></blockquote>
7600 void vgaHWSaveColormap(ScrnInfoPtr pScrn, vgaRegPtr save);
7603 This function saves the VGA colourmap (LUT). Before saving it, it
7604 attempts to verify that the colourmap is readable. In rare cases
7605 where it isn't readable, a default colourmap is saved instead.
7608 </blockquote></para></blockquote>
7612 void vgaHWRestore(ScrnInfoPtr pScrn, vgaRegPtr restore, int flags);
7615 This function programs the VGA state. The state programmed is
7616 that contained in the <structname>vgaRegRec</structname> pointed to by
7617 <parameter>restore</parameter>. <parameter>flags</parameter> is the same
7618 as described above for the <function>vgaHWSave()</function> function.
7622 The <structname>vgaHWRec</structname> and its <structfield>IOBase</structfield> fields
7623 must be initialised before this function is called. If
7624 <constant>VGA_SR_FONTS</constant> is set in <parameter>flags</parameter>, the
7625 VGA memory window must be mapped. If it isn't then
7626 <function>vgaHWMapMem()</function> will be called to map it, and
7627 <function>vgaHWUnmapMem()</function> will be called to unmap it
7628 afterwards. <function>vgaHWRestore()</function> uses the three functions
7629 below in the order <function>vgaHWRestoreFonts()</function>,
7630 <function>vgaHWRestoreMode()</function>,
7631 <function>vgaHWRestoreColormap()</function> to carry out the different
7632 restore phases. It is undecided at this stage whether they will
7633 remain part of the vgahw module's public interface or not.
7636 </blockquote></para></blockquote>
7640 void vgaHWRestoreMode(ScrnInfoPtr pScrn, vgaRegPtr restore);
7643 This function restores the VGA mode registers. They are restored
7644 from the data in the <structname>vgaRegRec</structname> pointed to by
7645 <parameter>restore</parameter>. The registers restored are:
7657 The number of registers actually restored may be modified by a prior call
7658 to <function>vgaHWSetRegCounts()</function>.
7661 </blockquote></para></blockquote>
7665 void vgaHWRestoreFonts(ScrnInfoPtr pScrn, vgaRegPtr restore);
7668 This function restores the text mode font and text data to the
7669 video memory. The VGA memory window must be mapped with
7670 <function>vgaHWMapMem()</function> before to calling this function.
7674 On some platforms, one or more of the font/text plane restores
7675 may be no-ops. This is the case when the platform's VC driver
7676 already takes care of this.
7679 </blockquote></para></blockquote>
7683 void vgaHWRestoreColormap(ScrnInfoPtr pScrn, vgaRegPtr restore);
7686 This function restores the VGA colourmap (LUT).
7689 </blockquote></para></blockquote>
7693 void vgaHWInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
7696 This function fills in the <structname>vgaHWRec</structname>'s
7697 <structfield>ModeReg</structfield> field with the values appropriate for
7698 programming the given video mode. It requires that the
7699 <structname>ScrnInfoRec</structname>'s <structfield>depth</structfield> field is
7700 initialised, which determines how the registers are programmed.
7703 </blockquote></para></blockquote>
7707 void vgaHWSeqReset(vgaHWPtr hwp, Bool start);
7710 Do a VGA sequencer reset. If start is <constant>TRUE</constant>, the
7711 reset is started. If start is <constant>FALSE</constant>, the reset
7715 </blockquote></para></blockquote>
7719 void vgaHWProtect(ScrnInfoPtr pScrn, Bool on);
7722 This function protects VGA registers and memory from corruption
7723 during loads. It is typically called with on set to
7724 <constant>TRUE</constant> before programming, and with on set to
7725 <constant>FALSE</constant> after programming.
7728 </blockquote></para></blockquote>
7732 Bool vgaHWSaveScreen(ScreenPtr pScreen, int mode);
7735 This function blanks and unblanks the screen. It is blanked when
7736 <parameter>mode</parameter> is <constant>SCREEN_SAVER_ON</constant> or
7737 <constant>SCREEN_SAVER_CYCLE</constant>, and unblanked when
7738 <parameter>mode</parameter> is <constant>SCREEN_SAVER_OFF</constant> or
7739 <constant>SCREEN_SAVER_FORCER</constant>.
7742 </blockquote></para></blockquote>
7746 void vgaHWBlankScreen(ScrnInfoPtr pScrn, Bool on);
7749 This function blanks and unblanks the screen. It is blanked when
7750 <parameter>on</parameter> is <constant>FALSE</constant>, and unblanked when
7751 <parameter>on</parameter> is <constant>TRUE</constant>. This function is
7752 provided for use in cases where the <structname>ScrnInfoRec</structname>
7753 can't be derived from the <structname>ScreenRec</structname> (while probing
7754 for clocks, for example).
7757 </blockquote></para></blockquote>
7762 <title>VGA Colormap Functions</title>
7765 The vgahw module uses the standard colormap support (see the
7766 <link linkend="cmap">Colormap Handling</link> section. This is initialised
7767 with the following function:
7771 Bool vgaHWHandleColormaps(ScreenPtr pScreen);
7773 </para></blockquote>
7779 <title>VGA Register Access Functions</title>
7782 The vgahw module abstracts access to the standard VGA registers by
7783 using a set of functions held in the <structname>vgaHWRec</structname>. When
7784 the <structname>vgaHWRec</structname> is created these function pointers are
7785 initialised with the set of standard VGA I/O register access functions.
7786 In addition to these, the vgahw module includes a basic set of MMIO
7787 register access functions, and the <structname>vgaHWRec</structname> function
7788 pointers can be initialised to these by calling the
7789 <function>vgaHWSetMmioFuncs()</function> function described above. Some
7790 drivers/platforms may require a different set of functions for VGA
7791 access. The access functions are described here.
7797 void writeCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value);
7800 Write <parameter>value</parameter> to CRTC register <parameter>index</parameter>.
7803 </blockquote></para></blockquote>
7807 CARD8 readCrtc(vgaHWPtr hwp, CARD8 index);
7810 Return the value read from CRTC register <parameter>index</parameter>.
7813 </blockquote></para></blockquote>
7817 void writeGr(vgaHWPtr hwp, CARD8 index, CARD8 value);
7820 Write <parameter>value</parameter> to Graphics Controller register
7821 <parameter>index</parameter>.
7824 </blockquote></para></blockquote>
7828 CARD8 readGR(vgaHWPtr hwp, CARD8 index);
7831 Return the value read from Graphics Controller register
7832 <parameter>index</parameter>.
7835 </blockquote></para></blockquote>
7839 void writeSeq(vgaHWPtr hwp, CARD8 index, CARD8, value);
7842 Write <parameter>value</parameter> to Sequencer register
7843 <parameter>index</parameter>.
7846 </blockquote></para></blockquote>
7850 CARD8 readSeq(vgaHWPtr hwp, CARD8 index);
7853 Return the value read from Sequencer register <parameter>index</parameter>.
7856 </blockquote></para></blockquote>
7860 void writeAttr(vgaHWPtr hwp, CARD8 index, CARD8, value);
7863 Write <parameter>value</parameter> to Attribute Controller register
7864 <parameter>index</parameter>. When writing out the index value this
7865 function should set bit 5 (<constant>0x20</constant>) according to the
7866 setting of <structfield>hwp->paletteEnabled</structfield> in order to
7867 preserve the palette access state. It should be cleared when
7868 <structfield>hwp->paletteEnabled</structfield> is <constant>TRUE</constant>
7869 and set when it is <constant>FALSE</constant>.
7872 </blockquote></para></blockquote>
7876 CARD8 readAttr(vgaHWPtr hwp, CARD8 index);
7879 Return the value read from Attribute Controller register
7880 <parameter>index</parameter>. When writing out the index value this
7881 function should set bit 5 (<constant>0x20</constant>) according to the
7882 setting of <structfield>hwp->paletteEnabled</structfield> in order to
7883 preserve the palette access state. It should be cleared when
7884 <structfield>hwp->paletteEnabled</structfield> is <constant>TRUE</constant>
7885 and set when it is <constant>FALSE</constant>.
7888 </blockquote></para></blockquote>
7892 void writeMiscOut(vgaHWPtr hwp, CARD8 value);
7895 Write <quote><parameter>value</parameter></quote> to the Miscellaneous Output register.
7898 </blockquote></para></blockquote>
7902 CARD8 readMiscOut(vgwHWPtr hwp);
7905 Return the value read from the Miscellaneous Output register.
7908 </blockquote></para></blockquote>
7912 void enablePalette(vgaHWPtr hwp);
7915 Clear the palette address source bit in the Attribute Controller
7916 index register and set <literal remap="tt">hwp->paletteEnabled</literal> to
7917 <constant>TRUE</constant>.
7920 </blockquote></para></blockquote>
7924 void disablePalette(vgaHWPtr hwp);
7927 Set the palette address source bit in the Attribute Controller
7928 index register and set <literal remap="tt">hwp->paletteEnabled</literal> to
7929 <constant>FALSE</constant>.
7932 </blockquote></para></blockquote>
7936 void writeDacMask(vgaHWPtr hwp, CARD8 value);
7939 Write <parameter>value</parameter> to the DAC Mask register.
7942 </blockquote></para></blockquote>
7946 CARD8 readDacMask(vgaHWptr hwp);
7949 Return the value read from the DAC Mask register.
7952 </blockquote></para></blockquote>
7956 void writeDacReadAddress(vgaHWPtr hwp, CARD8 value);
7959 Write <parameter>value</parameter> to the DAC Read Address register.
7962 </blockquote></para></blockquote>
7966 void writeDacWriteAddress(vgaHWPtr hwp, CARD8 value);
7969 Write <parameter>value</parameter> to the DAC Write Address register.
7972 </blockquote></para></blockquote>
7976 void writeDacData(vgaHWPtr hwp, CARD8 value);
7979 Write <parameter>value</parameter> to the DAC Data register.
7982 </blockquote></para></blockquote>
7986 CARD8 readDacData(vgaHWptr hwp);
7989 Return the value read from the DAC Data register.
7992 </blockquote></para></blockquote>
7996 CARD8 readEnable(vgaHWptr hwp);
7999 Return the value read from the VGA Enable register. (Note: This
8000 function is present in XFree86 4.1.0 and later.)
8003 </blockquote></para></blockquote>
8007 void writeEnable(vgaHWPtr hwp, CARD8 value);
8010 Write <parameter>value</parameter> to the VGA Enable register. (Note: This
8011 function is present in XFree86 4.1.0 and later.)
8014 </blockquote></para></blockquote>
8019 <title>Some notes about writing a driver</title>
8021 <note><para>NOTE: some parts of this are not up to date</para></note>
8024 The following is an outline for writing a basic unaccelerated driver
8025 for a PCI video card with a linear mapped framebuffer, and which has a
8026 VGA core. It is includes some general information that is relevant to
8027 most drivers (even those which don't fit that basic description).
8031 The information here is based on the initial conversion of the Matrox
8032 Millennium driver to the <quote>new design</quote>. For a fleshing out and sample
8033 implementation of some of the bits outlined here, refer to that driver.
8034 Note that this is an example only. The approach used here will not be
8035 appropriate for all drivers.
8039 Each driver must reserve a unique driver name, and a string that is used
8040 to prefix all of its externally visible symbols. This is to avoid name
8041 space clashes when loading multiple drivers. The examples here are for
8042 the <quote>ZZZ</quote> driver, which uses the <quote>ZZZ</quote> or <quote>zzz</quote> prefix for its externally
8047 <title>Include files</title>
8050 All drivers normally include the following headers:
8051 <literallayout><filename>
8056 </filename></literallayout>
8057 Wherever inb/outb (and related things) are used the following should be
8059 <literallayout><filename>
8061 </filename></literallayout>
8062 Note: in drivers, this must be included after <filename>"xf86_ansic.h"</filename>.
8066 Drivers that need to access PCI vendor/device definitions need this:
8067 <literallayout><filename>
8069 </filename></literallayout>
8073 Drivers that need to access the PCI config space need this:
8074 <literallayout><filename>
8076 </filename></literallayout>
8080 Drivers using the mi banking wrapper need:
8082 <literallayout><filename>
8084 </filename></literallayout>
8088 Drivers that initialise a SW cursor need this:
8089 <literallayout><filename>
8091 </filename></literallayout>
8095 All drivers implementing backing store need this:
8096 <literallayout><filename>
8098 </filename></literallayout>
8102 All drivers using the mi colourmap code need this:
8103 <literallayout><filename>
8105 </filename></literallayout>
8109 If a driver uses the vgahw module, it needs this:
8110 <literallayout><filename>
8112 </filename></literallayout>
8116 Drivers supporting VGA or Hercules monochrome screens need:
8117 <literallayout><filename>
8119 </filename></literallayout>
8123 Drivers supporting VGA or EGC 16-colour screens need:
8124 <literallayout><filename>
8126 </filename></literallayout>
8130 Drivers using cfb need:
8139 Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
8140 <literallayout><filename>
8144 </filename></literallayout>
8148 The driver's own header file:
8149 <literallayout><filename>
8151 </filename></literallayout>
8155 Drivers must NOT include the following:
8157 <literallayout><filename>
8170 <title>Data structures and initialisation</title>
8174 <para>The following macros should be defined:
8176 #define VERSION <version-as-an-int>
8177 #define ZZZ_NAME "ZZZ" /* the name used to prefix messages */
8178 #define ZZZ_DRIVER_NAME "zzz" /* the driver name as used in config file */
8179 #define ZZZ_MAJOR_VERSION <int>
8180 #define ZZZ_MINOR_VERSION <int>
8181 #define ZZZ_PATCHLEVEL <int>
8185 NOTE: <constant>ZZZ_DRIVER_NAME</constant> should match the name of the
8186 driver module without things like the "lib" prefix, the "_drv" suffix
8187 or filename extensions.
8193 A DriverRec must be defined, which includes the functions required
8194 at the pre-probe phase. The name of this DriverRec must be an
8195 upper-case version of ZZZ_DRIVER_NAME (for the purposes of static
8203 ZZZAvailableOptions,
8212 <para>Define list of supported chips and their matching ID:
8214 static SymTabRec ZZZChipsets[] = {
8215 { PCI_CHIP_ZZZ1234, "zzz1234a" },
8216 { PCI_CHIP_ZZZ5678, "zzz5678a" },
8222 The token field may be any integer value that the driver may use to
8223 uniquely identify the supported chipsets. For drivers that support
8224 only PCI devices using the PCI device IDs might be a natural choice,
8225 but this isn't mandatory. For drivers that support both PCI and other
8226 devices (like ISA), some other ID should probably used. When other
8227 IDs are used as the tokens it is recommended that the names be
8228 defined as an <type>enum</type> type.
8234 If the driver uses the <function>xf86MatchPciInstances()</function>
8235 helper (recommended for drivers that support PCI cards) a list that
8236 maps PCI IDs to chip IDs and fixed resources must be defined:
8238 static PciChipsets ZZZPciChipsets[] = {
8239 { PCI_CHIP_ZZZ1234, PCI_CHIP_ZZZ1234, RES_SHARED_VGA },
8240 { PCI_CHIP_ZZZ5678, PCI_CHIP_ZZZ5678, RES_SHARED_VGA },
8241 { -1, -1, RES_UNDEFINED }
8249 Define the <structname>XF86ModuleVersionInfo</structname> struct for the
8250 driver. This is required for the dynamically loaded version:
8252 static XF86ModuleVersionInfo zzzVersRec =
8258 XF86_VERSION_CURRENT,
8259 ZZZ_MAJOR_VERSION, ZZZ_MINOR_VERSION, ZZZ_PATCHLEVEL,
8261 ABI_VIDEODRV_VERSION,
8271 Define a data structure to hold the driver's screen-specific data.
8272 This must be used instead of global variables. This would be defined
8273 in the <filename>"zzz.h"</filename> file, something like:
8282 CloseScreenProcPtr CloseScreen;
8283 OptionInfoPtr Options;
8292 Define the list of config file Options that the driver accepts. For
8293 consistency between drivers those in the list of <quote>standard</quote> options
8294 should be used where appropriate before inventing new options.
8304 static const OptionInfoRec ZZZOptions[] = {
8305 { OPTION_FOO_HACK, "FooHack", OPTV_INTEGER, {0}, FALSE },
8306 { OPTION_PCI_RETRY, "PciRetry", OPTV_BOOLEAN, {0}, FALSE },
8307 { OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, FALSE },
8308 { OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE },
8309 { -1, NULL, OPTV_NONE, {0}, FALSE }
8318 <title>Functions</title>
8322 <title>SetupProc</title>
8325 For dynamically loaded modules, a <varname>ModuleData</varname>
8326 variable is required. It is should be the name of the driver
8327 prepended to "ModuleData". A <function>Setup()</function> function is
8328 also required, which calls <function>xf86AddDriver()</function> to add
8329 the driver to the main list of drivers.
8333 static MODULESETUPPROTO(zzzSetup);
8335 XF86ModuleData zzzModuleData = { &zzzVersRec, zzzSetup, NULL };
8338 zzzSetup(pointer module, pointer opts, int *errmaj, int *errmin)
8340 static Bool setupDone = FALSE;
8342 /* This module should be loaded only once, but check to be sure. */
8346 * Modules that this driver always requires may be loaded
8347 * here by calling LoadSubModule().
8351 xf86AddDriver(&MGA, module, 0);
8354 * The return value must be non-NULL on success even though
8355 * there is no TearDownProc.
8359 if (errmaj) *errmaj = LDR_ONCEONLY;
8367 <title>GetRec, FreeRec</title>
8370 A function is usually required to allocate the driver's
8371 screen-specific data structure and hook it into the
8372 <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> field.
8373 The <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> is
8374 initialised to <constant>NULL</constant>, so it is easy to check if the
8375 initialisation has already been done. After allocating it, initialise
8376 the fields. By using <function>xnfcalloc()</function> to do the allocation
8377 it is zeroed, and if the allocation fails the server exits.
8382 When allocating structures from inside the driver which are defined
8383 on the common level it is important to initialize the structure to
8385 Only this guarantees that the server remains source compatible to
8386 future changes in common level structures.
8391 ZZZGetRec(ScrnInfoPtr pScrn)
8393 if (pScrn->driverPrivate != NULL)
8395 pScrn->driverPrivate = xnfcalloc(sizeof(ZZZRec), 1);
8396 /* Initialise as required */
8403 Define a macro in <filename>"zzz.h"</filename> which gets a pointer to
8404 the <structname>ZZZRec</structname> when given <parameter>pScrn</parameter>:
8407 #define ZZZPTR(p) ((ZZZPtr)((p)->driverPrivate))
8412 Define a function to free the above, setting it to <constant>NULL</constant>
8413 once it has been freed:
8417 ZZZFreeRec(ScrnInfoPtr pScrn)
8419 if (pScrn->driverPrivate == NULL)
8421 xfree(pScrn->driverPrivate);
8422 pScrn->driverPrivate = NULL;
8429 <title>Identify</title>
8432 Define the <function>Identify()</function> function. It is run before
8433 the Probe, and typically prints out an identifying message, which
8434 might include the chipsets it supports. This function is mandatory:
8438 ZZZIdentify(int flags)
8440 xf86PrintChipsets(ZZZ_NAME, "driver for ZZZ Tech chipsets",
8448 <title>Probe</title>
8451 Define the <function>Probe()</function> function. The purpose of this
8452 is to find all instances of the hardware that the driver supports,
8453 and for the ones not already claimed by another driver, claim the
8454 slot, and allocate a <structname>ScrnInfoRec</structname>. This should be
8455 a minimal probe, and it should under no circumstances leave the
8456 state of the hardware changed. Because a device is found, don't
8457 assume that it will be used. Don't do any initialisations other
8458 than the required <structname>ScrnInfoRec</structname> initialisations.
8459 Don't allocate any new data structures.
8463 This function is mandatory.
8467 NOTE: The <function>xf86DrvMsg()</function> functions cannot be used from
8473 ZZZProbe(DriverPtr drv, int flags)
8475 Bool foundScreen = FALSE;
8476 int numDevSections, numUsed;
8477 GDevPtr *devSections;
8482 * Find the config file Device sections that match this
8483 * driver, and return if there are none.
8485 if ((numDevSections = xf86MatchDevice(ZZZ_DRIVER_NAME,
8486 &devSections)) <= 0) {
8491 * Since this is a PCI card, "probing" just amounts to checking
8492 * the PCI data that the server has already collected. If there
8495 * Although the config file is allowed to override things, it
8496 * is reasonable to not allow it to override the detection
8497 * of no PCI video cards.
8499 * The provided xf86MatchPciInstances() helper takes care of
8502 /* test if PCI bus present */
8503 if (xf86GetPciVideoInfo()) {
8505 numUsed = xf86MatchPciInstances(ZZZ_NAME, PCI_VENDOR_ZZZ,
8506 ZZZChipsets, ZZZPciChipsets, devSections,
8507 numDevSections, drv, &usedChips);
8509 for (i = 0; i < numUsed; i++) {
8510 ScrnInfoPtr pScrn = NULL;
8511 if ((pScrn = xf86ConfigPciEntity(pScrn, flags, usedChips[i],
8512 ZZZPciChipsets, NULL, NULL,
8513 NULL, NULL, NULL))) {
8514 /* Allocate a ScrnInfoRec */
8515 pScrn->driverVersion = VERSION;
8516 pScrn->driverName = ZZZ_DRIVER_NAME;
8517 pScrn->name = ZZZ_NAME;
8518 pScrn->Probe = ZZZProbe;
8519 pScrn->PreInit = ZZZPreInit;
8520 pScrn->ScreenInit = ZZZScreenInit;
8521 pScrn->SwitchMode = ZZZSwitchMode;
8522 pScrn->AdjustFrame = ZZZAdjustFrame;
8523 pScrn->EnterVT = ZZZEnterVT;
8524 pScrn->LeaveVT = ZZZLeaveVT;
8525 pScrn->FreeScreen = ZZZFreeScreen;
8526 pScrn->ValidMode = ZZZValidMode;
8528 /* add screen to entity */
8536 * If the driver supports ISA hardware, the following block
8537 * can be included too.
8539 numUsed = xf86MatchIsaInstances(ZZZ_NAME, ZZZChipsets,
8540 ZZZIsaChipsets, drv, ZZZFindIsaDevice,
8541 devSections, numDevSections, &usedChips);
8542 for (i = 0; i < numUsed; i++) {
8543 ScrnInfoPtr pScrn = NULL;
8544 if ((pScrn = xf86ConfigIsaEntity(pScrn, flags, usedChips[i],
8545 ZZZIsaChipsets, NULL, NULL, NULL,
8547 pScrn->driverVersion = VERSION;
8548 pScrn->driverName = ZZZ_DRIVER_NAME;
8549 pScrn->name = ZZZ_NAME;
8550 pScrn->Probe = ZZZProbe;
8551 pScrn->PreInit = ZZZPreInit;
8552 pScrn->ScreenInit = ZZZScreenInit;
8553 pScrn->SwitchMode = ZZZSwitchMode;
8554 pScrn->AdjustFrame = ZZZAdjustFrame;
8555 pScrn->EnterVT = ZZZEnterVT;
8556 pScrn->LeaveVT = ZZZLeaveVT;
8557 pScrn->FreeScreen = ZZZFreeScreen;
8558 pScrn->ValidMode = ZZZValidMode;
8563 #endif /* HAS_ISA_DEVS */
8571 <title>AvailableOptions</title>
8574 Define the <function>AvailableOptions()</function> function. The purpose
8575 of this is to return the available driver options back to the
8576 -configure option, so that an xorg.conf file can be built and the
8577 user can see which options are available for them to use.
8582 <title>PreInit</title>
8585 Define the <function>PreInit()</function> function. The purpose of
8586 this is to find all the information required to determine if the
8587 configuration is usable, and to initialise those parts of the
8588 <structname>ScrnInfoRec</structname> that can be set once at the beginning
8589 of the first server generation. The information should be found in
8590 the least intrusive way possible.
8594 This function is mandatory.
8601 The <function>PreInit()</function> function is only called once
8602 during the life of the X server (at the start of the first
8607 Data allocated here must be of the type that persists for
8608 the life of the X server. This means that data that hooks into
8609 the <structname>ScrnInfoRec</structname>'s <structfield>privates</structfield>
8610 field should be allocated here, but data that hooks into the
8611 <structname>ScreenRec</structname>'s <structfield>devPrivates</structfield> field
8612 should not be allocated here. The <structfield>driverPrivate</structfield>
8613 field should also be allocated here.
8617 Although the <structname>ScrnInfoRec</structname> has been allocated
8618 before this function is called, the <structname>ScreenRec</structname>
8619 has not been allocated. That means that things requiring it
8620 cannot be used in this function.
8624 Very little of the <structname>ScrnInfoRec</structname> has been
8625 initialised when this function is called. It is important to
8626 get the order of doing things right in this function.
8634 ZZZPreInit(ScrnInfoPtr pScrn, int flags)
8636 /* Fill in the monitor field */
8637 pScrn->monitor = pScrn->confScreen->monitor;
8640 * If using the vgahw module, it will typically be loaded
8641 * here by calling xf86LoadSubModule(pScrn, "vgahw");
8645 * Set the depth/bpp. Use the globally preferred depth/bpp. If the
8646 * driver has special default depth/bpp requirements, the defaults should
8647 * be specified here explicitly.
8648 * We support both 24bpp and 32bpp framebuffer layouts.
8649 * This sets pScrn->display also.
8651 if (!xf86SetDepthBpp(pScrn, 0, 0, 0,
8652 Support24bppFb | Support32bppFb)) {
8655 if (depth/bpp isn't one we support) {
8656 print error message;
8660 /* Print out the depth/bpp that was set */
8661 xf86PrintDepthBpp(pScrn);
8663 /* Set bits per RGB for 8bpp */
8664 if (pScrn->depth <= 8) {
8665 /* Take into account a dac_6_bit option here */
8666 pScrn->rgbBits = 6 or 8;
8670 * xf86SetWeight() and xf86SetDefaultVisual() must be called
8671 * after pScrn->display is initialised.
8674 /* Set weight/mask/offset for depth > 8 */
8675 if (pScrn->depth > 8) {
8676 if (!xf86SetWeight(pScrn, defaultWeight, defaultMask)) {
8679 if (weight isn't one we support) {
8680 print error message;
8686 /* Set the default visual. */
8687 if (!xf86SetDefaultVisual(pScrn, -1)) {
8690 if (visual isn't one we support) {
8691 print error message;
8696 /* If the driver supports gamma correction, set the gamma. */
8697 if (!xf86SetGamma(pScrn, default_gamma)) {
8701 /* This driver uses a programmable clock */
8702 pScrn->progClock = TRUE;
8704 /* Allocate the ZZZRec driverPrivate */
8705 if (!ZZZGetRec(pScrn)) {
8709 pZzz = ZZZPTR(pScrn);
8711 /* Collect all of the option flags (fill in pScrn->options) */
8712 xf86CollectOptions(pScrn, NULL);
8715 * Process the options based on the information in ZZZOptions.
8716 * The results are written to pZzz->Options. If all of the options
8717 * processing is done within this function a local variable "options"
8718 * can be used instead of pZzz->Options.
8720 if (!(pZzz->Options = xalloc(sizeof(ZZZOptions))))
8722 (void)memcpy(pZzz->Options, ZZZOptions, sizeof(ZZZOptions));
8723 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pZzz->Options);
8726 * Set various fields of ScrnInfoRec and/or ZZZRec based on
8727 * the options found.
8730 pZzz->hwCursor = FALSE;
8731 if (xf86IsOptionSet(pZzz->Options, OPTION_HW_CURSOR)) {
8733 pZzz->hwCursor = TRUE;
8735 xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
8736 pZzz->hwCursor ? "HW" : "SW");
8737 if (xf86IsOptionSet(pZzz->Options, OPTION_NOACCEL)) {
8738 pZzz->noAccel = TRUE;
8739 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
8740 "Acceleration disabled\n");
8742 pZzz->noAccel = FALSE;
8744 if (xf86IsOptionSet(pZzz->Options, OPTION_PCI_RETRY)) {
8745 pZzz->UsePCIRetry = TRUE;
8746 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "PCI retry enabled\n");
8748 pZzz->fooHack = 0;
8749 if (xf86GetOptValInteger(pZzz->Options, OPTION_FOO_HACK,
8750 &pZzz->fooHack)) {
8751 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Foo Hack set to %d\n",
8756 * Find the PCI slot(s) that this screen claimed in the probe.
8757 * In this case, exactly one is expected, so complain otherwise.
8758 * Note in this case we're not interested in the card types so
8759 * that parameter is set to NULL.
8761 if ((i = xf86GetPciInfoForScreen(pScrn->scrnIndex, &pciList, NULL))
8763 print error message;
8769 /* Note that pciList should be freed below when no longer needed */
8772 * Determine the chipset, allowing config file chipset and
8773 * chipid values to override the probed information. The config
8774 * chipset value has precedence over its chipid value if both
8777 * It isn't necessary to fill in pScrn->chipset if the driver
8778 * keeps track of the chipset in its ZZZRec.
8784 * Determine video memory, fb base address, I/O addresses, etc,
8785 * allowing the config file to override probed values.
8787 * Set the appropriate pScrn fields (videoRam is probably the
8788 * most important one that other code might require), and
8789 * print out the settings.
8794 /* Initialise a clockRanges list. */
8798 /* Set any other chipset specific things in the ZZZRec */
8802 /* Select valid modes from those available */
8804 i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
8805 pScrn->display->modes, clockRanges,
8806 NULL, minPitch, maxPitch, rounding,
8807 minHeight, maxHeight,
8808 pScrn->display->virtualX,
8809 pScrn->display->virtualY,
8810 pScrn->videoRam * 1024,
8811 LOOKUP_BEST_REFRESH);
8817 /* Prune the modes marked as invalid */
8819 xf86PruneDriverModes(pScrn);
8821 /* If no valid modes, return */
8823 if (i == 0 || pScrn->modes == NULL) {
8824 print error message;
8830 * Initialise the CRTC fields for the modes. This driver expects
8831 * vertical values to be halved for interlaced modes.
8833 xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V);
8835 /* Set the current mode to the first in the list. */
8836 pScrn->currentMode = pScrn->modes;
8838 /* Print the list of modes being used. */
8839 xf86PrintModes(pScrn);
8842 xf86SetDpi(pScrn, 0, 0);
8844 /* Load bpp-specific modules */
8845 switch (pScrn->bitsPerPixel) {
8865 if (mod && !xf86LoadSubModule(pScrn, mod))
8877 <title>MapMem, UnmapMem</title>
8880 Define functions to map and unmap the video memory and any other
8881 memory apertures required. These functions are not mandatory, but
8882 it is often useful to have such functions.
8887 ZZZMapMem(ScrnInfoPtr pScrn)
8889 /* Call xf86MapPciMem() to map each PCI memory area */
8891 return TRUE or FALSE;
8895 ZZZUnmapMem(ScrnInfoPtr pScrn)
8897 /* Call xf86UnMapVidMem() to unmap each memory area */
8899 return TRUE or FALSE;
8905 <title>Save, Restore</title>
8908 Define functions to save and restore the original video state. These
8909 functions are not mandatory, but are often useful.
8914 ZZZSave(ScrnInfoPtr pScrn)
8917 * Save state into per-screen data structures.
8918 * If using the vgahw module, vgaHWSave will typically be
8925 ZZZRestore(ScrnInfoPtr pScrn)
8928 * Restore state from per-screen data structures.
8929 * If using the vgahw module, vgaHWRestore will typically be
8938 <title>ModeInit</title>
8941 Define a function to initialise a new video mode. This function isn't
8942 mandatory, but is often useful.
8947 ZZZModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
8950 * Program a video mode. If using the vgahw module,
8951 * vgaHWInit and vgaRestore will typically be called here.
8952 * Once up to the point where there can't be a failure
8953 * set pScrn->vtSema to TRUE.
8961 <title>ScreenInit</title>
8964 Define the <function>ScreenInit()</function> function. This is called
8965 at the start of each server generation, and should fill in as much
8966 of the <structname>ScreenRec</structname> as possible as well as any other
8967 data that is initialised once per generation. It should initialise
8968 the framebuffer layers it is using, and initialise the initial video
8973 This function is mandatory.
8977 NOTE: The <structname>ScreenRec</structname> (<parameter>pScreen</parameter>) is
8978 passed to this driver, but it and the
8979 <varname>ScrnInfoRecs</varname> are not yet hooked into each
8980 other. This means that in this function, and functions it
8981 calls, one cannot be found from the other.
8986 ZZZScreenInit(ScreenPtr pScreen, int argc, char **argv)
8988 /* Get the ScrnInfoRec */
8989 pScrn = xf86ScreenToScrn(pScreen);
8992 * If using the vgahw module, its data structures and related
8993 * things are typically initialised/mapped here.
8996 /* Save the current video state */
8999 /* Initialise the first mode */
9000 ZZZModeInit(pScrn, pScrn->currentMode);
9002 /* Set the viewport if supported */
9004 ZZZAdjustFrame(pScrn, pScrn->frameX0, pScrn->frameY0);
9007 * Setup the screen's visuals, and initialise the framebuffer
9011 /* Reset the visual list */
9012 miClearVisualTypes();
9015 * Setup the visuals supported. This driver only supports
9016 * TrueColor for bpp > 8, so the default set of visuals isn't
9017 * acceptable. To deal with this, call miSetVisualTypes with
9018 * the appropriate visual mask.
9021 if (pScrn->bitsPerPixel > 8) {
9022 if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
9023 pScrn->rgbBits, pScrn->defaultVisual))
9026 if (!miSetVisualTypes(pScrn->depth,
9027 miGetDefaultVisualMask(pScrn->depth),
9028 pScrn->rgbBits, pScrn->defaultVisual))
9033 * Initialise the framebuffer.
9036 switch (pScrn->bitsPerPixel) {
9038 ret = xf1bppScreenInit(pScreen, FbBase,
9039 pScrn->virtualX, pScrn->virtualY,
9040 pScrn->xDpi, pScrn->yDpi,
9041 pScrn->displayWidth);
9044 ret = xf4bppScreenInit(pScreen, FbBase,
9045 pScrn->virtualX, pScrn->virtualY,
9046 pScrn->xDpi, pScrn->yDpi,
9047 pScrn->displayWidth);
9050 ret = cfbScreenInit(pScreen, FbBase,
9051 pScrn->virtualX, pScrn->virtualY,
9052 pScrn->xDpi, pScrn->yDpi,
9053 pScrn->displayWidth);
9056 ret = cfb16ScreenInit(pScreen, FbBase,
9057 pScrn->virtualX, pScrn->virtualY,
9058 pScrn->xDpi, pScrn->yDpi,
9059 pScrn->displayWidth);
9062 ret = cfb24ScreenInit(pScreen, FbBase,
9063 pScrn->virtualX, pScrn->virtualY,
9064 pScrn->xDpi, pScrn->yDpi,
9065 pScrn->displayWidth);
9068 ret = cfb32ScreenInit(pScreen, FbBase,
9069 pScrn->virtualX, pScrn->virtualY,
9070 pScrn->xDpi, pScrn->yDpi,
9071 pScrn->displayWidth);
9074 print a message about an internal error;
9082 /* Override the default mask/offset settings */
9083 if (pScrn->bitsPerPixel > 8) {
9084 for (i = 0, visual = pScreen->visuals;
9085 i < pScreen->numVisuals; i++, visual++) {
9086 if ((visual->class | DynamicClass) == DirectColor) {
9087 visual->offsetRed = pScrn->offset.red;
9088 visual->offsetGreen = pScrn->offset.green;
9089 visual->offsetBlue = pScrn->offset.blue;
9090 visual->redMask = pScrn->mask.red;
9091 visual->greenMask = pScrn->mask.green;
9092 visual->blueMask = pScrn->mask.blue;
9098 * If banking is needed, initialise an miBankInfoRec (defined in
9099 * "mibank.h"), and call miInitializeBanking().
9101 if (!miInitializeBanking(pScreen, pScrn->virtualX, pScrn->virtualY,
9102 pScrn->displayWidth, pBankInfo))
9106 * If backing store is to be supported (as is usually the case),
9109 miInitializeBackingStore(pScreen);
9112 * Set initial black & white colourmap indices.
9114 xf86SetBlackWhitePixels(pScreen);
9117 * Install colourmap functions. If using the vgahw module,
9118 * vgaHandleColormaps would usually be called here.
9124 * Initialise cursor functions. This example is for the mi
9127 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
9129 /* Initialise the default colourmap */
9130 switch (pScrn->depth) {
9132 if (!xf1bppCreateDefColormap(pScreen))
9136 if (!xf4bppCreateDefColormap(pScreen))
9140 if (!cfbCreateDefColormap(pScreen))
9146 * Wrap the CloseScreen vector and set SaveScreen.
9148 ZZZPTR(pScrn)->CloseScreen = pScreen->CloseScreen;
9149 pScreen->CloseScreen = ZZZCloseScreen;
9150 pScreen->SaveScreen = ZZZSaveScreen;
9152 /* Report any unused options (only for the first generation) */
9153 if (serverGeneration == 1) {
9154 xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
9164 <title>SwitchMode</title>
9167 Define the <function>SwitchMode()</function> function if mode switching
9168 is supported by the driver.
9173 ZZZSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
9175 return ZZZModeInit(pScrn, mode);
9181 <title>AdjustFrame</title>
9184 Define the <function>AdjustFrame()</function> function if the driver
9190 ZZZAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
9192 /* Adjust the viewport */
9198 <title>EnterVT, LeaveVT</title>
9201 Define the <function>EnterVT()</function> and <function>LeaveVT()</function>
9206 These functions are mandatory.
9211 ZZZEnterVT(ScrnInfoPtr pScrn)
9213 return ZZZModeInit(pScrn, pScrn->currentMode);
9217 ZZZLeaveVT(ScrnInfoPtr pScrn)
9225 <title>CloseScreen</title>
9228 Define the <function>CloseScreen()</function> function:
9232 This function is mandatory. Note that it unwraps the previously
9233 wrapped <structfield>pScreen->CloseScreen</structfield>, and finishes by
9239 ZZZCloseScreen(ScreenPtr pScreen)
9241 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
9242 if (pScrn->vtSema) {
9246 pScrn->vtSema = FALSE;
9247 pScreen->CloseScreen = ZZZPTR(pScrn)->CloseScreen;
9248 return (*pScreen->CloseScreen)(pScreen);
9254 <title>SaveScreen</title>
9257 Define the <function>SaveScreen()</function> function (the screen
9258 blanking function). When using the vgahw module, this will typically
9263 ZZZSaveScreen(ScreenPtr pScreen, int mode)
9265 return vgaHWSaveScreen(pScreen, mode);
9271 This function is mandatory. Before modifying any hardware register
9272 directly this function needs to make sure that the Xserver is active
9273 by checking if <parameter>pScrn</parameter> is non-NULL and for
9274 <literal remap="tt">pScrn->vtSema == TRUE</literal>.
9279 <title>FreeScreen</title>
9282 Define the <function>FreeScreen()</function> function. This function
9283 is optional. It should be defined if the <structname>ScrnInfoRec</structname>
9284 <structfield>driverPrivate</structfield> field is used so that it can be freed
9285 when a screen is deleted by the common layer for reasons possibly
9286 beyond the driver's control. This function is not used in during
9287 normal (error free) operation. The per-generation data is freed by
9288 the <function>CloseScreen()</function> function.
9293 ZZZFreeScreen(ScrnInfoPtr pScrn)
9296 * If the vgahw module is used vgaHWFreeHWRec() would be called