xref: /OK3568_Linux_fs/external/xserver/hw/xfree86/doc/ddxDesign.xml (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun<?xml version="1.0" encoding="ISO-8859-1"?>
2*4882a593Smuzhiyun<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3*4882a593Smuzhiyun "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
4*4882a593Smuzhiyun <!ENTITY % xorg-defs SYSTEM "defs.ent"> %xorg-defs;
5*4882a593Smuzhiyun <!ENTITY % defs SYSTEM "/xserver/doc/xml/xserver.ent"> %defs;
6*4882a593Smuzhiyun <!-- config file keyword markup -->
7*4882a593Smuzhiyun <!-- specific config file keywords -->
8*4882a593Smuzhiyun <!ENTITY k.device "<emphasis>Device</emphasis>">
9*4882a593Smuzhiyun <!ENTITY k.monitor "<emphasis>Monitor</emphasis>">
10*4882a593Smuzhiyun <!ENTITY k.display "<emphasis>Display</emphasis>">
11*4882a593Smuzhiyun <!ENTITY k.inputdevice "<emphasis>InputDevice</emphasis>">
12*4882a593Smuzhiyun <!ENTITY k.screen "<emphasis>Screen</emphasis>">
13*4882a593Smuzhiyun <!ENTITY k.serverlayout "<emphasis>ServerLayout</emphasis>">
14*4882a593Smuzhiyun <!ENTITY k.driver "<emphasis>Driver</emphasis>">
15*4882a593Smuzhiyun <!ENTITY k.module "<emphasis>Module</emphasis>">
16*4882a593Smuzhiyun <!ENTITY k.identifier "<emphasis>Identifier</emphasis>">
17*4882a593Smuzhiyun <!ENTITY k.serverflags "<emphasis>ServerFlags</emphasis>">
18*4882a593Smuzhiyun] >
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun<article id="ddxDesign">
21*4882a593Smuzhiyun  <articleinfo>
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun    <title>XFree86 DDX Design</title>
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun    <authorgroup>
26*4882a593Smuzhiyun      <corpauthor>The XFree86 Project</corpauthor>
27*4882a593Smuzhiyun      <corpauthor>The X.Org Foundation</corpauthor>
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun      <othercredit>
30*4882a593Smuzhiyun	<firstname>Jim</firstname><surname>Gettys</surname>
31*4882a593Smuzhiyun	<contrib>Updates for X11R6.7</contrib>
32*4882a593Smuzhiyun      </othercredit>
33*4882a593Smuzhiyun    </authorgroup>
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun    <pubdate>&xserver.reldate;</pubdate>
36*4882a593Smuzhiyun    <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo>
37*4882a593Smuzhiyun    <releaseinfo>X Server Version &xserver.version;</releaseinfo>
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun  </articleinfo>
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun  <note><para>
42*4882a593SmuzhiyunThis document describes software undergoing continual evolution, and
43*4882a593Smuzhiyunthe interfaces described here are subject to change without notice.
44*4882a593SmuzhiyunThis document is intended to cover the interfaces as found in the
45*4882a593Smuzhiyunxorg-server-&xserver.version; release, but is probably not completely
46*4882a593Smuzhiyunin sync with the code base.
47*4882a593Smuzhiyun    </para></note>
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun  <sect1>
51*4882a593Smuzhiyun    <title>Preface</title>
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun    <para>
54*4882a593SmuzhiyunThis document was originally the design spec for the DDX layer of the
55*4882a593SmuzhiyunXFree86 4.0 X server.  The X.Org Foundation adopted the XFree86 4.4rc2
56*4882a593Smuzhiyunversion of that server as the basis of the Xorg server project, and has
57*4882a593Smuzhiyunevolved the XFree86 DDX layer greatly since forking.   This document thus
58*4882a593Smuzhiyuncovers only the current implementation of the XFree86 DDX as found in the
59*4882a593SmuzhiyunXorg server &xserver.version; release, and no longer matches the XFree86
60*4882a593Smuzhiyunserver itself.
61*4882a593Smuzhiyun      </para>
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun    <para>
64*4882a593SmuzhiyunThe XFree86 Project's broad design principles for XFree86 4.0 were:
65*4882a593Smuzhiyun      <itemizedlist>
66*4882a593Smuzhiyun	<listitem><para>keep it reasonable
67*4882a593Smuzhiyun	    <itemizedlist>
68*4882a593Smuzhiyun	      <listitem><para>We cannot rewrite the complete server
69*4882a593Smuzhiyun		</para></listitem>
70*4882a593Smuzhiyun	      <listitem><para>We don't want to re-invent the wheel
71*4882a593Smuzhiyun		</para></listitem>
72*4882a593Smuzhiyun	    </itemizedlist></para></listitem>
73*4882a593Smuzhiyun	<listitem><para>keep it modular
74*4882a593Smuzhiyun	    <itemizedlist>
75*4882a593Smuzhiyun	      <listitem><para>As many things as possible should go into modules
76*4882a593Smuzhiyun		</para></listitem>
77*4882a593Smuzhiyun	      <listitem><para>The basic loader binary should be minimal
78*4882a593Smuzhiyun		</para></listitem>
79*4882a593Smuzhiyun	      <listitem><para>A clean design with well defined layering is
80*4882a593Smuzhiyun		  important</para></listitem>
81*4882a593Smuzhiyun	      <listitem><para>DDX specific global variables are a nono
82*4882a593Smuzhiyun		</para></listitem>
83*4882a593Smuzhiyun	      <listitem><para>The structure should be flexible enough to allow
84*4882a593Smuzhiyun		  future extensions</para></listitem>
85*4882a593Smuzhiyun	      <listitem><para>The structure should minimize duplication of
86*4882a593Smuzhiyun		  common code</para></listitem>
87*4882a593Smuzhiyun	    </itemizedlist></para></listitem>
88*4882a593Smuzhiyun	<listitem><para>keep important features in mind
89*4882a593Smuzhiyun	    <itemizedlist>
90*4882a593Smuzhiyun	      <listitem><para>multiple screens, including multiple instances
91*4882a593Smuzhiyun		  of drivers</para></listitem>
92*4882a593Smuzhiyun	      <listitem><para>mixing different color depths and visuals on
93*4882a593Smuzhiyun		  different and ideally even on the same screen
94*4882a593Smuzhiyun		</para></listitem>
95*4882a593Smuzhiyun	      <listitem><para>better control of the PCI device used
96*4882a593Smuzhiyun		</para></listitem>
97*4882a593Smuzhiyun	      <listitem><para>better config file parser</para></listitem>
98*4882a593Smuzhiyun	      <listitem><para>get rid of all VGA compatibility assumptions
99*4882a593Smuzhiyun		</para></listitem>
100*4882a593Smuzhiyun	    </itemizedlist></para></listitem>
101*4882a593Smuzhiyun      </itemizedlist>
102*4882a593Smuzhiyun    </para>
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun    <para>
105*4882a593SmuzhiyunWhile the XFree86 project had a goal of avoiding changes to the DIX
106*4882a593Smuzhiyunlayer unless they found major deficiencies there, to avoid divergence from
107*4882a593Smuzhiyunthe X.Org sample implementation they were integrating changes from, the
108*4882a593SmuzhiyunX.Org developers now maintain both sides, and make changes where they are
109*4882a593Smuzhiyunmost appropriate.   This document concentrates on the XFree86 DDX layer used
110*4882a593Smuzhiyunin the Xorg server itself (the code found in <filename>hw/xfree86</filename>
111*4882a593Smuzhiyunin the source tree), and developers will also want to refer to the
112*4882a593Smuzhiyun<filename>Xserver-spec</filename> documentation that covers the DIX layer
113*4882a593Smuzhiyunroutines common to all the X servers in the sample implementation.
114*4882a593Smuzhiyun    </para>
115*4882a593Smuzhiyun  </sect1>
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun  <sect1>
118*4882a593Smuzhiyun    <title>The xorg.conf File</title>
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun    <para>
121*4882a593SmuzhiyunThe xorg.conf file format is based on the XF86Config format from XFree86 4.4,
122*4882a593Smuzhiyunwhich is in turn similar to the old XFree86 3.x XF86Config format, with the
123*4882a593Smuzhiyunfollowing changes:
124*4882a593Smuzhiyun    </para>
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun    <sect2>
127*4882a593Smuzhiyun      <title>&k.device; section</title>
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun      <para>
130*4882a593Smuzhiyun    The &k.device; sections are similar to what they used to be, and
131*4882a593Smuzhiyun    describe hardware-specific information for a single video card.
132*4882a593Smuzhiyun    &k.device;
133*4882a593Smuzhiyun    Some new keywords are added:
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun	<variablelist>
137*4882a593Smuzhiyun	  <varlistentry><term>Driver "drivername"</term>
138*4882a593Smuzhiyun	    <listitem><para>
139*4882a593Smuzhiyun        Specifies the name of the driver to be used for the card.  This
140*4882a593Smuzhiyun        is mandatory.
141*4882a593Smuzhiyun	      </para></listitem></varlistentry>
142*4882a593Smuzhiyun	  <varlistentry><term>BusID "busslot"</term>
143*4882a593Smuzhiyun	    <listitem><para>
144*4882a593Smuzhiyun        Specifies uniquely the location of the card on the bus.  The
145*4882a593Smuzhiyun        purpose is to identify particular cards in a multi-headed
146*4882a593Smuzhiyun        configuration.  The format of the argument is intentionally
147*4882a593Smuzhiyun        vague, and may be architecture dependent.  For a PCI bus, it
148*4882a593Smuzhiyun        is something like "bus@domain:slot:func". The "@domain" part
149*4882a593Smuzhiyun        can be left out for domain 0.
150*4882a593Smuzhiyun	      </para></listitem></varlistentry>
151*4882a593Smuzhiyun	</variablelist>
152*4882a593Smuzhiyun      </para>
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun      <para>
155*4882a593Smuzhiyun    A &k.device; section is considered <quote>active</quote> if there is a reference
156*4882a593Smuzhiyun    to it in an active &k.screen; section.
157*4882a593Smuzhiyun      </para>
158*4882a593Smuzhiyun    </sect2>
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun    <sect2>
161*4882a593Smuzhiyun      <title>&k.screen; section</title>
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun      <para>
164*4882a593Smuzhiyun    The &k.screen; sections are similar to what they used to be.  They
165*4882a593Smuzhiyun    no longer have a &k.driver; keyword, but an &k.identifier; keyword
166*4882a593Smuzhiyun    is added.  (The &k.driver; keyword may be accepted in place of the
167*4882a593Smuzhiyun    &k.identifier; keyword for compatibility purposes.)  The identifier
168*4882a593Smuzhiyun    can be used to identify which screen is to be active when multiple
169*4882a593Smuzhiyun    &k.screen; sections are present.  It is possible to specify the active
170*4882a593Smuzhiyun    screen from the command line.  A default is chosen in the absence
171*4882a593Smuzhiyun    of one being specified.  A &k.screen; section is considered <quote>active</quote>
172*4882a593Smuzhiyun    if there is a reference to it either from the command line, or from
173*4882a593Smuzhiyun    an active &k.serverlayout; section.
174*4882a593Smuzhiyun      </para>
175*4882a593Smuzhiyun    </sect2>
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun    <sect2>
178*4882a593Smuzhiyun      <title>&k.inputdevice; section</title>
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun      <para>
181*4882a593Smuzhiyun    The &k.inputdevice; section is a new section that describes
182*4882a593Smuzhiyun    configuration information for input devices.  It replaces the old
183*4882a593Smuzhiyun    <emphasis>Keyboard</emphasis>, <emphasis>Pointer</emphasis> and <emphasis>XInput</emphasis>
184*4882a593Smuzhiyun    sections.  Like the &k.device; section, it has two mandatory keywords:
185*4882a593Smuzhiyun    &k.identifier; and &k.driver;.  For compatibility purposes the old
186*4882a593Smuzhiyun    <emphasis>Keyboard</emphasis> and <emphasis>Pointer</emphasis> sections are
187*4882a593Smuzhiyun    converted by the parser into &k.inputdevice; sections as follows:
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun	<variablelist>
190*4882a593Smuzhiyun	  <varlistentry><term><emphasis>Keyboard</emphasis></term>
191*4882a593Smuzhiyun	    <listitem><literallayout>
192*4882a593Smuzhiyun             &k.identifier; "Implicit Core Keyboard"
193*4882a593Smuzhiyun             &k.driver; "kbd"
194*4882a593Smuzhiyun	      </literallayout></listitem></varlistentry>
195*4882a593Smuzhiyun	  <varlistentry><term><emphasis>Pointer</emphasis></term>
196*4882a593Smuzhiyun	    <listitem><literallayout>
197*4882a593Smuzhiyun             &k.identifier; "Implicit Core Pointer"
198*4882a593Smuzhiyun             &k.driver; "mouse"
199*4882a593Smuzhiyun	      </literallayout></listitem></varlistentry>
200*4882a593Smuzhiyun	</variablelist>
201*4882a593Smuzhiyun      </para>
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun      <para>
204*4882a593Smuzhiyun    An &k.inputdevice; section is considered active if there is a
205*4882a593Smuzhiyun    reference to it in an active &k.serverlayout; section.  An
206*4882a593Smuzhiyun    &k.inputdevice; section may also be referenced implicitly if there
207*4882a593Smuzhiyun    is no &k.serverlayout; section, if the <option>-screen</option> command
208*4882a593Smuzhiyun    line options is used, or if the &k.serverlayout; section doesn't
209*4882a593Smuzhiyun    reference any &k.inputdevice; sections.  In this case, the first
210*4882a593Smuzhiyun    sections with drivers "kbd" and "mouse" are used as the core
211*4882a593Smuzhiyun    keyboard and pointer respectively.
212*4882a593Smuzhiyun      </para>
213*4882a593Smuzhiyun    </sect2>
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun    <sect2>
216*4882a593Smuzhiyun      <title>&k.serverlayout; section</title>
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun      <para>
219*4882a593Smuzhiyun    The &k.serverlayout; section is a new section that is used to identify
220*4882a593Smuzhiyun    which &k.screen; sections are to be used in a multi-headed configuration,
221*4882a593Smuzhiyun    and the relative layout of those screens.  It also identifies which
222*4882a593Smuzhiyun    &k.inputdevice; sections are to be used.  Each &k.serverlayout; section
223*4882a593Smuzhiyun    has an identifier, a list of &k.screen; section identifiers, and a list of
224*4882a593Smuzhiyun    &k.inputdevice; section identifiers.  &k.serverflags; options may also be
225*4882a593Smuzhiyun    included in a &k.serverlayout; section, making it possible to override
226*4882a593Smuzhiyun    the global values in the &k.serverflags; section.
227*4882a593Smuzhiyun      </para>
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun      <para>
230*4882a593Smuzhiyun    A &k.serverlayout; section can be made active by being referenced on
231*4882a593Smuzhiyun    the command line.  In the absence of this, a default will be chosen
232*4882a593Smuzhiyun    (the first one found).  The screen names may optionally be followed
233*4882a593Smuzhiyun    by a number specifying the preferred screen number, and optionally
234*4882a593Smuzhiyun    by information specifying the physical positioning of the screen,
235*4882a593Smuzhiyun    either in absolute terms or relative to another screen (or screens).
236*4882a593Smuzhiyun    When no screen number is specified, they are numbered according to
237*4882a593Smuzhiyun    the order in which they are listed.  The old (now obsolete) method
238*4882a593Smuzhiyun    of providing the positioning information is to give the names of
239*4882a593Smuzhiyun    the four adjacent screens.  The order of these is top, bottom, left,
240*4882a593Smuzhiyun    right.  Here is an example of a &k.serverlayout; section for two
241*4882a593Smuzhiyun    screens using the old method, with the second located to the right
242*4882a593Smuzhiyun    of the first:
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun	<programlisting>
245*4882a593Smuzhiyun      Section "ServerLayout"
246*4882a593Smuzhiyun        Identifier "Main Layout"
247*4882a593Smuzhiyun        Screen     0 "Screen 1" ""  ""  ""  "Screen 2"
248*4882a593Smuzhiyun        Screen     1 "Screen 2"
249*4882a593Smuzhiyun        Screen     "Screen 3"
250*4882a593Smuzhiyun      EndSection
251*4882a593Smuzhiyun	</programlisting>
252*4882a593Smuzhiyun      </para>
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun      <para>
255*4882a593Smuzhiyun    The preferred way of specifying the layout is to explicitly specify
256*4882a593Smuzhiyun    the screen's location in absolute terms or relative to another
257*4882a593Smuzhiyun    screen.
258*4882a593Smuzhiyun      </para>
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun      <para>
261*4882a593Smuzhiyun    In the absolute case, the upper left corner's coordinates are given
262*4882a593Smuzhiyun    after the <emphasis>Absolute</emphasis> keyword.  If the coordinates are
263*4882a593Smuzhiyun    omitted, a value of <code>(0,0)</code> is assumed.  An example
264*4882a593Smuzhiyun    of absolute positioning follows:
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun	<programlisting>
267*4882a593Smuzhiyun      Section "ServerLayout"
268*4882a593Smuzhiyun        Identifier "Main Layout"
269*4882a593Smuzhiyun        Screen     0 "Screen 1" Absolute 0 0
270*4882a593Smuzhiyun        Screen     1 "Screen 2" Absolute 1024 0
271*4882a593Smuzhiyun        Screen     "Screen 3" Absolute 2048 0
272*4882a593Smuzhiyun      EndSection
273*4882a593Smuzhiyun	</programlisting>
274*4882a593Smuzhiyun      </para>
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun      <para>
277*4882a593Smuzhiyun    In the relative case, the position is specified by either using one of
278*4882a593Smuzhiyun    the following keywords followed by the name of the reference screen:
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun	<simplelist type='vert' columns='1'>
281*4882a593Smuzhiyun	  <member><emphasis>RightOf</emphasis></member>
282*4882a593Smuzhiyun	  <member><emphasis>LeftOf</emphasis></member>
283*4882a593Smuzhiyun	  <member><emphasis>Above</emphasis></member>
284*4882a593Smuzhiyun	  <member><emphasis>Below</emphasis></member>
285*4882a593Smuzhiyun	  <member><emphasis>Relative</emphasis></member>
286*4882a593Smuzhiyun	</simplelist>
287*4882a593Smuzhiyun      </para>
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun      <para>
290*4882a593Smuzhiyun    When the <emphasis>Relative</emphasis> keyword is used, the reference screen
291*4882a593Smuzhiyun    name is followed by the coordinates of the new screen's origin
292*4882a593Smuzhiyun    relative to reference screen.  The following example shows how to use
293*4882a593Smuzhiyun    some of the relative positioning options.
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun	<programlisting>
296*4882a593Smuzhiyun      Section "ServerLayout"
297*4882a593Smuzhiyun        Identifier "Main Layout"
298*4882a593Smuzhiyun        Screen     0 "Screen 1"
299*4882a593Smuzhiyun        Screen     1 "Screen 2" RightOf "Screen 1"
300*4882a593Smuzhiyun        Screen     "Screen 3" Relative "Screen 1" 2048 0
301*4882a593Smuzhiyun      EndSection
302*4882a593Smuzhiyun	</programlisting>
303*4882a593Smuzhiyun      </para>
304*4882a593Smuzhiyun    </sect2>
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun    <sect2>
307*4882a593Smuzhiyun      <title>Options</title>
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun      <para>
310*4882a593Smuzhiyun    Options are used more extensively.  They may appear in most sections
311*4882a593Smuzhiyun    now.  Options related to drivers can be present in the &k.screen;,
312*4882a593Smuzhiyun    &k.device; and &k.monitor; sections and the &k.display; subsections.
313*4882a593Smuzhiyun    The order of precedence is &k.display;, &k.screen;, &k.monitor;,
314*4882a593Smuzhiyun    &k.device;.  Options have been extended to allow an optional value
315*4882a593Smuzhiyun    to be specified in addition to the option name.  For more details
316*4882a593Smuzhiyun    about options, see the <link linkend="options">Options</link> section
317*4882a593Smuzhiyun    for details.
318*4882a593Smuzhiyun      </para>
319*4882a593Smuzhiyun    </sect2>
320*4882a593Smuzhiyun  </sect1>
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun  <sect1>
323*4882a593Smuzhiyun    <title>Driver Interface</title>
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun    <para>
326*4882a593SmuzhiyunThe driver interface consists of a minimal set of entry points that are
327*4882a593Smuzhiyunrequired based on the external events that the driver must react to.
328*4882a593SmuzhiyunNo non-essential structure is imposed on the way they are used beyond
329*4882a593Smuzhiyunthat.  This is a significant difference compared with the old design.
330*4882a593Smuzhiyun    </para>
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun    <para>
333*4882a593SmuzhiyunThe entry points for drawing operations are already taken care of by
334*4882a593Smuzhiyunthe framebuffer code.  Extensions and enhancements to framebuffer code
335*4882a593Smuzhiyunare outside the scope of this document.
336*4882a593Smuzhiyun    </para>
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun    <para>
339*4882a593SmuzhiyunThis approach to the driver interface provides good flexibility, but does
340*4882a593Smuzhiyunincrease the complexity of drivers.  To help address this, the XFree86
341*4882a593Smuzhiyuncommon layer provides a set of <quote>helper</quote> functions to take care of things
342*4882a593Smuzhiyunthat most drivers need.  These helpers help minimise the amount of code
343*4882a593Smuzhiyunduplication between drivers.  The use of helper functions by drivers is
344*4882a593Smuzhiyunhowever optional, though encouraged.  The basic philosophy behind the
345*4882a593Smuzhiyunhelper functions is that they should be useful to many drivers, that
346*4882a593Smuzhiyunthey should balance this against the complexity of their interface.  It
347*4882a593Smuzhiyunis inevitable that some drivers may find some helpers unsuitable and
348*4882a593Smuzhiyunneed to provide their own code.
349*4882a593Smuzhiyun    </para>
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun    <para>
352*4882a593SmuzhiyunEvents that a driver needs to react to are:
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun      <variablelist>
355*4882a593Smuzhiyun	<varlistentry><term>ScreenInit</term>
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun	  <listitem><para>
358*4882a593Smuzhiyun     An initialisation function is called from the DIX layer for each
359*4882a593Smuzhiyun     screen at the start of each server generation.
360*4882a593Smuzhiyun	    </para></listitem></varlistentry>
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun	<varlistentry><term>Enter VT</term>
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun	  <listitem><para>
365*4882a593Smuzhiyun     The server takes control of the console.
366*4882a593Smuzhiyun	    </para></listitem></varlistentry>
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun	<varlistentry><term>Leave VT</term>
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun	  <listitem><para>
371*4882a593Smuzhiyun     The server releases control of the console.
372*4882a593Smuzhiyun	    </para></listitem></varlistentry>
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun	<varlistentry><term>Mode Switch</term>
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun	  <listitem><para>
377*4882a593Smuzhiyun     Change video mode.
378*4882a593Smuzhiyun	    </para></listitem></varlistentry>
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun	<varlistentry><term>ViewPort change</term>
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun	  <listitem><para>
383*4882a593Smuzhiyun     Change the origin of the physical view port.
384*4882a593Smuzhiyun	    </para></listitem></varlistentry>
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun	<varlistentry><term>ScreenSaver state change</term>
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun	  <listitem><para>
389*4882a593Smuzhiyun     Screen saver activation/deactivation.
390*4882a593Smuzhiyun	    </para></listitem></varlistentry>
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun	<varlistentry><term>CloseScreen</term>
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun	  <listitem><para>
395*4882a593Smuzhiyun     A close screen function is called from the DIX layer for each screen
396*4882a593Smuzhiyun     at the end of each server generation.
397*4882a593Smuzhiyun	    </para></listitem></varlistentry>
398*4882a593Smuzhiyun      </variablelist>
399*4882a593Smuzhiyun    </para>
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun    <para>
403*4882a593SmuzhiyunIn addition to these events, the following functions are required by
404*4882a593Smuzhiyunthe XFree86 common layer:
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun      <variablelist>
407*4882a593Smuzhiyun	<varlistentry><term>Identify</term>
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun	  <listitem><para>
410*4882a593Smuzhiyun     Print a driver identifying message.
411*4882a593Smuzhiyun	    </para></listitem></varlistentry>
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun	<varlistentry><term>Probe</term>
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun	  <listitem><para>
416*4882a593Smuzhiyun     This is how a driver identifies if there is any hardware present that
417*4882a593Smuzhiyun     it knows how to drive.
418*4882a593Smuzhiyun	    </para></listitem></varlistentry>
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun	<varlistentry><term>PreInit</term>
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun	  <listitem><para>
423*4882a593Smuzhiyun     Process information from the xorg.conf file, determine the
424*4882a593Smuzhiyun     full characteristics of the hardware, and determine if a valid
425*4882a593Smuzhiyun     configuration is present.
426*4882a593Smuzhiyun	    </para></listitem></varlistentry>
427*4882a593Smuzhiyun      </variablelist>
428*4882a593Smuzhiyun    </para>
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun    <para>
431*4882a593SmuzhiyunThe VidMode extension also requires:
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun      <variablelist>
434*4882a593Smuzhiyun	<varlistentry><term>ValidMode</term>
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun	  <listitem><para>
437*4882a593Smuzhiyun     Identify if a new mode is usable with the current configuration.
438*4882a593Smuzhiyun     The PreInit function (and/or helpers it calls) may also make use
439*4882a593Smuzhiyun     of the ValidMode function or something similar.
440*4882a593Smuzhiyun	    </para></listitem></varlistentry>
441*4882a593Smuzhiyun      </variablelist>
442*4882a593Smuzhiyun    </para>
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun    <para>
446*4882a593SmuzhiyunOther extensions may require other entry points.  The drivers will
447*4882a593Smuzhiyuninform the common layer of these in such cases.
448*4882a593Smuzhiyun    </para>
449*4882a593Smuzhiyun  </sect1>
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun  <sect1>
452*4882a593Smuzhiyun    <title>Resource Access Control Introduction</title>
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun    <para>
455*4882a593SmuzhiyunGraphics devices are accessed through ranges in I/O or memory space.
456*4882a593SmuzhiyunWhile most modern graphics devices allow relocation of such ranges many
457*4882a593Smuzhiyunof them still require the use of well established interfaces such as
458*4882a593SmuzhiyunVGA memory and IO ranges or 8514/A IO ranges.  With modern buses (like
459*4882a593SmuzhiyunPCI) it is possible for multiple video devices to share access to these
460*4882a593Smuzhiyunresources.  The RAC (Resource Access Control) subsystem provides a
461*4882a593Smuzhiyunmechanism for this.
462*4882a593Smuzhiyun    </para>
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun    <sect2>
465*4882a593Smuzhiyun      <title>Terms and Definitions</title>
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun      <sect3>
468*4882a593Smuzhiyun	<title>Bus</title>
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun	<para>
471*4882a593Smuzhiyun    <quote>Bus</quote> is ambiguous as it is used for different things: it may refer
472*4882a593Smuzhiyun    to physical incompatible extension connectors in a computer system.
473*4882a593Smuzhiyun    The RAC system knows two such systems: The ISA bus and the PCI bus.
474*4882a593Smuzhiyun    (On the software level EISA, MCA and VL buses are currently treated
475*4882a593Smuzhiyun    like ISA buses).  <quote>Bus</quote> may also refer to logically different
476*4882a593Smuzhiyun    entities on a single bus system which are connected via bridges.  A
477*4882a593Smuzhiyun    PCI system may have several distinct PCI buses connecting each other
478*4882a593Smuzhiyun    by PCI-PCI bridges or to the host CPU by HOST-PCI bridges.
479*4882a593Smuzhiyun	</para>
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun	<para>
482*4882a593Smuzhiyun    Systems that host more than one bus system link these together using
483*4882a593Smuzhiyun    bridges.  Bridges are a concern to RAC as they might block or pass
484*4882a593Smuzhiyun    specific resources.  PCI-PCI bridges may be set up to pass VGA
485*4882a593Smuzhiyun    resources to the secondary bus.  PCI-ISA buses pass any resources not
486*4882a593Smuzhiyun    decoded on the primary PCI bus to the ISA bus.  This way VGA resources
487*4882a593Smuzhiyun    (although exclusive on the ISA bus) can be shared by ISA and PCI
488*4882a593Smuzhiyun    cards.  Currently HOST-PCI bridges are not yet handled by RAC as they
489*4882a593Smuzhiyun    require specific drivers.
490*4882a593Smuzhiyun	</para>
491*4882a593Smuzhiyun      </sect3>
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun      <sect3>
494*4882a593Smuzhiyun	<title>Entity</title>
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun	<para>
497*4882a593Smuzhiyun    The smallest independently addressable unit on a system bus is
498*4882a593Smuzhiyun    referred to as an entity.  So far we know ISA and PCI entities.  PCI
499*4882a593Smuzhiyun    entities can be located on the PCI bus by an unique ID consisting of
500*4882a593Smuzhiyun    the bus, card and function number.
501*4882a593Smuzhiyun	</para>
502*4882a593Smuzhiyun      </sect3>
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun      <sect3>
505*4882a593Smuzhiyun	<title>Resource</title>
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun	<para>
508*4882a593Smuzhiyun    <quote>Resource</quote> refers to a range of memory or I/O addresses an entity
509*4882a593Smuzhiyun    can decode.
510*4882a593Smuzhiyun	</para>
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun	<para>
513*4882a593Smuzhiyun    If a device is capable of disabling this decoding the resource is
514*4882a593Smuzhiyun    called sharable.  For PCI devices a generic method is provided to
515*4882a593Smuzhiyun    control resource decoding.  Other devices will have to provide a
516*4882a593Smuzhiyun    device specific function to control decoding.
517*4882a593Smuzhiyun	</para>
518*4882a593Smuzhiyun
519*4882a593Smuzhiyun	<para>
520*4882a593Smuzhiyun    If the entity is capable of decoding this range at a different
521*4882a593Smuzhiyun    location this resource is considered relocatable.
522*4882a593Smuzhiyun	</para>
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun	<para>
525*4882a593Smuzhiyun    Resources which start at a specific address and occupy a single
526*4882a593Smuzhiyun    continuous range are called block resources.
527*4882a593Smuzhiyun	</para>
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun	<para>
530*4882a593Smuzhiyun    Alternatively resource addresses can be decoded in a way that they
531*4882a593Smuzhiyun    satisfy the conditions:
532*4882a593Smuzhiyun	  <programlisting>
533*4882a593Smuzhiyun                    address &amp; mask == base
534*4882a593Smuzhiyun	  </programlisting>
535*4882a593Smuzhiyun    and
536*4882a593Smuzhiyun	  <programlisting>
537*4882a593Smuzhiyun                       base &amp; mask == base
538*4882a593Smuzhiyun	  </programlisting>
539*4882a593Smuzhiyun    Resources addressed in such a way are called sparse resources.
540*4882a593Smuzhiyun	</para>
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun      </sect3>
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun      <sect3>
545*4882a593Smuzhiyun	<title>Server States</title>
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun	<para>
548*4882a593Smuzhiyun    The resource access control system knows two server states: the
549*4882a593Smuzhiyun    SETUP and the OPERATING state.  The SETUP state is entered whenever
550*4882a593Smuzhiyun    a mode change takes place or the server exits or does VT switching.
551*4882a593Smuzhiyun    During this state all entity resources are under resource access
552*4882a593Smuzhiyun    control.  During OPERATING state only those entities are controlled
553*4882a593Smuzhiyun    which actually have shared resources that conflict with others.
554*4882a593Smuzhiyun	</para>
555*4882a593Smuzhiyun      </sect3>
556*4882a593Smuzhiyun    </sect2>
557*4882a593Smuzhiyun  </sect1>
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun  <sect1>
560*4882a593Smuzhiyun    <title>Control Flow in the Server and Mandatory Driver Functions</title>
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun    <para>
563*4882a593SmuzhiyunAt the start of each server generation, <function>main()</function>
564*4882a593Smuzhiyun(<filename>dix/main.c</filename>) calls the DDX function
565*4882a593Smuzhiyun<function>InitOutput()</function>.  This is the first place that the DDX gets
566*4882a593Smuzhiyuncontrol.  <function>InitOutput()</function> is expected to fill in the global
567*4882a593Smuzhiyun<structname>screenInfo</structname> struct, and one
568*4882a593Smuzhiyun<structfield>screenInfo.screen[]</structfield> entry for each screen present.
569*4882a593SmuzhiyunHere is what <function>InitOutput()</function> does:
570*4882a593Smuzhiyun    </para>
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun    <sect2>
573*4882a593Smuzhiyun      <title>Parse the xorg.conf file</title>
574*4882a593Smuzhiyun
575*4882a593Smuzhiyun      <para>
576*4882a593Smuzhiyun    This is done at the start of the first server generation only.
577*4882a593Smuzhiyun      </para>
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun      <para>
580*4882a593Smuzhiyun    The xorg.conf file is read in full, and the resulting information
581*4882a593Smuzhiyun    stored in data structures.  None of the parsed information is
582*4882a593Smuzhiyun    processed at this point.  The parser data structures are opaque to
583*4882a593Smuzhiyun    the video drivers and to most of the common layer code.
584*4882a593Smuzhiyun      </para>
585*4882a593Smuzhiyun
586*4882a593Smuzhiyun      <para>
587*4882a593Smuzhiyun    The entire file is parsed first to remove any section ordering
588*4882a593Smuzhiyun    requirements.
589*4882a593Smuzhiyun      </para>
590*4882a593Smuzhiyun    </sect2>
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun
593*4882a593Smuzhiyun    <sect2>
594*4882a593Smuzhiyun      <title>Initial processing of parsed information and command line options
595*4882a593Smuzhiyun      </title>
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun      <para>
598*4882a593Smuzhiyun    This is done at the start of the first server generation only.
599*4882a593Smuzhiyun      </para>
600*4882a593Smuzhiyun
601*4882a593Smuzhiyun      <para>
602*4882a593Smuzhiyun    The initial processing is to determine paths like the
603*4882a593Smuzhiyun    <emphasis>ModulePath</emphasis>, etc, and to determine which &k.serverlayout;,
604*4882a593Smuzhiyun    &k.screen; and &k.device; sections are active.
605*4882a593Smuzhiyun      </para>
606*4882a593Smuzhiyun    </sect2>
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun    <sect2>
610*4882a593Smuzhiyun      <title>Enable port I/O access</title>
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun      <para>
613*4882a593Smuzhiyun    Port I/O access is controlled from the XFree86 common layer, and is
614*4882a593Smuzhiyun    <quote>all or nothing</quote>.  It is enabled prior to calling driver probes, at
615*4882a593Smuzhiyun    the start of subsequent server generations, and when VT switching
616*4882a593Smuzhiyun    back to the Xserver.  It is disabled at the end of server generations,
617*4882a593Smuzhiyun    and when VT switching away from the Xserver.
618*4882a593Smuzhiyun      </para>
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun      <para>
621*4882a593Smuzhiyun    The implementation details of this may vary on different platforms.
622*4882a593Smuzhiyun      </para>
623*4882a593Smuzhiyun    </sect2>
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun    <sect2>
627*4882a593Smuzhiyun      <title>General bus probe</title>
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun      <para>
630*4882a593Smuzhiyun    This is done at the start of the first server generation only.
631*4882a593Smuzhiyun      </para>
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun      <para>
634*4882a593Smuzhiyun    In the case of ix86 machines, this will be a general PCI probe.
635*4882a593Smuzhiyun    The full information obtained here will be available to the drivers.
636*4882a593Smuzhiyun    This information persists for the life of the Xserver.  In the PCI
637*4882a593Smuzhiyun    case, the PCI information for all video cards found is available by
638*4882a593Smuzhiyun    calling <function>xf86GetPciVideoInfo()</function>.
639*4882a593Smuzhiyun      </para>
640*4882a593Smuzhiyun
641*4882a593Smuzhiyun      <blockquote><para>
642*4882a593Smuzhiyun	  <programlisting>
643*4882a593Smuzhiyun    pciVideoPtr *xf86GetPciVideoInfo(void);
644*4882a593Smuzhiyun	  </programlisting>
645*4882a593Smuzhiyun	  <blockquote><para>
646*4882a593Smuzhiyun	returns a pointer to a list of pointers to
647*4882a593Smuzhiyun	<structname>pciVideoRec</structname> entries, of which there is one for
648*4882a593Smuzhiyun	each detected PCI video card.  The list is terminated with a
649*4882a593Smuzhiyun	<constant>NULL</constant> pointer.  If no PCI video cards were
650*4882a593Smuzhiyun	detected, the return value is <constant>NULL</constant>.
651*4882a593Smuzhiyun
652*4882a593Smuzhiyun	    </para></blockquote>
653*4882a593Smuzhiyun	</para></blockquote>
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun      <para>
656*4882a593Smuzhiyun    After the bus probe, the resource broker is initialised.
657*4882a593Smuzhiyun      </para>
658*4882a593Smuzhiyun    </sect2>
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun    <sect2>
662*4882a593Smuzhiyun      <title>Load initial set of modules</title>
663*4882a593Smuzhiyun
664*4882a593Smuzhiyun      <para>
665*4882a593Smuzhiyun    This is done at the start of the first server generation only.
666*4882a593Smuzhiyun      </para>
667*4882a593Smuzhiyun
668*4882a593Smuzhiyun      <para>
669*4882a593Smuzhiyun    The next set of modules loaded are those specified explicitly in the
670*4882a593Smuzhiyun    &k.module; section of the config file.
671*4882a593Smuzhiyun      </para>
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun      <para>
674*4882a593Smuzhiyun    The final set of initial modules are the driver modules referenced
675*4882a593Smuzhiyun    by the active &k.device; and &k.inputdevice; sections in the config
676*4882a593Smuzhiyun    file.  Each of these modules is loaded exactly once.
677*4882a593Smuzhiyun      </para>
678*4882a593Smuzhiyun    </sect2>
679*4882a593Smuzhiyun
680*4882a593Smuzhiyun
681*4882a593Smuzhiyun    <sect2>
682*4882a593Smuzhiyun      <title>Register Video and Input Drivers</title>
683*4882a593Smuzhiyun
684*4882a593Smuzhiyun      <para>
685*4882a593Smuzhiyun    This is done at the start of the first server generation only.
686*4882a593Smuzhiyun      </para>
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun      <para>
689*4882a593Smuzhiyun    When a driver module is loaded, the loader calls its
690*4882a593Smuzhiyun    <function>Setup</function> function.  For video drivers, this function
691*4882a593Smuzhiyun    calls <function>xf86AddDriver()</function> to register the driver's
692*4882a593Smuzhiyun    <structname>DriverRec</structname>, which contains a small set of essential
693*4882a593Smuzhiyun    details and driver entry points required during the early phase of
694*4882a593Smuzhiyun    <function>InitOutput()</function>.  <function>xf86AddDriver()</function>
695*4882a593Smuzhiyun    adds it to the global <varname>xf86DriverList[]</varname> array.
696*4882a593Smuzhiyun      </para>
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun      <para>
699*4882a593Smuzhiyun    The <structname>DriverRec</structname> contains the driver canonical name,
700*4882a593Smuzhiyun    the <function>Identify()</function>,
701*4882a593Smuzhiyun    <function>Probe()</function> and <function>AvailableOptions()</function>
702*4882a593Smuzhiyun    function entry points as well as a pointer
703*4882a593Smuzhiyun    to the driver's module (as returned from the loader when the driver
704*4882a593Smuzhiyun    was loaded) and a reference count which keeps track of how many
705*4882a593Smuzhiyun    screens are using the driver.  The entry driver entry points are
706*4882a593Smuzhiyun    those required prior to the driver allocating and filling in its
707*4882a593Smuzhiyun    <structname>ScrnInfoRec</structname>.
708*4882a593Smuzhiyun      </para>
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun      <para>
711*4882a593Smuzhiyun    For a static server, the <varname>xf86DriverList[]</varname> array is
712*4882a593Smuzhiyun    initialised at build time, and the loading of modules is not done.
713*4882a593Smuzhiyun      </para>
714*4882a593Smuzhiyun
715*4882a593Smuzhiyun      <para>
716*4882a593Smuzhiyun    A similar procedure is used for input drivers.  The input driver's
717*4882a593Smuzhiyun    <function>Setup</function> function calls
718*4882a593Smuzhiyun    <function>xf86AddInputDriver()</function> to register the driver's
719*4882a593Smuzhiyun    <structname>InputDriverRec</structname>, which contains a small set of
720*4882a593Smuzhiyun    essential details and driver entry points required during the early
721*4882a593Smuzhiyun    phase of <function>InitInput()</function>.
722*4882a593Smuzhiyun    <function>xf86AddInputDriver()</function> adds it to the global
723*4882a593Smuzhiyun    <varname>xf86InputDriverList[]</varname> array.  For a static server,
724*4882a593Smuzhiyun    the <varname>xf86InputDriverList[]</varname> array is initialised at
725*4882a593Smuzhiyun    build time.
726*4882a593Smuzhiyun      </para>
727*4882a593Smuzhiyun
728*4882a593Smuzhiyun      <para>
729*4882a593Smuzhiyun    Both the <varname>xf86DriverList[]</varname> and
730*4882a593Smuzhiyun    <varname>xf86InputDriverList[]</varname> arrays have been initialised
731*4882a593Smuzhiyun    by the end of this stage.
732*4882a593Smuzhiyun      </para>
733*4882a593Smuzhiyun
734*4882a593Smuzhiyun      <para>
735*4882a593Smuzhiyun    Once all the drivers are registered, their
736*4882a593Smuzhiyun    <function>ChipIdentify()</function> functions are called.
737*4882a593Smuzhiyun      </para>
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun      <blockquote><para>
740*4882a593Smuzhiyun	  <programlisting>
741*4882a593Smuzhiyun    void ChipIdentify(int flags);
742*4882a593Smuzhiyun	  </programlisting>
743*4882a593Smuzhiyun	  <blockquote><para>
744*4882a593Smuzhiyun      This is expected to print a message indicating the driver name,
745*4882a593Smuzhiyun      a short summary of what it supports, and a list of the chipset
746*4882a593Smuzhiyun      names that it supports.  It may use the xf86PrintChipsets() helper
747*4882a593Smuzhiyun      to do this.
748*4882a593Smuzhiyun	    </para></blockquote>
749*4882a593Smuzhiyun	</para></blockquote>
750*4882a593Smuzhiyun
751*4882a593Smuzhiyun      <blockquote><para>
752*4882a593Smuzhiyun	  <programlisting>
753*4882a593Smuzhiyun    void xf86PrintChipsets(const char *drvname, const char *drvmsg,
754*4882a593Smuzhiyun                           SymTabPtr chips);
755*4882a593Smuzhiyun	  </programlisting>
756*4882a593Smuzhiyun	  <blockquote><para>
757*4882a593Smuzhiyun      This function provides an easy way for a driver's ChipIdentify
758*4882a593Smuzhiyun      function to format the identification message.
759*4882a593Smuzhiyun	    </para></blockquote>
760*4882a593Smuzhiyun	</para></blockquote>
761*4882a593Smuzhiyun    </sect2>
762*4882a593Smuzhiyun
763*4882a593Smuzhiyun    <sect2>
764*4882a593Smuzhiyun      <title>Initialise Access Control</title>
765*4882a593Smuzhiyun
766*4882a593Smuzhiyun      <para>
767*4882a593Smuzhiyun    This is done at the start of the first server generation only.
768*4882a593Smuzhiyun      </para>
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun      <para>
771*4882a593Smuzhiyun    The Resource Access Control (RAC) subsystem is initialised before
772*4882a593Smuzhiyun    calling any driver functions that may access hardware.  All generic
773*4882a593Smuzhiyun    bus information is probed and saved (for restoration later).  All
774*4882a593Smuzhiyun    (shared resource) video devices are disabled at the generic bus
775*4882a593Smuzhiyun    level, and a probe is done to find the <quote>primary</quote> video device.  These
776*4882a593Smuzhiyun    devices remain disabled for the next step.
777*4882a593Smuzhiyun      </para>
778*4882a593Smuzhiyun    </sect2>
779*4882a593Smuzhiyun
780*4882a593Smuzhiyun
781*4882a593Smuzhiyun    <sect2 id="probe">
782*4882a593Smuzhiyun      <title>Video Driver Probe</title>
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun      <para>
785*4882a593Smuzhiyun    This is done at the start of the first server generation only.  The
786*4882a593Smuzhiyun    <function>ChipProbe()</function> function of each registered video driver
787*4882a593Smuzhiyun    is called.
788*4882a593Smuzhiyun      </para>
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun      <blockquote><para>
791*4882a593Smuzhiyun	  <programlisting>
792*4882a593Smuzhiyun    Bool ChipProbe(DriverPtr drv, int flags);
793*4882a593Smuzhiyun	  </programlisting>
794*4882a593Smuzhiyun	  <blockquote><para>
795*4882a593Smuzhiyun      The purpose of this is to identify all instances of hardware
796*4882a593Smuzhiyun      supported by the driver.  The flags value is currently either 0,
797*4882a593Smuzhiyun      <constant>PROBE_DEFAULT</constant> or <constant>PROBE_DETECT</constant>.
798*4882a593Smuzhiyun      <constant>PROBE_DETECT</constant> is used if "-configure" or "-probe"
799*4882a593Smuzhiyun      command line arguments are given and indicates to the
800*4882a593Smuzhiyun      <function>Probe()</function> function that it should not configure the
801*4882a593Smuzhiyun      bus entities and that no xorg.conf information is available.
802*4882a593Smuzhiyun	    </para>
803*4882a593Smuzhiyun
804*4882a593Smuzhiyun	  <para>
805*4882a593Smuzhiyun      The probe must find the active device sections that match the
806*4882a593Smuzhiyun      driver by calling <function>xf86MatchDevice()</function>.  The number
807*4882a593Smuzhiyun      of matches found limits the maximum number of instances for this
808*4882a593Smuzhiyun      driver.  If no matches are found, the function should return
809*4882a593Smuzhiyun      <constant>FALSE</constant> immediately.
810*4882a593Smuzhiyun	  </para>
811*4882a593Smuzhiyun
812*4882a593Smuzhiyun	<para>
813*4882a593Smuzhiyun      Devices that cannot be identified by using device-independent
814*4882a593Smuzhiyun      methods should be probed at this stage (keeping in mind that access
815*4882a593Smuzhiyun      to all resources that can be disabled in a device-independent way
816*4882a593Smuzhiyun      are disabled during this phase).  The probe must be a minimal
817*4882a593Smuzhiyun      probe.  It should just determine if there is a card present that
818*4882a593Smuzhiyun      the driver can drive.  It should use the least intrusive probe
819*4882a593Smuzhiyun      methods possible.  It must not do anything that is not essential,
820*4882a593Smuzhiyun      like probing for other details such as the amount of memory
821*4882a593Smuzhiyun      installed, etc.  It is recommended that the
822*4882a593Smuzhiyun      <function>xf86MatchPciInstances()</function> helper function be used
823*4882a593Smuzhiyun      for identifying matching PCI devices
824*4882a593Smuzhiyun      (see the <link linkend="rac">RAC</link> section).  These helpers also
825*4882a593Smuzhiyun      checks and claims the appropriate entity.  When not using the
826*4882a593Smuzhiyun      helper, that should be done with <function>xf86CheckPciSlot()</function>
827*4882a593Smuzhiyun      and <function>xf86ClaimPciSlot()</function> for PCI devices (see the
828*4882a593Smuzhiyun      <link linkend="rac">RAC</link> section).
829*4882a593Smuzhiyun	</para>
830*4882a593Smuzhiyun
831*4882a593Smuzhiyun	<para>
832*4882a593Smuzhiyun      The probe must register all non-relocatable resources at this
833*4882a593Smuzhiyun      stage.  If a resource conflict is found between exclusive resources
834*4882a593Smuzhiyun      the driver will fail immediately.  This is usually best done with
835*4882a593Smuzhiyun      the <function>xf86ConfigPciEntity()</function> helper function
836*4882a593Smuzhiyun      for PCI.
837*4882a593Smuzhiyun        </para>
838*4882a593Smuzhiyun
839*4882a593Smuzhiyun	<para>
840*4882a593Smuzhiyun      If a chipset is specified in an active device section which the
841*4882a593Smuzhiyun      driver considers relevant (ie it has no driver specified, or the
842*4882a593Smuzhiyun      driver specified matches the driver doing the probe), the Probe
843*4882a593Smuzhiyun      must return <constant>FALSE</constant> if the chipset doesn't match
844*4882a593Smuzhiyun      one supported by the driver.
845*4882a593Smuzhiyun	</para>
846*4882a593Smuzhiyun
847*4882a593Smuzhiyun	<para>
848*4882a593Smuzhiyun      If there are no active device sections that the driver considers
849*4882a593Smuzhiyun      relevant, it must return <constant>FALSE</constant>.
850*4882a593Smuzhiyun	</para>
851*4882a593Smuzhiyun
852*4882a593Smuzhiyun	<para>
853*4882a593Smuzhiyun      Allocate a <structname>ScrnInfoRec</structname> for each active instance of the
854*4882a593Smuzhiyun      hardware found, and fill in the basic information, including the
855*4882a593Smuzhiyun      other driver entry points.   This is best done with the
856*4882a593Smuzhiyun      <function>xf86ConfigPciEntity()</function> for PCI instances.
857*4882a593Smuzhiyun      These functions allocate a <structname>ScrnInfoRec</structname> for active
858*4882a593Smuzhiyun      entities. Optionally <function>xf86AllocateScreen()</function>
859*4882a593Smuzhiyun      function may also be used to allocate the <structname>ScrnInfoRec</structname>.
860*4882a593Smuzhiyun      Any of these functions take care of initialising fields to defined
861*4882a593Smuzhiyun      <quote>unused</quote> values.
862*4882a593Smuzhiyun	</para>
863*4882a593Smuzhiyun
864*4882a593Smuzhiyun	<para>
865*4882a593Smuzhiyun      Claim the entities for each instance of the hardware found.  This
866*4882a593Smuzhiyun      prevents other drivers from claiming the same hardware.
867*4882a593Smuzhiyun	</para>
868*4882a593Smuzhiyun
869*4882a593Smuzhiyun	<para>
870*4882a593Smuzhiyun      Must leave hardware in the same state it found it in, and must not
871*4882a593Smuzhiyun      do any hardware initialisation.
872*4882a593Smuzhiyun	</para>
873*4882a593Smuzhiyun
874*4882a593Smuzhiyun	<para>
875*4882a593Smuzhiyun      All detection can be overridden via the config file, and that
876*4882a593Smuzhiyun      parsed information is available to the driver at this stage.
877*4882a593Smuzhiyun	</para>
878*4882a593Smuzhiyun
879*4882a593Smuzhiyun	<para>
880*4882a593Smuzhiyun      Returns <constant>TRUE</constant> if one or more instances are found,
881*4882a593Smuzhiyun      and <constant>FALSE</constant> otherwise.
882*4882a593Smuzhiyun	</para>
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun	  </blockquote></para></blockquote>
885*4882a593Smuzhiyun
886*4882a593Smuzhiyun      <blockquote><para>
887*4882a593Smuzhiyun	  <programlisting>
888*4882a593Smuzhiyun    int xf86MatchDevice(const char *drivername,
889*4882a593Smuzhiyun                        GDevPtr **driversectlist)
890*4882a593Smuzhiyun	  </programlisting>
891*4882a593Smuzhiyun	  <blockquote><para>
892*4882a593Smuzhiyun      This function takes the name of the driver and returns via
893*4882a593Smuzhiyun      <parameter>driversectlist</parameter> a list of device sections that
894*4882a593Smuzhiyun      match the driver name.  The function return value is the number
895*4882a593Smuzhiyun      of matches found.  If a fatal error is encountered the return
896*4882a593Smuzhiyun      value is <literal>-1</literal>.
897*4882a593Smuzhiyun	    </para>
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun	    <para>
900*4882a593Smuzhiyun      The caller should use <function>xfree()</function> to free
901*4882a593Smuzhiyun      <parameter>*driversectlist</parameter> when it is no longer needed.
902*4882a593Smuzhiyun	    </para>
903*4882a593Smuzhiyun
904*4882a593Smuzhiyun	  </blockquote></para></blockquote>
905*4882a593Smuzhiyun
906*4882a593Smuzhiyun      <blockquote><para>
907*4882a593Smuzhiyun	  <programlisting>
908*4882a593Smuzhiyun    ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags)
909*4882a593Smuzhiyun	  </programlisting>
910*4882a593Smuzhiyun	  <blockquote><para>
911*4882a593Smuzhiyun      This function allocates a new <structname>ScrnInfoRec</structname> in the
912*4882a593Smuzhiyun      <varname>xf86Screens[]</varname> array.  This function is normally
913*4882a593Smuzhiyun      called by the video driver <function>ChipProbe()</function> functions.
914*4882a593Smuzhiyun      The return value is a pointer to the newly allocated
915*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname>.  The <structfield>scrnIndex</structfield>,
916*4882a593Smuzhiyun      <structfield>origIndex</structfield>, <structfield>module</structfield> and
917*4882a593Smuzhiyun      <structfield>drv</structfield> fields are initialised.  The reference count
918*4882a593Smuzhiyun      in <parameter>drv</parameter> is incremented.  The storage for any
919*4882a593Smuzhiyun      currently allocated <quote>privates</quote> pointers is also allocated and
920*4882a593Smuzhiyun      the <structfield>privates</structfield> field initialised (the privates data
921*4882a593Smuzhiyun      is of course not allocated or initialised).  This function never
922*4882a593Smuzhiyun      returns on failure.  If the allocation fails, the server exits
923*4882a593Smuzhiyun      with a fatal error.  The flags value is not currently used, and
924*4882a593Smuzhiyun      should be set to zero.
925*4882a593Smuzhiyun	    </para></blockquote>
926*4882a593Smuzhiyun	</para></blockquote>
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun      <para>
929*4882a593Smuzhiyun    At the completion of this, a list of <structname>ScrnInfoRecs</structname>
930*4882a593Smuzhiyun    have been allocated in the <varname>xf86Screens[]</varname> array, and
931*4882a593Smuzhiyun    the associated entities and fixed resources have been claimed.  The
932*4882a593Smuzhiyun    following <structname>ScrnInfoRec</structname> fields must be initialised at
933*4882a593Smuzhiyun    this point:
934*4882a593Smuzhiyun
935*4882a593Smuzhiyun	<literallayout>
936*4882a593Smuzhiyun          driverVersion
937*4882a593Smuzhiyun          driverName
938*4882a593Smuzhiyun          scrnIndex(*)
939*4882a593Smuzhiyun          origIndex(*)
940*4882a593Smuzhiyun          drv(*)
941*4882a593Smuzhiyun          module(*)
942*4882a593Smuzhiyun          name
943*4882a593Smuzhiyun          Probe
944*4882a593Smuzhiyun          PreInit
945*4882a593Smuzhiyun          ScreenInit
946*4882a593Smuzhiyun          EnterVT
947*4882a593Smuzhiyun          LeaveVT
948*4882a593Smuzhiyun          numEntities
949*4882a593Smuzhiyun          entityList
950*4882a593Smuzhiyun          access
951*4882a593Smuzhiyun	</literallayout>
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun    <literal>(*)</literal> These are initialised when the <structname>ScrnInfoRec</structname>
954*4882a593Smuzhiyun    is allocated, and not explicitly by the driver.
955*4882a593Smuzhiyun      </para>
956*4882a593Smuzhiyun
957*4882a593Smuzhiyun      <para>
958*4882a593Smuzhiyun    The following <structname>ScrnInfoRec</structname> fields must be initialised
959*4882a593Smuzhiyun    if the driver is going to use them:
960*4882a593Smuzhiyun
961*4882a593Smuzhiyun	<literallayout>
962*4882a593Smuzhiyun          SwitchMode
963*4882a593Smuzhiyun          AdjustFrame
964*4882a593Smuzhiyun          FreeScreen
965*4882a593Smuzhiyun          ValidMode
966*4882a593Smuzhiyun	</literallayout>
967*4882a593Smuzhiyun      </para>
968*4882a593Smuzhiyun    </sect2>
969*4882a593Smuzhiyun
970*4882a593Smuzhiyun    <sect2>
971*4882a593Smuzhiyun      <title>Matching Screens</title>
972*4882a593Smuzhiyun
973*4882a593Smuzhiyun      <para>
974*4882a593Smuzhiyun    This is done at the start of the first server generation only.
975*4882a593Smuzhiyun      </para>
976*4882a593Smuzhiyun
977*4882a593Smuzhiyun      <para>
978*4882a593Smuzhiyun    After the Probe phase is finished, there will be some number of
979*4882a593Smuzhiyun    <structname>ScrnInfoRec</structname>s.  These are then matched with the active
980*4882a593Smuzhiyun    &k.screen; sections in the xorg.conf, and those not having an active
981*4882a593Smuzhiyun    &k.screen; section are deleted.  If the number of remaining screens
982*4882a593Smuzhiyun    is 0, <function>InitOutput()</function> sets
983*4882a593Smuzhiyun    <structfield>screenInfo.numScreens</structfield> to <constant>0</constant> and
984*4882a593Smuzhiyun    returns.
985*4882a593Smuzhiyun      </para>
986*4882a593Smuzhiyun
987*4882a593Smuzhiyun      <para>
988*4882a593Smuzhiyun    At this point the following fields of the <structname>ScrnInfoRec</structname>s
989*4882a593Smuzhiyun    must be initialised:
990*4882a593Smuzhiyun
991*4882a593Smuzhiyun	<literallayout>
992*4882a593Smuzhiyun          confScreen
993*4882a593Smuzhiyun	</literallayout>
994*4882a593Smuzhiyun      </para>
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun    </sect2>
997*4882a593Smuzhiyun
998*4882a593Smuzhiyun    <sect2>
999*4882a593Smuzhiyun      <title>Allocate non-conflicting resources</title>
1000*4882a593Smuzhiyun
1001*4882a593Smuzhiyun      <para>
1002*4882a593Smuzhiyun    This is done at the start of the first server generation only.
1003*4882a593Smuzhiyun      </para>
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun      <para>
1006*4882a593Smuzhiyun    Before calling the drivers again, the resource information collected
1007*4882a593Smuzhiyun    from the Probe phase is processed.  This includes checking the extent
1008*4882a593Smuzhiyun    of PCI resources for the probed devices, and resolving any conflicts
1009*4882a593Smuzhiyun    in the relocatable PCI resources.  It also reports conflicts, checks
1010*4882a593Smuzhiyun    bus routing issues, and anything else that is needed to enable the
1011*4882a593Smuzhiyun    entities for the next phase.
1012*4882a593Smuzhiyun      </para>
1013*4882a593Smuzhiyun
1014*4882a593Smuzhiyun      <para>
1015*4882a593Smuzhiyun    If any drivers registered an <function>EntityInit()</function> function
1016*4882a593Smuzhiyun    during the Probe phase, then they are called here.
1017*4882a593Smuzhiyun      </para>
1018*4882a593Smuzhiyun
1019*4882a593Smuzhiyun    </sect2>
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun    <sect2>
1022*4882a593Smuzhiyun      <title>Sort the Screens and pre-check Monitor Information</title>
1023*4882a593Smuzhiyun
1024*4882a593Smuzhiyun      <para>
1025*4882a593Smuzhiyun    This is done at the start of the first server generation only.
1026*4882a593Smuzhiyun      </para>
1027*4882a593Smuzhiyun
1028*4882a593Smuzhiyun      <para>
1029*4882a593Smuzhiyun    The list of screens is sorted to match the ordering requested in the
1030*4882a593Smuzhiyun    config file.
1031*4882a593Smuzhiyun      </para>
1032*4882a593Smuzhiyun
1033*4882a593Smuzhiyun      <para>
1034*4882a593Smuzhiyun    The list of modes for each active monitor is checked against the
1035*4882a593Smuzhiyun    monitor's parameters.  Invalid modes are pruned.
1036*4882a593Smuzhiyun      </para>
1037*4882a593Smuzhiyun
1038*4882a593Smuzhiyun    </sect2>
1039*4882a593Smuzhiyun
1040*4882a593Smuzhiyun    <sect2>
1041*4882a593Smuzhiyun      <title>PreInit</title>
1042*4882a593Smuzhiyun
1043*4882a593Smuzhiyun      <para>
1044*4882a593Smuzhiyun    This is done at the start of the first server generation only.
1045*4882a593Smuzhiyun      </para>
1046*4882a593Smuzhiyun
1047*4882a593Smuzhiyun      <para>
1048*4882a593Smuzhiyun    For each <structname>ScrnInfoRec</structname>, enable access to the screens entities and call
1049*4882a593Smuzhiyun    the <function>ChipPreInit()</function> function.
1050*4882a593Smuzhiyun      </para>
1051*4882a593Smuzhiyun
1052*4882a593Smuzhiyun      <blockquote><para>
1053*4882a593Smuzhiyun	  <programlisting>
1054*4882a593Smuzhiyun    Bool ChipPreInit(ScrnInfoRec screen, int flags);
1055*4882a593Smuzhiyun	  </programlisting>
1056*4882a593Smuzhiyun	  <blockquote><para>
1057*4882a593Smuzhiyun      The purpose of this function is to find out all the information
1058*4882a593Smuzhiyun      required to determine if the configuration is usable, and to
1059*4882a593Smuzhiyun      initialise those parts of the <structname>ScrnInfoRec</structname> that
1060*4882a593Smuzhiyun      can be set once at the beginning of the first server generation.
1061*4882a593Smuzhiyun	    </para>
1062*4882a593Smuzhiyun
1063*4882a593Smuzhiyun	    <para>
1064*4882a593Smuzhiyun      The number of entities registered for the screen should be checked
1065*4882a593Smuzhiyun      against the expected number (most drivers expect only one).  The
1066*4882a593Smuzhiyun      entity information for each of them should be retrieved (with
1067*4882a593Smuzhiyun      <function>xf86GetEntityInfo()</function>) and checked for the correct
1068*4882a593Smuzhiyun      bus type and that none of the sharable resources registered during
1069*4882a593Smuzhiyun      the Probe phase was rejected.
1070*4882a593Smuzhiyun	    </para>
1071*4882a593Smuzhiyun
1072*4882a593Smuzhiyun	    <para>
1073*4882a593Smuzhiyun      Access to resources for the entities that can be controlled in a
1074*4882a593Smuzhiyun      device-independent way are enabled before this function is called.
1075*4882a593Smuzhiyun      If the driver needs to access any resources that it has disabled
1076*4882a593Smuzhiyun      in an <function>EntityInit()</function> function that it registered,
1077*4882a593Smuzhiyun      then it may enable them here providing that it disables them before
1078*4882a593Smuzhiyun      this function returns.
1079*4882a593Smuzhiyun	    </para>
1080*4882a593Smuzhiyun
1081*4882a593Smuzhiyun	    <para>
1082*4882a593Smuzhiyun      This includes probing for video memory, clocks, ramdac, and all
1083*4882a593Smuzhiyun      other HW info that is needed.  It includes determining the
1084*4882a593Smuzhiyun      depth/bpp/visual and related info.  It includes validating and
1085*4882a593Smuzhiyun      determining the set of video modes that will be used (and anything
1086*4882a593Smuzhiyun      that is required to determine that).
1087*4882a593Smuzhiyun	    </para>
1088*4882a593Smuzhiyun
1089*4882a593Smuzhiyun	    <para>
1090*4882a593Smuzhiyun      This information should be determined in the least intrusive way
1091*4882a593Smuzhiyun      possible.  The state of the HW must remain unchanged by this
1092*4882a593Smuzhiyun      function.  Although video memory (including MMIO) may be mapped
1093*4882a593Smuzhiyun      within this function, it must be unmapped before returning.  Driver
1094*4882a593Smuzhiyun      specific information should be stored in a structure hooked into
1095*4882a593Smuzhiyun      the <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield>
1096*4882a593Smuzhiyun      field.  Any other modules which require persistent data (ie data
1097*4882a593Smuzhiyun      that persists across server generations) should be initialised in
1098*4882a593Smuzhiyun      this function, and they should allocate a <quote>privates</quote> index to
1099*4882a593Smuzhiyun      hook their data into by calling
1100*4882a593Smuzhiyun      <function>xf86AllocateScrnInfoPrivateIndex()</function>.  The <quote>privates</quote>
1101*4882a593Smuzhiyun      data is persistent.
1102*4882a593Smuzhiyun	    </para>
1103*4882a593Smuzhiyun
1104*4882a593Smuzhiyun	    <para>
1105*4882a593Smuzhiyun      Helper functions for some of these things are provided at the
1106*4882a593Smuzhiyun      XFree86 common level, and the driver can choose to make use of
1107*4882a593Smuzhiyun      them.
1108*4882a593Smuzhiyun	    </para>
1109*4882a593Smuzhiyun
1110*4882a593Smuzhiyun	    <para>
1111*4882a593Smuzhiyun      Modules may be loaded at any point in this function, and all
1112*4882a593Smuzhiyun      modules that the driver will need must be loaded before the end
1113*4882a593Smuzhiyun      of this function.  Either the  <function>xf86LoadSubModule()</function>
1114*4882a593Smuzhiyun      or the <function>xf86LoadDrvSubModule()</function> function should be
1115*4882a593Smuzhiyun      used to load modules depending on whether a
1116*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname> has been set up. A driver may unload
1117*4882a593Smuzhiyun      a module within this function if it was only needed temporarily,
1118*4882a593Smuzhiyun      and the <function>xf86UnloadSubModule()</function> function should be used
1119*4882a593Smuzhiyun      to do that.  Otherwise there is no need to explicitly unload modules
1120*4882a593Smuzhiyun      because the loader takes care of module dependencies and will
1121*4882a593Smuzhiyun      unload submodules automatically if/when the driver module is
1122*4882a593Smuzhiyun      unloaded.
1123*4882a593Smuzhiyun	    </para>
1124*4882a593Smuzhiyun
1125*4882a593Smuzhiyun	    <para>
1126*4882a593Smuzhiyun      The bulk of the <structname>ScrnInfoRec</structname> fields should be filled
1127*4882a593Smuzhiyun      out in this function.
1128*4882a593Smuzhiyun	    </para>
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun	    <para>
1131*4882a593Smuzhiyun      <function>ChipPreInit()</function> returns <constant>FALSE</constant> when
1132*4882a593Smuzhiyun      the configuration is unusable in some way (unsupported depth, no
1133*4882a593Smuzhiyun      valid modes, not enough video memory, etc), and <constant>TRUE</constant>
1134*4882a593Smuzhiyun      if it is usable.
1135*4882a593Smuzhiyun	    </para>
1136*4882a593Smuzhiyun
1137*4882a593Smuzhiyun	    <para>
1138*4882a593Smuzhiyun      It is expected that if the <function>ChipPreInit()</function> function
1139*4882a593Smuzhiyun      returns <constant>TRUE</constant>, then the only reasons that subsequent
1140*4882a593Smuzhiyun      stages in the driver might fail are lack or resources (like xalloc
1141*4882a593Smuzhiyun      failures).  All other possible reasons for failure should be
1142*4882a593Smuzhiyun      determined by the <function>ChipPreInit()</function> function.
1143*4882a593Smuzhiyun	    </para></blockquote>
1144*4882a593Smuzhiyun	</para></blockquote>
1145*4882a593Smuzhiyun
1146*4882a593Smuzhiyun      <para>
1147*4882a593Smuzhiyun    The <structname>ScrnInfoRec</structname>s for screens where the <function>ChipPreInit()</function> fails are removed.
1148*4882a593Smuzhiyun    If none remain, <function>InitOutput()</function> sets <structfield>screenInfo.numScreens</structfield> to <constant>0</constant> and returns.
1149*4882a593Smuzhiyun      </para>
1150*4882a593Smuzhiyun
1151*4882a593Smuzhiyun      <para>
1152*4882a593Smuzhiyun    At this point, further fields of the <structname>ScrnInfoRec</structname>s would normally be
1153*4882a593Smuzhiyun    filled in.  Most are not strictly mandatory, but many are required
1154*4882a593Smuzhiyun    by other layers and/or helper functions that the driver may choose
1155*4882a593Smuzhiyun    to use.  The documentation for those layers and helper functions
1156*4882a593Smuzhiyun    indicates which they require.
1157*4882a593Smuzhiyun      </para>
1158*4882a593Smuzhiyun
1159*4882a593Smuzhiyun      <para>
1160*4882a593Smuzhiyun    The following fields of the <structname>ScrnInfoRec</structname>s should be filled in if the
1161*4882a593Smuzhiyun    driver is going to use them:
1162*4882a593Smuzhiyun
1163*4882a593Smuzhiyun	<literallayout>
1164*4882a593Smuzhiyun          monitor
1165*4882a593Smuzhiyun          display
1166*4882a593Smuzhiyun          depth
1167*4882a593Smuzhiyun          pixmapBPP
1168*4882a593Smuzhiyun          bitsPerPixel
1169*4882a593Smuzhiyun          weight                (&gt;8bpp only)
1170*4882a593Smuzhiyun          mask                  (&gt;8bpp only)
1171*4882a593Smuzhiyun          offset                (&gt;8bpp only)
1172*4882a593Smuzhiyun          rgbBits               (8bpp only)
1173*4882a593Smuzhiyun          gamma
1174*4882a593Smuzhiyun          defaultVisual
1175*4882a593Smuzhiyun          virtualX
1176*4882a593Smuzhiyun          virtualY
1177*4882a593Smuzhiyun          displayWidth
1178*4882a593Smuzhiyun          frameX0
1179*4882a593Smuzhiyun          frameY0
1180*4882a593Smuzhiyun          frameX1
1181*4882a593Smuzhiyun          frameY1
1182*4882a593Smuzhiyun          zoomLocked
1183*4882a593Smuzhiyun          modePool
1184*4882a593Smuzhiyun          modes
1185*4882a593Smuzhiyun          currentMode
1186*4882a593Smuzhiyun          progClock             (TRUE if clock is programmable)
1187*4882a593Smuzhiyun          chipset
1188*4882a593Smuzhiyun          ramdac
1189*4882a593Smuzhiyun          clockchip
1190*4882a593Smuzhiyun          numClocks             (if not programmable)
1191*4882a593Smuzhiyun          clock[]               (if not programmable)
1192*4882a593Smuzhiyun          videoRam
1193*4882a593Smuzhiyun          memBase
1194*4882a593Smuzhiyun          driverPrivate
1195*4882a593Smuzhiyun          chipID
1196*4882a593Smuzhiyun          chipRev
1197*4882a593Smuzhiyun	</literallayout>
1198*4882a593Smuzhiyun      </para>
1199*4882a593Smuzhiyun
1200*4882a593Smuzhiyun      <blockquote><para>
1201*4882a593Smuzhiyun	  <programlisting>
1202*4882a593Smuzhiyun    pointer xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name);
1203*4882a593Smuzhiyun      and
1204*4882a593Smuzhiyun    pointer xf86LoadDrvSubModule(DriverPtr drv, const char *name);
1205*4882a593Smuzhiyun	  </programlisting>
1206*4882a593Smuzhiyun	  <blockquote><para>
1207*4882a593Smuzhiyun      Load a module that a driver depends on.  This function loads the
1208*4882a593Smuzhiyun      module <parameter>name</parameter> as a sub module of the driver.  The
1209*4882a593Smuzhiyun      return value is a handle identifying the new module.  If the load
1210*4882a593Smuzhiyun      fails, the return value will be <constant>NULL</constant>.  If a driver
1211*4882a593Smuzhiyun      needs to explicitly unload a module it has loaded in this way,
1212*4882a593Smuzhiyun      the return value must be saved and passed to
1213*4882a593Smuzhiyun      <function>xf86UnloadSubModule()</function> when unloading.
1214*4882a593Smuzhiyun
1215*4882a593Smuzhiyun	    </para></blockquote>
1216*4882a593Smuzhiyun	</para></blockquote>
1217*4882a593Smuzhiyun
1218*4882a593Smuzhiyun      <blockquote><para>
1219*4882a593Smuzhiyun	  <programlisting>
1220*4882a593Smuzhiyun    void xf86UnloadSubModule(pointer module);
1221*4882a593Smuzhiyun	  </programlisting>
1222*4882a593Smuzhiyun	  <blockquote><para>
1223*4882a593Smuzhiyun      Unloads the module referenced by <parameter>module</parameter>.
1224*4882a593Smuzhiyun      <parameter>module</parameter> should be a pointer returned previously
1225*4882a593Smuzhiyun      by <function>xf86LoadSubModule()</function> or
1226*4882a593Smuzhiyun      <function>xf86LoadDrvSubModule()</function> .
1227*4882a593Smuzhiyun
1228*4882a593Smuzhiyun	    </para></blockquote>
1229*4882a593Smuzhiyun	</para></blockquote>
1230*4882a593Smuzhiyun    </sect2>
1231*4882a593Smuzhiyun
1232*4882a593Smuzhiyun    <sect2>
1233*4882a593Smuzhiyun      <title>Cleaning up Unused Drivers</title>
1234*4882a593Smuzhiyun
1235*4882a593Smuzhiyun      <para>
1236*4882a593Smuzhiyun    At this point it is known which screens will be in use, and which
1237*4882a593Smuzhiyun    drivers are being used.  Unreferenced drivers (and modules they
1238*4882a593Smuzhiyun    may have loaded) are unloaded here.
1239*4882a593Smuzhiyun      </para>
1240*4882a593Smuzhiyun
1241*4882a593Smuzhiyun    </sect2>
1242*4882a593Smuzhiyun
1243*4882a593Smuzhiyun    <sect2>
1244*4882a593Smuzhiyun      <title>Consistency Checks</title>
1245*4882a593Smuzhiyun
1246*4882a593Smuzhiyun      <para>
1247*4882a593Smuzhiyun    The parameters that must be global to the server, like pixmap formats,
1248*4882a593Smuzhiyun    bitmap bit order, bitmap scanline unit and image byte order are
1249*4882a593Smuzhiyun    compared for each of the screens.  If a mismatch is found, the server
1250*4882a593Smuzhiyun    exits with an appropriate message.
1251*4882a593Smuzhiyun      </para>
1252*4882a593Smuzhiyun
1253*4882a593Smuzhiyun    </sect2>
1254*4882a593Smuzhiyun
1255*4882a593Smuzhiyun    <sect2>
1256*4882a593Smuzhiyun      <title>Check if Resource Control is Needed</title>
1257*4882a593Smuzhiyun
1258*4882a593Smuzhiyun      <para>
1259*4882a593Smuzhiyun    Determine if resource access control is needed.  This is the case
1260*4882a593Smuzhiyun    if more than one screen is used.  If necessary the RAC wrapper module
1261*4882a593Smuzhiyun    is loaded.
1262*4882a593Smuzhiyun      </para>
1263*4882a593Smuzhiyun    </sect2>
1264*4882a593Smuzhiyun
1265*4882a593Smuzhiyun    <sect2>
1266*4882a593Smuzhiyun      <title>AddScreen (ScreenInit)</title>
1267*4882a593Smuzhiyun
1268*4882a593Smuzhiyun      <para>
1269*4882a593Smuzhiyun    At this point, the valid screens are known.
1270*4882a593Smuzhiyun    <function>AddScreen()</function> is called for each of them, passing
1271*4882a593Smuzhiyun    <function>ChipScreenInit()</function> as the argument.
1272*4882a593Smuzhiyun    <function>AddScreen()</function> is a DIX function that allocates a new
1273*4882a593Smuzhiyun    <structfield>screenInfo.screen[]</structfield> entry (aka
1274*4882a593Smuzhiyun    <varname>pScreen</varname>), and does some basic initialisation of it.
1275*4882a593Smuzhiyun    It then calls the <function>ChipScreenInit()</function> function, with
1276*4882a593Smuzhiyun    <parameter>pScreen</parameter> as one of its arguments.  If
1277*4882a593Smuzhiyun    <function>ChipScreenInit()</function> returns <constant>FALSE</constant>,
1278*4882a593Smuzhiyun    <function>AddScreen()</function> returns <constant>-1</constant>.  Otherwise
1279*4882a593Smuzhiyun    it returns the index of the screen.  <function>AddScreen()</function>
1280*4882a593Smuzhiyun    should only fail because of programming errors or failure to allocate
1281*4882a593Smuzhiyun    resources (like memory).  All configuration problems should be
1282*4882a593Smuzhiyun    detected BEFORE this point.
1283*4882a593Smuzhiyun      </para>
1284*4882a593Smuzhiyun
1285*4882a593Smuzhiyun      <blockquote><para>
1286*4882a593Smuzhiyun	  <programlisting>
1287*4882a593Smuzhiyun    Bool ChipScreenInit(ScreenPtr pScreen,
1288*4882a593Smuzhiyun                        int argc, char **argv);
1289*4882a593Smuzhiyun	  </programlisting>
1290*4882a593Smuzhiyun	  <blockquote><para>
1291*4882a593Smuzhiyun      This is called at the start of each server generation.
1292*4882a593Smuzhiyun	    </para>
1293*4882a593Smuzhiyun
1294*4882a593Smuzhiyun	    <para>
1295*4882a593Smuzhiyun      Fill in all of <parameter>pScreen</parameter>, possibly doing some of
1296*4882a593Smuzhiyun      this by calling ScreenInit functions from other layers like mi,
1297*4882a593Smuzhiyun      framebuffers (cfb, etc), and extensions.
1298*4882a593Smuzhiyun	    </para>
1299*4882a593Smuzhiyun
1300*4882a593Smuzhiyun	    <para>
1301*4882a593Smuzhiyun      Decide which operations need to be placed under resource access
1302*4882a593Smuzhiyun      control.  The classes of operations are the frame buffer operations
1303*4882a593Smuzhiyun      (<constant>RAC_FB</constant>), the pointer operations
1304*4882a593Smuzhiyun      (<constant>RAC_CURSOR</constant>), the viewport change operations
1305*4882a593Smuzhiyun      (<constant>RAC_VIEWPORT</constant>) and the colormap operations
1306*4882a593Smuzhiyun      (<constant>RAC_COLORMAP</constant>).  Any operation that requires
1307*4882a593Smuzhiyun      resources which might be disabled during OPERATING state should
1308*4882a593Smuzhiyun      be set to use RAC.  This can be specified separately for memory
1309*4882a593Smuzhiyun      and IO resources (the <structfield>racMemFlags</structfield> and
1310*4882a593Smuzhiyun      <structfield>racIoFlags</structfield> fields of the <structname>ScrnInfoRec</structname>
1311*4882a593Smuzhiyun      respectively).
1312*4882a593Smuzhiyun	    </para>
1313*4882a593Smuzhiyun
1314*4882a593Smuzhiyun	    <para>
1315*4882a593Smuzhiyun      Map any video memory or other memory regions.
1316*4882a593Smuzhiyun	    </para>
1317*4882a593Smuzhiyun
1318*4882a593Smuzhiyun	    <para>
1319*4882a593Smuzhiyun      Save the video card state.  Enough state must be saved so that
1320*4882a593Smuzhiyun      the original state can later be restored.
1321*4882a593Smuzhiyun	    </para>
1322*4882a593Smuzhiyun
1323*4882a593Smuzhiyun	    <para>
1324*4882a593Smuzhiyun      Initialise the initial video mode.  The <structname>ScrnInfoRec</structname>'s
1325*4882a593Smuzhiyun      <structfield>vtSema</structfield> field should be set to <constant>TRUE</constant>
1326*4882a593Smuzhiyun      just prior to changing the video hardware's state.
1327*4882a593Smuzhiyun
1328*4882a593Smuzhiyun	    </para></blockquote>
1329*4882a593Smuzhiyun	</para></blockquote>
1330*4882a593Smuzhiyun
1331*4882a593Smuzhiyun
1332*4882a593Smuzhiyun      <para>
1333*4882a593Smuzhiyun    The <function>ChipScreenInit()</function> function (or functions from other
1334*4882a593Smuzhiyun    layers that it calls) should allocate entries in the
1335*4882a593Smuzhiyun    <structname>ScreenRec</structname>'s <structfield>devPrivates</structfield> area by
1336*4882a593Smuzhiyun    calling <function>AllocateScreenPrivateIndex()</function> if it needs
1337*4882a593Smuzhiyun    per-generation storage.  Since the <structname>ScreenRec</structname>'s
1338*4882a593Smuzhiyun    <structfield>devPrivates</structfield> information is cleared for each server
1339*4882a593Smuzhiyun    generation, this is the correct place to initialise it.
1340*4882a593Smuzhiyun      </para>
1341*4882a593Smuzhiyun
1342*4882a593Smuzhiyun      <para>
1343*4882a593Smuzhiyun    After <function>AddScreen()</function> has successfully returned, the
1344*4882a593Smuzhiyun    following <structname>ScrnInfoRec</structname> fields are initialised:
1345*4882a593Smuzhiyun
1346*4882a593Smuzhiyun	<literallayout>
1347*4882a593Smuzhiyun          pScreen
1348*4882a593Smuzhiyun          racMemFlags
1349*4882a593Smuzhiyun          racIoFlags
1350*4882a593Smuzhiyun	</literallayout>
1351*4882a593Smuzhiyun      </para>
1352*4882a593Smuzhiyun
1353*4882a593Smuzhiyun      <para>
1354*4882a593Smuzhiyun    The <function>ChipScreenInit()</function> function should initialise the
1355*4882a593Smuzhiyun    <structfield>CloseScreen</structfield> and <structfield>SaveScreen</structfield> fields
1356*4882a593Smuzhiyun    of <parameter>pScreen</parameter>.  The old value of
1357*4882a593Smuzhiyun    <structfield>pScreen-&gt;CloseScreen</structfield> should be saved as part of
1358*4882a593Smuzhiyun    the driver's per-screen private data, allowing it to be called from
1359*4882a593Smuzhiyun    <function>ChipCloseScreen()</function>.  This means that the existing
1360*4882a593Smuzhiyun    <function>CloseScreen()</function> function is wrapped.
1361*4882a593Smuzhiyun      </para>
1362*4882a593Smuzhiyun    </sect2>
1363*4882a593Smuzhiyun
1364*4882a593Smuzhiyun    <sect2>
1365*4882a593Smuzhiyun      <title>Finalising RAC Initialisation</title>
1366*4882a593Smuzhiyun
1367*4882a593Smuzhiyun      <para>
1368*4882a593Smuzhiyun    After all the <function>ChipScreenInit()</function> functions have been
1369*4882a593Smuzhiyun    called, each screen has registered its RAC requirements.  This
1370*4882a593Smuzhiyun    information is used to determine which shared resources are requested
1371*4882a593Smuzhiyun    by more than one driver and set the access functions accordingly.
1372*4882a593Smuzhiyun    This is done following these rules:
1373*4882a593Smuzhiyun
1374*4882a593Smuzhiyun	<orderedlist>
1375*4882a593Smuzhiyun	  <listitem><para>
1376*4882a593Smuzhiyun	The sharable resources registered by each entity are compared.
1377*4882a593Smuzhiyun	If a resource is registered by more than one entity the entity
1378*4882a593Smuzhiyun	will be marked to indicate that it needs to share this resources
1379*4882a593Smuzhiyun	type (IO or MEM).
1380*4882a593Smuzhiyun	    </para></listitem>
1381*4882a593Smuzhiyun
1382*4882a593Smuzhiyun	  <listitem><para>
1383*4882a593Smuzhiyun        A resource marked <quote>disabled</quote> during OPERATING state will be
1384*4882a593Smuzhiyun        ignored entirely.
1385*4882a593Smuzhiyun	    </para></listitem>
1386*4882a593Smuzhiyun
1387*4882a593Smuzhiyun	  <listitem><para>
1388*4882a593Smuzhiyun	A resource marked <quote>unused</quote> will only conflict with an overlapping
1389*4882a593Smuzhiyun	resource of an other entity if the second is actually in use
1390*4882a593Smuzhiyun	during OPERATING state.
1391*4882a593Smuzhiyun	    </para></listitem>
1392*4882a593Smuzhiyun
1393*4882a593Smuzhiyun	  <listitem><para>
1394*4882a593Smuzhiyun	If an <quote>unused</quote> resource was found to conflict but the entity
1395*4882a593Smuzhiyun	does not use any other resource of this type the entire resource
1396*4882a593Smuzhiyun	type will be disabled for that entity.
1397*4882a593Smuzhiyun	    </para></listitem>
1398*4882a593Smuzhiyun	</orderedlist>
1399*4882a593Smuzhiyun      </para>
1400*4882a593Smuzhiyun
1401*4882a593Smuzhiyun    </sect2>
1402*4882a593Smuzhiyun
1403*4882a593Smuzhiyun    <sect2>
1404*4882a593Smuzhiyun      <title>Finishing InitOutput()</title>
1405*4882a593Smuzhiyun
1406*4882a593Smuzhiyun      <para>
1407*4882a593Smuzhiyun    At this point <function>InitOutput()</function> is finished, and all the
1408*4882a593Smuzhiyun    screens have been setup in their initial video mode.
1409*4882a593Smuzhiyun      </para>
1410*4882a593Smuzhiyun
1411*4882a593Smuzhiyun    </sect2>
1412*4882a593Smuzhiyun
1413*4882a593Smuzhiyun    <sect2>
1414*4882a593Smuzhiyun      <title>Mode Switching</title>
1415*4882a593Smuzhiyun
1416*4882a593Smuzhiyun      <para>
1417*4882a593Smuzhiyun    When a SwitchMode event is received, <function>ChipSwitchMode()</function>
1418*4882a593Smuzhiyun    is called (when it exists):
1419*4882a593Smuzhiyun      </para>
1420*4882a593Smuzhiyun
1421*4882a593Smuzhiyun      <blockquote><para>
1422*4882a593Smuzhiyun	  <programlisting>
1423*4882a593Smuzhiyun    Bool ChipSwitchMode(int index, DisplayModePtr mode);
1424*4882a593Smuzhiyun	  </programlisting>
1425*4882a593Smuzhiyun	  <blockquote><para>
1426*4882a593Smuzhiyun      Initialises the new mode for the screen identified by
1427*4882a593Smuzhiyun      <parameter>index;</parameter>.  The viewport may need to be adjusted
1428*4882a593Smuzhiyun      also.
1429*4882a593Smuzhiyun
1430*4882a593Smuzhiyun	    </para></blockquote>
1431*4882a593Smuzhiyun	</para></blockquote>
1432*4882a593Smuzhiyun
1433*4882a593Smuzhiyun    </sect2>
1434*4882a593Smuzhiyun
1435*4882a593Smuzhiyun    <sect2>
1436*4882a593Smuzhiyun      <title>Changing Viewport</title>
1437*4882a593Smuzhiyun
1438*4882a593Smuzhiyun      <para>
1439*4882a593Smuzhiyun    When a Change Viewport event is received,
1440*4882a593Smuzhiyun    <function>ChipAdjustFrame()</function> is called (when it exists):
1441*4882a593Smuzhiyun      </para>
1442*4882a593Smuzhiyun
1443*4882a593Smuzhiyun      <blockquote><para>
1444*4882a593Smuzhiyun	  <programlisting>
1445*4882a593Smuzhiyun    void ChipAdjustFrame(int index, int x, int y);
1446*4882a593Smuzhiyun	  </programlisting>
1447*4882a593Smuzhiyun	  <blockquote><para>
1448*4882a593Smuzhiyun      Changes the viewport for the screen identified by
1449*4882a593Smuzhiyun      <parameter>index;</parameter>.
1450*4882a593Smuzhiyun	    </para>
1451*4882a593Smuzhiyun
1452*4882a593Smuzhiyun	    <para>
1453*4882a593Smuzhiyun      It should be noted that many chipsets impose restrictions on where the
1454*4882a593Smuzhiyun      viewport may be placed in the virtual resolution, either for alignment
1455*4882a593Smuzhiyun      reasons, or to prevent the start of the viewport from being positioned
1456*4882a593Smuzhiyun      within a pixel (as can happen in a 24bpp mode).  After calculating the
1457*4882a593Smuzhiyun      value the chipset's panning registers need to be set to for non-DGA
1458*4882a593Smuzhiyun      modes, this function should recalculate the ScrnInfoRec's
1459*4882a593Smuzhiyun      <structfield>frameX0</structfield>, <structfield>frameY0</structfield>, <structfield>frameX1</structfield>
1460*4882a593Smuzhiyun      and <structfield>frameY1</structfield> fields to correspond to that value.  If
1461*4882a593Smuzhiyun      this is not done, switching to another mode might cause the position
1462*4882a593Smuzhiyun      of a hardware cursor to change.
1463*4882a593Smuzhiyun
1464*4882a593Smuzhiyun	    </para></blockquote>
1465*4882a593Smuzhiyun	</para></blockquote>
1466*4882a593Smuzhiyun
1467*4882a593Smuzhiyun    </sect2>
1468*4882a593Smuzhiyun
1469*4882a593Smuzhiyun    <sect2>
1470*4882a593Smuzhiyun      <title>VT Switching</title>
1471*4882a593Smuzhiyun
1472*4882a593Smuzhiyun      <para>
1473*4882a593Smuzhiyun    When a VT switch event is received, <function>xf86VTSwitch()</function>
1474*4882a593Smuzhiyun    is called.  <function>xf86VTSwitch()</function> does the following:
1475*4882a593Smuzhiyun
1476*4882a593Smuzhiyun	<variablelist>
1477*4882a593Smuzhiyun	  <varlistentry><term>On ENTER:</term>
1478*4882a593Smuzhiyun	    <listitem>
1479*4882a593Smuzhiyun	      <itemizedlist>
1480*4882a593Smuzhiyun		<listitem><para>
1481*4882a593Smuzhiyun		    enable port I/O access
1482*4882a593Smuzhiyun		  </para></listitem>
1483*4882a593Smuzhiyun
1484*4882a593Smuzhiyun		<listitem><para>
1485*4882a593Smuzhiyun		    save and initialise the bus/resource state
1486*4882a593Smuzhiyun		  </para></listitem>
1487*4882a593Smuzhiyun
1488*4882a593Smuzhiyun		<listitem><para>
1489*4882a593Smuzhiyun		    enter the SETUP server state
1490*4882a593Smuzhiyun		  </para></listitem>
1491*4882a593Smuzhiyun
1492*4882a593Smuzhiyun		<listitem><para>
1493*4882a593Smuzhiyun		    calls <function>ChipEnterVT()</function> for each screen
1494*4882a593Smuzhiyun		  </para></listitem>
1495*4882a593Smuzhiyun
1496*4882a593Smuzhiyun		<listitem><para>
1497*4882a593Smuzhiyun		    enter the OPERATING server state
1498*4882a593Smuzhiyun		  </para></listitem>
1499*4882a593Smuzhiyun
1500*4882a593Smuzhiyun		<listitem><para>
1501*4882a593Smuzhiyun		    validate GCs
1502*4882a593Smuzhiyun		  </para></listitem>
1503*4882a593Smuzhiyun
1504*4882a593Smuzhiyun		<listitem><para>
1505*4882a593Smuzhiyun		    Restore fb from saved pixmap for each screen
1506*4882a593Smuzhiyun		  </para></listitem>
1507*4882a593Smuzhiyun
1508*4882a593Smuzhiyun		<listitem><para>
1509*4882a593Smuzhiyun		    Enable all input devices
1510*4882a593Smuzhiyun		  </para></listitem>
1511*4882a593Smuzhiyun	      </itemizedlist>
1512*4882a593Smuzhiyun	    </listitem>
1513*4882a593Smuzhiyun	  </varlistentry>
1514*4882a593Smuzhiyun	  <varlistentry>
1515*4882a593Smuzhiyun	    <term>On LEAVE:</term>
1516*4882a593Smuzhiyun	    <listitem>
1517*4882a593Smuzhiyun	      <itemizedlist>
1518*4882a593Smuzhiyun		<listitem><para>
1519*4882a593Smuzhiyun		    Save fb to pixmap for each screen
1520*4882a593Smuzhiyun		  </para></listitem>
1521*4882a593Smuzhiyun
1522*4882a593Smuzhiyun		<listitem><para>
1523*4882a593Smuzhiyun		    validate GCs
1524*4882a593Smuzhiyun		  </para></listitem>
1525*4882a593Smuzhiyun
1526*4882a593Smuzhiyun		<listitem><para>
1527*4882a593Smuzhiyun		    enter the SETUP server state
1528*4882a593Smuzhiyun		  </para></listitem>
1529*4882a593Smuzhiyun
1530*4882a593Smuzhiyun		<listitem><para>
1531*4882a593Smuzhiyun		    calls <function>ChipLeaveVT()</function> for each screen
1532*4882a593Smuzhiyun		  </para></listitem>
1533*4882a593Smuzhiyun
1534*4882a593Smuzhiyun		<listitem><para>
1535*4882a593Smuzhiyun		    disable all input devices
1536*4882a593Smuzhiyun		  </para></listitem>
1537*4882a593Smuzhiyun
1538*4882a593Smuzhiyun		<listitem><para>
1539*4882a593Smuzhiyun		    restore bus/resource state
1540*4882a593Smuzhiyun		  </para></listitem>
1541*4882a593Smuzhiyun
1542*4882a593Smuzhiyun		<listitem><para>
1543*4882a593Smuzhiyun		    disables port I/O access
1544*4882a593Smuzhiyun		  </para></listitem>
1545*4882a593Smuzhiyun	      </itemizedlist>
1546*4882a593Smuzhiyun	    </listitem>
1547*4882a593Smuzhiyun	  </varlistentry>
1548*4882a593Smuzhiyun	</variablelist>
1549*4882a593Smuzhiyun      </para>
1550*4882a593Smuzhiyun
1551*4882a593Smuzhiyun      <blockquote><para>
1552*4882a593Smuzhiyun	  <programlisting>
1553*4882a593Smuzhiyun    Bool ChipEnterVT(ScrnInfoPtr pScrn);
1554*4882a593Smuzhiyun	  </programlisting>
1555*4882a593Smuzhiyun	  <blockquote><para>
1556*4882a593Smuzhiyun      This function should initialise the current video mode and
1557*4882a593Smuzhiyun      initialise the viewport, turn on the HW cursor if appropriate,
1558*4882a593Smuzhiyun      etc.
1559*4882a593Smuzhiyun	    </para>
1560*4882a593Smuzhiyun
1561*4882a593Smuzhiyun	    <para>
1562*4882a593Smuzhiyun      Should it re-save the video state before initialising the video
1563*4882a593Smuzhiyun      mode?
1564*4882a593Smuzhiyun	    </para>
1565*4882a593Smuzhiyun
1566*4882a593Smuzhiyun	  </blockquote></para></blockquote>
1567*4882a593Smuzhiyun
1568*4882a593Smuzhiyun      <blockquote><para>
1569*4882a593Smuzhiyun	  <programlisting>
1570*4882a593Smuzhiyun    void ChipLeaveVT(ScrnInfoPtr pScrn);
1571*4882a593Smuzhiyun	  </programlisting>
1572*4882a593Smuzhiyun	  <blockquote><para>
1573*4882a593Smuzhiyun      This function should restore the saved video state.  If
1574*4882a593Smuzhiyun      appropriate it should also turn off the HW cursor, and invalidate
1575*4882a593Smuzhiyun      any pixmap/font caches.
1576*4882a593Smuzhiyun	    </para>
1577*4882a593Smuzhiyun
1578*4882a593Smuzhiyun	  </blockquote></para></blockquote>
1579*4882a593Smuzhiyun
1580*4882a593Smuzhiyun      <para>
1581*4882a593Smuzhiyun    Optionally, <function>ChipLeaveVT()</function> may also unmap memory
1582*4882a593Smuzhiyun    regions.  If so, <function>ChipEnterVT()</function> will need to remap
1583*4882a593Smuzhiyun    them.  Additionally, if an aperture used to access video memory is
1584*4882a593Smuzhiyun    unmapped and remapped in this fashion, <function>ChipEnterVT()</function>
1585*4882a593Smuzhiyun    will also need to notify the framebuffer layers of the aperture's new
1586*4882a593Smuzhiyun    location in virtual memory.  This is done with a call to the screen's
1587*4882a593Smuzhiyun    <function>ModifyPixmapHeader()</function> function, as follows
1588*4882a593Smuzhiyun      </para>
1589*4882a593Smuzhiyun
1590*4882a593Smuzhiyun      <blockquote><para>
1591*4882a593Smuzhiyun	  <programlisting>
1592*4882a593Smuzhiyun    (*pScreen-&gt;ModifyPixmapHeader)(pScrn-&gt;ppix,
1593*4882a593Smuzhiyun                                   -1, -1, -1, -1, -1, NewApertureAddress);
1594*4882a593Smuzhiyun	  </programlisting>
1595*4882a593Smuzhiyun	  <blockquote><para>
1596*4882a593Smuzhiyun        where the <structfield>ppix</structfield> field in a ScrnInfoRec
1597*4882a593Smuzhiyun        points to the pixmap used by the screen's
1598*4882a593Smuzhiyun        <function>SaveRestoreImage()</function> function to hold the screen's
1599*4882a593Smuzhiyun        contents while switched out.
1600*4882a593Smuzhiyun	    </para>
1601*4882a593Smuzhiyun
1602*4882a593Smuzhiyun	  </blockquote></para></blockquote>
1603*4882a593Smuzhiyun
1604*4882a593Smuzhiyun      <para>
1605*4882a593Smuzhiyun    Other layers may wrap the <function>ChipEnterVT()</function> and
1606*4882a593Smuzhiyun    <function>ChipLeaveVT()</function> functions if they need to take some
1607*4882a593Smuzhiyun    action when these events are received.
1608*4882a593Smuzhiyun      </para>
1609*4882a593Smuzhiyun    </sect2>
1610*4882a593Smuzhiyun
1611*4882a593Smuzhiyun    <sect2>
1612*4882a593Smuzhiyun      <title>End of server generation</title>
1613*4882a593Smuzhiyun
1614*4882a593Smuzhiyun      <para>
1615*4882a593Smuzhiyun    At the end of each server generation, the DIX layer calls
1616*4882a593Smuzhiyun    <function>ChipCloseScreen()</function> for each screen:
1617*4882a593Smuzhiyun      </para>
1618*4882a593Smuzhiyun
1619*4882a593Smuzhiyun      <blockquote><para>
1620*4882a593Smuzhiyun	  <programlisting>
1621*4882a593Smuzhiyun    Bool ChipCloseScreen(int index, ScreenPtr pScreen);
1622*4882a593Smuzhiyun	  </programlisting>
1623*4882a593Smuzhiyun	  <blockquote><para>
1624*4882a593Smuzhiyun      This function should restore the saved video state and unmap the
1625*4882a593Smuzhiyun      memory regions.
1626*4882a593Smuzhiyun	    </para>
1627*4882a593Smuzhiyun
1628*4882a593Smuzhiyun	    <para>
1629*4882a593Smuzhiyun      It should also free per-screen data structures allocated by the
1630*4882a593Smuzhiyun      driver.  Note that the persistent data held in the
1631*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> field
1632*4882a593Smuzhiyun      should not be freed here because it is needed by subsequent server
1633*4882a593Smuzhiyun      generations.
1634*4882a593Smuzhiyun	    </para>
1635*4882a593Smuzhiyun
1636*4882a593Smuzhiyun	    <para>
1637*4882a593Smuzhiyun      The <structname>ScrnInfoRec</structname>'s <structfield>vtSema</structfield> field
1638*4882a593Smuzhiyun      should be set to <constant>FALSE</constant> once the video HW state
1639*4882a593Smuzhiyun      has been restored.
1640*4882a593Smuzhiyun	    </para>
1641*4882a593Smuzhiyun
1642*4882a593Smuzhiyun	    <para>
1643*4882a593Smuzhiyun      Before freeing the per-screen driver data the saved
1644*4882a593Smuzhiyun      <structfield>CloseScreen</structfield> value should be restored to
1645*4882a593Smuzhiyun      <structfield>pScreen-&gt;CloseScreen</structfield>, and that function should
1646*4882a593Smuzhiyun      be called after freeing the data.
1647*4882a593Smuzhiyun
1648*4882a593Smuzhiyun	    </para></blockquote>
1649*4882a593Smuzhiyun	</para></blockquote>
1650*4882a593Smuzhiyun    </sect2>
1651*4882a593Smuzhiyun  </sect1>
1652*4882a593Smuzhiyun
1653*4882a593Smuzhiyun  <sect1>
1654*4882a593Smuzhiyun    <title>Optional Driver Functions</title>
1655*4882a593Smuzhiyun
1656*4882a593Smuzhiyun    <para>
1657*4882a593SmuzhiyunThe functions outlined here can be called from the XFree86 common layer,
1658*4882a593Smuzhiyunbut their presence is optional.
1659*4882a593Smuzhiyun    </para>
1660*4882a593Smuzhiyun
1661*4882a593Smuzhiyun    <sect2>
1662*4882a593Smuzhiyun      <title>Mode Validation</title>
1663*4882a593Smuzhiyun
1664*4882a593Smuzhiyun      <para>
1665*4882a593Smuzhiyun    When a mode validation helper supplied by the XFree86-common layer is
1666*4882a593Smuzhiyun    being used, it can be useful to provide a function to check for hw
1667*4882a593Smuzhiyun    specific mode constraints:
1668*4882a593Smuzhiyun      </para>
1669*4882a593Smuzhiyun
1670*4882a593Smuzhiyun      <blockquote><para>
1671*4882a593Smuzhiyun	  <programlisting>
1672*4882a593Smuzhiyun    ModeStatus ChipValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode,
1673*4882a593Smuzhiyun                             Bool verbose, int flags);
1674*4882a593Smuzhiyun	  </programlisting>
1675*4882a593Smuzhiyun	  <blockquote><para>
1676*4882a593Smuzhiyun      Check the passed mode for hw-specific constraints, and return the
1677*4882a593Smuzhiyun      appropriate status value.
1678*4882a593Smuzhiyun
1679*4882a593Smuzhiyun	    </para></blockquote>
1680*4882a593Smuzhiyun	</para></blockquote>
1681*4882a593Smuzhiyun
1682*4882a593Smuzhiyun      <para>
1683*4882a593SmuzhiyunThis function may also modify the effective timings and clock of the passed
1684*4882a593Smuzhiyunmode.  These have been stored in the mode's <structfield>Crtc*</structfield> and
1685*4882a593Smuzhiyun<structfield>SynthClock</structfield> elements, and have already been adjusted for
1686*4882a593Smuzhiyuninterlacing, doublescanning, multiscanning and clock multipliers and dividers.
1687*4882a593SmuzhiyunThe function should not modify any other mode field, unless it wants to modify
1688*4882a593Smuzhiyunthe mode timings reported to the user by <function>xf86PrintModes()</function>.
1689*4882a593Smuzhiyun      </para>
1690*4882a593Smuzhiyun
1691*4882a593Smuzhiyun      <para>
1692*4882a593SmuzhiyunThe function is called once for every mode in the xorg.conf Monitor section
1693*4882a593Smuzhiyunassigned to the screen, with <parameter>flags</parameter> set to
1694*4882a593Smuzhiyun<constant>MODECHECK_INITIAL</constant>.  It is subsequently called for every mode
1695*4882a593Smuzhiyunin the xorg.conf Display subsection assigned to the screen, with
1696*4882a593Smuzhiyun<parameter>flags</parameter> set to <constant>MODECHECK_FINAL</constant>.  In the second
1697*4882a593Smuzhiyuncase, the mode will have successfully passed all other tests.  In addition,
1698*4882a593Smuzhiyunthe <structname>ScrnInfoRec</structname>'s <structfield>virtualX</structfield>,
1699*4882a593Smuzhiyun<structfield>virtualY</structfield> and <structfield>displayWidth</structfield> fields will have been
1700*4882a593Smuzhiyunset as if the mode to be validated were to be the last mode accepted.
1701*4882a593Smuzhiyun      </para>
1702*4882a593Smuzhiyun
1703*4882a593Smuzhiyun      <para>
1704*4882a593SmuzhiyunIn effect, calls with MODECHECK_INITIAL are intended for checks that do not
1705*4882a593Smuzhiyundepend on any mode other than the one being validated, while calls with
1706*4882a593SmuzhiyunMODECHECK_FINAL are intended for checks that may involve more than one mode.
1707*4882a593Smuzhiyun      </para>
1708*4882a593Smuzhiyun    </sect2>
1709*4882a593Smuzhiyun
1710*4882a593Smuzhiyun    <sect2>
1711*4882a593Smuzhiyun      <title>Free screen data</title>
1712*4882a593Smuzhiyun
1713*4882a593Smuzhiyun      <para>
1714*4882a593Smuzhiyun    When a screen is deleted prior to the completion of the ScreenInit
1715*4882a593Smuzhiyun    phase the <function>ChipFreeScreen()</function> function is called when defined.
1716*4882a593Smuzhiyun      </para>
1717*4882a593Smuzhiyun
1718*4882a593Smuzhiyun      <blockquote><para>
1719*4882a593Smuzhiyun	  <programlisting>
1720*4882a593Smuzhiyun    void ChipFreeScreen(ScrnInfoPtr pScrn);
1721*4882a593Smuzhiyun	  </programlisting>
1722*4882a593Smuzhiyun	  <blockquote><para>
1723*4882a593Smuzhiyun      Free any driver-allocated data that may have been allocated up to
1724*4882a593Smuzhiyun      and including an unsuccessful <function>ChipScreenInit()</function>
1725*4882a593Smuzhiyun      call.  This would predominantly be data allocated by
1726*4882a593Smuzhiyun      <function>ChipPreInit()</function> that persists across server
1727*4882a593Smuzhiyun      generations.  It would include the <structfield>driverPrivate</structfield>,
1728*4882a593Smuzhiyun      and any <quote>privates</quote> entries that modules may have allocated.
1729*4882a593Smuzhiyun
1730*4882a593Smuzhiyun	    </para></blockquote>
1731*4882a593Smuzhiyun	</para></blockquote>
1732*4882a593Smuzhiyun
1733*4882a593Smuzhiyun    </sect2>
1734*4882a593Smuzhiyun</sect1>
1735*4882a593Smuzhiyun
1736*4882a593Smuzhiyun  <sect1>
1737*4882a593Smuzhiyun    <title>Recommended driver functions</title>
1738*4882a593Smuzhiyun
1739*4882a593Smuzhiyun    <para>
1740*4882a593SmuzhiyunThe functions outlined here are for internal use by the driver only.
1741*4882a593SmuzhiyunThey are entirely optional, and are never accessed directly from higher
1742*4882a593Smuzhiyunlayers.  The sample function declarations shown here are just examples.
1743*4882a593SmuzhiyunThe interface (if any) used is up to the driver.
1744*4882a593Smuzhiyun    </para>
1745*4882a593Smuzhiyun
1746*4882a593Smuzhiyun    <sect2>
1747*4882a593Smuzhiyun      <title>Save</title>
1748*4882a593Smuzhiyun
1749*4882a593Smuzhiyun      <para>
1750*4882a593Smuzhiyun    Save the video state.  This could be called from <function>ChipScreenInit()</function> and
1751*4882a593Smuzhiyun    (possibly) <function>ChipEnterVT()</function>.
1752*4882a593Smuzhiyun      </para>
1753*4882a593Smuzhiyun
1754*4882a593Smuzhiyun      <blockquote><para>
1755*4882a593Smuzhiyun	  <programlisting>
1756*4882a593Smuzhiyun    void ChipSave(ScrnInfoPtr pScrn);
1757*4882a593Smuzhiyun	  </programlisting>
1758*4882a593Smuzhiyun	  <blockquote><para>
1759*4882a593Smuzhiyun      Saves the current state.  This will only be saving pre-server
1760*4882a593Smuzhiyun      states or states before returning to the server.  There is only
1761*4882a593Smuzhiyun      one current saved state per screen and it is stored in private
1762*4882a593Smuzhiyun      storage in the screen.
1763*4882a593Smuzhiyun
1764*4882a593Smuzhiyun	    </para></blockquote>
1765*4882a593Smuzhiyun	</para></blockquote>
1766*4882a593Smuzhiyun    </sect2>
1767*4882a593Smuzhiyun
1768*4882a593Smuzhiyun    <sect2>
1769*4882a593Smuzhiyun      <title>Restore</title>
1770*4882a593Smuzhiyun
1771*4882a593Smuzhiyun      <para>
1772*4882a593Smuzhiyun    Restore the original video state.  This could be called from the
1773*4882a593Smuzhiyun    <function>ChipLeaveVT()</function> and <function>ChipCloseScreen()</function>
1774*4882a593Smuzhiyun    functions.
1775*4882a593Smuzhiyun      </para>
1776*4882a593Smuzhiyun
1777*4882a593Smuzhiyun      <blockquote><para>
1778*4882a593Smuzhiyun	  <programlisting>
1779*4882a593Smuzhiyun    void ChipRestore(ScrnInfoPtr pScrn);
1780*4882a593Smuzhiyun	  </programlisting>
1781*4882a593Smuzhiyun	  <blockquote><para>
1782*4882a593Smuzhiyun      Restores the saved state from the private storage.  Usually only
1783*4882a593Smuzhiyun      used for restoring text modes.
1784*4882a593Smuzhiyun
1785*4882a593Smuzhiyun	    </para></blockquote>
1786*4882a593Smuzhiyun	</para></blockquote>
1787*4882a593Smuzhiyun
1788*4882a593Smuzhiyun    </sect2>
1789*4882a593Smuzhiyun
1790*4882a593Smuzhiyun    <sect2>
1791*4882a593Smuzhiyun      <title>Initialise Mode</title>
1792*4882a593Smuzhiyun
1793*4882a593Smuzhiyun      <para>
1794*4882a593Smuzhiyun    Initialise a video mode.  This could be called from the
1795*4882a593Smuzhiyun    <function>ChipScreenInit()</function>, <function>ChipSwitchMode()</function>
1796*4882a593Smuzhiyun    and <function>ChipEnterVT()</function> functions.
1797*4882a593Smuzhiyun      </para>
1798*4882a593Smuzhiyun
1799*4882a593Smuzhiyun      <blockquote><para>
1800*4882a593Smuzhiyun	  <programlisting>
1801*4882a593Smuzhiyun    Bool ChipModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
1802*4882a593Smuzhiyun	  </programlisting>
1803*4882a593Smuzhiyun	  <blockquote><para>
1804*4882a593Smuzhiyun      Programs the hardware for the given video mode.
1805*4882a593Smuzhiyun
1806*4882a593Smuzhiyun	    </para></blockquote>
1807*4882a593Smuzhiyun	</para></blockquote>
1808*4882a593Smuzhiyun
1809*4882a593Smuzhiyun    </sect2>
1810*4882a593Smuzhiyun  </sect1>
1811*4882a593Smuzhiyun
1812*4882a593Smuzhiyun  <sect1>
1813*4882a593Smuzhiyun    <title>Data and Data Structures</title>
1814*4882a593Smuzhiyun
1815*4882a593Smuzhiyun    <sect2>
1816*4882a593Smuzhiyun      <title>Command line data</title>
1817*4882a593Smuzhiyun
1818*4882a593Smuzhiyun      <para>
1819*4882a593SmuzhiyunCommand line options are typically global, and are stored in global
1820*4882a593Smuzhiyunvariables.  These variables are read-only and are available to drivers
1821*4882a593Smuzhiyunvia a function call interface.  Most of these command line values are
1822*4882a593Smuzhiyunprocessed via helper functions to ensure that they are treated consistently
1823*4882a593Smuzhiyunby all drivers.  The other means of access is provided for cases where
1824*4882a593Smuzhiyunthe supplied helper functions might not be appropriate.
1825*4882a593Smuzhiyun      </para>
1826*4882a593Smuzhiyun
1827*4882a593Smuzhiyun      <para>
1828*4882a593SmuzhiyunSome of them are:
1829*4882a593Smuzhiyun
1830*4882a593Smuzhiyun	<literallayout>
1831*4882a593Smuzhiyun    xf86Verbose               verbosity level
1832*4882a593Smuzhiyun    xf86Bpp                   -bpp from the command line
1833*4882a593Smuzhiyun    xf86Depth                 -depth from the command line
1834*4882a593Smuzhiyun    xf86Weight                -weight from the command line
1835*4882a593Smuzhiyun    xf86Gamma                 -{r,g,b,}gamma from the command line
1836*4882a593Smuzhiyun    xf86FlipPixels            -flippixels from the command line
1837*4882a593Smuzhiyun    xf86ProbeOnly             -probeonly from the command line
1838*4882a593Smuzhiyun    defaultColorVisualClass   -cc from the command line
1839*4882a593Smuzhiyun	</literallayout>
1840*4882a593Smuzhiyun      </para>
1841*4882a593Smuzhiyun
1842*4882a593Smuzhiyun      <para>
1843*4882a593SmuzhiyunIf we ever do allow for screen-specific command line options, we may
1844*4882a593Smuzhiyunneed to rethink this.
1845*4882a593Smuzhiyun      </para>
1846*4882a593Smuzhiyun
1847*4882a593Smuzhiyun      <para>
1848*4882a593SmuzhiyunThese can be accessed in a read-only manner by drivers with the following
1849*4882a593Smuzhiyunfunctions:
1850*4882a593Smuzhiyun      </para>
1851*4882a593Smuzhiyun
1852*4882a593Smuzhiyun     <blockquote><para>
1853*4882a593Smuzhiyun	  <programlisting>
1854*4882a593Smuzhiyun    int xf86GetVerbosity();
1855*4882a593Smuzhiyun	  </programlisting>
1856*4882a593Smuzhiyun	  <blockquote><para>
1857*4882a593Smuzhiyun      Returns the value of <varname>xf86Verbose</varname>.
1858*4882a593Smuzhiyun	    </para></blockquote>
1859*4882a593Smuzhiyun
1860*4882a593Smuzhiyun	</para></blockquote>
1861*4882a593Smuzhiyun
1862*4882a593Smuzhiyun     <blockquote><para>
1863*4882a593Smuzhiyun	  <programlisting>
1864*4882a593Smuzhiyun    int xf86GetDepth();
1865*4882a593Smuzhiyun	  </programlisting>
1866*4882a593Smuzhiyun	  <blockquote><para>
1867*4882a593Smuzhiyun      Returns the <option>-depth</option> command line setting.  If not
1868*4882a593Smuzhiyun      set on the command line, <constant>-1</constant> is returned.
1869*4882a593Smuzhiyun	    </para></blockquote>
1870*4882a593Smuzhiyun
1871*4882a593Smuzhiyun	</para></blockquote>
1872*4882a593Smuzhiyun
1873*4882a593Smuzhiyun     <blockquote><para>
1874*4882a593Smuzhiyun	  <programlisting>
1875*4882a593Smuzhiyun    rgb xf86GetWeight();
1876*4882a593Smuzhiyun	  </programlisting>
1877*4882a593Smuzhiyun	  <blockquote><para>
1878*4882a593Smuzhiyun      Returns the <option>-weight</option> command line setting.  If not
1879*4882a593Smuzhiyun      set on the command line, <literal remap="tt">{0, 0, 0}</literal> is returned.
1880*4882a593Smuzhiyun	    </para></blockquote>
1881*4882a593Smuzhiyun
1882*4882a593Smuzhiyun	</para></blockquote>
1883*4882a593Smuzhiyun
1884*4882a593Smuzhiyun      <blockquote><para>
1885*4882a593Smuzhiyun	  <programlisting>
1886*4882a593Smuzhiyun    Gamma xf86GetGamma();
1887*4882a593Smuzhiyun	  </programlisting>
1888*4882a593Smuzhiyun	  <blockquote><para>
1889*4882a593Smuzhiyun      Returns the <option>-gamma</option> or <option>-rgamma</option>,
1890*4882a593Smuzhiyun      <option>-ggamma</option>, <option>-bgamma</option> command line settings.
1891*4882a593Smuzhiyun      If not set on the command line, <literal remap="tt">{0.0, 0.0, 0.0}</literal>
1892*4882a593Smuzhiyun      is returned.
1893*4882a593Smuzhiyun	    </para></blockquote>
1894*4882a593Smuzhiyun
1895*4882a593Smuzhiyun	</para></blockquote>
1896*4882a593Smuzhiyun
1897*4882a593Smuzhiyun      <blockquote><para>
1898*4882a593Smuzhiyun	  <programlisting>
1899*4882a593Smuzhiyun    Bool xf86GetFlipPixels();
1900*4882a593Smuzhiyun	  </programlisting>
1901*4882a593Smuzhiyun	  <blockquote><para>
1902*4882a593Smuzhiyun      Returns <constant>TRUE</constant> if <option>-flippixels</option> is
1903*4882a593Smuzhiyun      present on the command line, and <constant>FALSE</constant> otherwise.
1904*4882a593Smuzhiyun	    </para></blockquote>
1905*4882a593Smuzhiyun
1906*4882a593Smuzhiyun	</para></blockquote>
1907*4882a593Smuzhiyun
1908*4882a593Smuzhiyun      <blockquote><para>
1909*4882a593Smuzhiyun	  <programlisting>
1910*4882a593Smuzhiyun    const char *xf86GetServerName();
1911*4882a593Smuzhiyun	  </programlisting>
1912*4882a593Smuzhiyun	  <blockquote><para>
1913*4882a593Smuzhiyun      Returns the name of the X server from the command line.
1914*4882a593Smuzhiyun	    </para></blockquote>
1915*4882a593Smuzhiyun
1916*4882a593Smuzhiyun	</para></blockquote>
1917*4882a593Smuzhiyun    </sect2>
1918*4882a593Smuzhiyun
1919*4882a593Smuzhiyun    <sect2>
1920*4882a593Smuzhiyun      <title>Data handling</title>
1921*4882a593Smuzhiyun
1922*4882a593Smuzhiyun      <para>
1923*4882a593SmuzhiyunConfig file data contains parts that are global, and parts that are
1924*4882a593SmuzhiyunScreen specific.  All of it is parsed into data structures that neither
1925*4882a593Smuzhiyunthe drivers or most other parts of the server need to know about.
1926*4882a593Smuzhiyun      </para>
1927*4882a593Smuzhiyun
1928*4882a593Smuzhiyun      <para>
1929*4882a593SmuzhiyunThe global data is typically not required by drivers, and as such, most
1930*4882a593Smuzhiyunof it is stored in the private <structname>xf86InfoRec</structname>.
1931*4882a593Smuzhiyun      </para>
1932*4882a593Smuzhiyun
1933*4882a593Smuzhiyun      <para>
1934*4882a593SmuzhiyunThe screen-specific data collected from the config file is stored in
1935*4882a593Smuzhiyunscreen, device, display, monitor-specific data structures that are separate
1936*4882a593Smuzhiyunfrom the <varname>ScrnInfoRecs</varname>, with the appropriate elements/fields
1937*4882a593Smuzhiyunhooked into the <varname>ScrnInfoRecs</varname> as required.  The screen
1938*4882a593Smuzhiyunconfig data is held in <structname>confScreenRec</structname>, device data in
1939*4882a593Smuzhiyunthe <structname>GDevRec</structname>, monitor data in the <structname>MonRec</structname>,
1940*4882a593Smuzhiyunand display data in the <structname>DispRec</structname>.
1941*4882a593Smuzhiyun      </para>
1942*4882a593Smuzhiyun
1943*4882a593Smuzhiyun      <para>
1944*4882a593SmuzhiyunThe XFree86 common layer's screen specific data (the actual data in use
1945*4882a593Smuzhiyunfor each screen) is held in the <varname>ScrnInfoRecs</varname>.  As has
1946*4882a593Smuzhiyunbeen outlined above, the <varname>ScrnInfoRecs</varname> are allocated at probe
1947*4882a593Smuzhiyuntime, and it is the responsibility of the Drivers' <function>Probe()</function>
1948*4882a593Smuzhiyunand <function>PreInit()</function> functions to finish filling them in based
1949*4882a593Smuzhiyunon both data provided on the command line and data provided from the
1950*4882a593SmuzhiyunConfig file.  The precedence for this is:
1951*4882a593Smuzhiyun
1952*4882a593Smuzhiyun	<blockquote><para>
1953*4882a593Smuzhiyun    command line  -&gt;  config file  -&gt;  probed/default data
1954*4882a593Smuzhiyun	</para></blockquote>
1955*4882a593Smuzhiyun      </para>
1956*4882a593Smuzhiyun
1957*4882a593Smuzhiyun      <para>
1958*4882a593SmuzhiyunFor most things in this category there are helper functions that the
1959*4882a593Smuzhiyundrivers can use to ensure that the above precedence is consistently
1960*4882a593Smuzhiyunused.
1961*4882a593Smuzhiyun      </para>
1962*4882a593Smuzhiyun
1963*4882a593Smuzhiyun      <para>
1964*4882a593SmuzhiyunAs well as containing screen-specific data that the XFree86 common layer
1965*4882a593Smuzhiyun(including essential parts of the server infrastructure as well as helper
1966*4882a593Smuzhiyunfunctions) needs to access, it also contains some data that drivers use
1967*4882a593Smuzhiyuninternally.  When considering whether to add a new field to the
1968*4882a593Smuzhiyun<structname>ScrnInfoRec</structname>, consider the balance between the convenience
1969*4882a593Smuzhiyunof things that lots of drivers need and the size/obscurity of the
1970*4882a593Smuzhiyun<structname>ScrnInfoRec</structname>.
1971*4882a593Smuzhiyun      </para>
1972*4882a593Smuzhiyun
1973*4882a593Smuzhiyun      <para>
1974*4882a593SmuzhiyunPer-screen driver specific data that cannot be accommodated with the
1975*4882a593Smuzhiyunstatic <structname>ScrnInfoRec</structname> fields is held in a driver-defined
1976*4882a593Smuzhiyundata structure, a pointer to which is assigned to the
1977*4882a593Smuzhiyun<structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> field.  This
1978*4882a593Smuzhiyunis per-screen data that persists across server generations (as does the
1979*4882a593Smuzhiyunbulk of the static <structname>ScrnInfoRec</structname> data).  It would typically
1980*4882a593Smuzhiyunalso include the video card's saved state.
1981*4882a593Smuzhiyun      </para>
1982*4882a593Smuzhiyun
1983*4882a593Smuzhiyun      <para>
1984*4882a593SmuzhiyunPer-screen data for other modules that the driver uses that is reset for each
1985*4882a593Smuzhiyunserver generation is hooked into the <structname>ScrnInfoRec</structname>
1986*4882a593Smuzhiyunthrough its <structfield>privates</structfield> field.
1987*4882a593Smuzhiyun      </para>
1988*4882a593Smuzhiyun
1989*4882a593Smuzhiyun      <para>
1990*4882a593SmuzhiyunOnce it has stabilised, the data structures and variables accessible to
1991*4882a593Smuzhiyunvideo drivers will be documented here.  In the meantime, those things
1992*4882a593Smuzhiyundefined in the <filename>xf86.h</filename> and <filename>xf86str.h</filename>
1993*4882a593Smuzhiyunfiles are visible to video drivers.  Things defined in
1994*4882a593Smuzhiyun<filename>xf86Priv.h</filename> and <filename>xf86Privstr.h</filename> are NOT
1995*4882a593Smuzhiyunintended to be visible to video drivers, and it is an error for a driver
1996*4882a593Smuzhiyunto include those files.
1997*4882a593Smuzhiyun      </para>
1998*4882a593Smuzhiyun
1999*4882a593Smuzhiyun    </sect2>
2000*4882a593Smuzhiyun
2001*4882a593Smuzhiyun    <sect2>
2002*4882a593Smuzhiyun      <title>Accessing global data</title>
2003*4882a593Smuzhiyun
2004*4882a593Smuzhiyun      <para>
2005*4882a593SmuzhiyunSome other global state information that the drivers may access via
2006*4882a593Smuzhiyunfunctions is as follows:
2007*4882a593Smuzhiyun      </para>
2008*4882a593Smuzhiyun
2009*4882a593Smuzhiyun      <blockquote><para>
2010*4882a593Smuzhiyun	  <programlisting>
2011*4882a593Smuzhiyun    Bool xf86ServerIsExiting();
2012*4882a593Smuzhiyun	  </programlisting>
2013*4882a593Smuzhiyun	  <blockquote><para>
2014*4882a593Smuzhiyun      Returns <constant>TRUE</constant> if the server is at the end of a
2015*4882a593Smuzhiyun      generation and is in the process of exiting, and
2016*4882a593Smuzhiyun      <constant>FALSE</constant> otherwise.
2017*4882a593Smuzhiyun	    </para></blockquote>
2018*4882a593Smuzhiyun
2019*4882a593Smuzhiyun	</para></blockquote>
2020*4882a593Smuzhiyun
2021*4882a593Smuzhiyun      <blockquote><para>
2022*4882a593Smuzhiyun	  <programlisting>
2023*4882a593Smuzhiyun    Bool xf86ServerIsResetting();
2024*4882a593Smuzhiyun	  </programlisting>
2025*4882a593Smuzhiyun	  <blockquote><para>
2026*4882a593Smuzhiyun      Returns <constant>TRUE</constant> if the server is at the end of a
2027*4882a593Smuzhiyun      generation and is in the process of resetting, and
2028*4882a593Smuzhiyun      <constant>FALSE</constant> otherwise.
2029*4882a593Smuzhiyun	    </para></blockquote>
2030*4882a593Smuzhiyun
2031*4882a593Smuzhiyun	</para></blockquote>
2032*4882a593Smuzhiyun
2033*4882a593Smuzhiyun      <blockquote><para>
2034*4882a593Smuzhiyun	  <programlisting>
2035*4882a593Smuzhiyun    Bool xf86ServerIsOnlyProbing();
2036*4882a593Smuzhiyun	  </programlisting>
2037*4882a593Smuzhiyun	  <blockquote><para>
2038*4882a593Smuzhiyun      Returns <constant>TRUE</constant> if the -probeonly command line flag
2039*4882a593Smuzhiyun      was specified, and <constant>FALSE</constant> otherwise.
2040*4882a593Smuzhiyun	    </para></blockquote>
2041*4882a593Smuzhiyun
2042*4882a593Smuzhiyun	</para></blockquote>
2043*4882a593Smuzhiyun
2044*4882a593Smuzhiyun    </sect2>
2045*4882a593Smuzhiyun
2046*4882a593Smuzhiyun    <sect2>
2047*4882a593Smuzhiyun      <title>Allocating private data</title>
2048*4882a593Smuzhiyun
2049*4882a593Smuzhiyun      <para>
2050*4882a593SmuzhiyunA driver and any module it uses may allocate per-screen private storage
2051*4882a593Smuzhiyunin either the <structname>ScreenRec</structname> (DIX level) or
2052*4882a593Smuzhiyun<structname>ScrnInfoRec</structname> (XFree86 common layer level).
2053*4882a593Smuzhiyun<structname>ScreenRec</structname> storage persists only for a single server
2054*4882a593Smuzhiyungeneration, and <structname>ScrnInfoRec</structname> storage persists across
2055*4882a593Smuzhiyungenerations for the lifetime of the server.
2056*4882a593Smuzhiyun      </para>
2057*4882a593Smuzhiyun
2058*4882a593Smuzhiyun      <para>
2059*4882a593SmuzhiyunThe <structname>ScreenRec</structname> <structfield>devPrivates</structfield> data must be
2060*4882a593Smuzhiyunreallocated/initialised at the start of each new generation.  This is
2061*4882a593Smuzhiyunnormally done from the <function>ChipScreenInit()</function> function, and
2062*4882a593SmuzhiyunInit functions for other modules that it calls.  Data allocated in this
2063*4882a593Smuzhiyunway should be freed by the driver's <function>ChipCloseScreen()</function>
2064*4882a593Smuzhiyunfunctions, and Close functions for other modules that it calls.  A new
2065*4882a593Smuzhiyun<structfield>devPrivates</structfield> entry is allocated by calling the
2066*4882a593Smuzhiyun<function>AllocateScreenPrivateIndex()</function> function.
2067*4882a593Smuzhiyun      </para>
2068*4882a593Smuzhiyun
2069*4882a593Smuzhiyun      <blockquote><para>
2070*4882a593Smuzhiyun	  <programlisting>
2071*4882a593Smuzhiyun    int AllocateScreenPrivateIndex();
2072*4882a593Smuzhiyun	  </programlisting>
2073*4882a593Smuzhiyun	  <blockquote><para>
2074*4882a593Smuzhiyun      This function allocates a new element in the
2075*4882a593Smuzhiyun      <structfield>devPrivates</structfield> field of all currently existing
2076*4882a593Smuzhiyun      <literal remap="tt">ScreenRecs</literal>.  The return value is the index of this
2077*4882a593Smuzhiyun      new element in the <structfield>devPrivates</structfield> array.  The
2078*4882a593Smuzhiyun      <structfield>devPrivates</structfield> field is of type
2079*4882a593Smuzhiyun      <structname>DevUnion</structname>:
2080*4882a593Smuzhiyun
2081*4882a593Smuzhiyun	      <programlisting>
2082*4882a593Smuzhiyun        typedef union _DevUnion {
2083*4882a593Smuzhiyun            pointer             ptr;
2084*4882a593Smuzhiyun            long                val;
2085*4882a593Smuzhiyun            unsigned long       uval;
2086*4882a593Smuzhiyun            pointer             (*fptr)(void);
2087*4882a593Smuzhiyun        } DevUnion;
2088*4882a593Smuzhiyun	      </programlisting>
2089*4882a593Smuzhiyun
2090*4882a593Smuzhiyun      which allows the element to be used for any of the above types.
2091*4882a593Smuzhiyun      It is commonly used as a pointer to data that the caller allocates
2092*4882a593Smuzhiyun      after the new index has been allocated.
2093*4882a593Smuzhiyun	    </para>
2094*4882a593Smuzhiyun
2095*4882a593Smuzhiyun	    <para>
2096*4882a593Smuzhiyun      This function will return <constant>-1</constant> when there is an
2097*4882a593Smuzhiyun      error allocating the new index.
2098*4882a593Smuzhiyun	    </para>
2099*4882a593Smuzhiyun
2100*4882a593Smuzhiyun	  </blockquote>
2101*4882a593Smuzhiyun	</para></blockquote>
2102*4882a593Smuzhiyun
2103*4882a593Smuzhiyun      <para>
2104*4882a593SmuzhiyunThe <structname>ScrnInfoRec</structname> <structfield>privates</structfield> data persists
2105*4882a593Smuzhiyunfor the life of the server, so only needs to be allocated once.  This
2106*4882a593Smuzhiyunshould be done from the <function>ChipPreInit()</function> function, and Init
2107*4882a593Smuzhiyunfunctions for other modules that it calls.  Data allocated in this way
2108*4882a593Smuzhiyunshould be freed by the driver's <function>ChipFreeScreen()</function> functions,
2109*4882a593Smuzhiyunand Free functions for other modules that it calls.  A new
2110*4882a593Smuzhiyun<structfield>privates</structfield> entry is allocated by calling the
2111*4882a593Smuzhiyun<function>xf86AllocateScrnInfoPrivateIndex()</function> function.
2112*4882a593Smuzhiyun      </para>
2113*4882a593Smuzhiyun
2114*4882a593Smuzhiyun      <blockquote><para>
2115*4882a593Smuzhiyun	  <programlisting>
2116*4882a593Smuzhiyun    int xf86AllocateScrnInfoPrivateIndex();
2117*4882a593Smuzhiyun	  </programlisting>
2118*4882a593Smuzhiyun	  <blockquote><para>
2119*4882a593Smuzhiyun      This function allocates a new element in the <structfield>privates</structfield>
2120*4882a593Smuzhiyun      field of all currently existing <varname>ScrnInfoRecs</varname>.
2121*4882a593Smuzhiyun      The return value is the index of this new element in the
2122*4882a593Smuzhiyun      <structfield>privates</structfield> array.  The <structfield>privates</structfield>
2123*4882a593Smuzhiyun      field is of type <structfield>DevUnion</structfield>:
2124*4882a593Smuzhiyun
2125*4882a593Smuzhiyun	      <programlisting>
2126*4882a593Smuzhiyun        typedef union _DevUnion {
2127*4882a593Smuzhiyun            pointer             ptr;
2128*4882a593Smuzhiyun            long                val;
2129*4882a593Smuzhiyun            unsigned long       uval;
2130*4882a593Smuzhiyun            pointer             (*fptr)(void);
2131*4882a593Smuzhiyun        } DevUnion;
2132*4882a593Smuzhiyun	      </programlisting>
2133*4882a593Smuzhiyun
2134*4882a593Smuzhiyun      which allows the element to be used for any of the above types.
2135*4882a593Smuzhiyun      It is commonly used as a pointer to data that the caller allocates
2136*4882a593Smuzhiyun      after the new index has been allocated.
2137*4882a593Smuzhiyun	    </para>
2138*4882a593Smuzhiyun
2139*4882a593Smuzhiyun	    <para>
2140*4882a593Smuzhiyun      This function will not return when there is an error allocating
2141*4882a593Smuzhiyun      the new index.  When there is an error it will cause the server
2142*4882a593Smuzhiyun      to exit with a fatal error.  The similar function for allocation
2143*4882a593Smuzhiyun      privates in the <structname>ScreenRec</structname>
2144*4882a593Smuzhiyun      (<function>AllocateScreenPrivateIndex()</function>) differs in this
2145*4882a593Smuzhiyun      respect by returning <constant>-1</constant> when the allocation fails.
2146*4882a593Smuzhiyun	    </para>
2147*4882a593Smuzhiyun
2148*4882a593Smuzhiyun	  </blockquote>
2149*4882a593Smuzhiyun	</para></blockquote>
2150*4882a593Smuzhiyun    </sect2>
2151*4882a593Smuzhiyun  </sect1>
2152*4882a593Smuzhiyun
2153*4882a593Smuzhiyun  <sect1 id="rac">
2154*4882a593Smuzhiyun    <title>Keeping Track of Bus Resources</title>
2155*4882a593Smuzhiyun
2156*4882a593Smuzhiyun    <sect2>
2157*4882a593Smuzhiyun      <title>Theory of Operation</title>
2158*4882a593Smuzhiyun
2159*4882a593Smuzhiyun      <para>
2160*4882a593SmuzhiyunThe XFree86 common layer has knowledge of generic access control mechanisms
2161*4882a593Smuzhiyunfor devices on certain bus systems (currently the PCI bus) as well as
2162*4882a593Smuzhiyunof methods to enable or disable access to the buses itself.  Furthermore
2163*4882a593Smuzhiyunit can access information on resources decoded by these devices and if
2164*4882a593Smuzhiyunnecessary modify it.
2165*4882a593Smuzhiyun      </para>
2166*4882a593Smuzhiyun
2167*4882a593Smuzhiyun      <para>
2168*4882a593SmuzhiyunWhen first starting the Xserver collects all this information, saves it
2169*4882a593Smuzhiyunfor restoration, checks it for consistency, and if necessary, corrects
2170*4882a593Smuzhiyunit.  Finally it disables all resources on a generic level prior to
2171*4882a593Smuzhiyuncalling any driver function.
2172*4882a593Smuzhiyun      </para>
2173*4882a593Smuzhiyun
2174*4882a593Smuzhiyun      <para>
2175*4882a593SmuzhiyunWhen the <function>Probe()</function> function of each driver is called the
2176*4882a593Smuzhiyundevice sections are matched against the devices found in the system.
2177*4882a593SmuzhiyunThe driver may probe devices at this stage that cannot be identified by
2178*4882a593Smuzhiyunusing device independent methods.  Access to all resources that can be
2179*4882a593Smuzhiyuncontrolled in a device independent way is disabled.  The
2180*4882a593Smuzhiyun<function>Probe()</function> function should register all non-relocatable
2181*4882a593Smuzhiyunresources at this stage.  If a resource conflict is found between
2182*4882a593Smuzhiyunexclusive resources the driver will fail immediately.  Optionally the
2183*4882a593Smuzhiyundriver might specify an <function>EntityInit()</function>,
2184*4882a593Smuzhiyun<function>EntityLeave()</function> and <function>EntityEnter()</function> function.
2185*4882a593Smuzhiyun      </para>
2186*4882a593Smuzhiyun
2187*4882a593Smuzhiyun      <para>
2188*4882a593Smuzhiyun<function>EntityInit()</function> can be used to disable any shared resources
2189*4882a593Smuzhiyunthat are not controlled by the generic access control functions.  It is
2190*4882a593Smuzhiyuncalled prior to the PreInit phase regardless if an entity is active or
2191*4882a593Smuzhiyunnot.  When calling the <function>EntityInit()</function>,
2192*4882a593Smuzhiyun<function>EntityEnter()</function> and <function>EntityLeave()</function> functions
2193*4882a593Smuzhiyunthe common level will disable access to all other entities on a generic
2194*4882a593Smuzhiyunlevel.  Since the common level has no knowledge of device specific
2195*4882a593Smuzhiyunmethods to disable access to resources it cannot be guaranteed that
2196*4882a593Smuzhiyuncertain resources are not decoded by any other entity until the
2197*4882a593Smuzhiyun<function>EntityInit()</function> or <function>EntityEnter()</function> phase is
2198*4882a593Smuzhiyunfinished.  Device drivers should therefore register all those resources
2199*4882a593Smuzhiyunwhich they are going to disable.  If these resources are never to be
2200*4882a593Smuzhiyunused by any driver function they may be flagged <constant>ResInit</constant>
2201*4882a593Smuzhiyunso that they can be removed from the resource list after processing all
2202*4882a593Smuzhiyun<function>EntityInit()</function> functions.  <function>EntityEnter()</function>
2203*4882a593Smuzhiyunshould disable decoding of all resources which are not registered as
2204*4882a593Smuzhiyunexclusive and which are not handled by the generic access control in
2205*4882a593Smuzhiyunthe common level.  The difference to <function>EntityInit()</function> is
2206*4882a593Smuzhiyunthat the latter one is only called once during lifetime of the server.
2207*4882a593SmuzhiyunIt can therefore be used to set up variables prior to disabling resources.
2208*4882a593Smuzhiyun<function>EntityLeave()</function> should restore the original state when
2209*4882a593Smuzhiyunexiting the server or switching to a different VT.  It also needs to
2210*4882a593Smuzhiyundisable device specific access functions if they need to be disabled on
2211*4882a593Smuzhiyunserver exit or VT switch.  The default state is to enable them before
2212*4882a593Smuzhiyungiving up the VT.
2213*4882a593Smuzhiyun      </para>
2214*4882a593Smuzhiyun
2215*4882a593Smuzhiyun      <para>
2216*4882a593SmuzhiyunIn <function>PreInit()</function> phase each driver should check if any
2217*4882a593Smuzhiyunsharable resources it has registered during <function>Probe()</function> has
2218*4882a593Smuzhiyunbeen denied and take appropriate action which could simply be to fail.
2219*4882a593SmuzhiyunIf it needs to access resources it has disabled during
2220*4882a593Smuzhiyun<function>EntitySetup()</function> it can do so provided it has registered
2221*4882a593Smuzhiyunthese and will disable them before returning from
2222*4882a593Smuzhiyun<function>PreInit()</function>.  This also applies to all other driver
2223*4882a593Smuzhiyunfunctions.  Several functions are provided to request resource ranges,
2224*4882a593Smuzhiyunregister these, correct PCI config space and add replacements for the
2225*4882a593Smuzhiyungeneric access functions.  Resources may be marked <quote>disabled</quote> or
2226*4882a593Smuzhiyun<quote>unused</quote> during OPERATING stage.  Although these steps could also be
2227*4882a593Smuzhiyunperformed in <function>ScreenInit()</function>, this is not desirable.
2228*4882a593Smuzhiyun      </para>
2229*4882a593Smuzhiyun
2230*4882a593Smuzhiyun      <para>
2231*4882a593SmuzhiyunFollowing <function>PreInit()</function> phase the common level determines
2232*4882a593Smuzhiyunif resource access control is needed.  This is the case if more than
2233*4882a593Smuzhiyunone screen is used.  If necessary the RAC wrapper module is loaded.  In
2234*4882a593Smuzhiyun<function>ScreenInit()</function> the drivers can decide which operations
2235*4882a593Smuzhiyunneed to be placed under RAC.  Available are the frame buffer operations,
2236*4882a593Smuzhiyunthe pointer operations and the colormap operations.  Any operation that
2237*4882a593Smuzhiyunrequires resources which might be disabled during OPERATING state should
2238*4882a593Smuzhiyunbe set to use RAC.  This can be specified separately for memory and IO
2239*4882a593Smuzhiyunresources.
2240*4882a593Smuzhiyun      </para>
2241*4882a593Smuzhiyun
2242*4882a593Smuzhiyun      <para>
2243*4882a593SmuzhiyunWhen <function>ScreenInit()</function> phase is done the common level will
2244*4882a593Smuzhiyundetermine which shared resources are requested by more than one driver
2245*4882a593Smuzhiyunand set the access functions accordingly.  This is done following these
2246*4882a593Smuzhiyunrules:
2247*4882a593Smuzhiyun
2248*4882a593Smuzhiyun	<orderedlist>
2249*4882a593Smuzhiyun	  <listitem><para>
2250*4882a593Smuzhiyun   The sharable resources registered by each entity are compared.  If
2251*4882a593Smuzhiyun   a resource is registered by more than one entity the entity will be
2252*4882a593Smuzhiyun   marked to need to share this resources type (<constant>IO</constant> or
2253*4882a593Smuzhiyun   <constant>MEM</constant>).
2254*4882a593Smuzhiyun	    </para></listitem>
2255*4882a593Smuzhiyun
2256*4882a593Smuzhiyun	  <listitem><para>
2257*4882a593Smuzhiyun   A resource marked <quote>disabled</quote> during OPERATING state will be ignored
2258*4882a593Smuzhiyun   entirely.
2259*4882a593Smuzhiyun	    </para></listitem>
2260*4882a593Smuzhiyun
2261*4882a593Smuzhiyun	  <listitem><para>
2262*4882a593Smuzhiyun   A resource marked <quote>unused</quote> will only conflicts with an overlapping
2263*4882a593Smuzhiyun   resource of an other entity if the second is actually in use during
2264*4882a593Smuzhiyun   OPERATING state.
2265*4882a593Smuzhiyun	    </para></listitem>
2266*4882a593Smuzhiyun
2267*4882a593Smuzhiyun	  <listitem><para>
2268*4882a593Smuzhiyun   If an <quote>unused</quote> resource was found to conflict however the entity
2269*4882a593Smuzhiyun   does not use any other resource of this type the entire resource type
2270*4882a593Smuzhiyun   will be disabled for that entity.
2271*4882a593Smuzhiyun	    </para></listitem>
2272*4882a593Smuzhiyun	</orderedlist>
2273*4882a593Smuzhiyun      </para>
2274*4882a593Smuzhiyun
2275*4882a593Smuzhiyun      <para>
2276*4882a593SmuzhiyunThe driver has the choice among different ways to control access to
2277*4882a593Smuzhiyuncertain resources:
2278*4882a593Smuzhiyun
2279*4882a593Smuzhiyun	<orderedlist>
2280*4882a593Smuzhiyun	  <listitem><para>
2281*4882a593Smuzhiyun   It can rely on the generic access functions.  This is probably the
2282*4882a593Smuzhiyun   most common case.  Here the driver only needs to register any resource
2283*4882a593Smuzhiyun   it is going to use.
2284*4882a593Smuzhiyun	    </para></listitem>
2285*4882a593Smuzhiyun
2286*4882a593Smuzhiyun	  <listitem><para>
2287*4882a593Smuzhiyun   It can replace the generic access functions by driver specific
2288*4882a593Smuzhiyun   ones.  This will mostly be used in cases where no generic access
2289*4882a593Smuzhiyun   functions are available.  In this case the driver has to make sure
2290*4882a593Smuzhiyun   these resources are disabled when entering the <function>PreInit()</function>
2291*4882a593Smuzhiyun   stage.  Since the replacement functions are registered in
2292*4882a593Smuzhiyun   <function>PreInit()</function> the driver will have to enable these
2293*4882a593Smuzhiyun   resources itself if it needs to access them during this state.  The
2294*4882a593Smuzhiyun   driver can specify if the replacement functions can control memory
2295*4882a593Smuzhiyun   and/or I/O resources separately.
2296*4882a593Smuzhiyun	    </para></listitem>
2297*4882a593Smuzhiyun
2298*4882a593Smuzhiyun	  <listitem><para>
2299*4882a593Smuzhiyun   The driver can enable resources itself when it needs them.  Each
2300*4882a593Smuzhiyun   driver function enabling them needs to disable them before it will
2301*4882a593Smuzhiyun   return.  This should be used if a resource which can be controlled
2302*4882a593Smuzhiyun   in a device dependent way is only required during SETUP state.  This
2303*4882a593Smuzhiyun   way it can be marked <quote>unused</quote> during OPERATING state.
2304*4882a593Smuzhiyun	    </para></listitem>
2305*4882a593Smuzhiyun	</orderedlist>
2306*4882a593Smuzhiyun      </para>
2307*4882a593Smuzhiyun
2308*4882a593Smuzhiyun      <para>
2309*4882a593SmuzhiyunA resource which is decoded during OPERATING state however never accessed
2310*4882a593Smuzhiyunby the driver should be marked unused.
2311*4882a593Smuzhiyun      </para>
2312*4882a593Smuzhiyun
2313*4882a593Smuzhiyun      <para>
2314*4882a593SmuzhiyunSince access switching latencies are an issue during Xserver operation,
2315*4882a593Smuzhiyunthe common level attempts to minimize the number of entities that need
2316*4882a593Smuzhiyunto be placed under RAC control.  When a wrapped operation is called,
2317*4882a593Smuzhiyunthe <function>EnableAccess()</function> function is called before control is
2318*4882a593Smuzhiyunpassed on.  <function>EnableAccess()</function> checks if a screen is under
2319*4882a593Smuzhiyunaccess control.  If not it just establishes bus routing and returns.
2320*4882a593SmuzhiyunIf the screen needs to be under access control,
2321*4882a593Smuzhiyun<function>EnableAccess()</function> determines which resource types
2322*4882a593Smuzhiyun(<literal remap="tt">MEM</literal>, <literal remap="tt">IO</literal>) are required.  Then it tests
2323*4882a593Smuzhiyunif this access is already established.  If so it simply returns.  If
2324*4882a593Smuzhiyunnot it disables the currently established access, fixes bus routing and
2325*4882a593Smuzhiyunenables access to all entities registered for this screen.
2326*4882a593Smuzhiyun      </para>
2327*4882a593Smuzhiyun
2328*4882a593Smuzhiyun      <para>
2329*4882a593SmuzhiyunWhenever a mode switch or a VT-switch is performed the common level will
2330*4882a593Smuzhiyunreturn to SETUP state.
2331*4882a593Smuzhiyun      </para>
2332*4882a593Smuzhiyun    </sect2>
2333*4882a593Smuzhiyun
2334*4882a593Smuzhiyun    <sect2>
2335*4882a593Smuzhiyun      <title>Resource Types</title>
2336*4882a593Smuzhiyun
2337*4882a593Smuzhiyun      <para>
2338*4882a593SmuzhiyunResource have certain properties.  When registering resources each range
2339*4882a593Smuzhiyunis accompanied by a flag consisting of the ORed flags of the different
2340*4882a593Smuzhiyunproperties the resource has.  Each resource range may be classified
2341*4882a593Smuzhiyunaccording to
2342*4882a593Smuzhiyun
2343*4882a593Smuzhiyun	<itemizedlist>
2344*4882a593Smuzhiyun	  <listitem><para>
2345*4882a593Smuzhiyun       its physical properties i.e., if it addresses
2346*4882a593Smuzhiyun       memory (<constant>ResMem</constant>)  or
2347*4882a593Smuzhiyun       I/O space (<constant>ResIo</constant>),
2348*4882a593Smuzhiyun	    </para></listitem>
2349*4882a593Smuzhiyun	  <listitem><para>
2350*4882a593Smuzhiyun       if it addresses a
2351*4882a593Smuzhiyun       block (<constant>ResBlock</constant>) or
2352*4882a593Smuzhiyun       sparse (<constant>ResSparse</constant>)
2353*4882a593Smuzhiyun       range,
2354*4882a593Smuzhiyun	    </para></listitem>
2355*4882a593Smuzhiyun	  <listitem><para>
2356*4882a593Smuzhiyun       its access properties.
2357*4882a593Smuzhiyun	    </para></listitem>
2358*4882a593Smuzhiyun	</itemizedlist>
2359*4882a593Smuzhiyun      </para>
2360*4882a593Smuzhiyun
2361*4882a593Smuzhiyun      <para>
2362*4882a593SmuzhiyunThere are two known access properties:
2363*4882a593Smuzhiyun
2364*4882a593Smuzhiyun	<itemizedlist>
2365*4882a593Smuzhiyun	  <listitem><para>
2366*4882a593Smuzhiyun  <constant>ResExclusive</constant>
2367*4882a593Smuzhiyun    for resources which may not be shared with any other device and
2368*4882a593Smuzhiyun	    </para></listitem>
2369*4882a593Smuzhiyun	  <listitem><para>
2370*4882a593Smuzhiyun  <constant>ResShared</constant>
2371*4882a593Smuzhiyun    for resources which can be disabled and therefore can be shared.
2372*4882a593Smuzhiyun	    </para></listitem>
2373*4882a593Smuzhiyun	</itemizedlist>
2374*4882a593Smuzhiyun      </para>
2375*4882a593Smuzhiyun
2376*4882a593Smuzhiyun      <para>
2377*4882a593SmuzhiyunIf it is necessary to test a resource against any type a generic access
2378*4882a593Smuzhiyuntype <constant>ResAny</constant> is provided.  If this is set the resource
2379*4882a593Smuzhiyunwill conflict with any resource of a different entity intersecting its
2380*4882a593Smuzhiyunrange.  Further it can be specified that a resource is decoded however
2381*4882a593Smuzhiyunnever used during any stage (<constant>ResUnused</constant>) or during
2382*4882a593SmuzhiyunOPERATING state (<constant>ResUnusedOpr</constant>).  A resource only visible
2383*4882a593Smuzhiyunduring the init functions (ie.  <function>EntityInit()</function>,
2384*4882a593Smuzhiyun<function>EntityEnter()</function> and <function>EntityLeave()</function> should
2385*4882a593Smuzhiyunbe registered with the flag <constant>ResInit</constant>.  A resource that
2386*4882a593Smuzhiyunmight conflict with background resource ranges may be flagged with
2387*4882a593Smuzhiyun<constant>ResBios</constant>.  This might be useful when registering resources
2388*4882a593Smuzhiyunranges that were assigned by the system Bios.
2389*4882a593Smuzhiyun      </para>
2390*4882a593Smuzhiyun
2391*4882a593Smuzhiyun      <para>
2392*4882a593SmuzhiyunSeveral predefined resource lists are available for VGA and 8514/A
2393*4882a593Smuzhiyunresources in <filename>common/xf86Resources.h</filename>.
2394*4882a593Smuzhiyun      </para>
2395*4882a593Smuzhiyun    </sect2>
2396*4882a593Smuzhiyun
2397*4882a593Smuzhiyun    <sect2 id="avail">
2398*4882a593Smuzhiyun      <title>Available Functions</title>
2399*4882a593Smuzhiyun
2400*4882a593Smuzhiyun      <para>
2401*4882a593SmuzhiyunThe functions provided for resource management are listed in their order
2402*4882a593Smuzhiyunof use in the driver.
2403*4882a593Smuzhiyun      </para>
2404*4882a593Smuzhiyun
2405*4882a593Smuzhiyun      <sect3>
2406*4882a593Smuzhiyun	<title>Probe Phase</title>
2407*4882a593Smuzhiyun
2408*4882a593Smuzhiyun	<para>
2409*4882a593SmuzhiyunIn this phase each driver detects those resources it is able to drive,
2410*4882a593Smuzhiyuncreates an entity record for each of them, registers non-relocatable
2411*4882a593Smuzhiyunresources and allocates screens and adds the resources to screens.
2412*4882a593Smuzhiyun	</para>
2413*4882a593Smuzhiyun
2414*4882a593Smuzhiyun	<para>
2415*4882a593SmuzhiyunTwo helper functions are provided for matching device sections in the
2416*4882a593Smuzhiyunxorg.conf file to the devices:
2417*4882a593Smuzhiyun	</para>
2418*4882a593Smuzhiyun
2419*4882a593Smuzhiyun	<blockquote><para>
2420*4882a593Smuzhiyun	    <programlisting>
2421*4882a593Smuzhiyun    int xf86MatchPciInstances(const char *driverName, int vendorID,
2422*4882a593Smuzhiyun                              SymTabPtr chipsets, PciChipsets *PCIchipsets,
2423*4882a593Smuzhiyun                              GDevPtr *devList, int numDevs, DriverPtr drvp,
2424*4882a593Smuzhiyun                              int **foundEntities);
2425*4882a593Smuzhiyun	    </programlisting>
2426*4882a593Smuzhiyun	    <blockquote><para>
2427*4882a593Smuzhiyun      This function finds matches between PCI cards that a driver supports
2428*4882a593Smuzhiyun      and config file device sections.  It is intended for use in the
2429*4882a593Smuzhiyun      <function>ChipProbe()</function> function of drivers for PCI cards.
2430*4882a593Smuzhiyun      Only probed PCI devices with a vendor ID matching
2431*4882a593Smuzhiyun      <parameter>vendorID</parameter> are considered.  <parameter>devList</parameter>
2432*4882a593Smuzhiyun      and <parameter>numDevs</parameter> are typically those found from
2433*4882a593Smuzhiyun      calling <function>xf86MatchDevice()</function>, and represent the active
2434*4882a593Smuzhiyun      config file device sections relevant to the driver.
2435*4882a593Smuzhiyun      <parameter>PCIchipsets</parameter> is a table that provides a mapping
2436*4882a593Smuzhiyun      between the PCI device IDs, the driver's internal chipset tokens
2437*4882a593Smuzhiyun      and a list of fixed resources.
2438*4882a593Smuzhiyun	      </para>
2439*4882a593Smuzhiyun
2440*4882a593Smuzhiyun	      <para>
2441*4882a593Smuzhiyun      When a device section doesn't have a <emphasis>BusID</emphasis> entry it
2442*4882a593Smuzhiyun      can only match the primary video device.  Secondary devices are
2443*4882a593Smuzhiyun      only matched with device sections that have a matching
2444*4882a593Smuzhiyun      <emphasis>BusID</emphasis> entry.
2445*4882a593Smuzhiyun	      </para>
2446*4882a593Smuzhiyun
2447*4882a593Smuzhiyun	      <para>
2448*4882a593Smuzhiyun      Once the preliminary matches have been found, a final match is
2449*4882a593Smuzhiyun      confirmed by checking if the chipset override, ChipID override or
2450*4882a593Smuzhiyun      probed PCI chipset type match one of those given in the
2451*4882a593Smuzhiyun      <parameter>chipsets</parameter> and <parameter>PCIchipsets</parameter> lists.
2452*4882a593Smuzhiyun      The <parameter>PCIchipsets</parameter> list includes a list of the PCI
2453*4882a593Smuzhiyun      device IDs supported by the driver.  The list should be terminated
2454*4882a593Smuzhiyun      with an entry with PCI ID <constant>-1</constant>".  The
2455*4882a593Smuzhiyun      <parameter>chipsets</parameter> list is a table mapping the driver's
2456*4882a593Smuzhiyun      internal chipset tokens to names, and should be terminated with
2457*4882a593Smuzhiyun      a <constant>NULL</constant> entry.  Only those entries with a
2458*4882a593Smuzhiyun      corresponding entry in the <parameter>PCIchipsets</parameter> list are
2459*4882a593Smuzhiyun      considered.  The order of precedence is: config file chipset,
2460*4882a593Smuzhiyun      config file ChipID, probed PCI device ID.
2461*4882a593Smuzhiyun	      </para>
2462*4882a593Smuzhiyun
2463*4882a593Smuzhiyun	      <para>
2464*4882a593Smuzhiyun      In cases where a driver handles PCI chipsets with more than one
2465*4882a593Smuzhiyun      vendor ID, it may set <parameter>vendorID</parameter> to
2466*4882a593Smuzhiyun      <constant>0</constant>, and OR each devID in the list with (the
2467*4882a593Smuzhiyun      vendor&nbsp;ID&nbsp;&lt;&lt;&nbsp;16).
2468*4882a593Smuzhiyun	      </para>
2469*4882a593Smuzhiyun
2470*4882a593Smuzhiyun	      <para>
2471*4882a593Smuzhiyun      Entity index numbers for confirmed matches are returned as an
2472*4882a593Smuzhiyun      array via <parameter>foundEntities</parameter>.  The PCI information,
2473*4882a593Smuzhiyun      chipset token and device section for each match are found in the
2474*4882a593Smuzhiyun      <structname>EntityInfoRec</structname> referenced by the indices.
2475*4882a593Smuzhiyun	      </para>
2476*4882a593Smuzhiyun
2477*4882a593Smuzhiyun	      <para>
2478*4882a593Smuzhiyun      The function return value is the number of confirmed matches.  A
2479*4882a593Smuzhiyun      return value of <constant>-1</constant> indicates an internal error.
2480*4882a593Smuzhiyun      The returned <parameter>foundEntities</parameter> array should be freed
2481*4882a593Smuzhiyun      by the driver with <function>xfree()</function> when it is no longer
2482*4882a593Smuzhiyun      needed in cases where the return value is greater than zero.
2483*4882a593Smuzhiyun	      </para>
2484*4882a593Smuzhiyun
2485*4882a593Smuzhiyun	    </blockquote></para></blockquote>
2486*4882a593Smuzhiyun
2487*4882a593Smuzhiyun	<para>
2488*4882a593SmuzhiyunThese two helper functions make use of several core functions that are
2489*4882a593Smuzhiyunavailable at the driver level:
2490*4882a593Smuzhiyun	</para>
2491*4882a593Smuzhiyun
2492*4882a593Smuzhiyun	<blockquote><para>
2493*4882a593Smuzhiyun	    <programlisting>
2494*4882a593Smuzhiyun    Bool xf86ParsePciBusString(const char *busID, int *bus,
2495*4882a593Smuzhiyun                               int *device, int *func);
2496*4882a593Smuzhiyun	    </programlisting>
2497*4882a593Smuzhiyun	    <blockquote><para>
2498*4882a593Smuzhiyun      Takes a <parameter>BusID</parameter> string, and if it is in the correct
2499*4882a593Smuzhiyun      format, returns the PCI <parameter>bus</parameter>, <parameter>device</parameter>,
2500*4882a593Smuzhiyun      <parameter>func</parameter> values that it indicates.  The format of the
2501*4882a593Smuzhiyun      string is expected to be "PCI:bus:device:func" where each of <quote>bus</quote>,
2502*4882a593Smuzhiyun      <quote>device</quote> and <quote>func</quote> are decimal integers.  The ":func" part may
2503*4882a593Smuzhiyun      be omitted, and the func value assumed to be zero, but this isn't
2504*4882a593Smuzhiyun      encouraged.  The "PCI" prefix may also be omitted.  The prefix
2505*4882a593Smuzhiyun      "AGP" is currently equivalent to the "PCI" prefix.  If the string
2506*4882a593Smuzhiyun      isn't a valid PCI BusID, the return value is <constant>FALSE</constant>.
2507*4882a593Smuzhiyun	      </para>
2508*4882a593Smuzhiyun
2509*4882a593Smuzhiyun	    </blockquote></para></blockquote>
2510*4882a593Smuzhiyun
2511*4882a593Smuzhiyun	<blockquote><para>
2512*4882a593Smuzhiyun	    <programlisting>
2513*4882a593Smuzhiyun    Bool xf86ComparePciBusString(const char *busID, int bus,
2514*4882a593Smuzhiyun                                 int device, int func);
2515*4882a593Smuzhiyun	    </programlisting>
2516*4882a593Smuzhiyun	    <blockquote><para>
2517*4882a593Smuzhiyun      Compares a <parameter>BusID</parameter> string with PCI <parameter>bus</parameter>,
2518*4882a593Smuzhiyun      <parameter>device</parameter>, <parameter>func</parameter> values.  If they
2519*4882a593Smuzhiyun      match <constant>TRUE</constant> is returned, and <constant>FALSE</constant>
2520*4882a593Smuzhiyun      if they don't.
2521*4882a593Smuzhiyun	      </para>
2522*4882a593Smuzhiyun
2523*4882a593Smuzhiyun	    </blockquote></para></blockquote>
2524*4882a593Smuzhiyun
2525*4882a593Smuzhiyun	<blockquote><para>
2526*4882a593Smuzhiyun	    <programlisting>
2527*4882a593Smuzhiyun    Bool xf86CheckPciSlot(int bus, int device, int func);
2528*4882a593Smuzhiyun	    </programlisting>
2529*4882a593Smuzhiyun	    <blockquote><para>
2530*4882a593Smuzhiyun      Checks if the PCI slot <literal remap="tt">bus:device:func</literal> has been
2531*4882a593Smuzhiyun      claimed.  If so, it returns <constant>FALSE</constant>, and otherwise
2532*4882a593Smuzhiyun      <constant>TRUE</constant>.
2533*4882a593Smuzhiyun	      </para>
2534*4882a593Smuzhiyun
2535*4882a593Smuzhiyun	    </blockquote></para></blockquote>
2536*4882a593Smuzhiyun
2537*4882a593Smuzhiyun	<blockquote><para>
2538*4882a593Smuzhiyun	    <programlisting>
2539*4882a593Smuzhiyun    int xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp,
2540*4882a593Smuzhiyun                         int chipset, GDevPtr dev, Bool active);
2541*4882a593Smuzhiyun	    </programlisting>
2542*4882a593Smuzhiyun	    <blockquote><para>
2543*4882a593Smuzhiyun      This function is used to claim a PCI slot, allocate the associated
2544*4882a593Smuzhiyun      entity record and initialise their data structures.  The return
2545*4882a593Smuzhiyun      value is the index of the newly allocated entity record, or
2546*4882a593Smuzhiyun      <constant>-1</constant> if the claim fails.  This function should always
2547*4882a593Smuzhiyun      succeed if <function>xf86CheckPciSlot()</function> returned
2548*4882a593Smuzhiyun      <constant>TRUE</constant> for the same PCI slot.
2549*4882a593Smuzhiyun	      </para>
2550*4882a593Smuzhiyun
2551*4882a593Smuzhiyun	    </blockquote></para></blockquote>
2552*4882a593Smuzhiyun
2553*4882a593Smuzhiyun	<blockquote><para>
2554*4882a593Smuzhiyun	    <programlisting>
2555*4882a593Smuzhiyun    Bool xf86IsPrimaryPci(void);
2556*4882a593Smuzhiyun	    </programlisting>
2557*4882a593Smuzhiyun	    <blockquote><para>
2558*4882a593Smuzhiyun      This function returns <constant>TRUE</constant> if the primary card is
2559*4882a593Smuzhiyun      a PCI device, and <constant>FALSE</constant> otherwise.
2560*4882a593Smuzhiyun	      </para>
2561*4882a593Smuzhiyun
2562*4882a593Smuzhiyun	    </blockquote></para></blockquote>
2563*4882a593Smuzhiyun
2564*4882a593Smuzhiyun	<para>
2565*4882a593SmuzhiyunTwo helper functions are provided to aid configuring entities:
2566*4882a593Smuzhiyun	</para>
2567*4882a593Smuzhiyun
2568*4882a593Smuzhiyun	<blockquote><para>
2569*4882a593Smuzhiyun	    <programlisting>
2570*4882a593Smuzhiyun    ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn,
2571*4882a593Smuzhiyun                                    int scrnFlag, int entityIndex,
2572*4882a593Smuzhiyun                                    PciChipsets *p_chip,
2573*4882a593Smuzhiyun                                    void *res, EntityProc init,
2574*4882a593Smuzhiyun                                    EntityProc enter, EntityProc leave,
2575*4882a593Smuzhiyun                                    pointer private);
2576*4882a593Smuzhiyun
2577*4882a593Smuzhiyun	    </programlisting>
2578*4882a593Smuzhiyun	    <blockquote><para>
2579*4882a593Smuzhiyun      This functions is used to register the entity. The <parameter>res</parameter>, <parameter>init</parameter>, <parameter>enter</parameter>, and <parameter>leave</parameter> arguments are unused, and should be <constant>NULL</constant>.
2580*4882a593Smuzhiyun      For active entities a <structname>ScrnInfoRec</structname> is allocated
2581*4882a593Smuzhiyun      if the <parameter>pScrn</parameter> argument is <constant>NULL</constant>.
2582*4882a593SmuzhiyunThe
2583*4882a593Smuzhiyun      return value is <constant>TRUE</constant> when successful.
2584*4882a593Smuzhiyun	      </para>
2585*4882a593Smuzhiyun
2586*4882a593Smuzhiyun	    </blockquote></para></blockquote>
2587*4882a593Smuzhiyun
2588*4882a593Smuzhiyun	<para>
2589*4882a593SmuzhiyunThese two helper functions make use of several core functions that are
2590*4882a593Smuzhiyunavailable at the driver level:
2591*4882a593Smuzhiyun
2592*4882a593Smuzhiyun	  <blockquote><para>
2593*4882a593Smuzhiyun	      <programlisting>
2594*4882a593Smuzhiyun    void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex);
2595*4882a593Smuzhiyun	      </programlisting>
2596*4882a593Smuzhiyun	      <blockquote><para>
2597*4882a593Smuzhiyun      This function associates the entity referenced by
2598*4882a593Smuzhiyun      <parameter>entityIndex</parameter> with the screen.
2599*4882a593Smuzhiyun		</para>
2600*4882a593Smuzhiyun
2601*4882a593Smuzhiyun	      </blockquote></para></blockquote>
2602*4882a593Smuzhiyun	</para>
2603*4882a593Smuzhiyun      </sect3>
2604*4882a593Smuzhiyun
2605*4882a593Smuzhiyun      <sect3>
2606*4882a593Smuzhiyun	<title>PreInit Phase</title>
2607*4882a593Smuzhiyun
2608*4882a593Smuzhiyun	<para>
2609*4882a593SmuzhiyunDuring this phase the remaining resources should be registered.
2610*4882a593Smuzhiyun<function>PreInit()</function> should call <function>xf86GetEntityInfo()</function>
2611*4882a593Smuzhiyunto obtain a pointer to an <structname>EntityInfoRec</structname> for each entity
2612*4882a593Smuzhiyunit is able to drive and check if any resource are listed in its
2613*4882a593Smuzhiyun<structfield>resources</structfield> field.  If resources registered in the Probe
2614*4882a593Smuzhiyunphase have been rejected in the post-Probe phase
2615*4882a593Smuzhiyun(<structfield>resources</structfield> is non-<constant>NULL</constant>), then the driver should
2616*4882a593Smuzhiyundecide if it can continue without using these or if it should fail.
2617*4882a593Smuzhiyun	</para>
2618*4882a593Smuzhiyun
2619*4882a593Smuzhiyun	<blockquote><para>
2620*4882a593Smuzhiyun	    <programlisting>
2621*4882a593Smuzhiyun    EntityInfoPtr xf86GetEntityInfo(int entityIndex);
2622*4882a593Smuzhiyun	    </programlisting>
2623*4882a593Smuzhiyun	    <blockquote><para>
2624*4882a593Smuzhiyun      This function returns a pointer to the <structname>EntityInfoRec</structname>
2625*4882a593Smuzhiyun      referenced by <parameter>entityIndex</parameter>.  The returned
2626*4882a593Smuzhiyun      <structname>EntityInfoRec</structname> should be freed with
2627*4882a593Smuzhiyun      <function>xfree()</function> when no longer needed.
2628*4882a593Smuzhiyun	      </para>
2629*4882a593Smuzhiyun
2630*4882a593Smuzhiyun	    </blockquote></para></blockquote>
2631*4882a593Smuzhiyun
2632*4882a593Smuzhiyun	<para>
2633*4882a593SmuzhiyunSeveral functions are provided to simplify resource registration:
2634*4882a593Smuzhiyun	  <blockquote><para>
2635*4882a593Smuzhiyun	      <programlisting>
2636*4882a593Smuzhiyun    Bool xf86IsEntityPrimary(int entityIndex);
2637*4882a593Smuzhiyun	      </programlisting>
2638*4882a593Smuzhiyun	      <blockquote><para>
2639*4882a593Smuzhiyun      This function returns <constant>TRUE</constant> if the entity referenced
2640*4882a593Smuzhiyun      by <parameter>entityIndex</parameter> is the primary display device (i.e.,
2641*4882a593Smuzhiyun      the one initialised at boot time and used in text mode).
2642*4882a593Smuzhiyun		</para>
2643*4882a593Smuzhiyun
2644*4882a593Smuzhiyun	      </blockquote></para></blockquote>
2645*4882a593Smuzhiyun
2646*4882a593Smuzhiyun	  <blockquote><para>
2647*4882a593Smuzhiyun	      <programlisting>
2648*4882a593Smuzhiyun    Bool xf86IsScreenPrimary(ScrnInfoPtr pScrn);
2649*4882a593Smuzhiyun	      </programlisting>
2650*4882a593Smuzhiyun	      <blockquote><para>
2651*4882a593Smuzhiyun      This function returns <constant>TRUE</constant> if the primary entity
2652*4882a593Smuzhiyun      is registered with the screen referenced by
2653*4882a593Smuzhiyun      <parameter>pScrn</parameter>.
2654*4882a593Smuzhiyun		</para>
2655*4882a593Smuzhiyun
2656*4882a593Smuzhiyun	      </blockquote></para></blockquote>
2657*4882a593Smuzhiyun
2658*4882a593Smuzhiyun	  <blockquote><para>
2659*4882a593Smuzhiyun	      <programlisting>
2660*4882a593Smuzhiyun    pciVideoPtr xf86GetPciInfoForEntity(int entityIndex);
2661*4882a593Smuzhiyun	      </programlisting>
2662*4882a593Smuzhiyun	      <blockquote><para>
2663*4882a593Smuzhiyun      This function returns a pointer to the <structname>pciVideoRec</structname>
2664*4882a593Smuzhiyun      for the specified entity.  If the entity is not a PCI device,
2665*4882a593Smuzhiyun      <constant>NULL</constant> is returned.
2666*4882a593Smuzhiyun		</para>
2667*4882a593Smuzhiyun
2668*4882a593Smuzhiyun	      </blockquote></para></blockquote>
2669*4882a593Smuzhiyun	</para>
2670*4882a593Smuzhiyun
2671*4882a593Smuzhiyun<para>
2672*4882a593SmuzhiyunTwo functions are provided to obtain a resource range of a given type:
2673*4882a593Smuzhiyun	  <blockquote><para>
2674*4882a593Smuzhiyun	      <programlisting>
2675*4882a593Smuzhiyun    resRange xf86GetBlock(long type, memType size,
2676*4882a593Smuzhiyun                          memType window_start, memType window_end,
2677*4882a593Smuzhiyun                          memType align_mask, resPtr avoid);
2678*4882a593Smuzhiyun	      </programlisting>
2679*4882a593Smuzhiyun	      <blockquote><para>
2680*4882a593Smuzhiyun      This function tries to find a block range of size
2681*4882a593Smuzhiyun      <parameter>size</parameter> and type <parameter>type</parameter> in a window
2682*4882a593Smuzhiyun      bound by <parameter>window_start</parameter> and <parameter>window_end</parameter>
2683*4882a593Smuzhiyun      with the alignment specified in <parameter>align_mask</parameter>.
2684*4882a593Smuzhiyun      Optionally a list of resource ranges which should be avoided within
2685*4882a593Smuzhiyun      the window can be supplied.  On failure a zero-length range of
2686*4882a593Smuzhiyun      type <constant>ResEnd</constant> will be returned.
2687*4882a593Smuzhiyun		</para>
2688*4882a593Smuzhiyun	      </blockquote></para></blockquote>
2689*4882a593Smuzhiyun
2690*4882a593Smuzhiyun	  <blockquote><para>
2691*4882a593Smuzhiyun	      <programlisting>
2692*4882a593Smuzhiyun    resRange xf86GetSparse(long type, memType fixed_bits,
2693*4882a593Smuzhiyun                           memType decode_mask, memType address_mask,
2694*4882a593Smuzhiyun                           resPtr avoid);
2695*4882a593Smuzhiyun	      </programlisting>
2696*4882a593Smuzhiyun	      <blockquote><para>
2697*4882a593Smuzhiyun      This function is like the previous one, but attempts to find a
2698*4882a593Smuzhiyun      sparse range instead of a block range.  Here three values have to
2699*4882a593Smuzhiyun      be specified: the <parameter>address_mask</parameter> which marks all
2700*4882a593Smuzhiyun      bits of the mask part of the address, the <parameter>decode_mask</parameter>
2701*4882a593Smuzhiyun      which masks out the bits which are hardcoded and are therefore
2702*4882a593Smuzhiyun      not available for relocation and the values of the fixed bits.
2703*4882a593Smuzhiyun      The function tries to find a base that satisfies the given condition.
2704*4882a593Smuzhiyun      If the function fails it will return a zero range of type
2705*4882a593Smuzhiyun      <constant>ResEnd</constant>.  Optionally it might be passed a list of
2706*4882a593Smuzhiyun      resource ranges to avoid.
2707*4882a593Smuzhiyun		</para>
2708*4882a593Smuzhiyun
2709*4882a593Smuzhiyun	      </blockquote></para></blockquote>
2710*4882a593Smuzhiyun	</para>
2711*4882a593Smuzhiyun
2712*4882a593Smuzhiyun	<para>
2713*4882a593Smuzhiyun	  <blockquote><para>
2714*4882a593Smuzhiyun	      <programlisting>
2715*4882a593Smuzhiyun    Bool xf86CheckPciMemBase(pciVideoPtr pPci, memType base);
2716*4882a593Smuzhiyun	      </programlisting>
2717*4882a593Smuzhiyun	      <blockquote><para>
2718*4882a593Smuzhiyun      This function checks that the memory base address specified matches
2719*4882a593Smuzhiyun      one of the PCI base address register values for the given PCI
2720*4882a593Smuzhiyun      device.  This is mostly used to check that an externally provided
2721*4882a593Smuzhiyun      base address (e.g., from a config file) matches an actual value
2722*4882a593Smuzhiyun      allocated to a device.
2723*4882a593Smuzhiyun		</para>
2724*4882a593Smuzhiyun
2725*4882a593Smuzhiyun	      </blockquote></para></blockquote>
2726*4882a593Smuzhiyun	</para>
2727*4882a593Smuzhiyun
2728*4882a593Smuzhiyun	<para>
2729*4882a593SmuzhiyunThe following two functions are provided for special cases:
2730*4882a593Smuzhiyun	  <blockquote><para>
2731*4882a593Smuzhiyun	      <programlisting>
2732*4882a593Smuzhiyun    void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex);
2733*4882a593Smuzhiyun	      </programlisting>
2734*4882a593Smuzhiyun	      <blockquote><para>
2735*4882a593Smuzhiyun      This function may be used to remove an entity from a screen.  This
2736*4882a593Smuzhiyun      only makes sense if a screen has more than one entity assigned or
2737*4882a593Smuzhiyun      the screen is to be deleted.  No test is made if the screen has
2738*4882a593Smuzhiyun      any entities left.
2739*4882a593Smuzhiyun		</para>
2740*4882a593Smuzhiyun
2741*4882a593Smuzhiyun	      </blockquote></para></blockquote>
2742*4882a593Smuzhiyun	</para>
2743*4882a593Smuzhiyun
2744*4882a593Smuzhiyun      </sect3>
2745*4882a593Smuzhiyun
2746*4882a593Smuzhiyun      <sect3>
2747*4882a593Smuzhiyun	<title>ScreenInit Phase</title>
2748*4882a593Smuzhiyun
2749*4882a593Smuzhiyun	<para>
2750*4882a593SmuzhiyunAll that is required in this phase is to setup the RAC flags.  Note that
2751*4882a593Smuzhiyunit is also permissible to set these flags up in the PreInit phase.  The
2752*4882a593SmuzhiyunRAC flags are held in the <structfield>racIoFlags</structfield> and <structfield>racMemFlags</structfield> fields of the
2753*4882a593Smuzhiyun<structname>ScrnInfoRec</structname> for each screen.  They specify which graphics operations
2754*4882a593Smuzhiyunmight require the use of shared resources.  This can be specified
2755*4882a593Smuzhiyunseparately for memory and I/O resources.  The available flags are defined
2756*4882a593Smuzhiyunin <filename>rac/xf86RAC.h</filename>.  They are:
2757*4882a593Smuzhiyun
2758*4882a593Smuzhiyun	  <variablelist>
2759*4882a593Smuzhiyun	    <varlistentry><term><constant>RAC_FB</constant></term>
2760*4882a593Smuzhiyun	      <listitem><para>
2761*4882a593Smuzhiyun	for framebuffer operations (including hw acceleration)
2762*4882a593Smuzhiyun		</para></listitem></varlistentry>
2763*4882a593Smuzhiyun	    <varlistentry><term><constant>RAC_CURSOR</constant></term>
2764*4882a593Smuzhiyun	      <listitem><para>
2765*4882a593Smuzhiyun	for Cursor operations
2766*4882a593Smuzhiyun        (??? I'm not sure if we need this for SW cursor it depends
2767*4882a593Smuzhiyun         on which level the sw cursor is drawn)
2768*4882a593Smuzhiyun		</para></listitem></varlistentry>
2769*4882a593Smuzhiyun	    <varlistentry><term><constant>RAC_COLORMAP</constant></term>
2770*4882a593Smuzhiyun	      <listitem><para>
2771*4882a593Smuzhiyun	for colormap operations
2772*4882a593Smuzhiyun		</para></listitem></varlistentry>
2773*4882a593Smuzhiyun	    <varlistentry><term><constant>RAC_VIEWPORT</constant></term>
2774*4882a593Smuzhiyun	      <listitem><para>
2775*4882a593Smuzhiyun	for the call to <function>ChipAdjustFrame()</function>
2776*4882a593Smuzhiyun		</para></listitem></varlistentry>
2777*4882a593Smuzhiyun	    </variablelist>
2778*4882a593Smuzhiyun
2779*4882a593Smuzhiyun
2780*4882a593SmuzhiyunThe flags are ORed together.
2781*4882a593Smuzhiyun	</para>
2782*4882a593Smuzhiyun      </sect3>
2783*4882a593Smuzhiyun    </sect2>
2784*4882a593Smuzhiyun  </sect1>
2785*4882a593Smuzhiyun
2786*4882a593Smuzhiyun  <sect1 id="options">
2787*4882a593Smuzhiyun    <title>Config file <quote>Option</quote> entries</title>
2788*4882a593Smuzhiyun
2789*4882a593Smuzhiyun    <para>
2790*4882a593SmuzhiyunOption entries are permitted in most sections and subsections of the
2791*4882a593Smuzhiyunconfig file.  There are two forms of option entries:
2792*4882a593Smuzhiyun
2793*4882a593Smuzhiyun      <variablelist>
2794*4882a593Smuzhiyun	<varlistentry><term>Option "option-name"</term>
2795*4882a593Smuzhiyun	  <listitem><para>
2796*4882a593Smuzhiyun	A boolean option.
2797*4882a593Smuzhiyun	    </para></listitem></varlistentry>
2798*4882a593Smuzhiyun	<varlistentry><term>Option "option-name" "option-value"</term>
2799*4882a593Smuzhiyun	  <listitem><para>
2800*4882a593Smuzhiyun	An option with an arbitrary value.
2801*4882a593Smuzhiyun	    </para></listitem></varlistentry>
2802*4882a593Smuzhiyun      </variablelist>
2803*4882a593Smuzhiyun    </para>
2804*4882a593Smuzhiyun
2805*4882a593Smuzhiyun    <para>
2806*4882a593SmuzhiyunThe option entries are handled by the parser, and a list of the parsed
2807*4882a593Smuzhiyunoptions is included with each of the appropriate data structures that
2808*4882a593Smuzhiyunthe drivers have access to.  The data structures used to hold the option
2809*4882a593Smuzhiyuninformation are opaque to the driver, and a driver must not access the
2810*4882a593Smuzhiyunoption data directly.  Instead, the common layer provides a set of
2811*4882a593Smuzhiyunfunctions that may be used to access, check and manipulate the option
2812*4882a593Smuzhiyundata.
2813*4882a593Smuzhiyun    </para>
2814*4882a593Smuzhiyun
2815*4882a593Smuzhiyun    <para>
2816*4882a593SmuzhiyunFirst, the low level option handling functions.  In most cases drivers
2817*4882a593Smuzhiyunwould not need to use these directly.
2818*4882a593Smuzhiyun    </para>
2819*4882a593Smuzhiyun
2820*4882a593Smuzhiyun    <blockquote><para>
2821*4882a593Smuzhiyun	<programlisting>
2822*4882a593Smuzhiyun    XF86OptionPtr xf86FindOption(XF86OptionPtr options, const char *name);
2823*4882a593Smuzhiyun	</programlisting>
2824*4882a593Smuzhiyun	<blockquote><para>
2825*4882a593Smuzhiyun      Takes a list of options and an option name, and returns a handle
2826*4882a593Smuzhiyun      for the first option entry in the list matching the name.  Returns
2827*4882a593Smuzhiyun      <constant>NULL</constant> if no match is found.
2828*4882a593Smuzhiyun	  </para>
2829*4882a593Smuzhiyun
2830*4882a593Smuzhiyun	</blockquote></para></blockquote>
2831*4882a593Smuzhiyun
2832*4882a593Smuzhiyun    <blockquote><para>
2833*4882a593Smuzhiyun	<programlisting>
2834*4882a593Smuzhiyun    const char *xf86FindOptionValue(XF86OptionPtr options, const char *name);
2835*4882a593Smuzhiyun	</programlisting>
2836*4882a593Smuzhiyun	<blockquote><para>
2837*4882a593Smuzhiyun      Takes a list of options and an option name, and returns the value
2838*4882a593Smuzhiyun      associated with the first option entry in the list matching the
2839*4882a593Smuzhiyun      name.  If the matching option has no value, an empty string
2840*4882a593Smuzhiyun      (<constant>""</constant>) is returned.  Returns <constant>NULL</constant>
2841*4882a593Smuzhiyun      if no match is found.
2842*4882a593Smuzhiyun	  </para>
2843*4882a593Smuzhiyun
2844*4882a593Smuzhiyun	</blockquote></para></blockquote>
2845*4882a593Smuzhiyun
2846*4882a593Smuzhiyun    <blockquote><para>
2847*4882a593Smuzhiyun	<programlisting>
2848*4882a593Smuzhiyun    void xf86MarkOptionUsed(XF86OptionPtr option);
2849*4882a593Smuzhiyun	</programlisting>
2850*4882a593Smuzhiyun	<blockquote><para>
2851*4882a593Smuzhiyun      Takes a handle for an option, and marks that option as used.
2852*4882a593Smuzhiyun	  </para>
2853*4882a593Smuzhiyun
2854*4882a593Smuzhiyun	</blockquote></para></blockquote>
2855*4882a593Smuzhiyun
2856*4882a593Smuzhiyun    <blockquote><para>
2857*4882a593Smuzhiyun	<programlisting>
2858*4882a593Smuzhiyun    void xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name);
2859*4882a593Smuzhiyun	</programlisting>
2860*4882a593Smuzhiyun	<blockquote><para>
2861*4882a593Smuzhiyun      Takes a list of options and an option name and marks the first
2862*4882a593Smuzhiyun      option entry in the list matching the name as used.
2863*4882a593Smuzhiyun	  </para>
2864*4882a593Smuzhiyun
2865*4882a593Smuzhiyun	</blockquote></para></blockquote>
2866*4882a593Smuzhiyun
2867*4882a593Smuzhiyun    <para>
2868*4882a593SmuzhiyunNext, the higher level functions that most drivers would use.
2869*4882a593Smuzhiyun    </para>
2870*4882a593Smuzhiyun    <blockquote><para>
2871*4882a593Smuzhiyun	<programlisting>
2872*4882a593Smuzhiyun    void xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts);
2873*4882a593Smuzhiyun	</programlisting>
2874*4882a593Smuzhiyun	<blockquote><para>
2875*4882a593Smuzhiyun      Collect the options from each of the config file sections used by
2876*4882a593Smuzhiyun      the screen (<parameter>pScrn</parameter>) and return the merged list as
2877*4882a593Smuzhiyun      <structfield>pScrn-&gt;options</structfield>.  This function requires that
2878*4882a593Smuzhiyun      <structfield>pScrn-&gt;confScreen</structfield>, <structfield>pScrn-&gt;display</structfield>,
2879*4882a593Smuzhiyun      <structfield>pScrn-&gt;monitor</structfield>,
2880*4882a593Smuzhiyun      <structfield>pScrn-&gt;numEntities</structfield>, and
2881*4882a593Smuzhiyun      <structfield>pScrn-&gt;entityList</structfield> are initialised.
2882*4882a593Smuzhiyun      <parameter>extraOpts</parameter> may optionally be set to an additional
2883*4882a593Smuzhiyun      list of options to be combined with the others.  The order of
2884*4882a593Smuzhiyun      precedence for options is <parameter>extraOpts</parameter>, display,
2885*4882a593Smuzhiyun      confScreen, monitor, device.
2886*4882a593Smuzhiyun	  </para>
2887*4882a593Smuzhiyun
2888*4882a593Smuzhiyun	</blockquote></para></blockquote>
2889*4882a593Smuzhiyun
2890*4882a593Smuzhiyun    <blockquote><para>
2891*4882a593Smuzhiyun	<programlisting>
2892*4882a593Smuzhiyun    void xf86ProcessOptions(int scrnIndex, XF86OptionPtr options,
2893*4882a593Smuzhiyun                            OptionInfoPtr optinfo);
2894*4882a593Smuzhiyun	</programlisting>
2895*4882a593Smuzhiyun	<blockquote><para>
2896*4882a593Smuzhiyun      Processes a list of options according to the information in the
2897*4882a593Smuzhiyun      array of <structname>OptionInfoRecs</structname> (<parameter>optinfo</parameter>).
2898*4882a593Smuzhiyun      The resulting information is stored in the <structfield>value</structfield>
2899*4882a593Smuzhiyun      fields of the appropriate <parameter>optinfo</parameter> entries.  The
2900*4882a593Smuzhiyun      <structfield>found</structfield> fields are set to <constant>TRUE</constant>
2901*4882a593Smuzhiyun      when an option with a value of the correct type if found, and
2902*4882a593Smuzhiyun      <constant>FALSE</constant> otherwise.  The <structfield>type</structfield> field
2903*4882a593Smuzhiyun      is used to determine the expected value type for each option.
2904*4882a593Smuzhiyun      Each option in the list of options for which there is a name match
2905*4882a593Smuzhiyun      (but not necessarily a value type match) is marked as used.
2906*4882a593Smuzhiyun      Warning messages are printed when option values don't match the
2907*4882a593Smuzhiyun      types specified in the optinfo data.
2908*4882a593Smuzhiyun	  </para>
2909*4882a593Smuzhiyun
2910*4882a593Smuzhiyun	  <para>
2911*4882a593Smuzhiyun      NOTE: If this function is called before a driver's screen number
2912*4882a593Smuzhiyun      is known (e.g., from the <function>ChipProbe()</function> function) a
2913*4882a593Smuzhiyun      <parameter>scrnIndex</parameter> value of <constant>-1</constant> should be
2914*4882a593Smuzhiyun      used.
2915*4882a593Smuzhiyun	  </para>
2916*4882a593Smuzhiyun
2917*4882a593Smuzhiyun	  <para>
2918*4882a593Smuzhiyun      NOTE 2: Given that this function stores into the
2919*4882a593Smuzhiyun      <literal remap="tt">OptionInfoRecs</literal> pointed to by <parameter>optinfo</parameter>,
2920*4882a593Smuzhiyun      the caller should ensure the <literal remap="tt">OptionInfoRecs</literal> are
2921*4882a593Smuzhiyun      (re-)initialised before the call, especially if the caller expects
2922*4882a593Smuzhiyun      to use the predefined option values as defaults.
2923*4882a593Smuzhiyun	  </para>
2924*4882a593Smuzhiyun
2925*4882a593Smuzhiyun	  <para>
2926*4882a593Smuzhiyun      The <structname>OptionInfoRec</structname> is defined as follows:
2927*4882a593Smuzhiyun
2928*4882a593Smuzhiyun	    <programlisting>
2929*4882a593Smuzhiyun      typedef struct {
2930*4882a593Smuzhiyun          double freq;
2931*4882a593Smuzhiyun          int units;
2932*4882a593Smuzhiyun      } OptFrequency;
2933*4882a593Smuzhiyun
2934*4882a593Smuzhiyun      typedef union {
2935*4882a593Smuzhiyun          unsigned long       num;
2936*4882a593Smuzhiyun          char *              str;
2937*4882a593Smuzhiyun          double              realnum;
2938*4882a593Smuzhiyun          Bool                bool;
2939*4882a593Smuzhiyun          OptFrequency        freq;
2940*4882a593Smuzhiyun      } ValueUnion;
2941*4882a593Smuzhiyun
2942*4882a593Smuzhiyun      typedef enum {
2943*4882a593Smuzhiyun          OPTV_NONE = 0,
2944*4882a593Smuzhiyun          OPTV_INTEGER,
2945*4882a593Smuzhiyun          OPTV_STRING,  /* a non-empty string */
2946*4882a593Smuzhiyun          OPTV_ANYSTR,  /* Any string, including an empty one */
2947*4882a593Smuzhiyun          OPTV_REAL,
2948*4882a593Smuzhiyun          OPTV_BOOLEAN,
2949*4882a593Smuzhiyun          OPTV_PERCENT,
2950*4882a593Smuzhiyun          OPTV_FREQ
2951*4882a593Smuzhiyun      } OptionValueType;
2952*4882a593Smuzhiyun
2953*4882a593Smuzhiyun      typedef enum {
2954*4882a593Smuzhiyun          OPTUNITS_HZ = 1,
2955*4882a593Smuzhiyun          OPTUNITS_KHZ,
2956*4882a593Smuzhiyun          OPTUNITS_MHZ
2957*4882a593Smuzhiyun      } OptFreqUnits;
2958*4882a593Smuzhiyun
2959*4882a593Smuzhiyun      typedef struct {
2960*4882a593Smuzhiyun          int                 token;
2961*4882a593Smuzhiyun          const char*         name;
2962*4882a593Smuzhiyun          OptionValueType     type;
2963*4882a593Smuzhiyun          ValueUnion          value;
2964*4882a593Smuzhiyun          Bool                found;
2965*4882a593Smuzhiyun      } OptionInfoRec, *OptionInfoPtr;
2966*4882a593Smuzhiyun	    </programlisting>
2967*4882a593Smuzhiyun	  </para>
2968*4882a593Smuzhiyun	  <para>
2969*4882a593Smuzhiyun      <constant>OPTV_FREQ</constant> can be used for options values that are
2970*4882a593Smuzhiyun      frequencies.  These values are a floating point number with an
2971*4882a593Smuzhiyun      optional unit name appended.  The unit name can be one of "Hz",
2972*4882a593Smuzhiyun      "kHz", "k", "MHz", "M".  The multiplier associated with the unit
2973*4882a593Smuzhiyun      is stored in <structfield>freq.units</structfield>, and the scaled frequency
2974*4882a593Smuzhiyun      is stored in <structfield>freq.freq</structfield>.  When no unit is specified,
2975*4882a593Smuzhiyun      <structfield>freq.units</structfield> is set to <constant>0</constant>, and
2976*4882a593Smuzhiyun      <structfield>freq.freq</structfield> is unscaled.
2977*4882a593Smuzhiyun	  </para>
2978*4882a593Smuzhiyun
2979*4882a593Smuzhiyun	  <para>
2980*4882a593Smuzhiyun      <constant>OPTV_PERCENT</constant> can be used for option values that are
2981*4882a593Smuzhiyun      specified in percent (e.g. "20%"). These values are a floating point
2982*4882a593Smuzhiyun      number with a percent sign appended. If the percent sign is missing,
2983*4882a593Smuzhiyun      the parser will fail to match the value.
2984*4882a593Smuzhiyun	  </para>
2985*4882a593Smuzhiyun
2986*4882a593Smuzhiyun	  <para>
2987*4882a593Smuzhiyun      Typical usage is to setup an array of
2988*4882a593Smuzhiyun      <structname>OptionInfoRec</structname>s with all fields initialised.
2989*4882a593Smuzhiyun      The <structfield>value</structfield> and <structfield>found</structfield> fields get
2990*4882a593Smuzhiyun      set by <function>xf86ProcessOptions()</function>.  For cases where the
2991*4882a593Smuzhiyun      value parsing is more complex, the driver should specify
2992*4882a593Smuzhiyun      <constant>OPTV_STRING</constant>, and parse the string itself.  An
2993*4882a593Smuzhiyun      example of using this option handling is included in the
2994*4882a593Smuzhiyun      <link linkend="sample">Sample Driver</link> section.
2995*4882a593Smuzhiyun	  </para>
2996*4882a593Smuzhiyun
2997*4882a593Smuzhiyun	</blockquote></para></blockquote>
2998*4882a593Smuzhiyun
2999*4882a593Smuzhiyun    <blockquote><para>
3000*4882a593Smuzhiyun	<programlisting>
3001*4882a593Smuzhiyun    void xf86ShowUnusedOptions(int scrnIndex, XF86OptionPtr options);
3002*4882a593Smuzhiyun	</programlisting>
3003*4882a593Smuzhiyun	<blockquote><para>
3004*4882a593Smuzhiyun      Prints out warning messages for each option in the list of options
3005*4882a593Smuzhiyun      that isn't marked as used.  This is intended to show options that
3006*4882a593Smuzhiyun      the driver hasn't recognised.  It would normally be called near
3007*4882a593Smuzhiyun      the end of the <function>ChipScreenInit()</function> function, but only
3008*4882a593Smuzhiyun      when <code>serverGeneration&nbsp;==&nbsp;1</code>
3009*4882a593Smuzhiyun	  </para>
3010*4882a593Smuzhiyun	</blockquote></para></blockquote>
3011*4882a593Smuzhiyun
3012*4882a593Smuzhiyun    <blockquote><para>
3013*4882a593Smuzhiyun	<programlisting>
3014*4882a593Smuzhiyun    OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table,
3015*4882a593Smuzhiyun                                     int token);
3016*4882a593Smuzhiyun	</programlisting>
3017*4882a593Smuzhiyun	<blockquote><para>
3018*4882a593Smuzhiyun      Returns a pointer to the <structname>OptionInfoRec</structname> in
3019*4882a593Smuzhiyun      <parameter>table</parameter> with a token field matching
3020*4882a593Smuzhiyun      <parameter>token</parameter>.  Returns <constant>NULL</constant> if no match
3021*4882a593Smuzhiyun      is found.
3022*4882a593Smuzhiyun	  </para>
3023*4882a593Smuzhiyun
3024*4882a593Smuzhiyun	</blockquote></para></blockquote>
3025*4882a593Smuzhiyun
3026*4882a593Smuzhiyun    <blockquote><para>
3027*4882a593Smuzhiyun	<programlisting>
3028*4882a593Smuzhiyun    Bool xf86IsOptionSet(const OptionInfoRec *table, int token);
3029*4882a593Smuzhiyun	</programlisting>
3030*4882a593Smuzhiyun	<blockquote><para>
3031*4882a593Smuzhiyun      Returns the <literal remap="tt">found</literal> field of the
3032*4882a593Smuzhiyun      <structname>OptionInfoRec</structname> in <parameter>table</parameter> with a
3033*4882a593Smuzhiyun      <structfield>token</structfield> field matching <parameter>token</parameter>.  This
3034*4882a593Smuzhiyun      can be used for options of all types.  Note that for options of
3035*4882a593Smuzhiyun      type <constant>OPTV_BOOLEAN</constant>, it isn't sufficient to check
3036*4882a593Smuzhiyun      this to determine the value of the option.  Returns
3037*4882a593Smuzhiyun      <constant>FALSE</constant> if no match is found.
3038*4882a593Smuzhiyun	  </para>
3039*4882a593Smuzhiyun
3040*4882a593Smuzhiyun	</blockquote></para></blockquote>
3041*4882a593Smuzhiyun
3042*4882a593Smuzhiyun    <blockquote><para>
3043*4882a593Smuzhiyun	<programlisting>
3044*4882a593Smuzhiyun    char *xf86GetOptValString(const OptionInfoRec *table, int token);
3045*4882a593Smuzhiyun	</programlisting>
3046*4882a593Smuzhiyun	<blockquote><para>
3047*4882a593Smuzhiyun      Returns the <structfield>value.str</structfield> field of the
3048*4882a593Smuzhiyun      <structname>OptionInfoRec</structname> in <parameter>table</parameter> with a
3049*4882a593Smuzhiyun      token field matching <parameter>token</parameter>.  Returns
3050*4882a593Smuzhiyun      <constant>NULL</constant> if no match is found.
3051*4882a593Smuzhiyun	  </para>
3052*4882a593Smuzhiyun
3053*4882a593Smuzhiyun	</blockquote></para></blockquote>
3054*4882a593Smuzhiyun
3055*4882a593Smuzhiyun	  <blockquote><para>
3056*4882a593Smuzhiyun	      <programlisting>
3057*4882a593Smuzhiyun    Bool xf86GetOptValInteger(const OptionInfoRec *table, int token,
3058*4882a593Smuzhiyun
3059*4882a593Smuzhiyun                                int *value);
3060*4882a593Smuzhiyun	      </programlisting>
3061*4882a593Smuzhiyun	      <blockquote><para>
3062*4882a593Smuzhiyun      Returns via <parameter>*value</parameter> the <structfield>value.num</structfield>
3063*4882a593Smuzhiyun      field of the <structname>OptionInfoRec</structname> in <parameter>table</parameter>
3064*4882a593Smuzhiyun      with a <structfield>token</structfield> field matching <parameter>token</parameter>.
3065*4882a593Smuzhiyun      <parameter>*value</parameter> is only changed when a match is found so
3066*4882a593Smuzhiyun      it can be safely initialised with a default prior to calling this
3067*4882a593Smuzhiyun      function.  The function return value is as for
3068*4882a593Smuzhiyun      <function>xf86IsOptionSet()</function>.
3069*4882a593Smuzhiyun	  </para>
3070*4882a593Smuzhiyun
3071*4882a593Smuzhiyun	</blockquote></para></blockquote>
3072*4882a593Smuzhiyun
3073*4882a593Smuzhiyun    <blockquote><para>
3074*4882a593Smuzhiyun	<programlisting>
3075*4882a593Smuzhiyun    Bool xf86GetOptValULong(const OptionInfoRec *table, int token,
3076*4882a593Smuzhiyun                            unsigned long *value);
3077*4882a593Smuzhiyun	</programlisting>
3078*4882a593Smuzhiyun	<blockquote><para>
3079*4882a593Smuzhiyun      Like <function>xf86GetOptValInteger()</function>, except the value is
3080*4882a593Smuzhiyun      treated as an <type>unsigned long</type>.
3081*4882a593Smuzhiyun	  </para>
3082*4882a593Smuzhiyun
3083*4882a593Smuzhiyun	</blockquote></para></blockquote>
3084*4882a593Smuzhiyun
3085*4882a593Smuzhiyun    <blockquote><para>
3086*4882a593Smuzhiyun	<programlisting>
3087*4882a593Smuzhiyun    Bool xf86GetOptValReal(const OptionInfoRec *table, int token,
3088*4882a593Smuzhiyun                           double *value);
3089*4882a593Smuzhiyun	</programlisting>
3090*4882a593Smuzhiyun	<blockquote><para>
3091*4882a593Smuzhiyun      Like <function>xf86GetOptValInteger()</function>, except that
3092*4882a593Smuzhiyun      <structfield>value.realnum</structfield> is used.
3093*4882a593Smuzhiyun	  </para>
3094*4882a593Smuzhiyun
3095*4882a593Smuzhiyun	</blockquote></para></blockquote>
3096*4882a593Smuzhiyun
3097*4882a593Smuzhiyun    <blockquote><para>
3098*4882a593Smuzhiyun	<programlisting>
3099*4882a593Smuzhiyun    Bool xf86GetOptValFreq(const OptionInfoRec *table, int token,
3100*4882a593Smuzhiyun                           OptFreqUnits expectedUnits, double *value);
3101*4882a593Smuzhiyun	</programlisting>
3102*4882a593Smuzhiyun	<blockquote><para>
3103*4882a593Smuzhiyun      Like <function>xf86GetOptValInteger()</function>, except that the
3104*4882a593Smuzhiyun      <structfield>value.freq</structfield> data is returned.  The frequency value
3105*4882a593Smuzhiyun      is scaled to the units indicated by <parameter>expectedUnits</parameter>.
3106*4882a593Smuzhiyun      The scaling is exact when the units were specified explicitly in
3107*4882a593Smuzhiyun      the option's value.  Otherwise, the <parameter>expectedUnits</parameter>
3108*4882a593Smuzhiyun      field is used as a hint when doing the scaling.  In this case,
3109*4882a593Smuzhiyun      values larger than <constant>1000</constant> are assumed to have be
3110*4882a593Smuzhiyun      specified in the next smallest units.  For example, if the Option
3111*4882a593Smuzhiyun      value is "10000" and expectedUnits is <constant>OPTUNITS_MHZ</constant>,
3112*4882a593Smuzhiyun      the value returned is <constant>10</constant>.
3113*4882a593Smuzhiyun	  </para>
3114*4882a593Smuzhiyun
3115*4882a593Smuzhiyun	</blockquote></para></blockquote>
3116*4882a593Smuzhiyun
3117*4882a593Smuzhiyun    <blockquote><para>
3118*4882a593Smuzhiyun      <programlisting>
3119*4882a593Smuzhiyun    Bool xf86GetOptValBool(const OptionInfoRec *table, int token, Bool *value);
3120*4882a593Smuzhiyun      </programlisting>
3121*4882a593Smuzhiyun	<blockquote><para>
3122*4882a593Smuzhiyun      This function is used to check boolean options
3123*4882a593Smuzhiyun      (<constant>OPTV_BOOLEAN</constant>).  If the function return value is
3124*4882a593Smuzhiyun      <constant>FALSE</constant>, it means the option wasn't set.  Otherwise
3125*4882a593Smuzhiyun      <parameter>*value</parameter> is set to the boolean value indicated by
3126*4882a593Smuzhiyun      the option's value.  No option <parameter>value</parameter> is interpreted
3127*4882a593Smuzhiyun      as <constant>TRUE</constant>.  Option values meaning <constant>TRUE</constant>
3128*4882a593Smuzhiyun      are "1", "yes", "on", "true", and option values meaning
3129*4882a593Smuzhiyun      <constant>FALSE</constant> are "0", "no", "off", "false".  Option names
3130*4882a593Smuzhiyun      both with the "no" prefix in their names, and with that prefix
3131*4882a593Smuzhiyun      removed are also checked and handled in the obvious way.
3132*4882a593Smuzhiyun      <parameter>*value</parameter> is not changed when the option isn't present.
3133*4882a593Smuzhiyun      It should normally be set to a default value before calling this
3134*4882a593Smuzhiyun      function.
3135*4882a593Smuzhiyun	  </para>
3136*4882a593Smuzhiyun
3137*4882a593Smuzhiyun	</blockquote></para></blockquote>
3138*4882a593Smuzhiyun
3139*4882a593Smuzhiyun    <blockquote><para>
3140*4882a593Smuzhiyun	<programlisting>
3141*4882a593Smuzhiyun    Bool xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def);
3142*4882a593Smuzhiyun	</programlisting>
3143*4882a593Smuzhiyun	<blockquote><para>
3144*4882a593Smuzhiyun      This function is used to check boolean options
3145*4882a593Smuzhiyun      (<constant>OPTV_BOOLEAN</constant>).  If the option is set, its value
3146*4882a593Smuzhiyun      is returned.  If the options is not set, the default value specified
3147*4882a593Smuzhiyun      by <parameter>def</parameter> is returned.  The option interpretation is
3148*4882a593Smuzhiyun      the same as for <function>xf86GetOptValBool()</function>.
3149*4882a593Smuzhiyun	  </para>
3150*4882a593Smuzhiyun
3151*4882a593Smuzhiyun	</blockquote></para></blockquote>
3152*4882a593Smuzhiyun
3153*4882a593Smuzhiyun    <blockquote><para>
3154*4882a593Smuzhiyun	<programlisting>
3155*4882a593Smuzhiyun    int xf86NameCmp(const char *s1, const char *s2);
3156*4882a593Smuzhiyun	</programlisting>
3157*4882a593Smuzhiyun	<blockquote><para>
3158*4882a593Smuzhiyun      This function should be used when comparing strings from the config
3159*4882a593Smuzhiyun      file with expected values.  It works like <function>strcmp()</function>,
3160*4882a593Smuzhiyun      but is not case sensitive and space, tab, and <quote><literal>_</literal></quote> characters
3161*4882a593Smuzhiyun      are ignored in the comparison.  The use of this function isn't
3162*4882a593Smuzhiyun      restricted to parsing option values.  It may be used anywhere
3163*4882a593Smuzhiyun      where this functionality required.
3164*4882a593Smuzhiyun	  </para>
3165*4882a593Smuzhiyun
3166*4882a593Smuzhiyun	</blockquote></para></blockquote>
3167*4882a593Smuzhiyun  </sect1>
3168*4882a593Smuzhiyun
3169*4882a593Smuzhiyun  <sect1>
3170*4882a593Smuzhiyun    <title>Modules, Drivers, Include Files and Interface Issues</title>
3171*4882a593Smuzhiyun
3172*4882a593Smuzhiyun    <para>
3173*4882a593SmuzhiyunNOTE: this section is incomplete.
3174*4882a593Smuzhiyun    </para>
3175*4882a593Smuzhiyun
3176*4882a593Smuzhiyun
3177*4882a593Smuzhiyun    <sect2>
3178*4882a593Smuzhiyun      <title>Include files</title>
3179*4882a593Smuzhiyun
3180*4882a593Smuzhiyun      <para>
3181*4882a593SmuzhiyunThe following include files are typically required by video drivers:
3182*4882a593Smuzhiyun
3183*4882a593Smuzhiyun	<blockquote><para>
3184*4882a593Smuzhiyun  All drivers should include these:
3185*4882a593Smuzhiyun	    <literallayout><filename>
3186*4882a593Smuzhiyun    "xf86.h"
3187*4882a593Smuzhiyun    "xf86_OSproc.h"
3188*4882a593Smuzhiyun    "xf86_ansic.h"
3189*4882a593Smuzhiyun    "xf86Resources.h"
3190*4882a593Smuzhiyun	    </filename></literallayout>
3191*4882a593Smuzhiyun  Wherever inb/outb (and related things) are used the following should be
3192*4882a593Smuzhiyun  included:
3193*4882a593Smuzhiyun	    <literallayout><filename>
3194*4882a593Smuzhiyun    "compiler.h"
3195*4882a593Smuzhiyun	      </filename></literallayout>
3196*4882a593Smuzhiyun  Note: in drivers, this must be included after <filename>"xf86_ansic.h"</filename>.
3197*4882a593Smuzhiyun	  </para>
3198*4882a593Smuzhiyun
3199*4882a593Smuzhiyun	  <para>
3200*4882a593Smuzhiyun  Drivers that need to access the PCI config space need this:
3201*4882a593Smuzhiyun	    <literallayout><filename>
3202*4882a593Smuzhiyun    "xf86Pci.h"
3203*4882a593Smuzhiyun	      </filename></literallayout>
3204*4882a593Smuzhiyun	  </para>
3205*4882a593Smuzhiyun
3206*4882a593Smuzhiyun	  <para>
3207*4882a593Smuzhiyun  Drivers that initialise a SW cursor need this:
3208*4882a593Smuzhiyun	    <literallayout><filename>
3209*4882a593Smuzhiyun    "mipointer.h"
3210*4882a593Smuzhiyun	      </filename></literallayout>
3211*4882a593Smuzhiyun	  </para>
3212*4882a593Smuzhiyun
3213*4882a593Smuzhiyun	  <para>
3214*4882a593Smuzhiyun  All drivers using the mi colourmap code need this:
3215*4882a593Smuzhiyun	    <literallayout><filename>
3216*4882a593Smuzhiyun    "micmap.h"
3217*4882a593Smuzhiyun	      </filename></literallayout>
3218*4882a593Smuzhiyun	  </para>
3219*4882a593Smuzhiyun
3220*4882a593Smuzhiyun	  <para>
3221*4882a593Smuzhiyun  If a driver uses the vgahw module, it needs this:
3222*4882a593Smuzhiyun	    <literallayout><filename>
3223*4882a593Smuzhiyun    "vgaHW.h"
3224*4882a593Smuzhiyun	      </filename></literallayout>
3225*4882a593Smuzhiyun	  </para>
3226*4882a593Smuzhiyun
3227*4882a593Smuzhiyun	  <para>
3228*4882a593Smuzhiyun  Drivers supporting VGA or Hercules monochrome screens need:
3229*4882a593Smuzhiyun	    <literallayout><filename>
3230*4882a593Smuzhiyun    "xf1bpp.h"
3231*4882a593Smuzhiyun	      </filename></literallayout>
3232*4882a593Smuzhiyun	  </para>
3233*4882a593Smuzhiyun
3234*4882a593Smuzhiyun	  <para>
3235*4882a593Smuzhiyun  Drivers supporting VGA or EGC 16-colour screens need:
3236*4882a593Smuzhiyun	    <literallayout><filename>
3237*4882a593Smuzhiyun    "xf4bpp.h"
3238*4882a593Smuzhiyun	      </filename></literallayout>
3239*4882a593Smuzhiyun	  </para>
3240*4882a593Smuzhiyun
3241*4882a593Smuzhiyun	  <para>
3242*4882a593Smuzhiyun  Drivers using cfb need:
3243*4882a593Smuzhiyun	    <programlisting>
3244*4882a593Smuzhiyun    #define PSZ 8
3245*4882a593Smuzhiyun    #include "cfb.h"
3246*4882a593Smuzhiyun    #undef PSZ
3247*4882a593Smuzhiyun	    </programlisting>
3248*4882a593Smuzhiyun	  </para>
3249*4882a593Smuzhiyun
3250*4882a593Smuzhiyun	  <para>
3251*4882a593Smuzhiyun  Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
3252*4882a593Smuzhiyun	    <literallayout><filename>
3253*4882a593Smuzhiyun    "cfb16.h"
3254*4882a593Smuzhiyun    "cfb24.h"
3255*4882a593Smuzhiyun    "cfb32.h"
3256*4882a593Smuzhiyun	      </filename></literallayout>
3257*4882a593Smuzhiyun	  </para>
3258*4882a593Smuzhiyun
3259*4882a593Smuzhiyun	  <para>
3260*4882a593Smuzhiyun  If a driver uses the fb manager, it needs this:
3261*4882a593Smuzhiyun	    <literallayout><filename>
3262*4882a593Smuzhiyun    "xf86fbman.h"
3263*4882a593Smuzhiyun	      </filename></literallayout>
3264*4882a593Smuzhiyun	  </para>
3265*4882a593Smuzhiyun	</blockquote>
3266*4882a593Smuzhiyun      </para>
3267*4882a593Smuzhiyun
3268*4882a593Smuzhiyun      <para>
3269*4882a593SmuzhiyunNon-driver modules should include <filename>"xf86_ansic.h"</filename> to get the correct
3270*4882a593Smuzhiyunwrapping of ANSI C/libc functions.
3271*4882a593Smuzhiyun      </para>
3272*4882a593Smuzhiyun
3273*4882a593Smuzhiyun      <para>
3274*4882a593SmuzhiyunAll modules must NOT include any system include files, or the following:
3275*4882a593Smuzhiyun
3276*4882a593Smuzhiyun	<literallayout><filename>
3277*4882a593Smuzhiyun    "xf86Priv.h"
3278*4882a593Smuzhiyun    "xf86Privstr.h"
3279*4882a593Smuzhiyun    "xf86_OSlib.h"
3280*4882a593Smuzhiyun    "Xos.h"
3281*4882a593Smuzhiyun	  </filename></literallayout>
3282*4882a593Smuzhiyun      </para>
3283*4882a593Smuzhiyun
3284*4882a593Smuzhiyun      <para>
3285*4882a593SmuzhiyunIn addition, "xf86_libc.h" must not be included explicitly.  It is
3286*4882a593Smuzhiyunincluded implicitly by "xf86_ansic.h".
3287*4882a593Smuzhiyun      </para>
3288*4882a593Smuzhiyun
3289*4882a593Smuzhiyun    </sect2>
3290*4882a593Smuzhiyun  </sect1>
3291*4882a593Smuzhiyun
3292*4882a593Smuzhiyun  <sect1>
3293*4882a593Smuzhiyun    <title>Offscreen Memory Manager</title>
3294*4882a593Smuzhiyun
3295*4882a593Smuzhiyun    <para>
3296*4882a593SmuzhiyunManagement of offscreen video memory may be handled by the XFree86
3297*4882a593Smuzhiyunframebuffer manager.  Once the offscreen memory manager is running,
3298*4882a593Smuzhiyundrivers or extensions may allocate, free or resize areas of offscreen
3299*4882a593Smuzhiyunvideo memory using the following functions (definitions taken from
3300*4882a593Smuzhiyun<filename>xf86fbman.h</filename>):
3301*4882a593Smuzhiyun
3302*4882a593Smuzhiyun      <programlisting>
3303*4882a593Smuzhiyun    typedef struct _FBArea {
3304*4882a593Smuzhiyun        ScreenPtr    pScreen;
3305*4882a593Smuzhiyun        BoxRec       box;
3306*4882a593Smuzhiyun        int          granularity;
3307*4882a593Smuzhiyun        void         (*MoveAreaCallback)(struct _FBArea*, struct _FBArea*)
3308*4882a593Smuzhiyun        void         (*RemoveAreaCallback)(struct _FBArea*)
3309*4882a593Smuzhiyun        DevUnion     devPrivate;
3310*4882a593Smuzhiyun    } FBArea, *FBAreaPtr;
3311*4882a593Smuzhiyun
3312*4882a593Smuzhiyun    typedef void (*MoveAreaCallbackProcPtr)(FBAreaPtr from, FBAreaPtr to)
3313*4882a593Smuzhiyun    typedef void (*RemoveAreaCallbackProcPtr)(FBAreaPtr)
3314*4882a593Smuzhiyun
3315*4882a593Smuzhiyun    FBAreaPtr xf86AllocateOffscreenArea (
3316*4882a593Smuzhiyun        ScreenPtr pScreen,
3317*4882a593Smuzhiyun        int width, int height,
3318*4882a593Smuzhiyun        int granularity,
3319*4882a593Smuzhiyun        MoveAreaCallbackProcPtr MoveAreaCallback,
3320*4882a593Smuzhiyun        RemoveAreaCallbackProcPtr RemoveAreaCallback,
3321*4882a593Smuzhiyun        pointer privData
3322*4882a593Smuzhiyun    )
3323*4882a593Smuzhiyun
3324*4882a593Smuzhiyun    void xf86FreeOffscreenArea (FBAreaPtr area)
3325*4882a593Smuzhiyun
3326*4882a593Smuzhiyun    Bool xf86ResizeOffscreenArea (
3327*4882a593Smuzhiyun	FBAreaPtr area
3328*4882a593Smuzhiyun	int w, int h
3329*4882a593Smuzhiyun    )
3330*4882a593Smuzhiyun      </programlisting>
3331*4882a593Smuzhiyun    </para>
3332*4882a593Smuzhiyun
3333*4882a593Smuzhiyun    <para>
3334*4882a593SmuzhiyunThe function:
3335*4882a593Smuzhiyun      <programlisting>
3336*4882a593Smuzhiyun    Bool xf86FBManagerRunning(ScreenPtr pScreen);
3337*4882a593Smuzhiyun      </programlisting>
3338*4882a593Smuzhiyun
3339*4882a593Smuzhiyuncan be used by an extension to check if the driver has initialized
3340*4882a593Smuzhiyunthe memory manager.  The manager is not available if this returns
3341*4882a593Smuzhiyun<constant>FALSE</constant> and the functions above will all fail.
3342*4882a593Smuzhiyun    </para>
3343*4882a593Smuzhiyun
3344*4882a593Smuzhiyun
3345*4882a593Smuzhiyun    <para>
3346*4882a593Smuzhiyun<function>xf86AllocateOffscreenArea()</function> can be used to request a
3347*4882a593Smuzhiyunrectangle of dimensions <parameter>width</parameter>&nbsp;&times;&nbsp;<parameter>height</parameter>
3348*4882a593Smuzhiyun(in pixels) from unused offscreen memory.  <parameter>granularity</parameter>
3349*4882a593Smuzhiyunspecifies that the leftmost edge of the rectangle must lie on some
3350*4882a593Smuzhiyunmultiple of <parameter>granularity</parameter> pixels.  A granularity of zero
3351*4882a593Smuzhiyunmeans the same thing as a granularity of one - no alignment preference.
3352*4882a593SmuzhiyunA <parameter>MoveAreaCallback</parameter> can be provided to notify the requester
3353*4882a593Smuzhiyunwhen the offscreen area is moved.  If no <parameter>MoveAreaCallback</parameter>
3354*4882a593Smuzhiyunis supplied then the area is considered to be immovable.  The
3355*4882a593Smuzhiyun<parameter>privData</parameter> field will be stored in the manager's internal
3356*4882a593Smuzhiyunstructure for that allocated area and will be returned to the requester
3357*4882a593Smuzhiyunin the <parameter>FBArea</parameter> passed via the
3358*4882a593Smuzhiyun<parameter>MoveAreaCallback</parameter>.  An optional
3359*4882a593Smuzhiyun<parameter>RemoveAreaCallback</parameter> is provided.  If the driver provides
3360*4882a593Smuzhiyunthis it indicates that the area should be allocated with a lower priority.
3361*4882a593SmuzhiyunSuch an area may be removed when a higher priority request (one that
3362*4882a593Smuzhiyundoesn't have a <parameter>RemoveAreaCallback</parameter>) is made.  When this
3363*4882a593Smuzhiyunfunction is called, the driver will have an opportunity to do whatever
3364*4882a593Smuzhiyuncleanup it needs to do to deal with the loss of the area, but it must
3365*4882a593Smuzhiyunfinish its cleanup before the function exits since the offscreen memory
3366*4882a593Smuzhiyunmanager will free the area immediately after.
3367*4882a593Smuzhiyun    </para>
3368*4882a593Smuzhiyun
3369*4882a593Smuzhiyun    <para>
3370*4882a593Smuzhiyun<function>xf86AllocateOffscreenArea()</function> returns <constant>NULL</constant>
3371*4882a593Smuzhiyunif it was unable to allocate the requested area.  When no longer needed,
3372*4882a593Smuzhiyunareas should be freed with <function>xf86FreeOffscreenArea()</function>.
3373*4882a593Smuzhiyun    </para>
3374*4882a593Smuzhiyun
3375*4882a593Smuzhiyun    <para>
3376*4882a593Smuzhiyun<function>xf86ResizeOffscreenArea()</function> resizes an existing
3377*4882a593Smuzhiyun<literal remap="tt">FBArea</literal>.  <function>xf86ResizeOffscreenArea()</function>
3378*4882a593Smuzhiyunreturns <constant>TRUE</constant> if the resize was successful.  If
3379*4882a593Smuzhiyun<function>xf86ResizeOffscreenArea()</function> returns <constant>FALSE</constant>,
3380*4882a593Smuzhiyunthe original <literal remap="tt">FBArea</literal> is left unmodified.  Resizing an
3381*4882a593Smuzhiyunarea maintains the area's original <literal remap="tt">granularity</literal>,
3382*4882a593Smuzhiyun<literal remap="tt">devPrivate</literal>, and <literal remap="tt">MoveAreaCallback</literal>.
3383*4882a593Smuzhiyun<function>xf86ResizeOffscreenArea()</function> has considerably less overhead
3384*4882a593Smuzhiyunthan freeing the old area then reallocating the new size, so it should
3385*4882a593Smuzhiyunbe used whenever possible.
3386*4882a593Smuzhiyun    </para>
3387*4882a593Smuzhiyun
3388*4882a593Smuzhiyun    <para>
3389*4882a593SmuzhiyunThe function:
3390*4882a593Smuzhiyun      <programlisting>
3391*4882a593Smuzhiyun    Bool xf86QueryLargestOffscreenArea(
3392*4882a593Smuzhiyun      ScreenPtr pScreen,
3393*4882a593Smuzhiyun      int *width, int *height,
3394*4882a593Smuzhiyun      int granularity,
3395*4882a593Smuzhiyun      int preferences,
3396*4882a593Smuzhiyun      int priority
3397*4882a593Smuzhiyun    );
3398*4882a593Smuzhiyun	</programlisting>
3399*4882a593Smuzhiyun
3400*4882a593Smuzhiyunis provided to query the width and height of the largest single
3401*4882a593Smuzhiyun<structname>FBArea</structname> allocatable given a particular priority.
3402*4882a593Smuzhiyun<parameter>preferences</parameter> can be one of the following to indicate
3403*4882a593Smuzhiyunwhether width, height or area should be considered when determining
3404*4882a593Smuzhiyunwhich is the largest single <structname>FBArea</structname> available.
3405*4882a593Smuzhiyun
3406*4882a593Smuzhiyun      <programlisting>
3407*4882a593Smuzhiyun  FAVOR_AREA_THEN_WIDTH
3408*4882a593Smuzhiyun  FAVOR_AREA_THEN_HEIGHT
3409*4882a593Smuzhiyun  FAVOR_WIDTH_THEN_AREA
3410*4882a593Smuzhiyun  FAVOR_HEIGHT_THEN_AREA
3411*4882a593Smuzhiyun      </programlisting>
3412*4882a593Smuzhiyun    </para>
3413*4882a593Smuzhiyun
3414*4882a593Smuzhiyun    <para>
3415*4882a593Smuzhiyun<parameter>priority</parameter> is one of the following:
3416*4882a593Smuzhiyun
3417*4882a593Smuzhiyun      <blockquote>
3418*4882a593Smuzhiyun	<para>
3419*4882a593Smuzhiyun  <constant>PRIORITY_LOW</constant>
3420*4882a593Smuzhiyun	  <blockquote><para>
3421*4882a593Smuzhiyun     Return the largest block available without stealing anyone else's
3422*4882a593Smuzhiyun     space.  This corresponds to the priority of allocating a
3423*4882a593Smuzhiyun     <structname>FBArea</structname> when a <function>RemoveAreaCallback</function>
3424*4882a593Smuzhiyun     is provided.
3425*4882a593Smuzhiyun	    </para></blockquote>
3426*4882a593Smuzhiyun	</para>
3427*4882a593Smuzhiyun
3428*4882a593Smuzhiyun	<para>
3429*4882a593Smuzhiyun   <constant>PRIORITY_NORMAL</constant>
3430*4882a593Smuzhiyun	  <blockquote><para>
3431*4882a593Smuzhiyun     Return the largest block available if it is acceptable to steal a
3432*4882a593Smuzhiyun     lower priority area from someone.  This corresponds to the priority
3433*4882a593Smuzhiyun     of allocating a <structname>FBArea</structname> without providing a
3434*4882a593Smuzhiyun     <function>RemoveAreaCallback</function>.
3435*4882a593Smuzhiyun	    </para></blockquote>
3436*4882a593Smuzhiyun	</para>
3437*4882a593Smuzhiyun
3438*4882a593Smuzhiyun	<para>
3439*4882a593Smuzhiyun    <constant>PRIORITY_EXTREME</constant>
3440*4882a593Smuzhiyun	  <blockquote><para>
3441*4882a593Smuzhiyun     Return the largest block available if all <structname>FBArea</structname>s
3442*4882a593Smuzhiyun     that aren't locked down were expunged from memory first.  This
3443*4882a593Smuzhiyun     corresponds to any allocation made directly after a call to
3444*4882a593Smuzhiyun     <function>xf86PurgeUnlockedOffscreenAreas()</function>.
3445*4882a593Smuzhiyun	    </para></blockquote>
3446*4882a593Smuzhiyun	</para>
3447*4882a593Smuzhiyun
3448*4882a593Smuzhiyun      </blockquote>
3449*4882a593Smuzhiyun    </para>
3450*4882a593Smuzhiyun
3451*4882a593Smuzhiyun
3452*4882a593Smuzhiyun    <para>
3453*4882a593SmuzhiyunThe function:
3454*4882a593Smuzhiyun
3455*4882a593Smuzhiyun      <programlisting>
3456*4882a593Smuzhiyun    Bool xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen);
3457*4882a593Smuzhiyun      </programlisting>
3458*4882a593Smuzhiyun
3459*4882a593Smuzhiyunis provided as an extreme method to free up offscreen memory.  This
3460*4882a593Smuzhiyunwill remove all removable <structname>FBArea</structname> allocations.
3461*4882a593Smuzhiyun    </para>
3462*4882a593Smuzhiyun
3463*4882a593Smuzhiyun
3464*4882a593Smuzhiyun    <para>
3465*4882a593SmuzhiyunInitialization of the XFree86 framebuffer manager is done via
3466*4882a593Smuzhiyun
3467*4882a593Smuzhiyun      <programlisting>
3468*4882a593Smuzhiyun    Bool xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox);
3469*4882a593Smuzhiyun      </programlisting>
3470*4882a593Smuzhiyun
3471*4882a593Smuzhiyun<parameter>FullBox</parameter> represents the area of the framebuffer that the
3472*4882a593Smuzhiyunmanager is allowed to manage.  This is typically a box with a width of
3473*4882a593Smuzhiyun<structfield>pScrn-&gt;displayWidth</structfield> and a height of as many lines as
3474*4882a593Smuzhiyuncan be fit within the total video memory, however, the driver can reserve
3475*4882a593Smuzhiyunareas at the extremities by passing a smaller area to the manager.
3476*4882a593Smuzhiyun    </para>
3477*4882a593Smuzhiyun  </sect1>
3478*4882a593Smuzhiyun
3479*4882a593Smuzhiyun  <sect1 id="cmap">
3480*4882a593Smuzhiyun    <title>Colormap Handling</title>
3481*4882a593Smuzhiyun
3482*4882a593Smuzhiyun    <para>
3483*4882a593SmuzhiyunA generic colormap handling layer is provided within the XFree86 common
3484*4882a593Smuzhiyunlayer.  This layer takes care of most of the details, and only requires
3485*4882a593Smuzhiyuna function from the driver that loads the hardware palette when required.
3486*4882a593SmuzhiyunTo use the colormap layer, a driver calls the
3487*4882a593Smuzhiyun<function>xf86HandleColormaps()</function> function.
3488*4882a593Smuzhiyun
3489*4882a593Smuzhiyun      <blockquote><para>
3490*4882a593Smuzhiyun	  <programlisting>
3491*4882a593Smuzhiyun    Bool xf86HandleColormaps(ScreenPtr pScreen, int maxColors,
3492*4882a593Smuzhiyun                             int sigRGBbits, LoadPaletteFuncPtr loadPalette,
3493*4882a593Smuzhiyun                             SetOverscanFuncPtr setOverscan,
3494*4882a593Smuzhiyun                             unsigned int flags);
3495*4882a593Smuzhiyun	  </programlisting>
3496*4882a593Smuzhiyun	  <blockquote><para>
3497*4882a593Smuzhiyun      This function must be called after the default colormap has been
3498*4882a593Smuzhiyun      initialised.  The <structfield>pScrn-&gt;gamma</structfield> field must also
3499*4882a593Smuzhiyun      be initialised, preferably by calling <function>xf86SetGamma()</function>.
3500*4882a593Smuzhiyun      <parameter>maxColors</parameter> is the number of entries in the palette.
3501*4882a593Smuzhiyun      <parameter>sigRGBbits</parameter> is the size in bits of each color
3502*4882a593Smuzhiyun      component in the DAC's palette.  <parameter>loadPalette</parameter>
3503*4882a593Smuzhiyun      is a driver-provided function for loading a colormap into the
3504*4882a593Smuzhiyun      hardware, and is described below.  <parameter>setOverscan</parameter> is
3505*4882a593Smuzhiyun      an optional function that may be provided when the overscan color
3506*4882a593Smuzhiyun      is an index from the standard LUT and when it needs to be adjusted
3507*4882a593Smuzhiyun      to keep it as close to black as possible.  The
3508*4882a593Smuzhiyun      <parameter>setOverscan</parameter> function programs the overscan index.
3509*4882a593Smuzhiyun      It shouldn't normally be used for depths other than 8.
3510*4882a593Smuzhiyun      <parameter>setOverscan</parameter> should be set to <constant>NULL</constant>
3511*4882a593Smuzhiyun      when it isn't needed.  <parameter>flags</parameter> may be set to the
3512*4882a593Smuzhiyun      following (which may be ORed together):
3513*4882a593Smuzhiyun
3514*4882a593Smuzhiyun	      <variablelist>
3515*4882a593Smuzhiyun		<varlistentry>
3516*4882a593Smuzhiyun		  <term><constant>CMAP_PALETTED_TRUECOLOR</constant></term>
3517*4882a593Smuzhiyun		  <listitem><para>
3518*4882a593Smuzhiyun				    the TrueColor visual is paletted and is
3519*4882a593Smuzhiyun				    just a special case of DirectColor.
3520*4882a593Smuzhiyun				    This flag is only valid for
3521*4882a593Smuzhiyun				    <code>bpp&nbsp;&gt;&nbsp;8</code>.
3522*4882a593Smuzhiyun
3523*4882a593Smuzhiyun		    </para></listitem></varlistentry>
3524*4882a593Smuzhiyun		<varlistentry>
3525*4882a593Smuzhiyun		  <term><constant>CMAP_RELOAD_ON_MODE_SWITCH</constant></term>
3526*4882a593Smuzhiyun		  <listitem><para>
3527*4882a593Smuzhiyun				    reload the colormap automatically
3528*4882a593Smuzhiyun                                    after mode switches.  This is useful
3529*4882a593Smuzhiyun                                    for when the driver is resetting the
3530*4882a593Smuzhiyun                                    hardware during mode switches and
3531*4882a593Smuzhiyun                                    corrupting or erasing the hardware
3532*4882a593Smuzhiyun                                    palette.
3533*4882a593Smuzhiyun
3534*4882a593Smuzhiyun		    </para></listitem></varlistentry>
3535*4882a593Smuzhiyun		<varlistentry>
3536*4882a593Smuzhiyun		  <term><constant>CMAP_LOAD_EVEN_IF_OFFSCREEN</constant></term>
3537*4882a593Smuzhiyun		  <listitem><para>
3538*4882a593Smuzhiyun				    reload the colormap even if the screen
3539*4882a593Smuzhiyun				    is switched out of the server's VC.
3540*4882a593Smuzhiyun				    The palette is <emphasis>not</emphasis> reloaded when
3541*4882a593Smuzhiyun				    the screen is switched back in, nor after
3542*4882a593Smuzhiyun				    mode switches.  This is useful when the
3543*4882a593Smuzhiyun				    driver needs to keep track of palette
3544*4882a593Smuzhiyun				    changes.
3545*4882a593Smuzhiyun
3546*4882a593Smuzhiyun		    </para></listitem></varlistentry>
3547*4882a593Smuzhiyun	      </variablelist>
3548*4882a593Smuzhiyun	    </para>
3549*4882a593Smuzhiyun
3550*4882a593Smuzhiyun	    <para>
3551*4882a593Smuzhiyun      The colormap layer normally reloads the palette after VT enters so it
3552*4882a593Smuzhiyun      is not necessary for the driver to save and restore the palette
3553*4882a593Smuzhiyun      when switching VTs.  The driver must, however, still save the
3554*4882a593Smuzhiyun      initial palette during server start up and restore it during
3555*4882a593Smuzhiyun      server exit.
3556*4882a593Smuzhiyun	    </para>
3557*4882a593Smuzhiyun
3558*4882a593Smuzhiyun	  </blockquote></para></blockquote>
3559*4882a593Smuzhiyun
3560*4882a593Smuzhiyun      <blockquote><para>
3561*4882a593Smuzhiyun	  <programlisting>
3562*4882a593Smuzhiyun    void LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
3563*4882a593Smuzhiyun                     LOCO *colors, VisualPtr pVisual);
3564*4882a593Smuzhiyun	  </programlisting>
3565*4882a593Smuzhiyun	  <blockquote><para>
3566*4882a593Smuzhiyun      <function>LoadPalette()</function> is a driver-provided function for
3567*4882a593Smuzhiyun      loading a colormap into hardware.  <parameter>colors</parameter> is the
3568*4882a593Smuzhiyun      array of RGB values that represent the full colormap.
3569*4882a593Smuzhiyun      <parameter>indices</parameter> is a list of index values into the colors
3570*4882a593Smuzhiyun      array.  These indices indicate the entries that need to be updated.
3571*4882a593Smuzhiyun      <parameter>numColors</parameter> is the number of the indices to be
3572*4882a593Smuzhiyun      updated.
3573*4882a593Smuzhiyun	    </para>
3574*4882a593Smuzhiyun
3575*4882a593Smuzhiyun	  </blockquote></para></blockquote>
3576*4882a593Smuzhiyun
3577*4882a593Smuzhiyun      <blockquote><para>
3578*4882a593Smuzhiyun	  <programlisting>
3579*4882a593Smuzhiyun    void SetOverscan(ScrnInfoPtr pScrn, int overscan);
3580*4882a593Smuzhiyun	  </programlisting>
3581*4882a593Smuzhiyun	  <blockquote><para>
3582*4882a593Smuzhiyun      <function>SetOverscan()</function> is a driver-provided function for
3583*4882a593Smuzhiyun      programming the <parameter>overscan</parameter> index.  As described
3584*4882a593Smuzhiyun      above, it is normally only appropriate for LUT modes where all
3585*4882a593Smuzhiyun      colormap entries are available for the display, but where one of
3586*4882a593Smuzhiyun      them is also used for the overscan (typically 8bpp for VGA compatible
3587*4882a593Smuzhiyun      LUTs).  It isn't required in cases where the overscan area is
3588*4882a593Smuzhiyun      never visible.
3589*4882a593Smuzhiyun	    </para>
3590*4882a593Smuzhiyun
3591*4882a593Smuzhiyun	  </blockquote></para>
3592*4882a593Smuzhiyun      </blockquote></para>
3593*4882a593Smuzhiyun
3594*4882a593Smuzhiyun  </sect1>
3595*4882a593Smuzhiyun
3596*4882a593Smuzhiyun  <sect1>
3597*4882a593Smuzhiyun    <title>DPMS Extension</title>
3598*4882a593Smuzhiyun
3599*4882a593Smuzhiyun    <para>
3600*4882a593SmuzhiyunSupport code for the DPMS extension is included in the XFree86 common layer.
3601*4882a593SmuzhiyunThis code provides an interface between the main extension code, and a means
3602*4882a593Smuzhiyunfor drivers to initialise DPMS when they support it.  One function is
3603*4882a593Smuzhiyunavailable to drivers to do this initialisation, and it is always available,
3604*4882a593Smuzhiyuneven when the DPMS extension is not supported by the core server (in
3605*4882a593Smuzhiyunwhich case it returns a failure result).
3606*4882a593Smuzhiyun    </para>
3607*4882a593Smuzhiyun
3608*4882a593Smuzhiyun    <blockquote><para>
3609*4882a593Smuzhiyun	<programlisting>
3610*4882a593Smuzhiyun    Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags);
3611*4882a593Smuzhiyun	</programlisting>
3612*4882a593Smuzhiyun	<blockquote><para>
3613*4882a593Smuzhiyun      This function registers a driver's DPMS level programming function
3614*4882a593Smuzhiyun      <parameter>set</parameter>.  It also checks
3615*4882a593Smuzhiyun      <structfield>pScrn-&gt;options</structfield> for the "dpms" option, and when
3616*4882a593Smuzhiyun      present marks DPMS as being enabled for that screen.  The
3617*4882a593Smuzhiyun      <parameter>set</parameter> function is called whenever the DPMS level
3618*4882a593Smuzhiyun      changes, and is used to program the requested level.
3619*4882a593Smuzhiyun      <parameter>flags</parameter> is currently not used, and should be
3620*4882a593Smuzhiyun      <constant>0</constant>.  If the initialisation fails for any reason,
3621*4882a593Smuzhiyun      including when there is no DPMS support in the core server, the
3622*4882a593Smuzhiyun      function returns <constant>FALSE</constant>.
3623*4882a593Smuzhiyun	  </para>
3624*4882a593Smuzhiyun
3625*4882a593Smuzhiyun	</blockquote></para></blockquote>
3626*4882a593Smuzhiyun
3627*4882a593Smuzhiyun
3628*4882a593Smuzhiyun    <para>
3629*4882a593SmuzhiyunDrivers that implement DPMS support must provide the following function,
3630*4882a593Smuzhiyunthat gets called when the DPMS level is changed:
3631*4882a593Smuzhiyun
3632*4882a593Smuzhiyun
3633*4882a593Smuzhiyun      <blockquote><para>
3634*4882a593Smuzhiyun	  <programlisting>
3635*4882a593Smuzhiyun    void ChipDPMSSet(ScrnInfoPtr pScrn, int level, int flags);
3636*4882a593Smuzhiyun	  </programlisting>
3637*4882a593Smuzhiyun	  <blockquote><para>
3638*4882a593Smuzhiyun      Program the DPMS level specified by <parameter>level</parameter>.  Valid
3639*4882a593Smuzhiyun      values of <parameter>level</parameter> are <constant>DPMSModeOn</constant>,
3640*4882a593Smuzhiyun      <constant>DPMSModeStandby</constant>, <constant>DPMSModeSuspend</constant>,
3641*4882a593Smuzhiyun      <constant>DPMSModeOff</constant>.  These values are defined in
3642*4882a593Smuzhiyun      <filename>"extensions/dpms.h"</filename>.
3643*4882a593Smuzhiyun	    </para>
3644*4882a593Smuzhiyun
3645*4882a593Smuzhiyun	  </blockquote></para></blockquote>
3646*4882a593Smuzhiyun    </para>
3647*4882a593Smuzhiyun
3648*4882a593Smuzhiyun  </sect1>
3649*4882a593Smuzhiyun
3650*4882a593Smuzhiyun  <sect1>
3651*4882a593Smuzhiyun    <title>DGA Extension</title>
3652*4882a593Smuzhiyun
3653*4882a593Smuzhiyun    <para>
3654*4882a593SmuzhiyunDrivers can support the XFree86 Direct Graphics Architecture (DGA) by
3655*4882a593Smuzhiyunfilling out a structure of function pointers and a list of modes and
3656*4882a593Smuzhiyunpassing them to DGAInit.
3657*4882a593Smuzhiyun    </para>
3658*4882a593Smuzhiyun
3659*4882a593Smuzhiyun    <blockquote><para>
3660*4882a593Smuzhiyun	<programlisting>
3661*4882a593Smuzhiyun    Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs,
3662*4882a593Smuzhiyun                 DGAModePtr modes, int num);
3663*4882a593Smuzhiyun
3664*4882a593Smuzhiyun/** The DGAModeRec **/
3665*4882a593Smuzhiyun
3666*4882a593Smuzhiyuntypedef struct {
3667*4882a593Smuzhiyun  int num;
3668*4882a593Smuzhiyun  DisplayModePtr mode;
3669*4882a593Smuzhiyun  int flags;
3670*4882a593Smuzhiyun  int imageWidth;
3671*4882a593Smuzhiyun  int imageHeight;
3672*4882a593Smuzhiyun  int pixmapWidth;
3673*4882a593Smuzhiyun  int pixmapHeight;
3674*4882a593Smuzhiyun  int bytesPerScanline;
3675*4882a593Smuzhiyun  int byteOrder;
3676*4882a593Smuzhiyun  int depth;
3677*4882a593Smuzhiyun  int bitsPerPixel;
3678*4882a593Smuzhiyun  unsigned long red_mask;
3679*4882a593Smuzhiyun  unsigned long green_mask;
3680*4882a593Smuzhiyun  unsigned long blue_mask;
3681*4882a593Smuzhiyun  int viewportWidth;
3682*4882a593Smuzhiyun  int viewportHeight;
3683*4882a593Smuzhiyun  int xViewportStep;
3684*4882a593Smuzhiyun  int yViewportStep;
3685*4882a593Smuzhiyun  int maxViewportX;
3686*4882a593Smuzhiyun  int maxViewportY;
3687*4882a593Smuzhiyun  int viewportFlags;
3688*4882a593Smuzhiyun  int offset;
3689*4882a593Smuzhiyun  unsigned char *address;
3690*4882a593Smuzhiyun  int reserved1;
3691*4882a593Smuzhiyun  int reserved2;
3692*4882a593Smuzhiyun} DGAModeRec, *DGAModePtr;
3693*4882a593Smuzhiyun	</programlisting>
3694*4882a593Smuzhiyun
3695*4882a593Smuzhiyun	<variablelist>
3696*4882a593Smuzhiyun	  <varlistentry>
3697*4882a593Smuzhiyun	    <term><structfield>num</structfield></term>
3698*4882a593Smuzhiyun	    <listitem><para>
3699*4882a593Smuzhiyun	 Can be ignored.  The DGA DDX will assign these numbers.
3700*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3701*4882a593Smuzhiyun
3702*4882a593Smuzhiyun	  <varlistentry>
3703*4882a593Smuzhiyun	    <term><structfield>mode</structfield></term>
3704*4882a593Smuzhiyun	    <listitem><para>
3705*4882a593Smuzhiyun	A pointer to the <structname>DisplayModeRec</structname> for this mode.
3706*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3707*4882a593Smuzhiyun
3708*4882a593Smuzhiyun	  <varlistentry>
3709*4882a593Smuzhiyun	    <term><structfield>flags</structfield></term>
3710*4882a593Smuzhiyun	      <listitem><para>
3711*4882a593Smuzhiyun	The following flags are defined and may be OR'd together:
3712*4882a593Smuzhiyun
3713*4882a593Smuzhiyun		  <variablelist>
3714*4882a593Smuzhiyun		    <varlistentry>
3715*4882a593Smuzhiyun		      <term><constant>DGA_CONCURRENT_ACCESS</constant></term>
3716*4882a593Smuzhiyun		      <listitem><para>
3717*4882a593Smuzhiyun            Indicates that the driver supports concurrent graphics
3718*4882a593Smuzhiyun            accelerator and linear framebuffer access.
3719*4882a593Smuzhiyun
3720*4882a593Smuzhiyun			</para></listitem></varlistentry>
3721*4882a593Smuzhiyun
3722*4882a593Smuzhiyun		    <varlistentry>
3723*4882a593Smuzhiyun		      <term><constant>DGA_FILL_RECT
3724*4882a593Smuzhiyun			  DGA_BLIT_RECT
3725*4882a593Smuzhiyun			  DGA_BLIT_RECT_TRANS</constant></term>
3726*4882a593Smuzhiyun		      <listitem><para>
3727*4882a593Smuzhiyun	    Indicates that the driver supports the FillRect, BlitRect
3728*4882a593Smuzhiyun            or BlitTransRect functions in this mode.
3729*4882a593Smuzhiyun
3730*4882a593Smuzhiyun			</para></listitem></varlistentry>
3731*4882a593Smuzhiyun
3732*4882a593Smuzhiyun		    <varlistentry>
3733*4882a593Smuzhiyun		      <term><constant>DGA_PIXMAP_AVAILABLE</constant></term>
3734*4882a593Smuzhiyun		      <listitem><para>
3735*4882a593Smuzhiyun	    Indicates that Xlib may be used on the framebuffer.
3736*4882a593Smuzhiyun            This flag will usually be set unless the driver wishes
3737*4882a593Smuzhiyun            to prohibit this for some reason.
3738*4882a593Smuzhiyun
3739*4882a593Smuzhiyun			</para></listitem></varlistentry>
3740*4882a593Smuzhiyun
3741*4882a593Smuzhiyun		    <varlistentry>
3742*4882a593Smuzhiyun		      <term><constant>DGA_INTERLACED
3743*4882a593Smuzhiyun			  DGA_DOUBLESCAN</constant></term>
3744*4882a593Smuzhiyun		      <listitem><para>
3745*4882a593Smuzhiyun            Indicates that these are interlaced or double scan modes.
3746*4882a593Smuzhiyun
3747*4882a593Smuzhiyun			</para></listitem></varlistentry>
3748*4882a593Smuzhiyun		  </variablelist>
3749*4882a593Smuzhiyun		</para></listitem></varlistentry>
3750*4882a593Smuzhiyun
3751*4882a593Smuzhiyun	  <varlistentry>
3752*4882a593Smuzhiyun	    <term><structfield>imageWidth
3753*4882a593Smuzhiyun		imageHeight</structfield></term>
3754*4882a593Smuzhiyun	    <listitem><para>
3755*4882a593Smuzhiyun		    These are the dimensions of the linear framebuffer
3756*4882a593Smuzhiyun                     accessible by the client.
3757*4882a593Smuzhiyun
3758*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3759*4882a593Smuzhiyun
3760*4882a593Smuzhiyun	  <varlistentry>
3761*4882a593Smuzhiyun	    <term><structfield>pixmapWidth
3762*4882a593Smuzhiyun		pixmapHeight</structfield></term>
3763*4882a593Smuzhiyun	    <listitem><para>
3764*4882a593Smuzhiyun		     These are the dimensions of the area of the
3765*4882a593Smuzhiyun                     framebuffer accessible by the graphics accelerator.
3766*4882a593Smuzhiyun
3767*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3768*4882a593Smuzhiyun
3769*4882a593Smuzhiyun	  <varlistentry>
3770*4882a593Smuzhiyun	    <term><structfield>bytesPerScanline</structfield></term>
3771*4882a593Smuzhiyun	    <listitem><para>
3772*4882a593Smuzhiyun		      Pitch of the framebuffer in bytes.
3773*4882a593Smuzhiyun
3774*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3775*4882a593Smuzhiyun
3776*4882a593Smuzhiyun	  <varlistentry>
3777*4882a593Smuzhiyun	    <term><structfield>byteOrder</structfield></term>
3778*4882a593Smuzhiyun	    <listitem><para>
3779*4882a593Smuzhiyun		     Usually the same as
3780*4882a593Smuzhiyun		     <structfield>pScrn-&gt;imageByteOrder</structfield>.
3781*4882a593Smuzhiyun
3782*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3783*4882a593Smuzhiyun
3784*4882a593Smuzhiyun	  <varlistentry>
3785*4882a593Smuzhiyun	    <term><structfield>depth</structfield></term>
3786*4882a593Smuzhiyun	    <listitem><para>
3787*4882a593Smuzhiyun		     The depth of the framebuffer in this mode.
3788*4882a593Smuzhiyun
3789*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3790*4882a593Smuzhiyun
3791*4882a593Smuzhiyun	  <varlistentry>
3792*4882a593Smuzhiyun	    <term><structfield>bitsPerPixel</structfield></term>
3793*4882a593Smuzhiyun	    <listitem><para>
3794*4882a593Smuzhiyun		      The number of bits per pixel in this mode.
3795*4882a593Smuzhiyun
3796*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3797*4882a593Smuzhiyun
3798*4882a593Smuzhiyun	  <varlistentry>
3799*4882a593Smuzhiyun	    <term><structfield>red_mask</structfield></term>
3800*4882a593Smuzhiyun	    <term><structfield>green_mask</structfield></term>
3801*4882a593Smuzhiyun	    <term><structfield>blue_mask</structfield></term>
3802*4882a593Smuzhiyun	    <listitem><para>
3803*4882a593Smuzhiyun		      The RGB masks for this mode, if applicable.
3804*4882a593Smuzhiyun
3805*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3806*4882a593Smuzhiyun
3807*4882a593Smuzhiyun	  <varlistentry>
3808*4882a593Smuzhiyun	    <term><structfield>viewportWidth</structfield></term>
3809*4882a593Smuzhiyun	    <term><structfield>viewportHeight</structfield></term>
3810*4882a593Smuzhiyun	    <listitem><para>
3811*4882a593Smuzhiyun		      Dimensions of the visible part of the framebuffer.
3812*4882a593Smuzhiyun		      Usually <structfield>mode-&gt;HDisplay</structfield> and
3813*4882a593Smuzhiyun		      <structfield>mode-&gt;VDisplay</structfield>.
3814*4882a593Smuzhiyun
3815*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3816*4882a593Smuzhiyun
3817*4882a593Smuzhiyun	  <varlistentry>
3818*4882a593Smuzhiyun	    <term><structfield>xViewportStep
3819*4882a593Smuzhiyun		yViewportStep</structfield></term>
3820*4882a593Smuzhiyun	    <listitem><para>
3821*4882a593Smuzhiyun		     The granularity of x and y viewport positions that
3822*4882a593Smuzhiyun                     the driver supports in this mode.
3823*4882a593Smuzhiyun
3824*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3825*4882a593Smuzhiyun
3826*4882a593Smuzhiyun	  <varlistentry>
3827*4882a593Smuzhiyun	    <term><structfield>maxViewportX
3828*4882a593Smuzhiyun		maxViewportY</structfield></term>
3829*4882a593Smuzhiyun	    <listitem><para>
3830*4882a593Smuzhiyun		      The maximum viewport position supported by the
3831*4882a593Smuzhiyun                       driver in this mode.
3832*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3833*4882a593Smuzhiyun
3834*4882a593Smuzhiyun	  <varlistentry>
3835*4882a593Smuzhiyun	    <term><structfield>viewportFlags</structfield></term>
3836*4882a593Smuzhiyun	    <listitem><para>
3837*4882a593Smuzhiyun		     The following may be OR'd together:
3838*4882a593Smuzhiyun
3839*4882a593Smuzhiyun		<variablelist>
3840*4882a593Smuzhiyun		  <varlistentry>
3841*4882a593Smuzhiyun		    <term><constant>DGA_FLIP_IMMEDIATE</constant></term>
3842*4882a593Smuzhiyun		    <listitem><para>
3843*4882a593Smuzhiyun		The driver supports immediate viewport changes.
3844*4882a593Smuzhiyun		      </para></listitem></varlistentry>
3845*4882a593Smuzhiyun
3846*4882a593Smuzhiyun		  <varlistentry>
3847*4882a593Smuzhiyun		    <term><constant>DGA_FLIP_RETRACE</constant></term>
3848*4882a593Smuzhiyun
3849*4882a593Smuzhiyun		    <listitem><para>
3850*4882a593Smuzhiyun		The driver supports viewport changes at retrace.
3851*4882a593Smuzhiyun		      </para></listitem></varlistentry>
3852*4882a593Smuzhiyun		  </variablelist>
3853*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3854*4882a593Smuzhiyun
3855*4882a593Smuzhiyun	  <varlistentry>
3856*4882a593Smuzhiyun	    <term><structfield>offset</structfield></term>
3857*4882a593Smuzhiyun	    <listitem><para>
3858*4882a593Smuzhiyun	        The offset into the linear framebuffer that corresponds to
3859*4882a593Smuzhiyun                pixel (0,0) for this mode.
3860*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3861*4882a593Smuzhiyun
3862*4882a593Smuzhiyun	  <varlistentry>
3863*4882a593Smuzhiyun	    <term><structfield>address</structfield></term>
3864*4882a593Smuzhiyun	    <listitem><para>
3865*4882a593Smuzhiyun                The virtual address of the framebuffer as mapped by the driver.
3866*4882a593Smuzhiyun                This is needed when DGA_PIXMAP_AVAILABLE is set.
3867*4882a593Smuzhiyun	      </para></listitem></varlistentry>
3868*4882a593Smuzhiyun
3869*4882a593Smuzhiyun	</variablelist>
3870*4882a593Smuzhiyun
3871*4882a593Smuzhiyun	<programlisting>
3872*4882a593Smuzhiyun/** The DGAFunctionRec **/
3873*4882a593Smuzhiyun
3874*4882a593Smuzhiyuntypedef struct {
3875*4882a593Smuzhiyun  Bool (*OpenFramebuffer)(
3876*4882a593Smuzhiyun       ScrnInfoPtr pScrn,
3877*4882a593Smuzhiyun       char **name,
3878*4882a593Smuzhiyun       unsigned char **mem,
3879*4882a593Smuzhiyun       int *size,
3880*4882a593Smuzhiyun       int *offset,
3881*4882a593Smuzhiyun       int *extra
3882*4882a593Smuzhiyun  );
3883*4882a593Smuzhiyun  void (*CloseFramebuffer)(ScrnInfoPtr pScrn);
3884*4882a593Smuzhiyun  Bool (*SetMode)(ScrnInfoPtr pScrn, DGAModePtr pMode);
3885*4882a593Smuzhiyun  void (*SetViewport)(ScrnInfoPtr pScrn, int x, int y, int flags);
3886*4882a593Smuzhiyun  int  (*GetViewport)(ScrnInfoPtr pScrn);
3887*4882a593Smuzhiyun  void (*Sync)(ScrnInfoPtr);
3888*4882a593Smuzhiyun  void (*FillRect)(
3889*4882a593Smuzhiyun       ScrnInfoPtr pScrn,
3890*4882a593Smuzhiyun       int x, int y, int w, int h,
3891*4882a593Smuzhiyun       unsigned long color
3892*4882a593Smuzhiyun  );
3893*4882a593Smuzhiyun  void (*BlitRect)(
3894*4882a593Smuzhiyun       ScrnInfoPtr pScrn,
3895*4882a593Smuzhiyun       int srcx, int srcy,
3896*4882a593Smuzhiyun       int w, int h,
3897*4882a593Smuzhiyun       int dstx, int dsty
3898*4882a593Smuzhiyun  );
3899*4882a593Smuzhiyun  void (*BlitTransRect)(
3900*4882a593Smuzhiyun       ScrnInfoPtr pScrn,
3901*4882a593Smuzhiyun       int srcx, int srcy,
3902*4882a593Smuzhiyun       int w, int h,
3903*4882a593Smuzhiyun       int dstx, int dsty,
3904*4882a593Smuzhiyun       unsigned long color
3905*4882a593Smuzhiyun  );
3906*4882a593Smuzhiyun} DGAFunctionRec, *DGAFunctionPtr;
3907*4882a593Smuzhiyun	</programlisting>
3908*4882a593Smuzhiyun
3909*4882a593Smuzhiyun
3910*4882a593Smuzhiyun	<blockquote><para>
3911*4882a593Smuzhiyun	    <programlisting>
3912*4882a593Smuzhiyun    Bool OpenFramebuffer (pScrn, name, mem, size, offset, extra);
3913*4882a593Smuzhiyun	    </programlisting>
3914*4882a593Smuzhiyun	    <blockquote><para>
3915*4882a593Smuzhiyun      <function>OpenFramebuffer()</function> should pass the client everything
3916*4882a593Smuzhiyun      it needs to know to be able to open the framebuffer.  These
3917*4882a593Smuzhiyun      parameters are OS specific and their meanings are to be interpreted
3918*4882a593Smuzhiyun      by an OS specific client library.
3919*4882a593Smuzhiyun
3920*4882a593Smuzhiyun		<variablelist>
3921*4882a593Smuzhiyun		  <varlistentry>
3922*4882a593Smuzhiyun		    <term><parameter>name</parameter></term>
3923*4882a593Smuzhiyun		    <listitem><para>
3924*4882a593Smuzhiyun	      The name of the device to open or <constant>NULL</constant> if
3925*4882a593Smuzhiyun	      there is no special device to open.  A <constant>NULL</constant>
3926*4882a593Smuzhiyun	      name tells the client that it should open whatever device
3927*4882a593Smuzhiyun	      one would usually open to access physical memory.
3928*4882a593Smuzhiyun		      </para></listitem></varlistentry>
3929*4882a593Smuzhiyun
3930*4882a593Smuzhiyun		  <varlistentry>
3931*4882a593Smuzhiyun		    <term><parameter>mem</parameter></term>
3932*4882a593Smuzhiyun		    <listitem><para>
3933*4882a593Smuzhiyun	      The physical address of the start of the framebuffer.
3934*4882a593Smuzhiyun		      </para></listitem></varlistentry>
3935*4882a593Smuzhiyun
3936*4882a593Smuzhiyun		  <varlistentry>
3937*4882a593Smuzhiyun		    <term><parameter>size</parameter></term>
3938*4882a593Smuzhiyun		    <listitem><para>
3939*4882a593Smuzhiyun	      The size of the framebuffer in bytes.
3940*4882a593Smuzhiyun		      </para></listitem></varlistentry>
3941*4882a593Smuzhiyun
3942*4882a593Smuzhiyun		  <varlistentry>
3943*4882a593Smuzhiyun		    <term><parameter>offset</parameter></term>
3944*4882a593Smuzhiyun		    <listitem><para>
3945*4882a593Smuzhiyun	      Any offset into the device, if applicable.
3946*4882a593Smuzhiyun		      </para></listitem></varlistentry>
3947*4882a593Smuzhiyun
3948*4882a593Smuzhiyun		  <varlistentry>
3949*4882a593Smuzhiyun		    <term><parameter>flags</parameter></term>
3950*4882a593Smuzhiyun		    <listitem><para>
3951*4882a593Smuzhiyun	      Any additional information that the client may need.
3952*4882a593Smuzhiyun	      Currently, only the <constant>DGA_NEED_ROOT</constant> flag is
3953*4882a593Smuzhiyun	      defined.
3954*4882a593Smuzhiyun		      </para></listitem></varlistentry>
3955*4882a593Smuzhiyun
3956*4882a593Smuzhiyun		</variablelist>
3957*4882a593Smuzhiyun	      </para></blockquote>
3958*4882a593Smuzhiyun	  </para></blockquote>
3959*4882a593Smuzhiyun
3960*4882a593Smuzhiyun	<blockquote><para>
3961*4882a593Smuzhiyun	    <programlisting>
3962*4882a593Smuzhiyun    void CloseFramebuffer (pScrn);
3963*4882a593Smuzhiyun	    </programlisting>
3964*4882a593Smuzhiyun	    <blockquote><para>
3965*4882a593Smuzhiyun      <function>CloseFramebuffer()</function> merely informs the driver (if it
3966*4882a593Smuzhiyun      even cares) that client no longer needs to access the framebuffer
3967*4882a593Smuzhiyun      directly.  This function is optional.
3968*4882a593Smuzhiyun	      </para>
3969*4882a593Smuzhiyun
3970*4882a593Smuzhiyun	    </blockquote></para></blockquote>
3971*4882a593Smuzhiyun
3972*4882a593Smuzhiyun	<blockquote><para>
3973*4882a593Smuzhiyun	    <programlisting>
3974*4882a593Smuzhiyun    Bool SetMode (pScrn, pMode);
3975*4882a593Smuzhiyun	    </programlisting>
3976*4882a593Smuzhiyun	    <blockquote><para>
3977*4882a593Smuzhiyun      <function>SetMode()</function> tells the driver to initialize the mode
3978*4882a593Smuzhiyun      passed to it.  If <parameter>pMode</parameter> is <constant>NULL</constant>,
3979*4882a593Smuzhiyun      then the driver should restore the original pre-DGA mode.
3980*4882a593Smuzhiyun	      </para>
3981*4882a593Smuzhiyun
3982*4882a593Smuzhiyun	    </blockquote></para></blockquote>
3983*4882a593Smuzhiyun
3984*4882a593Smuzhiyun	<blockquote><para>
3985*4882a593Smuzhiyun	    <programlisting>
3986*4882a593Smuzhiyun    void SetViewport (pScrn, x, y, flags);
3987*4882a593Smuzhiyun	    </programlisting>
3988*4882a593Smuzhiyun	    <blockquote><para>
3989*4882a593Smuzhiyun      <function>SetViewport()</function> tells the driver to make the upper
3990*4882a593Smuzhiyun      left-hand corner of the visible screen correspond to coordinate
3991*4882a593Smuzhiyun      <literal remap="tt">(x,y)</literal> on the framebuffer.  <parameter>flags</parameter>
3992*4882a593Smuzhiyun      currently defined are:
3993*4882a593Smuzhiyun
3994*4882a593Smuzhiyun		<variablelist>
3995*4882a593Smuzhiyun		  <varlistentry>
3996*4882a593Smuzhiyun		    <term><constant>DGA_FLIP_IMMEDIATE</constant></term>
3997*4882a593Smuzhiyun		    <listitem><para>
3998*4882a593Smuzhiyun	    The viewport change should occur immediately.
3999*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4000*4882a593Smuzhiyun
4001*4882a593Smuzhiyun		  <varlistentry>
4002*4882a593Smuzhiyun		    <term><constant>DGA_FLIP_RETRACE</constant></term>
4003*4882a593Smuzhiyun		    <listitem><para>
4004*4882a593Smuzhiyun	    The viewport change should occur at the
4005*4882a593Smuzhiyun            vertical retrace, but this function should
4006*4882a593Smuzhiyun            return sooner if possible.
4007*4882a593Smuzhiyun			</para></listitem></varlistentry>
4008*4882a593Smuzhiyun		</variablelist>
4009*4882a593Smuzhiyun	      </para>
4010*4882a593Smuzhiyun
4011*4882a593Smuzhiyun	      <para>
4012*4882a593Smuzhiyun      The <literal remap="tt">(x,y)</literal> locations will be passed as the client
4013*4882a593Smuzhiyun      specified them, however, the driver is expected to round these
4014*4882a593Smuzhiyun      locations down to the next supported location as specified by the
4015*4882a593Smuzhiyun      <structfield>xViewportStep</structfield> and <structfield>yViewportStep</structfield>
4016*4882a593Smuzhiyun      for the current mode.
4017*4882a593Smuzhiyun	      </para>
4018*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4019*4882a593Smuzhiyun
4020*4882a593Smuzhiyun	<blockquote><para>
4021*4882a593Smuzhiyun	    <programlisting>
4022*4882a593Smuzhiyun    int GetViewport (pScrn);
4023*4882a593Smuzhiyun	    </programlisting>
4024*4882a593Smuzhiyun	    <blockquote><para>
4025*4882a593Smuzhiyun      <function>GetViewport()</function> gets the current page flip status.
4026*4882a593Smuzhiyun      Set bits in the returned int correspond to viewport change requests
4027*4882a593Smuzhiyun      still pending.  For instance, set bit zero if the last SetViewport
4028*4882a593Smuzhiyun      request is still pending, bit one if the one before that is still
4029*4882a593Smuzhiyun      pending, etc.
4030*4882a593Smuzhiyun	      </para>
4031*4882a593Smuzhiyun
4032*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4033*4882a593Smuzhiyun
4034*4882a593Smuzhiyun	<blockquote><para>
4035*4882a593Smuzhiyun	    <programlisting>
4036*4882a593Smuzhiyun    void Sync (pScrn);
4037*4882a593Smuzhiyun	    </programlisting>
4038*4882a593Smuzhiyun	    <blockquote><para>
4039*4882a593Smuzhiyun      This function should ensure that any graphics accelerator operations
4040*4882a593Smuzhiyun      have finished.  This function should not return until the graphics
4041*4882a593Smuzhiyun      accelerator is idle.
4042*4882a593Smuzhiyun	      </para>
4043*4882a593Smuzhiyun
4044*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4045*4882a593Smuzhiyun
4046*4882a593Smuzhiyun	<blockquote><para>
4047*4882a593Smuzhiyun	    <programlisting>
4048*4882a593Smuzhiyun    void FillRect (pScrn, x, y, w, h, color);
4049*4882a593Smuzhiyun	    </programlisting>
4050*4882a593Smuzhiyun	    <blockquote><para>
4051*4882a593Smuzhiyun      This optional function should fill a rectangle
4052*4882a593Smuzhiyun      <parameter>w&nbsp;&times;&nbsp;h</parameter> located at
4053*4882a593Smuzhiyun      <parameter>(x,y)</parameter> in the given color.
4054*4882a593Smuzhiyun	      </para>
4055*4882a593Smuzhiyun
4056*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4057*4882a593Smuzhiyun
4058*4882a593Smuzhiyun	<blockquote><para>
4059*4882a593Smuzhiyun	    <programlisting>
4060*4882a593Smuzhiyun    void BlitRect (pScrn, srcx, srcy, w, h, dstx, dsty);
4061*4882a593Smuzhiyun	    </programlisting>
4062*4882a593Smuzhiyun	    <blockquote><para>
4063*4882a593Smuzhiyun      This optional function should copy an area
4064*4882a593Smuzhiyun      <parameter>w&nbsp;&times;&nbsp;h</parameter> located at
4065*4882a593Smuzhiyun      <parameter>(srcx,srcy)</parameter> to location <parameter>(dstx,dsty)</parameter>.
4066*4882a593Smuzhiyun      This function will need to handle copy directions as appropriate.
4067*4882a593Smuzhiyun	      </para>
4068*4882a593Smuzhiyun
4069*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4070*4882a593Smuzhiyun
4071*4882a593Smuzhiyun	<blockquote><para>
4072*4882a593Smuzhiyun	    <programlisting>
4073*4882a593Smuzhiyun    void BlitTransRect (pScrn, srcx, srcy, w, h, dstx, dsty, color);
4074*4882a593Smuzhiyun	    </programlisting>
4075*4882a593Smuzhiyun	    <blockquote><para>
4076*4882a593Smuzhiyun      This optional function is the same as BlitRect except that pixels
4077*4882a593Smuzhiyun      in the source corresponding to the color key <parameter>color</parameter>
4078*4882a593Smuzhiyun      should be skipped.
4079*4882a593Smuzhiyun	      </para>
4080*4882a593Smuzhiyun
4081*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4082*4882a593Smuzhiyun    </para></blockquote>
4083*4882a593Smuzhiyun
4084*4882a593Smuzhiyun  </sect1>
4085*4882a593Smuzhiyun
4086*4882a593Smuzhiyun  <sect1>
4087*4882a593Smuzhiyun    <title>The XFree86 X Video Extension (Xv) Device Dependent Layer</title>
4088*4882a593Smuzhiyun
4089*4882a593Smuzhiyun    <para>
4090*4882a593SmuzhiyunXFree86 offers the X Video Extension which allows clients to treat video
4091*4882a593Smuzhiyunas any another primitive and <quote>Put</quote> video into drawables.  By default,
4092*4882a593Smuzhiyunthe extension reports no video adaptors as being available since the
4093*4882a593SmuzhiyunDDX layer has not been initialized.  The driver can initialize the DDX
4094*4882a593Smuzhiyunlayer by filling out one or more <literal remap="tt">XF86VideoAdaptorRecs</literal>
4095*4882a593Smuzhiyunas described later in this document and passing a list of
4096*4882a593Smuzhiyun<literal remap="tt">XF86VideoAdaptorPtr</literal> pointers to the following function:
4097*4882a593Smuzhiyun
4098*4882a593Smuzhiyun      <programlisting>
4099*4882a593Smuzhiyun    Bool xf86XVScreenInit(ScreenPtr pScreen,
4100*4882a593Smuzhiyun                          XF86VideoAdaptorPtr *adaptPtrs,
4101*4882a593Smuzhiyun                          int num);
4102*4882a593Smuzhiyun      </programlisting>
4103*4882a593Smuzhiyun    </para>
4104*4882a593Smuzhiyun
4105*4882a593Smuzhiyun    <para>
4106*4882a593SmuzhiyunAfter doing this, the extension will report video adaptors as being
4107*4882a593Smuzhiyunavailable, providing the data in their respective
4108*4882a593Smuzhiyun<literal remap="tt">XF86VideoAdaptorRecs</literal> was valid.
4109*4882a593Smuzhiyun<function>xf86XVScreenInit()</function> <emphasis>copies</emphasis> data from the structure
4110*4882a593Smuzhiyunpassed to it so the driver may free it after the initialization.  At
4111*4882a593Smuzhiyunthe moment, the DDX only supports rendering into Window drawables.
4112*4882a593SmuzhiyunPixmap rendering will be supported after a sufficient survey of suitable
4113*4882a593Smuzhiyunhardware is completed.
4114*4882a593Smuzhiyun    </para>
4115*4882a593Smuzhiyun
4116*4882a593Smuzhiyun    <para>
4117*4882a593SmuzhiyunThe <structname>XF86VideoAdaptorRec</structname>:
4118*4882a593Smuzhiyun
4119*4882a593Smuzhiyun      <programlisting>
4120*4882a593Smuzhiyuntypedef struct {
4121*4882a593Smuzhiyun	unsigned int type;
4122*4882a593Smuzhiyun	int flags;
4123*4882a593Smuzhiyun	char *name;
4124*4882a593Smuzhiyun	int nEncodings;
4125*4882a593Smuzhiyun	XF86VideoEncodingPtr pEncodings;
4126*4882a593Smuzhiyun	int nFormats;
4127*4882a593Smuzhiyun	XF86VideoFormatPtr pFormats;
4128*4882a593Smuzhiyun	int nPorts;
4129*4882a593Smuzhiyun	DevUnion *pPortPrivates;
4130*4882a593Smuzhiyun	int nAttributes;
4131*4882a593Smuzhiyun	XF86AttributePtr pAttributes;
4132*4882a593Smuzhiyun	int nImages;
4133*4882a593Smuzhiyun	XF86ImagePtr pImages;
4134*4882a593Smuzhiyun	PutVideoFuncPtr PutVideo;
4135*4882a593Smuzhiyun	PutStillFuncPtr PutStill;
4136*4882a593Smuzhiyun	GetVideoFuncPtr GetVideo;
4137*4882a593Smuzhiyun	GetStillFuncPtr GetStill;
4138*4882a593Smuzhiyun	StopVideoFuncPtr StopVideo;
4139*4882a593Smuzhiyun	SetPortAttributeFuncPtr SetPortAttribute;
4140*4882a593Smuzhiyun	GetPortAttributeFuncPtr GetPortAttribute;
4141*4882a593Smuzhiyun	QueryBestSizeFuncPtr QueryBestSize;
4142*4882a593Smuzhiyun	PutImageFuncPtr PutImage;
4143*4882a593Smuzhiyun	QueryImageAttributesFuncPtr QueryImageAttributes;
4144*4882a593Smuzhiyun} XF86VideoAdaptorRec, *XF86VideoAdaptorPtr;
4145*4882a593Smuzhiyun      </programlisting></para>
4146*4882a593Smuzhiyun
4147*4882a593Smuzhiyun    <para>
4148*4882a593SmuzhiyunEach adaptor will have its own XF86VideoAdaptorRec.  The fields are
4149*4882a593Smuzhiyunas follows:
4150*4882a593Smuzhiyun
4151*4882a593Smuzhiyun      <variablelist>
4152*4882a593Smuzhiyun	<varlistentry>
4153*4882a593Smuzhiyun	  <term><structfield>type</structfield></term>
4154*4882a593Smuzhiyun	  <listitem><para>
4155*4882a593Smuzhiyun	This can be any of the following flags OR'd together.
4156*4882a593Smuzhiyun
4157*4882a593Smuzhiyun	      <variablelist>
4158*4882a593Smuzhiyun		<varlistentry>
4159*4882a593Smuzhiyun		  <term><constant>XvInputMask</constant>
4160*4882a593Smuzhiyun		    <constant>XvOutputMask</constant></term>
4161*4882a593Smuzhiyun		  <listitem><para>
4162*4882a593Smuzhiyun	    These refer to the target drawable and are similar to a Window's
4163*4882a593Smuzhiyun	    class. <literal remap="tt">XvInputMask</literal> indicates that the adaptor
4164*4882a593Smuzhiyun	    can put video into a drawable.  <literal remap="tt">XvOutputMask</literal>
4165*4882a593Smuzhiyun	    indicates that the adaptor can get video from a drawable.
4166*4882a593Smuzhiyun		    </para></listitem></varlistentry>
4167*4882a593Smuzhiyun
4168*4882a593Smuzhiyun		<varlistentry>
4169*4882a593Smuzhiyun		  <term><constant>XvVideoMask</constant>
4170*4882a593Smuzhiyun		    <constant>XvStillMask</constant>
4171*4882a593Smuzhiyun		    <constant>XvImageMask</constant></term>
4172*4882a593Smuzhiyun		  <listitem><para>
4173*4882a593Smuzhiyun	    These indicate that the adaptor supports video, still or
4174*4882a593Smuzhiyun	    image primitives respectively.
4175*4882a593Smuzhiyun		    </para></listitem></varlistentry>
4176*4882a593Smuzhiyun
4177*4882a593Smuzhiyun		<varlistentry>
4178*4882a593Smuzhiyun		  <term><constant>XvWindowMask</constant>
4179*4882a593Smuzhiyun		    <constant>XvPixmapMask</constant></term>
4180*4882a593Smuzhiyun		  <listitem><para>
4181*4882a593Smuzhiyun	    These indicate the types of drawables the adaptor is capable
4182*4882a593Smuzhiyun	    of rendering into.  At the moment, Pixmap rendering is not
4183*4882a593Smuzhiyun	    supported and the <constant>XvPixmapMask</constant> flag is ignored.
4184*4882a593Smuzhiyun		    </para></listitem></varlistentry>
4185*4882a593Smuzhiyun	      </variablelist>
4186*4882a593Smuzhiyun
4187*4882a593Smuzhiyun	    </para></listitem></varlistentry>
4188*4882a593Smuzhiyun
4189*4882a593Smuzhiyun	<varlistentry>
4190*4882a593Smuzhiyun	  <term><structfield>flags</structfield></term>
4191*4882a593Smuzhiyun	  <listitem><para>
4192*4882a593Smuzhiyun	Currently, the following flags are defined:
4193*4882a593Smuzhiyun
4194*4882a593Smuzhiyun	      <variablelist>
4195*4882a593Smuzhiyun		<varlistentry>
4196*4882a593Smuzhiyun		  <term><constant>VIDEO_OVERLAID_STILLS</constant></term>
4197*4882a593Smuzhiyun		  <listitem><para>
4198*4882a593Smuzhiyun	   Implementing PutStill for hardware that does video as an
4199*4882a593Smuzhiyun	   overlay can be awkward since it's unclear how long to leave
4200*4882a593Smuzhiyun	   the video up for.  When this flag is set, StopVideo will be
4201*4882a593Smuzhiyun	   called whenever the destination gets clipped or moved so that
4202*4882a593Smuzhiyun	   the still can be left up until then.
4203*4882a593Smuzhiyun		    </para></listitem>
4204*4882a593Smuzhiyun
4205*4882a593Smuzhiyun		</varlistentry>
4206*4882a593Smuzhiyun
4207*4882a593Smuzhiyun		<varlistentry>
4208*4882a593Smuzhiyun		  <term><constant>VIDEO_OVERLAID_IMAGES</constant></term>
4209*4882a593Smuzhiyun		  <listitem><para>
4210*4882a593Smuzhiyun	   Same as <constant>VIDEO_OVERLAID_STILLS</constant> but for images.
4211*4882a593Smuzhiyun		    </para></listitem>
4212*4882a593Smuzhiyun		</varlistentry>
4213*4882a593Smuzhiyun
4214*4882a593Smuzhiyun		<varlistentry>
4215*4882a593Smuzhiyun		  <term><constant>VIDEO_CLIP_TO_VIEWPORT</constant></term>
4216*4882a593Smuzhiyun		  <listitem><para>
4217*4882a593Smuzhiyun	    Indicates that the clip region passed to the driver functions
4218*4882a593Smuzhiyun	    should be clipped to the visible portion of the screen in the
4219*4882a593Smuzhiyun	    case where the viewport is smaller than the virtual desktop.
4220*4882a593Smuzhiyun		    </para></listitem></varlistentry>
4221*4882a593Smuzhiyun
4222*4882a593Smuzhiyun	      </variablelist>
4223*4882a593Smuzhiyun	    </para></listitem></varlistentry>
4224*4882a593Smuzhiyun
4225*4882a593Smuzhiyun	<varlistentry>
4226*4882a593Smuzhiyun	  <term><structfield>name</structfield></term>
4227*4882a593Smuzhiyun	  <listitem><para>
4228*4882a593Smuzhiyun	The name of the adaptor.
4229*4882a593Smuzhiyun	    </para></listitem></varlistentry>
4230*4882a593Smuzhiyun
4231*4882a593Smuzhiyun
4232*4882a593Smuzhiyun	<varlistentry>
4233*4882a593Smuzhiyun	  <term><structfield>nEncodings</structfield>
4234*4882a593Smuzhiyun	    <structfield>pEncodings</structfield></term>
4235*4882a593Smuzhiyun	  <listitem><para>
4236*4882a593Smuzhiyun	The number of encodings the adaptor is capable of and pointer
4237*4882a593Smuzhiyun	to the <structname>XF86VideoEncodingRec</structname> array.  The
4238*4882a593Smuzhiyun	<structname>XF86VideoEncodingRec</structname> is described later on.
4239*4882a593Smuzhiyun	For drivers that only support XvImages there should be an encoding
4240*4882a593Smuzhiyun	named "XV_IMAGE" and the width and height should specify
4241*4882a593Smuzhiyun	the maximum size source image supported.
4242*4882a593Smuzhiyun	  </para></listitem></varlistentry>
4243*4882a593Smuzhiyun
4244*4882a593Smuzhiyun
4245*4882a593Smuzhiyun	<varlistentry>
4246*4882a593Smuzhiyun	  <term><structfield>nFormats</structfield>
4247*4882a593Smuzhiyun	      <structfield>pFormats</structfield></term>
4248*4882a593Smuzhiyun	  <listitem><para>
4249*4882a593Smuzhiyun	The number of formats the adaptor is capable of and pointer to
4250*4882a593Smuzhiyun	the <structname>XF86VideoFormatRec</structname> array.  The
4251*4882a593Smuzhiyun	<structname>XF86VideoFormatRec</structname> is described later on.
4252*4882a593Smuzhiyun	    </para></listitem></varlistentry>
4253*4882a593Smuzhiyun
4254*4882a593Smuzhiyun
4255*4882a593Smuzhiyun	<varlistentry>
4256*4882a593Smuzhiyun	  <term><structfield>nPorts</structfield>
4257*4882a593Smuzhiyun	    <structfield>pPortPrivates</structfield></term>
4258*4882a593Smuzhiyun	  <listitem><para>
4259*4882a593Smuzhiyun	The number of ports is the number of separate data streams which
4260*4882a593Smuzhiyun	the adaptor can handle simultaneously.  If you have more than
4261*4882a593Smuzhiyun	one port, the adaptor is expected to be able to render into more
4262*4882a593Smuzhiyun	than one window at a time.  <structfield>pPortPrivates</structfield> is
4263*4882a593Smuzhiyun	an array of pointers or ints - one for each port.  A port's
4264*4882a593Smuzhiyun	private data will be passed to the driver any time the port is
4265*4882a593Smuzhiyun	requested to do something like put the video or stop the video.
4266*4882a593Smuzhiyun	In the case where there may be many ports, this enables the
4267*4882a593Smuzhiyun	driver to know which port the request is intended for.  Most
4268*4882a593Smuzhiyun	commonly, this will contain a pointer to the data structure
4269*4882a593Smuzhiyun	containing information about the port.  In Xv, all ports on
4270*4882a593Smuzhiyun	a particular adaptor are expected to be identical in their
4271*4882a593Smuzhiyun	functionality.
4272*4882a593Smuzhiyun	    </para></listitem></varlistentry>
4273*4882a593Smuzhiyun
4274*4882a593Smuzhiyun
4275*4882a593Smuzhiyun	<varlistentry>
4276*4882a593Smuzhiyun	  <term><structfield>nAttributes</structfield>
4277*4882a593Smuzhiyun	    <structfield>pAttributes</structfield></term>
4278*4882a593Smuzhiyun	  <listitem><para>
4279*4882a593Smuzhiyun	The number of attributes recognized by the adaptor and a pointer to
4280*4882a593Smuzhiyun	the array of <structname>XF86AttributeRecs</structname>.  The
4281*4882a593Smuzhiyun	<structname>XF86AttributeRec</structname> is described later on.
4282*4882a593Smuzhiyun	    </para></listitem></varlistentry>
4283*4882a593Smuzhiyun
4284*4882a593Smuzhiyun
4285*4882a593Smuzhiyun	<varlistentry>
4286*4882a593Smuzhiyun	  <term><structfield>nImages</structfield>
4287*4882a593Smuzhiyun	    <structfield>pImages</structfield></term>
4288*4882a593Smuzhiyun	  <listitem><para>
4289*4882a593Smuzhiyun	The number of <structname>XF86ImageRecs</structname> supported by the adaptor
4290*4882a593Smuzhiyun	and a pointer to the array of <structname>XF86ImageRecs</structname>. The
4291*4882a593Smuzhiyun	<structname>XF86ImageRec</structname> is described later on.
4292*4882a593Smuzhiyun	    </para></listitem></varlistentry>
4293*4882a593Smuzhiyun
4294*4882a593Smuzhiyun
4295*4882a593Smuzhiyun	<varlistentry>
4296*4882a593Smuzhiyun	  <term><structfield>
4297*4882a593Smuzhiyun     PutVideo PutStill GetVideo GetStill StopVideo
4298*4882a593Smuzhiyun     SetPortAttribute GetPortAttribute QueryBestSize PutImage
4299*4882a593Smuzhiyun     QueryImageAttributes
4300*4882a593Smuzhiyun	    </structfield></term>
4301*4882a593Smuzhiyun	  <listitem><para>
4302*4882a593Smuzhiyun	These functions define the DDX-&gt;driver interface.  In each
4303*4882a593Smuzhiyun	case, the pointer <parameter>data</parameter> is passed to the driver.
4304*4882a593Smuzhiyun	This is the port private for that port as described above.  All
4305*4882a593Smuzhiyun	fields are required except under the following conditions:
4306*4882a593Smuzhiyun
4307*4882a593Smuzhiyun	      <orderedlist>
4308*4882a593Smuzhiyun		<listitem><para>
4309*4882a593Smuzhiyun	     <structfield>PutVideo</structfield>, <structfield>PutStill</structfield> and
4310*4882a593Smuzhiyun	     the image routines <structfield>PutImage</structfield> and
4311*4882a593Smuzhiyun	     <structfield>QueryImageAttributes</structfield> are not required when the
4312*4882a593Smuzhiyun	     adaptor type does not contain <constant>XvInputMask</constant>.
4313*4882a593Smuzhiyun		  </para></listitem>
4314*4882a593Smuzhiyun
4315*4882a593Smuzhiyun		<listitem><para>
4316*4882a593Smuzhiyun	     <structfield>GetVideo</structfield> and <structfield>GetStill</structfield>
4317*4882a593Smuzhiyun	     are not required when the adaptor type does not contain
4318*4882a593Smuzhiyun	     <constant>XvOutputMask</constant>.
4319*4882a593Smuzhiyun		  </para></listitem>
4320*4882a593Smuzhiyun
4321*4882a593Smuzhiyun		<listitem><para>
4322*4882a593Smuzhiyun	     <structfield>GetVideo</structfield> and <structfield>PutVideo</structfield>
4323*4882a593Smuzhiyun	     are not required when the adaptor type does not contain
4324*4882a593Smuzhiyun	     <constant>XvVideoMask</constant>.
4325*4882a593Smuzhiyun		  </para></listitem>
4326*4882a593Smuzhiyun
4327*4882a593Smuzhiyun		<listitem><para>
4328*4882a593Smuzhiyun	     <structfield>GetStill</structfield> and <structfield>PutStill</structfield>
4329*4882a593Smuzhiyun	     are not required when the adaptor type does not contain
4330*4882a593Smuzhiyun	     <constant>XvStillMask</constant>.
4331*4882a593Smuzhiyun		  </para></listitem>
4332*4882a593Smuzhiyun
4333*4882a593Smuzhiyun		<listitem><para>
4334*4882a593Smuzhiyun	     <structfield>PutImage</structfield> and <structfield>QueryImageAttributes</structfield>
4335*4882a593Smuzhiyun	     are not required when the adaptor type does not contain
4336*4882a593Smuzhiyun	     <constant>XvImageMask</constant>.
4337*4882a593Smuzhiyun		  </para></listitem>
4338*4882a593Smuzhiyun
4339*4882a593Smuzhiyun	      </orderedlist>
4340*4882a593Smuzhiyun
4341*4882a593Smuzhiyun	    </para>
4342*4882a593Smuzhiyun
4343*4882a593Smuzhiyun	    <para>
4344*4882a593Smuzhiyun	With the exception of <structfield>QueryImageAttributes</structfield>, these
4345*4882a593Smuzhiyun	functions should return <constant>Success</constant> if the operation was
4346*4882a593Smuzhiyun	completed successfully.  They can return <constant>XvBadAlloc</constant>
4347*4882a593Smuzhiyun	otherwise. <structfield>QueryImageAttributes</structfield> returns the size
4348*4882a593Smuzhiyun	of the XvImage queried.
4349*4882a593Smuzhiyun	    </para>
4350*4882a593Smuzhiyun
4351*4882a593Smuzhiyun	    <para>
4352*4882a593Smuzhiyun	<literal remap="tt">ClipBoxes</literal> is an <literal remap="tt">X-Y</literal>
4353*4882a593Smuzhiyun	banded region identical to those used throughout the server.
4354*4882a593Smuzhiyun	The clipBoxes represent the visible portions of the area determined
4355*4882a593Smuzhiyun	by <literal remap="tt">drw_x</literal>, <literal remap="tt">drw_y</literal>,
4356*4882a593Smuzhiyun	<literal remap="tt">drw_w</literal> and <literal remap="tt">drw_h</literal> in the Get/Put
4357*4882a593Smuzhiyun	function.  The boxes are in screen coordinates, are guaranteed
4358*4882a593Smuzhiyun	not to overlap and an empty region will never be passed.
4359*4882a593Smuzhiyun
4360*4882a593Smuzhiyun	    </para></listitem></varlistentry>
4361*4882a593Smuzhiyun      </variablelist>
4362*4882a593Smuzhiyun
4363*4882a593Smuzhiyun      <blockquote><para>
4364*4882a593Smuzhiyun	  <programlisting>
4365*4882a593Smuzhiyun    typedef  int (* PutVideoFuncPtr)( ScrnInfoPtr pScrn,
4366*4882a593Smuzhiyun                   short vid_x, short vid_y, short drw_x, short drw_y,
4367*4882a593Smuzhiyun                   short vid_w, short vid_h, short drw_w, short drw_h,
4368*4882a593Smuzhiyun                   RegionPtr clipBoxes, pointer data );
4369*4882a593Smuzhiyun	  </programlisting>
4370*4882a593Smuzhiyun	      <blockquote><para>
4371*4882a593Smuzhiyun	  This indicates that the driver should take a subsection
4372*4882a593Smuzhiyun	  <parameter>vid_w</parameter> by <parameter>vid_h</parameter> at location
4373*4882a593Smuzhiyun	  <parameter>(vid_x,vid_y)</parameter> from the video stream and direct
4374*4882a593Smuzhiyun	  it into the rectangle <parameter>drw_w</parameter> by <parameter>drw_h</parameter>
4375*4882a593Smuzhiyun	  at location <parameter>(drw_x,drw_y)</parameter> on the screen, scaling as
4376*4882a593Smuzhiyun	  necessary.  Due to the large variations in capabilities of
4377*4882a593Smuzhiyun	  the various hardware expected to be used with this extension,
4378*4882a593Smuzhiyun	  it is not expected that all hardware will be able to do this
4379*4882a593Smuzhiyun	  exactly as described.  In that case the driver should just do
4380*4882a593Smuzhiyun	  <quote>the best it can,</quote> scaling as closely to the target rectangle
4381*4882a593Smuzhiyun	  as it can without rendering outside of it.  In the worst case,
4382*4882a593Smuzhiyun	  the driver can opt to just not turn on the video.
4383*4882a593Smuzhiyun	      </para>
4384*4882a593Smuzhiyun
4385*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4386*4882a593Smuzhiyun
4387*4882a593Smuzhiyun	  <blockquote><para>
4388*4882a593Smuzhiyun	      <programlisting>
4389*4882a593Smuzhiyun    typedef  int (* PutStillFuncPtr)( ScrnInfoPtr pScrn,
4390*4882a593Smuzhiyun                   short vid_x, short vid_y, short drw_x, short drw_y,
4391*4882a593Smuzhiyun                   short vid_w, short vid_h, short drw_w, short drw_h,
4392*4882a593Smuzhiyun                   RegionPtr clipBoxes, pointer data );
4393*4882a593Smuzhiyun	      </programlisting>
4394*4882a593Smuzhiyun	      <blockquote><para>
4395*4882a593Smuzhiyun	  This is same as <structfield>PutVideo</structfield> except that the driver
4396*4882a593Smuzhiyun	  should place only one frame from the stream on the screen.
4397*4882a593Smuzhiyun	      </para>
4398*4882a593Smuzhiyun
4399*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4400*4882a593Smuzhiyun
4401*4882a593Smuzhiyun	  <blockquote><para>
4402*4882a593Smuzhiyun	      <programlisting>
4403*4882a593Smuzhiyun    typedef int (* GetVideoFuncPtr)( ScrnInfoPtr pScrn,
4404*4882a593Smuzhiyun                  short vid_x, short vid_y, short drw_x, short drw_y,
4405*4882a593Smuzhiyun                  short vid_w, short vid_h, short drw_w, short drw_h,
4406*4882a593Smuzhiyun                  RegionPtr clipBoxes, pointer data );
4407*4882a593Smuzhiyun	      </programlisting>
4408*4882a593Smuzhiyun	      <blockquote><para>
4409*4882a593Smuzhiyun	  This is same as <structfield>PutVideo</structfield> except that the driver
4410*4882a593Smuzhiyun	  gets video from the screen and outputs it.  The driver should
4411*4882a593Smuzhiyun	  do the best it can to get the requested dimensions correct
4412*4882a593Smuzhiyun	  without reading from an area larger than requested.
4413*4882a593Smuzhiyun	      </para>
4414*4882a593Smuzhiyun
4415*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4416*4882a593Smuzhiyun
4417*4882a593Smuzhiyun	  <blockquote><para>
4418*4882a593Smuzhiyun	      <programlisting>
4419*4882a593Smuzhiyun    typedef int (* GetStillFuncPtr)( ScrnInfoPtr pScrn,
4420*4882a593Smuzhiyun                  short vid_x, short vid_y, short drw_x, short drw_y,
4421*4882a593Smuzhiyun                  short vid_w, short vid_h, short drw_w, short drw_h,
4422*4882a593Smuzhiyun                  RegionPtr clipBoxes, pointer data );
4423*4882a593Smuzhiyun	      </programlisting>
4424*4882a593Smuzhiyun	      <blockquote><para>
4425*4882a593Smuzhiyun	  This is the same as <literal remap="tt">GetVideo</literal> except that the
4426*4882a593Smuzhiyun	  driver should place only one frame from the screen into the
4427*4882a593Smuzhiyun	  output stream.
4428*4882a593Smuzhiyun	      </para>
4429*4882a593Smuzhiyun
4430*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4431*4882a593Smuzhiyun
4432*4882a593Smuzhiyun	  <blockquote><para>
4433*4882a593Smuzhiyun	      <programlisting>
4434*4882a593Smuzhiyun    typedef void (* StopVideoFuncPtr)(ScrnInfoPtr pScrn,
4435*4882a593Smuzhiyun                                      pointer data, Bool cleanup);
4436*4882a593Smuzhiyun	      </programlisting>
4437*4882a593Smuzhiyun	      <blockquote><para>
4438*4882a593Smuzhiyun	  This indicates the driver should stop displaying the video.
4439*4882a593Smuzhiyun	  This is used to stop both input and output video.  The
4440*4882a593Smuzhiyun	  <parameter>cleanup</parameter> field indicates that the video is
4441*4882a593Smuzhiyun	  being stopped because the client requested it to stop or
4442*4882a593Smuzhiyun	  because the server is exiting the current VT.  In that case
4443*4882a593Smuzhiyun	  the driver should deallocate any offscreen memory areas (if
4444*4882a593Smuzhiyun	  there are any) being used to put the video to the screen.  If
4445*4882a593Smuzhiyun	  <parameter>cleanup</parameter> is not set, the video is being stopped
4446*4882a593Smuzhiyun	  temporarily due to clipping or moving of the window, etc...
4447*4882a593Smuzhiyun	  and video will likely be restarted soon so the driver should
4448*4882a593Smuzhiyun	  not deallocate any offscreen areas associated with that port.
4449*4882a593Smuzhiyun	      </para>
4450*4882a593Smuzhiyun
4451*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4452*4882a593Smuzhiyun	  <blockquote><para>
4453*4882a593Smuzhiyun	      <programlisting>
4454*4882a593Smuzhiyun    typedef int (* SetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
4455*4882a593Smuzhiyun                                Atom attribute,INT32 value, pointer data);
4456*4882a593Smuzhiyun	      </programlisting>
4457*4882a593Smuzhiyun
4458*4882a593Smuzhiyun	      <programlisting>
4459*4882a593Smuzhiyun    typedef int (* GetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
4460*4882a593Smuzhiyun                                Atom attribute,INT32 *value, pointer data);
4461*4882a593Smuzhiyun	      </programlisting>
4462*4882a593Smuzhiyun	      <blockquote><para>
4463*4882a593Smuzhiyun	  A port may have particular attributes such as hue,
4464*4882a593Smuzhiyun	  saturation, brightness or contrast.  Xv clients set and
4465*4882a593Smuzhiyun	  get these attribute values by sending attribute strings
4466*4882a593Smuzhiyun	  (Atoms) to the server.  Such requests end up at these
4467*4882a593Smuzhiyun	  driver functions.  It is recommended that the driver provide
4468*4882a593Smuzhiyun	  at least the following attributes mentioned in the Xv client
4469*4882a593Smuzhiyun	  library docs:
4470*4882a593Smuzhiyun		<literallayout><constant>
4471*4882a593Smuzhiyun		XV_ENCODING
4472*4882a593Smuzhiyun		XV_HUE
4473*4882a593Smuzhiyun		XV_SATURATION
4474*4882a593Smuzhiyun		XV_BRIGHTNESS
4475*4882a593Smuzhiyun		XV_CONTRAST
4476*4882a593Smuzhiyun		  </constant></literallayout>
4477*4882a593Smuzhiyun	  but the driver may recognize as many atoms as it wishes.  If
4478*4882a593Smuzhiyun	  a requested attribute is unknown by the driver it should return
4479*4882a593Smuzhiyun	  <constant>BadMatch</constant>.  <constant>XV_ENCODING</constant> is the
4480*4882a593Smuzhiyun	  attribute intended to let the client specify which video
4481*4882a593Smuzhiyun	  encoding the particular port should be using (see the description
4482*4882a593Smuzhiyun	  of <structname>XF86VideoEncodingRec</structname> below).  If the
4483*4882a593Smuzhiyun	  requested encoding is unsupported, the driver should return
4484*4882a593Smuzhiyun	  <constant>XvBadEncoding</constant>.  If the value lies outside the
4485*4882a593Smuzhiyun	  advertised range <constant>BadValue</constant> may be returned.
4486*4882a593Smuzhiyun	  <constant>Success</constant> should be returned otherwise.
4487*4882a593Smuzhiyun	      </para>
4488*4882a593Smuzhiyun
4489*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4490*4882a593Smuzhiyun
4491*4882a593Smuzhiyun	  <blockquote><para>
4492*4882a593Smuzhiyun	    <programlisting>
4493*4882a593Smuzhiyun    typedef void (* QueryBestSizeFuncPtr)(ScrnInfoPtr pScrn,
4494*4882a593Smuzhiyun                   Bool motion, short vid_w, short vid_h,
4495*4882a593Smuzhiyun                   short drw_w, short drw_h,
4496*4882a593Smuzhiyun                   unsigned int *p_w, unsigned int *p_h, pointer data);
4497*4882a593Smuzhiyun	    </programlisting>
4498*4882a593Smuzhiyun	    <blockquote><para>
4499*4882a593Smuzhiyun	   <function>QueryBestSize</function> provides the client with a way
4500*4882a593Smuzhiyun	   to query what the destination dimensions would end up being
4501*4882a593Smuzhiyun	   if they were to request that an area
4502*4882a593Smuzhiyun	   <parameter>vid_w</parameter> by <parameter>vid_h</parameter> from the video
4503*4882a593Smuzhiyun	   stream be scaled to rectangle of
4504*4882a593Smuzhiyun	   <parameter>drw_w</parameter> by <parameter>drw_h</parameter> on the screen.
4505*4882a593Smuzhiyun	   Since it is not expected that all hardware will be able to
4506*4882a593Smuzhiyun	   get the target dimensions exactly, it is important that the
4507*4882a593Smuzhiyun	   driver provide this function.
4508*4882a593Smuzhiyun	      </para>
4509*4882a593Smuzhiyun
4510*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4511*4882a593Smuzhiyun
4512*4882a593Smuzhiyun	<blockquote><para>
4513*4882a593Smuzhiyun	    <programlisting>
4514*4882a593Smuzhiyun    typedef  int (* PutImageFuncPtr)( ScrnInfoPtr pScrn,
4515*4882a593Smuzhiyun                   short src_x, short src_y, short drw_x, short drw_y,
4516*4882a593Smuzhiyun                   short src_w, short src_h, short drw_w, short drw_h,
4517*4882a593Smuzhiyun                   int image, char *buf, short width, short height,
4518*4882a593Smuzhiyun                   Bool sync, RegionPtr clipBoxes, pointer data );
4519*4882a593Smuzhiyun	      </programlisting>
4520*4882a593Smuzhiyun	      <blockquote><para>
4521*4882a593Smuzhiyun	  This is similar to <structfield>PutStill</structfield> except that the
4522*4882a593Smuzhiyun	  source of the video is not a port but the data stored in a system
4523*4882a593Smuzhiyun	  memory buffer at <parameter>buf</parameter>.  The data is in the format
4524*4882a593Smuzhiyun	  indicated by the <parameter>image</parameter> descriptor and represents a
4525*4882a593Smuzhiyun	  source of size <parameter>width</parameter> by <parameter>height</parameter>.
4526*4882a593Smuzhiyun	  If <parameter>sync</parameter> is TRUE the driver should not return
4527*4882a593Smuzhiyun	  from this function until it is through reading the data
4528*4882a593Smuzhiyun	  from <parameter>buf</parameter>.  Returning when <parameter>sync</parameter>
4529*4882a593Smuzhiyun	  is TRUE indicates that it is safe for the data at <parameter>buf</parameter>
4530*4882a593Smuzhiyun	  to be replaced, freed, or modified.
4531*4882a593Smuzhiyun	      </para>
4532*4882a593Smuzhiyun
4533*4882a593Smuzhiyun	    </blockquote></para></blockquote>
4534*4882a593Smuzhiyun
4535*4882a593Smuzhiyun	<blockquote><para>
4536*4882a593Smuzhiyun	    <programlisting>
4537*4882a593Smuzhiyun    typedef  int (* QueryImageAttributesFuncPtr)( ScrnInfoPtr pScrn,
4538*4882a593Smuzhiyun                                int image, short *width, short *height,
4539*4882a593Smuzhiyun                                int *pitches, int *offsets);
4540*4882a593Smuzhiyun	    </programlisting>
4541*4882a593Smuzhiyun	    <blockquote><para>
4542*4882a593Smuzhiyun	  This function is called to let the driver specify how data for
4543*4882a593Smuzhiyun	  a particular <parameter>image</parameter> of size <parameter>width</parameter>
4544*4882a593Smuzhiyun	  by <parameter>height</parameter> should be stored.  Sometimes only
4545*4882a593Smuzhiyun	  the size and corrected width and height are needed.  In that
4546*4882a593Smuzhiyun	  case <parameter>pitches</parameter> and <parameter>offsets</parameter> are
4547*4882a593Smuzhiyun	  NULL.  The size of the memory required for the image is returned
4548*4882a593Smuzhiyun	  by this function.  The <parameter>width</parameter> and
4549*4882a593Smuzhiyun	  <parameter>height</parameter> of the requested image can be altered by
4550*4882a593Smuzhiyun	  the driver to reflect format limitations (such as component
4551*4882a593Smuzhiyun	  sampling periods that are larger than one).  If
4552*4882a593Smuzhiyun	  <parameter>pitches</parameter> and <parameter>offsets</parameter> are not NULL,
4553*4882a593Smuzhiyun	  these will be arrays with as many elements in them as there
4554*4882a593Smuzhiyun	  are planes in the <parameter>image</parameter> format.  The driver
4555*4882a593Smuzhiyun	  should specify the pitch (in bytes) of each scanline in the
4556*4882a593Smuzhiyun	  particular plane as well as the offset to that plane (in bytes)
4557*4882a593Smuzhiyun	  from the beginning of the image.
4558*4882a593Smuzhiyun	      </para>
4559*4882a593Smuzhiyun
4560*4882a593Smuzhiyun	  </blockquote></para></blockquote>
4561*4882a593Smuzhiyun    </para>
4562*4882a593Smuzhiyun
4563*4882a593Smuzhiyun    <para>
4564*4882a593SmuzhiyunThe XF86VideoEncodingRec:
4565*4882a593Smuzhiyun
4566*4882a593Smuzhiyun      <blockquote><para>
4567*4882a593Smuzhiyun	  <programlisting>
4568*4882a593Smuzhiyuntypedef struct {
4569*4882a593Smuzhiyun	int id;
4570*4882a593Smuzhiyun	char *name;
4571*4882a593Smuzhiyun	unsigned short width, height;
4572*4882a593Smuzhiyun	XvRationalRec rate;
4573*4882a593Smuzhiyun} XF86VideoEncodingRec, *XF86VideoEncodingPtr;
4574*4882a593Smuzhiyun
4575*4882a593Smuzhiyun	  </programlisting>
4576*4882a593Smuzhiyun	  <blockquote><para>
4577*4882a593Smuzhiyun   The <structname>XF86VideoEncodingRec</structname> specifies what encodings
4578*4882a593Smuzhiyun   the adaptor can support.  Most of this data is just informational
4579*4882a593Smuzhiyun   and for the client's benefit, and is what will be reported by
4580*4882a593Smuzhiyun   <function>XvQueryEncodings</function>.  The <parameter>id</parameter> field is
4581*4882a593Smuzhiyun   expected to be a unique identifier to allow the client to request a
4582*4882a593Smuzhiyun   certain encoding via the <constant>XV_ENCODING</constant> attribute string.
4583*4882a593Smuzhiyun
4584*4882a593Smuzhiyun	    </para>
4585*4882a593Smuzhiyun	  </blockquote></para></blockquote>
4586*4882a593Smuzhiyun    </para>
4587*4882a593Smuzhiyun
4588*4882a593Smuzhiyun    <para>
4589*4882a593SmuzhiyunThe XF86VideoFormatRec:
4590*4882a593Smuzhiyun
4591*4882a593Smuzhiyun      <blockquote><para>
4592*4882a593Smuzhiyun	  <programlisting>
4593*4882a593Smuzhiyuntypedef struct {
4594*4882a593Smuzhiyun	char  depth;
4595*4882a593Smuzhiyun	short class;
4596*4882a593Smuzhiyun} XF86VideoFormatRec, *XF86VideoFormatPtr;
4597*4882a593Smuzhiyun
4598*4882a593Smuzhiyun	  </programlisting>
4599*4882a593Smuzhiyun	  <blockquote><para>
4600*4882a593Smuzhiyun    This specifies what visuals the video is viewable in.
4601*4882a593Smuzhiyun    <parameter>depth</parameter> is the depth of the visual (not bpp).
4602*4882a593Smuzhiyun    <parameter>class</parameter> is the visual class such as
4603*4882a593Smuzhiyun    <constant>TrueColor</constant>, <constant>DirectColor</constant> or
4604*4882a593Smuzhiyun    <constant>PseudoColor</constant>.  Initialization of an adaptor will fail
4605*4882a593Smuzhiyun    if none of the visuals on that screen are supported.
4606*4882a593Smuzhiyun	    </para>
4607*4882a593Smuzhiyun
4608*4882a593Smuzhiyun	  </blockquote></para></blockquote>
4609*4882a593Smuzhiyun    </para>
4610*4882a593Smuzhiyun
4611*4882a593Smuzhiyun    <para>
4612*4882a593SmuzhiyunThe XF86AttributeRec:
4613*4882a593Smuzhiyun
4614*4882a593Smuzhiyun      <blockquote><para>
4615*4882a593Smuzhiyun	  <programlisting>
4616*4882a593Smuzhiyuntypedef struct {
4617*4882a593Smuzhiyun	int   flags;
4618*4882a593Smuzhiyun	int   min_value;
4619*4882a593Smuzhiyun	int   max_value;
4620*4882a593Smuzhiyun	char  *name;
4621*4882a593Smuzhiyun} XF86AttributeListRec, *XF86AttributeListPtr;
4622*4882a593Smuzhiyun
4623*4882a593Smuzhiyun	  </programlisting>
4624*4882a593Smuzhiyun	  <blockquote><para>
4625*4882a593Smuzhiyun   Each adaptor may have an array of these advertising the attributes
4626*4882a593Smuzhiyun   for its ports.  Currently defined flags are <literal remap="tt">XvGettable</literal>
4627*4882a593Smuzhiyun   and <literal remap="tt">XvSettable</literal> which may be OR'd together indicating that
4628*4882a593Smuzhiyun   attribute is <quote>gettable</quote> or <quote>settable</quote> by the client.  The
4629*4882a593Smuzhiyun   <literal remap="tt">min</literal> and <literal remap="tt">max</literal> field specify the valid range
4630*4882a593Smuzhiyun   for the value.  <literal remap="tt">Name</literal> is a text string describing the
4631*4882a593Smuzhiyun   attribute by name.
4632*4882a593Smuzhiyun	    </para>
4633*4882a593Smuzhiyun
4634*4882a593Smuzhiyun	  </blockquote></para></blockquote>
4635*4882a593Smuzhiyun
4636*4882a593Smuzhiyun    </para>
4637*4882a593Smuzhiyun
4638*4882a593Smuzhiyun    <para>
4639*4882a593SmuzhiyunThe XF86ImageRec:
4640*4882a593Smuzhiyun
4641*4882a593Smuzhiyun	<blockquote><para>
4642*4882a593Smuzhiyun	    <programlisting>
4643*4882a593Smuzhiyuntypedef struct {
4644*4882a593Smuzhiyun	int id;
4645*4882a593Smuzhiyun	int type;
4646*4882a593Smuzhiyun	int byte_order;
4647*4882a593Smuzhiyun	char guid[16];
4648*4882a593Smuzhiyun	int bits_per_pixel;
4649*4882a593Smuzhiyun	int format;
4650*4882a593Smuzhiyun	int num_planes;
4651*4882a593Smuzhiyun
4652*4882a593Smuzhiyun	/* for RGB formats */
4653*4882a593Smuzhiyun	int depth;
4654*4882a593Smuzhiyun	unsigned int red_mask;
4655*4882a593Smuzhiyun	unsigned int green_mask;
4656*4882a593Smuzhiyun	unsigned int blue_mask;
4657*4882a593Smuzhiyun
4658*4882a593Smuzhiyun	/* for YUV formats */
4659*4882a593Smuzhiyun	unsigned int y_sample_bits;
4660*4882a593Smuzhiyun	unsigned int u_sample_bits;
4661*4882a593Smuzhiyun	unsigned int v_sample_bits;
4662*4882a593Smuzhiyun	unsigned int horz_y_period;
4663*4882a593Smuzhiyun	unsigned int horz_u_period;
4664*4882a593Smuzhiyun	unsigned int horz_v_period;
4665*4882a593Smuzhiyun	unsigned int vert_y_period;
4666*4882a593Smuzhiyun	unsigned int vert_u_period;
4667*4882a593Smuzhiyun	unsigned int vert_v_period;
4668*4882a593Smuzhiyun	char component_order[32];
4669*4882a593Smuzhiyun	int scanline_order;
4670*4882a593Smuzhiyun} XF86ImageRec, *XF86ImagePtr;
4671*4882a593Smuzhiyun
4672*4882a593Smuzhiyun	    </programlisting>
4673*4882a593Smuzhiyun	    <blockquote><para>
4674*4882a593Smuzhiyun   XF86ImageRec describes how video source data is laid out in memory.
4675*4882a593Smuzhiyun   The fields are as follows:
4676*4882a593Smuzhiyun
4677*4882a593Smuzhiyun		<variablelist>
4678*4882a593Smuzhiyun		  <varlistentry>
4679*4882a593Smuzhiyun		    <term><structfield>id</structfield></term>
4680*4882a593Smuzhiyun		    <listitem><para>
4681*4882a593Smuzhiyun	This is a unique descriptor for the format.  It is often good to
4682*4882a593Smuzhiyun        set this value to the FOURCC for the format when applicable.
4683*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4684*4882a593Smuzhiyun
4685*4882a593Smuzhiyun		  <varlistentry>
4686*4882a593Smuzhiyun		    <term><structfield>type</structfield></term>
4687*4882a593Smuzhiyun		    <listitem><para>
4688*4882a593Smuzhiyun	This is <constant>XvRGB</constant> or <constant>XvYUV</constant>.
4689*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4690*4882a593Smuzhiyun
4691*4882a593Smuzhiyun		  <varlistentry>
4692*4882a593Smuzhiyun		    <term><structfield>byte_order</structfield></term>
4693*4882a593Smuzhiyun		    <listitem><para>
4694*4882a593Smuzhiyun	This is <constant>LSBFirst</constant> or <constant>MSBFirst</constant>.
4695*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4696*4882a593Smuzhiyun
4697*4882a593Smuzhiyun		  <varlistentry>
4698*4882a593Smuzhiyun		    <term><structfield>guid</structfield></term>
4699*4882a593Smuzhiyun		    <listitem><para>
4700*4882a593Smuzhiyun	This is the Globally Unique IDentifier for the format.  When
4701*4882a593Smuzhiyun	not applicable, all characters should be NULL.
4702*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4703*4882a593Smuzhiyun
4704*4882a593Smuzhiyun		  <varlistentry>
4705*4882a593Smuzhiyun		    <term><structfield>bits_per_pixel</structfield></term>
4706*4882a593Smuzhiyun		    <listitem><para>
4707*4882a593Smuzhiyun	The number of bits taken up (but not necessarily used) by each
4708*4882a593Smuzhiyun	pixel.  Note that for some planar formats which have fractional
4709*4882a593Smuzhiyun	bits per pixel (such as IF09) this number may be rounded _down_.
4710*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4711*4882a593Smuzhiyun
4712*4882a593Smuzhiyun		  <varlistentry>
4713*4882a593Smuzhiyun		    <term><structfield>format</structfield></term>
4714*4882a593Smuzhiyun		    <listitem><para>
4715*4882a593Smuzhiyun	This is <constant>XvPlanar</constant> or <constant>XvPacked</constant>.
4716*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4717*4882a593Smuzhiyun
4718*4882a593Smuzhiyun		  <varlistentry>
4719*4882a593Smuzhiyun		    <term><structfield>num_planes</structfield></term>
4720*4882a593Smuzhiyun		    <listitem><para>
4721*4882a593Smuzhiyun	The number of planes in planar formats.  This should be set to
4722*4882a593Smuzhiyun	one for packed formats.
4723*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4724*4882a593Smuzhiyun
4725*4882a593Smuzhiyun		  <varlistentry>
4726*4882a593Smuzhiyun		    <term><structfield>depth</structfield></term>
4727*4882a593Smuzhiyun		    <listitem><para>
4728*4882a593Smuzhiyun	The significant bits per pixel in RGB formats (analgous to the
4729*4882a593Smuzhiyun	depth of a pixmap format).
4730*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4731*4882a593Smuzhiyun
4732*4882a593Smuzhiyun		  <varlistentry>
4733*4882a593Smuzhiyun		    <term><structfield>red_mask</structfield></term>
4734*4882a593Smuzhiyun		    <term><structfield>green_mask</structfield></term>
4735*4882a593Smuzhiyun		    <term><structfield>blue_mask</structfield></term>
4736*4882a593Smuzhiyun		    <listitem><para>
4737*4882a593Smuzhiyun	The red, green and blue bitmasks for packed RGB formats.
4738*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4739*4882a593Smuzhiyun
4740*4882a593Smuzhiyun		  <varlistentry>
4741*4882a593Smuzhiyun		    <term><structfield>y_sample_bits</structfield></term>
4742*4882a593Smuzhiyun		    <term><structfield>u_sample_bits</structfield></term>
4743*4882a593Smuzhiyun		    <term><structfield>v_sample_bits</structfield></term>
4744*4882a593Smuzhiyun		    <listitem><para>
4745*4882a593Smuzhiyun	The y, u and v sample sizes (in bits).
4746*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4747*4882a593Smuzhiyun
4748*4882a593Smuzhiyun		  <varlistentry>
4749*4882a593Smuzhiyun		    <term><structfield>horz_y_period</structfield></term>
4750*4882a593Smuzhiyun		    <term><structfield>horz_u_period</structfield></term>
4751*4882a593Smuzhiyun		    <term><structfield>horz_v_period</structfield></term>
4752*4882a593Smuzhiyun		    <listitem><para>
4753*4882a593Smuzhiyun	The y, u and v sampling periods in the horizontal direction.
4754*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4755*4882a593Smuzhiyun
4756*4882a593Smuzhiyun		  <varlistentry>
4757*4882a593Smuzhiyun		    <term><structfield>vert_y_period</structfield></term>
4758*4882a593Smuzhiyun		    <term><structfield>vert_u_period</structfield></term>
4759*4882a593Smuzhiyun		    <term><structfield>vert_v_period</structfield></term>
4760*4882a593Smuzhiyun		    <listitem><para>
4761*4882a593Smuzhiyun	The y, u and v sampling periods in the vertical direction.
4762*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4763*4882a593Smuzhiyun
4764*4882a593Smuzhiyun		  <varlistentry>
4765*4882a593Smuzhiyun		    <term><structfield>component_order</structfield></term>
4766*4882a593Smuzhiyun		    <listitem><para>
4767*4882a593Smuzhiyun	Uppercase ascii characters representing the order that
4768*4882a593Smuzhiyun	samples are stored within packed formats.  For planar formats
4769*4882a593Smuzhiyun	this represents the ordering of the planes.  Unused characters
4770*4882a593Smuzhiyun	in the 32 byte string should be set to NULL.
4771*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4772*4882a593Smuzhiyun
4773*4882a593Smuzhiyun		  <varlistentry>
4774*4882a593Smuzhiyun		    <term><structfield>scanline_order</structfield></term>
4775*4882a593Smuzhiyun		    <listitem><para>
4776*4882a593Smuzhiyun	This is <constant>XvTopToBottom</constant> or <constant>XvBottomToTop</constant>.
4777*4882a593Smuzhiyun		      </para></listitem></varlistentry>
4778*4882a593Smuzhiyun
4779*4882a593Smuzhiyun		  </variablelist>
4780*4882a593Smuzhiyun	    </para>
4781*4882a593Smuzhiyun
4782*4882a593Smuzhiyun	    <para>
4783*4882a593Smuzhiyun  Since some formats (particular some planar YUV formats) may not
4784*4882a593Smuzhiyunbe completely defined by the parameters above, the guid, when
4785*4882a593Smuzhiyunavailable, should provide the most accurate description of the
4786*4882a593Smuzhiyunformat.
4787*4882a593Smuzhiyun	    </para>
4788*4882a593Smuzhiyun
4789*4882a593Smuzhiyun	  </blockquote></para></blockquote>
4790*4882a593Smuzhiyun    </para>
4791*4882a593Smuzhiyun  </sect1>
4792*4882a593Smuzhiyun
4793*4882a593Smuzhiyun  <sect1>
4794*4882a593Smuzhiyun    <title>The Loader</title>
4795*4882a593Smuzhiyun
4796*4882a593Smuzhiyun    <para>
4797*4882a593SmuzhiyunThis section describes the interfaces to the module loader.  The loader
4798*4882a593Smuzhiyuninterfaces can be divided into two groups: those that are only available to
4799*4882a593Smuzhiyunthe XFree86 common layer, and those that are also available to modules.
4800*4882a593Smuzhiyun    </para>
4801*4882a593Smuzhiyun
4802*4882a593Smuzhiyun    <sect2>
4803*4882a593Smuzhiyun      <title>Loader Overview</title>
4804*4882a593Smuzhiyun
4805*4882a593Smuzhiyun      <para>
4806*4882a593SmuzhiyunThe loader is capable of loading modules in a range of object formats,
4807*4882a593Smuzhiyunand knowledge of these formats is built in to the loader.  Knowledge of
4808*4882a593Smuzhiyunnew object formats can be added to the loader in a straightforward
4809*4882a593Smuzhiyunmanner.  This makes it possible to provide OS-independent modules (for
4810*4882a593Smuzhiyuna given CPU architecture type).  In addition to this, the loader can
4811*4882a593Smuzhiyunload modules via the OS-provided <function>dlopen(3)</function> service where
4812*4882a593Smuzhiyunavailable.  Such modules are not platform independent, and the semantics
4813*4882a593Smuzhiyunof <function>dlopen()</function> on most systems results in significant
4814*4882a593Smuzhiyunlimitations in the use of modules of this type.  Support for
4815*4882a593Smuzhiyun<function>dlopen()</function> modules in the loader is primarily for
4816*4882a593Smuzhiyunexperimental and development purposes.
4817*4882a593Smuzhiyun      </para>
4818*4882a593Smuzhiyun
4819*4882a593Smuzhiyun      <para>
4820*4882a593SmuzhiyunSymbols exported by the loader (on behalf of the core X server) to
4821*4882a593Smuzhiyunmodules are determined at compile time.  Only those symbols explicitly
4822*4882a593Smuzhiyunexported are available to modules.  All external symbols of loaded
4823*4882a593Smuzhiyunmodules are exported to other modules, and to the core X server.  The
4824*4882a593Smuzhiyunloader can be requested to check for unresolved symbols at any time,
4825*4882a593Smuzhiyunand the action to be taken for unresolved symbols can be controlled by
4826*4882a593Smuzhiyunthe caller of the loader.  Typically the caller identifies which symbols
4827*4882a593Smuzhiyuncan safely remain unresolved and which cannot.
4828*4882a593Smuzhiyun      </para>
4829*4882a593Smuzhiyun
4830*4882a593Smuzhiyun      <para>
4831*4882a593SmuzhiyunNOTE:  Now that ISO-C allows pointers to functions and pointers to data to
4832*4882a593Smuzhiyunhave different internal representations, some of the following interfaces
4833*4882a593Smuzhiyunwill need to be revisited.
4834*4882a593Smuzhiyun      </para>
4835*4882a593Smuzhiyun    </sect2>
4836*4882a593Smuzhiyun
4837*4882a593Smuzhiyun    <sect2>
4838*4882a593Smuzhiyun      <title>Semi-private Loader Interface</title>
4839*4882a593Smuzhiyun
4840*4882a593Smuzhiyun      <para>
4841*4882a593SmuzhiyunThe following is the semi-private loader interface that is available to the
4842*4882a593SmuzhiyunXFree86 common layer.
4843*4882a593Smuzhiyun      </para>
4844*4882a593Smuzhiyun
4845*4882a593Smuzhiyun      <blockquote><para>
4846*4882a593Smuzhiyun	  <programlisting>
4847*4882a593Smuzhiyun    void LoaderInit(void);
4848*4882a593Smuzhiyun	  </programlisting>
4849*4882a593Smuzhiyun	  <blockquote><para>
4850*4882a593Smuzhiyun    The <function>LoaderInit()</function> function initialises the loader,
4851*4882a593Smuzhiyun    and it must be called once before calling any other loader functions.
4852*4882a593Smuzhiyun    This function initialises the tables of exported symbols, and anything
4853*4882a593Smuzhiyun    else that might need to be initialised.
4854*4882a593Smuzhiyun	    </para>
4855*4882a593Smuzhiyun
4856*4882a593Smuzhiyun	  </blockquote></para></blockquote>
4857*4882a593Smuzhiyun
4858*4882a593Smuzhiyun      <blockquote><para>
4859*4882a593Smuzhiyun	  <programlisting>
4860*4882a593Smuzhiyun    void LoaderSetPath(const char *path);
4861*4882a593Smuzhiyun	  </programlisting>
4862*4882a593Smuzhiyun	  <blockquote><para>
4863*4882a593Smuzhiyun    The <function>LoaderSetPath()</function> function initialises a default
4864*4882a593Smuzhiyun    module search path.  This must be called if calls to other functions
4865*4882a593Smuzhiyun    are to be made without explicitly specifying a module search path.
4866*4882a593Smuzhiyun    The search path <parameter>path</parameter> must be a string of one or more
4867*4882a593Smuzhiyun    comma separated absolute paths.  Modules are expected to be located
4868*4882a593Smuzhiyun    below these paths, possibly in subdirectories of these paths.
4869*4882a593Smuzhiyun	    </para>
4870*4882a593Smuzhiyun
4871*4882a593Smuzhiyun	  </blockquote></para></blockquote>
4872*4882a593Smuzhiyun
4873*4882a593Smuzhiyun      <blockquote><para>
4874*4882a593Smuzhiyun	  <programlisting>
4875*4882a593Smuzhiyun    pointer LoadModule(const char *module, pointer options,
4876*4882a593Smuzhiyun                       const XF86ModReqInfo * modreq, int *errmaj);
4877*4882a593Smuzhiyun	  </programlisting>
4878*4882a593Smuzhiyun	  <blockquote><para>
4879*4882a593Smuzhiyun    The <function>LoadModule()</function> function loads the module called
4880*4882a593Smuzhiyun    <parameter>module</parameter>.  The return value is a module handle, and
4881*4882a593Smuzhiyun    may be used in future calls to the loader that require a reference
4882*4882a593Smuzhiyun    to a loaded module.  The module name <parameter>module</parameter> is
4883*4882a593Smuzhiyun    normally the module's canonical name, which doesn't contain any
4884*4882a593Smuzhiyun    directory path information, or any object/library file prefixes of
4885*4882a593Smuzhiyun    suffixes.  Currently a full pathname and/or filename is also accepted.
4886*4882a593Smuzhiyun    This might change.  The other parameters are:
4887*4882a593Smuzhiyun
4888*4882a593Smuzhiyun	      <variablelist>
4889*4882a593Smuzhiyun
4890*4882a593Smuzhiyun		<varlistentry>
4891*4882a593Smuzhiyun		  <term><parameter>options</parameter></term>
4892*4882a593Smuzhiyun		  <listitem><para>
4893*4882a593Smuzhiyun		  An optional parameter that is passed to the newly
4894*4882a593Smuzhiyun		  loaded module's <literal remap="tt">SetupProc</literal> function
4895*4882a593Smuzhiyun		  (if it has one).  This argument is normally a
4896*4882a593Smuzhiyun		  <constant>NULL</constant> terminated list of
4897*4882a593Smuzhiyun		  <structname>Options</structname>, and must be interpreted that
4898*4882a593Smuzhiyun		  way by modules loaded directly by the XFree86 common
4899*4882a593Smuzhiyun		  layer.  However, it may be used for application-specific
4900*4882a593Smuzhiyun		  parameter passing in other situations.
4901*4882a593Smuzhiyun		    </para></listitem></varlistentry>
4902*4882a593Smuzhiyun
4903*4882a593Smuzhiyun
4904*4882a593Smuzhiyun		<varlistentry>
4905*4882a593Smuzhiyun		  <term><parameter>modreq</parameter></term>
4906*4882a593Smuzhiyun		  <listitem><para>
4907*4882a593Smuzhiyun		  An optional <structname>XF86ModReqInfo*</structname> containing
4908*4882a593Smuzhiyun		  version/ABI/vendor information to requirements to
4909*4882a593Smuzhiyun		  check the newly loaded module against.  The main
4910*4882a593Smuzhiyun		  purpose of this is to allow the loader to verify that
4911*4882a593Smuzhiyun		  a module of the correct type/version before running
4912*4882a593Smuzhiyun		  its <function>SetupProc</function> function.
4913*4882a593Smuzhiyun		      </para>
4914*4882a593Smuzhiyun
4915*4882a593Smuzhiyun		    <para>
4916*4882a593Smuzhiyun		  The <literal remap="tt">XF86ModReqInfo</literal> struct is defined
4917*4882a593Smuzhiyun		  as follows:
4918*4882a593Smuzhiyun		      <programlisting>
4919*4882a593Smuzhiyuntypedef struct {
4920*4882a593Smuzhiyun	CARD8        majorversion;
4921*4882a593Smuzhiyun	CARD8        minorversion;
4922*4882a593Smuzhiyun	CARD16       patchlevel;
4923*4882a593Smuzhiyun	const char * abiclass;
4924*4882a593Smuzhiyun	CARD32       abiversion;
4925*4882a593Smuzhiyun	const char * moduleclass;
4926*4882a593Smuzhiyun} XF86ModReqInfo;
4927*4882a593Smuzhiyun			</programlisting>
4928*4882a593Smuzhiyun
4929*4882a593Smuzhiyun		  The information here is compared against the equivalent
4930*4882a593Smuzhiyun		  information in the module's
4931*4882a593Smuzhiyun		  <structname>XF86ModuleVersionInfo</structname> record (which
4932*4882a593Smuzhiyun		  is described below).  The values in comments above
4933*4882a593Smuzhiyun		  indicate <quote>don't care</quote> settings for each of the fields.
4934*4882a593Smuzhiyun		  The comparisons made are as follows:
4935*4882a593Smuzhiyun
4936*4882a593Smuzhiyun		      <variablelist>
4937*4882a593Smuzhiyun			<varlistentry>
4938*4882a593Smuzhiyun			  <term><structfield>majorversion</structfield></term>
4939*4882a593Smuzhiyun			  <listitem><para>
4940*4882a593Smuzhiyun				   Must match the module's majorversion
4941*4882a593Smuzhiyun				   exactly.
4942*4882a593Smuzhiyun			    </para></listitem></varlistentry>
4943*4882a593Smuzhiyun
4944*4882a593Smuzhiyun			<varlistentry>
4945*4882a593Smuzhiyun			  <term><structfield>minorversion</structfield></term>
4946*4882a593Smuzhiyun			  <listitem><para>
4947*4882a593Smuzhiyun				   The module's minor version must be
4948*4882a593Smuzhiyun				   no less than this value.  This
4949*4882a593Smuzhiyun				   comparison is only made if
4950*4882a593Smuzhiyun				   <structfield>majorversion</structfield>
4951*4882a593Smuzhiyun                                   matches.
4952*4882a593Smuzhiyun			    </para></listitem></varlistentry>
4953*4882a593Smuzhiyun
4954*4882a593Smuzhiyun			<varlistentry>
4955*4882a593Smuzhiyun			  <term><structfield>patchlevel</structfield></term>
4956*4882a593Smuzhiyun			  <listitem><para>
4957*4882a593Smuzhiyun				   The module's patchlevel must be no
4958*4882a593Smuzhiyun				   less than this value.  This comparison
4959*4882a593Smuzhiyun				   is only made if
4960*4882a593Smuzhiyun				   <structfield>minorversion</structfield>
4961*4882a593Smuzhiyun				   matches.
4962*4882a593Smuzhiyun			    </para></listitem></varlistentry>
4963*4882a593Smuzhiyun
4964*4882a593Smuzhiyun			<varlistentry>
4965*4882a593Smuzhiyun			  <term><structfield>abiclass</structfield></term>
4966*4882a593Smuzhiyun			  <listitem><para>
4967*4882a593Smuzhiyun				   String must match the module's abiclass
4968*4882a593Smuzhiyun				   string.
4969*4882a593Smuzhiyun			    </para></listitem></varlistentry>
4970*4882a593Smuzhiyun
4971*4882a593Smuzhiyun			<varlistentry>
4972*4882a593Smuzhiyun			  <term><structfield>abiversion</structfield></term>
4973*4882a593Smuzhiyun			  <listitem><para>
4974*4882a593Smuzhiyun				   Must be consistent with the module's
4975*4882a593Smuzhiyun				   abiversion (major equal, minor no
4976*4882a593Smuzhiyun				   older).
4977*4882a593Smuzhiyun			    </para></listitem></varlistentry>
4978*4882a593Smuzhiyun
4979*4882a593Smuzhiyun			<varlistentry>
4980*4882a593Smuzhiyun			  <term><structfield>moduleclass</structfield></term>
4981*4882a593Smuzhiyun			  <listitem><para>
4982*4882a593Smuzhiyun				   String must match the module's
4983*4882a593Smuzhiyun				   moduleclass string.
4984*4882a593Smuzhiyun			    </para></listitem></varlistentry>
4985*4882a593Smuzhiyun
4986*4882a593Smuzhiyun		      </variablelist>
4987*4882a593Smuzhiyun		    </para></listitem></varlistentry>
4988*4882a593Smuzhiyun
4989*4882a593Smuzhiyun		<varlistentry>
4990*4882a593Smuzhiyun		  <term><parameter>errmaj</parameter></term>
4991*4882a593Smuzhiyun		  <listitem><para>
4992*4882a593Smuzhiyun		  An optional pointer to a variable holding the major
4993*4882a593Smuzhiyun		  part or the error code.  When provided,
4994*4882a593Smuzhiyun		  <parameter>*errmaj</parameter> is filled in when
4995*4882a593Smuzhiyun		  <function>LoadModule()</function> fails.
4996*4882a593Smuzhiyun		    </para></listitem></varlistentry>
4997*4882a593Smuzhiyun
4998*4882a593Smuzhiyun	      </variablelist>
4999*4882a593Smuzhiyun
5000*4882a593Smuzhiyun	    </para></blockquote>
5001*4882a593Smuzhiyun	</para></blockquote>
5002*4882a593Smuzhiyun
5003*4882a593Smuzhiyun      <blockquote><para>
5004*4882a593Smuzhiyun	  <programlisting>
5005*4882a593Smuzhiyun    void UnloadModule(pointer mod);
5006*4882a593Smuzhiyun	  </programlisting>
5007*4882a593Smuzhiyun	  <blockquote><para>
5008*4882a593Smuzhiyun    This function unloads the module referred to by the handle mod.
5009*4882a593Smuzhiyun    All child modules are also unloaded recursively.  This function must
5010*4882a593Smuzhiyun    not be used to directly unload modules that are child modules (i.e.,
5011*4882a593Smuzhiyun    those that have been loaded with the <function>LoadSubModule()</function>
5012*4882a593Smuzhiyun    described below).
5013*4882a593Smuzhiyun	    </para>
5014*4882a593Smuzhiyun
5015*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5016*4882a593Smuzhiyun    </sect2>
5017*4882a593Smuzhiyun
5018*4882a593Smuzhiyun    <sect2>
5019*4882a593Smuzhiyun      <title>Module Requirements</title>
5020*4882a593Smuzhiyun
5021*4882a593Smuzhiyun      <para>
5022*4882a593SmuzhiyunModules must provide information about themselves to the loader, and
5023*4882a593Smuzhiyunmay optionally provide entry points for "setup" and "teardown" functions
5024*4882a593Smuzhiyun(those two functions are referred to here as <function>SetupProc</function>
5025*4882a593Smuzhiyunand <function>TearDownProc</function>).
5026*4882a593Smuzhiyun      </para>
5027*4882a593Smuzhiyun
5028*4882a593Smuzhiyun      <para>
5029*4882a593SmuzhiyunThe module information is contained in the
5030*4882a593Smuzhiyun<structname>XF86ModuleVersionInfo</structname> struct, which is defined as follows:
5031*4882a593Smuzhiyun
5032*4882a593Smuzhiyun	<programlisting>
5033*4882a593Smuzhiyuntypedef struct {
5034*4882a593Smuzhiyun    const char * modname;      /* name of module, e.g. "foo" */
5035*4882a593Smuzhiyun    const char * vendor;       /* vendor specific string */
5036*4882a593Smuzhiyun    CARD32       _modinfo1_;   /* constant MODINFOSTRING1/2 to find */
5037*4882a593Smuzhiyun    CARD32       _modinfo2_;   /* infoarea with a binary editor/sign tool */
5038*4882a593Smuzhiyun    CARD32       xf86version;  /* contains XF86_VERSION_CURRENT */
5039*4882a593Smuzhiyun    CARD8        majorversion; /* module-specific major version */
5040*4882a593Smuzhiyun    CARD8        minorversion; /* module-specific minor version */
5041*4882a593Smuzhiyun    CARD16       patchlevel;   /* module-specific patch level */
5042*4882a593Smuzhiyun    const char * abiclass;     /* ABI class that the module uses */
5043*4882a593Smuzhiyun    CARD32       abiversion;   /* ABI version */
5044*4882a593Smuzhiyun    const char * moduleclass;  /* module class */
5045*4882a593Smuzhiyun    CARD32       checksum[4];  /* contains a digital signature of the */
5046*4882a593Smuzhiyun                               /* version info structure */
5047*4882a593Smuzhiyun} XF86ModuleVersionInfo;
5048*4882a593Smuzhiyun	</programlisting>
5049*4882a593Smuzhiyun
5050*4882a593SmuzhiyunThe fields are used as follows:
5051*4882a593Smuzhiyun
5052*4882a593Smuzhiyun	<variablelist>
5053*4882a593Smuzhiyun	  <varlistentry>
5054*4882a593Smuzhiyun	    <term><structfield>modname</structfield></term>
5055*4882a593Smuzhiyun	    <listitem><para>
5056*4882a593Smuzhiyun		The module's name.  This field is currently only for
5057*4882a593Smuzhiyun		informational purposes, but the loader may be modified
5058*4882a593Smuzhiyun		in future to require it to match the module's canonical
5059*4882a593Smuzhiyun                name.
5060*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5061*4882a593Smuzhiyun
5062*4882a593Smuzhiyun
5063*4882a593Smuzhiyun	  <varlistentry>
5064*4882a593Smuzhiyun	    <term><structfield>vendor</structfield></term>
5065*4882a593Smuzhiyun	    <listitem><para>
5066*4882a593Smuzhiyun		The module vendor.  This field is for informational purposes
5067*4882a593Smuzhiyun                only.
5068*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5069*4882a593Smuzhiyun
5070*4882a593Smuzhiyun
5071*4882a593Smuzhiyun	  <varlistentry>
5072*4882a593Smuzhiyun	    <term><structfield>_modinfo1_</structfield></term>
5073*4882a593Smuzhiyun	    <listitem><para>
5074*4882a593Smuzhiyun		This field holds the first part of a signature that can
5075*4882a593Smuzhiyun                be used to locate this structure in the binary.  It should
5076*4882a593Smuzhiyun		always be initialised to <constant>MODINFOSTRING1</constant>.
5077*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5078*4882a593Smuzhiyun
5079*4882a593Smuzhiyun
5080*4882a593Smuzhiyun	  <varlistentry>
5081*4882a593Smuzhiyun	    <term><structfield>_modinfo2_</structfield></term>
5082*4882a593Smuzhiyun	    <listitem><para>
5083*4882a593Smuzhiyun		This field holds the second part of a signature that can
5084*4882a593Smuzhiyun                be used to locate this structure in the binary.  It should
5085*4882a593Smuzhiyun		always be initialised to <constant>MODINFOSTRING2</constant>.
5086*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5087*4882a593Smuzhiyun
5088*4882a593Smuzhiyun
5089*4882a593Smuzhiyun	  <varlistentry>
5090*4882a593Smuzhiyun	    <term><structfield>xf86version</structfield></term>
5091*4882a593Smuzhiyun	    <listitem><para>
5092*4882a593Smuzhiyun		The XFree86 version against which the module was compiled.
5093*4882a593Smuzhiyun                This is mostly for informational/diagnostic purposes.  It
5094*4882a593Smuzhiyun		should be initialised to <constant>XF86_VERSION_CURRENT</constant>, which is
5095*4882a593Smuzhiyun		defined in <filename>xf86Version.h</filename>.
5096*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5097*4882a593Smuzhiyun
5098*4882a593Smuzhiyun
5099*4882a593Smuzhiyun	  <varlistentry>
5100*4882a593Smuzhiyun	    <term><structfield>majorversion</structfield></term>
5101*4882a593Smuzhiyun	    <listitem><para>
5102*4882a593Smuzhiyun		The module-specific major version.  For modules where this
5103*4882a593Smuzhiyun		version is used for more than simply informational
5104*4882a593Smuzhiyun		purposes, the major version should only change (be
5105*4882a593Smuzhiyun		incremented) when ABI incompatibilities are introduced,
5106*4882a593Smuzhiyun		or ABI components are removed.
5107*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5108*4882a593Smuzhiyun
5109*4882a593Smuzhiyun
5110*4882a593Smuzhiyun	  <varlistentry>
5111*4882a593Smuzhiyun	    <term><structfield>minorversion</structfield></term>
5112*4882a593Smuzhiyun	    <listitem><para>
5113*4882a593Smuzhiyun		The module-specific minor version.  For modules where this
5114*4882a593Smuzhiyun		version is used for more than simply informational
5115*4882a593Smuzhiyun		purposes, the minor version should only change (be
5116*4882a593Smuzhiyun		incremented) when ABI additions are made in a backward
5117*4882a593Smuzhiyun		compatible way.  It should be reset to zero when the major
5118*4882a593Smuzhiyun                version is increased.
5119*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5120*4882a593Smuzhiyun
5121*4882a593Smuzhiyun
5122*4882a593Smuzhiyun	  <varlistentry>
5123*4882a593Smuzhiyun	    <term><structfield>patchlevel</structfield></term>
5124*4882a593Smuzhiyun	    <listitem><para>
5125*4882a593Smuzhiyun		The module-specific patch level.  The patch level should
5126*4882a593Smuzhiyun		increase with new revisions of the module where there
5127*4882a593Smuzhiyun		are no ABI changes, and it should be reset to zero when
5128*4882a593Smuzhiyun		the minor version is increased.
5129*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5130*4882a593Smuzhiyun
5131*4882a593Smuzhiyun
5132*4882a593Smuzhiyun	  <varlistentry>
5133*4882a593Smuzhiyun	    <term><structfield>abiclass</structfield></term>
5134*4882a593Smuzhiyun	    <listitem><para>
5135*4882a593Smuzhiyun		The ABI class that the module requires.  The class is
5136*4882a593Smuzhiyun                specified as a string for easy extensibility.  It should
5137*4882a593Smuzhiyun		indicate which (if any) of the X server's built-in ABI
5138*4882a593Smuzhiyun		classes that the module relies on, or a third-party ABI
5139*4882a593Smuzhiyun                if appropriate.  Built-in ABI classes currently defined are:
5140*4882a593Smuzhiyun
5141*4882a593Smuzhiyun		<variablelist>
5142*4882a593Smuzhiyun		  <varlistentry>
5143*4882a593Smuzhiyun		    <term><constant>ABI_CLASS_NONE</constant></term>
5144*4882a593Smuzhiyun		    <listitem><para>no class
5145*4882a593Smuzhiyun		      </para></listitem></varlistentry>
5146*4882a593Smuzhiyun		  <varlistentry>
5147*4882a593Smuzhiyun		    <term><constant>ABI_CLASS_ANSIC</constant></term>
5148*4882a593Smuzhiyun		    <listitem><para>only requires the ANSI C interfaces
5149*4882a593Smuzhiyun		      </para></listitem></varlistentry>
5150*4882a593Smuzhiyun		  <varlistentry>
5151*4882a593Smuzhiyun		    <term><constant>ABI_CLASS_VIDEODRV</constant></term>
5152*4882a593Smuzhiyun		    <listitem><para>requires the video driver ABI
5153*4882a593Smuzhiyun		      </para></listitem></varlistentry>
5154*4882a593Smuzhiyun		  <varlistentry>
5155*4882a593Smuzhiyun		    <term><constant>ABI_CLASS_XINPUT</constant></term>
5156*4882a593Smuzhiyun		    <listitem><para>requires the XInput driver ABI
5157*4882a593Smuzhiyun		      </para></listitem></varlistentry>
5158*4882a593Smuzhiyun		  <varlistentry>
5159*4882a593Smuzhiyun		    <term><constant>ABI_CLASS_EXTENSION</constant></term>
5160*4882a593Smuzhiyun		    <listitem><para>requires the extension module ABI
5161*4882a593Smuzhiyun		      </para></listitem></varlistentry>
5162*4882a593Smuzhiyun		</variablelist>
5163*4882a593Smuzhiyun
5164*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5165*4882a593Smuzhiyun
5166*4882a593Smuzhiyun	  <varlistentry>
5167*4882a593Smuzhiyun	    <term><structfield>abiversion</structfield></term>
5168*4882a593Smuzhiyun	    <listitem><para>
5169*4882a593Smuzhiyun		The version of abiclass that the module requires.  The
5170*4882a593Smuzhiyun		version consists of major and minor components.  The
5171*4882a593Smuzhiyun		major version must match and the minor version must be
5172*4882a593Smuzhiyun		no newer than that provided by the server or parent
5173*4882a593Smuzhiyun		module.  Version identifiers for the built-in classes
5174*4882a593Smuzhiyun		currently defined are:
5175*4882a593Smuzhiyun
5176*4882a593Smuzhiyun		<literallayout><constant>
5177*4882a593Smuzhiyun                   ABI_ANSIC_VERSION
5178*4882a593Smuzhiyun                   ABI_VIDEODRV_VERSION
5179*4882a593Smuzhiyun                   ABI_XINPUT_VERSION
5180*4882a593Smuzhiyun                   ABI_EXTENSION_VERSION
5181*4882a593Smuzhiyun		  </constant></literallayout>
5182*4882a593Smuzhiyun
5183*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5184*4882a593Smuzhiyun
5185*4882a593Smuzhiyun	  <varlistentry>
5186*4882a593Smuzhiyun	    <term><structfield>moduleclass</structfield></term>
5187*4882a593Smuzhiyun	    <listitem><para>
5188*4882a593Smuzhiyun		This is similar to the abiclass field, except that it
5189*4882a593Smuzhiyun		defines the type of module rather than the ABI it
5190*4882a593Smuzhiyun		requires.  For example, although all video drivers require
5191*4882a593Smuzhiyun		the video driver ABI, not all modules that require the
5192*4882a593Smuzhiyun		video driver ABI are video drivers.  This distinction
5193*4882a593Smuzhiyun		can be made with the moduleclass.  Currently pre-defined
5194*4882a593Smuzhiyun		module classes are:
5195*4882a593Smuzhiyun
5196*4882a593Smuzhiyun		<literallayout><constant>
5197*4882a593Smuzhiyun                   MOD_CLASS_NONE
5198*4882a593Smuzhiyun                   MOD_CLASS_VIDEODRV
5199*4882a593Smuzhiyun                   MOD_CLASS_XINPUT
5200*4882a593Smuzhiyun                   MOD_CLASS_EXTENSION
5201*4882a593Smuzhiyun		  </constant></literallayout>
5202*4882a593Smuzhiyun
5203*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5204*4882a593Smuzhiyun
5205*4882a593Smuzhiyun	  <varlistentry>
5206*4882a593Smuzhiyun	    <term><structfield>checksum</structfield></term>
5207*4882a593Smuzhiyun	    <listitem><para>
5208*4882a593Smuzhiyun		Not currently used.
5209*4882a593Smuzhiyun	      </para></listitem></varlistentry>
5210*4882a593Smuzhiyun
5211*4882a593Smuzhiyun	</variablelist>
5212*4882a593Smuzhiyun      </para>
5213*4882a593Smuzhiyun
5214*4882a593Smuzhiyun      <para>
5215*4882a593SmuzhiyunThe module version information, and the optional <function>SetupProc</function>
5216*4882a593Smuzhiyunand <function>TearDownProc</function> entry points are found by the loader
5217*4882a593Smuzhiyunby locating a data object in the module called "modnameModuleData",
5218*4882a593Smuzhiyunwhere "modname" is the canonical name of the module.  Modules must
5219*4882a593Smuzhiyuncontain such a data object, and it must be declared with global scope,
5220*4882a593Smuzhiyunbe compile-time initialised, and is of the following type:
5221*4882a593Smuzhiyun
5222*4882a593Smuzhiyun	<programlisting>
5223*4882a593Smuzhiyuntypedef struct {
5224*4882a593Smuzhiyun    XF86ModuleVersionInfo *     vers;
5225*4882a593Smuzhiyun    ModuleSetupProc             setup;
5226*4882a593Smuzhiyun    ModuleTearDownProc          teardown;
5227*4882a593Smuzhiyun} XF86ModuleData;
5228*4882a593Smuzhiyun	</programlisting>
5229*4882a593Smuzhiyun      </para>
5230*4882a593Smuzhiyun
5231*4882a593Smuzhiyun      <para>
5232*4882a593SmuzhiyunThe vers parameter must be initialised to a pointer to a correctly
5233*4882a593Smuzhiyuninitialised <structname>XF86ModuleVersionInfo</structname> struct.  The other
5234*4882a593Smuzhiyuntwo parameter are optional, and should be initialised to
5235*4882a593Smuzhiyun<constant>NULL</constant> when not required.  The other parameters are defined
5236*4882a593Smuzhiyunas
5237*4882a593Smuzhiyun
5238*4882a593Smuzhiyun	<blockquote><para>
5239*4882a593Smuzhiyun	    <programlisting>
5240*4882a593Smuzhiyun    typedef pointer (*ModuleSetupProc)(pointer, pointer, int *, int *);
5241*4882a593Smuzhiyun
5242*4882a593Smuzhiyun    typedef void (*ModuleTearDownProc)(pointer);
5243*4882a593Smuzhiyun
5244*4882a593Smuzhiyun    pointer SetupProc(pointer module, pointer options,
5245*4882a593Smuzhiyun                      int *errmaj, int *errmin);
5246*4882a593Smuzhiyun	    </programlisting>
5247*4882a593Smuzhiyun	    <blockquote><para>
5248*4882a593Smuzhiyun    When defined, this function is called by the loader after successfully
5249*4882a593Smuzhiyun    loading a module.  module is a handle for the newly loaded module,
5250*4882a593Smuzhiyun    and maybe used by the <function>SetupProc</function> if it calls other
5251*4882a593Smuzhiyun    loader functions that require a reference to it.   The remaining
5252*4882a593Smuzhiyun    arguments are those that were passed to the
5253*4882a593Smuzhiyun    <function>LoadModule()</function> (or <function>LoadSubModule()</function>),
5254*4882a593Smuzhiyun    and are described above. When the <function>SetupProc</function> is
5255*4882a593Smuzhiyun    successful it must return a non-<constant>NULL</constant> value.  The
5256*4882a593Smuzhiyun    loader checks this, and if it is <constant>NULL</constant> it unloads
5257*4882a593Smuzhiyun    the module and reports the failure to the caller of
5258*4882a593Smuzhiyun    <function>LoadModule()</function>.  If the <function>SetupProc</function>
5259*4882a593Smuzhiyun    does things that need to be undone when the module is unloaded,
5260*4882a593Smuzhiyun    it should define a <function>TearDownProc</function>, and return a
5261*4882a593Smuzhiyun    pointer that the <function>TearDownProc</function> can use to undo what
5262*4882a593Smuzhiyun    has been done.
5263*4882a593Smuzhiyun	      </para>
5264*4882a593Smuzhiyun
5265*4882a593Smuzhiyun	      <para>
5266*4882a593Smuzhiyun    When a module is loaded multiple times, the <function>SetupProc</function>
5267*4882a593Smuzhiyun    is called once for each time it is loaded.
5268*4882a593Smuzhiyun	      </para>
5269*4882a593Smuzhiyun
5270*4882a593Smuzhiyun	    </blockquote></para></blockquote>
5271*4882a593Smuzhiyun
5272*4882a593Smuzhiyun	<blockquote><para>
5273*4882a593Smuzhiyun	    <programlisting>
5274*4882a593Smuzhiyun    void TearDownProc(pointer tearDownData);
5275*4882a593Smuzhiyun	    </programlisting>
5276*4882a593Smuzhiyun	    <blockquote><para>
5277*4882a593Smuzhiyun    When defined, this function is called when the loader unloads a
5278*4882a593Smuzhiyun    module.  The <parameter>tearDownData</parameter> parameter is the return
5279*4882a593Smuzhiyun    value of the <function>SetupProc()</function> that was called when the
5280*4882a593Smuzhiyun    module was loaded.  The purpose of this function is to clean up
5281*4882a593Smuzhiyun    before the module is unloaded (for example, by freeing allocated
5282*4882a593Smuzhiyun    resources).
5283*4882a593Smuzhiyun	      </para>
5284*4882a593Smuzhiyun
5285*4882a593Smuzhiyun	    </blockquote></para></blockquote>
5286*4882a593Smuzhiyun      </para>
5287*4882a593Smuzhiyun    </sect2>
5288*4882a593Smuzhiyun
5289*4882a593Smuzhiyun    <sect2>
5290*4882a593Smuzhiyun      <title>Public Loader Interface</title>
5291*4882a593Smuzhiyun
5292*4882a593Smuzhiyun      <para>
5293*4882a593SmuzhiyunThe following is the Loader interface that is available to any part of
5294*4882a593Smuzhiyunthe server, and may also be used from within modules.
5295*4882a593Smuzhiyun      </para>
5296*4882a593Smuzhiyun
5297*4882a593Smuzhiyun      <blockquote><para>
5298*4882a593Smuzhiyun	  <programlisting>
5299*4882a593Smuzhiyun    pointer LoadSubModule(pointer parent, const char *module,
5300*4882a593Smuzhiyun                          const char **subdirlist, const char **patternlist,
5301*4882a593Smuzhiyun                          pointer options, const XF86ModReqInfo * modreq,
5302*4882a593Smuzhiyun                          int *errmaj, int *errmin);
5303*4882a593Smuzhiyun	  </programlisting>
5304*4882a593Smuzhiyun	  <blockquote><para>
5305*4882a593Smuzhiyun    This function is like the <function>LoadModule()</function> function
5306*4882a593Smuzhiyun    described above, except that the module loaded is registered as a
5307*4882a593Smuzhiyun    child of the calling module.  The <parameter>parent</parameter> parameter
5308*4882a593Smuzhiyun    is the calling module's handle.  Modules loaded with this function
5309*4882a593Smuzhiyun    are automatically unloaded when the parent module is unloaded.
5310*4882a593Smuzhiyun	    </para>
5311*4882a593Smuzhiyun
5312*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5313*4882a593Smuzhiyun
5314*4882a593Smuzhiyun      <blockquote><para>
5315*4882a593Smuzhiyun	  <programlisting>
5316*4882a593Smuzhiyun    void UnloadSubModule(pointer module);
5317*4882a593Smuzhiyun	  </programlisting>
5318*4882a593Smuzhiyun	  <blockquote><para>
5319*4882a593Smuzhiyun    This function unloads the module with handle <parameter>module</parameter>.
5320*4882a593Smuzhiyun    If that module itself has children, they are also unloaded.  It is
5321*4882a593Smuzhiyun    like <function>UnloadModule()</function>, except that it is safe to use
5322*4882a593Smuzhiyun    for unloading child modules.
5323*4882a593Smuzhiyun	    </para>
5324*4882a593Smuzhiyun
5325*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5326*4882a593Smuzhiyun
5327*4882a593Smuzhiyun      <blockquote><para>
5328*4882a593Smuzhiyun	  <programlisting>
5329*4882a593Smuzhiyun    pointer LoaderSymbol(const char *symbol);
5330*4882a593Smuzhiyun	  </programlisting>
5331*4882a593Smuzhiyun	<blockquote><para>
5332*4882a593Smuzhiyun    This function returns the address of the symbol with name
5333*4882a593Smuzhiyun    <parameter>symbol</parameter>.  This may be used to locate a module entry
5334*4882a593Smuzhiyun    point with a known name.
5335*4882a593Smuzhiyun	    </para>
5336*4882a593Smuzhiyun
5337*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5338*4882a593Smuzhiyun
5339*4882a593Smuzhiyun      <blockquote><para>
5340*4882a593Smuzhiyun	  <programlisting>
5341*4882a593Smuzhiyun    char **LoaderlistDirs(const char **subdirlist,
5342*4882a593Smuzhiyun                          const char **patternlist);
5343*4882a593Smuzhiyun	  </programlisting>
5344*4882a593Smuzhiyun	  <blockquote><para>
5345*4882a593Smuzhiyun    This function returns a <constant>NULL</constant> terminated list of
5346*4882a593Smuzhiyun    canonical modules names for modules found in the default module
5347*4882a593Smuzhiyun    search path.  The <parameter>subdirlist</parameter> and
5348*4882a593Smuzhiyun    <parameter>patternlist</parameter> parameters are as described above, and
5349*4882a593Smuzhiyun    can be used to control the locations and names that are searched.
5350*4882a593Smuzhiyun    If no modules are found, the return value is <constant>NULL</constant>.
5351*4882a593Smuzhiyun    The returned list should be freed by calling
5352*4882a593Smuzhiyun    <function>LoaderFreeDirList()</function> when it is no longer needed.
5353*4882a593Smuzhiyun	    </para>
5354*4882a593Smuzhiyun
5355*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5356*4882a593Smuzhiyun
5357*4882a593Smuzhiyun      <blockquote><para>
5358*4882a593Smuzhiyun	  <programlisting>
5359*4882a593Smuzhiyun    void LoaderFreeDirList(char **list);
5360*4882a593Smuzhiyun	  </programlisting>
5361*4882a593Smuzhiyun	  <blockquote><para>
5362*4882a593Smuzhiyun    This function frees a module list created by
5363*4882a593Smuzhiyun    <function>LoaderlistDirs()</function>.
5364*4882a593Smuzhiyun	    </para>
5365*4882a593Smuzhiyun
5366*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5367*4882a593Smuzhiyun
5368*4882a593Smuzhiyun      <blockquote><para>
5369*4882a593Smuzhiyun	  <programlisting>
5370*4882a593Smuzhiyun    void LoaderReqSymLists(const char **list0, ...);
5371*4882a593Smuzhiyun	  </programlisting>
5372*4882a593Smuzhiyun	  <blockquote><para>
5373*4882a593Smuzhiyun    This function allows the registration of required symbols with the
5374*4882a593Smuzhiyun    loader.  It is normally used by a caller of
5375*4882a593Smuzhiyun    <function>LoadSubModule()</function>.  If any symbols registered in this
5376*4882a593Smuzhiyun    way are found to be unresolved when
5377*4882a593Smuzhiyun    <function>LoaderCheckUnresolved()</function> is called then
5378*4882a593Smuzhiyun    <function>LoaderCheckUnresolved()</function> will report a failure.
5379*4882a593Smuzhiyun    The function takes one or more <constant>NULL</constant> terminated
5380*4882a593Smuzhiyun    lists of symbols.  The end of the argument list is indicated by a
5381*4882a593Smuzhiyun    <constant>NULL</constant> argument.
5382*4882a593Smuzhiyun	    </para>
5383*4882a593Smuzhiyun
5384*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5385*4882a593Smuzhiyun
5386*4882a593Smuzhiyun      <blockquote><para>
5387*4882a593Smuzhiyun	  <programlisting>
5388*4882a593Smuzhiyun    void LoaderReqSymbols(const char *sym0, ...);
5389*4882a593Smuzhiyun	  </programlisting>
5390*4882a593Smuzhiyun	<blockquote><para>
5391*4882a593Smuzhiyun    This function is like <function>LoaderReqSymLists()</function> except
5392*4882a593Smuzhiyun    that its arguments are symbols rather than lists of symbols.  This
5393*4882a593Smuzhiyun    function is more convenient when single functions are to be registered,
5394*4882a593Smuzhiyun    especially when the single function might depend on runtime factors.
5395*4882a593Smuzhiyun    The end of the argument list is indicated by a <constant>NULL</constant>
5396*4882a593Smuzhiyun    argument.
5397*4882a593Smuzhiyun	    </para>
5398*4882a593Smuzhiyun
5399*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5400*4882a593Smuzhiyun
5401*4882a593Smuzhiyun      <blockquote><para>
5402*4882a593Smuzhiyun	  <programlisting>
5403*4882a593Smuzhiyun    void LoaderRefSymLists(const char **list0, ...);
5404*4882a593Smuzhiyun	  </programlisting>
5405*4882a593Smuzhiyun	  <blockquote><para>
5406*4882a593Smuzhiyun    This function allows the registration of possibly unresolved symbols
5407*4882a593Smuzhiyun    with the loader.  When <function>LoaderCheckUnresolved()</function> is
5408*4882a593Smuzhiyun    run it won't generate warnings for symbols registered in this way
5409*4882a593Smuzhiyun    unless they were also registered as required symbols.
5410*4882a593Smuzhiyun    The function takes one or more <constant>NULL</constant> terminated
5411*4882a593Smuzhiyun    lists of symbols.  The end of the argument list is indicated by a
5412*4882a593Smuzhiyun    <constant>NULL</constant> argument.
5413*4882a593Smuzhiyun	    </para>
5414*4882a593Smuzhiyun
5415*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5416*4882a593Smuzhiyun
5417*4882a593Smuzhiyun      <blockquote><para>
5418*4882a593Smuzhiyun	  <programlisting>
5419*4882a593Smuzhiyun    void LoaderRefSymbols(const char *sym0, ...);
5420*4882a593Smuzhiyun	  </programlisting>
5421*4882a593Smuzhiyun	  <blockquote><para>
5422*4882a593Smuzhiyun    This function is like <function>LoaderRefSymLists()</function> except
5423*4882a593Smuzhiyun    that its arguments are symbols rather than lists of symbols.  This
5424*4882a593Smuzhiyun    function is more convenient when single functions are to be registered,
5425*4882a593Smuzhiyun    especially when the single function might depend on runtime factors.
5426*4882a593Smuzhiyun    The end of the argument list is indicated by a <constant>NULL</constant>
5427*4882a593Smuzhiyun    argument.
5428*4882a593Smuzhiyun	    </para>
5429*4882a593Smuzhiyun
5430*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5431*4882a593Smuzhiyun
5432*4882a593Smuzhiyun      <blockquote><para>
5433*4882a593Smuzhiyun	  <programlisting>
5434*4882a593Smuzhiyun    int LoaderCheckUnresolved(int delayflag);
5435*4882a593Smuzhiyun	  </programlisting>
5436*4882a593Smuzhiyun	  <blockquote><para>
5437*4882a593Smuzhiyun    This function checks for unresolved symbols.  It generates warnings
5438*4882a593Smuzhiyun    for unresolved symbols that have not been registered with
5439*4882a593Smuzhiyun    <function>LoaderRefSymLists()</function>, and maps them to a dummy
5440*4882a593Smuzhiyun    function.  This behaviour may change in future.  If unresolved
5441*4882a593Smuzhiyun    symbols are found that have been registered with
5442*4882a593Smuzhiyun    <function>LoaderReqSymLists()</function> or
5443*4882a593Smuzhiyun    <function>LoaderReqSymbols()</function> then this function returns a
5444*4882a593Smuzhiyun    non-zero value.  If none of these symbols are unresolved the return
5445*4882a593Smuzhiyun    value is zero, indicating success.
5446*4882a593Smuzhiyun	    </para>
5447*4882a593Smuzhiyun
5448*4882a593Smuzhiyun	    <para>
5449*4882a593Smuzhiyun    The <parameter>delayflag</parameter> parameter should normally be set to
5450*4882a593Smuzhiyun    <constant>LD_RESOLV_IFDONE</constant>.
5451*4882a593Smuzhiyun	    </para>
5452*4882a593Smuzhiyun
5453*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5454*4882a593Smuzhiyun
5455*4882a593Smuzhiyun      <blockquote><para>
5456*4882a593Smuzhiyun	  <programlisting>
5457*4882a593Smuzhiyun    LoaderErrorMsg(const char *name, const char *modname,
5458*4882a593Smuzhiyun                   int errmaj, int errmin);
5459*4882a593Smuzhiyun	  </programlisting>
5460*4882a593Smuzhiyun	  <blockquote><para>
5461*4882a593Smuzhiyun    This function prints an error message that includes the text <quote>Failed
5462*4882a593Smuzhiyun    to load module</quote>, the module name <parameter>modname</parameter>, a message
5463*4882a593Smuzhiyun    specific to the <parameter>errmaj</parameter> value, and the value if
5464*4882a593Smuzhiyun    <parameter>errmin</parameter>.  If <parameter>name</parameter> is
5465*4882a593Smuzhiyun    non-<constant>NULL</constant>, it is printed as an identifying prefix
5466*4882a593Smuzhiyun    to the message (followed by a <quote>:</quote>).
5467*4882a593Smuzhiyun	    </para>
5468*4882a593Smuzhiyun
5469*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5470*4882a593Smuzhiyun    </sect2>
5471*4882a593Smuzhiyun
5472*4882a593Smuzhiyun    <sect2>
5473*4882a593Smuzhiyun      <title>Special Registration Functions</title>
5474*4882a593Smuzhiyun
5475*4882a593Smuzhiyun      <para>
5476*4882a593SmuzhiyunThe loader contains some functions for registering some classes of modules.
5477*4882a593SmuzhiyunThese may be moved out of the loader at some point.
5478*4882a593Smuzhiyun      </para>
5479*4882a593Smuzhiyun
5480*4882a593Smuzhiyun      <blockquote><para>
5481*4882a593Smuzhiyun	  <programlisting>
5482*4882a593Smuzhiyun    void LoadExtensionList(const ExtensionModule ext[], int size, Bool builtin);
5483*4882a593Smuzhiyun	  </programlisting>
5484*4882a593Smuzhiyun	  <blockquote><para>
5485*4882a593Smuzhiyun    This registers the entry points for the extension array identified by
5486*4882a593Smuzhiyun    <parameter>ext</parameter>.  The <structname>ExtensionModule</structname> struct is
5487*4882a593Smuzhiyun    defined as:
5488*4882a593Smuzhiyun
5489*4882a593Smuzhiyun	      <programlisting>
5490*4882a593Smuzhiyuntypedef struct {
5491*4882a593Smuzhiyun    InitExtension       initFunc;
5492*4882a593Smuzhiyun    char *              name;
5493*4882a593Smuzhiyun    Bool                *disablePtr;
5494*4882a593Smuzhiyun} ExtensionModule;
5495*4882a593Smuzhiyun	      </programlisting>
5496*4882a593Smuzhiyun	    </para>
5497*4882a593Smuzhiyun
5498*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5499*4882a593Smuzhiyun
5500*4882a593Smuzhiyun    </sect2>
5501*4882a593Smuzhiyun
5502*4882a593Smuzhiyun  </sect1>
5503*4882a593Smuzhiyun
5504*4882a593Smuzhiyun  <sect1>
5505*4882a593Smuzhiyun    <title>Helper Functions</title>
5506*4882a593Smuzhiyun
5507*4882a593Smuzhiyun    <para>
5508*4882a593SmuzhiyunThis section describe <quote>helper</quote> functions that video driver
5509*4882a593Smuzhiyunmight find useful.  While video drivers are not required to use any of
5510*4882a593Smuzhiyunthese to be considered <quote>compliant</quote>, the use of appropriate helpers is
5511*4882a593Smuzhiyunstrongly encouraged to improve the consistency of driver behaviour.
5512*4882a593Smuzhiyun    </para>
5513*4882a593Smuzhiyun
5514*4882a593Smuzhiyun    <sect2>
5515*4882a593Smuzhiyun      <title>Functions for printing messages</title>
5516*4882a593Smuzhiyun
5517*4882a593Smuzhiyun      <blockquote><para>
5518*4882a593Smuzhiyun	  <programlisting>
5519*4882a593Smuzhiyun    ErrorF(const char *format, ...);
5520*4882a593Smuzhiyun	  </programlisting>
5521*4882a593Smuzhiyun	  <blockquote><para>
5522*4882a593Smuzhiyun      This is the basic function for writing to the error log (typically
5523*4882a593Smuzhiyun      stderr and/or a log file).  Video drivers should usually avoid
5524*4882a593Smuzhiyun      using this directly in favour of the more specialised functions
5525*4882a593Smuzhiyun      described below.  This function is useful for printing messages
5526*4882a593Smuzhiyun      while debugging a driver.
5527*4882a593Smuzhiyun	    </para>
5528*4882a593Smuzhiyun
5529*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5530*4882a593Smuzhiyun
5531*4882a593Smuzhiyun      <blockquote><para>
5532*4882a593Smuzhiyun	  <programlisting>
5533*4882a593Smuzhiyun    FatalError(const char *format, ...);
5534*4882a593Smuzhiyun	  </programlisting>
5535*4882a593Smuzhiyun	  <blockquote><para>
5536*4882a593Smuzhiyun      This prints a message and causes the Xserver to abort.  It should
5537*4882a593Smuzhiyun      rarely be used within a video driver, as most error conditions
5538*4882a593Smuzhiyun      should be flagged by the return values of the driver functions.
5539*4882a593Smuzhiyun      This allows the higher layers to decide how to proceed.  In rare
5540*4882a593Smuzhiyun      cases, this can be used within a driver if a fatal unexpected
5541*4882a593Smuzhiyun      condition is found.
5542*4882a593Smuzhiyun	    </para>
5543*4882a593Smuzhiyun
5544*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5545*4882a593Smuzhiyun
5546*4882a593Smuzhiyun      <blockquote><para>
5547*4882a593Smuzhiyun	  <programlisting>
5548*4882a593Smuzhiyun    xf86ErrorF(const char *format, ...);
5549*4882a593Smuzhiyun	  </programlisting>
5550*4882a593Smuzhiyun	  <blockquote><para>
5551*4882a593Smuzhiyun      This is like <function>ErrorF()</function>, except that the message is
5552*4882a593Smuzhiyun      only printed when the Xserver's verbosity level is set to the
5553*4882a593Smuzhiyun      default (<constant>1</constant>) or higher.  It means that the messages
5554*4882a593Smuzhiyun      are not printed when the server is started with the
5555*4882a593Smuzhiyun      <option>-quiet</option> flag.  Typically this function would only be
5556*4882a593Smuzhiyun      used for continuing messages started with one of the more specialised
5557*4882a593Smuzhiyun      functions described below.
5558*4882a593Smuzhiyun	    </para>
5559*4882a593Smuzhiyun
5560*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5561*4882a593Smuzhiyun
5562*4882a593Smuzhiyun      <blockquote><para>
5563*4882a593Smuzhiyun	  <programlisting>
5564*4882a593Smuzhiyun    xf86ErrorFVerb(int verb, const char *format, ...);
5565*4882a593Smuzhiyun	  </programlisting>
5566*4882a593Smuzhiyun	  <blockquote><para>
5567*4882a593Smuzhiyun      Like <function>xf86ErrorF()</function>, except the minimum verbosity
5568*4882a593Smuzhiyun      level for which the message is to be printed is given explicitly.
5569*4882a593Smuzhiyun      Passing a <parameter>verb</parameter> value of zero means the message
5570*4882a593Smuzhiyun      is always printed.  A value higher than <constant>1</constant> can be
5571*4882a593Smuzhiyun      used for information would normally not be needed, but which might
5572*4882a593Smuzhiyun      be useful when diagnosing problems.
5573*4882a593Smuzhiyun	    </para>
5574*4882a593Smuzhiyun
5575*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5576*4882a593Smuzhiyun
5577*4882a593Smuzhiyun
5578*4882a593Smuzhiyun      <blockquote><para>
5579*4882a593Smuzhiyun	  <programlisting>
5580*4882a593Smuzhiyun    xf86Msg(MessageType type, const char *format, ...);
5581*4882a593Smuzhiyun	  </programlisting>
5582*4882a593Smuzhiyun	  <blockquote><para>
5583*4882a593Smuzhiyun      This is like <function>xf86ErrorF()</function>, except that the message
5584*4882a593Smuzhiyun      is prefixed with a marker determined by the value of
5585*4882a593Smuzhiyun      <parameter>type</parameter>.  The marker is used to indicate the type of
5586*4882a593Smuzhiyun      message (warning, error, probed value, config value, etc).  Note
5587*4882a593Smuzhiyun      the <varname>xf86Verbose</varname> value is ignored for messages of
5588*4882a593Smuzhiyun      type <constant>X_ERROR</constant>.
5589*4882a593Smuzhiyun	    </para>
5590*4882a593Smuzhiyun
5591*4882a593Smuzhiyun	    <para>
5592*4882a593Smuzhiyun      The marker values are:
5593*4882a593Smuzhiyun
5594*4882a593Smuzhiyun	      <variablelist>
5595*4882a593Smuzhiyun		<varlistentry>
5596*4882a593Smuzhiyun		  <term><constant>X_PROBED</constant></term>
5597*4882a593Smuzhiyun		  <listitem><para>Value was probed.
5598*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5599*4882a593Smuzhiyun		<varlistentry>
5600*4882a593Smuzhiyun		  <term><constant>X_CONFIG</constant></term>
5601*4882a593Smuzhiyun		  <listitem><para>Value was given in the config file.
5602*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5603*4882a593Smuzhiyun		<varlistentry>
5604*4882a593Smuzhiyun		  <term><constant>X_DEFAULT</constant></term>
5605*4882a593Smuzhiyun		  <listitem><para>Value is a default.
5606*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5607*4882a593Smuzhiyun		<varlistentry>
5608*4882a593Smuzhiyun		  <term><constant>X_CMDLINE</constant></term>
5609*4882a593Smuzhiyun		  <listitem><para>Value was given on the command line.
5610*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5611*4882a593Smuzhiyun		<varlistentry>
5612*4882a593Smuzhiyun		  <term><constant>X_NOTICE</constant></term>
5613*4882a593Smuzhiyun		  <listitem><para>Notice.
5614*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5615*4882a593Smuzhiyun		<varlistentry>
5616*4882a593Smuzhiyun		  <term><constant>X_ERROR</constant></term>
5617*4882a593Smuzhiyun		  <listitem><para>Error message.
5618*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5619*4882a593Smuzhiyun		<varlistentry>
5620*4882a593Smuzhiyun		  <term><constant>X_WARNING</constant></term>
5621*4882a593Smuzhiyun		  <listitem><para>Warning message.
5622*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5623*4882a593Smuzhiyun		<varlistentry>
5624*4882a593Smuzhiyun		  <term><constant>X_INFO</constant></term>
5625*4882a593Smuzhiyun		  <listitem><para>Informational message.
5626*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5627*4882a593Smuzhiyun		<varlistentry>
5628*4882a593Smuzhiyun		  <term><constant>X_NONE</constant></term>
5629*4882a593Smuzhiyun		  <listitem><para>No prefix.
5630*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5631*4882a593Smuzhiyun		<varlistentry>
5632*4882a593Smuzhiyun		  <term><constant>X_NOT_IMPLEMENTED</constant></term>
5633*4882a593Smuzhiyun		  <listitem><para>The message relates to functionality
5634*4882a593Smuzhiyun		      that is not yetimplemented.
5635*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5636*4882a593Smuzhiyun		</variablelist>
5637*4882a593Smuzhiyun
5638*4882a593Smuzhiyun	    </para>
5639*4882a593Smuzhiyun
5640*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5641*4882a593Smuzhiyun
5642*4882a593Smuzhiyun      <blockquote><para>
5643*4882a593Smuzhiyun	  <programlisting>
5644*4882a593Smuzhiyun    xf86MsgVerb(MessageType type, int verb, const char *format, ...);
5645*4882a593Smuzhiyun	  </programlisting>
5646*4882a593Smuzhiyun	  <blockquote><para>
5647*4882a593Smuzhiyun      Like <function>xf86Msg()</function>, but with the verbosity level given
5648*4882a593Smuzhiyun      explicitly.
5649*4882a593Smuzhiyun	    </para>
5650*4882a593Smuzhiyun
5651*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5652*4882a593Smuzhiyun
5653*4882a593Smuzhiyun      <blockquote><para>
5654*4882a593Smuzhiyun	  <programlisting>
5655*4882a593Smuzhiyun    xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...);
5656*4882a593Smuzhiyun	  </programlisting>
5657*4882a593Smuzhiyun	  <blockquote><para>
5658*4882a593Smuzhiyun      This is like <function>xf86Msg()</function> except that the driver's
5659*4882a593Smuzhiyun      name (the <structfield>name</structfield> field of the
5660*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname>) followed by the
5661*4882a593Smuzhiyun      <parameter>scrnIndex</parameter> in parentheses is printed following the
5662*4882a593Smuzhiyun      prefix.  This should be used by video drivers in most cases as it
5663*4882a593Smuzhiyun      clearly indicates which driver/screen the message is for.  If
5664*4882a593Smuzhiyun      <parameter>scrnIndex</parameter> is negative, this function behaves
5665*4882a593Smuzhiyun      exactly like <function>xf86Msg()</function>.
5666*4882a593Smuzhiyun	    </para>
5667*4882a593Smuzhiyun
5668*4882a593Smuzhiyun	    <para>
5669*4882a593Smuzhiyun      NOTE: This function can only be used after the
5670*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname> and its <structfield>name</structfield> field
5671*4882a593Smuzhiyun      have been allocated.  Normally, this means that it can not be
5672*4882a593Smuzhiyun      used before the END of the <function>ChipProbe()</function> function.
5673*4882a593Smuzhiyun      Prior to that, use <function>xf86Msg()</function>, providing the
5674*4882a593Smuzhiyun      driver's name explicitly.  No screen number can be supplied at
5675*4882a593Smuzhiyun      that point.
5676*4882a593Smuzhiyun	    </para>
5677*4882a593Smuzhiyun
5678*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5679*4882a593Smuzhiyun
5680*4882a593Smuzhiyun      <blockquote><para>
5681*4882a593Smuzhiyun	  <programlisting>
5682*4882a593Smuzhiyun    xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb,
5683*4882a593Smuzhiyun                                const char *format, ...);
5684*4882a593Smuzhiyun	  </programlisting>
5685*4882a593Smuzhiyun	  <blockquote><para>
5686*4882a593Smuzhiyun      Like <function>xf86DrvMsg()</function>, but with the verbosity level
5687*4882a593Smuzhiyun      given explicitly.
5688*4882a593Smuzhiyun	    </para>
5689*4882a593Smuzhiyun
5690*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5691*4882a593Smuzhiyun    </sect2>
5692*4882a593Smuzhiyun
5693*4882a593Smuzhiyun
5694*4882a593Smuzhiyun    <sect2>
5695*4882a593Smuzhiyun      <title>Functions for setting values based on command line and config file</title>
5696*4882a593Smuzhiyun
5697*4882a593Smuzhiyun      <blockquote><para>
5698*4882a593Smuzhiyun	  <programlisting>
5699*4882a593Smuzhiyun    Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp,
5700*4882a593Smuzhiyun
5701*4882a593Smuzhiyun                                int fbbpp, int depth24flags);
5702*4882a593Smuzhiyun	  </programlisting>
5703*4882a593Smuzhiyun	  <blockquote><para>
5704*4882a593Smuzhiyun      This function sets the <structfield>depth</structfield>, <structfield>pixmapBPP</structfield> and <structfield>bitsPerPixel</structfield> fields
5705*4882a593Smuzhiyun      of the <structname>ScrnInfoRec</structname>.  It also determines the defaults for display-wide
5706*4882a593Smuzhiyun      attributes and pixmap formats the screen will support, and finds
5707*4882a593Smuzhiyun      the Display subsection that matches the depth/bpp.  This function
5708*4882a593Smuzhiyun      should normally be called very early from the
5709*4882a593Smuzhiyun      <function>ChipPreInit()</function> function.
5710*4882a593Smuzhiyun	    </para>
5711*4882a593Smuzhiyun
5712*4882a593Smuzhiyun	    <para>
5713*4882a593Smuzhiyun      It requires that the <structfield>confScreen</structfield> field of the <structname>ScrnInfoRec</structname> be
5714*4882a593Smuzhiyun      initialised prior to calling it.  This is done by the XFree86
5715*4882a593Smuzhiyun      common layer prior to calling <function>ChipPreInit()</function>.
5716*4882a593Smuzhiyun	    </para>
5717*4882a593Smuzhiyun
5718*4882a593Smuzhiyun	    <para>
5719*4882a593Smuzhiyun      The parameters passed are:
5720*4882a593Smuzhiyun
5721*4882a593Smuzhiyun	      <variablelist>
5722*4882a593Smuzhiyun		<varlistentry>
5723*4882a593Smuzhiyun		  <term><parameter>depth</parameter></term>
5724*4882a593Smuzhiyun		  <listitem><para>
5725*4882a593Smuzhiyun		driver's preferred default depth if no other is given.
5726*4882a593Smuzhiyun                If zero, use the overall server default.
5727*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5728*4882a593Smuzhiyun
5729*4882a593Smuzhiyun		<varlistentry>
5730*4882a593Smuzhiyun		  <term><parameter>bpp</parameter></term>
5731*4882a593Smuzhiyun		  <listitem><para>
5732*4882a593Smuzhiyun		Same, but for the pixmap bpp.
5733*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5734*4882a593Smuzhiyun
5735*4882a593Smuzhiyun		<varlistentry>
5736*4882a593Smuzhiyun		  <term><parameter>fbbpp</parameter></term>
5737*4882a593Smuzhiyun		  <listitem><para>
5738*4882a593Smuzhiyun		Same, but for the framebuffer bpp.
5739*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5740*4882a593Smuzhiyun
5741*4882a593Smuzhiyun		<varlistentry>
5742*4882a593Smuzhiyun		  <term><parameter>depth24flags</parameter></term>
5743*4882a593Smuzhiyun		  <listitem><para>
5744*4882a593Smuzhiyun		Flags that indicate the level of 24/32bpp support
5745*4882a593Smuzhiyun                and whether conversion between different framebuffer
5746*4882a593Smuzhiyun                and pixmap formats is supported.  The flags for this
5747*4882a593Smuzhiyun                argument are defined as follows, and multiple flags
5748*4882a593Smuzhiyun                may be ORed together:
5749*4882a593Smuzhiyun
5750*4882a593Smuzhiyun		      <variablelist>
5751*4882a593Smuzhiyun			<varlistentry>
5752*4882a593Smuzhiyun			  <term><constant>NoDepth24Support</constant></term>
5753*4882a593Smuzhiyun			  <listitem><para>No depth 24 formats supported
5754*4882a593Smuzhiyun			    </para></listitem></varlistentry>
5755*4882a593Smuzhiyun			<varlistentry>
5756*4882a593Smuzhiyun			  <term><constant>Support24bppFb</constant></term>
5757*4882a593Smuzhiyun			  <listitem><para>24bpp framebuffer supported
5758*4882a593Smuzhiyun			    </para></listitem></varlistentry>
5759*4882a593Smuzhiyun			<varlistentry>
5760*4882a593Smuzhiyun			  <term><constant>Support32bppFb</constant></term>
5761*4882a593Smuzhiyun			  <listitem><para>32bpp framebuffer supported
5762*4882a593Smuzhiyun			    </para></listitem></varlistentry>
5763*4882a593Smuzhiyun			<varlistentry>
5764*4882a593Smuzhiyun			  <term><constant>SupportConvert24to32</constant></term>
5765*4882a593Smuzhiyun			  <listitem><para>Can convert 24bpp pixmap to 32bpp fb
5766*4882a593Smuzhiyun			    </para></listitem></varlistentry>
5767*4882a593Smuzhiyun			<varlistentry>
5768*4882a593Smuzhiyun			  <term><constant>SupportConvert32to24</constant></term>
5769*4882a593Smuzhiyun			  <listitem><para>Can convert 32bpp pixmap to 24bpp fb
5770*4882a593Smuzhiyun			    </para></listitem></varlistentry>
5771*4882a593Smuzhiyun			<varlistentry>
5772*4882a593Smuzhiyun			  <term><constant>ForceConvert24to32</constant></term>
5773*4882a593Smuzhiyun			  <listitem><para>Force 24bpp pixmap to 32bpp fb conversion
5774*4882a593Smuzhiyun			    </para></listitem></varlistentry>
5775*4882a593Smuzhiyun			<varlistentry>
5776*4882a593Smuzhiyun			  <term><constant>ForceConvert32to24</constant></term>
5777*4882a593Smuzhiyun			  <listitem><para>Force 32bpp pixmap to 24bpp fb conversion
5778*4882a593Smuzhiyun			    </para></listitem></varlistentry>
5779*4882a593Smuzhiyun		      </variablelist>
5780*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5781*4882a593Smuzhiyun
5782*4882a593Smuzhiyun	      </variablelist>
5783*4882a593Smuzhiyun	    </para>
5784*4882a593Smuzhiyun
5785*4882a593Smuzhiyun	    <para>
5786*4882a593Smuzhiyun      It uses the command line, config file, and default values in the
5787*4882a593Smuzhiyun      correct order of precedence to determine the depth and bpp values.
5788*4882a593Smuzhiyun      It is up to the driver to check the results to see that it supports
5789*4882a593Smuzhiyun      them.  If not the <function>ChipPreInit()</function> function should
5790*4882a593Smuzhiyun      return <constant>FALSE</constant>.
5791*4882a593Smuzhiyun	    </para>
5792*4882a593Smuzhiyun
5793*4882a593Smuzhiyun	    <para>
5794*4882a593Smuzhiyun      If only one of depth/bpp is given, the other is set to a reasonable
5795*4882a593Smuzhiyun      (and consistent) default.
5796*4882a593Smuzhiyun	    </para>
5797*4882a593Smuzhiyun
5798*4882a593Smuzhiyun	    <para>
5799*4882a593Smuzhiyun      If a driver finds that the initial <parameter>depth24flags</parameter>
5800*4882a593Smuzhiyun      it uses later results in a fb format that requires more video
5801*4882a593Smuzhiyun      memory than is available it may call this function a second time
5802*4882a593Smuzhiyun      with a different <parameter>depth24flags</parameter> setting.
5803*4882a593Smuzhiyun	    </para>
5804*4882a593Smuzhiyun
5805*4882a593Smuzhiyun	    <para>
5806*4882a593Smuzhiyun      On success, the return value is <constant>TRUE</constant>.  On failure
5807*4882a593Smuzhiyun      it prints an error message and returns <constant>FALSE</constant>.
5808*4882a593Smuzhiyun	    </para>
5809*4882a593Smuzhiyun
5810*4882a593Smuzhiyun	    <para>
5811*4882a593Smuzhiyun      The following fields of the <structname>ScrnInfoRec</structname> are
5812*4882a593Smuzhiyun      initialised by this function:
5813*4882a593Smuzhiyun
5814*4882a593Smuzhiyun	      <blockquote><para>
5815*4882a593Smuzhiyun<structfield>depth</structfield>, <structfield>bitsPerPixel</structfield>,
5816*4882a593Smuzhiyun<structfield>display</structfield>, <structfield>imageByteOrder</structfield>,
5817*4882a593Smuzhiyun<structfield>bitmapScanlinePad</structfield>,
5818*4882a593Smuzhiyun<structfield>bitmapScanlineUnit</structfield>, <structfield>bitmapBitOrder</structfield>,
5819*4882a593Smuzhiyun<structfield>numFormats</structfield>, <structfield>formats</structfield>,
5820*4882a593Smuzhiyun<structfield>fbFormat</structfield>.
5821*4882a593Smuzhiyun		</para></blockquote>
5822*4882a593Smuzhiyun	    </para>
5823*4882a593Smuzhiyun
5824*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5825*4882a593Smuzhiyun
5826*4882a593Smuzhiyun      <blockquote><para>
5827*4882a593Smuzhiyun	  <programlisting>
5828*4882a593Smuzhiyun    void xf86PrintDepthBpp(scrnInfoPtr scrp);
5829*4882a593Smuzhiyun	  </programlisting>
5830*4882a593Smuzhiyun	  <blockquote><para>
5831*4882a593Smuzhiyun      This function can be used to print out the depth and bpp settings.
5832*4882a593Smuzhiyun      It should be called after the final call to
5833*4882a593Smuzhiyun      <function>xf86SetDepthBpp()</function>.
5834*4882a593Smuzhiyun	    </para>
5835*4882a593Smuzhiyun
5836*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5837*4882a593Smuzhiyun
5838*4882a593Smuzhiyun      <blockquote><para>
5839*4882a593Smuzhiyun	  <programlisting>
5840*4882a593Smuzhiyun    Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask);
5841*4882a593Smuzhiyun	  </programlisting>
5842*4882a593Smuzhiyun	  <blockquote><para>
5843*4882a593Smuzhiyun      This function sets the <structfield>weight</structfield>, <structfield>mask</structfield>,
5844*4882a593Smuzhiyun      <structfield>offset</structfield> and <structfield>rgbBits</structfield> fields of the
5845*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname>.  It would normally be called fairly
5846*4882a593Smuzhiyun      early in the <function>ChipPreInit()</function> function for
5847*4882a593Smuzhiyun      depths&nbsp;&gt;&nbsp;8bpp.
5848*4882a593Smuzhiyun	    </para>
5849*4882a593Smuzhiyun
5850*4882a593Smuzhiyun	    <para>
5851*4882a593Smuzhiyun      It requires that the <structfield>depth</structfield> and
5852*4882a593Smuzhiyun      <structfield>display</structfield> fields of the <structname>ScrnInfoRec</structname>
5853*4882a593Smuzhiyun      be initialised prior to calling it.
5854*4882a593Smuzhiyun	    </para>
5855*4882a593Smuzhiyun
5856*4882a593Smuzhiyun	    <para>
5857*4882a593Smuzhiyun      The parameters passed are:
5858*4882a593Smuzhiyun
5859*4882a593Smuzhiyun	      <variablelist>
5860*4882a593Smuzhiyun		<varlistentry>
5861*4882a593Smuzhiyun		  <term><parameter>weight</parameter></term>
5862*4882a593Smuzhiyun		  <listitem><para>
5863*4882a593Smuzhiyun		driver's preferred default weight if no other is given.
5864*4882a593Smuzhiyun                If zero, use the overall server default.
5865*4882a593Smuzhiyun
5866*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5867*4882a593Smuzhiyun
5868*4882a593Smuzhiyun		<varlistentry>
5869*4882a593Smuzhiyun		  <term><parameter>mask</parameter></term>
5870*4882a593Smuzhiyun		  <listitem><para>
5871*4882a593Smuzhiyun		Same, but for mask.
5872*4882a593Smuzhiyun
5873*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5874*4882a593Smuzhiyun	      </variablelist>
5875*4882a593Smuzhiyun	    </para>
5876*4882a593Smuzhiyun
5877*4882a593Smuzhiyun	    <para>
5878*4882a593Smuzhiyun      It uses the command line, config file, and default values in the
5879*4882a593Smuzhiyun      correct order of precedence to determine the weight value.  It
5880*4882a593Smuzhiyun      derives the mask and offset values from the weight and the defaults.
5881*4882a593Smuzhiyun      It is up to the driver to check the results to see that it supports
5882*4882a593Smuzhiyun      them.  If not the <function>ChipPreInit()</function> function should
5883*4882a593Smuzhiyun      return <constant>FALSE</constant>.
5884*4882a593Smuzhiyun	    </para>
5885*4882a593Smuzhiyun
5886*4882a593Smuzhiyun	    <para>
5887*4882a593Smuzhiyun      On success, this function prints a message showing the weight
5888*4882a593Smuzhiyun      values selected, and returns <constant>TRUE</constant>.
5889*4882a593Smuzhiyun	    </para>
5890*4882a593Smuzhiyun
5891*4882a593Smuzhiyun	    <para>
5892*4882a593Smuzhiyun      On failure it prints an error message and returns <constant>FALSE</constant>.
5893*4882a593Smuzhiyun	    </para>
5894*4882a593Smuzhiyun
5895*4882a593Smuzhiyun	    <para>
5896*4882a593Smuzhiyun      The following fields of the <structname>ScrnInfoRec</structname> are
5897*4882a593Smuzhiyun      initialised by this function:
5898*4882a593Smuzhiyun
5899*4882a593Smuzhiyun	      <blockquote><para>
5900*4882a593Smuzhiyun		  <structfield>weight</structfield>,
5901*4882a593Smuzhiyun		  <structfield>mask</structfield>,
5902*4882a593Smuzhiyun		  <structfield>offset</structfield>.
5903*4882a593Smuzhiyun		</para></blockquote>
5904*4882a593Smuzhiyun	    </para>
5905*4882a593Smuzhiyun
5906*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5907*4882a593Smuzhiyun
5908*4882a593Smuzhiyun      <blockquote><para>
5909*4882a593Smuzhiyun	  <programlisting>
5910*4882a593Smuzhiyun    Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual);
5911*4882a593Smuzhiyun	  </programlisting>
5912*4882a593Smuzhiyun	  <blockquote><para>
5913*4882a593Smuzhiyun      This function sets the <structfield>defaultVisual</structfield> field of the
5914*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname>.  It would normally be called fairly
5915*4882a593Smuzhiyun      early from the <function>ChipPreInit()</function> function.
5916*4882a593Smuzhiyun	    </para>
5917*4882a593Smuzhiyun
5918*4882a593Smuzhiyun	    <para>
5919*4882a593Smuzhiyun      It requires that the <structfield>depth</structfield> and
5920*4882a593Smuzhiyun      <structfield>display</structfield> fields of the <structname>ScrnInfoRec</structname>
5921*4882a593Smuzhiyun      be initialised prior to calling it.
5922*4882a593Smuzhiyun	    </para>
5923*4882a593Smuzhiyun
5924*4882a593Smuzhiyun	    <para>
5925*4882a593Smuzhiyun      The parameters passed are:
5926*4882a593Smuzhiyun
5927*4882a593Smuzhiyun	      <variablelist>
5928*4882a593Smuzhiyun		<varlistentry>
5929*4882a593Smuzhiyun		  <term><parameter>visual</parameter></term>
5930*4882a593Smuzhiyun		  <listitem><para>
5931*4882a593Smuzhiyun		driver's preferred default visual if no other is given.
5932*4882a593Smuzhiyun		If <constant>-1</constant>, use the overall server default.
5933*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5934*4882a593Smuzhiyun
5935*4882a593Smuzhiyun	      </variablelist>
5936*4882a593Smuzhiyun	    </para>
5937*4882a593Smuzhiyun
5938*4882a593Smuzhiyun	    <para>
5939*4882a593Smuzhiyun      It uses the command line, config file, and default values in the
5940*4882a593Smuzhiyun      correct order of precedence to determine the default visual value.
5941*4882a593Smuzhiyun      It is up to the driver to check the result to see that it supports
5942*4882a593Smuzhiyun      it.  If not the <function>ChipPreInit()</function> function should
5943*4882a593Smuzhiyun      return <constant>FALSE</constant>.
5944*4882a593Smuzhiyun	    </para>
5945*4882a593Smuzhiyun
5946*4882a593Smuzhiyun	    <para>
5947*4882a593Smuzhiyun      On success, this function prints a message showing the default visual
5948*4882a593Smuzhiyun      selected, and returns <constant>TRUE</constant>.
5949*4882a593Smuzhiyun	    </para>
5950*4882a593Smuzhiyun
5951*4882a593Smuzhiyun	    <para>
5952*4882a593Smuzhiyun      On failure it prints an error message and returns <constant>FALSE</constant>.
5953*4882a593Smuzhiyun	    </para>
5954*4882a593Smuzhiyun
5955*4882a593Smuzhiyun	  </blockquote></para></blockquote>
5956*4882a593Smuzhiyun
5957*4882a593Smuzhiyun      <blockquote><para>
5958*4882a593Smuzhiyun	  <programlisting>
5959*4882a593Smuzhiyun    Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma);
5960*4882a593Smuzhiyun	  </programlisting>
5961*4882a593Smuzhiyun	  <blockquote><para>
5962*4882a593Smuzhiyun      This function sets the <structfield>gamma</structfield> field of the
5963*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname>.  It would normally be called fairly
5964*4882a593Smuzhiyun      early from the <function>ChipPreInit()</function> function in cases
5965*4882a593Smuzhiyun      where the driver supports gamma correction.
5966*4882a593Smuzhiyun	    </para>
5967*4882a593Smuzhiyun
5968*4882a593Smuzhiyun	    <para>
5969*4882a593Smuzhiyun      It requires that the <structfield>monitor</structfield> field of the
5970*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname> be initialised prior to calling it.
5971*4882a593Smuzhiyun	    </para>
5972*4882a593Smuzhiyun
5973*4882a593Smuzhiyun	    <para>
5974*4882a593Smuzhiyun      The parameters passed are:
5975*4882a593Smuzhiyun
5976*4882a593Smuzhiyun	      <variablelist>
5977*4882a593Smuzhiyun		<varlistentry>
5978*4882a593Smuzhiyun		  <term><parameter>gamma</parameter></term>
5979*4882a593Smuzhiyun		  <listitem><para>
5980*4882a593Smuzhiyun		driver's preferred default gamma if no other is given.
5981*4882a593Smuzhiyun		If zero (<code>&lt; 0.01</code>), use the overall server
5982*4882a593Smuzhiyun		default.
5983*4882a593Smuzhiyun		    </para></listitem></varlistentry>
5984*4882a593Smuzhiyun
5985*4882a593Smuzhiyun	      </variablelist>
5986*4882a593Smuzhiyun	    </para>
5987*4882a593Smuzhiyun
5988*4882a593Smuzhiyun	    <para>
5989*4882a593Smuzhiyun      It uses the command line, config file, and default values in the
5990*4882a593Smuzhiyun      correct order of precedence to determine the gamma value.  It is
5991*4882a593Smuzhiyun      up to the driver to check the results to see that it supports
5992*4882a593Smuzhiyun      them.  If not the <function>ChipPreInit()</function> function should
5993*4882a593Smuzhiyun      return <constant>FALSE</constant>.
5994*4882a593Smuzhiyun	    </para>
5995*4882a593Smuzhiyun
5996*4882a593Smuzhiyun	    <para>
5997*4882a593Smuzhiyun      On success, this function prints a message showing the gamma
5998*4882a593Smuzhiyun      value selected, and returns <constant>TRUE</constant>.
5999*4882a593Smuzhiyun	    </para>
6000*4882a593Smuzhiyun
6001*4882a593Smuzhiyun	    <para>
6002*4882a593Smuzhiyun      On failure it prints an error message and returns <constant>FALSE</constant>.
6003*4882a593Smuzhiyun	    </para>
6004*4882a593Smuzhiyun
6005*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6006*4882a593Smuzhiyun
6007*4882a593Smuzhiyun
6008*4882a593Smuzhiyun      <blockquote><para>
6009*4882a593Smuzhiyun	  <programlisting>
6010*4882a593Smuzhiyun    void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y);
6011*4882a593Smuzhiyun	  </programlisting>
6012*4882a593Smuzhiyun	  <blockquote><para>
6013*4882a593Smuzhiyun      This function sets the <structfield>xDpi</structfield> and <structfield>yDpi</structfield>
6014*4882a593Smuzhiyun      fields of the <structname>ScrnInfoRec</structname>.  The driver can specify
6015*4882a593Smuzhiyun      preferred defaults by setting <parameter>x</parameter> and <parameter>y</parameter>
6016*4882a593Smuzhiyun      to non-zero values.  The <option>-dpi</option> command line option
6017*4882a593Smuzhiyun      overrides all other settings.  Otherwise, if the
6018*4882a593Smuzhiyun      <emphasis>DisplaySize</emphasis> entry is present in the screen's &k.monitor;
6019*4882a593Smuzhiyun      config file section, it is used together with the virtual size to
6020*4882a593Smuzhiyun      calculate the dpi values.  This function should be called after
6021*4882a593Smuzhiyun      all the mode resolution has been done.
6022*4882a593Smuzhiyun	    </para>
6023*4882a593Smuzhiyun
6024*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6025*4882a593Smuzhiyun
6026*4882a593Smuzhiyun      <blockquote><para>
6027*4882a593Smuzhiyun	  <programlisting>
6028*4882a593Smuzhiyun    void xf86SetBlackWhitePixels(ScrnInfoPtr pScrn);
6029*4882a593Smuzhiyun	  </programlisting>
6030*4882a593Smuzhiyun	  <blockquote><para>
6031*4882a593Smuzhiyun      This functions sets the <structfield>blackPixel</structfield> and
6032*4882a593Smuzhiyun      <structfield>whitePixel</structfield> fields of the <structname>ScrnInfoRec</structname>
6033*4882a593Smuzhiyun      according to whether or not the <option>-flipPixels</option> command
6034*4882a593Smuzhiyun      line options is present.
6035*4882a593Smuzhiyun	    </para>
6036*4882a593Smuzhiyun
6037*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6038*4882a593Smuzhiyun
6039*4882a593Smuzhiyun      <blockquote><para>
6040*4882a593Smuzhiyun	  <programlisting>
6041*4882a593Smuzhiyun    const char *xf86GetVisualName(int visual);
6042*4882a593Smuzhiyun	  </programlisting>
6043*4882a593Smuzhiyun	  <blockquote><para>
6044*4882a593Smuzhiyun      Returns a printable string with the visual name matching the
6045*4882a593Smuzhiyun      numerical visual class provided.  If the value is outside the
6046*4882a593Smuzhiyun      range of valid visual classes, <constant>NULL</constant> is returned.
6047*4882a593Smuzhiyun	    </para>
6048*4882a593Smuzhiyun
6049*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6050*4882a593Smuzhiyun
6051*4882a593Smuzhiyun    </sect2>
6052*4882a593Smuzhiyun
6053*4882a593Smuzhiyun    <sect2>
6054*4882a593Smuzhiyun      <title>Primary Mode functions</title>
6055*4882a593Smuzhiyun
6056*4882a593Smuzhiyun      <para>
6057*4882a593SmuzhiyunThe primary mode helper functions are those which would normally be
6058*4882a593Smuzhiyunused by a driver, unless it has unusual requirements which cannot
6059*4882a593Smuzhiyunbe catered for the by the helpers.
6060*4882a593Smuzhiyun      </para>
6061*4882a593Smuzhiyun
6062*4882a593Smuzhiyun      <blockquote><para>
6063*4882a593Smuzhiyun	  <programlisting>
6064*4882a593Smuzhiyun    int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
6065*4882a593Smuzhiyun                          char **modeNames, ClockRangePtr clockRanges,
6066*4882a593Smuzhiyun                          int *linePitches, int minPitch, int maxPitch,
6067*4882a593Smuzhiyun                          int pitchInc, int minHeight, int maxHeight,
6068*4882a593Smuzhiyun                          int virtualX, int virtualY,
6069*4882a593Smuzhiyun                          unsigned long apertureSize,
6070*4882a593Smuzhiyun                          LookupModeFlags strategy);
6071*4882a593Smuzhiyun	  </programlisting>
6072*4882a593Smuzhiyun	  <blockquote><para>
6073*4882a593Smuzhiyun      This function basically selects the set of modes to use based on
6074*4882a593Smuzhiyun      those available and the various constraints.  It also sets some
6075*4882a593Smuzhiyun      other related parameters.  It is normally called near the end of
6076*4882a593Smuzhiyun      the <function>ChipPreInit()</function> function.
6077*4882a593Smuzhiyun	    </para>
6078*4882a593Smuzhiyun
6079*4882a593Smuzhiyun	    <para>
6080*4882a593Smuzhiyun      The parameters passed to the function are:
6081*4882a593Smuzhiyun
6082*4882a593Smuzhiyun	      <variablelist>
6083*4882a593Smuzhiyun		<varlistentry>
6084*4882a593Smuzhiyun		  <term><parameter>availModes</parameter></term>
6085*4882a593Smuzhiyun		  <listitem><para>
6086*4882a593Smuzhiyun		List of modes available for the monitor.
6087*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6088*4882a593Smuzhiyun
6089*4882a593Smuzhiyun		<varlistentry>
6090*4882a593Smuzhiyun		  <term><parameter>modeNames</parameter></term>
6091*4882a593Smuzhiyun		  <listitem><para>
6092*4882a593Smuzhiyun		List of mode names that the screen is requesting.
6093*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6094*4882a593Smuzhiyun
6095*4882a593Smuzhiyun		<varlistentry>
6096*4882a593Smuzhiyun		  <term><parameter>clockRanges</parameter></term>
6097*4882a593Smuzhiyun		  <listitem><para>
6098*4882a593Smuzhiyun		A list of clock ranges allowed by the driver.  Each
6099*4882a593Smuzhiyun		range includes whether interlaced or multiscan modes
6100*4882a593Smuzhiyun		are supported for that range.  See below for more on
6101*4882a593Smuzhiyun		<parameter>clockRanges</parameter>.
6102*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6103*4882a593Smuzhiyun
6104*4882a593Smuzhiyun		<varlistentry>
6105*4882a593Smuzhiyun		  <term><parameter>linePitches</parameter></term>
6106*4882a593Smuzhiyun		  <listitem><para>
6107*4882a593Smuzhiyun		List of line pitches supported by the driver.
6108*4882a593Smuzhiyun		This is optional and should be <constant>NULL</constant> when
6109*4882a593Smuzhiyun		not used.
6110*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6111*4882a593Smuzhiyun
6112*4882a593Smuzhiyun		<varlistentry>
6113*4882a593Smuzhiyun		  <term><parameter>minPitch</parameter></term>
6114*4882a593Smuzhiyun		  <listitem><para>
6115*4882a593Smuzhiyun		Minimum line pitch supported by the driver.  This must
6116*4882a593Smuzhiyun		be supplied when <parameter>linePitches</parameter> is
6117*4882a593Smuzhiyun		<constant>NULL</constant>, and is ignored otherwise.
6118*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6119*4882a593Smuzhiyun
6120*4882a593Smuzhiyun		<varlistentry>
6121*4882a593Smuzhiyun		  <term><parameter>maxPitch</parameter></term>
6122*4882a593Smuzhiyun		  <listitem><para>
6123*4882a593Smuzhiyun		Maximum line pitch supported by the driver.  This is
6124*4882a593Smuzhiyun		required when <parameter>minPitch</parameter> is required.
6125*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6126*4882a593Smuzhiyun
6127*4882a593Smuzhiyun		<varlistentry>
6128*4882a593Smuzhiyun		  <term><parameter>pitchInc</parameter></term>
6129*4882a593Smuzhiyun		  <listitem><para>
6130*4882a593Smuzhiyun		Granularity of horizontal pitch values as supported by
6131*4882a593Smuzhiyun		the chipset.  This is expressed in bits.  This must be
6132*4882a593Smuzhiyun		supplied.
6133*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6134*4882a593Smuzhiyun
6135*4882a593Smuzhiyun		<varlistentry>
6136*4882a593Smuzhiyun		  <term><parameter>minHeight</parameter></term>
6137*4882a593Smuzhiyun		  <listitem><para>
6138*4882a593Smuzhiyun		minimum virtual height allowed.  If zero, no limit is
6139*4882a593Smuzhiyun		imposed.
6140*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6141*4882a593Smuzhiyun
6142*4882a593Smuzhiyun		<varlistentry>
6143*4882a593Smuzhiyun		  <term><parameter>maxHeight</parameter></term>
6144*4882a593Smuzhiyun		  <listitem><para>
6145*4882a593Smuzhiyun		maximum virtual height allowed.  If zero, no limit is
6146*4882a593Smuzhiyun		imposed.
6147*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6148*4882a593Smuzhiyun
6149*4882a593Smuzhiyun		<varlistentry>
6150*4882a593Smuzhiyun		  <term><parameter>virtualX</parameter></term>
6151*4882a593Smuzhiyun		  <listitem><para>
6152*4882a593Smuzhiyun		If greater than zero, this is the virtual width value
6153*4882a593Smuzhiyun		that will be used.  Otherwise, the virtual width is
6154*4882a593Smuzhiyun		chosen to be the smallest that can accommodate the modes
6155*4882a593Smuzhiyun		selected.
6156*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6157*4882a593Smuzhiyun
6158*4882a593Smuzhiyun		<varlistentry>
6159*4882a593Smuzhiyun		  <term><parameter>virtualY</parameter></term>
6160*4882a593Smuzhiyun		  <listitem><para>
6161*4882a593Smuzhiyun		If greater than zero, this is the virtual height value
6162*4882a593Smuzhiyun		that will be used.  Otherwise, the virtual height is
6163*4882a593Smuzhiyun		chosen to be the smallest that can accommodate the modes
6164*4882a593Smuzhiyun		selected.
6165*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6166*4882a593Smuzhiyun
6167*4882a593Smuzhiyun		<varlistentry>
6168*4882a593Smuzhiyun		  <term><parameter>apertureSize</parameter></term>
6169*4882a593Smuzhiyun		  <listitem><para>
6170*4882a593Smuzhiyun		The size (in bytes) of the aperture used to access video
6171*4882a593Smuzhiyun		memory.
6172*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6173*4882a593Smuzhiyun
6174*4882a593Smuzhiyun		<varlistentry>
6175*4882a593Smuzhiyun		  <term><parameter>strategy</parameter></term>
6176*4882a593Smuzhiyun		  <listitem><para>
6177*4882a593Smuzhiyun		The strategy to use when choosing from multiple modes
6178*4882a593Smuzhiyun		with the same name.  The options are:
6179*4882a593Smuzhiyun
6180*4882a593Smuzhiyun		      <variablelist>
6181*4882a593Smuzhiyun			<varlistentry>
6182*4882a593Smuzhiyun			  <term><constant>LOOKUP_DEFAULT</constant></term>
6183*4882a593Smuzhiyun			  <listitem><para>???
6184*4882a593Smuzhiyun			    </para></listitem></varlistentry>
6185*4882a593Smuzhiyun			<varlistentry>
6186*4882a593Smuzhiyun			  <term><constant>LOOKUP_BEST_REFRESH</constant></term>
6187*4882a593Smuzhiyun			  <listitem><para>mode with best refresh rate
6188*4882a593Smuzhiyun			    </para></listitem></varlistentry>
6189*4882a593Smuzhiyun			<varlistentry>
6190*4882a593Smuzhiyun			  <term><constant>LOOKUP_CLOSEST_CLOCK</constant></term>
6191*4882a593Smuzhiyun			  <listitem><para>mode with closest matching clock
6192*4882a593Smuzhiyun			    </para></listitem></varlistentry>
6193*4882a593Smuzhiyun			<varlistentry>
6194*4882a593Smuzhiyun			  <term><constant>LOOKUP_LIST_ORDER</constant></term>
6195*4882a593Smuzhiyun			  <listitem><para>first usable mode in list
6196*4882a593Smuzhiyun			    </para></listitem></varlistentry>
6197*4882a593Smuzhiyun		      </variablelist>
6198*4882a593Smuzhiyun
6199*4882a593Smuzhiyun		The following options can also be combined (OR'ed) with
6200*4882a593Smuzhiyun		one of the above:
6201*4882a593Smuzhiyun
6202*4882a593Smuzhiyun		      <variablelist>
6203*4882a593Smuzhiyun			<varlistentry>
6204*4882a593Smuzhiyun			  <term><constant>LOOKUP_CLKDIV2</constant></term>
6205*4882a593Smuzhiyun			  <listitem><para>Allow halved clocks
6206*4882a593Smuzhiyun			    </para></listitem></varlistentry>
6207*4882a593Smuzhiyun			<varlistentry>
6208*4882a593Smuzhiyun			  <term><constant>LOOKUP_OPTIONAL_TOLERANCES</constant></term>
6209*4882a593Smuzhiyun			  <listitem><para>
6210*4882a593Smuzhiyun		      Allow missing horizontal sync and/or vertical refresh
6211*4882a593Smuzhiyun		      ranges in the xorg.conf Monitor section
6212*4882a593Smuzhiyun			    </para></listitem></varlistentry>
6213*4882a593Smuzhiyun		      </variablelist>
6214*4882a593Smuzhiyun
6215*4882a593Smuzhiyun		<constant>LOOKUP_OPTIONAL_TOLERANCES</constant> should only be
6216*4882a593Smuzhiyun		specified when the driver can ensure all modes it generates
6217*4882a593Smuzhiyun		can sync on, or at least not damage, the monitor or digital
6218*4882a593Smuzhiyun		flat panel.  Horizontal sync and/or vertical refresh ranges
6219*4882a593Smuzhiyun		specified by the user will still be honoured (and acted upon).
6220*4882a593Smuzhiyun
6221*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6222*4882a593Smuzhiyun	      </variablelist>
6223*4882a593Smuzhiyun	    </para>
6224*4882a593Smuzhiyun
6225*4882a593Smuzhiyun	    <para>
6226*4882a593Smuzhiyun      This function requires that the following fields of the
6227*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname> are initialised prior to calling it:
6228*4882a593Smuzhiyun
6229*4882a593Smuzhiyun	      <variablelist>
6230*4882a593Smuzhiyun		<varlistentry>
6231*4882a593Smuzhiyun		  <term><structfield>clock[]</structfield></term>
6232*4882a593Smuzhiyun		  <listitem><para>
6233*4882a593Smuzhiyun		      List of discrete clocks (when non-programmable)
6234*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6235*4882a593Smuzhiyun		<varlistentry>
6236*4882a593Smuzhiyun		  <term><structfield>numClocks</structfield></term>
6237*4882a593Smuzhiyun		  <listitem><para>
6238*4882a593Smuzhiyun		      Number of discrete clocks (when non-programmable)
6239*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6240*4882a593Smuzhiyun		<varlistentry>
6241*4882a593Smuzhiyun		  <term><structfield>progClock</structfield></term>
6242*4882a593Smuzhiyun		  <listitem><para>
6243*4882a593Smuzhiyun		      Whether the clock is programmable or not
6244*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6245*4882a593Smuzhiyun		<varlistentry>
6246*4882a593Smuzhiyun		  <term><structfield>monitor</structfield></term>
6247*4882a593Smuzhiyun		  <listitem><para>
6248*4882a593Smuzhiyun		      Pointer to the applicable xorg.conf monitor section
6249*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6250*4882a593Smuzhiyun		<varlistentry>
6251*4882a593Smuzhiyun		  <term><structfield>fdFormat</structfield></term>
6252*4882a593Smuzhiyun		  <listitem><para>
6253*4882a593Smuzhiyun		      Format of the screen buffer
6254*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6255*4882a593Smuzhiyun		<varlistentry>
6256*4882a593Smuzhiyun		  <term><structfield>videoRam</structfield></term>
6257*4882a593Smuzhiyun		  <listitem><para>
6258*4882a593Smuzhiyun		      total video memory size (in bytes)
6259*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6260*4882a593Smuzhiyun		<varlistentry>
6261*4882a593Smuzhiyun		  <term><structfield>xInc</structfield></term>
6262*4882a593Smuzhiyun		  <listitem><para>
6263*4882a593Smuzhiyun		      Horizontal timing increment in pixels (defaults to 8)
6264*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6265*4882a593Smuzhiyun	      </variablelist>
6266*4882a593Smuzhiyun	    </para>
6267*4882a593Smuzhiyun
6268*4882a593Smuzhiyun	    <para>
6269*4882a593Smuzhiyun      This function fills in the following <structname>ScrnInfoRec</structname>
6270*4882a593Smuzhiyun      fields:
6271*4882a593Smuzhiyun
6272*4882a593Smuzhiyun	      <variablelist>
6273*4882a593Smuzhiyun		<varlistentry>
6274*4882a593Smuzhiyun		  <term><structfield>modePool</structfield></term>
6275*4882a593Smuzhiyun		  <listitem><para>
6276*4882a593Smuzhiyun		A subset of the modes available to the monitor which
6277*4882a593Smuzhiyun                are compatible with the driver.
6278*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6279*4882a593Smuzhiyun
6280*4882a593Smuzhiyun		<varlistentry>
6281*4882a593Smuzhiyun		  <term><structfield>modes</structfield></term>
6282*4882a593Smuzhiyun		  <listitem><para>
6283*4882a593Smuzhiyun		One mode entry for each of the requested modes, with
6284*4882a593Smuzhiyun                the status field of each filled in to indicate if
6285*4882a593Smuzhiyun                the mode has been accepted or not.  This list of
6286*4882a593Smuzhiyun                modes is a circular list.
6287*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6288*4882a593Smuzhiyun
6289*4882a593Smuzhiyun		<varlistentry>
6290*4882a593Smuzhiyun		  <term><structfield>virtualX</structfield></term>
6291*4882a593Smuzhiyun		  <listitem><para>
6292*4882a593Smuzhiyun		The resulting virtual width.
6293*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6294*4882a593Smuzhiyun
6295*4882a593Smuzhiyun		<varlistentry>
6296*4882a593Smuzhiyun		  <term><structfield>virtualY</structfield></term>
6297*4882a593Smuzhiyun		  <listitem><para>
6298*4882a593Smuzhiyun		The resulting virtual height.
6299*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6300*4882a593Smuzhiyun
6301*4882a593Smuzhiyun		<varlistentry>
6302*4882a593Smuzhiyun		  <term><structfield>displayWidth</structfield></term>
6303*4882a593Smuzhiyun		  <listitem><para>
6304*4882a593Smuzhiyun		The resulting line pitch.
6305*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6306*4882a593Smuzhiyun
6307*4882a593Smuzhiyun	      </variablelist>
6308*4882a593Smuzhiyun	    </para>
6309*4882a593Smuzhiyun
6310*4882a593Smuzhiyun	    <para>
6311*4882a593Smuzhiyun      The first stage of this function checks that the
6312*4882a593Smuzhiyun      <parameter>virtualX</parameter> and <parameter>virtualY</parameter> values
6313*4882a593Smuzhiyun      supplied (if greater than zero) are consistent with the line pitch
6314*4882a593Smuzhiyun      and <parameter>maxHeight</parameter> limitations.  If not, an error
6315*4882a593Smuzhiyun      message is printed, and the return value is <constant>-1</constant>.
6316*4882a593Smuzhiyun	    </para>
6317*4882a593Smuzhiyun
6318*4882a593Smuzhiyun	    <para>
6319*4882a593Smuzhiyun      The second stage sets up the mode pool, eliminating immediately
6320*4882a593Smuzhiyun      any modes that exceed the driver's line pitch limits, and also
6321*4882a593Smuzhiyun      the virtual width and height limits (if greater than zero).  For
6322*4882a593Smuzhiyun      each mode removed an informational message is printed at verbosity
6323*4882a593Smuzhiyun      level <constant>2</constant>.  If the mode pool ends up being empty,
6324*4882a593Smuzhiyun      a warning message is printed, and the return value is
6325*4882a593Smuzhiyun      <constant>0</constant>.
6326*4882a593Smuzhiyun	    </para>
6327*4882a593Smuzhiyun
6328*4882a593Smuzhiyun	    <para>
6329*4882a593Smuzhiyun      The final stage is to lookup each mode name, and fill in the remaining
6330*4882a593Smuzhiyun      parameters.  If an error condition is encountered, a message is
6331*4882a593Smuzhiyun      printed, and the return value is <constant>-1</constant>.  Otherwise,
6332*4882a593Smuzhiyun      the return value is the number of valid modes found
6333*4882a593Smuzhiyun      (<constant>0</constant> if none are found).
6334*4882a593Smuzhiyun	    </para>
6335*4882a593Smuzhiyun
6336*4882a593Smuzhiyun	    <para>
6337*4882a593Smuzhiyun      Even if the supplied mode names include duplicates, no two names will
6338*4882a593Smuzhiyun      ever match the same mode.  Furthermore, if the supplied mode names do not
6339*4882a593Smuzhiyun      yield a valid mode (including the case where no names are passed at all),
6340*4882a593Smuzhiyun      the function will continue looking through the mode pool until it finds
6341*4882a593Smuzhiyun      a mode that survives all checks, or until the mode pool is exhausted.
6342*4882a593Smuzhiyun	    </para>
6343*4882a593Smuzhiyun
6344*4882a593Smuzhiyun	    <para>
6345*4882a593Smuzhiyun      A message is only printed by this function when a fundamental
6346*4882a593Smuzhiyun      problem is found.  It is intended that this function may be called
6347*4882a593Smuzhiyun      more than once if there is more than one set of constraints that
6348*4882a593Smuzhiyun      the driver can work within.
6349*4882a593Smuzhiyun	    </para>
6350*4882a593Smuzhiyun
6351*4882a593Smuzhiyun	    <para>
6352*4882a593Smuzhiyun      If this function returns <constant>-1</constant>, the
6353*4882a593Smuzhiyun      <function>ChipPreInit()</function> function should return
6354*4882a593Smuzhiyun      <constant>FALSE</constant>.
6355*4882a593Smuzhiyun	    </para>
6356*4882a593Smuzhiyun
6357*4882a593Smuzhiyun	    <para>
6358*4882a593Smuzhiyun      <parameter>clockRanges</parameter> is a linked list of clock ranges
6359*4882a593Smuzhiyun      allowed by the driver.  If a mode doesn't fit in any of the defined
6360*4882a593Smuzhiyun      <parameter>clockRanges</parameter>, it is rejected.  The first
6361*4882a593Smuzhiyun      <literal remap="tt">clockRange</literal> that matches all requirements is used.
6362*4882a593Smuzhiyun      This structure needs to be initialized to NULL when allocated.
6363*4882a593Smuzhiyun	    </para>
6364*4882a593Smuzhiyun
6365*4882a593Smuzhiyun	    <para>
6366*4882a593Smuzhiyun      <parameter>clockRanges</parameter> contains the following fields:
6367*4882a593Smuzhiyun
6368*4882a593Smuzhiyun	      <variablelist>
6369*4882a593Smuzhiyun		<varlistentry>
6370*4882a593Smuzhiyun		  <term><structfield>minClock</structfield></term>
6371*4882a593Smuzhiyun		  <term><structfield>maxClock</structfield></term>
6372*4882a593Smuzhiyun		  <listitem><para>
6373*4882a593Smuzhiyun		The lower and upper mode clock bounds for which the rest
6374*4882a593Smuzhiyun		of the <structname>clockRange</structname> parameters apply.
6375*4882a593Smuzhiyun		Since these are the mode clocks, they are not scaled
6376*4882a593Smuzhiyun		with the <structfield>ClockMulFactor</structfield> and
6377*4882a593Smuzhiyun		<structfield>ClockDivFactor</structfield>.  It is up to the driver
6378*4882a593Smuzhiyun		to adjust these values if they depend on the clock
6379*4882a593Smuzhiyun		scaling factors.
6380*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6381*4882a593Smuzhiyun
6382*4882a593Smuzhiyun		<varlistentry>
6383*4882a593Smuzhiyun		  <term><structfield>clockIndex</structfield></term>
6384*4882a593Smuzhiyun		  <listitem><para>
6385*4882a593Smuzhiyun		(not used yet) <constant>-1</constant> for programmable clocks
6386*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6387*4882a593Smuzhiyun
6388*4882a593Smuzhiyun		<varlistentry>
6389*4882a593Smuzhiyun		  <term><structfield>interlaceAllowed</structfield></term>
6390*4882a593Smuzhiyun		  <listitem><para>
6391*4882a593Smuzhiyun		<constant>TRUE</constant> if interlacing is allowed for this
6392*4882a593Smuzhiyun		range
6393*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6394*4882a593Smuzhiyun
6395*4882a593Smuzhiyun		<varlistentry>
6396*4882a593Smuzhiyun		  <term><structfield>doubleScanAllowed</structfield></term>
6397*4882a593Smuzhiyun		  <listitem><para>
6398*4882a593Smuzhiyun		<constant>TRUE</constant> if doublescan or multiscan is allowed
6399*4882a593Smuzhiyun		for this range
6400*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6401*4882a593Smuzhiyun
6402*4882a593Smuzhiyun		<varlistentry>
6403*4882a593Smuzhiyun		  <term><structfield>ClockMulFactor</structfield></term>
6404*4882a593Smuzhiyun		  <term><structfield>ClockDivFactor</structfield></term>
6405*4882a593Smuzhiyun		  <listitem><para>
6406*4882a593Smuzhiyun		Scaling factors that are applied to the mode clocks ONLY
6407*4882a593Smuzhiyun		before selecting a clock index (when there is no
6408*4882a593Smuzhiyun		programmable clock) or a <structfield>SynthClock</structfield>
6409*4882a593Smuzhiyun		value.  This is useful for drivers that support pixel
6410*4882a593Smuzhiyun		multiplexing or that need to scale the clocks because
6411*4882a593Smuzhiyun		of hardware restrictions (like sending 24bpp data to an
6412*4882a593Smuzhiyun		8 bit RAMDAC using a tripled clock).
6413*4882a593Smuzhiyun		    </para>
6414*4882a593Smuzhiyun
6415*4882a593Smuzhiyun		    <para>
6416*4882a593Smuzhiyun		Note that these parameters describe what must be done
6417*4882a593Smuzhiyun		to the mode clock to achieve the data transport clock
6418*4882a593Smuzhiyun		between graphics controller and RAMDAC.  For example
6419*4882a593Smuzhiyun		for <literal remap="tt">2:1</literal> pixel multiplexing, two pixels
6420*4882a593Smuzhiyun		are sent to the RAMDAC on each clock.  This allows the
6421*4882a593Smuzhiyun		RAMDAC clock to be half of the actual pixel clock.
6422*4882a593Smuzhiyun		Hence, <code>ClockMulFactor=1</code> and
6423*4882a593Smuzhiyun		<code>ClockDivFactor=2</code>.  This means that the
6424*4882a593Smuzhiyun		clock used for clock selection (ie, determining the
6425*4882a593Smuzhiyun		correct clock index from the list of discrete clocks)
6426*4882a593Smuzhiyun		or for the <structfield>SynthClock</structfield> field in case of
6427*4882a593Smuzhiyun		a programmable clock is:  (<code>mode-&gt;Clock *
6428*4882a593Smuzhiyun		ClockMulFactor) / ClockDivFactor</code>.
6429*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6430*4882a593Smuzhiyun
6431*4882a593Smuzhiyun		<varlistentry>
6432*4882a593Smuzhiyun		  <term><structfield>PrivFlags</structfield></term>
6433*4882a593Smuzhiyun		  <listitem><para>
6434*4882a593Smuzhiyun		This field is copied into the
6435*4882a593Smuzhiyun		<literal remap="tt">mode-&gt;PrivFlags</literal> field when this
6436*4882a593Smuzhiyun		<literal remap="tt">clockRange</literal> is selected by
6437*4882a593Smuzhiyun		<function>xf86ValidateModes()</function>.  It allows the
6438*4882a593Smuzhiyun		driver to find out what clock range was selected, so it
6439*4882a593Smuzhiyun		knows it needs to set up pixel multiplexing or any other
6440*4882a593Smuzhiyun		range-dependent feature.  This field is purely
6441*4882a593Smuzhiyun		driver-defined: it may contain flag bits, an index or
6442*4882a593Smuzhiyun		anything else (as long as it is an <literal remap="tt">INT</literal>).
6443*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6444*4882a593Smuzhiyun	      </variablelist>
6445*4882a593Smuzhiyun	    </para>
6446*4882a593Smuzhiyun
6447*4882a593Smuzhiyun	    <para>
6448*4882a593Smuzhiyun      Note that the <structfield>mode-&gt;SynthClock</structfield> field is always
6449*4882a593Smuzhiyun      filled in by <function>xf86ValidateModes()</function>: it will contain
6450*4882a593Smuzhiyun      the <quote>data transport clock</quote>, which is the clock that will have
6451*4882a593Smuzhiyun      to be programmed in the chip when it has a programmable clock, or
6452*4882a593Smuzhiyun      the clock that will be picked from the clocks list when it is not
6453*4882a593Smuzhiyun      a programmable one.  Thus:
6454*4882a593Smuzhiyun
6455*4882a593Smuzhiyun	      <programlisting>
6456*4882a593Smuzhiyun    mode-&gt;SynthClock = (mode-&gt;Clock * ClockMulFactor) / ClockDivFactor
6457*4882a593Smuzhiyun	      </programlisting>
6458*4882a593Smuzhiyun	    </para>
6459*4882a593Smuzhiyun
6460*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6461*4882a593Smuzhiyun
6462*4882a593Smuzhiyun      <blockquote><para>
6463*4882a593Smuzhiyun	  <programlisting>
6464*4882a593Smuzhiyun    void xf86PruneDriverModes(ScrnInfoPtr scrp);
6465*4882a593Smuzhiyun	  </programlisting>
6466*4882a593Smuzhiyun	  <blockquote><para>
6467*4882a593Smuzhiyun      This function deletes modes in the modes field of the
6468*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname> that have been marked as invalid.
6469*4882a593Smuzhiyun      This is normally run after having run
6470*4882a593Smuzhiyun      <function>xf86ValidateModes()</function> for the last time.  For each
6471*4882a593Smuzhiyun      mode that is deleted, a warning message is printed out indicating
6472*4882a593Smuzhiyun      the reason for it being deleted.
6473*4882a593Smuzhiyun	    </para>
6474*4882a593Smuzhiyun
6475*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6476*4882a593Smuzhiyun
6477*4882a593Smuzhiyun      <blockquote><para>
6478*4882a593Smuzhiyun	  <programlisting>
6479*4882a593Smuzhiyun    void xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags);
6480*4882a593Smuzhiyun	  </programlisting>
6481*4882a593Smuzhiyun	  <blockquote><para>
6482*4882a593Smuzhiyun      This function fills in the <structname>Crtc*</structname> fields for all
6483*4882a593Smuzhiyun      the modes in the <structfield>modes</structfield> field of the
6484*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname>.  The <parameter>adjustFlags</parameter>
6485*4882a593Smuzhiyun      parameter determines how the vertical CRTC values are scaled for
6486*4882a593Smuzhiyun      interlaced modes.  They are halved if it is
6487*4882a593Smuzhiyun      <constant>INTERLACE_HALVE_V</constant>.  The vertical CRTC values are
6488*4882a593Smuzhiyun      doubled for doublescan modes, and are further multiplied by the
6489*4882a593Smuzhiyun      <literal remap="tt">VScan</literal> value.
6490*4882a593Smuzhiyun	    </para>
6491*4882a593Smuzhiyun
6492*4882a593Smuzhiyun	    <para>
6493*4882a593Smuzhiyun      This function is normally called after calling
6494*4882a593Smuzhiyun      <function>xf86PruneDriverModes()</function>.
6495*4882a593Smuzhiyun	    </para>
6496*4882a593Smuzhiyun
6497*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6498*4882a593Smuzhiyun
6499*4882a593Smuzhiyun      <blockquote><para>
6500*4882a593Smuzhiyun	  <programlisting>
6501*4882a593Smuzhiyun    void xf86PrintModes(ScrnInfoPtr scrp);
6502*4882a593Smuzhiyun	  </programlisting>
6503*4882a593Smuzhiyun	  <blockquote><para>
6504*4882a593Smuzhiyun      This function prints out the virtual size setting, and the line
6505*4882a593Smuzhiyun      pitch being used.  It also prints out two lines for each mode being
6506*4882a593Smuzhiyun      used.  The first line includes the mode's pixel clock, horizontal sync
6507*4882a593Smuzhiyun      rate, refresh rate, and whether it is interlaced, doublescanned and/or
6508*4882a593Smuzhiyun      multi-scanned.  The second line is the mode's Modeline.
6509*4882a593Smuzhiyun	    </para>
6510*4882a593Smuzhiyun
6511*4882a593Smuzhiyun	    <para>
6512*4882a593Smuzhiyun      This function is normally called after calling
6513*4882a593Smuzhiyun      <function>xf86SetCrtcForModes()</function>.
6514*4882a593Smuzhiyun	    </para>
6515*4882a593Smuzhiyun
6516*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6517*4882a593Smuzhiyun
6518*4882a593Smuzhiyun    </sect2>
6519*4882a593Smuzhiyun
6520*4882a593Smuzhiyun    <sect2>
6521*4882a593Smuzhiyun      <title>Secondary Mode functions</title>
6522*4882a593Smuzhiyun
6523*4882a593Smuzhiyun      <para>
6524*4882a593SmuzhiyunThe secondary mode helper functions are functions which are normally
6525*4882a593Smuzhiyunused by the primary mode helper functions, and which are not normally
6526*4882a593Smuzhiyuncalled directly by a driver.  If a driver has unusual requirements
6527*4882a593Smuzhiyunand needs to do its own mode validation, it might be able to make
6528*4882a593Smuzhiyunuse of some of these secondary mode helper functions.
6529*4882a593Smuzhiyun      </para>
6530*4882a593Smuzhiyun
6531*4882a593Smuzhiyun      <blockquote><para>
6532*4882a593Smuzhiyun	  <programlisting>
6533*4882a593Smuzhiyun    const char *xf86ModeStatusToString(ModeStatus status);
6534*4882a593Smuzhiyun	  </programlisting>
6535*4882a593Smuzhiyun	  <blockquote><para>
6536*4882a593Smuzhiyun      This function converts the <parameter>status</parameter> value to a
6537*4882a593Smuzhiyun      descriptive printable string.
6538*4882a593Smuzhiyun	    </para>
6539*4882a593Smuzhiyun
6540*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6541*4882a593Smuzhiyun
6542*4882a593Smuzhiyun      <blockquote><para>
6543*4882a593Smuzhiyun	  <programlisting>
6544*4882a593Smuzhiyun    void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode);
6545*4882a593Smuzhiyun	  </programlisting>
6546*4882a593Smuzhiyun	  <blockquote><para>
6547*4882a593Smuzhiyun      This function deletes the <parameter>mode</parameter> given from the
6548*4882a593Smuzhiyun      <parameter>modeList</parameter>.  It never prints any messages, so it is
6549*4882a593Smuzhiyun      up to the caller to print a message if required.
6550*4882a593Smuzhiyun	    </para>
6551*4882a593Smuzhiyun
6552*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6553*4882a593Smuzhiyun    </sect2>
6554*4882a593Smuzhiyun
6555*4882a593Smuzhiyun    <sect2>
6556*4882a593Smuzhiyun      <title>Functions for handling strings and tokens</title>
6557*4882a593Smuzhiyun
6558*4882a593Smuzhiyun      <para>
6559*4882a593Smuzhiyun    Tables associating strings and numerical tokens combined with the
6560*4882a593Smuzhiyun    following functions provide a compact way of handling strings from
6561*4882a593Smuzhiyun    the config file, and for converting tokens into printable strings.
6562*4882a593Smuzhiyun    The table data structure is:
6563*4882a593Smuzhiyun
6564*4882a593Smuzhiyun	<programlisting>
6565*4882a593Smuzhiyuntypedef struct {
6566*4882a593Smuzhiyun    int                 token;
6567*4882a593Smuzhiyun    const char *        name;
6568*4882a593Smuzhiyun} SymTabRec, *SymTabPtr;
6569*4882a593Smuzhiyun	</programlisting>
6570*4882a593Smuzhiyun      </para>
6571*4882a593Smuzhiyun
6572*4882a593Smuzhiyun      <para>
6573*4882a593Smuzhiyun    A table is an initialised array of <structname>SymTabRec</structname>.  The
6574*4882a593Smuzhiyun    tokens must be non-negative integers.  Multiple names may be mapped
6575*4882a593Smuzhiyun    to a single token.  The table is terminated with an element with a
6576*4882a593Smuzhiyun    <structfield>token</structfield> value of <constant>-1</constant> and
6577*4882a593Smuzhiyun    <constant>NULL</constant> for the <structfield>name</structfield>.
6578*4882a593Smuzhiyun      </para>
6579*4882a593Smuzhiyun
6580*4882a593Smuzhiyun      <blockquote><para>
6581*4882a593Smuzhiyun	  <programlisting>
6582*4882a593Smuzhiyun    const char *xf86TokenToString(SymTabPtr table, int token);
6583*4882a593Smuzhiyun	  </programlisting>
6584*4882a593Smuzhiyun	  <blockquote><para>
6585*4882a593Smuzhiyun      This function returns the first string in <parameter>table</parameter>
6586*4882a593Smuzhiyun      that matches <parameter>token</parameter>.  If no match is found,
6587*4882a593Smuzhiyun      <constant>NULL</constant> is returned (NOTE, older versions of this
6588*4882a593Smuzhiyun      function would return the string "unknown" when no match is found).
6589*4882a593Smuzhiyun	    </para>
6590*4882a593Smuzhiyun
6591*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6592*4882a593Smuzhiyun
6593*4882a593Smuzhiyun      <blockquote><para>
6594*4882a593Smuzhiyun	  <programlisting>
6595*4882a593Smuzhiyun    int xf86StringToToken(SymTabPtr table, const char *string);
6596*4882a593Smuzhiyun	  </programlisting>
6597*4882a593Smuzhiyun	  <blockquote><para>
6598*4882a593Smuzhiyun      This function returns the first token in <parameter>table</parameter>
6599*4882a593Smuzhiyun      that matches <parameter>string</parameter>.  The
6600*4882a593Smuzhiyun      <function>xf86NameCmp()</function> function is used to determine the
6601*4882a593Smuzhiyun      match.  If no match is found, <constant>-1</constant> is returned.
6602*4882a593Smuzhiyun	    </para>
6603*4882a593Smuzhiyun
6604*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6605*4882a593Smuzhiyun
6606*4882a593Smuzhiyun    </sect2>
6607*4882a593Smuzhiyun
6608*4882a593Smuzhiyun    <sect2>
6609*4882a593Smuzhiyun      <title>Functions for finding which config file entries to use</title>
6610*4882a593Smuzhiyun
6611*4882a593Smuzhiyun      <para>
6612*4882a593Smuzhiyun    These functions can be used to select the appropriate config file
6613*4882a593Smuzhiyun    entries that match the detected hardware.  They are described above
6614*4882a593Smuzhiyun    in the <link linkend="probe">Probe</link> and
6615*4882a593Smuzhiyun    <link linkend="avail">Available Functions</link> sections.
6616*4882a593Smuzhiyun      </para>
6617*4882a593Smuzhiyun
6618*4882a593Smuzhiyun    </sect2>
6619*4882a593Smuzhiyun
6620*4882a593Smuzhiyun    <sect2>
6621*4882a593Smuzhiyun      <title>Probing discrete clocks on old hardware</title>
6622*4882a593Smuzhiyun
6623*4882a593Smuzhiyun      <para>
6624*4882a593Smuzhiyun    The <function>xf86GetClocks()</function> function may be used to assist
6625*4882a593Smuzhiyun    in finding the discrete pixel clock values on older hardware.
6626*4882a593Smuzhiyun      </para>
6627*4882a593Smuzhiyun
6628*4882a593Smuzhiyun      <blockquote><para>
6629*4882a593Smuzhiyun	  <programlisting>
6630*4882a593Smuzhiyun    void xf86GetClocks(ScrnInfoPtr pScrn, int num,
6631*4882a593Smuzhiyun                       Bool (*ClockFunc)(ScrnInfoPtr, int),
6632*4882a593Smuzhiyun                       void (*ProtectRegs)(ScrnInfoPtr, Bool),
6633*4882a593Smuzhiyun                       void (*BlankScreen)(ScrnInfoPtr, Bool),
6634*4882a593Smuzhiyun                       int vertsyncreg, int maskval, int knownclkindex,
6635*4882a593Smuzhiyun                       int knownclkvalue);
6636*4882a593Smuzhiyun	  </programlisting>
6637*4882a593Smuzhiyun	  <blockquote><para>
6638*4882a593Smuzhiyun      This function uses a comparative sampling method to measure the
6639*4882a593Smuzhiyun      discrete pixel clock values.  The number of discrete clocks to
6640*4882a593Smuzhiyun      measure is given by <parameter>num</parameter>.  <parameter>clockFunc</parameter>
6641*4882a593Smuzhiyun      is a function that selects the <parameter>n</parameter>'th clock.  It
6642*4882a593Smuzhiyun      should also save or restore any state affected by programming the
6643*4882a593Smuzhiyun      clocks when the index passed is <constant>CLK_REG_SAVE</constant> or
6644*4882a593Smuzhiyun      <constant>CLK_REG_RESTORE</constant>.  <parameter>ProtectRegs</parameter> is
6645*4882a593Smuzhiyun      a function that does whatever is required to protect the hardware
6646*4882a593Smuzhiyun      state while selecting a new clock.  <parameter>BlankScreen</parameter>
6647*4882a593Smuzhiyun      is a function that blanks the screen.  <parameter>vertsyncreg</parameter>
6648*4882a593Smuzhiyun      and <parameter>maskval</parameter> are the register and bitmask to
6649*4882a593Smuzhiyun      check for the presence of vertical sync pulses.
6650*4882a593Smuzhiyun      <parameter>knownclkindex</parameter> and <parameter>knownclkvalue</parameter>
6651*4882a593Smuzhiyun      are the index and value of a known clock.  These are the known
6652*4882a593Smuzhiyun      references on which the comparative measurements are based.  The
6653*4882a593Smuzhiyun      number of clocks probed is set in <structfield>pScrn-&gt;numClocks</structfield>,
6654*4882a593Smuzhiyun      and the probed clocks are set in the <structfield>pScrn-&gt;clock[]</structfield>
6655*4882a593Smuzhiyun      array.  All of the clock values are in units of kHz.
6656*4882a593Smuzhiyun	    </para>
6657*4882a593Smuzhiyun
6658*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6659*4882a593Smuzhiyun
6660*4882a593Smuzhiyun      <blockquote><para>
6661*4882a593Smuzhiyun	  <programlisting>
6662*4882a593Smuzhiyun    void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from);
6663*4882a593Smuzhiyun	  </programlisting>
6664*4882a593Smuzhiyun	  <blockquote><para>
6665*4882a593Smuzhiyun      Print out the pixel clocks <parameter>scrp-&gt;clock[]</parameter>.
6666*4882a593Smuzhiyun      <parameter>from</parameter> indicates whether the clocks were probed
6667*4882a593Smuzhiyun      or from the config file.
6668*4882a593Smuzhiyun	    </para>
6669*4882a593Smuzhiyun
6670*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6671*4882a593Smuzhiyun    </sect2>
6672*4882a593Smuzhiyun
6673*4882a593Smuzhiyun    <sect2>
6674*4882a593Smuzhiyun      <title>Other helper functions</title>
6675*4882a593Smuzhiyun
6676*4882a593Smuzhiyun      <blockquote><para>
6677*4882a593Smuzhiyun	  <programlisting>
6678*4882a593Smuzhiyun    Bool xf86IsUnblank(int mode);
6679*4882a593Smuzhiyun	  </programlisting>
6680*4882a593Smuzhiyun	  <blockquote><para>
6681*4882a593Smuzhiyun      Returns <constant>TRUE</constant> when the screen saver mode specified
6682*4882a593Smuzhiyun      by <parameter>mode</parameter> requires the screen be unblanked,
6683*4882a593Smuzhiyun      and <constant>FALSE</constant> otherwise.  The screen saver modes that
6684*4882a593Smuzhiyun      require blanking are <constant>SCREEN_SAVER_ON</constant> and
6685*4882a593Smuzhiyun      <constant>SCREEN_SAVER_CYCLE</constant>, and the screen saver modes that
6686*4882a593Smuzhiyun      require unblanking are <constant>SCREEN_SAVER_OFF</constant> and
6687*4882a593Smuzhiyun      <constant>SCREEN_SAVER_FORCER</constant>.  Drivers may call this helper
6688*4882a593Smuzhiyun      from their <function>SaveScreen()</function> function to interpret the
6689*4882a593Smuzhiyun      screen saver modes.
6690*4882a593Smuzhiyun	    </para>
6691*4882a593Smuzhiyun
6692*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6693*4882a593Smuzhiyun    </sect2>
6694*4882a593Smuzhiyun  </sect1>
6695*4882a593Smuzhiyun
6696*4882a593Smuzhiyun  <sect1>
6697*4882a593Smuzhiyun    <title>The vgahw module</title>
6698*4882a593Smuzhiyun
6699*4882a593Smuzhiyun    <para>
6700*4882a593SmuzhiyunThe vgahw modules provides an interface for saving, restoring and
6701*4882a593Smuzhiyunprogramming the standard VGA registers, and for handling VGA colourmaps.
6702*4882a593Smuzhiyun    </para>
6703*4882a593Smuzhiyun
6704*4882a593Smuzhiyun    <sect2>
6705*4882a593Smuzhiyun      <title>Data Structures</title>
6706*4882a593Smuzhiyun
6707*4882a593Smuzhiyun      <para>
6708*4882a593Smuzhiyun    The public data structures used by the vgahw module are
6709*4882a593Smuzhiyun    <structname>vgaRegRec</structname> and <structname>vgaHWRec</structname>.  They are
6710*4882a593Smuzhiyun    defined in <filename>vgaHW.h.</filename>
6711*4882a593Smuzhiyun      </para>
6712*4882a593Smuzhiyun
6713*4882a593Smuzhiyun    </sect2>
6714*4882a593Smuzhiyun
6715*4882a593Smuzhiyun    <sect2>
6716*4882a593Smuzhiyun      <title>General vgahw Functions</title>
6717*4882a593Smuzhiyun
6718*4882a593Smuzhiyun      <blockquote><para>
6719*4882a593Smuzhiyun	  <programlisting>
6720*4882a593Smuzhiyun    Bool vgaHWGetHWRec(ScrnInfoPtr pScrn);
6721*4882a593Smuzhiyun	  </programlisting>
6722*4882a593Smuzhiyun	  <blockquote><para>
6723*4882a593Smuzhiyun      This function allocates a <structname>vgaHWRec</structname> structure, and
6724*4882a593Smuzhiyun      hooks it into the <structname>ScrnInfoRec</structname>'s
6725*4882a593Smuzhiyun      <structfield>privates</structfield>.  Like all information hooked into the
6726*4882a593Smuzhiyun      <structfield>privates</structfield>, it is persistent, and only needs to be
6727*4882a593Smuzhiyun      allocated once per screen.  This function should normally be called
6728*4882a593Smuzhiyun      from the driver's <function>ChipPreInit()</function> function.  The
6729*4882a593Smuzhiyun      <structname>vgaHWRec</structname> is zero-allocated, and the following
6730*4882a593Smuzhiyun      fields are explicitly initialised:
6731*4882a593Smuzhiyun
6732*4882a593Smuzhiyun	      <variablelist>
6733*4882a593Smuzhiyun		<varlistentry>
6734*4882a593Smuzhiyun		  <term><structfield>ModeReg.DAC[]</structfield></term>
6735*4882a593Smuzhiyun		  <listitem><para>initialised with a default colourmap
6736*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6737*4882a593Smuzhiyun		<varlistentry>
6738*4882a593Smuzhiyun		  <term><structfield>ModeReg.Attribute[0x11]</structfield></term>
6739*4882a593Smuzhiyun		  <listitem><para>initialised with the default overscan index
6740*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6741*4882a593Smuzhiyun		<varlistentry>
6742*4882a593Smuzhiyun		  <term><structfield>ShowOverscan</structfield></term>
6743*4882a593Smuzhiyun		  <listitem><para>initialised according to the "ShowOverscan" option
6744*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6745*4882a593Smuzhiyun		<varlistentry>
6746*4882a593Smuzhiyun		  <term><structfield>paletteEnabled</structfield></term>
6747*4882a593Smuzhiyun		  <listitem><para>initialised to FALSE
6748*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6749*4882a593Smuzhiyun		<varlistentry>
6750*4882a593Smuzhiyun		  <term><structfield>cmapSaved</structfield></term>
6751*4882a593Smuzhiyun		  <listitem><para>initialised to FALSE
6752*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6753*4882a593Smuzhiyun		<varlistentry>
6754*4882a593Smuzhiyun		  <term><structfield>pScrn</structfield></term>
6755*4882a593Smuzhiyun		  <listitem><para>initialised to pScrn
6756*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6757*4882a593Smuzhiyun	      </variablelist>
6758*4882a593Smuzhiyun	    </para>
6759*4882a593Smuzhiyun
6760*4882a593Smuzhiyun	    <para>
6761*4882a593Smuzhiyun      In addition to the above, <function>vgaHWSetStdFuncs()</function> is
6762*4882a593Smuzhiyun      called to initialise the register access function fields with the
6763*4882a593Smuzhiyun      standard VGA set of functions.
6764*4882a593Smuzhiyun	    </para>
6765*4882a593Smuzhiyun
6766*4882a593Smuzhiyun	    <para>
6767*4882a593Smuzhiyun      Once allocated, a pointer to the <structname>vgaHWRec</structname> can be
6768*4882a593Smuzhiyun      obtained from the <literal remap="tt">ScrnInfoPtr</literal> with the
6769*4882a593Smuzhiyun      <literal remap="tt">VGAHWPTR(pScrn)</literal> macro.
6770*4882a593Smuzhiyun	    </para>
6771*4882a593Smuzhiyun
6772*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6773*4882a593Smuzhiyun
6774*4882a593Smuzhiyun      <blockquote><para>
6775*4882a593Smuzhiyun	  <programlisting>
6776*4882a593Smuzhiyun    void vgaHWFreeHWRec(ScrnInfoPtr pScrn);
6777*4882a593Smuzhiyun	  </programlisting>
6778*4882a593Smuzhiyun	  <blockquote><para>
6779*4882a593Smuzhiyun      This function frees a <structname>vgaHWRec</structname> structure.  It
6780*4882a593Smuzhiyun      should be called from a driver's <function>ChipFreeScreen()</function>
6781*4882a593Smuzhiyun      function.
6782*4882a593Smuzhiyun	    </para>
6783*4882a593Smuzhiyun
6784*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6785*4882a593Smuzhiyun
6786*4882a593Smuzhiyun      <blockquote><para>
6787*4882a593Smuzhiyun	  <programlisting>
6788*4882a593Smuzhiyun    Bool vgaHWSetRegCounts(ScrnInfoPtr pScrn, int numCRTC,
6789*4882a593Smuzhiyun                          int numSequencer, int numGraphics, int numAttribute);
6790*4882a593Smuzhiyun	  </programlisting>
6791*4882a593Smuzhiyun	  <blockquote><para>
6792*4882a593Smuzhiyun      This function allows the number of CRTC, Sequencer, Graphics and
6793*4882a593Smuzhiyun      Attribute registers to be changed.  This makes it possible for
6794*4882a593Smuzhiyun      extended registers to be saved and restored with
6795*4882a593Smuzhiyun      <function>vgaHWSave()</function> and <function>vgaHWRestore()</function>.
6796*4882a593Smuzhiyun      This function should be called after a <structname>vgaHWRec</structname>
6797*4882a593Smuzhiyun      has been allocated with <function>vgaHWGetHWRec()</function>.  The
6798*4882a593Smuzhiyun      default values are defined in <filename>vgaHW.h</filename> as follows:
6799*4882a593Smuzhiyun
6800*4882a593Smuzhiyun	      <programlisting>
6801*4882a593Smuzhiyun#define VGA_NUM_CRTC 25
6802*4882a593Smuzhiyun#define VGA_NUM_SEQ   5
6803*4882a593Smuzhiyun#define VGA_NUM_GFX   9
6804*4882a593Smuzhiyun#define VGA_NUM_ATTR 21
6805*4882a593Smuzhiyun	      </programlisting>
6806*4882a593Smuzhiyun	    </para>
6807*4882a593Smuzhiyun
6808*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6809*4882a593Smuzhiyun
6810*4882a593Smuzhiyun      <blockquote><para>
6811*4882a593Smuzhiyun	  <programlisting>
6812*4882a593Smuzhiyun    Bool vgaHWCopyReg(vgaRegPtr dst, vgaRegPtr src);
6813*4882a593Smuzhiyun	  </programlisting>
6814*4882a593Smuzhiyun	  <blockquote><para>
6815*4882a593Smuzhiyun      This function copies the contents of the VGA saved registers in
6816*4882a593Smuzhiyun      <parameter>src</parameter> to <parameter>dst</parameter>.  Note that it isn't
6817*4882a593Smuzhiyun      possible to simply do this with <function>memcpy()</function> (or
6818*4882a593Smuzhiyun      similar).  This function returns <constant>TRUE</constant> unless there
6819*4882a593Smuzhiyun      is a problem allocating space for the <structfield>CRTC</structfield> and
6820*4882a593Smuzhiyun      related fields in <parameter>dst</parameter>.
6821*4882a593Smuzhiyun	    </para>
6822*4882a593Smuzhiyun
6823*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6824*4882a593Smuzhiyun
6825*4882a593Smuzhiyun      <blockquote><para>
6826*4882a593Smuzhiyun	  <programlisting>
6827*4882a593Smuzhiyun    void vgaHWSetStdFuncs(vgaHWPtr hwp);
6828*4882a593Smuzhiyun	  </programlisting>
6829*4882a593Smuzhiyun	  <blockquote><para>
6830*4882a593Smuzhiyun      This function initialises the register access function fields of
6831*4882a593Smuzhiyun      <parameter>hwp</parameter> with the standard VGA set of functions.  This
6832*4882a593Smuzhiyun      is called by <function>vgaHWGetHWRec()</function>, so there is usually
6833*4882a593Smuzhiyun      no need to call this explicitly.  The register access functions
6834*4882a593Smuzhiyun      are described below.  If the registers are shadowed in some other
6835*4882a593Smuzhiyun      port I/O space (for example a PCI I/O region), these functions
6836*4882a593Smuzhiyun      can be used to access the shadowed registers if
6837*4882a593Smuzhiyun      <structfield>hwp-&gt;PIOOffset</structfield> is initialised with
6838*4882a593Smuzhiyun      <literal remap="tt">offset</literal>, calculated in such a way that when the
6839*4882a593Smuzhiyun      standard VGA I/O port value is added to it the correct offset into
6840*4882a593Smuzhiyun      the PIO area results.  This value is initialised to zero in
6841*4882a593Smuzhiyun      <function>vgaHWGetHWRec()</function>.  (Note: the PIOOffset functionality
6842*4882a593Smuzhiyun      is present in XFree86 4.1.0 and later.)
6843*4882a593Smuzhiyun	    </para>
6844*4882a593Smuzhiyun
6845*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6846*4882a593Smuzhiyun
6847*4882a593Smuzhiyun      <blockquote><para>
6848*4882a593Smuzhiyun	  <programlisting>
6849*4882a593Smuzhiyun    void vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset);
6850*4882a593Smuzhiyun	  </programlisting>
6851*4882a593Smuzhiyun	  <blockquote><para>
6852*4882a593Smuzhiyun      This function initialised the register access function fields of
6853*4882a593Smuzhiyun      hwp with a generic MMIO set of functions.
6854*4882a593Smuzhiyun      <structfield>hwp-&gt;MMIOBase</structfield> is initialised with
6855*4882a593Smuzhiyun      <parameter>base</parameter>, which must be the virtual address that the
6856*4882a593Smuzhiyun      start of MMIO area is mapped to.  <structfield>hwp-&gt;MMIOOffset</structfield>
6857*4882a593Smuzhiyun      is initialised with <parameter>offset</parameter>, which must be calculated
6858*4882a593Smuzhiyun      in such a way that when the standard VGA I/O port value is added
6859*4882a593Smuzhiyun      to it the correct offset into the MMIO area results.  That means
6860*4882a593Smuzhiyun      that these functions are only suitable when the VGA I/O ports are
6861*4882a593Smuzhiyun      made available in a direct mapping to the MMIO space.  If that is
6862*4882a593Smuzhiyun      not the case, the driver will need to provide its own register
6863*4882a593Smuzhiyun      access functions.  The register access functions are described
6864*4882a593Smuzhiyun      below.
6865*4882a593Smuzhiyun	    </para>
6866*4882a593Smuzhiyun
6867*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6868*4882a593Smuzhiyun
6869*4882a593Smuzhiyun      <blockquote><para>
6870*4882a593Smuzhiyun	  <programlisting>
6871*4882a593Smuzhiyun    Bool vgaHWMapMem(ScrnInfoPtr pScrn);
6872*4882a593Smuzhiyun	  </programlisting>
6873*4882a593Smuzhiyun	  <blockquote><para>
6874*4882a593Smuzhiyun      This function maps the VGA memory window.  It requires that the
6875*4882a593Smuzhiyun      <structname>vgaHWRec</structname> be allocated.  If a driver requires
6876*4882a593Smuzhiyun      non-default <structfield>MapPhys</structfield> or <structfield>MapSize</structfield>
6877*4882a593Smuzhiyun      settings (the physical location and size of the VGA memory window)
6878*4882a593Smuzhiyun      then those fields of the <structname>vgaHWRec</structname> must be initialised
6879*4882a593Smuzhiyun      before calling this function.  Otherwise, this function initialiases
6880*4882a593Smuzhiyun      the default values of <constant>0xA0000</constant> for
6881*4882a593Smuzhiyun      <structfield>MapPhys</structfield> and <code>(64&nbsp;*&nbsp;1024)</code> for
6882*4882a593Smuzhiyun      <structfield>MapSize</structfield>.  This function must be called before
6883*4882a593Smuzhiyun      attempting to save or restore the VGA state.  If the driver doesn't
6884*4882a593Smuzhiyun      call it explicitly, the <function>vgaHWSave()</function> and
6885*4882a593Smuzhiyun      <function>vgaHWRestore()</function> functions may call it if they need
6886*4882a593Smuzhiyun      to access the VGA memory (in which case they will also call
6887*4882a593Smuzhiyun      <function>vgaHWUnmapMem()</function> to unmap the VGA memory before
6888*4882a593Smuzhiyun      exiting).
6889*4882a593Smuzhiyun	    </para>
6890*4882a593Smuzhiyun
6891*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6892*4882a593Smuzhiyun
6893*4882a593Smuzhiyun      <blockquote><para>
6894*4882a593Smuzhiyun	  <programlisting>
6895*4882a593Smuzhiyun    void vgaHWUnmapMem(ScrnInfoPtr pScrn);
6896*4882a593Smuzhiyun	  </programlisting>
6897*4882a593Smuzhiyun	  <blockquote><para>
6898*4882a593Smuzhiyun      This function unmaps the VGA memory window.  It must only be called
6899*4882a593Smuzhiyun      after the memory has been mapped.  The <structfield>Base</structfield> field
6900*4882a593Smuzhiyun      of the <structname>vgaHWRec</structname> field is set to <constant>NULL</constant>
6901*4882a593Smuzhiyun      to indicate that the memory is no longer mapped.
6902*4882a593Smuzhiyun	    </para>
6903*4882a593Smuzhiyun
6904*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6905*4882a593Smuzhiyun
6906*4882a593Smuzhiyun      <blockquote><para>
6907*4882a593Smuzhiyun	  <programlisting>
6908*4882a593Smuzhiyun    void vgaHWGetIOBase(vgaHWPtr hwp);
6909*4882a593Smuzhiyun	  </programlisting>
6910*4882a593Smuzhiyun	  <blockquote><para>
6911*4882a593Smuzhiyun      This function initialises the <structfield>IOBase</structfield> field of the
6912*4882a593Smuzhiyun      <structname>vgaHWRec</structname>.  This function must be called before
6913*4882a593Smuzhiyun      using any other functions that access the video hardware.
6914*4882a593Smuzhiyun	    </para>
6915*4882a593Smuzhiyun
6916*4882a593Smuzhiyun	    <para>
6917*4882a593Smuzhiyun      A macro <function>VGAHW_GET_IOBASE()</function> is also available in
6918*4882a593Smuzhiyun      <filename>vgaHW.h</filename> that returns the I/O base, and this may
6919*4882a593Smuzhiyun      be used when the vgahw module is not loaded (for example, in the
6920*4882a593Smuzhiyun      <function>ChipProbe()</function> function).
6921*4882a593Smuzhiyun	    </para>
6922*4882a593Smuzhiyun
6923*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6924*4882a593Smuzhiyun
6925*4882a593Smuzhiyun      <blockquote><para>
6926*4882a593Smuzhiyun	  <programlisting>
6927*4882a593Smuzhiyun    void vgaHWUnlock(vgaHWPtr hwp);
6928*4882a593Smuzhiyun	  </programlisting>
6929*4882a593Smuzhiyun	  <blockquote><para>
6930*4882a593Smuzhiyun      This function unlocks the VGA <literal remap="tt">CRTC[0-7]</literal> registers,
6931*4882a593Smuzhiyun      and must be called before attempting to write to those registers.
6932*4882a593Smuzhiyun	    </para>
6933*4882a593Smuzhiyun
6934*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6935*4882a593Smuzhiyun
6936*4882a593Smuzhiyun      <blockquote><para>
6937*4882a593Smuzhiyun	  <programlisting>
6938*4882a593Smuzhiyun    void vgaHWLock(vgaHWPtr hwp);
6939*4882a593Smuzhiyun	  </programlisting>
6940*4882a593Smuzhiyun	  <blockquote><para>
6941*4882a593Smuzhiyun      This function locks the VGA <literal remap="tt">CRTC[0-7]</literal> registers.
6942*4882a593Smuzhiyun	    </para>
6943*4882a593Smuzhiyun
6944*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6945*4882a593Smuzhiyun
6946*4882a593Smuzhiyun      <blockquote><para>
6947*4882a593Smuzhiyun	  <programlisting>
6948*4882a593Smuzhiyun    void vgaHWEnable(vgaHWPtr hwp);
6949*4882a593Smuzhiyun	  </programlisting>
6950*4882a593Smuzhiyun	  <blockquote><para>
6951*4882a593Smuzhiyun      This function enables the VGA subsystem.  (Note, this function is
6952*4882a593Smuzhiyun      present in XFree86 4.1.0 and later.).
6953*4882a593Smuzhiyun	    </para>
6954*4882a593Smuzhiyun
6955*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6956*4882a593Smuzhiyun
6957*4882a593Smuzhiyun      <blockquote><para>
6958*4882a593Smuzhiyun	  <programlisting>
6959*4882a593Smuzhiyun    void vgaHWDisable(vgaHWPtr hwp);
6960*4882a593Smuzhiyun	  </programlisting>
6961*4882a593Smuzhiyun	  <blockquote><para>
6962*4882a593Smuzhiyun      This function disables the VGA subsystem.  (Note, this function is
6963*4882a593Smuzhiyun      present in XFree86 4.1.0 and later.).
6964*4882a593Smuzhiyun	    </para>
6965*4882a593Smuzhiyun
6966*4882a593Smuzhiyun	  </blockquote></para></blockquote>
6967*4882a593Smuzhiyun
6968*4882a593Smuzhiyun      <blockquote><para>
6969*4882a593Smuzhiyun	  <programlisting>
6970*4882a593Smuzhiyun    void vgaHWSave(ScrnInfoPtr pScrn, vgaRegPtr save, int flags);
6971*4882a593Smuzhiyun	  </programlisting>
6972*4882a593Smuzhiyun	  <blockquote><para>
6973*4882a593Smuzhiyun      This function saves the VGA state.  The state is written to the
6974*4882a593Smuzhiyun      <structname>vgaRegRec</structname> pointed to by <parameter>save</parameter>.
6975*4882a593Smuzhiyun      <parameter>flags</parameter> is set to one or more of the following flags
6976*4882a593Smuzhiyun      ORed together:
6977*4882a593Smuzhiyun
6978*4882a593Smuzhiyun	      <variablelist>
6979*4882a593Smuzhiyun		<varlistentry>
6980*4882a593Smuzhiyun		  <term><constant>VGA_SR_MODE</constant></term>
6981*4882a593Smuzhiyun		  <listitem><para>the mode setting registers are saved
6982*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6983*4882a593Smuzhiyun		<varlistentry>
6984*4882a593Smuzhiyun		  <term><constant>VGA_SR_FONTS</constant></term>
6985*4882a593Smuzhiyun		  <listitem><para>the text mode font/text data is saved
6986*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6987*4882a593Smuzhiyun		<varlistentry>
6988*4882a593Smuzhiyun		  <term><constant>VGA_SR_CMAP</constant></term>
6989*4882a593Smuzhiyun		  <listitem><para>the colourmap (LUT) is saved
6990*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6991*4882a593Smuzhiyun		<varlistentry>
6992*4882a593Smuzhiyun		  <term><constant>VGA_SR_ALL</constant></term>
6993*4882a593Smuzhiyun		  <listitem><para>all of the above are saved
6994*4882a593Smuzhiyun		    </para></listitem></varlistentry>
6995*4882a593Smuzhiyun	      </variablelist>
6996*4882a593Smuzhiyun	    </para>
6997*4882a593Smuzhiyun
6998*4882a593Smuzhiyun	    <para>
6999*4882a593Smuzhiyun      The <structname>vgaHWRec</structname> and its <structfield>IOBase</structfield> fields
7000*4882a593Smuzhiyun      must be initialised before this function is called.  If
7001*4882a593Smuzhiyun      <constant>VGA_SR_FONTS</constant> is set in <parameter>flags</parameter>, the
7002*4882a593Smuzhiyun      VGA memory window must be mapped.  If it isn't then
7003*4882a593Smuzhiyun      <function>vgaHWMapMem()</function> will be called to map it, and
7004*4882a593Smuzhiyun      <function>vgaHWUnmapMem()</function> will be called to unmap it
7005*4882a593Smuzhiyun      afterwards.  <function>vgaHWSave()</function> uses the three functions
7006*4882a593Smuzhiyun      below in the order <function>vgaHWSaveColormap()</function>,
7007*4882a593Smuzhiyun      <function>vgaHWSaveMode()</function>, <function>vgaHWSaveFonts()</function> to
7008*4882a593Smuzhiyun      carry out the different save phases.  It is undecided at this
7009*4882a593Smuzhiyun      stage whether they will remain part of the vgahw module's public
7010*4882a593Smuzhiyun      interface or not.
7011*4882a593Smuzhiyun	    </para>
7012*4882a593Smuzhiyun
7013*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7014*4882a593Smuzhiyun
7015*4882a593Smuzhiyun      <blockquote><para>
7016*4882a593Smuzhiyun	  <programlisting>
7017*4882a593Smuzhiyun    void vgaHWSaveMode(ScrnInfoPtr pScrn, vgaRegPtr save);
7018*4882a593Smuzhiyun	  </programlisting>
7019*4882a593Smuzhiyun	  <blockquote><para>
7020*4882a593Smuzhiyun      This function saves the VGA mode registers.  They are saved to
7021*4882a593Smuzhiyun      the <structname>vgaRegRec</structname> pointed to by <parameter>save</parameter>.
7022*4882a593Smuzhiyun      The registers saved are:
7023*4882a593Smuzhiyun
7024*4882a593Smuzhiyun	      <literallayout>
7025*4882a593Smuzhiyun        MiscOut
7026*4882a593Smuzhiyun        CRTC[0-0x18]
7027*4882a593Smuzhiyun        Attribute[0-0x14]
7028*4882a593Smuzhiyun        Graphics[0-8]
7029*4882a593Smuzhiyun        Sequencer[0-4]
7030*4882a593Smuzhiyun	      </literallayout>
7031*4882a593Smuzhiyun	    </para>
7032*4882a593Smuzhiyun
7033*4882a593Smuzhiyun	    <para>
7034*4882a593Smuzhiyun    The number of registers actually saved may be modified by a prior call
7035*4882a593Smuzhiyun    to <function>vgaHWSetRegCounts()</function>.
7036*4882a593Smuzhiyun	    </para>
7037*4882a593Smuzhiyun
7038*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7039*4882a593Smuzhiyun
7040*4882a593Smuzhiyun      <blockquote><para>
7041*4882a593Smuzhiyun	  <programlisting>
7042*4882a593Smuzhiyun    void vgaHWSaveFonts(ScrnInfoPtr pScrn, vgaRegPtr save);
7043*4882a593Smuzhiyun	  </programlisting>
7044*4882a593Smuzhiyun	  <blockquote><para>
7045*4882a593Smuzhiyun      This function saves the text mode font and text data held in the
7046*4882a593Smuzhiyun      video memory.  If called while in a graphics mode, no save is
7047*4882a593Smuzhiyun      done.  The VGA memory window must be mapped with
7048*4882a593Smuzhiyun      <function>vgaHWMapMem()</function> before to calling this function.
7049*4882a593Smuzhiyun	    </para>
7050*4882a593Smuzhiyun
7051*4882a593Smuzhiyun	    <para>
7052*4882a593Smuzhiyun      On some platforms, one or more of the font/text plane saves may be
7053*4882a593Smuzhiyun      no-ops.  This is the case when the platform's VC driver already
7054*4882a593Smuzhiyun      takes care of this.
7055*4882a593Smuzhiyun	    </para>
7056*4882a593Smuzhiyun
7057*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7058*4882a593Smuzhiyun
7059*4882a593Smuzhiyun      <blockquote><para>
7060*4882a593Smuzhiyun	  <programlisting>
7061*4882a593Smuzhiyun    void vgaHWSaveColormap(ScrnInfoPtr pScrn, vgaRegPtr save);
7062*4882a593Smuzhiyun	  </programlisting>
7063*4882a593Smuzhiyun	  <blockquote><para>
7064*4882a593Smuzhiyun      This function saves the VGA colourmap (LUT).  Before saving it, it
7065*4882a593Smuzhiyun      attempts to verify that the colourmap is readable.  In rare cases
7066*4882a593Smuzhiyun      where it isn't readable, a default colourmap is saved instead.
7067*4882a593Smuzhiyun	    </para>
7068*4882a593Smuzhiyun
7069*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7070*4882a593Smuzhiyun
7071*4882a593Smuzhiyun      <blockquote><para>
7072*4882a593Smuzhiyun	  <programlisting>
7073*4882a593Smuzhiyun    void vgaHWRestore(ScrnInfoPtr pScrn, vgaRegPtr restore, int flags);
7074*4882a593Smuzhiyun	  </programlisting>
7075*4882a593Smuzhiyun	  <blockquote><para>
7076*4882a593Smuzhiyun      This function programs the VGA state.  The state programmed is
7077*4882a593Smuzhiyun      that contained in the <structname>vgaRegRec</structname> pointed to by
7078*4882a593Smuzhiyun      <parameter>restore</parameter>.  <parameter>flags</parameter> is the same
7079*4882a593Smuzhiyun      as described above for the <function>vgaHWSave()</function> function.
7080*4882a593Smuzhiyun	    </para>
7081*4882a593Smuzhiyun
7082*4882a593Smuzhiyun	    <para>
7083*4882a593Smuzhiyun      The <structname>vgaHWRec</structname> and its <structfield>IOBase</structfield> fields
7084*4882a593Smuzhiyun      must be initialised before this function is called.  If
7085*4882a593Smuzhiyun      <constant>VGA_SR_FONTS</constant> is set in <parameter>flags</parameter>, the
7086*4882a593Smuzhiyun      VGA memory window must be mapped.  If it isn't then
7087*4882a593Smuzhiyun      <function>vgaHWMapMem()</function> will be called to map it, and
7088*4882a593Smuzhiyun      <function>vgaHWUnmapMem()</function> will be called to unmap it
7089*4882a593Smuzhiyun      afterwards.  <function>vgaHWRestore()</function> uses the three functions
7090*4882a593Smuzhiyun      below in the order <function>vgaHWRestoreFonts()</function>,
7091*4882a593Smuzhiyun      <function>vgaHWRestoreMode()</function>,
7092*4882a593Smuzhiyun      <function>vgaHWRestoreColormap()</function> to carry out the different
7093*4882a593Smuzhiyun      restore phases.  It is undecided at this stage whether they will
7094*4882a593Smuzhiyun      remain part of the vgahw module's public interface or not.
7095*4882a593Smuzhiyun	    </para>
7096*4882a593Smuzhiyun
7097*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7098*4882a593Smuzhiyun
7099*4882a593Smuzhiyun      <blockquote><para>
7100*4882a593Smuzhiyun	  <programlisting>
7101*4882a593Smuzhiyun    void vgaHWRestoreMode(ScrnInfoPtr pScrn, vgaRegPtr restore);
7102*4882a593Smuzhiyun	  </programlisting>
7103*4882a593Smuzhiyun	  <blockquote><para>
7104*4882a593Smuzhiyun      This function restores the VGA mode registers.  They are restored
7105*4882a593Smuzhiyun      from the data in the <structname>vgaRegRec</structname> pointed to by
7106*4882a593Smuzhiyun      <parameter>restore</parameter>.  The registers restored are:
7107*4882a593Smuzhiyun
7108*4882a593Smuzhiyun	      <literallayout>
7109*4882a593Smuzhiyun        MiscOut
7110*4882a593Smuzhiyun        CRTC[0-0x18]
7111*4882a593Smuzhiyun        Attribute[0-0x14]
7112*4882a593Smuzhiyun        Graphics[0-8]
7113*4882a593Smuzhiyun        Sequencer[0-4]
7114*4882a593Smuzhiyun	      </literallayout>
7115*4882a593Smuzhiyun	    </para>
7116*4882a593Smuzhiyun
7117*4882a593Smuzhiyun	    <para>
7118*4882a593Smuzhiyun    The number of registers actually restored may be modified by a prior call
7119*4882a593Smuzhiyun    to <function>vgaHWSetRegCounts()</function>.
7120*4882a593Smuzhiyun	    </para>
7121*4882a593Smuzhiyun
7122*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7123*4882a593Smuzhiyun
7124*4882a593Smuzhiyun      <blockquote><para>
7125*4882a593Smuzhiyun	  <programlisting>
7126*4882a593Smuzhiyun    void vgaHWRestoreFonts(ScrnInfoPtr pScrn, vgaRegPtr restore);
7127*4882a593Smuzhiyun	  </programlisting>
7128*4882a593Smuzhiyun	  <blockquote><para>
7129*4882a593Smuzhiyun      This function restores the text mode font and text data to the
7130*4882a593Smuzhiyun      video memory.  The VGA memory window must be mapped with
7131*4882a593Smuzhiyun      <function>vgaHWMapMem()</function> before to calling this function.
7132*4882a593Smuzhiyun	    </para>
7133*4882a593Smuzhiyun
7134*4882a593Smuzhiyun	    <para>
7135*4882a593Smuzhiyun      On some platforms, one or more of the font/text plane restores
7136*4882a593Smuzhiyun      may be no-ops.  This is the case when the platform's VC driver
7137*4882a593Smuzhiyun      already takes care of this.
7138*4882a593Smuzhiyun	    </para>
7139*4882a593Smuzhiyun
7140*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7141*4882a593Smuzhiyun
7142*4882a593Smuzhiyun      <blockquote><para>
7143*4882a593Smuzhiyun	  <programlisting>
7144*4882a593Smuzhiyun    void vgaHWRestoreColormap(ScrnInfoPtr pScrn, vgaRegPtr restore);
7145*4882a593Smuzhiyun	  </programlisting>
7146*4882a593Smuzhiyun	  <blockquote><para>
7147*4882a593Smuzhiyun      This function restores the VGA colourmap (LUT).
7148*4882a593Smuzhiyun	    </para>
7149*4882a593Smuzhiyun
7150*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7151*4882a593Smuzhiyun
7152*4882a593Smuzhiyun      <blockquote><para>
7153*4882a593Smuzhiyun	  <programlisting>
7154*4882a593Smuzhiyun    void vgaHWInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
7155*4882a593Smuzhiyun	  </programlisting>
7156*4882a593Smuzhiyun	  <blockquote><para>
7157*4882a593Smuzhiyun      This function fills in the <structname>vgaHWRec</structname>'s
7158*4882a593Smuzhiyun      <structfield>ModeReg</structfield> field with the values appropriate for
7159*4882a593Smuzhiyun      programming the given video mode.  It requires that the
7160*4882a593Smuzhiyun      <structname>ScrnInfoRec</structname>'s <structfield>depth</structfield> field is
7161*4882a593Smuzhiyun      initialised, which determines how the registers are programmed.
7162*4882a593Smuzhiyun	    </para>
7163*4882a593Smuzhiyun
7164*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7165*4882a593Smuzhiyun
7166*4882a593Smuzhiyun      <blockquote><para>
7167*4882a593Smuzhiyun	  <programlisting>
7168*4882a593Smuzhiyun    void vgaHWSeqReset(vgaHWPtr hwp, Bool start);
7169*4882a593Smuzhiyun	  </programlisting>
7170*4882a593Smuzhiyun	  <blockquote><para>
7171*4882a593Smuzhiyun      Do a VGA sequencer reset.  If start is <constant>TRUE</constant>, the
7172*4882a593Smuzhiyun      reset is started.  If start is <constant>FALSE</constant>, the reset
7173*4882a593Smuzhiyun      is ended.
7174*4882a593Smuzhiyun	    </para>
7175*4882a593Smuzhiyun
7176*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7177*4882a593Smuzhiyun
7178*4882a593Smuzhiyun      <blockquote><para>
7179*4882a593Smuzhiyun	  <programlisting>
7180*4882a593Smuzhiyun    void vgaHWProtect(ScrnInfoPtr pScrn, Bool on);
7181*4882a593Smuzhiyun	  </programlisting>
7182*4882a593Smuzhiyun	  <blockquote><para>
7183*4882a593Smuzhiyun      This function protects VGA registers and memory from corruption
7184*4882a593Smuzhiyun      during loads.  It is typically called with on set to
7185*4882a593Smuzhiyun      <constant>TRUE</constant> before programming, and with on set to
7186*4882a593Smuzhiyun      <constant>FALSE</constant> after programming.
7187*4882a593Smuzhiyun	    </para>
7188*4882a593Smuzhiyun
7189*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7190*4882a593Smuzhiyun
7191*4882a593Smuzhiyun      <blockquote><para>
7192*4882a593Smuzhiyun	  <programlisting>
7193*4882a593Smuzhiyun    Bool vgaHWSaveScreen(ScreenPtr pScreen, int mode);
7194*4882a593Smuzhiyun	  </programlisting>
7195*4882a593Smuzhiyun	  <blockquote><para>
7196*4882a593Smuzhiyun      This function blanks and unblanks the screen.  It is blanked when
7197*4882a593Smuzhiyun      <parameter>mode</parameter> is <constant>SCREEN_SAVER_ON</constant> or
7198*4882a593Smuzhiyun      <constant>SCREEN_SAVER_CYCLE</constant>, and unblanked when
7199*4882a593Smuzhiyun      <parameter>mode</parameter> is <constant>SCREEN_SAVER_OFF</constant> or
7200*4882a593Smuzhiyun      <constant>SCREEN_SAVER_FORCER</constant>.
7201*4882a593Smuzhiyun	    </para>
7202*4882a593Smuzhiyun
7203*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7204*4882a593Smuzhiyun
7205*4882a593Smuzhiyun      <blockquote><para>
7206*4882a593Smuzhiyun	  <programlisting>
7207*4882a593Smuzhiyun    void vgaHWBlankScreen(ScrnInfoPtr pScrn, Bool on);
7208*4882a593Smuzhiyun	  </programlisting>
7209*4882a593Smuzhiyun	  <blockquote><para>
7210*4882a593Smuzhiyun      This function blanks and unblanks the screen.  It is blanked when
7211*4882a593Smuzhiyun      <parameter>on</parameter> is <constant>FALSE</constant>, and unblanked when
7212*4882a593Smuzhiyun      <parameter>on</parameter> is <constant>TRUE</constant>.  This function is
7213*4882a593Smuzhiyun      provided for use in cases where the <structname>ScrnInfoRec</structname>
7214*4882a593Smuzhiyun      can't be derived from the <structname>ScreenRec</structname> (while probing
7215*4882a593Smuzhiyun      for clocks, for example).
7216*4882a593Smuzhiyun	    </para>
7217*4882a593Smuzhiyun
7218*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7219*4882a593Smuzhiyun
7220*4882a593Smuzhiyun    </sect2>
7221*4882a593Smuzhiyun
7222*4882a593Smuzhiyun    <sect2>
7223*4882a593Smuzhiyun      <title>VGA Colormap Functions</title>
7224*4882a593Smuzhiyun
7225*4882a593Smuzhiyun      <para>
7226*4882a593Smuzhiyun    The vgahw module uses the standard colormap support (see the
7227*4882a593Smuzhiyun    <link linkend="cmap">Colormap Handling</link> section.  This is initialised
7228*4882a593Smuzhiyun    with the following function:
7229*4882a593Smuzhiyun
7230*4882a593Smuzhiyun	<blockquote><para>
7231*4882a593Smuzhiyun	  <programlisting>
7232*4882a593Smuzhiyun    Bool vgaHWHandleColormaps(ScreenPtr pScreen);
7233*4882a593Smuzhiyun	    </programlisting>
7234*4882a593Smuzhiyun	  </para></blockquote>
7235*4882a593Smuzhiyun      </para>
7236*4882a593Smuzhiyun
7237*4882a593Smuzhiyun    </sect2>
7238*4882a593Smuzhiyun
7239*4882a593Smuzhiyun    <sect2>
7240*4882a593Smuzhiyun      <title>VGA Register Access Functions</title>
7241*4882a593Smuzhiyun
7242*4882a593Smuzhiyun      <para>
7243*4882a593Smuzhiyun    The vgahw module abstracts access to the standard VGA registers by
7244*4882a593Smuzhiyun    using a set of functions held in the <structname>vgaHWRec</structname>.  When
7245*4882a593Smuzhiyun    the <structname>vgaHWRec</structname> is created these function pointers are
7246*4882a593Smuzhiyun    initialised with the set of standard VGA I/O register access functions.
7247*4882a593Smuzhiyun    In addition to these, the vgahw module includes a basic set of MMIO
7248*4882a593Smuzhiyun    register access functions, and the <structname>vgaHWRec</structname> function
7249*4882a593Smuzhiyun    pointers can be initialised to these by calling the
7250*4882a593Smuzhiyun    <function>vgaHWSetMmioFuncs()</function> function described above.  Some
7251*4882a593Smuzhiyun    drivers/platforms may require a different set of functions for VGA
7252*4882a593Smuzhiyun    access.  The access functions are described here.
7253*4882a593Smuzhiyun      </para>
7254*4882a593Smuzhiyun
7255*4882a593Smuzhiyun
7256*4882a593Smuzhiyun      <blockquote><para>
7257*4882a593Smuzhiyun	  <programlisting>
7258*4882a593Smuzhiyun    void writeCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value);
7259*4882a593Smuzhiyun	  </programlisting>
7260*4882a593Smuzhiyun	  <blockquote><para>
7261*4882a593Smuzhiyun      Write <parameter>value</parameter> to CRTC register <parameter>index</parameter>.
7262*4882a593Smuzhiyun	    </para>
7263*4882a593Smuzhiyun
7264*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7265*4882a593Smuzhiyun
7266*4882a593Smuzhiyun      <blockquote><para>
7267*4882a593Smuzhiyun	  <programlisting>
7268*4882a593Smuzhiyun    CARD8 readCrtc(vgaHWPtr hwp, CARD8 index);
7269*4882a593Smuzhiyun	  </programlisting>
7270*4882a593Smuzhiyun	  <blockquote><para>
7271*4882a593Smuzhiyun      Return the value read from CRTC register <parameter>index</parameter>.
7272*4882a593Smuzhiyun	    </para>
7273*4882a593Smuzhiyun
7274*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7275*4882a593Smuzhiyun
7276*4882a593Smuzhiyun      <blockquote><para>
7277*4882a593Smuzhiyun	  <programlisting>
7278*4882a593Smuzhiyun    void writeGr(vgaHWPtr hwp, CARD8 index, CARD8 value);
7279*4882a593Smuzhiyun	  </programlisting>
7280*4882a593Smuzhiyun	  <blockquote><para>
7281*4882a593Smuzhiyun      Write <parameter>value</parameter> to Graphics Controller register
7282*4882a593Smuzhiyun      <parameter>index</parameter>.
7283*4882a593Smuzhiyun	    </para>
7284*4882a593Smuzhiyun
7285*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7286*4882a593Smuzhiyun
7287*4882a593Smuzhiyun      <blockquote><para>
7288*4882a593Smuzhiyun	  <programlisting>
7289*4882a593Smuzhiyun    CARD8 readGR(vgaHWPtr hwp, CARD8 index);
7290*4882a593Smuzhiyun	  </programlisting>
7291*4882a593Smuzhiyun	  <blockquote><para>
7292*4882a593Smuzhiyun      Return the value read from Graphics Controller register
7293*4882a593Smuzhiyun      <parameter>index</parameter>.
7294*4882a593Smuzhiyun	    </para>
7295*4882a593Smuzhiyun
7296*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7297*4882a593Smuzhiyun
7298*4882a593Smuzhiyun      <blockquote><para>
7299*4882a593Smuzhiyun	  <programlisting>
7300*4882a593Smuzhiyun    void writeSeq(vgaHWPtr hwp, CARD8 index, CARD8, value);
7301*4882a593Smuzhiyun	  </programlisting>
7302*4882a593Smuzhiyun	  <blockquote><para>
7303*4882a593Smuzhiyun      Write <parameter>value</parameter> to Sequencer register
7304*4882a593Smuzhiyun      <parameter>index</parameter>.
7305*4882a593Smuzhiyun	    </para>
7306*4882a593Smuzhiyun
7307*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7308*4882a593Smuzhiyun
7309*4882a593Smuzhiyun      <blockquote><para>
7310*4882a593Smuzhiyun	  <programlisting>
7311*4882a593Smuzhiyun    CARD8 readSeq(vgaHWPtr hwp, CARD8 index);
7312*4882a593Smuzhiyun	  </programlisting>
7313*4882a593Smuzhiyun	  <blockquote><para>
7314*4882a593Smuzhiyun      Return the value read from Sequencer register <parameter>index</parameter>.
7315*4882a593Smuzhiyun	    </para>
7316*4882a593Smuzhiyun
7317*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7318*4882a593Smuzhiyun
7319*4882a593Smuzhiyun      <blockquote><para>
7320*4882a593Smuzhiyun	  <programlisting>
7321*4882a593Smuzhiyun    void writeAttr(vgaHWPtr hwp, CARD8 index, CARD8, value);
7322*4882a593Smuzhiyun	  </programlisting>
7323*4882a593Smuzhiyun	  <blockquote><para>
7324*4882a593Smuzhiyun      Write <parameter>value</parameter> to Attribute Controller register
7325*4882a593Smuzhiyun      <parameter>index</parameter>.  When writing out the index value this
7326*4882a593Smuzhiyun      function should set bit 5 (<constant>0x20</constant>) according to the
7327*4882a593Smuzhiyun      setting of <structfield>hwp-&gt;paletteEnabled</structfield> in order to
7328*4882a593Smuzhiyun      preserve the palette access state.  It should be cleared when
7329*4882a593Smuzhiyun      <structfield>hwp-&gt;paletteEnabled</structfield> is <constant>TRUE</constant>
7330*4882a593Smuzhiyun      and set when it is <constant>FALSE</constant>.
7331*4882a593Smuzhiyun	    </para>
7332*4882a593Smuzhiyun
7333*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7334*4882a593Smuzhiyun
7335*4882a593Smuzhiyun      <blockquote><para>
7336*4882a593Smuzhiyun	  <programlisting>
7337*4882a593Smuzhiyun    CARD8 readAttr(vgaHWPtr hwp, CARD8 index);
7338*4882a593Smuzhiyun	  </programlisting>
7339*4882a593Smuzhiyun	  <blockquote><para>
7340*4882a593Smuzhiyun      Return the value read from Attribute Controller register
7341*4882a593Smuzhiyun      <parameter>index</parameter>.  When writing out the index value this
7342*4882a593Smuzhiyun      function should set bit 5 (<constant>0x20</constant>) according to the
7343*4882a593Smuzhiyun      setting of <structfield>hwp-&gt;paletteEnabled</structfield> in order to
7344*4882a593Smuzhiyun      preserve the palette access state.  It should be cleared when
7345*4882a593Smuzhiyun      <structfield>hwp-&gt;paletteEnabled</structfield> is <constant>TRUE</constant>
7346*4882a593Smuzhiyun      and set when it is <constant>FALSE</constant>.
7347*4882a593Smuzhiyun	    </para>
7348*4882a593Smuzhiyun
7349*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7350*4882a593Smuzhiyun
7351*4882a593Smuzhiyun      <blockquote><para>
7352*4882a593Smuzhiyun	  <programlisting>
7353*4882a593Smuzhiyun    void writeMiscOut(vgaHWPtr hwp, CARD8 value);
7354*4882a593Smuzhiyun	  </programlisting>
7355*4882a593Smuzhiyun	  <blockquote><para>
7356*4882a593Smuzhiyun      Write <quote><parameter>value</parameter></quote> to the Miscellaneous Output register.
7357*4882a593Smuzhiyun	    </para>
7358*4882a593Smuzhiyun
7359*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7360*4882a593Smuzhiyun
7361*4882a593Smuzhiyun      <blockquote><para>
7362*4882a593Smuzhiyun	  <programlisting>
7363*4882a593Smuzhiyun    CARD8 readMiscOut(vgwHWPtr hwp);
7364*4882a593Smuzhiyun	  </programlisting>
7365*4882a593Smuzhiyun	  <blockquote><para>
7366*4882a593Smuzhiyun      Return the value read from the Miscellaneous Output register.
7367*4882a593Smuzhiyun	    </para>
7368*4882a593Smuzhiyun
7369*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7370*4882a593Smuzhiyun
7371*4882a593Smuzhiyun      <blockquote><para>
7372*4882a593Smuzhiyun	  <programlisting>
7373*4882a593Smuzhiyun    void enablePalette(vgaHWPtr hwp);
7374*4882a593Smuzhiyun	  </programlisting>
7375*4882a593Smuzhiyun	  <blockquote><para>
7376*4882a593Smuzhiyun      Clear the palette address source bit in the Attribute Controller
7377*4882a593Smuzhiyun      index register and set <literal remap="tt">hwp-&gt;paletteEnabled</literal> to
7378*4882a593Smuzhiyun      <constant>TRUE</constant>.
7379*4882a593Smuzhiyun	    </para>
7380*4882a593Smuzhiyun
7381*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7382*4882a593Smuzhiyun
7383*4882a593Smuzhiyun      <blockquote><para>
7384*4882a593Smuzhiyun	  <programlisting>
7385*4882a593Smuzhiyun    void disablePalette(vgaHWPtr hwp);
7386*4882a593Smuzhiyun	  </programlisting>
7387*4882a593Smuzhiyun	  <blockquote><para>
7388*4882a593Smuzhiyun      Set the palette address source bit in the Attribute Controller
7389*4882a593Smuzhiyun      index register and set <literal remap="tt">hwp-&gt;paletteEnabled</literal> to
7390*4882a593Smuzhiyun      <constant>FALSE</constant>.
7391*4882a593Smuzhiyun	    </para>
7392*4882a593Smuzhiyun
7393*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7394*4882a593Smuzhiyun
7395*4882a593Smuzhiyun      <blockquote><para>
7396*4882a593Smuzhiyun	  <programlisting>
7397*4882a593Smuzhiyun    void writeDacMask(vgaHWPtr hwp, CARD8 value);
7398*4882a593Smuzhiyun	  </programlisting>
7399*4882a593Smuzhiyun	  <blockquote><para>
7400*4882a593Smuzhiyun      Write <parameter>value</parameter> to the DAC Mask register.
7401*4882a593Smuzhiyun	    </para>
7402*4882a593Smuzhiyun
7403*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7404*4882a593Smuzhiyun
7405*4882a593Smuzhiyun      <blockquote><para>
7406*4882a593Smuzhiyun	  <programlisting>
7407*4882a593Smuzhiyun    CARD8 readDacMask(vgaHWptr hwp);
7408*4882a593Smuzhiyun	  </programlisting>
7409*4882a593Smuzhiyun	  <blockquote><para>
7410*4882a593Smuzhiyun      Return the value read from the DAC Mask register.
7411*4882a593Smuzhiyun	    </para>
7412*4882a593Smuzhiyun
7413*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7414*4882a593Smuzhiyun
7415*4882a593Smuzhiyun      <blockquote><para>
7416*4882a593Smuzhiyun	  <programlisting>
7417*4882a593Smuzhiyun    void writeDacReadAddress(vgaHWPtr hwp, CARD8 value);
7418*4882a593Smuzhiyun	  </programlisting>
7419*4882a593Smuzhiyun	  <blockquote><para>
7420*4882a593Smuzhiyun      Write <parameter>value</parameter> to the DAC Read Address register.
7421*4882a593Smuzhiyun	    </para>
7422*4882a593Smuzhiyun
7423*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7424*4882a593Smuzhiyun
7425*4882a593Smuzhiyun      <blockquote><para>
7426*4882a593Smuzhiyun	  <programlisting>
7427*4882a593Smuzhiyun    void writeDacWriteAddress(vgaHWPtr hwp, CARD8 value);
7428*4882a593Smuzhiyun	  </programlisting>
7429*4882a593Smuzhiyun	  <blockquote><para>
7430*4882a593Smuzhiyun      Write <parameter>value</parameter> to the DAC Write Address register.
7431*4882a593Smuzhiyun	    </para>
7432*4882a593Smuzhiyun
7433*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7434*4882a593Smuzhiyun
7435*4882a593Smuzhiyun      <blockquote><para>
7436*4882a593Smuzhiyun	  <programlisting>
7437*4882a593Smuzhiyun    void writeDacData(vgaHWPtr hwp, CARD8 value);
7438*4882a593Smuzhiyun	  </programlisting>
7439*4882a593Smuzhiyun	  <blockquote><para>
7440*4882a593Smuzhiyun      Write <parameter>value</parameter> to the DAC Data register.
7441*4882a593Smuzhiyun	    </para>
7442*4882a593Smuzhiyun
7443*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7444*4882a593Smuzhiyun
7445*4882a593Smuzhiyun      <blockquote><para>
7446*4882a593Smuzhiyun	  <programlisting>
7447*4882a593Smuzhiyun    CARD8 readDacData(vgaHWptr hwp);
7448*4882a593Smuzhiyun	  </programlisting>
7449*4882a593Smuzhiyun	  <blockquote><para>
7450*4882a593Smuzhiyun      Return the value read from the DAC Data register.
7451*4882a593Smuzhiyun	    </para>
7452*4882a593Smuzhiyun
7453*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7454*4882a593Smuzhiyun
7455*4882a593Smuzhiyun      <blockquote><para>
7456*4882a593Smuzhiyun	  <programlisting>
7457*4882a593Smuzhiyun    CARD8 readEnable(vgaHWptr hwp);
7458*4882a593Smuzhiyun	  </programlisting>
7459*4882a593Smuzhiyun	  <blockquote><para>
7460*4882a593Smuzhiyun      Return the value read from the VGA Enable register.  (Note: This
7461*4882a593Smuzhiyun      function is present in XFree86 4.1.0 and later.)
7462*4882a593Smuzhiyun	    </para>
7463*4882a593Smuzhiyun
7464*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7465*4882a593Smuzhiyun
7466*4882a593Smuzhiyun      <blockquote><para>
7467*4882a593Smuzhiyun	  <programlisting>
7468*4882a593Smuzhiyun    void writeEnable(vgaHWPtr hwp, CARD8 value);
7469*4882a593Smuzhiyun	  </programlisting>
7470*4882a593Smuzhiyun	  <blockquote><para>
7471*4882a593Smuzhiyun      Write <parameter>value</parameter> to the VGA Enable register.  (Note: This
7472*4882a593Smuzhiyun      function is present in XFree86 4.1.0 and later.)
7473*4882a593Smuzhiyun	    </para>
7474*4882a593Smuzhiyun
7475*4882a593Smuzhiyun	  </blockquote></para></blockquote>
7476*4882a593Smuzhiyun    </sect2>
7477*4882a593Smuzhiyun  </sect1>
7478*4882a593Smuzhiyun
7479*4882a593Smuzhiyun  <sect1 id="sample">
7480*4882a593Smuzhiyun    <title>Some notes about writing a driver</title>
7481*4882a593Smuzhiyun
7482*4882a593Smuzhiyun    <note><para>NOTE: some parts of this are not up to date</para></note>
7483*4882a593Smuzhiyun
7484*4882a593Smuzhiyun    <para>
7485*4882a593SmuzhiyunThe following is an outline for writing a basic unaccelerated driver
7486*4882a593Smuzhiyunfor a PCI video card with a linear mapped framebuffer, and which has a
7487*4882a593SmuzhiyunVGA core.  It is includes some general information that is relevant to
7488*4882a593Smuzhiyunmost drivers (even those which don't fit that basic description).
7489*4882a593Smuzhiyun    </para>
7490*4882a593Smuzhiyun
7491*4882a593Smuzhiyun    <para>
7492*4882a593SmuzhiyunThe information here is based on the initial conversion of the Matrox
7493*4882a593SmuzhiyunMillennium driver to the <quote>new design</quote>.  For a fleshing out and sample
7494*4882a593Smuzhiyunimplementation of some of the bits outlined here, refer to that driver.
7495*4882a593SmuzhiyunNote that this is an example only.  The approach used here will not be
7496*4882a593Smuzhiyunappropriate for all drivers.
7497*4882a593Smuzhiyun    </para>
7498*4882a593Smuzhiyun
7499*4882a593Smuzhiyun    <para>
7500*4882a593SmuzhiyunEach driver must reserve a unique driver name, and a string that is used
7501*4882a593Smuzhiyunto prefix all of its externally visible symbols.  This is to avoid name
7502*4882a593Smuzhiyunspace clashes when loading multiple drivers.  The examples here are for
7503*4882a593Smuzhiyunthe <quote>ZZZ</quote> driver, which uses the <quote>ZZZ</quote> or <quote>zzz</quote> prefix for its externally
7504*4882a593Smuzhiyunvisible symbols.
7505*4882a593Smuzhiyun    </para>
7506*4882a593Smuzhiyun
7507*4882a593Smuzhiyun    <sect2>
7508*4882a593Smuzhiyun      <title>Include files</title>
7509*4882a593Smuzhiyun
7510*4882a593Smuzhiyun      <para>
7511*4882a593Smuzhiyun  All drivers normally include the following headers:
7512*4882a593Smuzhiyun	<literallayout><filename>
7513*4882a593Smuzhiyun    "xf86.h"
7514*4882a593Smuzhiyun    "xf86_OSproc.h"
7515*4882a593Smuzhiyun    "xf86_ansic.h"
7516*4882a593Smuzhiyun    "xf86Resources.h"
7517*4882a593Smuzhiyun	  </filename></literallayout>
7518*4882a593Smuzhiyun  Wherever inb/outb (and related things) are used the following should be
7519*4882a593Smuzhiyun  included:
7520*4882a593Smuzhiyun	<literallayout><filename>
7521*4882a593Smuzhiyun    "compiler.h"
7522*4882a593Smuzhiyun	  </filename></literallayout>
7523*4882a593Smuzhiyun  Note: in drivers, this must be included after <filename>"xf86_ansic.h"</filename>.
7524*4882a593Smuzhiyun      </para>
7525*4882a593Smuzhiyun
7526*4882a593Smuzhiyun      <para>
7527*4882a593Smuzhiyun  Drivers that need to access PCI vendor/device definitions need this:
7528*4882a593Smuzhiyun	<literallayout><filename>
7529*4882a593Smuzhiyun    "xf86PciInfo.h"
7530*4882a593Smuzhiyun	  </filename></literallayout>
7531*4882a593Smuzhiyun      </para>
7532*4882a593Smuzhiyun
7533*4882a593Smuzhiyun      <para>
7534*4882a593Smuzhiyun  Drivers that need to access the PCI config space need this:
7535*4882a593Smuzhiyun	<literallayout><filename>
7536*4882a593Smuzhiyun    "xf86Pci.h"
7537*4882a593Smuzhiyun	  </filename></literallayout>
7538*4882a593Smuzhiyun      </para>
7539*4882a593Smuzhiyun
7540*4882a593Smuzhiyun      <para>
7541*4882a593Smuzhiyun  Drivers using the mi banking wrapper need:
7542*4882a593Smuzhiyun
7543*4882a593Smuzhiyun	<literallayout><filename>
7544*4882a593Smuzhiyun    "mibank.h"
7545*4882a593Smuzhiyun	  </filename></literallayout>
7546*4882a593Smuzhiyun      </para>
7547*4882a593Smuzhiyun
7548*4882a593Smuzhiyun      <para>
7549*4882a593Smuzhiyun  Drivers that initialise a SW cursor need this:
7550*4882a593Smuzhiyun	<literallayout><filename>
7551*4882a593Smuzhiyun    "mipointer.h"
7552*4882a593Smuzhiyun	  </filename></literallayout>
7553*4882a593Smuzhiyun      </para>
7554*4882a593Smuzhiyun
7555*4882a593Smuzhiyun      <para>
7556*4882a593Smuzhiyun  All drivers using the mi colourmap code need this:
7557*4882a593Smuzhiyun	<literallayout><filename>
7558*4882a593Smuzhiyun    "micmap.h"
7559*4882a593Smuzhiyun	  </filename></literallayout>
7560*4882a593Smuzhiyun      </para>
7561*4882a593Smuzhiyun
7562*4882a593Smuzhiyun      <para>
7563*4882a593Smuzhiyun  If a driver uses the vgahw module, it needs this:
7564*4882a593Smuzhiyun	<literallayout><filename>
7565*4882a593Smuzhiyun    "vgaHW.h"
7566*4882a593Smuzhiyun	  </filename></literallayout>
7567*4882a593Smuzhiyun      </para>
7568*4882a593Smuzhiyun
7569*4882a593Smuzhiyun      <para>
7570*4882a593Smuzhiyun  Drivers supporting VGA or Hercules monochrome screens need:
7571*4882a593Smuzhiyun	<literallayout><filename>
7572*4882a593Smuzhiyun    "xf1bpp.h"
7573*4882a593Smuzhiyun	  </filename></literallayout>
7574*4882a593Smuzhiyun      </para>
7575*4882a593Smuzhiyun
7576*4882a593Smuzhiyun      <para>
7577*4882a593Smuzhiyun  Drivers supporting VGA or EGC 16-colour screens need:
7578*4882a593Smuzhiyun	<literallayout><filename>
7579*4882a593Smuzhiyun    "xf4bpp.h"
7580*4882a593Smuzhiyun	  </filename></literallayout>
7581*4882a593Smuzhiyun      </para>
7582*4882a593Smuzhiyun
7583*4882a593Smuzhiyun      <para>
7584*4882a593Smuzhiyun  Drivers using cfb need:
7585*4882a593Smuzhiyun	<programlisting>
7586*4882a593Smuzhiyun    #define PSZ 8
7587*4882a593Smuzhiyun    #include "cfb.h"
7588*4882a593Smuzhiyun    #undef PSZ
7589*4882a593Smuzhiyun	</programlisting>
7590*4882a593Smuzhiyun      </para>
7591*4882a593Smuzhiyun
7592*4882a593Smuzhiyun      <para>
7593*4882a593Smuzhiyun  Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
7594*4882a593Smuzhiyun	<literallayout><filename>
7595*4882a593Smuzhiyun    "cfb16.h"
7596*4882a593Smuzhiyun    "cfb24.h"
7597*4882a593Smuzhiyun    "cfb32.h"
7598*4882a593Smuzhiyun	  </filename></literallayout>
7599*4882a593Smuzhiyun      </para>
7600*4882a593Smuzhiyun
7601*4882a593Smuzhiyun      <para>
7602*4882a593Smuzhiyun  The driver's own header file:
7603*4882a593Smuzhiyun	<literallayout><filename>
7604*4882a593Smuzhiyun    "zzz.h"
7605*4882a593Smuzhiyun	  </filename></literallayout>
7606*4882a593Smuzhiyun      </para>
7607*4882a593Smuzhiyun
7608*4882a593Smuzhiyun      <para>
7609*4882a593Smuzhiyun  Drivers must NOT include the following:
7610*4882a593Smuzhiyun
7611*4882a593Smuzhiyun	<literallayout><filename>
7612*4882a593Smuzhiyun    "xf86Priv.h"
7613*4882a593Smuzhiyun    "xf86Privstr.h"
7614*4882a593Smuzhiyun    "xf86_libc.h"
7615*4882a593Smuzhiyun    "xf86_OSlib.h"
7616*4882a593Smuzhiyun    "Xos.h"</filename>
7617*4882a593Smuzhiyun    any OS header
7618*4882a593Smuzhiyun	</literallayout>
7619*4882a593Smuzhiyun      </para>
7620*4882a593Smuzhiyun
7621*4882a593Smuzhiyun    </sect2>
7622*4882a593Smuzhiyun
7623*4882a593Smuzhiyun    <sect2>
7624*4882a593Smuzhiyun      <title>Data structures and initialisation</title>
7625*4882a593Smuzhiyun
7626*4882a593Smuzhiyun      <itemizedlist>
7627*4882a593Smuzhiyun	<listitem>
7628*4882a593Smuzhiyun	  <para>The following macros should be defined:
7629*4882a593Smuzhiyun	    <programlisting>
7630*4882a593Smuzhiyun#define VERSION &lt;version-as-an-int&gt;
7631*4882a593Smuzhiyun#define ZZZ_NAME "ZZZ"         /* the name used to prefix messages */
7632*4882a593Smuzhiyun#define ZZZ_DRIVER_NAME "zzz"  /* the driver name as used in config file */
7633*4882a593Smuzhiyun#define ZZZ_MAJOR_VERSION &lt;int&gt;
7634*4882a593Smuzhiyun#define ZZZ_MINOR_VERSION &lt;int&gt;
7635*4882a593Smuzhiyun#define ZZZ_PATCHLEVEL    &lt;int&gt;
7636*4882a593Smuzhiyun	    </programlisting>
7637*4882a593Smuzhiyun	  </para>
7638*4882a593Smuzhiyun	  <para>
7639*4882a593Smuzhiyun    NOTE: <constant>ZZZ_DRIVER_NAME</constant> should match the name of the
7640*4882a593Smuzhiyun    driver module without things like the "lib" prefix, the "_drv" suffix
7641*4882a593Smuzhiyun    or filename extensions.
7642*4882a593Smuzhiyun	  </para>
7643*4882a593Smuzhiyun	</listitem>
7644*4882a593Smuzhiyun
7645*4882a593Smuzhiyun	<listitem>
7646*4882a593Smuzhiyun	  <para>
7647*4882a593Smuzhiyun    A DriverRec must be defined, which includes the functions required
7648*4882a593Smuzhiyun    at the pre-probe phase.  The name of this DriverRec must be an
7649*4882a593Smuzhiyun    upper-case version of ZZZ_DRIVER_NAME (for the purposes of static
7650*4882a593Smuzhiyun    linking).
7651*4882a593Smuzhiyun	    <programlisting>
7652*4882a593SmuzhiyunDriverRec ZZZ = {
7653*4882a593Smuzhiyun    VERSION,
7654*4882a593Smuzhiyun    ZZZ_DRIVER_NAME,
7655*4882a593Smuzhiyun    ZZZIdentify,
7656*4882a593Smuzhiyun    ZZZProbe,
7657*4882a593Smuzhiyun    ZZZAvailableOptions,
7658*4882a593Smuzhiyun    NULL,
7659*4882a593Smuzhiyun    0
7660*4882a593Smuzhiyun};
7661*4882a593Smuzhiyun	    </programlisting>
7662*4882a593Smuzhiyun	  </para>
7663*4882a593Smuzhiyun	</listitem>
7664*4882a593Smuzhiyun
7665*4882a593Smuzhiyun	<listitem>
7666*4882a593Smuzhiyun	  <para>Define list of supported chips and their matching ID:
7667*4882a593Smuzhiyun	    <programlisting>
7668*4882a593Smuzhiyunstatic SymTabRec ZZZChipsets[] = {
7669*4882a593Smuzhiyun    { PCI_CHIP_ZZZ1234, "zzz1234a" },
7670*4882a593Smuzhiyun    { PCI_CHIP_ZZZ5678, "zzz5678a" },
7671*4882a593Smuzhiyun    { -1,               NULL }
7672*4882a593Smuzhiyun};
7673*4882a593Smuzhiyun	    </programlisting>
7674*4882a593Smuzhiyun	  </para>
7675*4882a593Smuzhiyun	  <para>
7676*4882a593Smuzhiyun    The token field may be any integer value that the driver may use to
7677*4882a593Smuzhiyun    uniquely identify the supported chipsets.  For drivers that support
7678*4882a593Smuzhiyun    only PCI devices using the PCI device IDs might be a natural choice,
7679*4882a593Smuzhiyun    but this isn't mandatory.  For drivers that support both PCI and other
7680*4882a593Smuzhiyun    devices (like ISA), some other ID should probably used.  When other
7681*4882a593Smuzhiyun    IDs are used as the tokens it is recommended that the names be
7682*4882a593Smuzhiyun    defined as an <type>enum</type> type.
7683*4882a593Smuzhiyun	  </para>
7684*4882a593Smuzhiyun	</listitem>
7685*4882a593Smuzhiyun
7686*4882a593Smuzhiyun	<listitem>
7687*4882a593Smuzhiyun	  <para>
7688*4882a593Smuzhiyun    If the driver uses the <function>xf86MatchPciInstances()</function>
7689*4882a593Smuzhiyun    helper (recommended for drivers that support PCI cards) a list that
7690*4882a593Smuzhiyun    maps PCI IDs to chip IDs and fixed resources must be defined:
7691*4882a593Smuzhiyun	    <programlisting>
7692*4882a593Smuzhiyunstatic PciChipsets ZZZPciChipsets[] = {
7693*4882a593Smuzhiyun    { PCI_CHIP_ZZZ1234, PCI_CHIP_ZZZ1234, RES_SHARED_VGA },
7694*4882a593Smuzhiyun    { PCI_CHIP_ZZZ5678, PCI_CHIP_ZZZ5678, RES_SHARED_VGA },
7695*4882a593Smuzhiyun    { -1,               -1,               RES_UNDEFINED }
7696*4882a593Smuzhiyun}
7697*4882a593Smuzhiyun	    </programlisting>
7698*4882a593Smuzhiyun	  </para>
7699*4882a593Smuzhiyun	</listitem>
7700*4882a593Smuzhiyun
7701*4882a593Smuzhiyun	<listitem>
7702*4882a593Smuzhiyun	  <para>
7703*4882a593Smuzhiyun    Define the <structname>XF86ModuleVersionInfo</structname> struct for the
7704*4882a593Smuzhiyun    driver.  This is required for the dynamically loaded version:
7705*4882a593Smuzhiyun	    <programlisting>
7706*4882a593Smuzhiyunstatic XF86ModuleVersionInfo zzzVersRec =
7707*4882a593Smuzhiyun{
7708*4882a593Smuzhiyun    "zzz",
7709*4882a593Smuzhiyun    MODULEVENDORSTRING,
7710*4882a593Smuzhiyun    MODINFOSTRING1,
7711*4882a593Smuzhiyun    MODINFOSTRING2,
7712*4882a593Smuzhiyun    XF86_VERSION_CURRENT,
7713*4882a593Smuzhiyun    ZZZ_MAJOR_VERSION, ZZZ_MINOR_VERSION, ZZZ_PATCHLEVEL,
7714*4882a593Smuzhiyun    ABI_CLASS_VIDEODRV,
7715*4882a593Smuzhiyun    ABI_VIDEODRV_VERSION,
7716*4882a593Smuzhiyun    MOD_CLASS_VIDEODRV,
7717*4882a593Smuzhiyun    {0,0,0,0}
7718*4882a593Smuzhiyun};
7719*4882a593Smuzhiyun	    </programlisting>
7720*4882a593Smuzhiyun	  </para>
7721*4882a593Smuzhiyun	</listitem>
7722*4882a593Smuzhiyun
7723*4882a593Smuzhiyun	<listitem>
7724*4882a593Smuzhiyun	  <para>
7725*4882a593Smuzhiyun    Define a data structure to hold the driver's screen-specific data.
7726*4882a593Smuzhiyun    This must be used instead of global variables.  This would be defined
7727*4882a593Smuzhiyun    in the <filename>"zzz.h"</filename> file, something like:
7728*4882a593Smuzhiyun	    <programlisting>
7729*4882a593Smuzhiyuntypedef struct {
7730*4882a593Smuzhiyun    type1  field1;
7731*4882a593Smuzhiyun    type2  field2;
7732*4882a593Smuzhiyun    int    fooHack;
7733*4882a593Smuzhiyun    Bool   pciRetry;
7734*4882a593Smuzhiyun    Bool   noAccel;
7735*4882a593Smuzhiyun    Bool   hwCursor;
7736*4882a593Smuzhiyun    CloseScreenProcPtr CloseScreen;
7737*4882a593Smuzhiyun    OptionInfoPtr Options;
7738*4882a593Smuzhiyun    ...
7739*4882a593Smuzhiyun} ZZZRec, *ZZZPtr;
7740*4882a593Smuzhiyun	    </programlisting>
7741*4882a593Smuzhiyun	  </para>
7742*4882a593Smuzhiyun	</listitem>
7743*4882a593Smuzhiyun
7744*4882a593Smuzhiyun	<listitem>
7745*4882a593Smuzhiyun	  <para>
7746*4882a593Smuzhiyun    Define the list of config file Options that the driver accepts.  For
7747*4882a593Smuzhiyun    consistency between drivers those in the list of <quote>standard</quote> options
7748*4882a593Smuzhiyun    should be used where appropriate before inventing new options.
7749*4882a593Smuzhiyun
7750*4882a593Smuzhiyun	    <programlisting>
7751*4882a593Smuzhiyuntypedef enum {
7752*4882a593Smuzhiyun    OPTION_FOO_HACK,
7753*4882a593Smuzhiyun    OPTION_PCI_RETRY,
7754*4882a593Smuzhiyun    OPTION_HW_CURSOR,
7755*4882a593Smuzhiyun    OPTION_NOACCEL
7756*4882a593Smuzhiyun} ZZZOpts;
7757*4882a593Smuzhiyun
7758*4882a593Smuzhiyunstatic const OptionInfoRec ZZZOptions[] = {
7759*4882a593Smuzhiyun  { OPTION_FOO_HACK,  "FooHack",   OPTV_INTEGER, {0}, FALSE },
7760*4882a593Smuzhiyun  { OPTION_PCI_RETRY, "PciRetry",  OPTV_BOOLEAN, {0}, FALSE },
7761*4882a593Smuzhiyun  { OPTION_HW_CURSOR, "HWcursor",  OPTV_BOOLEAN, {0}, FALSE },
7762*4882a593Smuzhiyun  { OPTION_NOACCEL,   "NoAccel",   OPTV_BOOLEAN, {0}, FALSE },
7763*4882a593Smuzhiyun  { -1,               NULL,        OPTV_NONE,    {0}, FALSE }
7764*4882a593Smuzhiyun};
7765*4882a593Smuzhiyun	    </programlisting>
7766*4882a593Smuzhiyun	  </para>
7767*4882a593Smuzhiyun	</listitem>
7768*4882a593Smuzhiyun      </itemizedlist>
7769*4882a593Smuzhiyun    </sect2>
7770*4882a593Smuzhiyun
7771*4882a593Smuzhiyun    <sect2>
7772*4882a593Smuzhiyun      <title>Functions</title>
7773*4882a593Smuzhiyun
7774*4882a593Smuzhiyun
7775*4882a593Smuzhiyun      <sect3>
7776*4882a593Smuzhiyun	<title>SetupProc</title>
7777*4882a593Smuzhiyun
7778*4882a593Smuzhiyun	<para>
7779*4882a593Smuzhiyun    For dynamically loaded modules, a <varname>ModuleData</varname>
7780*4882a593Smuzhiyun    variable is required.  It is should be the name of the driver
7781*4882a593Smuzhiyun    prepended to "ModuleData".  A <function>Setup()</function> function is
7782*4882a593Smuzhiyun    also required, which calls <function>xf86AddDriver()</function> to add
7783*4882a593Smuzhiyun    the driver to the main list of drivers.
7784*4882a593Smuzhiyun	</para>
7785*4882a593Smuzhiyun
7786*4882a593Smuzhiyun	<programlisting>
7787*4882a593Smuzhiyunstatic MODULESETUPPROTO(zzzSetup);
7788*4882a593Smuzhiyun
7789*4882a593SmuzhiyunXF86ModuleData zzzModuleData = { &amp;zzzVersRec, zzzSetup, NULL };
7790*4882a593Smuzhiyun
7791*4882a593Smuzhiyunstatic pointer
7792*4882a593SmuzhiyunzzzSetup(pointer module, pointer opts, int *errmaj, int *errmin)
7793*4882a593Smuzhiyun{
7794*4882a593Smuzhiyun    static Bool setupDone = FALSE;
7795*4882a593Smuzhiyun
7796*4882a593Smuzhiyun    /* This module should be loaded only once, but check to be sure. */
7797*4882a593Smuzhiyun
7798*4882a593Smuzhiyun    if (!setupDone) {
7799*4882a593Smuzhiyun        /*
7800*4882a593Smuzhiyun         * Modules that this driver always requires may be loaded
7801*4882a593Smuzhiyun         * here  by calling LoadSubModule().
7802*4882a593Smuzhiyun         */
7803*4882a593Smuzhiyun
7804*4882a593Smuzhiyun        setupDone = TRUE;
7805*4882a593Smuzhiyun        xf86AddDriver(&amp;MGA, module, 0);
7806*4882a593Smuzhiyun
7807*4882a593Smuzhiyun        /*
7808*4882a593Smuzhiyun         * The return value must be non-NULL on success even though
7809*4882a593Smuzhiyun         * there is no TearDownProc.
7810*4882a593Smuzhiyun         */
7811*4882a593Smuzhiyun        return (pointer)1;
7812*4882a593Smuzhiyun    } else {
7813*4882a593Smuzhiyun        if (errmaj) *errmaj = LDR_ONCEONLY;
7814*4882a593Smuzhiyun        return NULL;
7815*4882a593Smuzhiyun    }
7816*4882a593Smuzhiyun}
7817*4882a593Smuzhiyun	</programlisting>
7818*4882a593Smuzhiyun      </sect3>
7819*4882a593Smuzhiyun
7820*4882a593Smuzhiyun      <sect3>
7821*4882a593Smuzhiyun	<title>GetRec, FreeRec</title>
7822*4882a593Smuzhiyun
7823*4882a593Smuzhiyun	<para>
7824*4882a593Smuzhiyun    A function is usually required to allocate the driver's
7825*4882a593Smuzhiyun    screen-specific data structure and hook it into the
7826*4882a593Smuzhiyun    <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> field.
7827*4882a593Smuzhiyun    The <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> is
7828*4882a593Smuzhiyun    initialised to <constant>NULL</constant>, so it is easy to check if the
7829*4882a593Smuzhiyun    initialisation has already been done.  After allocating it, initialise
7830*4882a593Smuzhiyun    the fields.  By using <function>xnfcalloc()</function> to do the allocation
7831*4882a593Smuzhiyun    it is zeroed, and if the allocation fails the server exits.
7832*4882a593Smuzhiyun	</para>
7833*4882a593Smuzhiyun
7834*4882a593Smuzhiyun	<para>
7835*4882a593Smuzhiyun    NOTE:
7836*4882a593Smuzhiyun    When allocating structures from inside the driver which are defined
7837*4882a593Smuzhiyun    on the common level it is important to initialize the structure to
7838*4882a593Smuzhiyun    zero.
7839*4882a593Smuzhiyun    Only this guarantees that the server remains source compatible to
7840*4882a593Smuzhiyun    future changes in common level structures.
7841*4882a593Smuzhiyun	</para>
7842*4882a593Smuzhiyun
7843*4882a593Smuzhiyun	<programlisting>
7844*4882a593Smuzhiyunstatic Bool
7845*4882a593SmuzhiyunZZZGetRec(ScrnInfoPtr pScrn)
7846*4882a593Smuzhiyun{
7847*4882a593Smuzhiyun    if (pScrn-&gt;driverPrivate != NULL)
7848*4882a593Smuzhiyun        return TRUE;
7849*4882a593Smuzhiyun    pScrn-&gt;driverPrivate = xnfcalloc(sizeof(ZZZRec), 1);
7850*4882a593Smuzhiyun    /* Initialise as required */
7851*4882a593Smuzhiyun    ...
7852*4882a593Smuzhiyun    return TRUE;
7853*4882a593Smuzhiyun}
7854*4882a593Smuzhiyun	</programlisting>
7855*4882a593Smuzhiyun
7856*4882a593Smuzhiyun	<para>
7857*4882a593Smuzhiyun    Define a macro in <filename>"zzz.h"</filename> which gets a pointer to
7858*4882a593Smuzhiyun    the <structname>ZZZRec</structname> when given <parameter>pScrn</parameter>:
7859*4882a593Smuzhiyun
7860*4882a593Smuzhiyun	  <programlisting>
7861*4882a593Smuzhiyun#define ZZZPTR(p) ((ZZZPtr)((p)-&gt;driverPrivate))
7862*4882a593Smuzhiyun	  </programlisting>
7863*4882a593Smuzhiyun	</para>
7864*4882a593Smuzhiyun
7865*4882a593Smuzhiyun	<para>
7866*4882a593Smuzhiyun    Define a function to free the above, setting it to <constant>NULL</constant>
7867*4882a593Smuzhiyun    once it has been freed:
7868*4882a593Smuzhiyun
7869*4882a593Smuzhiyun	  <programlisting>
7870*4882a593Smuzhiyunstatic void
7871*4882a593SmuzhiyunZZZFreeRec(ScrnInfoPtr pScrn)
7872*4882a593Smuzhiyun{
7873*4882a593Smuzhiyun    if (pScrn-&gt;driverPrivate == NULL)
7874*4882a593Smuzhiyun        return;
7875*4882a593Smuzhiyun    xfree(pScrn-&gt;driverPrivate);
7876*4882a593Smuzhiyun    pScrn-&gt;driverPrivate = NULL;
7877*4882a593Smuzhiyun}
7878*4882a593Smuzhiyun	  </programlisting>
7879*4882a593Smuzhiyun	</para>
7880*4882a593Smuzhiyun      </sect3>
7881*4882a593Smuzhiyun
7882*4882a593Smuzhiyun      <sect3>
7883*4882a593Smuzhiyun	<title>Identify</title>
7884*4882a593Smuzhiyun
7885*4882a593Smuzhiyun	<para>
7886*4882a593Smuzhiyun    Define the <function>Identify()</function> function.  It is run before
7887*4882a593Smuzhiyun    the Probe, and typically prints out an identifying message, which
7888*4882a593Smuzhiyun    might include the chipsets it supports.  This function is mandatory:
7889*4882a593Smuzhiyun
7890*4882a593Smuzhiyun	  <programlisting>
7891*4882a593Smuzhiyunstatic void
7892*4882a593SmuzhiyunZZZIdentify(int flags)
7893*4882a593Smuzhiyun{
7894*4882a593Smuzhiyun    xf86PrintChipsets(ZZZ_NAME, "driver for ZZZ Tech chipsets",
7895*4882a593Smuzhiyun                      ZZZChipsets);
7896*4882a593Smuzhiyun}
7897*4882a593Smuzhiyun	  </programlisting>
7898*4882a593Smuzhiyun	</para>
7899*4882a593Smuzhiyun      </sect3>
7900*4882a593Smuzhiyun
7901*4882a593Smuzhiyun      <sect3>
7902*4882a593Smuzhiyun	<title>Probe</title>
7903*4882a593Smuzhiyun
7904*4882a593Smuzhiyun	<para>
7905*4882a593Smuzhiyun    Define the <function>Probe()</function> function.  The purpose of this
7906*4882a593Smuzhiyun    is to find all instances of the hardware that the driver supports,
7907*4882a593Smuzhiyun    and for the ones not already claimed by another driver, claim the
7908*4882a593Smuzhiyun    slot, and allocate a <structname>ScrnInfoRec</structname>.  This should be
7909*4882a593Smuzhiyun    a minimal probe, and it should under no circumstances leave the
7910*4882a593Smuzhiyun    state of the hardware changed.  Because a device is found, don't
7911*4882a593Smuzhiyun    assume that it will be used.  Don't do any initialisations other
7912*4882a593Smuzhiyun    than the required <structname>ScrnInfoRec</structname> initialisations.
7913*4882a593Smuzhiyun    Don't allocate any new data structures.
7914*4882a593Smuzhiyun	</para>
7915*4882a593Smuzhiyun
7916*4882a593Smuzhiyun	<para>
7917*4882a593Smuzhiyun    This function is mandatory.
7918*4882a593Smuzhiyun	</para>
7919*4882a593Smuzhiyun
7920*4882a593Smuzhiyun	<para>
7921*4882a593Smuzhiyun    NOTE: The <function>xf86DrvMsg()</function> functions cannot be used from
7922*4882a593Smuzhiyun    the Probe.
7923*4882a593Smuzhiyun	</para>
7924*4882a593Smuzhiyun
7925*4882a593Smuzhiyun	<programlisting>
7926*4882a593Smuzhiyunstatic Bool
7927*4882a593SmuzhiyunZZZProbe(DriverPtr drv, int flags)
7928*4882a593Smuzhiyun{
7929*4882a593Smuzhiyun    Bool foundScreen = FALSE;
7930*4882a593Smuzhiyun    int numDevSections, numUsed;
7931*4882a593Smuzhiyun    GDevPtr *devSections;
7932*4882a593Smuzhiyun    int *usedChips;
7933*4882a593Smuzhiyun    int i;
7934*4882a593Smuzhiyun
7935*4882a593Smuzhiyun    /*
7936*4882a593Smuzhiyun     * Find the config file Device sections that match this
7937*4882a593Smuzhiyun     * driver, and return if there are none.
7938*4882a593Smuzhiyun     */
7939*4882a593Smuzhiyun    if ((numDevSections = xf86MatchDevice(ZZZ_DRIVER_NAME,
7940*4882a593Smuzhiyun                                          &amp;devSections)) &lt;= 0) {
7941*4882a593Smuzhiyun        return FALSE;
7942*4882a593Smuzhiyun    }
7943*4882a593Smuzhiyun
7944*4882a593Smuzhiyun    /*
7945*4882a593Smuzhiyun     * Since this is a PCI card, "probing" just amounts to checking
7946*4882a593Smuzhiyun     * the PCI data that the server has already collected.  If there
7947*4882a593Smuzhiyun     * is none, return.
7948*4882a593Smuzhiyun     *
7949*4882a593Smuzhiyun     * Although the config file is allowed to override things, it
7950*4882a593Smuzhiyun     * is reasonable to not allow it to override the detection
7951*4882a593Smuzhiyun     * of no PCI video cards.
7952*4882a593Smuzhiyun     *
7953*4882a593Smuzhiyun     * The provided xf86MatchPciInstances() helper takes care of
7954*4882a593Smuzhiyun     * the details.
7955*4882a593Smuzhiyun     */
7956*4882a593Smuzhiyun    /* test if PCI bus present */
7957*4882a593Smuzhiyun    if (xf86GetPciVideoInfo()) {
7958*4882a593Smuzhiyun
7959*4882a593Smuzhiyun        numUsed = xf86MatchPciInstances(ZZZ_NAME, PCI_VENDOR_ZZZ,
7960*4882a593Smuzhiyun                            ZZZChipsets, ZZZPciChipsets, devSections,
7961*4882a593Smuzhiyun                            numDevSections, drv, &amp;usedChips);
7962*4882a593Smuzhiyun
7963*4882a593Smuzhiyun        for (i = 0; i &lt; numUsed; i++) {
7964*4882a593Smuzhiyun            ScrnInfoPtr pScrn = NULL;
7965*4882a593Smuzhiyun            if ((pScrn = xf86ConfigPciEntity(pScrn, flags, usedChips[i],
7966*4882a593Smuzhiyun                                             ZZZPciChipsets, NULL, NULL,
7967*4882a593Smuzhiyun                                             NULL, NULL, NULL))) {
7968*4882a593Smuzhiyun               /* Allocate a ScrnInfoRec */
7969*4882a593Smuzhiyun               pScrn-&gt;driverVersion = VERSION;
7970*4882a593Smuzhiyun               pScrn-&gt;driverName    = ZZZ_DRIVER_NAME;
7971*4882a593Smuzhiyun               pScrn-&gt;name          = ZZZ_NAME;
7972*4882a593Smuzhiyun               pScrn-&gt;Probe         = ZZZProbe;
7973*4882a593Smuzhiyun               pScrn-&gt;PreInit       = ZZZPreInit;
7974*4882a593Smuzhiyun               pScrn-&gt;ScreenInit    = ZZZScreenInit;
7975*4882a593Smuzhiyun               pScrn-&gt;SwitchMode    = ZZZSwitchMode;
7976*4882a593Smuzhiyun               pScrn-&gt;AdjustFrame   = ZZZAdjustFrame;
7977*4882a593Smuzhiyun               pScrn-&gt;EnterVT       = ZZZEnterVT;
7978*4882a593Smuzhiyun               pScrn-&gt;LeaveVT       = ZZZLeaveVT;
7979*4882a593Smuzhiyun               pScrn-&gt;FreeScreen    = ZZZFreeScreen;
7980*4882a593Smuzhiyun               pScrn-&gt;ValidMode     = ZZZValidMode;
7981*4882a593Smuzhiyun               foundScreen = TRUE;
7982*4882a593Smuzhiyun               /* add screen to entity */
7983*4882a593Smuzhiyun           }
7984*4882a593Smuzhiyun        }
7985*4882a593Smuzhiyun        xfree(usedChips);
7986*4882a593Smuzhiyun    }
7987*4882a593Smuzhiyun
7988*4882a593Smuzhiyun    xfree(devSections);
7989*4882a593Smuzhiyun    return foundScreen;
7990*4882a593Smuzhiyun	</programlisting>
7991*4882a593Smuzhiyun      </sect3>
7992*4882a593Smuzhiyun
7993*4882a593Smuzhiyun      <sect3>
7994*4882a593Smuzhiyun	<title>AvailableOptions</title>
7995*4882a593Smuzhiyun
7996*4882a593Smuzhiyun	<para>
7997*4882a593Smuzhiyun    Define the <function>AvailableOptions()</function> function. The purpose
7998*4882a593Smuzhiyun    of this is to return the available driver options back to the
7999*4882a593Smuzhiyun    -configure option, so that an xorg.conf file can be built and the
8000*4882a593Smuzhiyun    user can see which options are available for them to use.
8001*4882a593Smuzhiyun	</para>
8002*4882a593Smuzhiyun      </sect3>
8003*4882a593Smuzhiyun
8004*4882a593Smuzhiyun      <sect3>
8005*4882a593Smuzhiyun	<title>PreInit</title>
8006*4882a593Smuzhiyun
8007*4882a593Smuzhiyun	<para>
8008*4882a593Smuzhiyun    Define the <function>PreInit()</function> function.  The purpose of
8009*4882a593Smuzhiyun    this is to find all the information required to determine if the
8010*4882a593Smuzhiyun    configuration is usable, and to initialise those parts of the
8011*4882a593Smuzhiyun    <structname>ScrnInfoRec</structname> that can be set once at the beginning
8012*4882a593Smuzhiyun    of the first server generation.  The information should be found in
8013*4882a593Smuzhiyun    the least intrusive way possible.
8014*4882a593Smuzhiyun	</para>
8015*4882a593Smuzhiyun
8016*4882a593Smuzhiyun	<para>
8017*4882a593Smuzhiyun    This function is mandatory.
8018*4882a593Smuzhiyun	</para>
8019*4882a593Smuzhiyun
8020*4882a593Smuzhiyun	<para>
8021*4882a593Smuzhiyun    NOTES:
8022*4882a593Smuzhiyun	  <orderedlist>
8023*4882a593Smuzhiyun	    <listitem><para>
8024*4882a593Smuzhiyun	 The <function>PreInit()</function> function is only called once
8025*4882a593Smuzhiyun	 during the life of the X server (at the start of the first
8026*4882a593Smuzhiyun	 generation).
8027*4882a593Smuzhiyun	      </para></listitem>
8028*4882a593Smuzhiyun
8029*4882a593Smuzhiyun	    <listitem><para>
8030*4882a593Smuzhiyun	 Data allocated here must be of the type that persists for
8031*4882a593Smuzhiyun	 the life of the X server.  This means that data that hooks into
8032*4882a593Smuzhiyun	 the <structname>ScrnInfoRec</structname>'s <structfield>privates</structfield>
8033*4882a593Smuzhiyun	 field should be allocated here, but data that hooks into the
8034*4882a593Smuzhiyun	 <structname>ScreenRec</structname>'s <structfield>devPrivates</structfield> field
8035*4882a593Smuzhiyun	 should not be allocated here.  The <structfield>driverPrivate</structfield>
8036*4882a593Smuzhiyun	 field should also be allocated here.
8037*4882a593Smuzhiyun	      </para></listitem>
8038*4882a593Smuzhiyun
8039*4882a593Smuzhiyun	    <listitem><para>
8040*4882a593Smuzhiyun	 Although the <structname>ScrnInfoRec</structname> has been allocated
8041*4882a593Smuzhiyun	 before this function is called, the <structname>ScreenRec</structname>
8042*4882a593Smuzhiyun	 has not been allocated.  That means that things requiring it
8043*4882a593Smuzhiyun	 cannot be used in this function.
8044*4882a593Smuzhiyun	      </para></listitem>
8045*4882a593Smuzhiyun
8046*4882a593Smuzhiyun	    <listitem><para>
8047*4882a593Smuzhiyun	 Very little of the <structname>ScrnInfoRec</structname> has been
8048*4882a593Smuzhiyun	 initialised when this function is called.  It is important to
8049*4882a593Smuzhiyun	 get the order of doing things right in this function.
8050*4882a593Smuzhiyun	      </para></listitem>
8051*4882a593Smuzhiyun
8052*4882a593Smuzhiyun	  </orderedlist>
8053*4882a593Smuzhiyun	</para>
8054*4882a593Smuzhiyun
8055*4882a593Smuzhiyun	<programlisting>
8056*4882a593Smuzhiyunstatic Bool
8057*4882a593SmuzhiyunZZZPreInit(ScrnInfoPtr pScrn, int flags)
8058*4882a593Smuzhiyun{
8059*4882a593Smuzhiyun    /* Fill in the monitor field */
8060*4882a593Smuzhiyun    pScrn-&gt;monitor = pScrn-&gt;confScreen-&gt;monitor;
8061*4882a593Smuzhiyun
8062*4882a593Smuzhiyun    /*
8063*4882a593Smuzhiyun     * If using the vgahw module, it will typically be loaded
8064*4882a593Smuzhiyun     * here by calling xf86LoadSubModule(pScrn, "vgahw");
8065*4882a593Smuzhiyun     */
8066*4882a593Smuzhiyun
8067*4882a593Smuzhiyun    /*
8068*4882a593Smuzhiyun     * Set the depth/bpp.  Use the globally preferred depth/bpp.  If the
8069*4882a593Smuzhiyun     * driver has special default depth/bpp requirements, the defaults should
8070*4882a593Smuzhiyun     * be specified here explicitly.
8071*4882a593Smuzhiyun     * We support both 24bpp and 32bpp framebuffer layouts.
8072*4882a593Smuzhiyun     * This sets pScrn-&gt;display also.
8073*4882a593Smuzhiyun     */
8074*4882a593Smuzhiyun    if (!xf86SetDepthBpp(pScrn, 0, 0, 0,
8075*4882a593Smuzhiyun                         Support24bppFb | Support32bppFb)) {
8076*4882a593Smuzhiyun        return FALSE;
8077*4882a593Smuzhiyun    } else {
8078*4882a593Smuzhiyun        if (depth/bpp isn't one we support) {
8079*4882a593Smuzhiyun            print error message;
8080*4882a593Smuzhiyun            return FALSE;
8081*4882a593Smuzhiyun        }
8082*4882a593Smuzhiyun    }
8083*4882a593Smuzhiyun    /* Print out the depth/bpp that was set */
8084*4882a593Smuzhiyun    xf86PrintDepthBpp(pScrn);
8085*4882a593Smuzhiyun
8086*4882a593Smuzhiyun    /* Set bits per RGB for 8bpp */
8087*4882a593Smuzhiyun    if (pScrn-&gt;depth &lt;= 8) {
8088*4882a593Smuzhiyun        /* Take into account a dac_6_bit option here */
8089*4882a593Smuzhiyun        pScrn-&gt;rgbBits = 6 or 8;
8090*4882a593Smuzhiyun    }
8091*4882a593Smuzhiyun
8092*4882a593Smuzhiyun    /*
8093*4882a593Smuzhiyun     * xf86SetWeight() and xf86SetDefaultVisual() must be called
8094*4882a593Smuzhiyun     * after pScrn-&gt;display is initialised.
8095*4882a593Smuzhiyun     */
8096*4882a593Smuzhiyun
8097*4882a593Smuzhiyun    /* Set weight/mask/offset for depth &gt; 8 */
8098*4882a593Smuzhiyun    if (pScrn-&gt;depth &gt; 8) {
8099*4882a593Smuzhiyun        if (!xf86SetWeight(pScrn, defaultWeight, defaultMask)) {
8100*4882a593Smuzhiyun            return FALSE;
8101*4882a593Smuzhiyun        } else {
8102*4882a593Smuzhiyun            if (weight isn't one we support) {
8103*4882a593Smuzhiyun                print error message;
8104*4882a593Smuzhiyun                return FALSE;
8105*4882a593Smuzhiyun            }
8106*4882a593Smuzhiyun        }
8107*4882a593Smuzhiyun    }
8108*4882a593Smuzhiyun
8109*4882a593Smuzhiyun    /* Set the default visual. */
8110*4882a593Smuzhiyun    if (!xf86SetDefaultVisual(pScrn, -1)) {
8111*4882a593Smuzhiyun        return FALSE;
8112*4882a593Smuzhiyun    } else {
8113*4882a593Smuzhiyun        if (visual isn't one we support) {
8114*4882a593Smuzhiyun            print error message;
8115*4882a593Smuzhiyun            return FALSE;
8116*4882a593Smuzhiyun        }
8117*4882a593Smuzhiyun    }
8118*4882a593Smuzhiyun
8119*4882a593Smuzhiyun    /* If the driver supports gamma correction, set the gamma. */
8120*4882a593Smuzhiyun    if (!xf86SetGamma(pScrn, default_gamma)) {
8121*4882a593Smuzhiyun        return FALSE;
8122*4882a593Smuzhiyun    }
8123*4882a593Smuzhiyun
8124*4882a593Smuzhiyun    /* This driver uses a programmable clock */
8125*4882a593Smuzhiyun    pScrn-&gt;progClock = TRUE;
8126*4882a593Smuzhiyun
8127*4882a593Smuzhiyun    /* Allocate the ZZZRec driverPrivate */
8128*4882a593Smuzhiyun    if (!ZZZGetRec(pScrn)) {
8129*4882a593Smuzhiyun        return FALSE;
8130*4882a593Smuzhiyun    }
8131*4882a593Smuzhiyun
8132*4882a593Smuzhiyun    pZzz = ZZZPTR(pScrn);
8133*4882a593Smuzhiyun
8134*4882a593Smuzhiyun    /* Collect all of the option flags (fill in pScrn-&gt;options) */
8135*4882a593Smuzhiyun    xf86CollectOptions(pScrn, NULL);
8136*4882a593Smuzhiyun
8137*4882a593Smuzhiyun    /*
8138*4882a593Smuzhiyun     * Process the options based on the information in ZZZOptions.
8139*4882a593Smuzhiyun     * The results are written to pZzz-&gt;Options.  If all of the options
8140*4882a593Smuzhiyun     * processing is done within this function a local variable "options"
8141*4882a593Smuzhiyun     * can be used instead of pZzz-&gt;Options.
8142*4882a593Smuzhiyun     */
8143*4882a593Smuzhiyun    if (!(pZzz-&gt;Options = xalloc(sizeof(ZZZOptions))))
8144*4882a593Smuzhiyun        return FALSE;
8145*4882a593Smuzhiyun    (void)memcpy(pZzz-&gt;Options, ZZZOptions, sizeof(ZZZOptions));
8146*4882a593Smuzhiyun    xf86ProcessOptions(pScrn-&gt;scrnIndex, pScrn-&gt;options, pZzz-&gt;Options);
8147*4882a593Smuzhiyun
8148*4882a593Smuzhiyun    /*
8149*4882a593Smuzhiyun     * Set various fields of ScrnInfoRec and/or ZZZRec based on
8150*4882a593Smuzhiyun     * the options found.
8151*4882a593Smuzhiyun     */
8152*4882a593Smuzhiyun    from = X_DEFAULT;
8153*4882a593Smuzhiyun    pZzz-&gt;hwCursor = FALSE;
8154*4882a593Smuzhiyun    if (xf86IsOptionSet(pZzz-&gt;Options, OPTION_HW_CURSOR)) {
8155*4882a593Smuzhiyun        from = X_CONFIG;
8156*4882a593Smuzhiyun        pZzz-&gt;hwCursor = TRUE;
8157*4882a593Smuzhiyun    }
8158*4882a593Smuzhiyun    xf86DrvMsg(pScrn-&gt;scrnIndex, from, "Using %s cursor\n",
8159*4882a593Smuzhiyun               pZzz-&gt;hwCursor ? "HW" : "SW");
8160*4882a593Smuzhiyun    if (xf86IsOptionSet(pZzz-&gt;Options, OPTION_NOACCEL)) {
8161*4882a593Smuzhiyun        pZzz-&gt;noAccel = TRUE;
8162*4882a593Smuzhiyun        xf86DrvMsg(pScrn-&gt;scrnIndex, X_CONFIG,
8163*4882a593Smuzhiyun                   "Acceleration disabled\n");
8164*4882a593Smuzhiyun    } else {
8165*4882a593Smuzhiyun        pZzz-&gt;noAccel = FALSE;
8166*4882a593Smuzhiyun    }
8167*4882a593Smuzhiyun    if (xf86IsOptionSet(pZzz-&gt;Options, OPTION_PCI_RETRY)) {
8168*4882a593Smuzhiyun        pZzz-&gt;UsePCIRetry = TRUE;
8169*4882a593Smuzhiyun        xf86DrvMsg(pScrn-&gt;scrnIndex, X_CONFIG, "PCI retry enabled\n");
8170*4882a593Smuzhiyun    }
8171*4882a593Smuzhiyun    pZzz-&gt;fooHack = 0;
8172*4882a593Smuzhiyun    if (xf86GetOptValInteger(pZzz-&gt;Options, OPTION_FOO_HACK,
8173*4882a593Smuzhiyun                             &amp;pZzz-&gt;fooHack)) {
8174*4882a593Smuzhiyun        xf86DrvMsg(pScrn-&gt;scrnIndex, X_CONFIG, "Foo Hack set to %d\n",
8175*4882a593Smuzhiyun                   pZzz-&gt;fooHack);
8176*4882a593Smuzhiyun    }
8177*4882a593Smuzhiyun
8178*4882a593Smuzhiyun    /*
8179*4882a593Smuzhiyun     * Find the PCI slot(s) that this screen claimed in the probe.
8180*4882a593Smuzhiyun     * In this case, exactly one is expected, so complain otherwise.
8181*4882a593Smuzhiyun     * Note in this case we're not interested in the card types so
8182*4882a593Smuzhiyun     * that parameter is set to NULL.
8183*4882a593Smuzhiyun     */
8184*4882a593Smuzhiyun    if ((i = xf86GetPciInfoForScreen(pScrn-&gt;scrnIndex, &amp;pciList, NULL))
8185*4882a593Smuzhiyun        != 1) {
8186*4882a593Smuzhiyun        print error message;
8187*4882a593Smuzhiyun        ZZZFreeRec(pScrn);
8188*4882a593Smuzhiyun        if (i &gt; 0)
8189*4882a593Smuzhiyun            xfree(pciList);
8190*4882a593Smuzhiyun        return FALSE;
8191*4882a593Smuzhiyun    }
8192*4882a593Smuzhiyun    /* Note that pciList should be freed below when no longer needed */
8193*4882a593Smuzhiyun
8194*4882a593Smuzhiyun    /*
8195*4882a593Smuzhiyun     * Determine the chipset, allowing config file chipset and
8196*4882a593Smuzhiyun     * chipid values to override the probed information.  The config
8197*4882a593Smuzhiyun     * chipset value has precedence over its chipid value if both
8198*4882a593Smuzhiyun     * are present.
8199*4882a593Smuzhiyun     *
8200*4882a593Smuzhiyun     * It isn't necessary to fill in pScrn-&gt;chipset if the driver
8201*4882a593Smuzhiyun     * keeps track of the chipset in its ZZZRec.
8202*4882a593Smuzhiyun     */
8203*4882a593Smuzhiyun
8204*4882a593Smuzhiyun    ...
8205*4882a593Smuzhiyun
8206*4882a593Smuzhiyun    /*
8207*4882a593Smuzhiyun     * Determine video memory, fb base address, I/O addresses, etc,
8208*4882a593Smuzhiyun     * allowing the config file to override probed values.
8209*4882a593Smuzhiyun     *
8210*4882a593Smuzhiyun     * Set the appropriate pScrn fields (videoRam is probably the
8211*4882a593Smuzhiyun     * most important one that other code might require), and
8212*4882a593Smuzhiyun     * print out the settings.
8213*4882a593Smuzhiyun     */
8214*4882a593Smuzhiyun
8215*4882a593Smuzhiyun    ...
8216*4882a593Smuzhiyun
8217*4882a593Smuzhiyun    /* Initialise a clockRanges list. */
8218*4882a593Smuzhiyun
8219*4882a593Smuzhiyun    ...
8220*4882a593Smuzhiyun
8221*4882a593Smuzhiyun    /* Set any other chipset specific things in the ZZZRec */
8222*4882a593Smuzhiyun
8223*4882a593Smuzhiyun    ...
8224*4882a593Smuzhiyun
8225*4882a593Smuzhiyun    /* Select valid modes from those available */
8226*4882a593Smuzhiyun
8227*4882a593Smuzhiyun    i = xf86ValidateModes(pScrn, pScrn-&gt;monitor-&gt;Modes,
8228*4882a593Smuzhiyun                          pScrn-&gt;display-&gt;modes, clockRanges,
8229*4882a593Smuzhiyun                          NULL, minPitch, maxPitch, rounding,
8230*4882a593Smuzhiyun                          minHeight, maxHeight,
8231*4882a593Smuzhiyun                          pScrn-&gt;display-&gt;virtualX,
8232*4882a593Smuzhiyun                          pScrn-&gt;display-&gt;virtualY,
8233*4882a593Smuzhiyun                          pScrn-&gt;videoRam * 1024,
8234*4882a593Smuzhiyun                          LOOKUP_BEST_REFRESH);
8235*4882a593Smuzhiyun    if (i == -1) {
8236*4882a593Smuzhiyun        ZZZFreeRec(pScrn);
8237*4882a593Smuzhiyun        return FALSE;
8238*4882a593Smuzhiyun    }
8239*4882a593Smuzhiyun
8240*4882a593Smuzhiyun    /* Prune the modes marked as invalid */
8241*4882a593Smuzhiyun
8242*4882a593Smuzhiyun    xf86PruneDriverModes(pScrn);
8243*4882a593Smuzhiyun
8244*4882a593Smuzhiyun    /* If no valid modes, return */
8245*4882a593Smuzhiyun
8246*4882a593Smuzhiyun    if (i == 0 || pScrn-&gt;modes == NULL) {
8247*4882a593Smuzhiyun        print error message;
8248*4882a593Smuzhiyun        ZZZFreeRec(pScrn);
8249*4882a593Smuzhiyun        return FALSE;
8250*4882a593Smuzhiyun    }
8251*4882a593Smuzhiyun
8252*4882a593Smuzhiyun    /*
8253*4882a593Smuzhiyun     * Initialise the CRTC fields for the modes.  This driver expects
8254*4882a593Smuzhiyun     * vertical values to be halved for interlaced modes.
8255*4882a593Smuzhiyun     */
8256*4882a593Smuzhiyun    xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V);
8257*4882a593Smuzhiyun
8258*4882a593Smuzhiyun    /* Set the current mode to the first in the list. */
8259*4882a593Smuzhiyun    pScrn-&gt;currentMode = pScrn-&gt;modes;
8260*4882a593Smuzhiyun
8261*4882a593Smuzhiyun    /* Print the list of modes being used. */
8262*4882a593Smuzhiyun    xf86PrintModes(pScrn);
8263*4882a593Smuzhiyun
8264*4882a593Smuzhiyun    /* Set the DPI */
8265*4882a593Smuzhiyun    xf86SetDpi(pScrn, 0, 0);
8266*4882a593Smuzhiyun
8267*4882a593Smuzhiyun    /* Load bpp-specific modules */
8268*4882a593Smuzhiyun    switch (pScrn-&gt;bitsPerPixel) {
8269*4882a593Smuzhiyun    case 1:
8270*4882a593Smuzhiyun        mod = "xf1bpp";
8271*4882a593Smuzhiyun        break;
8272*4882a593Smuzhiyun    case 4:
8273*4882a593Smuzhiyun        mod = "xf4bpp";
8274*4882a593Smuzhiyun        break;
8275*4882a593Smuzhiyun    case 8:
8276*4882a593Smuzhiyun        mod = "cfb";
8277*4882a593Smuzhiyun        break;
8278*4882a593Smuzhiyun    case 16:
8279*4882a593Smuzhiyun        mod = "cfb16";
8280*4882a593Smuzhiyun        break;
8281*4882a593Smuzhiyun    case 24:
8282*4882a593Smuzhiyun        mod = "cfb24";
8283*4882a593Smuzhiyun        break;
8284*4882a593Smuzhiyun    case 32:
8285*4882a593Smuzhiyun        mod = "cfb32";
8286*4882a593Smuzhiyun        break;
8287*4882a593Smuzhiyun    }
8288*4882a593Smuzhiyun    if (mod &amp;&amp; !xf86LoadSubModule(pScrn, mod))
8289*4882a593Smuzhiyun        ZZZFreeRec(pScrn);
8290*4882a593Smuzhiyun        return FALSE;
8291*4882a593Smuzhiyun
8292*4882a593Smuzhiyun
8293*4882a593Smuzhiyun    /* Done */
8294*4882a593Smuzhiyun    return TRUE;
8295*4882a593Smuzhiyun}
8296*4882a593Smuzhiyun	</programlisting>
8297*4882a593Smuzhiyun      </sect3>
8298*4882a593Smuzhiyun
8299*4882a593Smuzhiyun      <sect3>
8300*4882a593Smuzhiyun	<title>MapMem, UnmapMem</title>
8301*4882a593Smuzhiyun
8302*4882a593Smuzhiyun	<para>
8303*4882a593Smuzhiyun    Define functions to map and unmap the video memory and any other
8304*4882a593Smuzhiyun    memory apertures required.  These functions are not mandatory, but
8305*4882a593Smuzhiyun    it is often useful to have such functions.
8306*4882a593Smuzhiyun	</para>
8307*4882a593Smuzhiyun
8308*4882a593Smuzhiyun	<programlisting>
8309*4882a593Smuzhiyunstatic Bool
8310*4882a593SmuzhiyunZZZMapMem(ScrnInfoPtr pScrn)
8311*4882a593Smuzhiyun{
8312*4882a593Smuzhiyun    /* Call xf86MapPciMem() to map each PCI memory area */
8313*4882a593Smuzhiyun    ...
8314*4882a593Smuzhiyun    return TRUE or FALSE;
8315*4882a593Smuzhiyun}
8316*4882a593Smuzhiyun
8317*4882a593Smuzhiyunstatic Bool
8318*4882a593SmuzhiyunZZZUnmapMem(ScrnInfoPtr pScrn)
8319*4882a593Smuzhiyun{
8320*4882a593Smuzhiyun    /* Call xf86UnMapVidMem() to unmap each memory area */
8321*4882a593Smuzhiyun    ...
8322*4882a593Smuzhiyun    return TRUE or FALSE;
8323*4882a593Smuzhiyun}
8324*4882a593Smuzhiyun	</programlisting>
8325*4882a593Smuzhiyun      </sect3>
8326*4882a593Smuzhiyun
8327*4882a593Smuzhiyun      <sect3>
8328*4882a593Smuzhiyun	<title>Save, Restore</title>
8329*4882a593Smuzhiyun
8330*4882a593Smuzhiyun	<para>
8331*4882a593Smuzhiyun    Define functions to save and restore the original video state.  These
8332*4882a593Smuzhiyun    functions are not mandatory, but are often useful.
8333*4882a593Smuzhiyun	</para>
8334*4882a593Smuzhiyun
8335*4882a593Smuzhiyun	<programlisting>
8336*4882a593Smuzhiyunstatic void
8337*4882a593SmuzhiyunZZZSave(ScrnInfoPtr pScrn)
8338*4882a593Smuzhiyun{
8339*4882a593Smuzhiyun    /*
8340*4882a593Smuzhiyun     * Save state into per-screen data structures.
8341*4882a593Smuzhiyun     * If using the vgahw module, vgaHWSave will typically be
8342*4882a593Smuzhiyun     * called here.
8343*4882a593Smuzhiyun     */
8344*4882a593Smuzhiyun    ...
8345*4882a593Smuzhiyun}
8346*4882a593Smuzhiyun
8347*4882a593Smuzhiyunstatic void
8348*4882a593SmuzhiyunZZZRestore(ScrnInfoPtr pScrn)
8349*4882a593Smuzhiyun{
8350*4882a593Smuzhiyun    /*
8351*4882a593Smuzhiyun     * Restore state from per-screen data structures.
8352*4882a593Smuzhiyun     * If using the vgahw module, vgaHWRestore will typically be
8353*4882a593Smuzhiyun     * called here.
8354*4882a593Smuzhiyun     */
8355*4882a593Smuzhiyun    ...
8356*4882a593Smuzhiyun}
8357*4882a593Smuzhiyun	</programlisting>
8358*4882a593Smuzhiyun      </sect3>
8359*4882a593Smuzhiyun
8360*4882a593Smuzhiyun      <sect3>
8361*4882a593Smuzhiyun	<title>ModeInit</title>
8362*4882a593Smuzhiyun
8363*4882a593Smuzhiyun	<para>
8364*4882a593Smuzhiyun    Define a function to initialise a new video mode.  This function isn't
8365*4882a593Smuzhiyun    mandatory, but is often useful.
8366*4882a593Smuzhiyun	</para>
8367*4882a593Smuzhiyun
8368*4882a593Smuzhiyun	<programlisting>
8369*4882a593Smuzhiyunstatic Bool
8370*4882a593SmuzhiyunZZZModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
8371*4882a593Smuzhiyun{
8372*4882a593Smuzhiyun    /*
8373*4882a593Smuzhiyun     * Program a video mode.  If using the vgahw module,
8374*4882a593Smuzhiyun     * vgaHWInit and vgaRestore will typically be called here.
8375*4882a593Smuzhiyun     * Once up to the point where there can't be a failure
8376*4882a593Smuzhiyun     * set pScrn-&gt;vtSema to TRUE.
8377*4882a593Smuzhiyun     */
8378*4882a593Smuzhiyun    ...
8379*4882a593Smuzhiyun}
8380*4882a593Smuzhiyun	</programlisting>
8381*4882a593Smuzhiyun      </sect3>
8382*4882a593Smuzhiyun
8383*4882a593Smuzhiyun      <sect3>
8384*4882a593Smuzhiyun	<title>ScreenInit</title>
8385*4882a593Smuzhiyun
8386*4882a593Smuzhiyun	<para>
8387*4882a593Smuzhiyun    Define the <function>ScreenInit()</function> function.  This is called
8388*4882a593Smuzhiyun    at the start of each server generation, and should fill in as much
8389*4882a593Smuzhiyun    of the <structname>ScreenRec</structname> as possible as well as any other
8390*4882a593Smuzhiyun    data that is initialised once per generation.  It should initialise
8391*4882a593Smuzhiyun    the framebuffer layers it is using, and initialise the initial video
8392*4882a593Smuzhiyun    mode.
8393*4882a593Smuzhiyun	</para>
8394*4882a593Smuzhiyun
8395*4882a593Smuzhiyun	<para>
8396*4882a593Smuzhiyun    This function is mandatory.
8397*4882a593Smuzhiyun	</para>
8398*4882a593Smuzhiyun
8399*4882a593Smuzhiyun	<para>
8400*4882a593Smuzhiyun    NOTE: The <structname>ScreenRec</structname> (<parameter>pScreen</parameter>) is
8401*4882a593Smuzhiyun	  passed to this driver, but it and the
8402*4882a593Smuzhiyun	  <varname>ScrnInfoRecs</varname> are not yet hooked into each
8403*4882a593Smuzhiyun	  other.  This means that in this function, and functions it
8404*4882a593Smuzhiyun	  calls, one cannot be found from the other.
8405*4882a593Smuzhiyun	</para>
8406*4882a593Smuzhiyun
8407*4882a593Smuzhiyun	<programlisting>
8408*4882a593Smuzhiyunstatic Bool
8409*4882a593SmuzhiyunZZZScreenInit(ScreenPtr pScreen, int argc, char **argv)
8410*4882a593Smuzhiyun{
8411*4882a593Smuzhiyun    /* Get the ScrnInfoRec */
8412*4882a593Smuzhiyun    pScrn = xf86ScreenToScrn(pScreen);
8413*4882a593Smuzhiyun
8414*4882a593Smuzhiyun    /*
8415*4882a593Smuzhiyun     * If using the vgahw module, its data structures and related
8416*4882a593Smuzhiyun     * things are typically initialised/mapped here.
8417*4882a593Smuzhiyun     */
8418*4882a593Smuzhiyun
8419*4882a593Smuzhiyun    /* Save the current video state */
8420*4882a593Smuzhiyun    ZZZSave(pScrn);
8421*4882a593Smuzhiyun
8422*4882a593Smuzhiyun    /* Initialise the first mode */
8423*4882a593Smuzhiyun    ZZZModeInit(pScrn, pScrn-&gt;currentMode);
8424*4882a593Smuzhiyun
8425*4882a593Smuzhiyun    /* Set the viewport if supported */
8426*4882a593Smuzhiyun
8427*4882a593Smuzhiyun    ZZZAdjustFrame(pScrn, pScrn-&gt;frameX0, pScrn-&gt;frameY0);
8428*4882a593Smuzhiyun
8429*4882a593Smuzhiyun    /*
8430*4882a593Smuzhiyun     * Setup the screen's visuals, and initialise the framebuffer
8431*4882a593Smuzhiyun     * code.
8432*4882a593Smuzhiyun     */
8433*4882a593Smuzhiyun
8434*4882a593Smuzhiyun    /* Reset the visual list */
8435*4882a593Smuzhiyun    miClearVisualTypes();
8436*4882a593Smuzhiyun
8437*4882a593Smuzhiyun    /*
8438*4882a593Smuzhiyun     * Setup the visuals supported.  This driver only supports
8439*4882a593Smuzhiyun     * TrueColor for bpp &gt; 8, so the default set of visuals isn't
8440*4882a593Smuzhiyun     * acceptable.  To deal with this, call miSetVisualTypes with
8441*4882a593Smuzhiyun     * the appropriate visual mask.
8442*4882a593Smuzhiyun     */
8443*4882a593Smuzhiyun
8444*4882a593Smuzhiyun    if (pScrn-&gt;bitsPerPixel &gt; 8) {
8445*4882a593Smuzhiyun        if (!miSetVisualTypes(pScrn-&gt;depth, TrueColorMask,
8446*4882a593Smuzhiyun                              pScrn-&gt;rgbBits, pScrn-&gt;defaultVisual))
8447*4882a593Smuzhiyun            return FALSE;
8448*4882a593Smuzhiyun    } else {
8449*4882a593Smuzhiyun        if (!miSetVisualTypes(pScrn-&gt;depth,
8450*4882a593Smuzhiyun                              miGetDefaultVisualMask(pScrn-&gt;depth),
8451*4882a593Smuzhiyun                              pScrn-&gt;rgbBits, pScrn-&gt;defaultVisual))
8452*4882a593Smuzhiyun            return FALSE;
8453*4882a593Smuzhiyun    }
8454*4882a593Smuzhiyun
8455*4882a593Smuzhiyun    /*
8456*4882a593Smuzhiyun     * Initialise the framebuffer.
8457*4882a593Smuzhiyun     */
8458*4882a593Smuzhiyun
8459*4882a593Smuzhiyun    switch (pScrn-&gt;bitsPerPixel) {
8460*4882a593Smuzhiyun    case 1:
8461*4882a593Smuzhiyun        ret = xf1bppScreenInit(pScreen, FbBase,
8462*4882a593Smuzhiyun                               pScrn-&gt;virtualX, pScrn-&gt;virtualY,
8463*4882a593Smuzhiyun                               pScrn-&gt;xDpi, pScrn-&gt;yDpi,
8464*4882a593Smuzhiyun                               pScrn-&gt;displayWidth);
8465*4882a593Smuzhiyun        break;
8466*4882a593Smuzhiyun    case 4:
8467*4882a593Smuzhiyun        ret = xf4bppScreenInit(pScreen, FbBase,
8468*4882a593Smuzhiyun                               pScrn-&gt;virtualX, pScrn-&gt;virtualY,
8469*4882a593Smuzhiyun                               pScrn-&gt;xDpi, pScrn-&gt;yDpi,
8470*4882a593Smuzhiyun                               pScrn-&gt;displayWidth);
8471*4882a593Smuzhiyun        break;
8472*4882a593Smuzhiyun    case 8:
8473*4882a593Smuzhiyun        ret = cfbScreenInit(pScreen, FbBase,
8474*4882a593Smuzhiyun                            pScrn-&gt;virtualX, pScrn-&gt;virtualY,
8475*4882a593Smuzhiyun                            pScrn-&gt;xDpi, pScrn-&gt;yDpi,
8476*4882a593Smuzhiyun                            pScrn-&gt;displayWidth);
8477*4882a593Smuzhiyun        break;
8478*4882a593Smuzhiyun    case 16:
8479*4882a593Smuzhiyun        ret = cfb16ScreenInit(pScreen, FbBase,
8480*4882a593Smuzhiyun                              pScrn-&gt;virtualX, pScrn-&gt;virtualY,
8481*4882a593Smuzhiyun                              pScrn-&gt;xDpi, pScrn-&gt;yDpi,
8482*4882a593Smuzhiyun                              pScrn-&gt;displayWidth);
8483*4882a593Smuzhiyun        break;
8484*4882a593Smuzhiyun    case 24:
8485*4882a593Smuzhiyun        ret = cfb24ScreenInit(pScreen, FbBase,
8486*4882a593Smuzhiyun                              pScrn-&gt;virtualX, pScrn-&gt;virtualY,
8487*4882a593Smuzhiyun                              pScrn-&gt;xDpi, pScrn-&gt;yDpi,
8488*4882a593Smuzhiyun                              pScrn-&gt;displayWidth);
8489*4882a593Smuzhiyun        break;
8490*4882a593Smuzhiyun    case 32:
8491*4882a593Smuzhiyun        ret = cfb32ScreenInit(pScreen, FbBase,
8492*4882a593Smuzhiyun                              pScrn-&gt;virtualX, pScrn-&gt;virtualY,
8493*4882a593Smuzhiyun                              pScrn-&gt;xDpi, pScrn-&gt;yDpi,
8494*4882a593Smuzhiyun                              pScrn-&gt;displayWidth);
8495*4882a593Smuzhiyun        break;
8496*4882a593Smuzhiyun    default:
8497*4882a593Smuzhiyun        print a message about an internal error;
8498*4882a593Smuzhiyun        ret = FALSE;
8499*4882a593Smuzhiyun        break;
8500*4882a593Smuzhiyun    }
8501*4882a593Smuzhiyun
8502*4882a593Smuzhiyun    if (!ret)
8503*4882a593Smuzhiyun        return FALSE;
8504*4882a593Smuzhiyun
8505*4882a593Smuzhiyun    /* Override the default mask/offset settings */
8506*4882a593Smuzhiyun    if (pScrn-&gt;bitsPerPixel &gt; 8) {
8507*4882a593Smuzhiyun        for (i = 0, visual = pScreen-&gt;visuals;
8508*4882a593Smuzhiyun             i &lt; pScreen-&gt;numVisuals; i++, visual++) {
8509*4882a593Smuzhiyun            if ((visual-&gt;class | DynamicClass) == DirectColor) {
8510*4882a593Smuzhiyun                visual-&gt;offsetRed = pScrn-&gt;offset.red;
8511*4882a593Smuzhiyun                visual-&gt;offsetGreen = pScrn-&gt;offset.green;
8512*4882a593Smuzhiyun                visual-&gt;offsetBlue = pScrn-&gt;offset.blue;
8513*4882a593Smuzhiyun                visual-&gt;redMask = pScrn-&gt;mask.red;
8514*4882a593Smuzhiyun                visual-&gt;greenMask = pScrn-&gt;mask.green;
8515*4882a593Smuzhiyun                visual-&gt;blueMask = pScrn-&gt;mask.blue;
8516*4882a593Smuzhiyun            }
8517*4882a593Smuzhiyun        }
8518*4882a593Smuzhiyun    }
8519*4882a593Smuzhiyun
8520*4882a593Smuzhiyun    /*
8521*4882a593Smuzhiyun     * If banking is needed, initialise an miBankInfoRec (defined in
8522*4882a593Smuzhiyun     * "mibank.h"), and call miInitializeBanking().
8523*4882a593Smuzhiyun     */
8524*4882a593Smuzhiyun    if (!miInitializeBanking(pScreen, pScrn-&gt;virtualX, pScrn-&gt;virtualY,
8525*4882a593Smuzhiyun                                     pScrn-&gt;displayWidth, pBankInfo))
8526*4882a593Smuzhiyun        return FALSE;
8527*4882a593Smuzhiyun
8528*4882a593Smuzhiyun    /*
8529*4882a593Smuzhiyun     * Set initial black &amp; white colourmap indices.
8530*4882a593Smuzhiyun     */
8531*4882a593Smuzhiyun    xf86SetBlackWhitePixels(pScreen);
8532*4882a593Smuzhiyun
8533*4882a593Smuzhiyun    /*
8534*4882a593Smuzhiyun     * Install colourmap functions.
8535*4882a593Smuzhiyun     */
8536*4882a593Smuzhiyun
8537*4882a593Smuzhiyun    ...
8538*4882a593Smuzhiyun
8539*4882a593Smuzhiyun    /*
8540*4882a593Smuzhiyun     * Initialise cursor functions.  This example is for the mi
8541*4882a593Smuzhiyun     * software cursor.
8542*4882a593Smuzhiyun     */
8543*4882a593Smuzhiyun    miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
8544*4882a593Smuzhiyun
8545*4882a593Smuzhiyun    /* Initialise the default colourmap */
8546*4882a593Smuzhiyun    switch (pScrn-&gt;depth) {
8547*4882a593Smuzhiyun    case 1:
8548*4882a593Smuzhiyun        if (!xf1bppCreateDefColormap(pScreen))
8549*4882a593Smuzhiyun            return FALSE;
8550*4882a593Smuzhiyun        break;
8551*4882a593Smuzhiyun    case 4:
8552*4882a593Smuzhiyun        if (!xf4bppCreateDefColormap(pScreen))
8553*4882a593Smuzhiyun            return FALSE;
8554*4882a593Smuzhiyun        break;
8555*4882a593Smuzhiyun    default:
8556*4882a593Smuzhiyun        if (!cfbCreateDefColormap(pScreen))
8557*4882a593Smuzhiyun            return FALSE;
8558*4882a593Smuzhiyun        break;
8559*4882a593Smuzhiyun    }
8560*4882a593Smuzhiyun
8561*4882a593Smuzhiyun    /*
8562*4882a593Smuzhiyun     * Wrap the CloseScreen vector and set SaveScreen.
8563*4882a593Smuzhiyun     */
8564*4882a593Smuzhiyun    ZZZPTR(pScrn)-&gt;CloseScreen = pScreen-&gt;CloseScreen;
8565*4882a593Smuzhiyun    pScreen-&gt;CloseScreen = ZZZCloseScreen;
8566*4882a593Smuzhiyun    pScreen-&gt;SaveScreen = ZZZSaveScreen;
8567*4882a593Smuzhiyun
8568*4882a593Smuzhiyun    /* Report any unused options (only for the first generation) */
8569*4882a593Smuzhiyun    if (serverGeneration == 1) {
8570*4882a593Smuzhiyun        xf86ShowUnusedOptions(pScrn-&gt;scrnIndex, pScrn-&gt;options);
8571*4882a593Smuzhiyun    }
8572*4882a593Smuzhiyun
8573*4882a593Smuzhiyun    /* Done */
8574*4882a593Smuzhiyun    return TRUE;
8575*4882a593Smuzhiyun}
8576*4882a593Smuzhiyun	</programlisting>
8577*4882a593Smuzhiyun      </sect3>
8578*4882a593Smuzhiyun
8579*4882a593Smuzhiyun      <sect3>
8580*4882a593Smuzhiyun	<title>SwitchMode</title>
8581*4882a593Smuzhiyun
8582*4882a593Smuzhiyun	<para>
8583*4882a593Smuzhiyun    Define the <function>SwitchMode()</function> function if mode switching
8584*4882a593Smuzhiyun    is supported by the driver.
8585*4882a593Smuzhiyun	</para>
8586*4882a593Smuzhiyun
8587*4882a593Smuzhiyun	<programlisting>
8588*4882a593Smuzhiyunstatic Bool
8589*4882a593SmuzhiyunZZZSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
8590*4882a593Smuzhiyun{
8591*4882a593Smuzhiyun    return ZZZModeInit(pScrn, mode);
8592*4882a593Smuzhiyun}
8593*4882a593Smuzhiyun	</programlisting>
8594*4882a593Smuzhiyun      </sect3>
8595*4882a593Smuzhiyun
8596*4882a593Smuzhiyun      <sect3>
8597*4882a593Smuzhiyun	<title>AdjustFrame</title>
8598*4882a593Smuzhiyun
8599*4882a593Smuzhiyun	<para>
8600*4882a593Smuzhiyun    Define the <function>AdjustFrame()</function> function if the driver
8601*4882a593Smuzhiyun    supports this.
8602*4882a593Smuzhiyun	</para>
8603*4882a593Smuzhiyun
8604*4882a593Smuzhiyun	<programlisting>
8605*4882a593Smuzhiyunstatic void
8606*4882a593SmuzhiyunZZZAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
8607*4882a593Smuzhiyun{
8608*4882a593Smuzhiyun    /* Adjust the viewport */
8609*4882a593Smuzhiyun}
8610*4882a593Smuzhiyun	</programlisting>
8611*4882a593Smuzhiyun      </sect3>
8612*4882a593Smuzhiyun
8613*4882a593Smuzhiyun      <sect3>
8614*4882a593Smuzhiyun	<title>EnterVT, LeaveVT</title>
8615*4882a593Smuzhiyun
8616*4882a593Smuzhiyun	<para>
8617*4882a593Smuzhiyun    Define the <function>EnterVT()</function> and <function>LeaveVT()</function>
8618*4882a593Smuzhiyun    functions.
8619*4882a593Smuzhiyun	</para>
8620*4882a593Smuzhiyun
8621*4882a593Smuzhiyun	<para>
8622*4882a593Smuzhiyun    These functions are mandatory.
8623*4882a593Smuzhiyun	</para>
8624*4882a593Smuzhiyun
8625*4882a593Smuzhiyun	<programlisting>
8626*4882a593Smuzhiyunstatic Bool
8627*4882a593SmuzhiyunZZZEnterVT(ScrnInfoPtr pScrn)
8628*4882a593Smuzhiyun{
8629*4882a593Smuzhiyun    return ZZZModeInit(pScrn, pScrn-&gt;currentMode);
8630*4882a593Smuzhiyun}
8631*4882a593Smuzhiyun
8632*4882a593Smuzhiyunstatic void
8633*4882a593SmuzhiyunZZZLeaveVT(ScrnInfoPtr pScrn)
8634*4882a593Smuzhiyun{
8635*4882a593Smuzhiyun    ZZZRestore(pScrn);
8636*4882a593Smuzhiyun}
8637*4882a593Smuzhiyun	</programlisting>
8638*4882a593Smuzhiyun      </sect3>
8639*4882a593Smuzhiyun
8640*4882a593Smuzhiyun      <sect3>
8641*4882a593Smuzhiyun	<title>CloseScreen</title>
8642*4882a593Smuzhiyun
8643*4882a593Smuzhiyun	<para>
8644*4882a593Smuzhiyun    Define the <function>CloseScreen()</function> function:
8645*4882a593Smuzhiyun	</para>
8646*4882a593Smuzhiyun
8647*4882a593Smuzhiyun	<para>
8648*4882a593Smuzhiyun    This function is mandatory.  Note that it unwraps the previously
8649*4882a593Smuzhiyun    wrapped <structfield>pScreen-&gt;CloseScreen</structfield>, and finishes by
8650*4882a593Smuzhiyun    calling it.
8651*4882a593Smuzhiyun	</para>
8652*4882a593Smuzhiyun
8653*4882a593Smuzhiyun	<programlisting>
8654*4882a593Smuzhiyunstatic Bool
8655*4882a593SmuzhiyunZZZCloseScreen(ScreenPtr pScreen)
8656*4882a593Smuzhiyun{
8657*4882a593Smuzhiyun    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
8658*4882a593Smuzhiyun    if (pScrn-&gt;vtSema) {
8659*4882a593Smuzhiyun        ZZZRestore(pScrn);
8660*4882a593Smuzhiyun        ZZZUnmapMem(pScrn);
8661*4882a593Smuzhiyun    }
8662*4882a593Smuzhiyun    pScrn-&gt;vtSema = FALSE;
8663*4882a593Smuzhiyun    pScreen-&gt;CloseScreen = ZZZPTR(pScrn)-&gt;CloseScreen;
8664*4882a593Smuzhiyun    return (*pScreen-&gt;CloseScreen)(pScreen);
8665*4882a593Smuzhiyun}
8666*4882a593Smuzhiyun	</programlisting>
8667*4882a593Smuzhiyun      </sect3>
8668*4882a593Smuzhiyun
8669*4882a593Smuzhiyun      <sect3>
8670*4882a593Smuzhiyun	<title>SaveScreen</title>
8671*4882a593Smuzhiyun
8672*4882a593Smuzhiyun	<para>
8673*4882a593Smuzhiyun    Define the <function>SaveScreen()</function> function (the screen
8674*4882a593Smuzhiyun    blanking function).  When using the vgahw module, this will typically
8675*4882a593Smuzhiyun    be:
8676*4882a593Smuzhiyun
8677*4882a593Smuzhiyun	  <programlisting>
8678*4882a593Smuzhiyunstatic Bool
8679*4882a593SmuzhiyunZZZSaveScreen(ScreenPtr pScreen, int mode)
8680*4882a593Smuzhiyun{
8681*4882a593Smuzhiyun    return vgaHWSaveScreen(pScreen, mode);
8682*4882a593Smuzhiyun}
8683*4882a593Smuzhiyun	  </programlisting>
8684*4882a593Smuzhiyun	</para>
8685*4882a593Smuzhiyun
8686*4882a593Smuzhiyun	<para>
8687*4882a593Smuzhiyun    This function is mandatory.  Before modifying any hardware register
8688*4882a593Smuzhiyun    directly this function needs to make sure that the Xserver is active
8689*4882a593Smuzhiyun    by checking if <parameter>pScrn</parameter> is non-NULL and for
8690*4882a593Smuzhiyun    <literal remap="tt">pScrn-&gt;vtSema == TRUE</literal>.
8691*4882a593Smuzhiyun	</para>
8692*4882a593Smuzhiyun      </sect3>
8693*4882a593Smuzhiyun
8694*4882a593Smuzhiyun      <sect3>
8695*4882a593Smuzhiyun	<title>FreeScreen</title>
8696*4882a593Smuzhiyun
8697*4882a593Smuzhiyun	<para>
8698*4882a593Smuzhiyun    Define the <function>FreeScreen()</function> function.  This function
8699*4882a593Smuzhiyun    is optional.  It should be defined if the <structname>ScrnInfoRec</structname>
8700*4882a593Smuzhiyun    <structfield>driverPrivate</structfield> field is used so that it can be freed
8701*4882a593Smuzhiyun    when a screen is deleted by the common layer for reasons possibly
8702*4882a593Smuzhiyun    beyond the driver's control.  This function is not used in during
8703*4882a593Smuzhiyun    normal (error free) operation.  The per-generation data is freed by
8704*4882a593Smuzhiyun    the <function>CloseScreen()</function> function.
8705*4882a593Smuzhiyun	</para>
8706*4882a593Smuzhiyun
8707*4882a593Smuzhiyun	<programlisting>
8708*4882a593Smuzhiyunstatic void
8709*4882a593SmuzhiyunZZZFreeScreen(ScrnInfoPtr pScrn)
8710*4882a593Smuzhiyun{
8711*4882a593Smuzhiyun    /*
8712*4882a593Smuzhiyun     * If the vgahw module is used vgaHWFreeHWRec() would be called
8713*4882a593Smuzhiyun     * here.
8714*4882a593Smuzhiyun     */
8715*4882a593Smuzhiyun    ZZZFreeRec(pScrn);
8716*4882a593Smuzhiyun}
8717*4882a593Smuzhiyun
8718*4882a593Smuzhiyun	</programlisting>
8719*4882a593Smuzhiyun
8720*4882a593Smuzhiyun      </sect3>
8721*4882a593Smuzhiyun
8722*4882a593Smuzhiyun    </sect2>
8723*4882a593Smuzhiyun
8724*4882a593Smuzhiyun  </sect1>
8725*4882a593Smuzhiyun
8726*4882a593Smuzhiyun</article>
8727