1706f2543Smrg<?xml version="1.0" encoding="ISO-8859-1"?>
2706f2543Smrg<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3706f2543Smrg "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
4706f2543Smrg <!ENTITY % defs SYSTEM "/xserver/doc/xml/xserver.ent"> %defs;
5706f2543Smrg <!-- config file keyword markup -->
6706f2543Smrg <!-- specific config file keywords -->
7706f2543Smrg <!ENTITY k.device "<emphasis>Device</emphasis>">
8706f2543Smrg <!ENTITY k.monitor "<emphasis>Monitor</emphasis>">
9706f2543Smrg <!ENTITY k.display "<emphasis>Display</emphasis>">
10706f2543Smrg <!ENTITY k.inputdevice "<emphasis>InputDevice</emphasis>">
11706f2543Smrg <!ENTITY k.screen "<emphasis>Screen</emphasis>">
12706f2543Smrg <!ENTITY k.serverlayout "<emphasis>ServerLayout</emphasis>">
13706f2543Smrg <!ENTITY k.driver "<emphasis>Driver</emphasis>">
14706f2543Smrg <!ENTITY k.module "<emphasis>Module</emphasis>">
15706f2543Smrg <!ENTITY k.identifier "<emphasis>Identifier</emphasis>">
16706f2543Smrg <!ENTITY k.serverflags "<emphasis>ServerFlags</emphasis>">
17706f2543Smrg] >
18706f2543Smrg
19706f2543Smrg<article>
20706f2543Smrg  <articleinfo>
21706f2543Smrg
22706f2543Smrg    <title>XFree86 DDX Design (Xorg server version &xserver.version;)</title>
23706f2543Smrg
24706f2543Smrg    <authorgroup>
25706f2543Smrg      <corpauthor><ulink url="http://www.xfree86.org/">
26706f2543Smrg	The XFree86 Project, Inc.</ulink></corpauthor>
27706f2543Smrg      <corpauthor><ulink url="http://www.x.org/">
28706f2543Smrg	The X.Org Foundation, Inc.</ulink></corpauthor>
29706f2543Smrg
30706f2543Smrg      <othercredit>
31706f2543Smrg	<firstname>Jim</firstname><surname>Gettys</surname>
32706f2543Smrg	<contrib>Updates for X11R6.7</contrib>
33706f2543Smrg      </othercredit>
34706f2543Smrg    </authorgroup>
35706f2543Smrg
36706f2543Smrg    <pubdate>&xserver.reldate;</pubdate>
37706f2543Smrg    <releaseinfo>Xorg server version &xserver.version;</releaseinfo>
38706f2543Smrg
39706f2543Smrg  </articleinfo>
40706f2543Smrg
41706f2543Smrg  <note><para>
42706f2543SmrgThis document describes software undergoing continual evolution, and
43706f2543Smrgthe interfaces described here are subject to change without notice.
44706f2543SmrgThis document is intended to cover the interfaces as found in the
45706f2543Smrgxorg-server-&xserver.version; release, but is probably not completely
46706f2543Smrgin sync with the code base.
47706f2543Smrg    </para></note>
48706f2543Smrg
49706f2543Smrg
50706f2543Smrg  <sect1>
51706f2543Smrg    <title>Preface</title>
52706f2543Smrg
53706f2543Smrg    <para>
54706f2543SmrgThis document was originally the design spec for the DDX layer of the
55706f2543SmrgXFree86 4.0 X server.  The X.Org Foundation adopted the XFree86 4.4rc2
56706f2543Smrgversion of that server as the basis of the Xorg server project, and has
57706f2543Smrgevolved the XFree86 DDX layer greatly since forking.   This document thus
58706f2543Smrgcovers only the current implementation of the XFree86 DDX as found in the
59706f2543SmrgXorg server &xserver.version; release, and no longer matches the XFree86
60706f2543Smrgserver itself.
61706f2543Smrg      </para>
62706f2543Smrg
63706f2543Smrg    <para>
64706f2543SmrgThe XFree86 Project's broad design principles for XFree86 4.0 were:
65706f2543Smrg      <itemizedlist>
66706f2543Smrg	<listitem><para>keep it reasonable
67706f2543Smrg	    <itemizedlist>
68706f2543Smrg	      <listitem><para>We cannot rewrite the complete server
69706f2543Smrg		</para></listitem>
70706f2543Smrg	      <listitem><para>We don't want to re-invent the wheel
71706f2543Smrg		</para></listitem>
72706f2543Smrg	    </itemizedlist></para></listitem>
73706f2543Smrg	<listitem><para>keep it modular
74706f2543Smrg	    <itemizedlist>
75706f2543Smrg	      <listitem><para>As many things as possible should go into modules
76706f2543Smrg		</para></listitem>
77706f2543Smrg	      <listitem><para>The basic loader binary should be minimal
78706f2543Smrg		</para></listitem>
79706f2543Smrg	      <listitem><para>A clean design with well defined layering is
80706f2543Smrg		  important</para></listitem>
81706f2543Smrg	      <listitem><para>DDX specific global variables are a nono
82706f2543Smrg		</para></listitem>
83706f2543Smrg	      <listitem><para>The structure should be flexible enough to allow
84706f2543Smrg		  future extensions</para></listitem>
85706f2543Smrg	      <listitem><para>The structure should minimize duplication of
86706f2543Smrg		  common code</para></listitem>
87706f2543Smrg	    </itemizedlist></para></listitem>
88706f2543Smrg	<listitem><para>keep important features in mind
89706f2543Smrg	    <itemizedlist>
90706f2543Smrg	      <listitem><para>multiple screens, including multiple instances
91706f2543Smrg		  of drivers</para></listitem>
92706f2543Smrg	      <listitem><para>mixing different color depths and visuals on
93706f2543Smrg		  different and ideally even on the same screen
94706f2543Smrg		</para></listitem>
95706f2543Smrg	      <listitem><para>better control of the PCI device used
96706f2543Smrg		</para></listitem>
97706f2543Smrg	      <listitem><para>better config file parser</para></listitem>
98706f2543Smrg	      <listitem><para>get rid of all VGA compatibility assumptions
99706f2543Smrg		</para></listitem>
100706f2543Smrg	    </itemizedlist></para></listitem>
101706f2543Smrg      </itemizedlist>
102706f2543Smrg    </para>
103706f2543Smrg
104706f2543Smrg    <para>
105706f2543SmrgWhile the XFree86 project had a goal of avoiding changes to the DIX
106706f2543Smrglayer unless they found major deficiencies there, to avoid divergence from
107706f2543Smrgthe X.Org sample implementation they were integrating changes from, the
108706f2543SmrgX.Org developers now maintain both sides, and make changes where they are
109706f2543Smrgmost appropriate.   This document concentrates on the XFree86 DDX layer used
110706f2543Smrgin the Xorg server itself (the code found in <filename>hw/xfree86</filename>
111706f2543Smrgin the source tree), and developers will also want to refer to the
112706f2543Smrg<filename>Xserver-spec</filename> documentation that covers the DIX layer
113706f2543Smrgroutines common to all the X servers in the sample implementation.
114706f2543Smrg    </para>
115706f2543Smrg  </sect1>
116706f2543Smrg
117706f2543Smrg  <sect1>
118706f2543Smrg    <title>The xorg.conf File</title>
119706f2543Smrg
120706f2543Smrg    <para>
121706f2543SmrgThe xorg.conf file format is based on the XF86Config format from XFree86 4.4,
122706f2543Smrgwhich is in turn similar to the old XFree86 3.x XF86Config format, with the
123706f2543Smrgfollowing changes:
124706f2543Smrg    </para>
125706f2543Smrg
126706f2543Smrg    <sect2>
127706f2543Smrg      <title>&k.device; section</title>
128706f2543Smrg
129706f2543Smrg      <para>
130706f2543Smrg    The &k.device; sections are similar to what they used to be, and
131706f2543Smrg    describe hardware-specific information for a single video card.
132706f2543Smrg    &k.device;
133706f2543Smrg    Some new keywords are added:
134706f2543Smrg
135706f2543Smrg
136706f2543Smrg	<variablelist>
137706f2543Smrg	  <varlistentry><term>Driver "drivername"</term>
138706f2543Smrg	    <listitem><para>
139706f2543Smrg        Specifies the name of the driver to be used for the card.  This
140706f2543Smrg        is mandatory.
141706f2543Smrg	      </para></listitem></varlistentry>
142706f2543Smrg	  <varlistentry><term>BusID "busslot"</term>
143706f2543Smrg	    <listitem><para>
144706f2543Smrg        Specifies uniquely the location of the card on the bus.  The
145706f2543Smrg        purpose is to identify particular cards in a multi-headed
146706f2543Smrg        configuration.  The format of the argument is intentionally
147706f2543Smrg        vague, and may be architecture dependent.  For a PCI bus, it
148706f2543Smrg        is something like "bus:slot:func".
149706f2543Smrg	      </para></listitem></varlistentry>
150706f2543Smrg	</variablelist>
151706f2543Smrg      </para>
152706f2543Smrg
153706f2543Smrg      <para>
154706f2543Smrg    A &k.device; section is considered <quote>active</quote> if there is a reference
155706f2543Smrg    to it in an active &k.screen; section.
156706f2543Smrg      </para>
157706f2543Smrg    </sect2>
158706f2543Smrg
159706f2543Smrg    <sect2>
160706f2543Smrg      <title>&k.screen; section</title>
161706f2543Smrg
162706f2543Smrg      <para>
163706f2543Smrg    The &k.screen; sections are similar to what they used to be.  They
164706f2543Smrg    no longer have a &k.driver; keyword, but an &k.identifier; keyword
165706f2543Smrg    is added.  (The &k.driver; keyword may be accepted in place of the
166706f2543Smrg    &k.identifier; keyword for compatibility purposes.)  The identifier
167706f2543Smrg    can be used to identify which screen is to be active when multiple
168706f2543Smrg    &k.screen; sections are present.  It is possible to specify the active
169706f2543Smrg    screen from the command line.  A default is chosen in the absence
170706f2543Smrg    of one being specified.  A &k.screen; section is considered <quote>active</quote>
171706f2543Smrg    if there is a reference to it either from the command line, or from
172706f2543Smrg    an active &k.serverlayout; section.
173706f2543Smrg      </para>
174706f2543Smrg    </sect2>
175706f2543Smrg
176706f2543Smrg    <sect2>
177706f2543Smrg      <title>&k.inputdevice; section</title>
178706f2543Smrg
179706f2543Smrg      <para>
180706f2543Smrg    The &k.inputdevice; section is a new section that describes
181706f2543Smrg    configuration information for input devices.  It replaces the old
182706f2543Smrg    <emphasis>Keyboard</emphasis>, <emphasis>Pointer</emphasis> and <emphasis>XInput</emphasis>
183706f2543Smrg    sections.  Like the &k.device; section, it has two mandatory keywords:
184706f2543Smrg    &k.identifier; and &k.driver;.  For compatibility purposes the old
185706f2543Smrg    <emphasis>Keyboard</emphasis> and <emphasis>Pointer</emphasis> sections are
186706f2543Smrg    converted by the parser into &k.inputdevice; sections as follows:
187706f2543Smrg
188706f2543Smrg	<variablelist>
189706f2543Smrg	  <varlistentry><term><emphasis>Keyboard</emphasis></term>
190706f2543Smrg	    <listitem><literallayout>
191706f2543Smrg             &k.identifier; "Implicit Core Keyboard"
192706f2543Smrg             &k.driver; "keyboard"
193706f2543Smrg	      </literallayout></listitem></varlistentry>
194706f2543Smrg	  <varlistentry><term><emphasis>Pointer</emphasis></term>
195706f2543Smrg	    <listitem><literallayout>
196706f2543Smrg             &k.identifier; "Implicit Core Pointer"
197706f2543Smrg             &k.driver; "mouse"
198706f2543Smrg	      </literallayout></listitem></varlistentry>
199706f2543Smrg	</variablelist>
200706f2543Smrg      </para>
201706f2543Smrg
202706f2543Smrg      <para>
203706f2543Smrg    An &k.inputdevice; section is considered active if there is a
204706f2543Smrg    reference to it in an active &k.serverlayout; section.  An
205706f2543Smrg    &k.inputdevice; section may also be referenced implicitly if there
206706f2543Smrg    is no &k.serverlayout; section, if the <option>-screen</option> command
207706f2543Smrg    line options is used, or if the &k.serverlayout; section doesn't
208706f2543Smrg    reference any &k.inputdevice; sections.  In this case, the first
209706f2543Smrg    sections with drivers "keyboard" and "mouse" are used as the core
210706f2543Smrg    keyboard and pointer respectively.
211706f2543Smrg      </para>
212706f2543Smrg    </sect2>
213706f2543Smrg
214706f2543Smrg    <sect2>
215706f2543Smrg      <title>&k.serverlayout; section</title>
216706f2543Smrg
217706f2543Smrg      <para>
218706f2543Smrg    The &k.serverlayout; section is a new section that is used to identify
219706f2543Smrg    which &k.screen; sections are to be used in a multi-headed configuration,
220706f2543Smrg    and the relative layout of those screens.  It also identifies which
221706f2543Smrg    &k.inputdevice; sections are to be used.  Each &k.serverlayout; section
222706f2543Smrg    has an identifier, a list of &k.screen; section identifiers, and a list of
223706f2543Smrg    &k.inputdevice; section identifiers.  &k.serverflags; options may also be
224706f2543Smrg    included in a &k.serverlayout; section, making it possible to override
225706f2543Smrg    the global values in the &k.serverflags; section.
226706f2543Smrg      </para>
227706f2543Smrg
228706f2543Smrg      <para>
229706f2543Smrg    A &k.serverlayout; section can be made active by being referenced on
230706f2543Smrg    the command line.  In the absence of this, a default will be chosen
231706f2543Smrg    (the first one found).  The screen names may optionally be followed
232706f2543Smrg    by a number specifying the preferred screen number, and optionally
233706f2543Smrg    by information specifying the physical positioning of the screen,
234706f2543Smrg    either in absolute terms or relative to another screen (or screens).
235706f2543Smrg    When no screen number is specified, they are numbered according to
236706f2543Smrg    the order in which they are listed.  The old (now obsolete) method
237706f2543Smrg    of providing the positioning information is to give the names of
238706f2543Smrg    the four adjacent screens.  The order of these is top, bottom, left,
239706f2543Smrg    right.  Here is an example of a &k.serverlayout; section for two
240706f2543Smrg    screens using the old method, with the second located to the right
241706f2543Smrg    of the first:
242706f2543Smrg
243706f2543Smrg	<programlisting>
244706f2543Smrg      Section "ServerLayout"
245706f2543Smrg        Identifier "Main Layout"
246706f2543Smrg        Screen     0 "Screen 1" ""  ""  ""  "Screen 2"
247706f2543Smrg        Screen     1 "Screen 2"
248706f2543Smrg        Screen     "Screen 3"
249706f2543Smrg      EndSection
250706f2543Smrg	</programlisting>
251706f2543Smrg      </para>
252706f2543Smrg
253706f2543Smrg      <para>
254706f2543Smrg    The preferred way of specifying the layout is to explicitly specify
255706f2543Smrg    the screen's location in absolute terms or relative to another
256706f2543Smrg    screen.
257706f2543Smrg      </para>
258706f2543Smrg
259706f2543Smrg      <para>
260706f2543Smrg    In the absolute case, the upper left corner's coordinates are given
261706f2543Smrg    after the <emphasis>Absolute</emphasis> keyword.  If the coordinates are
262706f2543Smrg    omitted, a value of <code>(0,0)</code> is assumed.  An example
263706f2543Smrg    of absolute positioning follows:
264706f2543Smrg
265706f2543Smrg	<programlisting>
266706f2543Smrg      Section "ServerLayout"
267706f2543Smrg        Identifier "Main Layout"
268706f2543Smrg        Screen     0 "Screen 1" Absolute 0 0
269706f2543Smrg        Screen     1 "Screen 2" Absolute 1024 0
270706f2543Smrg        Screen     "Screen 3" Absolute 2048 0
271706f2543Smrg      EndSection
272706f2543Smrg	</programlisting>
273706f2543Smrg      </para>
274706f2543Smrg
275706f2543Smrg      <para>
276706f2543Smrg    In the relative case, the position is specified by either using one of
277706f2543Smrg    the following keywords followed by the name of the reference screen:
278706f2543Smrg
279706f2543Smrg	<simplelist type='vert' columns='1'>
280706f2543Smrg	  <member><emphasis>RightOf</emphasis></member>
281706f2543Smrg	  <member><emphasis>LeftOf</emphasis></member>
282706f2543Smrg	  <member><emphasis>Above</emphasis></member>
283706f2543Smrg	  <member><emphasis>Below</emphasis></member>
284706f2543Smrg	  <member><emphasis>Relative</emphasis></member>
285706f2543Smrg	</simplelist>
286706f2543Smrg      </para>
287706f2543Smrg
288706f2543Smrg      <para>
289706f2543Smrg    When the <emphasis>Relative</emphasis> keyword is used, the reference screen
290706f2543Smrg    name is followed by the coordinates of the new screen's origin
291706f2543Smrg    relative to reference screen.  The following example shows how to use
292706f2543Smrg    some of the relative positioning options.
293706f2543Smrg
294706f2543Smrg	<programlisting>
295706f2543Smrg      Section "ServerLayout"
296706f2543Smrg        Identifier "Main Layout"
297706f2543Smrg        Screen     0 "Screen 1"
298706f2543Smrg        Screen     1 "Screen 2" RightOf "Screen 1"
299706f2543Smrg        Screen     "Screen 3" Relative "Screen 1" 2048 0
300706f2543Smrg      EndSection
301706f2543Smrg	</programlisting>
302706f2543Smrg      </para>
303706f2543Smrg    </sect2>
304706f2543Smrg
305706f2543Smrg    <sect2>
306706f2543Smrg      <title>Options</title>
307706f2543Smrg
308706f2543Smrg      <para>
309706f2543Smrg    Options are used more extensively.  They may appear in most sections
310706f2543Smrg    now.  Options related to drivers can be present in the &k.screen;,
311706f2543Smrg    &k.device; and &k.monitor; sections and the &k.display; subsections.
312706f2543Smrg    The order of precedence is &k.display;, &k.screen;, &k.monitor;,
313706f2543Smrg    &k.device;.  Options have been extended to allow an optional value
314706f2543Smrg    to be specified in addition to the option name.  For more details
315706f2543Smrg    about options, see the <link linkend="options">Options</link> section
316706f2543Smrg    for details.
317706f2543Smrg      </para>
318706f2543Smrg    </sect2>
319706f2543Smrg  </sect1>
320706f2543Smrg
321706f2543Smrg  <sect1>
322706f2543Smrg    <title>Driver Interface</title>
323706f2543Smrg
324706f2543Smrg    <para>
325706f2543SmrgThe driver interface consists of a minimal set of entry points that are
326706f2543Smrgrequired based on the external events that the driver must react to.
327706f2543SmrgNo non-essential structure is imposed on the way they are used beyond
328706f2543Smrgthat.  This is a significant difference compared with the old design.
329706f2543Smrg    </para>
330706f2543Smrg
331706f2543Smrg    <para>
332706f2543SmrgThe entry points for drawing operations are already taken care of by
333706f2543Smrgthe framebuffer code (including, XAA).  Extensions and enhancements to
334706f2543Smrgframebuffer code are outside the scope of this document.
335706f2543Smrg    </para>
336706f2543Smrg
337706f2543Smrg    <para>
338706f2543SmrgThis approach to the driver interface provides good flexibility, but does
339706f2543Smrgincrease the complexity of drivers.  To help address this, the XFree86
340706f2543Smrgcommon layer provides a set of <quote>helper</quote> functions to take care of things
341706f2543Smrgthat most drivers need.  These helpers help minimise the amount of code
342706f2543Smrgduplication between drivers.  The use of helper functions by drivers is
343706f2543Smrghowever optional, though encouraged.  The basic philosophy behind the
344706f2543Smrghelper functions is that they should be useful to many drivers, that
345706f2543Smrgthey should balance this against the complexity of their interface.  It
346706f2543Smrgis inevitable that some drivers may find some helpers unsuitable and
347706f2543Smrgneed to provide their own code.
348706f2543Smrg    </para>
349706f2543Smrg
350706f2543Smrg    <para>
351706f2543SmrgEvents that a driver needs to react to are:
352706f2543Smrg
353706f2543Smrg      <variablelist>
354706f2543Smrg	<varlistentry><term>ScreenInit</term>
355706f2543Smrg
356706f2543Smrg	  <listitem><para>
357706f2543Smrg     An initialisation function is called from the DIX layer for each
358706f2543Smrg     screen at the start of each server generation.
359706f2543Smrg	    </para></listitem></varlistentry>
360706f2543Smrg
361706f2543Smrg	<varlistentry><term>Enter VT</term>
362706f2543Smrg
363706f2543Smrg	  <listitem><para>
364706f2543Smrg     The server takes control of the console.
365706f2543Smrg	    </para></listitem></varlistentry>
366706f2543Smrg
367706f2543Smrg	<varlistentry><term>Leave VT</term>
368706f2543Smrg
369706f2543Smrg	  <listitem><para>
370706f2543Smrg     The server releases control of the console.
371706f2543Smrg	    </para></listitem></varlistentry>
372706f2543Smrg
373706f2543Smrg	<varlistentry><term>Mode Switch</term>
374706f2543Smrg
375706f2543Smrg	  <listitem><para>
376706f2543Smrg     Change video mode.
377706f2543Smrg	    </para></listitem></varlistentry>
378706f2543Smrg
379706f2543Smrg	<varlistentry><term>ViewPort change</term>
380706f2543Smrg
381706f2543Smrg	  <listitem><para>
382706f2543Smrg     Change the origin of the physical view port.
383706f2543Smrg	    </para></listitem></varlistentry>
384706f2543Smrg
385706f2543Smrg	<varlistentry><term>ScreenSaver state change</term>
386706f2543Smrg
387706f2543Smrg	  <listitem><para>
388706f2543Smrg     Screen saver activation/deactivation.
389706f2543Smrg	    </para></listitem></varlistentry>
390706f2543Smrg
391706f2543Smrg	<varlistentry><term>CloseScreen</term>
392706f2543Smrg
393706f2543Smrg	  <listitem><para>
394706f2543Smrg     A close screen function is called from the DIX layer for each screen
395706f2543Smrg     at the end of each server generation.
396706f2543Smrg	    </para></listitem></varlistentry>
397706f2543Smrg      </variablelist>
398706f2543Smrg    </para>
399706f2543Smrg
400706f2543Smrg
401706f2543Smrg    <para>
402706f2543SmrgIn addition to these events, the following functions are required by
403706f2543Smrgthe XFree86 common layer:
404706f2543Smrg
405706f2543Smrg      <variablelist>
406706f2543Smrg	<varlistentry><term>Identify</term>
407706f2543Smrg
408706f2543Smrg	  <listitem><para>
409706f2543Smrg     Print a driver identifying message.
410706f2543Smrg	    </para></listitem></varlistentry>
411706f2543Smrg
412706f2543Smrg	<varlistentry><term>Probe</term>
413706f2543Smrg
414706f2543Smrg	  <listitem><para>
415706f2543Smrg     This is how a driver identifies if there is any hardware present that
416706f2543Smrg     it knows how to drive.
417706f2543Smrg	    </para></listitem></varlistentry>
418706f2543Smrg
419706f2543Smrg	<varlistentry><term>PreInit</term>
420706f2543Smrg
421706f2543Smrg	  <listitem><para>
422706f2543Smrg     Process information from the xorg.conf file, determine the
423706f2543Smrg     full characteristics of the hardware, and determine if a valid
424706f2543Smrg     configuration is present.
425706f2543Smrg	    </para></listitem></varlistentry>
426706f2543Smrg      </variablelist>
427706f2543Smrg    </para>
428706f2543Smrg
429706f2543Smrg    <para>
430706f2543SmrgThe VidMode extension also requires:
431706f2543Smrg
432706f2543Smrg      <variablelist>
433706f2543Smrg	<varlistentry><term>ValidMode</term>
434706f2543Smrg
435706f2543Smrg	  <listitem><para>
436706f2543Smrg     Identify if a new mode is usable with the current configuration.
437706f2543Smrg     The PreInit function (and/or helpers it calls) may also make use
438706f2543Smrg     of the ValidMode function or something similar.
439706f2543Smrg	    </para></listitem></varlistentry>
440706f2543Smrg      </variablelist>
441706f2543Smrg    </para>
442706f2543Smrg
443706f2543Smrg
444706f2543Smrg    <para>
445706f2543SmrgOther extensions may require other entry points.  The drivers will
446706f2543Smrginform the common layer of these in such cases.
447706f2543Smrg    </para>
448706f2543Smrg  </sect1>
449706f2543Smrg
450706f2543Smrg  <sect1>
451706f2543Smrg    <title>Resource Access Control Introduction</title>
452706f2543Smrg
453706f2543Smrg    <para>
454706f2543SmrgGraphics devices are accessed through ranges in I/O or memory space.
455706f2543SmrgWhile most modern graphics devices allow relocation of such ranges many
456706f2543Smrgof them still require the use of well established interfaces such as
457706f2543SmrgVGA memory and IO ranges or 8514/A IO ranges.  With modern buses (like
458706f2543SmrgPCI) it is possible for multiple video devices to share access to these
459706f2543Smrgresources.  The RAC (Resource Access Control) subsystem provides a
460706f2543Smrgmechanism for this.
461706f2543Smrg    </para>
462706f2543Smrg
463706f2543Smrg    <sect2>
464706f2543Smrg      <title>Terms and Definitions</title>
465706f2543Smrg
466706f2543Smrg      <sect3>
467706f2543Smrg	<title>Bus</title>
468706f2543Smrg
469706f2543Smrg	<para>
470706f2543Smrg    <quote>Bus</quote> is ambiguous as it is used for different things: it may refer
471706f2543Smrg    to physical incompatible extension connectors in a computer system.
472706f2543Smrg    The RAC system knows two such systems: The ISA bus and the PCI bus.
473706f2543Smrg    (On the software level EISA, MCA and VL buses are currently treated
474706f2543Smrg    like ISA buses).  <quote>Bus</quote> may also refer to logically different
475706f2543Smrg    entities on a single bus system which are connected via bridges.  A
476706f2543Smrg    PCI system may have several distinct PCI buses connecting each other
477706f2543Smrg    by PCI-PCI bridges or to the host CPU by HOST-PCI bridges.
478706f2543Smrg	</para>
479706f2543Smrg
480706f2543Smrg	<para>
481706f2543Smrg    Systems that host more than one bus system link these together using
482706f2543Smrg    bridges.  Bridges are a concern to RAC as they might block or pass
483706f2543Smrg    specific resources.  PCI-PCI bridges may be set up to pass VGA
484706f2543Smrg    resources to the secondary bus.  PCI-ISA buses pass any resources not
485706f2543Smrg    decoded on the primary PCI bus to the ISA bus.  This way VGA resources
486706f2543Smrg    (although exclusive on the ISA bus) can be shared by ISA and PCI
487706f2543Smrg    cards.  Currently HOST-PCI bridges are not yet handled by RAC as they
488706f2543Smrg    require specific drivers.
489706f2543Smrg	</para>
490706f2543Smrg      </sect3>
491706f2543Smrg
492706f2543Smrg      <sect3>
493706f2543Smrg	<title>Entity</title>
494706f2543Smrg
495706f2543Smrg	<para>
496706f2543Smrg    The smallest independently addressable unit on a system bus is
497706f2543Smrg    referred to as an entity.  So far we know ISA and PCI entities.  PCI
498706f2543Smrg    entities can be located on the PCI bus by an unique ID consisting of
499706f2543Smrg    the bus, card and function number.
500706f2543Smrg	</para>
501706f2543Smrg      </sect3>
502706f2543Smrg
503706f2543Smrg      <sect3>
504706f2543Smrg	<title>Resource</title>
505706f2543Smrg
506706f2543Smrg	<para>
507706f2543Smrg    <quote>Resource</quote> refers to a range of memory or I/O addresses an entity
508706f2543Smrg    can decode.
509706f2543Smrg	</para>
510706f2543Smrg
511706f2543Smrg	<para>
512706f2543Smrg    If a device is capable of disabling this decoding the resource is
513706f2543Smrg    called sharable.  For PCI devices a generic method is provided to
514706f2543Smrg    control resource decoding.  Other devices will have to provide a
515706f2543Smrg    device specific function to control decoding.
516706f2543Smrg	</para>
517706f2543Smrg
518706f2543Smrg	<para>
519706f2543Smrg    If the entity is capable of decoding this range at a different
520706f2543Smrg    location this resource is considered relocatable.
521706f2543Smrg	</para>
522706f2543Smrg
523706f2543Smrg	<para>
524706f2543Smrg    Resources which start at a specific address and occupy a single
525706f2543Smrg    continuous range are called block resources.
526706f2543Smrg	</para>
527706f2543Smrg
528706f2543Smrg	<para>
529706f2543Smrg    Alternatively resource addresses can be decoded in a way that they
530706f2543Smrg    satisfy the conditions:
531706f2543Smrg	  <programlisting>
532706f2543Smrg                    address &amp; mask == base
533706f2543Smrg	  </programlisting>
534706f2543Smrg    and
535706f2543Smrg	  <programlisting>
536706f2543Smrg                       base &amp; mask == base
537706f2543Smrg	  </programlisting>
538706f2543Smrg    Resources addressed in such a way are called sparse resources.
539706f2543Smrg	</para>
540706f2543Smrg
541706f2543Smrg      </sect3>
542706f2543Smrg
543706f2543Smrg      <sect3>
544706f2543Smrg	<title>Server States</title>
545706f2543Smrg
546706f2543Smrg	<para>
547706f2543Smrg    The resource access control system knows two server states: the
548706f2543Smrg    SETUP and the OPERATING state.  The SETUP state is entered whenever
549706f2543Smrg    a mode change takes place or the server exits or does VT switching.
550706f2543Smrg    During this state all entity resources are under resource access
551706f2543Smrg    control.  During OPERATING state only those entities are controlled
552706f2543Smrg    which actually have shared resources that conflict with others.
553706f2543Smrg	</para>
554706f2543Smrg      </sect3>
555706f2543Smrg    </sect2>
556706f2543Smrg  </sect1>
557706f2543Smrg
558706f2543Smrg  <sect1>
559706f2543Smrg    <title>Control Flow in the Server and Mandatory Driver Functions</title>
560706f2543Smrg
561706f2543Smrg    <para>
562706f2543SmrgAt the start of each server generation, <function>main()</function>
563706f2543Smrg(<filename>dix/main.c</filename>) calls the DDX function
564706f2543Smrg<function>InitOutput()</function>.  This is the first place that the DDX gets
565706f2543Smrgcontrol.  <function>InitOutput()</function> is expected to fill in the global
566706f2543Smrg<structname>screenInfo</structname> struct, and one
567706f2543Smrg<structfield>screenInfo.screen[]</structfield> entry for each screen present.
568706f2543SmrgHere is what <function>InitOutput()</function> does:
569706f2543Smrg    </para>
570706f2543Smrg
571706f2543Smrg    <sect2>
572706f2543Smrg      <title>Parse the xorg.conf file</title>
573706f2543Smrg
574706f2543Smrg      <para>
575706f2543Smrg    This is done at the start of the first server generation only.
576706f2543Smrg      </para>
577706f2543Smrg
578706f2543Smrg      <para>
579706f2543Smrg    The xorg.conf file is read in full, and the resulting information
580706f2543Smrg    stored in data structures.  None of the parsed information is
581706f2543Smrg    processed at this point.  The parser data structures are opaque to
582706f2543Smrg    the video drivers and to most of the common layer code.
583706f2543Smrg      </para>
584706f2543Smrg
585706f2543Smrg      <para>
586706f2543Smrg    The entire file is parsed first to remove any section ordering
587706f2543Smrg    requirements.
588706f2543Smrg      </para>
589706f2543Smrg    </sect2>
590706f2543Smrg
591706f2543Smrg
592706f2543Smrg    <sect2>
593706f2543Smrg      <title>Initial processing of parsed information and command line options
594706f2543Smrg      </title>
595706f2543Smrg
596706f2543Smrg      <para>
597706f2543Smrg    This is done at the start of the first server generation only.
598706f2543Smrg      </para>
599706f2543Smrg
600706f2543Smrg      <para>
601706f2543Smrg    The initial processing is to determine paths like the
602706f2543Smrg    <emphasis>ModulePath</emphasis>, etc, and to determine which &k.serverlayout;,
603706f2543Smrg    &k.screen; and &k.device; sections are active.
604706f2543Smrg      </para>
605706f2543Smrg    </sect2>
606706f2543Smrg
607706f2543Smrg
608706f2543Smrg    <sect2>
609706f2543Smrg      <title>Enable port I/O access</title>
610706f2543Smrg
611706f2543Smrg      <para>
612706f2543Smrg    Port I/O access is controlled from the XFree86 common layer, and is
613706f2543Smrg    <quote>all or nothing</quote>.  It is enabled prior to calling driver probes, at
614706f2543Smrg    the start of subsequent server generations, and when VT switching
615706f2543Smrg    back to the Xserver.  It is disabled at the end of server generations,
616706f2543Smrg    and when VT switching away from the Xserver.
617706f2543Smrg      </para>
618706f2543Smrg
619706f2543Smrg      <para>
620706f2543Smrg    The implementation details of this may vary on different platforms.
621706f2543Smrg      </para>
622706f2543Smrg    </sect2>
623706f2543Smrg
624706f2543Smrg
625706f2543Smrg    <sect2>
626706f2543Smrg      <title>General bus probe</title>
627706f2543Smrg
628706f2543Smrg      <para>
629706f2543Smrg    This is done at the start of the first server generation only.
630706f2543Smrg      </para>
631706f2543Smrg
632706f2543Smrg      <para>
633706f2543Smrg    In the case of ix86 machines, this will be a general PCI probe.
634706f2543Smrg    The full information obtained here will be available to the drivers.
635706f2543Smrg    This information persists for the life of the Xserver.  In the PCI
636706f2543Smrg    case, the PCI information for all video cards found is available by
637706f2543Smrg    calling <function>xf86GetPciVideoInfo()</function>.
638706f2543Smrg      </para>
639706f2543Smrg
640706f2543Smrg      <blockquote><para>
641706f2543Smrg	  <programlisting>
642706f2543Smrg    pciVideoPtr *xf86GetPciVideoInfo(void);
643706f2543Smrg	  </programlisting>
644706f2543Smrg	  <blockquote><para>
645706f2543Smrg	returns a pointer to a list of pointers to
646706f2543Smrg	<structname>pciVideoRec</structname> entries, of which there is one for
647706f2543Smrg	each detected PCI video card.  The list is terminated with a
648706f2543Smrg	<constant>NULL</constant> pointer.  If no PCI video cards were
649706f2543Smrg	detected, the return value is <constant>NULL</constant>.
650706f2543Smrg
651706f2543Smrg	    </para></blockquote>
652706f2543Smrg	</para></blockquote>
653706f2543Smrg
654706f2543Smrg      <para>
655706f2543Smrg    After the bus probe, the resource broker is initialised.
656706f2543Smrg      </para>
657706f2543Smrg    </sect2>
658706f2543Smrg
659706f2543Smrg
660706f2543Smrg    <sect2>
661706f2543Smrg      <title>Load initial set of modules</title>
662706f2543Smrg
663706f2543Smrg      <para>
664706f2543Smrg    This is done at the start of the first server generation only.
665706f2543Smrg      </para>
666706f2543Smrg
667706f2543Smrg      <para>
668706f2543Smrg    The core server contains a list of mandatory modules.  These are loaded
669706f2543Smrg    first.  Currently the only module on this list is the bitmap font module.
670706f2543Smrg      </para>
671706f2543Smrg
672706f2543Smrg      <para>
673706f2543Smrg    The next set of modules loaded are those specified explicitly in the
674706f2543Smrg    &k.module; section of the config file.
675706f2543Smrg      </para>
676706f2543Smrg
677706f2543Smrg      <para>
678706f2543Smrg    The final set of initial modules are the driver modules referenced
679706f2543Smrg    by the active &k.device; and &k.inputdevice; sections in the config
680706f2543Smrg    file.  Each of these modules is loaded exactly once.
681706f2543Smrg      </para>
682706f2543Smrg    </sect2>
683706f2543Smrg
684706f2543Smrg
685706f2543Smrg    <sect2>
686706f2543Smrg      <title>Register Video and Input Drivers</title>
687706f2543Smrg
688706f2543Smrg      <para>
689706f2543Smrg    This is done at the start of the first server generation only.
690706f2543Smrg      </para>
691706f2543Smrg
692706f2543Smrg      <para>
693706f2543Smrg    When a driver module is loaded, the loader calls its
694706f2543Smrg    <function>Setup</function> function.  For video drivers, this function
695706f2543Smrg    calls <function>xf86AddDriver()</function> to register the driver's
696706f2543Smrg    <structname>DriverRec</structname>, which contains a small set of essential
697706f2543Smrg    details and driver entry points required during the early phase of
698706f2543Smrg    <function>InitOutput()</function>.  <function>xf86AddDriver()</function>
699706f2543Smrg    adds it to the global <varname>xf86DriverList[]</varname> array.
700706f2543Smrg      </para>
701706f2543Smrg
702706f2543Smrg      <para>
703706f2543Smrg    The <structname>DriverRec</structname> contains the driver canonical name,
704706f2543Smrg    the <function>Identify()</function>,
705706f2543Smrg    <function>Probe()</function> and <function>AvailableOptions()</function>
706706f2543Smrg    function entry points as well as a pointer
707706f2543Smrg    to the driver's module (as returned from the loader when the driver
708706f2543Smrg    was loaded) and a reference count which keeps track of how many
709706f2543Smrg    screens are using the driver.  The entry driver entry points are
710706f2543Smrg    those required prior to the driver allocating and filling in its
711706f2543Smrg    <structname>ScrnInfoRec</structname>.
712706f2543Smrg      </para>
713706f2543Smrg
714706f2543Smrg      <para>
715706f2543Smrg    For a static server, the <varname>xf86DriverList[]</varname> array is
716706f2543Smrg    initialised at build time, and the loading of modules is not done.
717706f2543Smrg      </para>
718706f2543Smrg
719706f2543Smrg      <para>
720706f2543Smrg    A similar procedure is used for input drivers.  The input driver's
721706f2543Smrg    <function>Setup</function> function calls
722706f2543Smrg    <function>xf86AddInputDriver()</function> to register the driver's
723706f2543Smrg    <structname>InputDriverRec</structname>, which contains a small set of
724706f2543Smrg    essential details and driver entry points required during the early
725706f2543Smrg    phase of <function>InitInput()</function>.
726706f2543Smrg    <function>xf86AddInputDriver()</function> adds it to the global
727706f2543Smrg    <varname>xf86InputDriverList[]</varname> array.  For a static server,
728706f2543Smrg    the <varname>xf86InputDriverList[]</varname> array is initialised at
729706f2543Smrg    build time.
730706f2543Smrg      </para>
731706f2543Smrg
732706f2543Smrg      <para>
733706f2543Smrg    Both the <varname>xf86DriverList[]</varname> and
734706f2543Smrg    <varname>xf86InputDriverList[]</varname> arrays have been initialised
735706f2543Smrg    by the end of this stage.
736706f2543Smrg      </para>
737706f2543Smrg
738706f2543Smrg      <para>
739706f2543Smrg    Once all the drivers are registered, their
740706f2543Smrg    <function>ChipIdentify()</function> functions are called.
741706f2543Smrg      </para>
742706f2543Smrg
743706f2543Smrg      <blockquote><para>
744706f2543Smrg	  <programlisting>
745706f2543Smrg    void ChipIdentify(int flags);
746706f2543Smrg	  </programlisting>
747706f2543Smrg	  <blockquote><para>
748706f2543Smrg      This is expected to print a message indicating the driver name,
749706f2543Smrg      a short summary of what it supports, and a list of the chipset
750706f2543Smrg      names that it supports.  It may use the xf86PrintChipsets() helper
751706f2543Smrg      to do this.
752706f2543Smrg	    </para></blockquote>
753706f2543Smrg	</para></blockquote>
754706f2543Smrg
755706f2543Smrg      <blockquote><para>
756706f2543Smrg	  <programlisting>
757706f2543Smrg    void xf86PrintChipsets(const char *drvname, const char *drvmsg,
758706f2543Smrg                           SymTabPtr chips);
759706f2543Smrg	  </programlisting>
760706f2543Smrg	  <blockquote><para>
761706f2543Smrg      This function provides an easy way for a driver's ChipIdentify
762706f2543Smrg      function to format the identification message.
763706f2543Smrg	    </para></blockquote>
764706f2543Smrg	</para></blockquote>
765706f2543Smrg    </sect2>
766706f2543Smrg
767706f2543Smrg    <sect2>
768706f2543Smrg      <title>Initialise Access Control</title>
769706f2543Smrg
770706f2543Smrg      <para>
771706f2543Smrg    This is done at the start of the first server generation only.
772706f2543Smrg      </para>
773706f2543Smrg
774706f2543Smrg      <para>
775706f2543Smrg    The Resource Access Control (RAC) subsystem is initialised before
776706f2543Smrg    calling any driver functions that may access hardware.  All generic
777706f2543Smrg    bus information is probed and saved (for restoration later).  All
778706f2543Smrg    (shared resource) video devices are disabled at the generic bus
779706f2543Smrg    level, and a probe is done to find the <quote>primary</quote> video device.  These
780706f2543Smrg    devices remain disabled for the next step.
781706f2543Smrg      </para>
782706f2543Smrg    </sect2>
783706f2543Smrg
784706f2543Smrg
785706f2543Smrg    <sect2 id="probe">
786706f2543Smrg      <title>Video Driver Probe</title>
787706f2543Smrg
788706f2543Smrg      <para>
789706f2543Smrg    This is done at the start of the first server generation only.  The
790706f2543Smrg    <function>ChipProbe()</function> function of each registered video driver
791706f2543Smrg    is called.
792706f2543Smrg      </para>
793706f2543Smrg
794706f2543Smrg      <blockquote><para>
795706f2543Smrg	  <programlisting>
796706f2543Smrg    Bool ChipProbe(DriverPtr drv, int flags);
797706f2543Smrg	  </programlisting>
798706f2543Smrg	  <blockquote><para>
799706f2543Smrg      The purpose of this is to identify all instances of hardware
800706f2543Smrg      supported by the driver.  The flags value is currently either 0,
801706f2543Smrg      <constant>PROBE_DEFAULT</constant> or <constant>PROBE_DETECT</constant>.
802706f2543Smrg      <constant>PROBE_DETECT</constant> is used if "-configure" or "-probe"
803706f2543Smrg      command line arguments are given and indicates to the
804706f2543Smrg      <function>Probe()</function> function that it should not configure the
805706f2543Smrg      bus entities and that no xorg.conf information is available.
806706f2543Smrg	    </para>
807706f2543Smrg
808706f2543Smrg	  <para>
809706f2543Smrg      The probe must find the active device sections that match the
810706f2543Smrg      driver by calling <function>xf86MatchDevice()</function>.  The number
811706f2543Smrg      of matches found limits the maximum number of instances for this
812706f2543Smrg      driver.  If no matches are found, the function should return
813706f2543Smrg      <constant>FALSE</constant> immediately.
814706f2543Smrg	  </para>
815706f2543Smrg
816706f2543Smrg	<para>
817706f2543Smrg      Devices that cannot be identified by using device-independent
818706f2543Smrg      methods should be probed at this stage (keeping in mind that access
819706f2543Smrg      to all resources that can be disabled in a device-independent way
820706f2543Smrg      are disabled during this phase).  The probe must be a minimal
821706f2543Smrg      probe.  It should just determine if there is a card present that
822706f2543Smrg      the driver can drive.  It should use the least intrusive probe
823706f2543Smrg      methods possible.  It must not do anything that is not essential,
824706f2543Smrg      like probing for other details such as the amount of memory
825706f2543Smrg      installed, etc.  It is recommended that the
826706f2543Smrg      <function>xf86MatchPciInstances()</function> helper function be used
827706f2543Smrg      for identifying matching PCI devices, and similarly the
828706f2543Smrg      <function>xf86MatchIsaInstances()</function> for ISA (non-PCI) devices
829706f2543Smrg      (see the <link linkend="rac">RAC</link> section).  These helpers also
830706f2543Smrg      checks and claims the appropriate entity.  When not using the
831706f2543Smrg      helper, that should be done with <function>xf86CheckPciSlot()</function>
832706f2543Smrg      and <function>xf86ClaimPciSlot()</function> for PCI devices and
833706f2543Smrg      <function>xf86ClaimIsaSlot()</function> for ISA devices (see the
834706f2543Smrg      <link linkend="rac">RAC</link> section).
835706f2543Smrg	</para>
836706f2543Smrg
837706f2543Smrg	<para>
838706f2543Smrg      The probe must register all non-relocatable resources at this
839706f2543Smrg      stage.  If a resource conflict is found between exclusive resources
840706f2543Smrg      the driver will fail immediately.  This is usually best done with
841706f2543Smrg      the <function>xf86ConfigPciEntity()</function> helper function
842706f2543Smrg      for PCI and <function>xf86ConfigIsaEntity()</function> for ISA
843706f2543Smrg      (see the <link linkend="rac">RAC</link> section).  It is possible to
844706f2543Smrg      register some entity specific functions with those helpers.  When
845706f2543Smrg      not using the helpers, the <function>xf86AddEntityToScreen()</function>
846706f2543Smrg      <function>xf86ClaimFixedResources()</function> and
847706f2543Smrg      <function>xf86SetEntityFuncs()</function> should be used instead (see
848706f2543Smrg      the <link linkend="rac">RAC</link> section).
849706f2543Smrg	</para>
850706f2543Smrg
851706f2543Smrg	<para>
852706f2543Smrg      If a chipset is specified in an active device section which the
853706f2543Smrg      driver considers relevant (ie it has no driver specified, or the
854706f2543Smrg      driver specified matches the driver doing the probe), the Probe
855706f2543Smrg      must return <constant>FALSE</constant> if the chipset doesn't match
856706f2543Smrg      one supported by the driver.
857706f2543Smrg	</para>
858706f2543Smrg
859706f2543Smrg	<para>
860706f2543Smrg      If there are no active device sections that the driver considers
861706f2543Smrg      relevant, it must return <constant>FALSE</constant>.
862706f2543Smrg	</para>
863706f2543Smrg
864706f2543Smrg	<para>
865706f2543Smrg      Allocate a <structname>ScrnInfoRec</structname> for each active instance of the
866706f2543Smrg      hardware found, and fill in the basic information, including the
867706f2543Smrg      other driver entry points.   This is best done with the
868706f2543Smrg      <function>xf86ConfigIsaEntity()</function> helper function for ISA
869706f2543Smrg      instances or <function>xf86ConfigPciEntity()</function> for PCI instances.
870706f2543Smrg      These functions allocate a <structname>ScrnInfoRec</structname> for active
871706f2543Smrg      entities. Optionally <function>xf86AllocateScreen()</function>
872706f2543Smrg      function may also be used to allocate the <structname>ScrnInfoRec</structname>.
873706f2543Smrg      Any of these functions take care of initialising fields to defined
874706f2543Smrg      <quote>unused</quote> values.
875706f2543Smrg	</para>
876706f2543Smrg
877706f2543Smrg	<para>
878706f2543Smrg      Claim the entities for each instance of the hardware found.  This
879706f2543Smrg      prevents other drivers from claiming the same hardware.
880706f2543Smrg	</para>
881706f2543Smrg
882706f2543Smrg	<para>
883706f2543Smrg      Must leave hardware in the same state it found it in, and must not
884706f2543Smrg      do any hardware initialisation.
885706f2543Smrg	</para>
886706f2543Smrg
887706f2543Smrg	<para>
888706f2543Smrg      All detection can be overridden via the config file, and that
889706f2543Smrg      parsed information is available to the driver at this stage.
890706f2543Smrg	</para>
891706f2543Smrg
892706f2543Smrg	<para>
893706f2543Smrg      Returns <constant>TRUE</constant> if one or more instances are found,
894706f2543Smrg      and <constant>FALSE</constant> otherwise.
895706f2543Smrg	</para>
896706f2543Smrg
897706f2543Smrg	  </blockquote></para></blockquote>
898706f2543Smrg
899706f2543Smrg      <blockquote><para>
900706f2543Smrg	  <programlisting>
901706f2543Smrg    int xf86MatchDevice(const char *drivername,
902706f2543Smrg                        GDevPtr **driversectlist)
903706f2543Smrg	  </programlisting>
904706f2543Smrg	  <blockquote><para>
905706f2543Smrg      This function takes the name of the driver and returns via
906706f2543Smrg      <parameter>driversectlist</parameter> a list of device sections that
907706f2543Smrg      match the driver name.  The function return value is the number
908706f2543Smrg      of matches found.  If a fatal error is encountered the return
909706f2543Smrg      value is <literal>-1</literal>.
910706f2543Smrg	    </para>
911706f2543Smrg
912706f2543Smrg	    <para>
913706f2543Smrg      The caller should use <function>xfree()</function> to free
914706f2543Smrg      <parameter>*driversectlist</parameter> when it is no longer needed.
915706f2543Smrg	    </para>
916706f2543Smrg
917706f2543Smrg	  </blockquote></para></blockquote>
918706f2543Smrg
919706f2543Smrg      <blockquote><para>
920706f2543Smrg	  <programlisting>
921706f2543Smrg    ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags)
922706f2543Smrg	  </programlisting>
923706f2543Smrg	  <blockquote><para>
924706f2543Smrg      This function allocates a new <structname>ScrnInfoRec</structname> in the
925706f2543Smrg      <varname>xf86Screens[]</varname> array.  This function is normally
926706f2543Smrg      called by the video driver <function>ChipProbe()</function> functions.
927706f2543Smrg      The return value is a pointer to the newly allocated
928706f2543Smrg      <structname>ScrnInfoRec</structname>.  The <structfield>scrnIndex</structfield>,
929706f2543Smrg      <structfield>origIndex</structfield>, <structfield>module</structfield> and
930706f2543Smrg      <structfield>drv</structfield> fields are initialised.  The reference count
931706f2543Smrg      in <parameter>drv</parameter> is incremented.  The storage for any
932706f2543Smrg      currently allocated <quote>privates</quote> pointers is also allocated and
933706f2543Smrg      the <structfield>privates</structfield> field initialised (the privates data
934706f2543Smrg      is of course not allocated or initialised).  This function never
935706f2543Smrg      returns on failure.  If the allocation fails, the server exits
936706f2543Smrg      with a fatal error.  The flags value is not currently used, and
937706f2543Smrg      should be set to zero.
938706f2543Smrg	    </para></blockquote>
939706f2543Smrg	</para></blockquote>
940706f2543Smrg
941706f2543Smrg      <para>
942706f2543Smrg    At the completion of this, a list of <structname>ScrnInfoRecs</structname>
943706f2543Smrg    have been allocated in the <varname>xf86Screens[]</varname> array, and
944706f2543Smrg    the associated entities and fixed resources have been claimed.  The
945706f2543Smrg    following <structname>ScrnInfoRec</structname> fields must be initialised at
946706f2543Smrg    this point:
947706f2543Smrg
948706f2543Smrg	<literallayout>
949706f2543Smrg          driverVersion
950706f2543Smrg          driverName
951706f2543Smrg          scrnIndex(*)
952706f2543Smrg          origIndex(*)
953706f2543Smrg          drv(*)
954706f2543Smrg          module(*)
955706f2543Smrg          name
956706f2543Smrg          Probe
957706f2543Smrg          PreInit
958706f2543Smrg          ScreenInit
959706f2543Smrg          EnterVT
960706f2543Smrg          LeaveVT
961706f2543Smrg          numEntities
962706f2543Smrg          entityList
963706f2543Smrg          access
964706f2543Smrg	</literallayout>
965706f2543Smrg
966706f2543Smrg    <literal>(*)</literal> These are initialised when the <structname>ScrnInfoRec</structname>
967706f2543Smrg    is allocated, and not explicitly by the driver.
968706f2543Smrg      </para>
969706f2543Smrg
970706f2543Smrg      <para>
971706f2543Smrg    The following <structname>ScrnInfoRec</structname> fields must be initialised
972706f2543Smrg    if the driver is going to use them:
973706f2543Smrg
974706f2543Smrg	<literallayout>
975706f2543Smrg          SwitchMode
976706f2543Smrg          AdjustFrame
977706f2543Smrg          FreeScreen
978706f2543Smrg          ValidMode
979706f2543Smrg	</literallayout>
980706f2543Smrg      </para>
981706f2543Smrg    </sect2>
982706f2543Smrg
983706f2543Smrg    <sect2>
984706f2543Smrg      <title>Matching Screens</title>
985706f2543Smrg
986706f2543Smrg      <para>
987706f2543Smrg    This is done at the start of the first server generation only.
988706f2543Smrg      </para>
989706f2543Smrg
990706f2543Smrg      <para>
991706f2543Smrg    After the Probe phase is finished, there will be some number of
992706f2543Smrg    <structname>ScrnInfoRec</structname>s.  These are then matched with the active
993706f2543Smrg    &k.screen; sections in the xorg.conf, and those not having an active
994706f2543Smrg    &k.screen; section are deleted.  If the number of remaining screens
995706f2543Smrg    is 0, <function>InitOutput()</function> sets
996706f2543Smrg    <structfield>screenInfo.numScreens</structfield> to <constant>0</constant> and
997706f2543Smrg    returns.
998706f2543Smrg      </para>
999706f2543Smrg
1000706f2543Smrg      <para>
1001706f2543Smrg    At this point the following fields of the <structname>ScrnInfoRec</structname>s
1002706f2543Smrg    must be initialised:
1003706f2543Smrg
1004706f2543Smrg	<literallayout>
1005706f2543Smrg          confScreen
1006706f2543Smrg	</literallayout>
1007706f2543Smrg      </para>
1008706f2543Smrg
1009706f2543Smrg    </sect2>
1010706f2543Smrg
1011706f2543Smrg    <sect2>
1012706f2543Smrg      <title>Allocate non-conflicting resources</title>
1013706f2543Smrg
1014706f2543Smrg      <para>
1015706f2543Smrg    This is done at the start of the first server generation only.
1016706f2543Smrg      </para>
1017706f2543Smrg
1018706f2543Smrg      <para>
1019706f2543Smrg    Before calling the drivers again, the resource information collected
1020706f2543Smrg    from the Probe phase is processed.  This includes checking the extent
1021706f2543Smrg    of PCI resources for the probed devices, and resolving any conflicts
1022706f2543Smrg    in the relocatable PCI resources.  It also reports conflicts, checks
1023706f2543Smrg    bus routing issues, and anything else that is needed to enable the
1024706f2543Smrg    entities for the next phase.
1025706f2543Smrg      </para>
1026706f2543Smrg
1027706f2543Smrg      <para>
1028706f2543Smrg    If any drivers registered an <function>EntityInit()</function> function
1029706f2543Smrg    during the Probe phase, then they are called here.
1030706f2543Smrg      </para>
1031706f2543Smrg
1032706f2543Smrg    </sect2>
1033706f2543Smrg
1034706f2543Smrg    <sect2>
1035706f2543Smrg      <title>Sort the Screens and pre-check Monitor Information</title>
1036706f2543Smrg
1037706f2543Smrg      <para>
1038706f2543Smrg    This is done at the start of the first server generation only.
1039706f2543Smrg      </para>
1040706f2543Smrg
1041706f2543Smrg      <para>
1042706f2543Smrg    The list of screens is sorted to match the ordering requested in the
1043706f2543Smrg    config file.
1044706f2543Smrg      </para>
1045706f2543Smrg
1046706f2543Smrg      <para>
1047706f2543Smrg    The list of modes for each active monitor is checked against the
1048706f2543Smrg    monitor's parameters.  Invalid modes are pruned.
1049706f2543Smrg      </para>
1050706f2543Smrg
1051706f2543Smrg    </sect2>
1052706f2543Smrg
1053706f2543Smrg    <sect2>
1054706f2543Smrg      <title>PreInit</title>
1055706f2543Smrg
1056706f2543Smrg      <para>
1057706f2543Smrg    This is done at the start of the first server generation only.
1058706f2543Smrg      </para>
1059706f2543Smrg
1060706f2543Smrg      <para>
1061706f2543Smrg    For each <structname>ScrnInfoRec</structname>, enable access to the screens entities and call
1062706f2543Smrg    the <function>ChipPreInit()</function> function.
1063706f2543Smrg      </para>
1064706f2543Smrg
1065706f2543Smrg      <blockquote><para>
1066706f2543Smrg	  <programlisting>
1067706f2543Smrg    Bool ChipPreInit(ScrnInfoRec screen, int flags);
1068706f2543Smrg	  </programlisting>
1069706f2543Smrg	  <blockquote><para>
1070706f2543Smrg      The purpose of this function is to find out all the information
1071706f2543Smrg      required to determine if the configuration is usable, and to
1072706f2543Smrg      initialise those parts of the <structname>ScrnInfoRec</structname> that
1073706f2543Smrg      can be set once at the beginning of the first server generation.
1074706f2543Smrg	    </para>
1075706f2543Smrg
1076706f2543Smrg	    <para>
1077706f2543Smrg      The number of entities registered for the screen should be checked
1078706f2543Smrg      against the expected number (most drivers expect only one).  The
1079706f2543Smrg      entity information for each of them should be retrieved (with
1080706f2543Smrg      <function>xf86GetEntityInfo()</function>) and checked for the correct
1081706f2543Smrg      bus type and that none of the sharable resources registered during
1082706f2543Smrg      the Probe phase was rejected.
1083706f2543Smrg	    </para>
1084706f2543Smrg
1085706f2543Smrg	    <para>
1086706f2543Smrg      Access to resources for the entities that can be controlled in a
1087706f2543Smrg      device-independent way are enabled before this function is called.
1088706f2543Smrg      If the driver needs to access any resources that it has disabled
1089706f2543Smrg      in an <function>EntityInit()</function> function that it registered,
1090706f2543Smrg      then it may enable them here providing that it disables them before
1091706f2543Smrg      this function returns.
1092706f2543Smrg	    </para>
1093706f2543Smrg
1094706f2543Smrg	    <para>
1095706f2543Smrg      This includes probing for video memory, clocks, ramdac, and all
1096706f2543Smrg      other HW info that is needed.  It includes determining the
1097706f2543Smrg      depth/bpp/visual and related info.  It includes validating and
1098706f2543Smrg      determining the set of video modes that will be used (and anything
1099706f2543Smrg      that is required to determine that).
1100706f2543Smrg	    </para>
1101706f2543Smrg
1102706f2543Smrg	    <para>
1103706f2543Smrg      This information should be determined in the least intrusive way
1104706f2543Smrg      possible.  The state of the HW must remain unchanged by this
1105706f2543Smrg      function.  Although video memory (including MMIO) may be mapped
1106706f2543Smrg      within this function, it must be unmapped before returning.  Driver
1107706f2543Smrg      specific information should be stored in a structure hooked into
1108706f2543Smrg      the <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield>
1109706f2543Smrg      field.  Any other modules which require persistent data (ie data
1110706f2543Smrg      that persists across server generations) should be initialised in
1111706f2543Smrg      this function, and they should allocate a <quote>privates</quote> index to
1112706f2543Smrg      hook their data into by calling
1113706f2543Smrg      <function>xf86AllocateScrnInfoPrivateIndex()</function>.  The <quote>privates</quote>
1114706f2543Smrg      data is persistent.
1115706f2543Smrg	    </para>
1116706f2543Smrg
1117706f2543Smrg	    <para>
1118706f2543Smrg      Helper functions for some of these things are provided at the
1119706f2543Smrg      XFree86 common level, and the driver can choose to make use of
1120706f2543Smrg      them.
1121706f2543Smrg	    </para>
1122706f2543Smrg
1123706f2543Smrg	    <para>
1124706f2543Smrg      All additional resources that the screen needs must be registered
1125706f2543Smrg      here.  This should be done with
1126706f2543Smrg      <function>xf86RegisterResources()</function>.  If some of the fixed
1127706f2543Smrg      resources registered in the Probe phase are not needed or not
1128706f2543Smrg      decoded by the hardware when in the OPERATING server state, their
1129706f2543Smrg      status should be updated with
1130706f2543Smrg      <function>xf86SetOperatingState()</function>.
1131706f2543Smrg	    </para>
1132706f2543Smrg
1133706f2543Smrg	    <para>
1134706f2543Smrg      Modules may be loaded at any point in this function, and all
1135706f2543Smrg      modules that the driver will need must be loaded before the end
1136706f2543Smrg      of this function.  Either the  <function>xf86LoadSubModule()</function>
1137706f2543Smrg      or the <function>xf86LoadDrvSubModule()</function> function should be
1138706f2543Smrg      used to load modules depending on whether a
1139706f2543Smrg      <structname>ScrnInfoRec</structname> has been set up. A driver may unload
1140706f2543Smrg      a module within this function if it was only needed temporarily,
1141706f2543Smrg      and the <function>xf86UnloadSubModule()</function> function should be used
1142706f2543Smrg      to do that.  Otherwise there is no need to explicitly unload modules
1143706f2543Smrg      because the loader takes care of module dependencies and will
1144706f2543Smrg      unload submodules automatically if/when the driver module is
1145706f2543Smrg      unloaded.
1146706f2543Smrg	    </para>
1147706f2543Smrg
1148706f2543Smrg	    <para>
1149706f2543Smrg      The bulk of the <structname>ScrnInfoRec</structname> fields should be filled
1150706f2543Smrg      out in this function.
1151706f2543Smrg	    </para>
1152706f2543Smrg
1153706f2543Smrg	    <para>
1154706f2543Smrg      <function>ChipPreInit()</function> returns <constant>FALSE</constant> when
1155706f2543Smrg      the configuration is unusable in some way (unsupported depth, no
1156706f2543Smrg      valid modes, not enough video memory, etc), and <constant>TRUE</constant>
1157706f2543Smrg      if it is usable.
1158706f2543Smrg	    </para>
1159706f2543Smrg
1160706f2543Smrg	    <para>
1161706f2543Smrg      It is expected that if the <function>ChipPreInit()</function> function
1162706f2543Smrg      returns <constant>TRUE</constant>, then the only reasons that subsequent
1163706f2543Smrg      stages in the driver might fail are lack or resources (like xalloc
1164706f2543Smrg      failures).  All other possible reasons for failure should be
1165706f2543Smrg      determined by the <function>ChipPreInit()</function> function.
1166706f2543Smrg	    </para></blockquote>
1167706f2543Smrg	</para></blockquote>
1168706f2543Smrg
1169706f2543Smrg      <para>
1170706f2543Smrg    The <structname>ScrnInfoRec</structname>s for screens where the <function>ChipPreInit()</function> fails are removed.
1171706f2543Smrg    If none remain, <function>InitOutput()</function> sets <structfield>screenInfo.numScreens</structfield> to <constant>0</constant> and returns.
1172706f2543Smrg      </para>
1173706f2543Smrg
1174706f2543Smrg      <para>
1175706f2543Smrg    At this point, further fields of the <structname>ScrnInfoRec</structname>s would normally be
1176706f2543Smrg    filled in.  Most are not strictly mandatory, but many are required
1177706f2543Smrg    by other layers and/or helper functions that the driver may choose
1178706f2543Smrg    to use.  The documentation for those layers and helper functions
1179706f2543Smrg    indicates which they require.
1180706f2543Smrg      </para>
1181706f2543Smrg
1182706f2543Smrg      <para>
1183706f2543Smrg    The following fields of the <structname>ScrnInfoRec</structname>s should be filled in if the
1184706f2543Smrg    driver is going to use them:
1185706f2543Smrg
1186706f2543Smrg	<literallayout>
1187706f2543Smrg          monitor
1188706f2543Smrg          display
1189706f2543Smrg          depth
1190706f2543Smrg          pixmapBPP
1191706f2543Smrg          bitsPerPixel
1192706f2543Smrg          weight                (&gt;8bpp only)
1193706f2543Smrg          mask                  (&gt;8bpp only)
1194706f2543Smrg          offset                (&gt;8bpp only)
1195706f2543Smrg          rgbBits               (8bpp only)
1196706f2543Smrg          gamma
1197706f2543Smrg          defaultVisual
1198706f2543Smrg          maxHValue
1199706f2543Smrg          maxVValue
1200706f2543Smrg          virtualX
1201706f2543Smrg          virtualY
1202706f2543Smrg          displayWidth
1203706f2543Smrg          frameX0
1204706f2543Smrg          frameY0
1205706f2543Smrg          frameX1
1206706f2543Smrg          frameY1
1207706f2543Smrg          zoomLocked
1208706f2543Smrg          modePool
1209706f2543Smrg          modes
1210706f2543Smrg          currentMode
1211706f2543Smrg          progClock             (TRUE if clock is programmable)
1212706f2543Smrg          chipset
1213706f2543Smrg          ramdac
1214706f2543Smrg          clockchip
1215706f2543Smrg          numClocks             (if not programmable)
1216706f2543Smrg          clock[]               (if not programmable)
1217706f2543Smrg          videoRam
1218706f2543Smrg          biosBase
1219706f2543Smrg          memBase
1220706f2543Smrg          memClk
1221706f2543Smrg          driverPrivate
1222706f2543Smrg          chipID
1223706f2543Smrg          chipRev
1224706f2543Smrg	</literallayout>
1225706f2543Smrg      </para>
1226706f2543Smrg
1227706f2543Smrg      <blockquote><para>
1228706f2543Smrg	  <programlisting>
1229706f2543Smrg    pointer xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name);
1230706f2543Smrg      and
1231706f2543Smrg    pointer xf86LoadDrvSubModule(DriverPtr drv, const char *name);
1232706f2543Smrg	  </programlisting>
1233706f2543Smrg	  <blockquote><para>
1234706f2543Smrg      Load a module that a driver depends on.  This function loads the
1235706f2543Smrg      module <parameter>name</parameter> as a sub module of the driver.  The
1236706f2543Smrg      return value is a handle identifying the new module.  If the load
1237706f2543Smrg      fails, the return value will be <constant>NULL</constant>.  If a driver
1238706f2543Smrg      needs to explicitly unload a module it has loaded in this way,
1239706f2543Smrg      the return value must be saved and passed to
1240706f2543Smrg      <function>xf86UnloadSubModule()</function> when unloading.
1241706f2543Smrg
1242706f2543Smrg	    </para></blockquote>
1243706f2543Smrg	</para></blockquote>
1244706f2543Smrg
1245706f2543Smrg      <blockquote><para>
1246706f2543Smrg	  <programlisting>
1247706f2543Smrg    void xf86UnloadSubModule(pointer module);
1248706f2543Smrg	  </programlisting>
1249706f2543Smrg	  <blockquote><para>
1250706f2543Smrg      Unloads the module referenced by <parameter>module</parameter>.
1251706f2543Smrg      <parameter>module</parameter> should be a pointer returned previously
1252706f2543Smrg      by <function>xf86LoadSubModule()</function> or
1253706f2543Smrg      <function>xf86LoadDrvSubModule()</function> .
1254706f2543Smrg
1255706f2543Smrg	    </para></blockquote>
1256706f2543Smrg	</para></blockquote>
1257706f2543Smrg    </sect2>
1258706f2543Smrg
1259706f2543Smrg    <sect2>
1260706f2543Smrg      <title>Cleaning up Unused Drivers</title>
1261706f2543Smrg
1262706f2543Smrg      <para>
1263706f2543Smrg    At this point it is known which screens will be in use, and which
1264706f2543Smrg    drivers are being used.  Unreferenced drivers (and modules they
1265706f2543Smrg    may have loaded) are unloaded here.
1266706f2543Smrg      </para>
1267706f2543Smrg
1268706f2543Smrg    </sect2>
1269706f2543Smrg
1270706f2543Smrg    <sect2>
1271706f2543Smrg      <title>Consistency Checks</title>
1272706f2543Smrg
1273706f2543Smrg      <para>
1274706f2543Smrg    The parameters that must be global to the server, like pixmap formats,
1275706f2543Smrg    bitmap bit order, bitmap scanline unit and image byte order are
1276706f2543Smrg    compared for each of the screens.  If a mismatch is found, the server
1277706f2543Smrg    exits with an appropriate message.
1278706f2543Smrg      </para>
1279706f2543Smrg
1280706f2543Smrg    </sect2>
1281706f2543Smrg
1282706f2543Smrg    <sect2>
1283706f2543Smrg      <title>Check if Resource Control is Needed</title>
1284706f2543Smrg
1285706f2543Smrg      <para>
1286706f2543Smrg    Determine if resource access control is needed.  This is the case
1287706f2543Smrg    if more than one screen is used.  If necessary the RAC wrapper module
1288706f2543Smrg    is loaded.
1289706f2543Smrg      </para>
1290706f2543Smrg    </sect2>
1291706f2543Smrg
1292706f2543Smrg    <sect2>
1293706f2543Smrg      <title>AddScreen (ScreenInit)</title>
1294706f2543Smrg
1295706f2543Smrg      <para>
1296706f2543Smrg    At this point, the valid screens are known.
1297706f2543Smrg    <function>AddScreen()</function> is called for each of them, passing
1298706f2543Smrg    <function>ChipScreenInit()</function> as the argument.
1299706f2543Smrg    <function>AddScreen()</function> is a DIX function that allocates a new
1300706f2543Smrg    <structfield>screenInfo.screen[]</structfield> entry (aka
1301706f2543Smrg    <varname>pScreen</varname>), and does some basic initialisation of it.
1302706f2543Smrg    It then calls the <function>ChipScreenInit()</function> function, with
1303706f2543Smrg    <parameter>pScreen</parameter> as one of its arguments.  If
1304706f2543Smrg    <function>ChipScreenInit()</function> returns <constant>FALSE</constant>,
1305706f2543Smrg    <function>AddScreen()</function> returns <constant>-1</constant>.  Otherwise
1306706f2543Smrg    it returns the index of the screen.  <function>AddScreen()</function>
1307706f2543Smrg    should only fail because of programming errors or failure to allocate
1308706f2543Smrg    resources (like memory).  All configuration problems should be
1309706f2543Smrg    detected BEFORE this point.
1310706f2543Smrg      </para>
1311706f2543Smrg
1312706f2543Smrg      <blockquote><para>
1313706f2543Smrg	  <programlisting>
1314706f2543Smrg    Bool ChipScreenInit(int index, ScreenPtr pScreen,
1315706f2543Smrg                        int argc, char **argv);
1316706f2543Smrg	  </programlisting>
1317706f2543Smrg	  <blockquote><para>
1318706f2543Smrg      This is called at the start of each server generation.
1319706f2543Smrg	    </para>
1320706f2543Smrg
1321706f2543Smrg	    <para>
1322706f2543Smrg      Fill in all of <parameter>pScreen</parameter>, possibly doing some of
1323706f2543Smrg      this by calling ScreenInit functions from other layers like mi,
1324706f2543Smrg      framebuffers (cfb, etc), and extensions.
1325706f2543Smrg	    </para>
1326706f2543Smrg
1327706f2543Smrg	    <para>
1328706f2543Smrg      Decide which operations need to be placed under resource access
1329706f2543Smrg      control.  The classes of operations are the frame buffer operations
1330706f2543Smrg      (<constant>RAC_FB</constant>), the pointer operations
1331706f2543Smrg      (<constant>RAC_CURSOR</constant>), the viewport change operations
1332706f2543Smrg      (<constant>RAC_VIEWPORT</constant>) and the colormap operations
1333706f2543Smrg      (<constant>RAC_COLORMAP</constant>).  Any operation that requires
1334706f2543Smrg      resources which might be disabled during OPERATING state should
1335706f2543Smrg      be set to use RAC.  This can be specified separately for memory
1336706f2543Smrg      and IO resources (the <structfield>racMemFlags</structfield> and
1337706f2543Smrg      <structfield>racIoFlags</structfield> fields of the <structname>ScrnInfoRec</structname>
1338706f2543Smrg      respectively).
1339706f2543Smrg	    </para>
1340706f2543Smrg
1341706f2543Smrg	    <para>
1342706f2543Smrg      Map any video memory or other memory regions.
1343706f2543Smrg	    </para>
1344706f2543Smrg
1345706f2543Smrg	    <para>
1346706f2543Smrg      Save the video card state.  Enough state must be saved so that
1347706f2543Smrg      the original state can later be restored.
1348706f2543Smrg	    </para>
1349706f2543Smrg
1350706f2543Smrg	    <para>
1351706f2543Smrg      Initialise the initial video mode.  The <structname>ScrnInfoRec</structname>'s
1352706f2543Smrg      <structfield>vtSema</structfield> field should be set to <constant>TRUE</constant>
1353706f2543Smrg      just prior to changing the video hardware's state.
1354706f2543Smrg
1355706f2543Smrg	    </para></blockquote>
1356706f2543Smrg	</para></blockquote>
1357706f2543Smrg
1358706f2543Smrg
1359706f2543Smrg      <para>
1360706f2543Smrg    The <function>ChipScreenInit()</function> function (or functions from other
1361706f2543Smrg    layers that it calls) should allocate entries in the
1362706f2543Smrg    <structname>ScreenRec</structname>'s <structfield>devPrivates</structfield> area by
1363706f2543Smrg    calling <function>AllocateScreenPrivateIndex()</function> if it needs
1364706f2543Smrg    per-generation storage.  Since the <structname>ScreenRec</structname>'s
1365706f2543Smrg    <structfield>devPrivates</structfield> information is cleared for each server
1366706f2543Smrg    generation, this is the correct place to initialise it.
1367706f2543Smrg      </para>
1368706f2543Smrg
1369706f2543Smrg      <para>
1370706f2543Smrg    After <function>AddScreen()</function> has successfully returned, the
1371706f2543Smrg    following <structname>ScrnInfoRec</structname> fields are initialised:
1372706f2543Smrg
1373706f2543Smrg	<literallayout>
1374706f2543Smrg          pScreen
1375706f2543Smrg          racMemFlags
1376706f2543Smrg          racIoFlags
1377706f2543Smrg	</literallayout>
1378706f2543Smrg      </para>
1379706f2543Smrg
1380706f2543Smrg      <para>
1381706f2543Smrg    The <function>ChipScreenInit()</function> function should initialise the
1382706f2543Smrg    <structfield>CloseScreen</structfield> and <structfield>SaveScreen</structfield> fields
1383706f2543Smrg    of <parameter>pScreen</parameter>.  The old value of
1384706f2543Smrg    <structfield>pScreen-&gt;CloseScreen</structfield> should be saved as part of
1385706f2543Smrg    the driver's per-screen private data, allowing it to be called from
1386706f2543Smrg    <function>ChipCloseScreen()</function>.  This means that the existing
1387706f2543Smrg    <function>CloseScreen()</function> function is wrapped.
1388706f2543Smrg      </para>
1389706f2543Smrg    </sect2>
1390706f2543Smrg
1391706f2543Smrg    <sect2>
1392706f2543Smrg      <title>Finalising RAC Initialisation</title>
1393706f2543Smrg
1394706f2543Smrg      <para>
1395706f2543Smrg    After all the <function>ChipScreenInit()</function> functions have been
1396706f2543Smrg    called, each screen has registered its RAC requirements.  This
1397706f2543Smrg    information is used to determine which shared resources are requested
1398706f2543Smrg    by more than one driver and set the access functions accordingly.
1399706f2543Smrg    This is done following these rules:
1400706f2543Smrg
1401706f2543Smrg	<orderedlist>
1402706f2543Smrg	  <listitem><para>
1403706f2543Smrg	The sharable resources registered by each entity are compared.
1404706f2543Smrg	If a resource is registered by more than one entity the entity
1405706f2543Smrg	will be marked to indicate that it needs to share this resources
1406706f2543Smrg	type (IO or MEM).
1407706f2543Smrg	    </para></listitem>
1408706f2543Smrg
1409706f2543Smrg	  <listitem><para>
1410706f2543Smrg        A resource marked <quote>disabled</quote> during OPERATING state will be
1411706f2543Smrg        ignored entirely.
1412706f2543Smrg	    </para></listitem>
1413706f2543Smrg
1414706f2543Smrg	  <listitem><para>
1415706f2543Smrg	A resource marked <quote>unused</quote> will only conflict with an overlapping
1416706f2543Smrg	resource of an other entity if the second is actually in use
1417706f2543Smrg	during OPERATING state.
1418706f2543Smrg	    </para></listitem>
1419706f2543Smrg
1420706f2543Smrg	  <listitem><para>
1421706f2543Smrg	If an <quote>unused</quote> resource was found to conflict but the entity
1422706f2543Smrg	does not use any other resource of this type the entire resource
1423706f2543Smrg	type will be disabled for that entity.
1424706f2543Smrg	    </para></listitem>
1425706f2543Smrg	</orderedlist>
1426706f2543Smrg      </para>
1427706f2543Smrg
1428706f2543Smrg    </sect2>
1429706f2543Smrg
1430706f2543Smrg    <sect2>
1431706f2543Smrg      <title>Finishing InitOutput()</title>
1432706f2543Smrg
1433706f2543Smrg      <para>
1434706f2543Smrg    At this point <function>InitOutput()</function> is finished, and all the
1435706f2543Smrg    screens have been setup in their initial video mode.
1436706f2543Smrg      </para>
1437706f2543Smrg
1438706f2543Smrg    </sect2>
1439706f2543Smrg
1440706f2543Smrg    <sect2>
1441706f2543Smrg      <title>Mode Switching</title>
1442706f2543Smrg
1443706f2543Smrg      <para>
1444706f2543Smrg    When a SwitchMode event is received, <function>ChipSwitchMode()</function>
1445706f2543Smrg    is called (when it exists):
1446706f2543Smrg      </para>
1447706f2543Smrg
1448706f2543Smrg      <blockquote><para>
1449706f2543Smrg	  <programlisting>
1450706f2543Smrg    Bool ChipSwitchMode(int index, DisplayModePtr mode, int flags);
1451706f2543Smrg	  </programlisting>
1452706f2543Smrg	  <blockquote><para>
1453706f2543Smrg      Initialises the new mode for the screen identified by
1454706f2543Smrg      <parameter>index;</parameter>.  The viewport may need to be adjusted
1455706f2543Smrg      also.
1456706f2543Smrg
1457706f2543Smrg	    </para></blockquote>
1458706f2543Smrg	</para></blockquote>
1459706f2543Smrg
1460706f2543Smrg    </sect2>
1461706f2543Smrg
1462706f2543Smrg    <sect2>
1463706f2543Smrg      <title>Changing Viewport</title>
1464706f2543Smrg
1465706f2543Smrg      <para>
1466706f2543Smrg    When a Change Viewport event is received,
1467706f2543Smrg    <function>ChipAdjustFrame()</function> is called (when it exists):
1468706f2543Smrg      </para>
1469706f2543Smrg
1470706f2543Smrg      <blockquote><para>
1471706f2543Smrg	  <programlisting>
1472706f2543Smrg    void ChipAdjustFrame(int index, int x, int y, int flags);
1473706f2543Smrg	  </programlisting>
1474706f2543Smrg	  <blockquote><para>
1475706f2543Smrg      Changes the viewport for the screen identified by
1476706f2543Smrg      <parameter>index;</parameter>.
1477706f2543Smrg	    </para>
1478706f2543Smrg
1479706f2543Smrg	    <para>
1480706f2543Smrg      It should be noted that many chipsets impose restrictions on where the
1481706f2543Smrg      viewport may be placed in the virtual resolution, either for alignment
1482706f2543Smrg      reasons, or to prevent the start of the viewport from being positioned
1483706f2543Smrg      within a pixel (as can happen in a 24bpp mode).  After calculating the
1484706f2543Smrg      value the chipset's panning registers need to be set to for non-DGA
1485706f2543Smrg      modes, this function should recalculate the ScrnInfoRec's
1486706f2543Smrg      <structfield>frameX0</structfield>, <structfield>frameY0</structfield>, <structfield>frameX1</structfield>
1487706f2543Smrg      and <structfield>frameY1</structfield> fields to correspond to that value.  If
1488706f2543Smrg      this is not done, switching to another mode might cause the position
1489706f2543Smrg      of a hardware cursor to change.
1490706f2543Smrg
1491706f2543Smrg	    </para></blockquote>
1492706f2543Smrg	</para></blockquote>
1493706f2543Smrg
1494706f2543Smrg    </sect2>
1495706f2543Smrg
1496706f2543Smrg    <sect2>
1497706f2543Smrg      <title>VT Switching</title>
1498706f2543Smrg
1499706f2543Smrg      <para>
1500706f2543Smrg    When a VT switch event is received, <function>xf86VTSwitch()</function>
1501706f2543Smrg    is called.  <function>xf86VTSwitch()</function> does the following:
1502706f2543Smrg
1503706f2543Smrg	<variablelist>
1504706f2543Smrg	  <varlistentry><term>On ENTER:</term>
1505706f2543Smrg	    <listitem>
1506706f2543Smrg	      <itemizedlist>
1507706f2543Smrg		<listitem><para>
1508706f2543Smrg		    enable port I/O access
1509706f2543Smrg		  </para></listitem>
1510706f2543Smrg
1511706f2543Smrg		<listitem><para>
1512706f2543Smrg		    save and initialise the bus/resource state
1513706f2543Smrg		  </para></listitem>
1514706f2543Smrg
1515706f2543Smrg		<listitem><para>
1516706f2543Smrg		    enter the SETUP server state
1517706f2543Smrg		  </para></listitem>
1518706f2543Smrg
1519706f2543Smrg		<listitem><para>
1520706f2543Smrg		    calls <function>ChipEnterVT()</function> for each screen
1521706f2543Smrg		  </para></listitem>
1522706f2543Smrg
1523706f2543Smrg		<listitem><para>
1524706f2543Smrg		    enter the OPERATING server state
1525706f2543Smrg		  </para></listitem>
1526706f2543Smrg
1527706f2543Smrg		<listitem><para>
1528706f2543Smrg		    validate GCs
1529706f2543Smrg		  </para></listitem>
1530706f2543Smrg
1531706f2543Smrg		<listitem><para>
1532706f2543Smrg		    Restore fb from saved pixmap for each screen
1533706f2543Smrg		  </para></listitem>
1534706f2543Smrg
1535706f2543Smrg		<listitem><para>
1536706f2543Smrg		    Enable all input devices
1537706f2543Smrg		  </para></listitem>
1538706f2543Smrg	      </itemizedlist>
1539706f2543Smrg	    </listitem>
1540706f2543Smrg	  </varlistentry>
1541706f2543Smrg	  <varlistentry>
1542706f2543Smrg	    <term>On LEAVE:</term>
1543706f2543Smrg	    <listitem>
1544706f2543Smrg	      <itemizedlist>
1545706f2543Smrg		<listitem><para>
1546706f2543Smrg		    Save fb to pixmap for each screen
1547706f2543Smrg		  </para></listitem>
1548706f2543Smrg
1549706f2543Smrg		<listitem><para>
1550706f2543Smrg		    validate GCs
1551706f2543Smrg		  </para></listitem>
1552706f2543Smrg
1553706f2543Smrg		<listitem><para>
1554706f2543Smrg		    enter the SETUP server state
1555706f2543Smrg		  </para></listitem>
1556706f2543Smrg
1557706f2543Smrg		<listitem><para>
1558706f2543Smrg		    calls <function>ChipLeaveVT()</function> for each screen
1559706f2543Smrg		  </para></listitem>
1560706f2543Smrg
1561706f2543Smrg		<listitem><para>
1562706f2543Smrg		    disable all input devices
1563706f2543Smrg		  </para></listitem>
1564706f2543Smrg
1565706f2543Smrg		<listitem><para>
1566706f2543Smrg		    restore bus/resource state
1567706f2543Smrg		  </para></listitem>
1568706f2543Smrg
1569706f2543Smrg		<listitem><para>
1570706f2543Smrg		    disables port I/O access
1571706f2543Smrg		  </para></listitem>
1572706f2543Smrg	      </itemizedlist>
1573706f2543Smrg	    </listitem>
1574706f2543Smrg	  </varlistentry>
1575706f2543Smrg	</variablelist>
1576706f2543Smrg      </para>
1577706f2543Smrg
1578706f2543Smrg      <blockquote><para>
1579706f2543Smrg	  <programlisting>
1580706f2543Smrg    Bool ChipEnterVT(int index, int flags);
1581706f2543Smrg	  </programlisting>
1582706f2543Smrg	  <blockquote><para>
1583706f2543Smrg      This function should initialise the current video mode and
1584706f2543Smrg      initialise the viewport, turn on the HW cursor if appropriate,
1585706f2543Smrg      etc.
1586706f2543Smrg	    </para>
1587706f2543Smrg
1588706f2543Smrg	    <para>
1589706f2543Smrg      Should it re-save the video state before initialising the video
1590706f2543Smrg      mode?
1591706f2543Smrg	    </para>
1592706f2543Smrg
1593706f2543Smrg	  </blockquote></para></blockquote>
1594706f2543Smrg
1595706f2543Smrg      <blockquote><para>
1596706f2543Smrg	  <programlisting>
1597706f2543Smrg    void ChipLeaveVT(int index, int flags);
1598706f2543Smrg	  </programlisting>
1599706f2543Smrg	  <blockquote><para>
1600706f2543Smrg      This function should restore the saved video state.  If
1601706f2543Smrg      appropriate it should also turn off the HW cursor, and invalidate
1602706f2543Smrg      any pixmap/font caches.
1603706f2543Smrg	    </para>
1604706f2543Smrg
1605706f2543Smrg	  </blockquote></para></blockquote>
1606706f2543Smrg
1607706f2543Smrg      <para>
1608706f2543Smrg    Optionally, <function>ChipLeaveVT()</function> may also unmap memory
1609706f2543Smrg    regions.  If so, <function>ChipEnterVT()</function> will need to remap
1610706f2543Smrg    them.  Additionally, if an aperture used to access video memory is
1611706f2543Smrg    unmapped and remapped in this fashion, <function>ChipEnterVT()</function>
1612706f2543Smrg    will also need to notify the framebuffer layers of the aperture's new
1613706f2543Smrg    location in virtual memory.  This is done with a call to the screen's
1614706f2543Smrg    <function>ModifyPixmapHeader()</function> function, as follows
1615706f2543Smrg      </para>
1616706f2543Smrg
1617706f2543Smrg      <blockquote><para>
1618706f2543Smrg	  <programlisting>
1619706f2543Smrg    (*pScreen-&gt;ModifyPixmapHeader)(pScrn-&gt;ppix,
1620706f2543Smrg                                   -1, -1, -1, -1, -1, NewApertureAddress);
1621706f2543Smrg	  </programlisting>
1622706f2543Smrg	  <blockquote><para>
1623706f2543Smrg        where the <structfield>ppix</structfield> field in a ScrnInfoRec
1624706f2543Smrg        points to the pixmap used by the screen's
1625706f2543Smrg        <function>SaveRestoreImage()</function> function to hold the screen's
1626706f2543Smrg        contents while switched out.
1627706f2543Smrg	    </para>
1628706f2543Smrg
1629706f2543Smrg	  </blockquote></para></blockquote>
1630706f2543Smrg
1631706f2543Smrg      <para>
1632706f2543Smrg    Other layers may wrap the <function>ChipEnterVT()</function> and
1633706f2543Smrg    <function>ChipLeaveVT()</function> functions if they need to take some
1634706f2543Smrg    action when these events are received.
1635706f2543Smrg      </para>
1636706f2543Smrg    </sect2>
1637706f2543Smrg
1638706f2543Smrg    <sect2>
1639706f2543Smrg      <title>End of server generation</title>
1640706f2543Smrg
1641706f2543Smrg      <para>
1642706f2543Smrg    At the end of each server generation, the DIX layer calls
1643706f2543Smrg    <function>ChipCloseScreen()</function> for each screen:
1644706f2543Smrg      </para>
1645706f2543Smrg
1646706f2543Smrg      <blockquote><para>
1647706f2543Smrg	  <programlisting>
1648706f2543Smrg    Bool ChipCloseScreen(int index, ScreenPtr pScreen);
1649706f2543Smrg	  </programlisting>
1650706f2543Smrg	  <blockquote><para>
1651706f2543Smrg      This function should restore the saved video state and unmap the
1652706f2543Smrg      memory regions.
1653706f2543Smrg	    </para>
1654706f2543Smrg
1655706f2543Smrg	    <para>
1656706f2543Smrg      It should also free per-screen data structures allocated by the
1657706f2543Smrg      driver.  Note that the persistent data held in the
1658706f2543Smrg      <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> field
1659706f2543Smrg      should not be freed here because it is needed by subsequent server
1660706f2543Smrg      generations.
1661706f2543Smrg	    </para>
1662706f2543Smrg
1663706f2543Smrg	    <para>
1664706f2543Smrg      The <structname>ScrnInfoRec</structname>'s <structfield>vtSema</structfield> field
1665706f2543Smrg      should be set to <constant>FALSE</constant> once the video HW state
1666706f2543Smrg      has been restored.
1667706f2543Smrg	    </para>
1668706f2543Smrg
1669706f2543Smrg	    <para>
1670706f2543Smrg      Before freeing the per-screen driver data the saved
1671706f2543Smrg      <structfield>CloseScreen</structfield> value should be restored to
1672706f2543Smrg      <structfield>pScreen-&gt;CloseScreen</structfield>, and that function should
1673706f2543Smrg      be called after freeing the data.
1674706f2543Smrg
1675706f2543Smrg	    </para></blockquote>
1676706f2543Smrg	</para></blockquote>
1677706f2543Smrg    </sect2>
1678706f2543Smrg  </sect1>
1679706f2543Smrg
1680706f2543Smrg  <sect1>
1681706f2543Smrg    <title>Optional Driver Functions</title>
1682706f2543Smrg
1683706f2543Smrg    <para>
1684706f2543SmrgThe functions outlined here can be called from the XFree86 common layer,
1685706f2543Smrgbut their presence is optional.
1686706f2543Smrg    </para>
1687706f2543Smrg
1688706f2543Smrg    <sect2>
1689706f2543Smrg      <title>Mode Validation</title>
1690706f2543Smrg
1691706f2543Smrg      <para>
1692706f2543Smrg    When a mode validation helper supplied by the XFree86-common layer is
1693706f2543Smrg    being used, it can be useful to provide a function to check for hw
1694706f2543Smrg    specific mode constraints:
1695706f2543Smrg      </para>
1696706f2543Smrg
1697706f2543Smrg      <blockquote><para>
1698706f2543Smrg	  <programlisting>
1699706f2543Smrg    ModeStatus ChipValidMode(int index, DisplayModePtr mode,
1700706f2543Smrg                             Bool verbose, int flags);
1701706f2543Smrg	  </programlisting>
1702706f2543Smrg	  <blockquote><para>
1703706f2543Smrg      Check the passed mode for hw-specific constraints, and return the
1704706f2543Smrg      appropriate status value.
1705706f2543Smrg
1706706f2543Smrg	    </para></blockquote>
1707706f2543Smrg	</para></blockquote>
1708706f2543Smrg
1709706f2543Smrg      <para>
1710706f2543SmrgThis function may also modify the effective timings and clock of the passed
1711706f2543Smrgmode.  These have been stored in the mode's <structfield>Crtc*</structfield> and
1712706f2543Smrg<structfield>SynthClock</structfield> elements, and have already been adjusted for
1713706f2543Smrginterlacing, doublescanning, multiscanning and clock multipliers and dividers.
1714706f2543SmrgThe function should not modify any other mode field, unless it wants to modify
1715706f2543Smrgthe mode timings reported to the user by <function>xf86PrintModes()</function>.
1716706f2543Smrg      </para>
1717706f2543Smrg
1718706f2543Smrg      <para>
1719706f2543SmrgThe function is called once for every mode in the xorg.conf Monitor section
1720706f2543Smrgassigned to the screen, with <parameter>flags</parameter> set to
1721706f2543Smrg<constant>MODECHECK_INITIAL</constant>.  It is subsequently called for every mode
1722706f2543Smrgin the xorg.conf Display subsection assigned to the screen, with
1723706f2543Smrg<parameter>flags</parameter> set to <constant>MODECHECK_FINAL</constant>.  In the second
1724706f2543Smrgcase, the mode will have successfully passed all other tests.  In addition,
1725706f2543Smrgthe <structname>ScrnInfoRec</structname>'s <structfield>virtualX</structfield>,
1726706f2543Smrg<structfield>virtualY</structfield> and <structfield>displayWidth</structfield> fields will have been
1727706f2543Smrgset as if the mode to be validated were to be the last mode accepted.
1728706f2543Smrg      </para>
1729706f2543Smrg
1730706f2543Smrg      <para>
1731706f2543SmrgIn effect, calls with MODECHECK_INITIAL are intended for checks that do not
1732706f2543Smrgdepend on any mode other than the one being validated, while calls with
1733706f2543SmrgMODECHECK_FINAL are intended for checks that may involve more than one mode.
1734706f2543Smrg      </para>
1735706f2543Smrg    </sect2>
1736706f2543Smrg
1737706f2543Smrg    <sect2>
1738706f2543Smrg      <title>Free screen data</title>
1739706f2543Smrg
1740706f2543Smrg      <para>
1741706f2543Smrg    When a screen is deleted prior to the completion of the ScreenInit
1742706f2543Smrg    phase the <function>ChipFreeScreen()</function> function is called when defined.
1743706f2543Smrg      </para>
1744706f2543Smrg
1745706f2543Smrg      <blockquote><para>
1746706f2543Smrg	  <programlisting>
1747706f2543Smrg    void ChipFreeScreen(int scrnindex, int flags);
1748706f2543Smrg	  </programlisting>
1749706f2543Smrg	  <blockquote><para>
1750706f2543Smrg      Free any driver-allocated data that may have been allocated up to
1751706f2543Smrg      and including an unsuccessful <function>ChipScreenInit()</function>
1752706f2543Smrg      call.  This would predominantly be data allocated by
1753706f2543Smrg      <function>ChipPreInit()</function> that persists across server
1754706f2543Smrg      generations.  It would include the <structfield>driverPrivate</structfield>,
1755706f2543Smrg      and any <quote>privates</quote> entries that modules may have allocated.
1756706f2543Smrg
1757706f2543Smrg	    </para></blockquote>
1758706f2543Smrg	</para></blockquote>
1759706f2543Smrg
1760706f2543Smrg    </sect2>
1761706f2543Smrg</sect1>
1762706f2543Smrg
1763706f2543Smrg  <sect1>
1764706f2543Smrg    <title>Recommended driver functions</title>
1765706f2543Smrg
1766706f2543Smrg    <para>
1767706f2543SmrgThe functions outlined here are for internal use by the driver only.
1768706f2543SmrgThey are entirely optional, and are never accessed directly from higher
1769706f2543Smrglayers.  The sample function declarations shown here are just examples.
1770706f2543SmrgThe interface (if any) used is up to the driver.
1771706f2543Smrg    </para>
1772706f2543Smrg
1773706f2543Smrg    <sect2>
1774706f2543Smrg      <title>Save</title>
1775706f2543Smrg
1776706f2543Smrg      <para>
1777706f2543Smrg    Save the video state.  This could be called from <function>ChipScreenInit()</function> and
1778706f2543Smrg    (possibly) <function>ChipEnterVT()</function>.
1779706f2543Smrg      </para>
1780706f2543Smrg
1781706f2543Smrg      <blockquote><para>
1782706f2543Smrg	  <programlisting>
1783706f2543Smrg    void ChipSave(ScrnInfoPtr pScrn);
1784706f2543Smrg	  </programlisting>
1785706f2543Smrg	  <blockquote><para>
1786706f2543Smrg      Saves the current state.  This will only be saving pre-server
1787706f2543Smrg      states or states before returning to the server.  There is only
1788706f2543Smrg      one current saved state per screen and it is stored in private
1789706f2543Smrg      storage in the screen.
1790706f2543Smrg
1791706f2543Smrg	    </para></blockquote>
1792706f2543Smrg	</para></blockquote>
1793706f2543Smrg    </sect2>
1794706f2543Smrg
1795706f2543Smrg    <sect2>
1796706f2543Smrg      <title>Restore</title>
1797706f2543Smrg
1798706f2543Smrg      <para>
1799706f2543Smrg    Restore the original video state.  This could be called from the
1800706f2543Smrg    <function>ChipLeaveVT()</function> and <function>ChipCloseScreen()</function>
1801706f2543Smrg    functions.
1802706f2543Smrg      </para>
1803706f2543Smrg
1804706f2543Smrg      <blockquote><para>
1805706f2543Smrg	  <programlisting>
1806706f2543Smrg    void ChipRestore(ScrnInfoPtr pScrn);
1807706f2543Smrg	  </programlisting>
1808706f2543Smrg	  <blockquote><para>
1809706f2543Smrg      Restores the saved state from the private storage.  Usually only
1810706f2543Smrg      used for restoring text modes.
1811706f2543Smrg
1812706f2543Smrg	    </para></blockquote>
1813706f2543Smrg	</para></blockquote>
1814706f2543Smrg
1815706f2543Smrg    </sect2>
1816706f2543Smrg
1817706f2543Smrg    <sect2>
1818706f2543Smrg      <title>Initialise Mode</title>
1819706f2543Smrg
1820706f2543Smrg      <para>
1821706f2543Smrg    Initialise a video mode.  This could be called from the
1822706f2543Smrg    <function>ChipScreenInit()</function>, <function>ChipSwitchMode()</function>
1823706f2543Smrg    and <function>ChipEnterVT()</function> functions.
1824706f2543Smrg      </para>
1825706f2543Smrg
1826706f2543Smrg      <blockquote><para>
1827706f2543Smrg	  <programlisting>
1828706f2543Smrg    Bool ChipModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
1829706f2543Smrg	  </programlisting>
1830706f2543Smrg	  <blockquote><para>
1831706f2543Smrg      Programs the hardware for the given video mode.
1832706f2543Smrg
1833706f2543Smrg	    </para></blockquote>
1834706f2543Smrg	</para></blockquote>
1835706f2543Smrg
1836706f2543Smrg    </sect2>
1837706f2543Smrg  </sect1>
1838706f2543Smrg
1839706f2543Smrg  <sect1>
1840706f2543Smrg    <title>Data and Data Structures</title>
1841706f2543Smrg
1842706f2543Smrg    <sect2>
1843706f2543Smrg      <title>Command line data</title>
1844706f2543Smrg
1845706f2543Smrg      <para>
1846706f2543SmrgCommand line options are typically global, and are stored in global
1847706f2543Smrgvariables.  These variables are read-only and are available to drivers
1848706f2543Smrgvia a function call interface.  Most of these command line values are
1849706f2543Smrgprocessed via helper functions to ensure that they are treated consistently
1850706f2543Smrgby all drivers.  The other means of access is provided for cases where
1851706f2543Smrgthe supplied helper functions might not be appropriate.
1852706f2543Smrg      </para>
1853706f2543Smrg
1854706f2543Smrg      <para>
1855706f2543SmrgSome of them are:
1856706f2543Smrg
1857706f2543Smrg	<literallayout>
1858706f2543Smrg    xf86Verbose               verbosity level
1859706f2543Smrg    xf86Bpp                   -bpp from the command line
1860706f2543Smrg    xf86Depth                 -depth from the command line
1861706f2543Smrg    xf86Weight                -weight from the command line
1862706f2543Smrg    xf86Gamma                 -{r,g,b,}gamma from the command line
1863706f2543Smrg    xf86FlipPixels            -flippixels from the command line
1864706f2543Smrg    xf86ProbeOnly             -probeonly from the command line
1865706f2543Smrg    defaultColorVisualClass   -cc from the command line
1866706f2543Smrg	</literallayout>
1867706f2543Smrg      </para>
1868706f2543Smrg
1869706f2543Smrg      <para>
1870706f2543SmrgIf we ever do allow for screen-specific command line options, we may
1871706f2543Smrgneed to rethink this.
1872706f2543Smrg      </para>
1873706f2543Smrg
1874706f2543Smrg      <para>
1875706f2543SmrgThese can be accessed in a read-only manner by drivers with the following
1876706f2543Smrgfunctions:
1877706f2543Smrg      </para>
1878706f2543Smrg
1879706f2543Smrg     <blockquote><para>
1880706f2543Smrg	  <programlisting>
1881706f2543Smrg    int xf86GetVerbosity();
1882706f2543Smrg	  </programlisting>
1883706f2543Smrg	  <blockquote><para>
1884706f2543Smrg      Returns the value of <varname>xf86Verbose</varname>.
1885706f2543Smrg	    </para></blockquote>
1886706f2543Smrg
1887706f2543Smrg	</para></blockquote>
1888706f2543Smrg
1889706f2543Smrg     <blockquote><para>
1890706f2543Smrg	  <programlisting>
1891706f2543Smrg    int xf86GetDepth();
1892706f2543Smrg	  </programlisting>
1893706f2543Smrg	  <blockquote><para>
1894706f2543Smrg      Returns the <option>-depth</option> command line setting.  If not
1895706f2543Smrg      set on the command line, <constant>-1</constant> is returned.
1896706f2543Smrg	    </para></blockquote>
1897706f2543Smrg
1898706f2543Smrg	</para></blockquote>
1899706f2543Smrg
1900706f2543Smrg     <blockquote><para>
1901706f2543Smrg	  <programlisting>
1902706f2543Smrg    rgb xf86GetWeight();
1903706f2543Smrg	  </programlisting>
1904706f2543Smrg	  <blockquote><para>
1905706f2543Smrg      Returns the <option>-weight</option> command line setting.  If not
1906706f2543Smrg      set on the command line, <literal remap="tt">{0, 0, 0}</literal> is returned.
1907706f2543Smrg	    </para></blockquote>
1908706f2543Smrg
1909706f2543Smrg	</para></blockquote>
1910706f2543Smrg
1911706f2543Smrg      <blockquote><para>
1912706f2543Smrg	  <programlisting>
1913706f2543Smrg    Gamma xf86GetGamma();
1914706f2543Smrg	  </programlisting>
1915706f2543Smrg	  <blockquote><para>
1916706f2543Smrg      Returns the <option>-gamma</option> or <option>-rgamma</option>,
1917706f2543Smrg      <option>-ggamma</option>, <option>-bgamma</option> command line settings.
1918706f2543Smrg      If not set on the command line, <literal remap="tt">{0.0, 0.0, 0.0}</literal>
1919706f2543Smrg      is returned.
1920706f2543Smrg	    </para></blockquote>
1921706f2543Smrg
1922706f2543Smrg	</para></blockquote>
1923706f2543Smrg
1924706f2543Smrg      <blockquote><para>
1925706f2543Smrg	  <programlisting>
1926706f2543Smrg    Bool xf86GetFlipPixels();
1927706f2543Smrg	  </programlisting>
1928706f2543Smrg	  <blockquote><para>
1929706f2543Smrg      Returns <constant>TRUE</constant> if <option>-flippixels</option> is
1930706f2543Smrg      present on the command line, and <constant>FALSE</constant> otherwise.
1931706f2543Smrg	    </para></blockquote>
1932706f2543Smrg
1933706f2543Smrg	</para></blockquote>
1934706f2543Smrg
1935706f2543Smrg      <blockquote><para>
1936706f2543Smrg	  <programlisting>
1937706f2543Smrg    const char *xf86GetServerName();
1938706f2543Smrg	  </programlisting>
1939706f2543Smrg	  <blockquote><para>
1940706f2543Smrg      Returns the name of the X server from the command line.
1941706f2543Smrg	    </para></blockquote>
1942706f2543Smrg
1943706f2543Smrg	</para></blockquote>
1944706f2543Smrg    </sect2>
1945706f2543Smrg
1946706f2543Smrg    <sect2>
1947706f2543Smrg      <title>Data handling</title>
1948706f2543Smrg
1949706f2543Smrg      <para>
1950706f2543SmrgConfig file data contains parts that are global, and parts that are
1951706f2543SmrgScreen specific.  All of it is parsed into data structures that neither
1952706f2543Smrgthe drivers or most other parts of the server need to know about.
1953706f2543Smrg      </para>
1954706f2543Smrg
1955706f2543Smrg      <para>
1956706f2543SmrgThe global data is typically not required by drivers, and as such, most
1957706f2543Smrgof it is stored in the private <structname>xf86InfoRec</structname>.
1958706f2543Smrg      </para>
1959706f2543Smrg
1960706f2543Smrg      <para>
1961706f2543SmrgThe screen-specific data collected from the config file is stored in
1962706f2543Smrgscreen, device, display, monitor-specific data structures that are separate
1963706f2543Smrgfrom the <varname>ScrnInfoRecs</varname>, with the appropriate elements/fields
1964706f2543Smrghooked into the <varname>ScrnInfoRecs</varname> as required.  The screen
1965706f2543Smrgconfig data is held in <structname>confScreenRec</structname>, device data in
1966706f2543Smrgthe <structname>GDevRec</structname>, monitor data in the <structname>MonRec</structname>,
1967706f2543Smrgand display data in the <structname>DispRec</structname>.
1968706f2543Smrg      </para>
1969706f2543Smrg
1970706f2543Smrg      <para>
1971706f2543SmrgThe XFree86 common layer's screen specific data (the actual data in use
1972706f2543Smrgfor each screen) is held in the <varname>ScrnInfoRecs</varname>.  As has
1973706f2543Smrgbeen outlined above, the <varname>ScrnInfoRecs</varname> are allocated at probe
1974706f2543Smrgtime, and it is the responsibility of the Drivers' <function>Probe()</function>
1975706f2543Smrgand <function>PreInit()</function> functions to finish filling them in based
1976706f2543Smrgon both data provided on the command line and data provided from the
1977706f2543SmrgConfig file.  The precedence for this is:
1978706f2543Smrg
1979706f2543Smrg	<blockquote><para>
1980706f2543Smrg    command line  -&gt;  config file  -&gt;  probed/default data
1981706f2543Smrg	</para></blockquote>
1982706f2543Smrg      </para>
1983706f2543Smrg
1984706f2543Smrg      <para>
1985706f2543SmrgFor most things in this category there are helper functions that the
1986706f2543Smrgdrivers can use to ensure that the above precedence is consistently
1987706f2543Smrgused.
1988706f2543Smrg      </para>
1989706f2543Smrg
1990706f2543Smrg      <para>
1991706f2543SmrgAs well as containing screen-specific data that the XFree86 common layer
1992706f2543Smrg(including essential parts of the server infrastructure as well as helper
1993706f2543Smrgfunctions) needs to access, it also contains some data that drivers use
1994706f2543Smrginternally.  When considering whether to add a new field to the
1995706f2543Smrg<structname>ScrnInfoRec</structname>, consider the balance between the convenience
1996706f2543Smrgof things that lots of drivers need and the size/obscurity of the
1997706f2543Smrg<structname>ScrnInfoRec</structname>.
1998706f2543Smrg      </para>
1999706f2543Smrg
2000706f2543Smrg      <para>
2001706f2543SmrgPer-screen driver specific data that cannot be accommodated with the
2002706f2543Smrgstatic <structname>ScrnInfoRec</structname> fields is held in a driver-defined
2003706f2543Smrgdata structure, a pointer to which is assigned to the
2004706f2543Smrg<structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> field.  This
2005706f2543Smrgis per-screen data that persists across server generations (as does the
2006706f2543Smrgbulk of the static <structname>ScrnInfoRec</structname> data).  It would typically
2007706f2543Smrgalso include the video card's saved state.
2008706f2543Smrg      </para>
2009706f2543Smrg
2010706f2543Smrg      <para>
2011706f2543SmrgPer-screen data for other modules that the driver uses (for example,
2012706f2543Smrgthe XAA module) that is reset for each server generation is hooked into
2013706f2543Smrgthe <structname>ScrnInfoRec</structname> through it's <structfield>privates</structfield>
2014706f2543Smrgfield.
2015706f2543Smrg      </para>
2016706f2543Smrg
2017706f2543Smrg      <para>
2018706f2543SmrgOnce it has stabilised, the data structures and variables accessible to
2019706f2543Smrgvideo drivers will be documented here.  In the meantime, those things
2020706f2543Smrgdefined in the <filename>xf86.h</filename> and <filename>xf86str.h</filename>
2021706f2543Smrgfiles are visible to video drivers.  Things defined in
2022706f2543Smrg<filename>xf86Priv.h</filename> and <filename>xf86Privstr.h</filename> are NOT
2023706f2543Smrgintended to be visible to video drivers, and it is an error for a driver
2024706f2543Smrgto include those files.
2025706f2543Smrg      </para>
2026706f2543Smrg
2027706f2543Smrg    </sect2>
2028706f2543Smrg
2029706f2543Smrg    <sect2>
2030706f2543Smrg      <title>Accessing global data</title>
2031706f2543Smrg
2032706f2543Smrg      <para>
2033706f2543SmrgSome other global state information that the drivers may access via
2034706f2543Smrgfunctions is as follows:
2035706f2543Smrg      </para>
2036706f2543Smrg
2037706f2543Smrg      <blockquote><para>
2038706f2543Smrg	  <programlisting>
2039706f2543Smrg    Bool xf86ServerIsExiting();
2040706f2543Smrg	  </programlisting>
2041706f2543Smrg	  <blockquote><para>
2042706f2543Smrg      Returns <constant>TRUE</constant> if the server is at the end of a
2043706f2543Smrg      generation and is in the process of exiting, and
2044706f2543Smrg      <constant>FALSE</constant> otherwise.
2045706f2543Smrg	    </para></blockquote>
2046706f2543Smrg
2047706f2543Smrg	</para></blockquote>
2048706f2543Smrg
2049706f2543Smrg      <blockquote><para>
2050706f2543Smrg	  <programlisting>
2051706f2543Smrg    Bool xf86ServerIsResetting();
2052706f2543Smrg	  </programlisting>
2053706f2543Smrg	  <blockquote><para>
2054706f2543Smrg      Returns <constant>TRUE</constant> if the server is at the end of a
2055706f2543Smrg      generation and is in the process of resetting, and
2056706f2543Smrg      <constant>FALSE</constant> otherwise.
2057706f2543Smrg	    </para></blockquote>
2058706f2543Smrg
2059706f2543Smrg	</para></blockquote>
2060706f2543Smrg
2061706f2543Smrg      <blockquote><para>
2062706f2543Smrg	  <programlisting>
2063706f2543Smrg    Bool xf86ServerIsInitialising();
2064706f2543Smrg	  </programlisting>
2065706f2543Smrg	  <blockquote><para>
2066706f2543Smrg      Returns <constant>TRUE</constant> if the server is at the beginning of
2067706f2543Smrg      a generation and is in the process of initialising, and
2068706f2543Smrg      <constant>FALSE</constant> otherwise.
2069706f2543Smrg	    </para></blockquote>
2070706f2543Smrg
2071706f2543Smrg	</para></blockquote>
2072706f2543Smrg
2073706f2543Smrg      <blockquote><para>
2074706f2543Smrg	  <programlisting>
2075706f2543Smrg    Bool xf86ServerIsOnlyProbing();
2076706f2543Smrg	  </programlisting>
2077706f2543Smrg	  <blockquote><para>
2078706f2543Smrg      Returns <constant>TRUE</constant> if the -probeonly command line flag
2079706f2543Smrg      was specified, and <constant>FALSE</constant> otherwise.
2080706f2543Smrg	    </para></blockquote>
2081706f2543Smrg
2082706f2543Smrg	</para></blockquote>
2083706f2543Smrg
2084706f2543Smrg      <blockquote><para>
2085706f2543Smrg	  <programlisting>
2086706f2543Smrg    Bool xf86CaughtSignal();
2087706f2543Smrg	  </programlisting>
2088706f2543Smrg	  <blockquote><para>
2089706f2543Smrg      Returns <constant>TRUE</constant> if the server has caught a signal,
2090706f2543Smrg      and <constant>FALSE</constant> otherwise.
2091706f2543Smrg	    </para></blockquote>
2092706f2543Smrg
2093706f2543Smrg	</para></blockquote>
2094706f2543Smrg    </sect2>
2095706f2543Smrg
2096706f2543Smrg    <sect2>
2097706f2543Smrg      <title>Allocating private data</title>
2098706f2543Smrg
2099706f2543Smrg      <para>
2100706f2543SmrgA driver and any module it uses may allocate per-screen private storage
2101706f2543Smrgin either the <structname>ScreenRec</structname> (DIX level) or
2102706f2543Smrg<structname>ScrnInfoRec</structname> (XFree86 common layer level).
2103706f2543Smrg<structname>ScreenRec</structname> storage persists only for a single server
2104706f2543Smrggeneration, and <structname>ScrnInfoRec</structname> storage persists across
2105706f2543Smrggenerations for the lifetime of the server.
2106706f2543Smrg      </para>
2107706f2543Smrg
2108706f2543Smrg      <para>
2109706f2543SmrgThe <structname>ScreenRec</structname> <structfield>devPrivates</structfield> data must be
2110706f2543Smrgreallocated/initialised at the start of each new generation.  This is
2111706f2543Smrgnormally done from the <function>ChipScreenInit()</function> function, and
2112706f2543SmrgInit functions for other modules that it calls.  Data allocated in this
2113706f2543Smrgway should be freed by the driver's <function>ChipCloseScreen()</function>
2114706f2543Smrgfunctions, and Close functions for other modules that it calls.  A new
2115706f2543Smrg<structfield>devPrivates</structfield> entry is allocated by calling the
2116706f2543Smrg<function>AllocateScreenPrivateIndex()</function> function.
2117706f2543Smrg      </para>
2118706f2543Smrg
2119706f2543Smrg      <blockquote><para>
2120706f2543Smrg	  <programlisting>
2121706f2543Smrg    int AllocateScreenPrivateIndex();
2122706f2543Smrg	  </programlisting>
2123706f2543Smrg	  <blockquote><para>
2124706f2543Smrg      This function allocates a new element in the
2125706f2543Smrg      <structfield>devPrivates</structfield> field of all currently existing
2126706f2543Smrg      <literal remap="tt">ScreenRecs</literal>.  The return value is the index of this
2127706f2543Smrg      new element in the <structfield>devPrivates</structfield> array.  The
2128706f2543Smrg      <structfield>devPrivates</structfield> field is of type
2129706f2543Smrg      <structname>DevUnion</structname>:
2130706f2543Smrg
2131706f2543Smrg	      <programlisting>
2132706f2543Smrg        typedef union _DevUnion {
2133706f2543Smrg            pointer             ptr;
2134706f2543Smrg            long                val;
2135706f2543Smrg            unsigned long       uval;
2136706f2543Smrg            pointer             (*fptr)(void);
2137706f2543Smrg        } DevUnion;
2138706f2543Smrg	      </programlisting>
2139706f2543Smrg
2140706f2543Smrg      which allows the element to be used for any of the above types.
2141706f2543Smrg      It is commonly used as a pointer to data that the caller allocates
2142706f2543Smrg      after the new index has been allocated.
2143706f2543Smrg	    </para>
2144706f2543Smrg
2145706f2543Smrg	    <para>
2146706f2543Smrg      This function will return <constant>-1</constant> when there is an
2147706f2543Smrg      error allocating the new index.
2148706f2543Smrg	    </para>
2149706f2543Smrg
2150706f2543Smrg	  </blockquote>
2151706f2543Smrg	</para></blockquote>
2152706f2543Smrg
2153706f2543Smrg      <para>
2154706f2543SmrgThe <structname>ScrnInfoRec</structname> <structfield>privates</structfield> data persists
2155706f2543Smrgfor the life of the server, so only needs to be allocated once.  This
2156706f2543Smrgshould be done from the <function>ChipPreInit()</function> function, and Init
2157706f2543Smrgfunctions for other modules that it calls.  Data allocated in this way
2158706f2543Smrgshould be freed by the driver's <function>ChipFreeScreen()</function> functions,
2159706f2543Smrgand Free functions for other modules that it calls.  A new
2160706f2543Smrg<structfield>privates</structfield> entry is allocated by calling the
2161706f2543Smrg<function>xf86AllocateScrnInfoPrivateIndex()</function> function.
2162706f2543Smrg      </para>
2163706f2543Smrg
2164706f2543Smrg      <blockquote><para>
2165706f2543Smrg	  <programlisting>
2166706f2543Smrg    int xf86AllocateScrnInfoPrivateIndex();
2167706f2543Smrg	  </programlisting>
2168706f2543Smrg	  <blockquote><para>
2169706f2543Smrg      This function allocates a new element in the <structfield>privates</structfield>
2170706f2543Smrg      field of all currently existing <varname>ScrnInfoRecs</varname>.
2171706f2543Smrg      The return value is the index of this new element in the
2172706f2543Smrg      <structfield>privates</structfield> array.  The <structfield>privates</structfield>
2173706f2543Smrg      field is of type <structfield>DevUnion</structfield>:
2174706f2543Smrg
2175706f2543Smrg	      <programlisting>
2176706f2543Smrg        typedef union _DevUnion {
2177706f2543Smrg            pointer             ptr;
2178706f2543Smrg            long                val;
2179706f2543Smrg            unsigned long       uval;
2180706f2543Smrg            pointer             (*fptr)(void);
2181706f2543Smrg        } DevUnion;
2182706f2543Smrg	      </programlisting>
2183706f2543Smrg
2184706f2543Smrg      which allows the element to be used for any of the above types.
2185706f2543Smrg      It is commonly used as a pointer to data that the caller allocates
2186706f2543Smrg      after the new index has been allocated.
2187706f2543Smrg	    </para>
2188706f2543Smrg
2189706f2543Smrg	    <para>
2190706f2543Smrg      This function will not return when there is an error allocating
2191706f2543Smrg      the new index.  When there is an error it will cause the server
2192706f2543Smrg      to exit with a fatal error.  The similar function for allocation
2193706f2543Smrg      privates in the <structname>ScreenRec</structname>
2194706f2543Smrg      (<function>AllocateScreenPrivateIndex()</function>) differs in this
2195706f2543Smrg      respect by returning <constant>-1</constant> when the allocation fails.
2196706f2543Smrg	    </para>
2197706f2543Smrg
2198706f2543Smrg	  </blockquote>
2199706f2543Smrg	</para></blockquote>
2200706f2543Smrg    </sect2>
2201706f2543Smrg  </sect1>
2202706f2543Smrg
2203706f2543Smrg  <sect1 id="rac">
2204706f2543Smrg    <title>Keeping Track of Bus Resources</title>
2205706f2543Smrg
2206706f2543Smrg    <sect2>
2207706f2543Smrg      <title>Theory of Operation</title>
2208706f2543Smrg
2209706f2543Smrg      <para>
2210706f2543SmrgThe XFree86 common layer has knowledge of generic access control mechanisms
2211706f2543Smrgfor devices on certain bus systems (currently the PCI bus) as well as
2212706f2543Smrgof methods to enable or disable access to the buses itself.  Furthermore
2213706f2543Smrgit can access information on resources decoded by these devices and if
2214706f2543Smrgnecessary modify it.
2215706f2543Smrg      </para>
2216706f2543Smrg
2217706f2543Smrg      <para>
2218706f2543SmrgWhen first starting the Xserver collects all this information, saves it
2219706f2543Smrgfor restoration, checks it for consistency, and if necessary, corrects
2220706f2543Smrgit.  Finally it disables all resources on a generic level prior to
2221706f2543Smrgcalling any driver function.
2222706f2543Smrg      </para>
2223706f2543Smrg
2224706f2543Smrg      <para>
2225706f2543SmrgWhen the <function>Probe()</function> function of each driver is called the
2226706f2543Smrgdevice sections are matched against the devices found in the system.
2227706f2543SmrgThe driver may probe devices at this stage that cannot be identified by
2228706f2543Smrgusing device independent methods.  Access to all resources that can be
2229706f2543Smrgcontrolled in a device independent way is disabled.  The
2230706f2543Smrg<function>Probe()</function> function should register all non-relocatable
2231706f2543Smrgresources at this stage.  If a resource conflict is found between
2232706f2543Smrgexclusive resources the driver will fail immediately.  Optionally the
2233706f2543Smrgdriver might specify an <function>EntityInit()</function>,
2234706f2543Smrg<function>EntityLeave()</function> and <function>EntityEnter()</function> function.
2235706f2543Smrg      </para>
2236706f2543Smrg
2237706f2543Smrg      <para>
2238706f2543Smrg<function>EntityInit()</function> can be used to disable any shared resources
2239706f2543Smrgthat are not controlled by the generic access control functions.  It is
2240706f2543Smrgcalled prior to the PreInit phase regardless if an entity is active or
2241706f2543Smrgnot.  When calling the <function>EntityInit()</function>,
2242706f2543Smrg<function>EntityEnter()</function> and <function>EntityLeave()</function> functions
2243706f2543Smrgthe common level will disable access to all other entities on a generic
2244706f2543Smrglevel.  Since the common level has no knowledge of device specific
2245706f2543Smrgmethods to disable access to resources it cannot be guaranteed that
2246706f2543Smrgcertain resources are not decoded by any other entity until the
2247706f2543Smrg<function>EntityInit()</function> or <function>EntityEnter()</function> phase is
2248706f2543Smrgfinished.  Device drivers should therefore register all those resources
2249706f2543Smrgwhich they are going to disable.  If these resources are never to be
2250706f2543Smrgused by any driver function they may be flagged <constant>ResInit</constant>
2251706f2543Smrgso that they can be removed from the resource list after processing all
2252706f2543Smrg<function>EntityInit()</function> functions.  <function>EntityEnter()</function>
2253706f2543Smrgshould disable decoding of all resources which are not registered as
2254706f2543Smrgexclusive and which are not handled by the generic access control in
2255706f2543Smrgthe common level.  The difference to <function>EntityInit()</function> is
2256706f2543Smrgthat the latter one is only called once during lifetime of the server.
2257706f2543SmrgIt can therefore be used to set up variables prior to disabling resources.
2258706f2543Smrg<function>EntityLeave()</function> should restore the original state when
2259706f2543Smrgexiting the server or switching to a different VT.  It also needs to
2260706f2543Smrgdisable device specific access functions if they need to be disabled on
2261706f2543Smrgserver exit or VT switch.  The default state is to enable them before
2262706f2543Smrggiving up the VT.
2263706f2543Smrg      </para>
2264706f2543Smrg
2265706f2543Smrg      <para>
2266706f2543SmrgIn <function>PreInit()</function> phase each driver should check if any
2267706f2543Smrgsharable resources it has registered during <function>Probe()</function> has
2268706f2543Smrgbeen denied and take appropriate action which could simply be to fail.
2269706f2543SmrgIf it needs to access resources it has disabled during
2270706f2543Smrg<function>EntitySetup()</function> it can do so provided it has registered
2271706f2543Smrgthese and will disable them before returning from
2272706f2543Smrg<function>PreInit()</function>.  This also applies to all other driver
2273706f2543Smrgfunctions.  Several functions are provided to request resource ranges,
2274706f2543Smrgregister these, correct PCI config space and add replacements for the
2275706f2543Smrggeneric access functions.  Resources may be marked <quote>disabled</quote> or
2276706f2543Smrg<quote>unused</quote> during OPERATING stage.  Although these steps could also be
2277706f2543Smrgperformed in <function>ScreenInit()</function>, this is not desirable.
2278706f2543Smrg      </para>
2279706f2543Smrg
2280706f2543Smrg      <para>
2281706f2543SmrgFollowing <function>PreInit()</function> phase the common level determines
2282706f2543Smrgif resource access control is needed.  This is the case if more than
2283706f2543Smrgone screen is used.  If necessary the RAC wrapper module is loaded.  In
2284706f2543Smrg<function>ScreenInit()</function> the drivers can decide which operations
2285706f2543Smrgneed to be placed under RAC.  Available are the frame buffer operations,
2286706f2543Smrgthe pointer operations and the colormap operations.  Any operation that
2287706f2543Smrgrequires resources which might be disabled during OPERATING state should
2288706f2543Smrgbe set to use RAC.  This can be specified separately for memory and IO
2289706f2543Smrgresources.
2290706f2543Smrg      </para>
2291706f2543Smrg
2292706f2543Smrg      <para>
2293706f2543SmrgWhen <function>ScreenInit()</function> phase is done the common level will
2294706f2543Smrgdetermine which shared resources are requested by more than one driver
2295706f2543Smrgand set the access functions accordingly.  This is done following these
2296706f2543Smrgrules:
2297706f2543Smrg
2298706f2543Smrg	<orderedlist>
2299706f2543Smrg	  <listitem><para>
2300706f2543Smrg   The sharable resources registered by each entity are compared.  If
2301706f2543Smrg   a resource is registered by more than one entity the entity will be
2302706f2543Smrg   marked to need to share this resources type (<constant>IO</constant> or
2303706f2543Smrg   <constant>MEM</constant>).
2304706f2543Smrg	    </para></listitem>
2305706f2543Smrg
2306706f2543Smrg	  <listitem><para>
2307706f2543Smrg   A resource marked <quote>disabled</quote> during OPERATING state will be ignored
2308706f2543Smrg   entirely.
2309706f2543Smrg	    </para></listitem>
2310706f2543Smrg
2311706f2543Smrg	  <listitem><para>
2312706f2543Smrg   A resource marked <quote>unused</quote> will only conflicts with an overlapping
2313706f2543Smrg   resource of an other entity if the second is actually in use during
2314706f2543Smrg   OPERATING state.
2315706f2543Smrg	    </para></listitem>
2316706f2543Smrg
2317706f2543Smrg	  <listitem><para>
2318706f2543Smrg   If an <quote>unused</quote> resource was found to conflict however the entity
2319706f2543Smrg   does not use any other resource of this type the entire resource type
2320706f2543Smrg   will be disabled for that entity.
2321706f2543Smrg	    </para></listitem>
2322706f2543Smrg	</orderedlist>
2323706f2543Smrg      </para>
2324706f2543Smrg
2325706f2543Smrg      <para>
2326706f2543SmrgThe driver has the choice among different ways to control access to
2327706f2543Smrgcertain resources:
2328706f2543Smrg
2329706f2543Smrg	<orderedlist>
2330706f2543Smrg	  <listitem><para>
2331706f2543Smrg   It can rely on the generic access functions.  This is probably the
2332706f2543Smrg   most common case.  Here the driver only needs to register any resource
2333706f2543Smrg   it is going to use.
2334706f2543Smrg	    </para></listitem>
2335706f2543Smrg
2336706f2543Smrg	  <listitem><para>
2337706f2543Smrg   It can replace the generic access functions by driver specific
2338706f2543Smrg   ones.  This will mostly be used in cases where no generic access
2339706f2543Smrg   functions are available.  In this case the driver has to make sure
2340706f2543Smrg   these resources are disabled when entering the <function>PreInit()</function>
2341706f2543Smrg   stage.  Since the replacement functions are registered in
2342706f2543Smrg   <function>PreInit()</function> the driver will have to enable these
2343706f2543Smrg   resources itself if it needs to access them during this state.  The
2344706f2543Smrg   driver can specify if the replacement functions can control memory
2345706f2543Smrg   and/or I/O resources separately.
2346706f2543Smrg	    </para></listitem>
2347706f2543Smrg
2348706f2543Smrg	  <listitem><para>
2349706f2543Smrg   The driver can enable resources itself when it needs them.  Each
2350706f2543Smrg   driver function enabling them needs to disable them before it will
2351706f2543Smrg   return.  This should be used if a resource which can be controlled
2352706f2543Smrg   in a device dependent way is only required during SETUP state.  This
2353706f2543Smrg   way it can be marked <quote>unused</quote> during OPERATING state.
2354706f2543Smrg	    </para></listitem>
2355706f2543Smrg	</orderedlist>
2356706f2543Smrg      </para>
2357706f2543Smrg
2358706f2543Smrg      <para>
2359706f2543SmrgA resource which is decoded during OPERATING state however never accessed
2360706f2543Smrgby the driver should be marked unused.
2361706f2543Smrg      </para>
2362706f2543Smrg
2363706f2543Smrg      <para>
2364706f2543SmrgSince access switching latencies are an issue during Xserver operation,
2365706f2543Smrgthe common level attempts to minimize the number of entities that need
2366706f2543Smrgto be placed under RAC control.  When a wrapped operation is called,
2367706f2543Smrgthe <function>EnableAccess()</function> function is called before control is
2368706f2543Smrgpassed on.  <function>EnableAccess()</function> checks if a screen is under
2369706f2543Smrgaccess control.  If not it just establishes bus routing and returns.
2370706f2543SmrgIf the screen needs to be under access control,
2371706f2543Smrg<function>EnableAccess()</function> determines which resource types
2372706f2543Smrg(<literal remap="tt">MEM</literal>, <literal remap="tt">IO</literal>) are required.  Then it tests
2373706f2543Smrgif this access is already established.  If so it simply returns.  If
2374706f2543Smrgnot it disables the currently established access, fixes bus routing and
2375706f2543Smrgenables access to all entities registered for this screen.
2376706f2543Smrg      </para>
2377706f2543Smrg
2378706f2543Smrg      <para>
2379706f2543SmrgWhenever a mode switch or a VT-switch is performed the common level will
2380706f2543Smrgreturn to SETUP state.
2381706f2543Smrg      </para>
2382706f2543Smrg    </sect2>
2383706f2543Smrg
2384706f2543Smrg    <sect2>
2385706f2543Smrg      <title>Resource Types</title>
2386706f2543Smrg
2387706f2543Smrg      <para>
2388706f2543SmrgResource have certain properties.  When registering resources each range
2389706f2543Smrgis accompanied by a flag consisting of the ORed flags of the different
2390706f2543Smrgproperties the resource has.  Each resource range may be classified
2391706f2543Smrgaccording to
2392706f2543Smrg
2393706f2543Smrg	<itemizedlist>
2394706f2543Smrg	  <listitem><para>
2395706f2543Smrg       its physical properties i.e., if it addresses
2396706f2543Smrg       memory (<constant>ResMem</constant>)  or
2397706f2543Smrg       I/O space (<constant>ResIo</constant>),
2398706f2543Smrg	    </para></listitem>
2399706f2543Smrg	  <listitem><para>
2400706f2543Smrg       if it addresses a
2401706f2543Smrg       block (<constant>ResBlock</constant>) or
2402706f2543Smrg       sparse (<constant>ResSparse</constant>)
2403706f2543Smrg       range,
2404706f2543Smrg	    </para></listitem>
2405706f2543Smrg	  <listitem><para>
2406706f2543Smrg       its access properties.
2407706f2543Smrg	    </para></listitem>
2408706f2543Smrg	</itemizedlist>
2409706f2543Smrg      </para>
2410706f2543Smrg
2411706f2543Smrg      <para>
2412706f2543SmrgThere are two known access properties:
2413706f2543Smrg
2414706f2543Smrg	<itemizedlist>
2415706f2543Smrg	  <listitem><para>
2416706f2543Smrg  <constant>ResExclusive</constant>
2417706f2543Smrg    for resources which may not be shared with any other device and
2418706f2543Smrg	    </para></listitem>
2419706f2543Smrg	  <listitem><para>
2420706f2543Smrg  <constant>ResShared</constant>
2421706f2543Smrg    for resources which can be disabled and therefore can be shared.
2422706f2543Smrg	    </para></listitem>
2423706f2543Smrg	</itemizedlist>
2424706f2543Smrg      </para>
2425706f2543Smrg
2426706f2543Smrg      <para>
2427706f2543SmrgIf it is necessary to test a resource against any type a generic access
2428706f2543Smrgtype <constant>ResAny</constant> is provided.  If this is set the resource
2429706f2543Smrgwill conflict with any resource of a different entity intersecting its
2430706f2543Smrgrange.  Further it can be specified that a resource is decoded however
2431706f2543Smrgnever used during any stage (<constant>ResUnused</constant>) or during
2432706f2543SmrgOPERATING state (<constant>ResUnusedOpr</constant>).  A resource only visible
2433706f2543Smrgduring the init functions (ie.  <function>EntityInit()</function>,
2434706f2543Smrg<function>EntityEnter()</function> and <function>EntityLeave()</function> should
2435706f2543Smrgbe registered with the flag <constant>ResInit</constant>.  A resource that
2436706f2543Smrgmight conflict with background resource ranges may be flagged with
2437706f2543Smrg<constant>ResBios</constant>.  This might be useful when registering resources
2438706f2543Smrgranges that were assigned by the system Bios.
2439706f2543Smrg      </para>
2440706f2543Smrg
2441706f2543Smrg      <para>
2442706f2543SmrgSeveral predefined resource lists are available for VGA and 8514/A
2443706f2543Smrgresources in <filename>common/xf86Resources.h</filename>.
2444706f2543Smrg      </para>
2445706f2543Smrg    </sect2>
2446706f2543Smrg
2447706f2543Smrg    <sect2 id="avail">
2448706f2543Smrg      <title>Available Functions</title>
2449706f2543Smrg
2450706f2543Smrg      <para>
2451706f2543SmrgThe functions provided for resource management are listed in their order
2452706f2543Smrgof use in the driver.
2453706f2543Smrg      </para>
2454706f2543Smrg
2455706f2543Smrg      <sect3>
2456706f2543Smrg	<title>Probe Phase</title>
2457706f2543Smrg
2458706f2543Smrg	<para>
2459706f2543SmrgIn this phase each driver detects those resources it is able to drive,
2460706f2543Smrgcreates an entity record for each of them, registers non-relocatable
2461706f2543Smrgresources and allocates screens and adds the resources to screens.
2462706f2543Smrg	</para>
2463706f2543Smrg
2464706f2543Smrg	<para>
2465706f2543SmrgTwo helper functions are provided for matching device sections in the
2466706f2543Smrgxorg.conf file to the devices:
2467706f2543Smrg	</para>
2468706f2543Smrg
2469706f2543Smrg	<blockquote><para>
2470706f2543Smrg	    <programlisting>
2471706f2543Smrg    int xf86MatchPciInstances(const char *driverName, int vendorID,
2472706f2543Smrg                              SymTabPtr chipsets, PciChipsets *PCIchipsets,
2473706f2543Smrg                              GDevPtr *devList, int numDevs, DriverPtr drvp,
2474706f2543Smrg                              int **foundEntities);
2475706f2543Smrg	    </programlisting>
2476706f2543Smrg	    <blockquote><para>
2477706f2543Smrg      This function finds matches between PCI cards that a driver supports
2478706f2543Smrg      and config file device sections.  It is intended for use in the
2479706f2543Smrg      <function>ChipProbe()</function> function of drivers for PCI cards.
2480706f2543Smrg      Only probed PCI devices with a vendor ID matching
2481706f2543Smrg      <parameter>vendorID</parameter> are considered.  <parameter>devList</parameter>
2482706f2543Smrg      and <parameter>numDevs</parameter> are typically those found from
2483706f2543Smrg      calling <function>xf86MatchDevice()</function>, and represent the active
2484706f2543Smrg      config file device sections relevant to the driver.
2485706f2543Smrg      <parameter>PCIchipsets</parameter> is a table that provides a mapping
2486706f2543Smrg      between the PCI device IDs, the driver's internal chipset tokens
2487706f2543Smrg      and a list of fixed resources.
2488706f2543Smrg	      </para>
2489706f2543Smrg
2490706f2543Smrg	      <para>
2491706f2543Smrg      When a device section doesn't have a <emphasis>BusID</emphasis> entry it
2492706f2543Smrg      can only match the primary video device.  Secondary devices are
2493706f2543Smrg      only matched with device sections that have a matching
2494706f2543Smrg      <emphasis>BusID</emphasis> entry.
2495706f2543Smrg	      </para>
2496706f2543Smrg
2497706f2543Smrg	      <para>
2498706f2543Smrg      Once the preliminary matches have been found, a final match is
2499706f2543Smrg      confirmed by checking if the chipset override, ChipID override or
2500706f2543Smrg      probed PCI chipset type match one of those given in the
2501706f2543Smrg      <parameter>chipsets</parameter> and <parameter>PCIchipsets</parameter> lists.
2502706f2543Smrg      The <parameter>PCIchipsets</parameter> list includes a list of the PCI
2503706f2543Smrg      device IDs supported by the driver.  The list should be terminated
2504706f2543Smrg      with an entry with PCI ID <constant>-1</constant>".  The
2505706f2543Smrg      <parameter>chipsets</parameter> list is a table mapping the driver's
2506706f2543Smrg      internal chipset tokens to names, and should be terminated with
2507706f2543Smrg      a <constant>NULL</constant> entry.  Only those entries with a
2508706f2543Smrg      corresponding entry in the <parameter>PCIchipsets</parameter> list are
2509706f2543Smrg      considered.  The order of precedence is: config file chipset,
2510706f2543Smrg      config file ChipID, probed PCI device ID.
2511706f2543Smrg	      </para>
2512706f2543Smrg
2513706f2543Smrg	      <para>
2514706f2543Smrg      In cases where a driver handles PCI chipsets with more than one
2515706f2543Smrg      vendor ID, it may set <parameter>vendorID</parameter> to
2516706f2543Smrg      <constant>0</constant>, and OR each devID in the list with (the
2517706f2543Smrg      vendor&nbsp;ID&nbsp;&lt;&lt;&nbsp;16).
2518706f2543Smrg	      </para>
2519706f2543Smrg
2520706f2543Smrg	      <para>
2521706f2543Smrg      Entity index numbers for confirmed matches are returned as an
2522706f2543Smrg      array via <parameter>foundEntities</parameter>.  The PCI information,
2523706f2543Smrg      chipset token and device section for each match are found in the
2524706f2543Smrg      <structname>EntityInfoRec</structname> referenced by the indices.
2525706f2543Smrg	      </para>
2526706f2543Smrg
2527706f2543Smrg	      <para>
2528706f2543Smrg      The function return value is the number of confirmed matches.  A
2529706f2543Smrg      return value of <constant>-1</constant> indicates an internal error.
2530706f2543Smrg      The returned <parameter>foundEntities</parameter> array should be freed
2531706f2543Smrg      by the driver with <function>xfree()</function> when it is no longer
2532706f2543Smrg      needed in cases where the return value is greater than zero.
2533706f2543Smrg	      </para>
2534706f2543Smrg
2535706f2543Smrg	    </blockquote></para></blockquote>
2536706f2543Smrg
2537706f2543Smrg	<blockquote><para>
2538706f2543Smrg	    <programlisting>
2539706f2543Smrg    int xf86MatchIsaInstances(const char *driverName,
2540706f2543Smrg                              SymTabPtr chipsets, IsaChipsets *ISAchipsets,
2541706f2543Smrg                              DriverPtr drvp, FindIsaDevProc FindIsaDevice,
2542706f2543Smrg                              GDevPtr *devList, int numDevs,
2543706f2543Smrg                              int **foundEntities);
2544706f2543Smrg	    </programlisting>
2545706f2543Smrg	    <blockquote><para>
2546706f2543Smrg      This function finds matches between ISA cards that a driver supports
2547706f2543Smrg      and config file device sections.  It is intended for use in the
2548706f2543Smrg      <function>ChipProbe()</function> function of drivers for ISA cards.
2549706f2543Smrg      <parameter>devList</parameter> and <parameter>numDevs</parameter> are
2550706f2543Smrg      typically those found from calling <function>xf86MatchDevice()</function>,
2551706f2543Smrg      and represent the active config file device sections relevant to
2552706f2543Smrg      the driver.  <parameter>ISAchipsets</parameter> is a table that provides
2553706f2543Smrg      a mapping between the driver's internal chipset tokens and the
2554706f2543Smrg      resource classes.  <parameter>FindIsaDevice</parameter> is a
2555706f2543Smrg      driver-provided function that probes the hardware and returns the
2556706f2543Smrg      chipset token corresponding to what was detected, and
2557706f2543Smrg      <constant>-1</constant> if nothing was detected.
2558706f2543Smrg	      </para>
2559706f2543Smrg
2560706f2543Smrg	      <para>
2561706f2543Smrg      If the config file device section contains a chipset entry, then
2562706f2543Smrg      it is checked against the <parameter>chipsets</parameter> list.  When
2563706f2543Smrg      no chipset entry is present, the <parameter>FindIsaDevice</parameter>
2564706f2543Smrg      function is called instead.
2565706f2543Smrg	      </para>
2566706f2543Smrg
2567706f2543Smrg	      <para>
2568706f2543Smrg      Entity index numbers for confirmed matches are returned as an
2569706f2543Smrg      array via <parameter>foundEntities</parameter>.  The chipset token and
2570706f2543Smrg      device section for each match are found in the
2571706f2543Smrg      <structname>EntityInfoRec</structname> referenced by the indices.
2572706f2543Smrg	      </para>
2573706f2543Smrg
2574706f2543Smrg	      <para>
2575706f2543Smrg      The function return value is the number of confirmed matches.  A
2576706f2543Smrg      return value of <constant>-1</constant> indicates an internal error.
2577706f2543Smrg      The returned <parameter>foundEntities</parameter> array should be freed
2578706f2543Smrg      by the driver with <function>xfree()</function> when it is no longer
2579706f2543Smrg      needed in cases where the return value is greater than zero.
2580706f2543Smrg	      </para>
2581706f2543Smrg
2582706f2543Smrg	    </blockquote></para></blockquote>
2583706f2543Smrg
2584706f2543Smrg	<para>
2585706f2543SmrgThese two helper functions make use of several core functions that are
2586706f2543Smrgavailable at the driver level:
2587706f2543Smrg	</para>
2588706f2543Smrg
2589706f2543Smrg	<blockquote><para>
2590706f2543Smrg	    <programlisting>
2591706f2543Smrg    Bool xf86ParsePciBusString(const char *busID, int *bus,
2592706f2543Smrg                               int *device, int *func);
2593706f2543Smrg	    </programlisting>
2594706f2543Smrg	    <blockquote><para>
2595706f2543Smrg      Takes a <parameter>BusID</parameter> string, and if it is in the correct
2596706f2543Smrg      format, returns the PCI <parameter>bus</parameter>, <parameter>device</parameter>,
2597706f2543Smrg      <parameter>func</parameter> values that it indicates.  The format of the
2598706f2543Smrg      string is expected to be "PCI:bus:device:func" where each of <quote>bus</quote>,
2599706f2543Smrg      <quote>device</quote> and <quote>func</quote> are decimal integers.  The ":func" part may
2600706f2543Smrg      be omitted, and the func value assumed to be zero, but this isn't
2601706f2543Smrg      encouraged.  The "PCI" prefix may also be omitted.  The prefix
2602706f2543Smrg      "AGP" is currently equivalent to the "PCI" prefix.  If the string
2603706f2543Smrg      isn't a valid PCI BusID, the return value is <constant>FALSE</constant>.
2604706f2543Smrg	      </para>
2605706f2543Smrg
2606706f2543Smrg	    </blockquote></para></blockquote>
2607706f2543Smrg
2608706f2543Smrg	<blockquote><para>
2609706f2543Smrg	    <programlisting>
2610706f2543Smrg    Bool xf86ComparePciBusString(const char *busID, int bus,
2611706f2543Smrg                                 int device, int func);
2612706f2543Smrg	    </programlisting>
2613706f2543Smrg	    <blockquote><para>
2614706f2543Smrg      Compares a <parameter>BusID</parameter> string with PCI <parameter>bus</parameter>,
2615706f2543Smrg      <parameter>device</parameter>, <parameter>func</parameter> values.  If they
2616706f2543Smrg      match <constant>TRUE</constant> is returned, and <constant>FALSE</constant>
2617706f2543Smrg      if they don't.
2618706f2543Smrg	      </para>
2619706f2543Smrg
2620706f2543Smrg	    </blockquote></para></blockquote>
2621706f2543Smrg
2622706f2543Smrg	<blockquote><para>
2623706f2543Smrg	    <programlisting>
2624706f2543Smrg    Bool xf86ParseIsaBusString(const char *busID);
2625706f2543Smrg	    </programlisting>
2626706f2543Smrg	    <blockquote><para>
2627706f2543Smrg      Compares a <parameter>BusID</parameter> string with the ISA bus ID string
2628706f2543Smrg      ("ISA" or "ISA:").  If they match <constant>TRUE</constant> is returned,
2629706f2543Smrg      and <constant>FALSE</constant> if they don't.
2630706f2543Smrg	      </para>
2631706f2543Smrg
2632706f2543Smrg	    </blockquote></para></blockquote>
2633706f2543Smrg
2634706f2543Smrg	<blockquote><para>
2635706f2543Smrg	    <programlisting>
2636706f2543Smrg    Bool xf86CheckPciSlot(int bus, int device, int func);
2637706f2543Smrg	    </programlisting>
2638706f2543Smrg	    <blockquote><para>
2639706f2543Smrg      Checks if the PCI slot <literal remap="tt">bus:device:func</literal> has been
2640706f2543Smrg      claimed.  If so, it returns <constant>FALSE</constant>, and otherwise
2641706f2543Smrg      <constant>TRUE</constant>.
2642706f2543Smrg	      </para>
2643706f2543Smrg
2644706f2543Smrg	    </blockquote></para></blockquote>
2645706f2543Smrg
2646706f2543Smrg	<blockquote><para>
2647706f2543Smrg	    <programlisting>
2648706f2543Smrg    int xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp,
2649706f2543Smrg                         int chipset, GDevPtr dev, Bool active);
2650706f2543Smrg	    </programlisting>
2651706f2543Smrg	    <blockquote><para>
2652706f2543Smrg      This function is used to claim a PCI slot, allocate the associated
2653706f2543Smrg      entity record and initialise their data structures.  The return
2654706f2543Smrg      value is the index of the newly allocated entity record, or
2655706f2543Smrg      <constant>-1</constant> if the claim fails.  This function should always
2656706f2543Smrg      succeed if <function>xf86CheckPciSlot()</function> returned
2657706f2543Smrg      <constant>TRUE</constant> for the same PCI slot.
2658706f2543Smrg	      </para>
2659706f2543Smrg
2660706f2543Smrg	    </blockquote></para></blockquote>
2661706f2543Smrg
2662706f2543Smrg	<blockquote><para>
2663706f2543Smrg	    <programlisting>
2664706f2543Smrg    Bool xf86IsPrimaryPci(void);
2665706f2543Smrg	    </programlisting>
2666706f2543Smrg	    <blockquote><para>
2667706f2543Smrg      This function returns <constant>TRUE</constant> if the primary card is
2668706f2543Smrg      a PCI device, and <constant>FALSE</constant> otherwise.
2669706f2543Smrg	      </para>
2670706f2543Smrg
2671706f2543Smrg	    </blockquote></para></blockquote>
2672706f2543Smrg
2673706f2543Smrg	<blockquote><para>
2674706f2543Smrg	    <programlisting>
2675706f2543Smrg    int xf86ClaimIsaSlot(DriverPtr drvp, int chipset,
2676706f2543Smrg                         GDevPtr dev, Bool active);
2677706f2543Smrg	    </programlisting>
2678706f2543Smrg	    <blockquote><para>
2679706f2543Smrg      This allocates an entity record entity and initialise the data
2680706f2543Smrg      structures.  The return value is the index of the newly allocated
2681706f2543Smrg      entity record.
2682706f2543Smrg	      </para>
2683706f2543Smrg
2684706f2543Smrg	    </blockquote></para></blockquote>
2685706f2543Smrg
2686706f2543Smrg	<blockquote><para>
2687706f2543Smrg	    <programlisting>
2688706f2543Smrg    Bool xf86IsPrimaryIsa(void);
2689706f2543Smrg	    </programlisting>
2690706f2543Smrg	    <blockquote><para>
2691706f2543Smrg      This function returns <constant>TRUE</constant> if the primary card is
2692706f2543Smrg      an ISA (non-PCI) device, and <constant>FALSE</constant> otherwise.
2693706f2543Smrg	      </para>
2694706f2543Smrg
2695706f2543Smrg	    </blockquote></para></blockquote>
2696706f2543Smrg
2697706f2543Smrg	<para>
2698706f2543SmrgTwo helper functions are provided to aid configuring entities:
2699706f2543Smrg	</para>
2700706f2543Smrg
2701706f2543Smrg	<blockquote><para>
2702706f2543Smrg	    <programlisting>
2703706f2543Smrg    ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn,
2704706f2543Smrg                                    int scrnFlag, int entityIndex,
2705706f2543Smrg                                    PciChipsets *p_chip,
2706706f2543Smrg                                    resList res, EntityProc init,
2707706f2543Smrg                                    EntityProc enter, EntityProc leave,
2708706f2543Smrg                                    pointer private);
2709706f2543Smrg
2710706f2543Smrg    ScrnInfoPtr xf86ConfigIsaEntity(ScrnInfoPtr pScrn,
2711706f2543Smrg                                    int scrnFlag, int entityIndex,
2712706f2543Smrg                                    IsaChipsets *i_chip,
2713706f2543Smrg                                    resList res, EntityProc init,
2714706f2543Smrg                                    EntityProc enter, EntityProc leave,
2715706f2543Smrg                                    pointer private);
2716706f2543Smrg	    </programlisting>
2717706f2543Smrg	    <blockquote><para>
2718706f2543Smrg      These functions are used to register the non-relocatable resources
2719706f2543Smrg      for an entity, and the optional entity-specific <parameter>Init</parameter>, <parameter>Enter</parameter> and
2720706f2543Smrg      <parameter>Leave</parameter> functions.  Usually the list of fixed resources is obtained
2721706f2543Smrg      from the Isa/PciChipsets lists.  However an additional list of
2722706f2543Smrg      resources may be passed.  Generally this is not required.
2723706f2543Smrg      For active entities a <structname>ScrnInfoRec</structname> is allocated
2724706f2543Smrg      if the <parameter>pScrn</parameter> argument is <constant>NULL</constant>.
2725706f2543SmrgThe
2726706f2543Smrg      return value is <constant>TRUE</constant> when successful.  The init, enter, leave
2727706f2543Smrg      functions are defined as follows:
2728706f2543Smrg
2729706f2543Smrg		<blockquote><para>
2730706f2543Smrg		    <programlisting>
2731706f2543Smrg        typedef void (*EntityProc)(int entityIndex,
2732706f2543Smrg                                   pointer private);
2733706f2543Smrg		    </programlisting>
2734706f2543Smrg		  </para></blockquote>
2735706f2543Smrg
2736706f2543Smrg      They are passed the entity index and a pointer to a private scratch
2737706f2543Smrg      area.  This can be set up during <function>Probe()</function> and
2738706f2543Smrg      its address can be passed to
2739706f2543Smrg      <function>xf86ConfigIsaEntity()</function> and
2740706f2543Smrg      <function>xf86ConfigPciEntity()</function> as the last argument.
2741706f2543Smrg	      </para>
2742706f2543Smrg
2743706f2543Smrg	    </blockquote></para></blockquote>
2744706f2543Smrg
2745706f2543Smrg	<para>
2746706f2543SmrgThese two helper functions make use of several core functions that are
2747706f2543Smrgavailable at the driver level:
2748706f2543Smrg
2749706f2543Smrg	  <blockquote><para>
2750706f2543Smrg	      <programlisting>
2751706f2543Smrg    void xf86ClaimFixedResources(resList list, int entityIndex);
2752706f2543Smrg	      </programlisting>
2753706f2543Smrg	      <blockquote><para>
2754706f2543Smrg      This function registers the non-relocatable resources which cannot
2755706f2543Smrg      be disabled and which therefore would cause the server to fail
2756706f2543Smrg      immediately if they were found to conflict.  It also records
2757706f2543Smrg      non-relocatable but sharable resources for processing after the
2758706f2543Smrg      <function>Probe()</function> phase.
2759706f2543Smrg		</para>
2760706f2543Smrg
2761706f2543Smrg	      </blockquote></para></blockquote>
2762706f2543Smrg
2763706f2543Smrg	  <blockquote><para>
2764706f2543Smrg	      <programlisting>
2765706f2543Smrg    Bool xf86SetEntityFuncs(int entityIndex, EntityProc init,
2766706f2543Smrg                            EntityProc enter, EntityProc leave, pointer);
2767706f2543Smrg	      </programlisting>
2768706f2543Smrg	      <blockquote><para>
2769706f2543Smrg      This function registers with an entity the <parameter>init</parameter>,
2770706f2543Smrg      <parameter>enter</parameter>, <parameter>leave</parameter> functions along
2771706f2543Smrg      with the pointer to their private area.
2772706f2543Smrg		</para>
2773706f2543Smrg
2774706f2543Smrg	    </blockquote></para></blockquote>
2775706f2543Smrg
2776706f2543Smrg	  <blockquote><para>
2777706f2543Smrg	      <programlisting>
2778706f2543Smrg    void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex);
2779706f2543Smrg	      </programlisting>
2780706f2543Smrg	      <blockquote><para>
2781706f2543Smrg      This function associates the entity referenced by
2782706f2543Smrg      <parameter>entityIndex</parameter> with the screen.
2783706f2543Smrg		</para>
2784706f2543Smrg
2785706f2543Smrg	      </blockquote></para></blockquote>
2786706f2543Smrg	</para>
2787706f2543Smrg      </sect3>
2788706f2543Smrg
2789706f2543Smrg      <sect3>
2790706f2543Smrg	<title>PreInit Phase</title>
2791706f2543Smrg
2792706f2543Smrg	<para>
2793706f2543SmrgDuring this phase the remaining resources should be registered.
2794706f2543Smrg<function>PreInit()</function> should call <function>xf86GetEntityInfo()</function>
2795706f2543Smrgto obtain a pointer to an <structname>EntityInfoRec</structname> for each entity
2796706f2543Smrgit is able to drive and check if any resource are listed in its
2797706f2543Smrg<structfield>resources</structfield> field.  If resources registered in the Probe
2798706f2543Smrgphase have been rejected in the post-Probe phase
2799706f2543Smrg(<structfield>resources</structfield> is non-<constant>NULL</constant>), then the driver should
2800706f2543Smrgdecide if it can continue without using these or if it should fail.
2801706f2543Smrg	</para>
2802706f2543Smrg
2803706f2543Smrg	<blockquote><para>
2804706f2543Smrg	    <programlisting>
2805706f2543Smrg    EntityInfoPtr xf86GetEntityInfo(int entityIndex);
2806706f2543Smrg	    </programlisting>
2807706f2543Smrg	    <blockquote><para>
2808706f2543Smrg      This function returns a pointer to the <structname>EntityInfoRec</structname>
2809706f2543Smrg      referenced by <parameter>entityIndex</parameter>.  The returned
2810706f2543Smrg      <structname>EntityInfoRec</structname> should be freed with
2811706f2543Smrg      <function>xfree()</function> when no longer needed.
2812706f2543Smrg	      </para>
2813706f2543Smrg
2814706f2543Smrg	    </blockquote></para></blockquote>
2815706f2543Smrg
2816706f2543Smrg	<para>
2817706f2543SmrgSeveral functions are provided to simplify resource registration:
2818706f2543Smrg	  <blockquote><para>
2819706f2543Smrg	      <programlisting>
2820706f2543Smrg    Bool xf86IsEntityPrimary(int entityIndex);
2821706f2543Smrg	      </programlisting>
2822706f2543Smrg	      <blockquote><para>
2823706f2543Smrg      This function returns <constant>TRUE</constant> if the entity referenced
2824706f2543Smrg      by <parameter>entityIndex</parameter> is the primary display device (i.e.,
2825706f2543Smrg      the one initialised at boot time and used in text mode).
2826706f2543Smrg		</para>
2827706f2543Smrg
2828706f2543Smrg	      </blockquote></para></blockquote>
2829706f2543Smrg
2830706f2543Smrg	  <blockquote><para>
2831706f2543Smrg	      <programlisting>
2832706f2543Smrg    Bool xf86IsScreenPrimary(int scrnIndex);
2833706f2543Smrg	      </programlisting>
2834706f2543Smrg	      <blockquote><para>
2835706f2543Smrg      This function returns <constant>TRUE</constant> if the primary entity
2836706f2543Smrg      is registered with the screen referenced by
2837706f2543Smrg      <parameter>scrnIndex</parameter>.
2838706f2543Smrg		</para>
2839706f2543Smrg
2840706f2543Smrg	      </blockquote></para></blockquote>
2841706f2543Smrg
2842706f2543Smrg	  <blockquote><para>
2843706f2543Smrg	      <programlisting>
2844706f2543Smrg    pciVideoPtr xf86GetPciInfoForEntity(int entityIndex);
2845706f2543Smrg	      </programlisting>
2846706f2543Smrg	      <blockquote><para>
2847706f2543Smrg      This function returns a pointer to the <structname>pciVideoRec</structname>
2848706f2543Smrg      for the specified entity.  If the entity is not a PCI device,
2849706f2543Smrg      <constant>NULL</constant> is returned.
2850706f2543Smrg		</para>
2851706f2543Smrg
2852706f2543Smrg	      </blockquote></para></blockquote>
2853706f2543Smrg	</para>
2854706f2543Smrg
2855706f2543Smrg	<para>
2856706f2543SmrgThe primary function for registration of resources is:
2857706f2543Smrg	  <blockquote><para>
2858706f2543Smrg	      <programlisting>
2859706f2543Smrg    resPtr xf86RegisterResources(int entityIndex, resList list,
2860706f2543Smrg                                 int access);
2861706f2543Smrg	      </programlisting>
2862706f2543Smrg	      <blockquote><para>
2863706f2543Smrg      This function tries to register the resources in
2864706f2543Smrg      <parameter>list</parameter>.  If list is <constant>NULL</constant> it tries
2865706f2543Smrg      to determine the resources automatically.  This only works for
2866706f2543Smrg      entities that provide a generic way to read out the resource ranges
2867706f2543Smrg      they decode.  So far this is only the case for PCI devices.  By
2868706f2543Smrg      default the PCI resources are registered as shared
2869706f2543Smrg      (<constant>ResShared</constant>) if the driver wants to set a different
2870706f2543Smrg      access type it can do so by specifying the access flags in the
2871706f2543Smrg      third argument.  A value of <constant>0</constant> means to use the
2872706f2543Smrg      default settings.  If for any reason the resource broker is not
2873706f2543Smrg      able to register some of the requested resources the function will
2874706f2543Smrg      return a pointer to a list of the failed ones.  In this case the
2875706f2543Smrg      driver may be able to move the resource to different locations.
2876706f2543Smrg      In case of PCI bus entities this is done by passing the list of
2877706f2543Smrg      failed resources to <function>xf86ReallocatePciResources()</function>.
2878706f2543Smrg      When the registration succeeds, the return value is
2879706f2543Smrg      <constant>NULL</constant>.
2880706f2543Smrg		</para>
2881706f2543Smrg
2882706f2543Smrg	      </blockquote></para></blockquote>
2883706f2543Smrg	  </para>
2884706f2543Smrg
2885706f2543Smrg	<blockquote><para>
2886706f2543Smrg	    <programlisting>
2887706f2543Smrg    resPtr xf86ReallocatePciResources(int entityIndex, resPtr pRes);
2888706f2543Smrg	    </programlisting>
2889706f2543Smrg	    <blockquote><para>
2890706f2543Smrg      This function takes a list of PCI resources that need to be
2891706f2543Smrg      reallocated and returns <constant>NULL</constant> when all relocations are
2892706f2543Smrg      successful.
2893706f2543Smrg      <function>xf86RegisterResources()</function> should be called again to
2894706f2543Smrg      register the relocated resources with the broker.
2895706f2543Smrg      If the reallocation fails, a list of the resources that could not be
2896706f2543Smrg      relocated is returned.
2897706f2543Smrg	      </para>
2898706f2543Smrg
2899706f2543Smrg	    </blockquote></para></blockquote>
2900706f2543Smrg
2901706f2543Smrg<para>
2902706f2543SmrgTwo functions are provided to obtain a resource range of a given type:
2903706f2543Smrg	  <blockquote><para>
2904706f2543Smrg	      <programlisting>
2905706f2543Smrg    resRange xf86GetBlock(long type, memType size,
2906706f2543Smrg                          memType window_start, memType window_end,
2907706f2543Smrg                          memType align_mask, resPtr avoid);
2908706f2543Smrg	      </programlisting>
2909706f2543Smrg	      <blockquote><para>
2910706f2543Smrg      This function tries to find a block range of size
2911706f2543Smrg      <parameter>size</parameter> and type <parameter>type</parameter> in a window
2912706f2543Smrg      bound by <parameter>window_start</parameter> and <parameter>window_end</parameter>
2913706f2543Smrg      with the alignment specified in <parameter>align_mask</parameter>.
2914706f2543Smrg      Optionally a list of resource ranges which should be avoided within
2915706f2543Smrg      the window can be supplied.  On failure a zero-length range of
2916706f2543Smrg      type <constant>ResEnd</constant> will be returned.
2917706f2543Smrg		</para>
2918706f2543Smrg	      </blockquote></para></blockquote>
2919706f2543Smrg
2920706f2543Smrg	  <blockquote><para>
2921706f2543Smrg	      <programlisting>
2922706f2543Smrg    resRange xf86GetSparse(long type, memType fixed_bits,
2923706f2543Smrg                           memType decode_mask, memType address_mask,
2924706f2543Smrg                           resPtr avoid);
2925706f2543Smrg	      </programlisting>
2926706f2543Smrg	      <blockquote><para>
2927706f2543Smrg      This function is like the previous one, but attempts to find a
2928706f2543Smrg      sparse range instead of a block range.  Here three values have to
2929706f2543Smrg      be specified: the <parameter>address_mask</parameter> which marks all
2930706f2543Smrg      bits of the mask part of the address, the <parameter>decode_mask</parameter>
2931706f2543Smrg      which masks out the bits which are hardcoded and are therefore
2932706f2543Smrg      not available for relocation and the values of the fixed bits.
2933706f2543Smrg      The function tries to find a base that satisfies the given condition.
2934706f2543Smrg      If the function fails it will return a zero range of type
2935706f2543Smrg      <constant>ResEnd</constant>.  Optionally it might be passed a list of
2936706f2543Smrg      resource ranges to avoid.
2937706f2543Smrg		</para>
2938706f2543Smrg
2939706f2543Smrg	      </blockquote></para></blockquote>
2940706f2543Smrg	</para>
2941706f2543Smrg
2942706f2543Smrg	<para>
2943706f2543SmrgSome PCI devices are broken in the sense that they return invalid size
2944706f2543Smrginformation for a certain resource.  In this case the driver can supply
2945706f2543Smrgthe correct size and make sure that the resource range allocated for
2946706f2543Smrgthe card is large enough to hold the address range decoded by the card.
2947706f2543SmrgThe function <function>xf86FixPciResource()</function> can be used to do this:
2948706f2543Smrg	  <blockquote><para>
2949706f2543Smrg	      <programlisting>
2950706f2543Smrg    Bool xf86FixPciResource(int entityIndex, unsigned int prt,
2951706f2543Smrg                            CARD32 alignment, long type);
2952706f2543Smrg	      </programlisting>
2953706f2543Smrg	      <blockquote><para>
2954706f2543Smrg      This function fixes a PCI resource allocation.  The
2955706f2543Smrg      <parameter>prt</parameter> parameter contains the number of the PCI base
2956706f2543Smrg      register that needs to be fixed (<constant>0-5</constant>, and
2957706f2543Smrg      <constant>6</constant> for the BIOS base register).  The size is
2958706f2543Smrg      specified by the alignment.  Since PCI resources need to span an
2959706f2543Smrg      integral range of size <literal remap="tt">2&circ;n</literal>, the alignm      ent also
2960706f2543Smrg      specifies the number of addresses that will be decoded.  If the
2961706f2543Smrg      driver specifies a type mask it can override the default type for
2962706f2543Smrg      PCI resources which is <constant>ResShared</constant>.  The resource
2963706f2543Smrg      broker needs to know that to find a matching resource range.  This
2964706f2543Smrg      function should be called before calling
2965706f2543Smrg      <function>xf86RegisterResources()</function>.  The return value is
2966706f2543Smrg      <constant>TRUE</constant> when the function succeeds.
2967706f2543Smrg		</para>
2968706f2543Smrg
2969706f2543Smrg	      </blockquote></para></blockquote>
2970706f2543Smrg
2971706f2543Smrg	  <blockquote><para>
2972706f2543Smrg	      <programlisting>
2973706f2543Smrg    Bool xf86CheckPciMemBase(pciVideoPtr pPci, memType base);
2974706f2543Smrg	      </programlisting>
2975706f2543Smrg	      <blockquote><para>
2976706f2543Smrg      This function checks that the memory base address specified matches
2977706f2543Smrg      one of the PCI base address register values for the given PCI
2978706f2543Smrg      device.  This is mostly used to check that an externally provided
2979706f2543Smrg      base address (e.g., from a config file) matches an actual value
2980706f2543Smrg      allocated to a device.
2981706f2543Smrg		</para>
2982706f2543Smrg
2983706f2543Smrg	      </blockquote></para></blockquote>
2984706f2543Smrg	</para>
2985706f2543Smrg
2986706f2543Smrg	<para>
2987706f2543SmrgThe driver may replace the generic access control functions for an entity.
2988706f2543SmrgThis is done with the <function>xf86SetAccessFuncs()</function>:
2989706f2543Smrg	  <blockquote><para>
2990706f2543Smrg	      <programlisting>
2991706f2543Smrg    void xf86SetAccessFuncs(EntityInfoPtr pEnt,
2992706f2543Smrg                            xf86SetAccessFuncPtr funcs,
2993706f2543Smrg                            xf86SetAccessFuncPtr oldFuncs);
2994706f2543Smrg	      </programlisting>
2995706f2543Smrg     with:
2996706f2543Smrg	      <programlisting>
2997706f2543Smrg      typedef struct {
2998706f2543Smrg          xf86AccessPtr mem;
2999706f2543Smrg          xf86AccessPtr io;
3000706f2543Smrg          xf86AccessPtr io_mem;
3001706f2543Smrg      } xf86SetAccessFuncRec, *xf86SetAccessFuncPtr;
3002706f2543Smrg	      </programlisting>
3003706f2543Smrg	      <blockquote><para>
3004706f2543Smrg      The driver can pass three functions: one for I/O access, one for
3005706f2543Smrg      memory access and one for combined memory and I/O access.  If the
3006706f2543Smrg      memory access and combined access functions are identical the
3007706f2543Smrg      common level assumes that the memory access cannot be controlled
3008706f2543Smrg      independently of I/O access, if the I/O access function and the
3009706f2543Smrg      combined access functions are the same it is assumed that I/O can
3010706f2543Smrg      not be controlled independently.  If memory and I/O have to be
3011706f2543Smrg      controlled together all three values should be the same.  If a
3012706f2543Smrg      non <constant>NULL</constant> value is passed as third argument it is
3013706f2543Smrg      interpreted as an address where to store the old access record.
3014706f2543Smrg      If the third argument is <constant>NULL</constant> it will be assumed
3015706f2543Smrg      that the generic access should be enabled before replacing the
3016706f2543Smrg      access functions.  Otherwise it will be disabled.  The driver may
3017706f2543Smrg      enable them itself using the returned values.  It should do this
3018706f2543Smrg      from its replacement access functions as the generic access may
3019706f2543Smrg      be disabled by the common level on certain occasions.  If replacement
3020706f2543Smrg      functions are specified they must control all resources of the
3021706f2543Smrg      specific type registered for the entity.
3022706f2543Smrg		</para>
3023706f2543Smrg
3024706f2543Smrg	      </blockquote></para></blockquote>
3025706f2543Smrg	</para>
3026706f2543Smrg
3027706f2543Smrg	<para>
3028706f2543SmrgTo find out if a specific resource range conflicts with another
3029706f2543Smrgresource the <function>xf86ChkConflict()</function> function may be used:
3030706f2543Smrg	  <blockquote><para>
3031706f2543Smrg	      <programlisting>
3032706f2543Smrg    memType xf86ChkConflict(resRange *rgp, int entityIndex);
3033706f2543Smrg	      </programlisting>
3034706f2543Smrg	      <blockquote><para>
3035706f2543Smrg      This function checks if the resource range <parameter>rgp</parameter> of
3036706f2543Smrg      for the specified entity conflicts with with another resource.
3037706f2543Smrg      If a conflict is found, the address of the start of the conflict
3038706f2543Smrg      is returned.  The return value is zero when there is no conflict.
3039706f2543Smrg		</para>
3040706f2543Smrg
3041706f2543Smrg	      </blockquote></para></blockquote>
3042706f2543Smrg	</para>
3043706f2543Smrg
3044706f2543Smrg	<para>
3045706f2543SmrgThe OPERATING state properties of previously registered fixed resources
3046706f2543Smrgcan be set with the <function>xf86SetOperatingState()</function> function:
3047706f2543Smrg	  <blockquote><para>
3048706f2543Smrg	      <programlisting>
3049706f2543Smrg    resPtr xf86SetOperatingState(resList list, int entityIndex,
3050706f2543Smrg                                 int mask);
3051706f2543Smrg	      </programlisting>
3052706f2543Smrg	      <blockquote><para>
3053706f2543Smrg      This function is used to set the status of a resource during
3054706f2543Smrg      OPERATING state.  <parameter>list</parameter> holds a list to which
3055706f2543Smrg      <parameter>mask</parameter> is to be applied.  The parameter
3056706f2543Smrg      <parameter>mask</parameter> may have the value <constant>ResUnusedOpr</constant>
3057706f2543Smrg      and <constant>ResDisableOpr</constant>.  The first one should be used
3058706f2543Smrg      if a resource isn't used by the driver during OPERATING state
3059706f2543Smrg      although it is decoded by the device, while the latter one indicates
3060706f2543Smrg      that the resource is not decoded during OPERATING state.  Note
3061706f2543Smrg      that the resource ranges have to match those specified during
3062706f2543Smrg      registration.  If a range has been specified starting at
3063706f2543Smrg      <literal remap="tt">A</literal> and ending at <literal remap="tt">B</literal> and suppose
3064706f2543Smrg      <literal remap="tt">C</literal> us a value satisfying
3065706f2543Smrg      <literal remap="tt">A&nbsp;&lt;&nbsp;C&nbsp;&lt;&nbsp;B</literal> one may not
3066706f2543Smrg      specify the resource range <literal remap="tt">(A,B)</literal> by splitting it
3067706f2543Smrg      into two ranges <literal remap="tt">(A,C)</literal> and <literal remap="tt">(C,B)</literal>.
3068706f2543Smrg		</para>
3069706f2543Smrg
3070706f2543Smrg	      </blockquote></para></blockquote>
3071706f2543Smrg	</para>
3072706f2543Smrg
3073706f2543Smrg	<para>
3074706f2543SmrgThe following two functions are provided for special cases:
3075706f2543Smrg	  <blockquote><para>
3076706f2543Smrg	      <programlisting>
3077706f2543Smrg    void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex);
3078706f2543Smrg	      </programlisting>
3079706f2543Smrg	      <blockquote><para>
3080706f2543Smrg      This function may be used to remove an entity from a screen.  This
3081706f2543Smrg      only makes sense if a screen has more than one entity assigned or
3082706f2543Smrg      the screen is to be deleted.  No test is made if the screen has
3083706f2543Smrg      any entities left.
3084706f2543Smrg		</para>
3085706f2543Smrg
3086706f2543Smrg	      </blockquote></para></blockquote>
3087706f2543Smrg
3088706f2543Smrg	  <blockquote><para>
3089706f2543Smrg	      <programlisting>
3090706f2543Smrg    void xf86DeallocateResourcesForEntity(int entityIndex, long type);
3091706f2543Smrg	      </programlisting>
3092706f2543Smrg	      <blockquote><para>
3093706f2543Smrg      This function deallocates all resources of a given type registered
3094706f2543Smrg      for a certain entity from the resource broker list.
3095706f2543Smrg		</para>
3096706f2543Smrg
3097706f2543Smrg	      </blockquote></para></blockquote>
3098706f2543Smrg	</para>
3099706f2543Smrg
3100706f2543Smrg      </sect3>
3101706f2543Smrg
3102706f2543Smrg      <sect3>
3103706f2543Smrg	<title>ScreenInit Phase</title>
3104706f2543Smrg
3105706f2543Smrg	<para>
3106706f2543SmrgAll that is required in this phase is to setup the RAC flags.  Note that
3107706f2543Smrgit is also permissible to set these flags up in the PreInit phase.  The
3108706f2543SmrgRAC flags are held in the <structfield>racIoFlags</structfield> and <structfield>racMemFlags</structfield> fields of the
3109706f2543Smrg<structname>ScrnInfoRec</structname> for each screen.  They specify which graphics operations
3110706f2543Smrgmight require the use of shared resources.  This can be specified
3111706f2543Smrgseparately for memory and I/O resources.  The available flags are defined
3112706f2543Smrgin <filename>rac/xf86RAC.h</filename>.  They are:
3113706f2543Smrg
3114706f2543Smrg	  <variablelist>
3115706f2543Smrg	    <varlistentry><term><constant>RAC_FB</constant></term>
3116706f2543Smrg	      <listitem><para>
3117706f2543Smrg	for framebuffer operations (including hw acceleration)
3118706f2543Smrg		</para></listitem></varlistentry>
3119706f2543Smrg	    <varlistentry><term><constant>RAC_CURSOR</constant></term>
3120706f2543Smrg	      <listitem><para>
3121706f2543Smrg	for Cursor operations
3122706f2543Smrg        (??? I'm not sure if we need this for SW cursor it depends
3123706f2543Smrg         on which level the sw cursor is drawn)
3124706f2543Smrg		</para></listitem></varlistentry>
3125706f2543Smrg	    <varlistentry><term><constant>RAC_COLORMAP</constant></term>
3126706f2543Smrg	      <listitem><para>
3127706f2543Smrg	for colormap operations
3128706f2543Smrg		</para></listitem></varlistentry>
3129706f2543Smrg	    <varlistentry><term><constant>RAC_VIEWPORT</constant></term>
3130706f2543Smrg	      <listitem><para>
3131706f2543Smrg	for the call to <function>ChipAdjustFrame()</function>
3132706f2543Smrg		</para></listitem></varlistentry>
3133706f2543Smrg	    </variablelist>
3134706f2543Smrg
3135706f2543Smrg
3136706f2543SmrgThe flags are ORed together.
3137706f2543Smrg	</para>
3138706f2543Smrg      </sect3>
3139706f2543Smrg    </sect2>
3140706f2543Smrg  </sect1>
3141706f2543Smrg
3142706f2543Smrg  <sect1 id="options">
3143706f2543Smrg    <title>Config file <quote>Option</quote> entries</title>
3144706f2543Smrg
3145706f2543Smrg    <para>
3146706f2543SmrgOption entries are permitted in most sections and subsections of the
3147706f2543Smrgconfig file.  There are two forms of option entries:
3148706f2543Smrg
3149706f2543Smrg      <variablelist>
3150706f2543Smrg	<varlistentry><term>Option "option-name"</term>
3151706f2543Smrg	  <listitem><para>
3152706f2543Smrg	A boolean option.
3153706f2543Smrg	    </para></listitem></varlistentry>
3154706f2543Smrg	<varlistentry><term>Option "option-name" "option-value"</term>
3155706f2543Smrg	  <listitem><para>
3156706f2543Smrg	An option with an arbitrary value.
3157706f2543Smrg	    </para></listitem></varlistentry>
3158706f2543Smrg      </variablelist>
3159706f2543Smrg    </para>
3160706f2543Smrg
3161706f2543Smrg    <para>
3162706f2543SmrgThe option entries are handled by the parser, and a list of the parsed
3163706f2543Smrgoptions is included with each of the appropriate data structures that
3164706f2543Smrgthe drivers have access to.  The data structures used to hold the option
3165706f2543Smrginformation are opaque to the driver, and a driver must not access the
3166706f2543Smrgoption data directly.  Instead, the common layer provides a set of
3167706f2543Smrgfunctions that may be used to access, check and manipulate the option
3168706f2543Smrgdata.
3169706f2543Smrg    </para>
3170706f2543Smrg
3171706f2543Smrg    <para>
3172706f2543SmrgFirst, the low level option handling functions.  In most cases drivers
3173706f2543Smrgwould not need to use these directly.
3174706f2543Smrg    </para>
3175706f2543Smrg
3176706f2543Smrg    <blockquote><para>
3177706f2543Smrg	<programlisting>
3178706f2543Smrg    pointer xf86FindOption(pointer options, const char *name);
3179706f2543Smrg	</programlisting>
3180706f2543Smrg	<blockquote><para>
3181706f2543Smrg      Takes a list of options and an option name, and returns a handle
3182706f2543Smrg      for the first option entry in the list matching the name.  Returns
3183706f2543Smrg      <constant>NULL</constant> if no match is found.
3184706f2543Smrg	  </para>
3185706f2543Smrg
3186706f2543Smrg	</blockquote></para></blockquote>
3187706f2543Smrg
3188706f2543Smrg    <blockquote><para>
3189706f2543Smrg	<programlisting>
3190706f2543Smrg    char *xf86FindOptionValue(pointer options, const char *name);
3191706f2543Smrg	</programlisting>
3192706f2543Smrg	<blockquote><para>
3193706f2543Smrg      Takes a list of options and an option name, and returns the value
3194706f2543Smrg      associated with the first option entry in the list matching the
3195706f2543Smrg      name.  If the matching option has no value, an empty string
3196706f2543Smrg      (<constant>""</constant>) is returned.  Returns <constant>NULL</constant>
3197706f2543Smrg      if no match is found.
3198706f2543Smrg	  </para>
3199706f2543Smrg
3200706f2543Smrg	</blockquote></para></blockquote>
3201706f2543Smrg
3202706f2543Smrg    <blockquote><para>
3203706f2543Smrg	<programlisting>
3204706f2543Smrg    void xf86MarkOptionUsed(pointer option);
3205706f2543Smrg	</programlisting>
3206706f2543Smrg	<blockquote><para>
3207706f2543Smrg      Takes a handle for an option, and marks that option as used.
3208706f2543Smrg	  </para>
3209706f2543Smrg
3210706f2543Smrg	</blockquote></para></blockquote>
3211706f2543Smrg
3212706f2543Smrg    <blockquote><para>
3213706f2543Smrg	<programlisting>
3214706f2543Smrg    void xf86MarkOptionUsedByName(pointer options, const char *name);
3215706f2543Smrg	</programlisting>
3216706f2543Smrg	<blockquote><para>
3217706f2543Smrg      Takes a list of options and an option name and marks the first
3218706f2543Smrg      option entry in the list matching the name as used.
3219706f2543Smrg	  </para>
3220706f2543Smrg
3221706f2543Smrg	</blockquote></para></blockquote>
3222706f2543Smrg
3223706f2543Smrg    <para>
3224706f2543SmrgNext, the higher level functions that most drivers would use.
3225706f2543Smrg    </para>
3226706f2543Smrg    <blockquote><para>
3227706f2543Smrg	<programlisting>
3228706f2543Smrg    void xf86CollectOptions(ScrnInfoPtr pScrn, pointer extraOpts);
3229706f2543Smrg	</programlisting>
3230706f2543Smrg	<blockquote><para>
3231706f2543Smrg      Collect the options from each of the config file sections used by
3232706f2543Smrg      the screen (<parameter>pScrn</parameter>) and return the merged list as
3233706f2543Smrg      <structfield>pScrn-&gt;options</structfield>.  This function requires that
3234706f2543Smrg      <structfield>pScrn-&gt;confScreen</structfield>, <structfield>pScrn-&gt;display</structfield>,
3235706f2543Smrg      <structfield>pScrn-&gt;monitor</structfield>,
3236706f2543Smrg      <structfield>pScrn-&gt;numEntities</structfield>, and
3237706f2543Smrg      <structfield>pScrn-&gt;entityList</structfield> are initialised.
3238706f2543Smrg      <parameter>extraOpts</parameter> may optionally be set to an additional
3239706f2543Smrg      list of options to be combined with the others.  The order of
3240706f2543Smrg      precedence for options is <parameter>extraOpts</parameter>, display,
3241706f2543Smrg      confScreen, monitor, device.
3242706f2543Smrg	  </para>
3243706f2543Smrg
3244706f2543Smrg	</blockquote></para></blockquote>
3245706f2543Smrg
3246706f2543Smrg    <blockquote><para>
3247706f2543Smrg	<programlisting>
3248706f2543Smrg    void xf86ProcessOptions(int scrnIndex, pointer options,
3249706f2543Smrg                            OptionInfoPtr optinfo);
3250706f2543Smrg	</programlisting>
3251706f2543Smrg	<blockquote><para>
3252706f2543Smrg      Processes a list of options according to the information in the
3253706f2543Smrg      array of <structname>OptionInfoRecs</structname> (<parameter>optinfo</parameter>).
3254706f2543Smrg      The resulting information is stored in the <structfield>value</structfield>
3255706f2543Smrg      fields of the appropriate <parameter>optinfo</parameter> entries.  The
3256706f2543Smrg      <structfield>found</structfield> fields are set to <constant>TRUE</constant>
3257706f2543Smrg      when an option with a value of the correct type if found, and
3258706f2543Smrg      <constant>FALSE</constant> otherwise.  The <structfield>type</structfield> field
3259706f2543Smrg      is used to determine the expected value type for each option.
3260706f2543Smrg      Each option in the list of options for which there is a name match
3261706f2543Smrg      (but not necessarily a value type match) is marked as used.
3262706f2543Smrg      Warning messages are printed when option values don't match the
3263706f2543Smrg      types specified in the optinfo data.
3264706f2543Smrg	  </para>
3265706f2543Smrg
3266706f2543Smrg	  <para>
3267706f2543Smrg      NOTE: If this function is called before a driver's screen number
3268706f2543Smrg      is known (e.g., from the <function>ChipProbe()</function> function) a
3269706f2543Smrg      <parameter>scrnIndex</parameter> value of <constant>-1</constant> should be
3270706f2543Smrg      used.
3271706f2543Smrg	  </para>
3272706f2543Smrg
3273706f2543Smrg	  <para>
3274706f2543Smrg      NOTE 2: Given that this function stores into the
3275706f2543Smrg      <literal remap="tt">OptionInfoRecs</literal> pointed to by <parameter>optinfo</parameter>,
3276706f2543Smrg      the caller should ensure the <literal remap="tt">OptionInfoRecs</literal> are
3277706f2543Smrg      (re-)initialised before the call, especially if the caller expects
3278706f2543Smrg      to use the predefined option values as defaults.
3279706f2543Smrg	  </para>
3280706f2543Smrg
3281706f2543Smrg	  <para>
3282706f2543Smrg      The <structname>OptionInfoRec</structname> is defined as follows:
3283706f2543Smrg
3284706f2543Smrg	    <programlisting>
3285706f2543Smrg      typedef struct {
3286706f2543Smrg          double freq;
3287706f2543Smrg          int units;
3288706f2543Smrg      } OptFrequency;
3289706f2543Smrg
3290706f2543Smrg      typedef union {
3291706f2543Smrg          unsigned long       num;
3292706f2543Smrg          char *              str;
3293706f2543Smrg          double              realnum;
3294706f2543Smrg          Bool                bool;
3295706f2543Smrg          OptFrequency        freq;
3296706f2543Smrg      } ValueUnion;
3297706f2543Smrg
3298706f2543Smrg      typedef enum {
3299706f2543Smrg          OPTV_NONE = 0,
3300706f2543Smrg          OPTV_INTEGER,
3301706f2543Smrg          OPTV_STRING,  /* a non-empty string */
3302706f2543Smrg          OPTV_ANYSTR,  /* Any string, including an empty one */
3303706f2543Smrg          OPTV_REAL,
3304706f2543Smrg          OPTV_BOOLEAN,
3305706f2543Smrg          OPTV_PERCENT,
3306706f2543Smrg          OPTV_FREQ
3307706f2543Smrg      } OptionValueType;
3308706f2543Smrg
3309706f2543Smrg      typedef enum {
3310706f2543Smrg          OPTUNITS_HZ = 1,
3311706f2543Smrg          OPTUNITS_KHZ,
3312706f2543Smrg          OPTUNITS_MHZ
3313706f2543Smrg      } OptFreqUnits;
3314706f2543Smrg
3315706f2543Smrg      typedef struct {
3316706f2543Smrg          int                 token;
3317706f2543Smrg          const char*         name;
3318706f2543Smrg          OptionValueType     type;
3319706f2543Smrg          ValueUnion          value;
3320706f2543Smrg          Bool                found;
3321706f2543Smrg      } OptionInfoRec, *OptionInfoPtr;
3322706f2543Smrg	    </programlisting>
3323706f2543Smrg	  </para>
3324706f2543Smrg	  <para>
3325706f2543Smrg      <constant>OPTV_FREQ</constant> can be used for options values that are
3326706f2543Smrg      frequencies.  These values are a floating point number with an
3327706f2543Smrg      optional unit name appended.  The unit name can be one of "Hz",
3328706f2543Smrg      "kHz", "k", "MHz", "M".  The multiplier associated with the unit
3329706f2543Smrg      is stored in <structfield>freq.units</structfield>, and the scaled frequency
3330706f2543Smrg      is stored in <structfield>freq.freq</structfield>.  When no unit is specified,
3331706f2543Smrg      <structfield>freq.units</structfield> is set to <constant>0</constant>, and
3332706f2543Smrg      <structfield>freq.freq</structfield> is unscaled.
3333706f2543Smrg	  </para>
3334706f2543Smrg
3335706f2543Smrg	  <para>
3336706f2543Smrg      <constant>OPTV_PERCENT</constant> can be used for option values that are
3337706f2543Smrg      specified in percent (e.g. "20%"). These values are a floating point
3338706f2543Smrg      number with a percent sign appended. If the percent sign is missing,
3339706f2543Smrg      the parser will fail to match the value.
3340706f2543Smrg	  </para>
3341706f2543Smrg
3342706f2543Smrg	  <para>
3343706f2543Smrg      Typical usage is to setup an array of
3344706f2543Smrg      <structname>OptionInfoRec</structname>s with all fields initialised.
3345706f2543Smrg      The <structfield>value</structfield> and <structfield>found</structfield> fields get
3346706f2543Smrg      set by <function>xf86ProcessOptions()</function>.  For cases where the
3347706f2543Smrg      value parsing is more complex, the driver should specify
3348706f2543Smrg      <constant>OPTV_STRING</constant>, and parse the string itself.  An
3349706f2543Smrg      example of using this option handling is included in the
3350706f2543Smrg      <link linkend="sample">Sample Driver</link> section.
3351706f2543Smrg	  </para>
3352706f2543Smrg
3353706f2543Smrg	</blockquote></para></blockquote>
3354706f2543Smrg
3355706f2543Smrg    <blockquote><para>
3356706f2543Smrg	<programlisting>
3357706f2543Smrg    void xf86ShowUnusedOptions(int scrnIndex, pointer options);
3358706f2543Smrg	</programlisting>
3359706f2543Smrg	<blockquote><para>
3360706f2543Smrg      Prints out warning messages for each option in the list of options
3361706f2543Smrg      that isn't marked as used.  This is intended to show options that
3362706f2543Smrg      the driver hasn't recognised.  It would normally be called near
3363706f2543Smrg      the end of the <function>ChipScreenInit()</function> function, but only
3364706f2543Smrg      when <code>serverGeneration&nbsp;==&nbsp;1</code>
3365706f2543Smrg	  </para>
3366706f2543Smrg	</blockquote></para></blockquote>
3367706f2543Smrg
3368706f2543Smrg    <blockquote><para>
3369706f2543Smrg	<programlisting>
3370706f2543Smrg    OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table,
3371706f2543Smrg                                     int token);
3372706f2543Smrg	</programlisting>
3373706f2543Smrg	<blockquote><para>
3374706f2543Smrg      Returns a pointer to the <structname>OptionInfoRec</structname> in
3375706f2543Smrg      <parameter>table</parameter> with a token field matching
3376706f2543Smrg      <parameter>token</parameter>.  Returns <constant>NULL</constant> if no match
3377706f2543Smrg      is found.
3378706f2543Smrg	  </para>
3379706f2543Smrg
3380706f2543Smrg	</blockquote></para></blockquote>
3381706f2543Smrg
3382706f2543Smrg    <blockquote><para>
3383706f2543Smrg	<programlisting>
3384706f2543Smrg    Bool xf86IsOptionSet(const OptionInfoRec *table, int token);
3385706f2543Smrg	</programlisting>
3386706f2543Smrg	<blockquote><para>
3387706f2543Smrg      Returns the <literal remap="tt">found</literal> field of the
3388706f2543Smrg      <structname>OptionInfoRec</structname> in <parameter>table</parameter> with a
3389706f2543Smrg      <structfield>token</structfield> field matching <parameter>token</parameter>.  This
3390706f2543Smrg      can be used for options of all types.  Note that for options of
3391706f2543Smrg      type <constant>OPTV_BOOLEAN</constant>, it isn't sufficient to check
3392706f2543Smrg      this to determine the value of the option.  Returns
3393706f2543Smrg      <constant>FALSE</constant> if no match is found.
3394706f2543Smrg	  </para>
3395706f2543Smrg
3396706f2543Smrg	</blockquote></para></blockquote>
3397706f2543Smrg
3398706f2543Smrg    <blockquote><para>
3399706f2543Smrg	<programlisting>
3400706f2543Smrg    char *xf86GetOptValString(const OptionInfoRec *table, int token);
3401706f2543Smrg	</programlisting>
3402706f2543Smrg	<blockquote><para>
3403706f2543Smrg      Returns the <structfield>value.str</structfield> field of the
3404706f2543Smrg      <structname>OptionInfoRec</structname> in <parameter>table</parameter> with a
3405706f2543Smrg      token field matching <parameter>token</parameter>.  Returns
3406706f2543Smrg      <constant>NULL</constant> if no match is found.
3407706f2543Smrg	  </para>
3408706f2543Smrg
3409706f2543Smrg	</blockquote></para></blockquote>
3410706f2543Smrg
3411706f2543Smrg	  <blockquote><para>
3412706f2543Smrg	      <programlisting>
3413706f2543Smrg    Bool xf86GetOptValInteger(const OptionInfoRec *table, int token,
3414706f2543Smrg
3415706f2543Smrg                                int *value);
3416706f2543Smrg	      </programlisting>
3417706f2543Smrg	      <blockquote><para>
3418706f2543Smrg      Returns via <parameter>*value</parameter> the <structfield>value.num</structfield>
3419706f2543Smrg      field of the <structname>OptionInfoRec</structname> in <parameter>table</parameter>
3420706f2543Smrg      with a <structfield>token</structfield> field matching <parameter>token</parameter>.
3421706f2543Smrg      <parameter>*value</parameter> is only changed when a match is found so
3422706f2543Smrg      it can be safely initialised with a default prior to calling this
3423706f2543Smrg      function.  The function return value is as for
3424706f2543Smrg      <function>xf86IsOptionSet()</function>.
3425706f2543Smrg	  </para>
3426706f2543Smrg
3427706f2543Smrg	</blockquote></para></blockquote>
3428706f2543Smrg
3429706f2543Smrg    <blockquote><para>
3430706f2543Smrg	<programlisting>
3431706f2543Smrg    Bool xf86GetOptValULong(const OptionInfoRec *table, int token,
3432706f2543Smrg                            unsigned long *value);
3433706f2543Smrg	</programlisting>
3434706f2543Smrg	<blockquote><para>
3435706f2543Smrg      Like <function>xf86GetOptValInteger()</function>, except the value is
3436706f2543Smrg      treated as an <type>unsigned long</type>.
3437706f2543Smrg	  </para>
3438706f2543Smrg
3439706f2543Smrg	</blockquote></para></blockquote>
3440706f2543Smrg
3441706f2543Smrg    <blockquote><para>
3442706f2543Smrg	<programlisting>
3443706f2543Smrg    Bool xf86GetOptValReal(const OptionInfoRec *table, int token,
3444706f2543Smrg                           double *value);
3445706f2543Smrg	</programlisting>
3446706f2543Smrg	<blockquote><para>
3447706f2543Smrg      Like <function>xf86GetOptValInteger()</function>, except that
3448706f2543Smrg      <structfield>value.realnum</structfield> is used.
3449706f2543Smrg	  </para>
3450706f2543Smrg
3451706f2543Smrg	</blockquote></para></blockquote>
3452706f2543Smrg
3453706f2543Smrg    <blockquote><para>
3454706f2543Smrg	<programlisting>
3455706f2543Smrg    Bool xf86GetOptValFreq(const OptionInfoRec *table, int token,
3456706f2543Smrg                           OptFreqUnits expectedUnits, double *value);
3457706f2543Smrg	</programlisting>
3458706f2543Smrg	<blockquote><para>
3459706f2543Smrg      Like <function>xf86GetOptValInteger()</function>, except that the
3460706f2543Smrg      <structfield>value.freq</structfield> data is returned.  The frequency value
3461706f2543Smrg      is scaled to the units indicated by <parameter>expectedUnits</parameter>.
3462706f2543Smrg      The scaling is exact when the units were specified explicitly in
3463706f2543Smrg      the option's value.  Otherwise, the <parameter>expectedUnits</parameter>
3464706f2543Smrg      field is used as a hint when doing the scaling.  In this case,
3465706f2543Smrg      values larger than <constant>1000</constant> are assumed to have be
3466706f2543Smrg      specified in the next smallest units.  For example, if the Option
3467706f2543Smrg      value is "10000" and expectedUnits is <constant>OPTUNITS_MHZ</constant>,
3468706f2543Smrg      the value returned is <constant>10</constant>.
3469706f2543Smrg	  </para>
3470706f2543Smrg
3471706f2543Smrg	</blockquote></para></blockquote>
3472706f2543Smrg
3473706f2543Smrg    <blockquote><para>
3474706f2543Smrg      <programlisting>
3475706f2543Smrg    Bool xf86GetOptValBool(const OptionInfoRec *table, int token, Bool *value);
3476706f2543Smrg      </programlisting>
3477706f2543Smrg	<blockquote><para>
3478706f2543Smrg      This function is used to check boolean options
3479706f2543Smrg      (<constant>OPTV_BOOLEAN</constant>).  If the function return value is
3480706f2543Smrg      <constant>FALSE</constant>, it means the option wasn't set.  Otherwise
3481706f2543Smrg      <parameter>*value</parameter> is set to the boolean value indicated by
3482706f2543Smrg      the option's value.  No option <parameter>value</parameter> is interpreted
3483706f2543Smrg      as <constant>TRUE</constant>.  Option values meaning <constant>TRUE</constant>
3484706f2543Smrg      are "1", "yes", "on", "true", and option values meaning
3485706f2543Smrg      <constant>FALSE</constant> are "0", "no", "off", "false".  Option names
3486706f2543Smrg      both with the "no" prefix in their names, and with that prefix
3487706f2543Smrg      removed are also checked and handled in the obvious way.
3488706f2543Smrg      <parameter>*value</parameter> is not changed when the option isn't present.
3489706f2543Smrg      It should normally be set to a default value before calling this
3490706f2543Smrg      function.
3491706f2543Smrg	  </para>
3492706f2543Smrg
3493706f2543Smrg	</blockquote></para></blockquote>
3494706f2543Smrg
3495706f2543Smrg    <blockquote><para>
3496706f2543Smrg	<programlisting>
3497706f2543Smrg    Bool xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def);
3498706f2543Smrg	</programlisting>
3499706f2543Smrg	<blockquote><para>
3500706f2543Smrg      This function is used to check boolean options
3501706f2543Smrg      (<constant>OPTV_BOOLEAN</constant>).  If the option is set, its value
3502706f2543Smrg      is returned.  If the options is not set, the default value specified
3503706f2543Smrg      by <parameter>def</parameter> is returned.  The option interpretation is
3504706f2543Smrg      the same as for <function>xf86GetOptValBool()</function>.
3505706f2543Smrg	  </para>
3506706f2543Smrg
3507706f2543Smrg	</blockquote></para></blockquote>
3508706f2543Smrg
3509706f2543Smrg    <blockquote><para>
3510706f2543Smrg	<programlisting>
3511706f2543Smrg    int xf86NameCmp(const char *s1, const char *s2);
3512706f2543Smrg	</programlisting>
3513706f2543Smrg	<blockquote><para>
3514706f2543Smrg      This function should be used when comparing strings from the config
3515706f2543Smrg      file with expected values.  It works like <function>strcmp()</function>,
3516706f2543Smrg      but is not case sensitive and space, tab, and <quote><literal>_</literal></quote> characters
3517706f2543Smrg      are ignored in the comparison.  The use of this function isn't
3518706f2543Smrg      restricted to parsing option values.  It may be used anywhere
3519706f2543Smrg      where this functionality required.
3520706f2543Smrg	  </para>
3521706f2543Smrg
3522706f2543Smrg	</blockquote></para></blockquote>
3523706f2543Smrg  </sect1>
3524706f2543Smrg
3525706f2543Smrg  <sect1>
3526706f2543Smrg    <title>Modules, Drivers, Include Files and Interface Issues</title>
3527706f2543Smrg
3528706f2543Smrg    <para>
3529706f2543SmrgNOTE: this section is incomplete.
3530706f2543Smrg    </para>
3531706f2543Smrg
3532706f2543Smrg
3533706f2543Smrg    <sect2>
3534706f2543Smrg      <title>Include files</title>
3535706f2543Smrg
3536706f2543Smrg      <para>
3537706f2543SmrgThe following include files are typically required by video drivers:
3538706f2543Smrg
3539706f2543Smrg	<blockquote><para>
3540706f2543Smrg  All drivers should include these:
3541706f2543Smrg	    <literallayout><filename>
3542706f2543Smrg    "xf86.h"
3543706f2543Smrg    "xf86_OSproc.h"
3544706f2543Smrg    "xf86_ansic.h"
3545706f2543Smrg    "xf86Resources.h"
3546706f2543Smrg	    </filename></literallayout>
3547706f2543Smrg  Wherever inb/outb (and related things) are used the following should be
3548706f2543Smrg  included:
3549706f2543Smrg	    <literallayout><filename>
3550706f2543Smrg    "compiler.h"
3551706f2543Smrg	      </filename></literallayout>
3552706f2543Smrg  Note: in drivers, this must be included after <filename>"xf86_ansic.h"</filename>.
3553706f2543Smrg	  </para>
3554706f2543Smrg
3555706f2543Smrg	  <para>
3556706f2543Smrg  Drivers that need to access PCI vendor/device definitions need this:
3557706f2543Smrg	    <literallayout><filename>
3558706f2543Smrg    "xf86PciInfo.h"
3559706f2543Smrg	      </filename></literallayout>
3560706f2543Smrg	  </para>
3561706f2543Smrg
3562706f2543Smrg	  <para>
3563706f2543Smrg  Drivers that need to access the PCI config space need this:
3564706f2543Smrg	    <literallayout><filename>
3565706f2543Smrg    "xf86Pci.h"
3566706f2543Smrg	      </filename></literallayout>
3567706f2543Smrg	  </para>
3568706f2543Smrg
3569706f2543Smrg	  <para>
3570706f2543Smrg  Drivers that initialise a SW cursor need this:
3571706f2543Smrg	    <literallayout><filename>
3572706f2543Smrg    "mipointer.h"
3573706f2543Smrg	      </filename></literallayout>
3574706f2543Smrg	  </para>
3575706f2543Smrg
3576706f2543Smrg	  <para>
3577706f2543Smrg  All drivers implementing backing store need this:
3578706f2543Smrg	    <literallayout><filename>
3579706f2543Smrg    "mibstore.h"
3580706f2543Smrg	      </filename></literallayout>
3581706f2543Smrg	  </para>
3582706f2543Smrg
3583706f2543Smrg	  <para>
3584706f2543Smrg  All drivers using the mi colourmap code need this:
3585706f2543Smrg	    <literallayout><filename>
3586706f2543Smrg    "micmap.h"
3587706f2543Smrg	      </filename></literallayout>
3588706f2543Smrg	  </para>
3589706f2543Smrg
3590706f2543Smrg	  <para>
3591706f2543Smrg  If a driver uses the vgahw module, it needs this:
3592706f2543Smrg	    <literallayout><filename>
3593706f2543Smrg    "vgaHW.h"
3594706f2543Smrg	      </filename></literallayout>
3595706f2543Smrg	  </para>
3596706f2543Smrg
3597706f2543Smrg	  <para>
3598706f2543Smrg  Drivers supporting VGA or Hercules monochrome screens need:
3599706f2543Smrg	    <literallayout><filename>
3600706f2543Smrg    "xf1bpp.h"
3601706f2543Smrg	      </filename></literallayout>
3602706f2543Smrg	  </para>
3603706f2543Smrg
3604706f2543Smrg	  <para>
3605706f2543Smrg  Drivers supporting VGA or EGC 16-colour screens need:
3606706f2543Smrg	    <literallayout><filename>
3607706f2543Smrg    "xf4bpp.h"
3608706f2543Smrg	      </filename></literallayout>
3609706f2543Smrg	  </para>
3610706f2543Smrg
3611706f2543Smrg	  <para>
3612706f2543Smrg  Drivers using cfb need:
3613706f2543Smrg	    <programlisting>
3614706f2543Smrg    #define PSZ 8
3615706f2543Smrg    #include "cfb.h"
3616706f2543Smrg    #undef PSZ
3617706f2543Smrg	    </programlisting>
3618706f2543Smrg	  </para>
3619706f2543Smrg
3620706f2543Smrg	  <para>
3621706f2543Smrg  Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
3622706f2543Smrg	    <literallayout><filename>
3623706f2543Smrg    "cfb16.h"
3624706f2543Smrg    "cfb24.h"
3625706f2543Smrg    "cfb32.h"
3626706f2543Smrg	      </filename></literallayout>
3627706f2543Smrg	  </para>
3628706f2543Smrg
3629706f2543Smrg	  <para>
3630706f2543Smrg  If a driver uses XAA, it needs these:
3631706f2543Smrg	    <literallayout><filename>
3632706f2543Smrg    "xaa.h"
3633706f2543Smrg    "xaalocal.h"
3634706f2543Smrg	      </filename></literallayout>
3635706f2543Smrg	  </para>
3636706f2543Smrg
3637706f2543Smrg	  <para>
3638706f2543Smrg  If a driver uses the fb manager, it needs this:
3639706f2543Smrg	    <literallayout><filename>
3640706f2543Smrg    "xf86fbman.h"
3641706f2543Smrg	      </filename></literallayout>
3642706f2543Smrg	  </para>
3643706f2543Smrg	</blockquote>
3644706f2543Smrg      </para>
3645706f2543Smrg
3646706f2543Smrg      <para>
3647706f2543SmrgNon-driver modules should include <filename>"xf86_ansic.h"</filename> to get the correct
3648706f2543Smrgwrapping of ANSI C/libc functions.
3649706f2543Smrg      </para>
3650706f2543Smrg
3651706f2543Smrg      <para>
3652706f2543SmrgAll modules must NOT include any system include files, or the following:
3653706f2543Smrg
3654706f2543Smrg	<literallayout><filename>
3655706f2543Smrg    "xf86Priv.h"
3656706f2543Smrg    "xf86Privstr.h"
3657706f2543Smrg    "xf86_OSlib.h"
3658706f2543Smrg    "Xos.h"
3659706f2543Smrg	  </filename></literallayout>
3660706f2543Smrg      </para>
3661706f2543Smrg
3662706f2543Smrg      <para>
3663706f2543SmrgIn addition, "xf86_libc.h" must not be included explicitly.  It is
3664706f2543Smrgincluded implicitly by "xf86_ansic.h".
3665706f2543Smrg      </para>
3666706f2543Smrg
3667706f2543Smrg    </sect2>
3668706f2543Smrg  </sect1>
3669706f2543Smrg
3670706f2543Smrg  <sect1>
3671706f2543Smrg    <title>Offscreen Memory Manager</title>
3672706f2543Smrg
3673706f2543Smrg    <para>
3674706f2543SmrgManagement of offscreen video memory may be handled by the XFree86
3675706f2543Smrgframebuffer manager.  Once the offscreen memory manager is running,
3676706f2543Smrgdrivers or extensions may allocate, free or resize areas of offscreen
3677706f2543Smrgvideo memory using the following functions (definitions taken from
3678706f2543Smrg<filename>xf86fbman.h</filename>):
3679706f2543Smrg
3680706f2543Smrg      <programlisting>
3681706f2543Smrg    typedef struct _FBArea {
3682706f2543Smrg        ScreenPtr    pScreen;
3683706f2543Smrg        BoxRec       box;
3684706f2543Smrg        int          granularity;
3685706f2543Smrg        void         (*MoveAreaCallback)(struct _FBArea*, struct _FBArea*)
3686706f2543Smrg        void         (*RemoveAreaCallback)(struct _FBArea*)
3687706f2543Smrg        DevUnion     devPrivate;
3688706f2543Smrg    } FBArea, *FBAreaPtr;
3689706f2543Smrg
3690706f2543Smrg    typedef void (*MoveAreaCallbackProcPtr)(FBAreaPtr from, FBAreaPtr to)
3691706f2543Smrg    typedef void (*RemoveAreaCallbackProcPtr)(FBAreaPtr)
3692706f2543Smrg
3693706f2543Smrg    FBAreaPtr xf86AllocateOffscreenArea (
3694706f2543Smrg        ScreenPtr pScreen,
3695706f2543Smrg        int width, int height,
3696706f2543Smrg        int granularity,
3697706f2543Smrg        MoveAreaCallbackProcPtr MoveAreaCallback,
3698706f2543Smrg        RemoveAreaCallbackProcPtr RemoveAreaCallback,
3699706f2543Smrg        pointer privData
3700706f2543Smrg    )
3701706f2543Smrg
3702706f2543Smrg    void xf86FreeOffscreenArea (FBAreaPtr area)
3703706f2543Smrg
3704706f2543Smrg    Bool xf86ResizeOffscreenArea (
3705706f2543Smrg	FBAreaPtr area
3706706f2543Smrg	int w, int h
3707706f2543Smrg    )
3708706f2543Smrg      </programlisting>
3709706f2543Smrg    </para>
3710706f2543Smrg
3711706f2543Smrg    <para>
3712706f2543SmrgThe function:
3713706f2543Smrg      <programlisting>
3714706f2543Smrg    Bool xf86FBManagerRunning(ScreenPtr pScreen);
3715706f2543Smrg      </programlisting>
3716706f2543Smrg
3717706f2543Smrgcan be used by an extension to check if the driver has initialized
3718706f2543Smrgthe memory manager.  The manager is not available if this returns
3719706f2543Smrg<constant>FALSE</constant> and the functions above will all fail.
3720706f2543Smrg    </para>
3721706f2543Smrg
3722706f2543Smrg
3723706f2543Smrg    <para>
3724706f2543Smrg<function>xf86AllocateOffscreenArea()</function> can be used to request a
3725706f2543Smrgrectangle of dimensions <parameter>width</parameter>&nbsp;&times;&nbsp;<parameter>height</parameter>
3726706f2543Smrg(in pixels) from unused offscreen memory.  <parameter>granularity</parameter>
3727706f2543Smrgspecifies that the leftmost edge of the rectangle must lie on some
3728706f2543Smrgmultiple of <parameter>granularity</parameter> pixels.  A granularity of zero
3729706f2543Smrgmeans the same thing as a granularity of one - no alignment preference.
3730706f2543SmrgA <parameter>MoveAreaCallback</parameter> can be provided to notify the requester
3731706f2543Smrgwhen the offscreen area is moved.  If no <parameter>MoveAreaCallback</parameter>
3732706f2543Smrgis supplied then the area is considered to be immovable.  The
3733706f2543Smrg<parameter>privData</parameter> field will be stored in the manager's internal
3734706f2543Smrgstructure for that allocated area and will be returned to the requester
3735706f2543Smrgin the <parameter>FBArea</parameter> passed via the
3736706f2543Smrg<parameter>MoveAreaCallback</parameter>.  An optional
3737706f2543Smrg<parameter>RemoveAreaCallback</parameter> is provided.  If the driver provides
3738706f2543Smrgthis it indicates that the area should be allocated with a lower priority.
3739706f2543SmrgSuch an area may be removed when a higher priority request (one that
3740706f2543Smrgdoesn't have a <parameter>RemoveAreaCallback</parameter>) is made.  When this
3741706f2543Smrgfunction is called, the driver will have an opportunity to do whatever
3742706f2543Smrgcleanup it needs to do to deal with the loss of the area, but it must
3743706f2543Smrgfinish its cleanup before the function exits since the offscreen memory
3744706f2543Smrgmanager will free the area immediately after.
3745706f2543Smrg    </para>
3746706f2543Smrg
3747706f2543Smrg    <para>
3748706f2543Smrg<function>xf86AllocateOffscreenArea()</function> returns <constant>NULL</constant>
3749706f2543Smrgif it was unable to allocate the requested area.  When no longer needed,
3750706f2543Smrgareas should be freed with <function>xf86FreeOffscreenArea()</function>.
3751706f2543Smrg    </para>
3752706f2543Smrg
3753706f2543Smrg    <para>
3754706f2543Smrg<function>xf86ResizeOffscreenArea()</function> resizes an existing
3755706f2543Smrg<literal remap="tt">FBArea</literal>.  <function>xf86ResizeOffscreenArea()</function>
3756706f2543Smrgreturns <constant>TRUE</constant> if the resize was successful.  If
3757706f2543Smrg<function>xf86ResizeOffscreenArea()</function> returns <constant>FALSE</constant>,
3758706f2543Smrgthe original <literal remap="tt">FBArea</literal> is left unmodified.  Resizing an
3759706f2543Smrgarea maintains the area's original <literal remap="tt">granularity</literal>,
3760706f2543Smrg<literal remap="tt">devPrivate</literal>, and <literal remap="tt">MoveAreaCallback</literal>.
3761706f2543Smrg<function>xf86ResizeOffscreenArea()</function> has considerably less overhead
3762706f2543Smrgthan freeing the old area then reallocating the new size, so it should
3763706f2543Smrgbe used whenever possible.
3764706f2543Smrg    </para>
3765706f2543Smrg
3766706f2543Smrg    <para>
3767706f2543SmrgThe function:
3768706f2543Smrg      <programlisting>
3769706f2543Smrg    Bool xf86QueryLargestOffscreenArea(
3770706f2543Smrg      ScreenPtr pScreen,
3771706f2543Smrg      int *width, int *height,
3772706f2543Smrg      int granularity,
3773706f2543Smrg      int preferences,
3774706f2543Smrg      int priority
3775706f2543Smrg    );
3776706f2543Smrg	</programlisting>
3777706f2543Smrg
3778706f2543Smrgis provided to query the width and height of the largest single
3779706f2543Smrg<structname>FBArea</structname> allocatable given a particular priority.
3780706f2543Smrg<parameter>preferences</parameter> can be one of the following to indicate
3781706f2543Smrgwhether width, height or area should be considered when determining
3782706f2543Smrgwhich is the largest single <structname>FBArea</structname> available.
3783706f2543Smrg
3784706f2543Smrg      <programlisting>
3785706f2543Smrg  FAVOR_AREA_THEN_WIDTH
3786706f2543Smrg  FAVOR_AREA_THEN_HEIGHT
3787706f2543Smrg  FAVOR_WIDTH_THEN_AREA
3788706f2543Smrg  FAVOR_HEIGHT_THEN_AREA
3789706f2543Smrg      </programlisting>
3790706f2543Smrg    </para>
3791706f2543Smrg
3792706f2543Smrg    <para>
3793706f2543Smrg<parameter>priority</parameter> is one of the following:
3794706f2543Smrg
3795706f2543Smrg      <blockquote>
3796706f2543Smrg	<para>
3797706f2543Smrg  <constant>PRIORITY_LOW</constant>
3798706f2543Smrg	  <blockquote><para>
3799706f2543Smrg     Return the largest block available without stealing anyone else's
3800706f2543Smrg     space.  This corresponds to the priority of allocating a
3801706f2543Smrg     <structname>FBArea</structname> when a <function>RemoveAreaCallback</function>
3802706f2543Smrg     is provided.
3803706f2543Smrg	    </para></blockquote>
3804706f2543Smrg	</para>
3805706f2543Smrg
3806706f2543Smrg	<para>
3807706f2543Smrg   <constant>PRIORITY_NORMAL</constant>
3808706f2543Smrg	  <blockquote><para>
3809706f2543Smrg     Return the largest block available if it is acceptable to steal a
3810706f2543Smrg     lower priority area from someone.  This corresponds to the priority
3811706f2543Smrg     of allocating a <structname>FBArea</structname> without providing a
3812706f2543Smrg     <function>RemoveAreaCallback</function>.
3813706f2543Smrg	    </para></blockquote>
3814706f2543Smrg	</para>
3815706f2543Smrg
3816706f2543Smrg	<para>
3817706f2543Smrg    <constant>PRIORITY_EXTREME</constant>
3818706f2543Smrg	  <blockquote><para>
3819706f2543Smrg     Return the largest block available if all <structname>FBArea</structname>s
3820706f2543Smrg     that aren't locked down were expunged from memory first.  This
3821706f2543Smrg     corresponds to any allocation made directly after a call to
3822706f2543Smrg     <function>xf86PurgeUnlockedOffscreenAreas()</function>.
3823706f2543Smrg	    </para></blockquote>
3824706f2543Smrg	</para>
3825706f2543Smrg
3826706f2543Smrg      </blockquote>
3827706f2543Smrg    </para>
3828706f2543Smrg
3829706f2543Smrg
3830706f2543Smrg    <para>
3831706f2543SmrgThe function:
3832706f2543Smrg
3833706f2543Smrg      <programlisting>
3834706f2543Smrg    Bool xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen);
3835706f2543Smrg      </programlisting>
3836706f2543Smrg
3837706f2543Smrgis provided as an extreme method to free up offscreen memory.  This
3838706f2543Smrgwill remove all removable <structname>FBArea</structname> allocations.
3839706f2543Smrg    </para>
3840706f2543Smrg
3841706f2543Smrg
3842706f2543Smrg    <para>
3843706f2543SmrgInitialization of the XFree86 framebuffer manager is done via
3844706f2543Smrg
3845706f2543Smrg      <programlisting>
3846706f2543Smrg    Bool xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox);
3847706f2543Smrg      </programlisting>
3848706f2543Smrg
3849706f2543Smrg<parameter>FullBox</parameter> represents the area of the framebuffer that the
3850706f2543Smrgmanager is allowed to manage.  This is typically a box with a width of
3851706f2543Smrg<structfield>pScrn-&gt;displayWidth</structfield> and a height of as many lines as
3852706f2543Smrgcan be fit within the total video memory, however, the driver can reserve
3853706f2543Smrgareas at the extremities by passing a smaller area to the manager.
3854706f2543Smrg    </para>
3855706f2543Smrg
3856706f2543Smrg    <para>
3857706f2543Smrg<function>xf86InitFBManager()</function> must be called before XAA is
3858706f2543Smrginitialized since XAA uses the manager for it's pixmap cache.
3859706f2543Smrg    </para>
3860706f2543Smrg
3861706f2543Smrg    <para>
3862706f2543SmrgAn alternative function is provided to allow the driver to initialize
3863706f2543Smrgthe framebuffer manager with a Region rather than a box.
3864706f2543Smrg
3865706f2543Smrg    <programlisting>
3866706f2543Smrg    Bool xf86InitFBManagerRegion(ScreenPtr pScreen,
3867706f2543Smrg                                 RegionPtr FullRegion);
3868706f2543Smrg    </programlisting>
3869706f2543Smrg
3870706f2543Smrg<function>xf86InitFBManagerRegion()</function>, unlike
3871706f2543Smrg<function>xf86InitFBManager()</function>, does not remove the area used for
3872706f2543Smrgthe visible screen so that area should not be included in the region
3873706f2543Smrgpassed to the function.  <function>xf86InitFBManagerRegion()</function> is
3874706f2543Smrguseful when non-contiguous areas are available to be managed, and is
3875706f2543Smrgrequired when multiple framebuffers are stored in video memory (as in
3876706f2543Smrgthe case where an overlay of a different depth is stored as a second
3877706f2543Smrgframebuffer in offscreen memory).
3878706f2543Smrg    </para>
3879706f2543Smrg
3880706f2543Smrg  </sect1>
3881706f2543Smrg
3882706f2543Smrg  <sect1 id="cmap">
3883706f2543Smrg    <title>Colormap Handling</title>
3884706f2543Smrg
3885706f2543Smrg    <para>
3886706f2543SmrgA generic colormap handling layer is provided within the XFree86 common
3887706f2543Smrglayer.  This layer takes care of most of the details, and only requires
3888706f2543Smrga function from the driver that loads the hardware palette when required.
3889706f2543SmrgTo use the colormap layer, a driver calls the
3890706f2543Smrg<function>xf86HandleColormaps()</function> function.
3891706f2543Smrg
3892706f2543Smrg      <blockquote><para>
3893706f2543Smrg	  <programlisting>
3894706f2543Smrg    Bool xf86HandleColormaps(ScreenPtr pScreen, int maxColors,
3895706f2543Smrg                             int sigRGBbits, LoadPaletteFuncPtr loadPalette,
3896706f2543Smrg                             SetOverscanFuncPtr setOverscan,
3897706f2543Smrg                             unsigned int flags);
3898706f2543Smrg	  </programlisting>
3899706f2543Smrg	  <blockquote><para>
3900706f2543Smrg      This function must be called after the default colormap has been
3901706f2543Smrg      initialised.  The <structfield>pScrn-&gt;gamma</structfield> field must also
3902706f2543Smrg      be initialised, preferably by calling <function>xf86SetGamma()</function>.
3903706f2543Smrg      <parameter>maxColors</parameter> is the number of entries in the palette.
3904706f2543Smrg      <parameter>sigRGBbits</parameter> is the size in bits of each color
3905706f2543Smrg      component in the DAC's palette.  <parameter>loadPalette</parameter>
3906706f2543Smrg      is a driver-provided function for loading a colormap into the
3907706f2543Smrg      hardware, and is described below.  <parameter>setOverscan</parameter> is
3908706f2543Smrg      an optional function that may be provided when the overscan color
3909706f2543Smrg      is an index from the standard LUT and when it needs to be adjusted
3910706f2543Smrg      to keep it as close to black as possible.  The
3911706f2543Smrg      <parameter>setOverscan</parameter> function programs the overscan index.
3912706f2543Smrg      It shouldn't normally be used for depths other than 8.
3913706f2543Smrg      <parameter>setOverscan</parameter> should be set to <constant>NULL</constant>
3914706f2543Smrg      when it isn't needed.  <parameter>flags</parameter> may be set to the
3915706f2543Smrg      following (which may be ORed together):
3916706f2543Smrg
3917706f2543Smrg	      <variablelist>
3918706f2543Smrg		<varlistentry>
3919706f2543Smrg		  <term><constant>CMAP_PALETTED_TRUECOLOR</constant></term>
3920706f2543Smrg		  <listitem><para>
3921706f2543Smrg				    the TrueColor visual is paletted and is
3922706f2543Smrg				    just a special case of DirectColor.
3923706f2543Smrg				    This flag is only valid for
3924706f2543Smrg				    <code>bpp&nbsp;&gt;&nbsp;8</code>.
3925706f2543Smrg
3926706f2543Smrg		    </para></listitem></varlistentry>
3927706f2543Smrg		<varlistentry>
3928706f2543Smrg		  <term><constant>CMAP_RELOAD_ON_MODE_SWITCH</constant></term>
3929706f2543Smrg		  <listitem><para>
3930706f2543Smrg				    reload the colormap automatically
3931706f2543Smrg                                    after mode switches.  This is useful
3932706f2543Smrg                                    for when the driver is resetting the
3933706f2543Smrg                                    hardware during mode switches and
3934706f2543Smrg                                    corrupting or erasing the hardware
3935706f2543Smrg                                    palette.
3936706f2543Smrg
3937706f2543Smrg		    </para></listitem></varlistentry>
3938706f2543Smrg		<varlistentry>
3939706f2543Smrg		  <term><constant>CMAP_LOAD_EVEN_IF_OFFSCREEN</constant></term>
3940706f2543Smrg		  <listitem><para>
3941706f2543Smrg				    reload the colormap even if the screen
3942706f2543Smrg				    is switched out of the server's VC.
3943706f2543Smrg				    The palette is <emphasis>not</emphasis> reloaded when
3944706f2543Smrg				    the screen is switched back in, nor after
3945706f2543Smrg				    mode switches.  This is useful when the
3946706f2543Smrg				    driver needs to keep track of palette
3947706f2543Smrg				    changes.
3948706f2543Smrg
3949706f2543Smrg		    </para></listitem></varlistentry>
3950706f2543Smrg	      </variablelist>
3951706f2543Smrg	    </para>
3952706f2543Smrg
3953706f2543Smrg	    <para>
3954706f2543Smrg      The colormap layer normally reloads the palette after VT enters so it
3955706f2543Smrg      is not necessary for the driver to save and restore the palette
3956706f2543Smrg      when switching VTs.  The driver must, however, still save the
3957706f2543Smrg      initial palette during server start up and restore it during
3958706f2543Smrg      server exit.
3959706f2543Smrg	    </para>
3960706f2543Smrg
3961706f2543Smrg	  </blockquote></para></blockquote>
3962706f2543Smrg
3963706f2543Smrg      <blockquote><para>
3964706f2543Smrg	  <programlisting>
3965706f2543Smrg    void LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
3966706f2543Smrg                     LOCO *colors, VisualPtr pVisual);
3967706f2543Smrg	  </programlisting>
3968706f2543Smrg	  <blockquote><para>
3969706f2543Smrg      <function>LoadPalette()</function> is a driver-provided function for
3970706f2543Smrg      loading a colormap into hardware.  <parameter>colors</parameter> is the
3971706f2543Smrg      array of RGB values that represent the full colormap.
3972706f2543Smrg      <parameter>indices</parameter> is a list of index values into the colors
3973706f2543Smrg      array.  These indices indicate the entries that need to be updated.
3974706f2543Smrg      <parameter>numColors</parameter> is the number of the indices to be
3975706f2543Smrg      updated.
3976706f2543Smrg	    </para>
3977706f2543Smrg
3978706f2543Smrg	  </blockquote></para></blockquote>
3979706f2543Smrg
3980706f2543Smrg      <blockquote><para>
3981706f2543Smrg	  <programlisting>
3982706f2543Smrg    void SetOverscan(ScrnInfoPtr pScrn, int overscan);
3983706f2543Smrg	  </programlisting>
3984706f2543Smrg	  <blockquote><para>
3985706f2543Smrg      <function>SetOverscan()</function> is a driver-provided function for
3986706f2543Smrg      programming the <parameter>overscan</parameter> index.  As described
3987706f2543Smrg      above, it is normally only appropriate for LUT modes where all
3988706f2543Smrg      colormap entries are available for the display, but where one of
3989706f2543Smrg      them is also used for the overscan (typically 8bpp for VGA compatible
3990706f2543Smrg      LUTs).  It isn't required in cases where the overscan area is
3991706f2543Smrg      never visible.
3992706f2543Smrg	    </para>
3993706f2543Smrg
3994706f2543Smrg	  </blockquote></para>
3995706f2543Smrg      </blockquote></para>
3996706f2543Smrg
3997706f2543Smrg  </sect1>
3998706f2543Smrg
3999706f2543Smrg  <sect1>
4000706f2543Smrg    <title>DPMS Extension</title>
4001706f2543Smrg
4002706f2543Smrg    <para>
4003706f2543SmrgSupport code for the DPMS extension is included in the XFree86 common layer.
4004706f2543SmrgThis code provides an interface between the main extension code, and a means
4005706f2543Smrgfor drivers to initialise DPMS when they support it.  One function is
4006706f2543Smrgavailable to drivers to do this initialisation, and it is always available,
4007706f2543Smrgeven when the DPMS extension is not supported by the core server (in
4008706f2543Smrgwhich case it returns a failure result).
4009706f2543Smrg    </para>
4010706f2543Smrg
4011706f2543Smrg    <blockquote><para>
4012706f2543Smrg	<programlisting>
4013706f2543Smrg    Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags);
4014706f2543Smrg	</programlisting>
4015706f2543Smrg	<blockquote><para>
4016706f2543Smrg      This function registers a driver's DPMS level programming function
4017706f2543Smrg      <parameter>set</parameter>.  It also checks
4018706f2543Smrg      <structfield>pScrn-&gt;options</structfield> for the "dpms" option, and when
4019706f2543Smrg      present marks DPMS as being enabled for that screen.  The
4020706f2543Smrg      <parameter>set</parameter> function is called whenever the DPMS level
4021706f2543Smrg      changes, and is used to program the requested level.
4022706f2543Smrg      <parameter>flags</parameter> is currently not used, and should be
4023706f2543Smrg      <constant>0</constant>.  If the initialisation fails for any reason,
4024706f2543Smrg      including when there is no DPMS support in the core server, the
4025706f2543Smrg      function returns <constant>FALSE</constant>.
4026706f2543Smrg	  </para>
4027706f2543Smrg
4028706f2543Smrg	</blockquote></para></blockquote>
4029706f2543Smrg
4030706f2543Smrg
4031706f2543Smrg    <para>
4032706f2543SmrgDrivers that implement DPMS support must provide the following function,
4033706f2543Smrgthat gets called when the DPMS level is changed:
4034706f2543Smrg
4035706f2543Smrg
4036706f2543Smrg      <blockquote><para>
4037706f2543Smrg	  <programlisting>
4038706f2543Smrg    void ChipDPMSSet(ScrnInfoPtr pScrn, int level, int flags);
4039706f2543Smrg	  </programlisting>
4040706f2543Smrg	  <blockquote><para>
4041706f2543Smrg      Program the DPMS level specified by <parameter>level</parameter>.  Valid
4042706f2543Smrg      values of <parameter>level</parameter> are <constant>DPMSModeOn</constant>,
4043706f2543Smrg      <constant>DPMSModeStandby</constant>, <constant>DPMSModeSuspend</constant>,
4044706f2543Smrg      <constant>DPMSModeOff</constant>.  These values are defined in
4045706f2543Smrg      <filename>"extensions/dpms.h"</filename>.
4046706f2543Smrg	    </para>
4047706f2543Smrg
4048706f2543Smrg	  </blockquote></para></blockquote>
4049706f2543Smrg    </para>
4050706f2543Smrg
4051706f2543Smrg  </sect1>
4052706f2543Smrg
4053706f2543Smrg  <sect1>
4054706f2543Smrg    <title>DGA Extension</title>
4055706f2543Smrg
4056706f2543Smrg    <para>
4057706f2543SmrgDrivers can support the XFree86 Direct Graphics Architecture (DGA) by
4058706f2543Smrgfilling out a structure of function pointers and a list of modes and
4059706f2543Smrgpassing them to DGAInit.
4060706f2543Smrg    </para>
4061706f2543Smrg
4062706f2543Smrg    <blockquote><para>
4063706f2543Smrg	<programlisting>
4064706f2543Smrg    Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs,
4065706f2543Smrg                 DGAModePtr modes, int num);
4066706f2543Smrg
4067706f2543Smrg/** The DGAModeRec **/
4068706f2543Smrg
4069706f2543Smrgtypedef struct {
4070706f2543Smrg  int num;
4071706f2543Smrg  DisplayModePtr mode;
4072706f2543Smrg  int flags;
4073706f2543Smrg  int imageWidth;
4074706f2543Smrg  int imageHeight;
4075706f2543Smrg  int pixmapWidth;
4076706f2543Smrg  int pixmapHeight;
4077706f2543Smrg  int bytesPerScanline;
4078706f2543Smrg  int byteOrder;
4079706f2543Smrg  int depth;
4080706f2543Smrg  int bitsPerPixel;
4081706f2543Smrg  unsigned long red_mask;
4082706f2543Smrg  unsigned long green_mask;
4083706f2543Smrg  unsigned long blue_mask;
4084706f2543Smrg  int viewportWidth;
4085706f2543Smrg  int viewportHeight;
4086706f2543Smrg  int xViewportStep;
4087706f2543Smrg  int yViewportStep;
4088706f2543Smrg  int maxViewportX;
4089706f2543Smrg  int maxViewportY;
4090706f2543Smrg  int viewportFlags;
4091706f2543Smrg  int offset;
4092706f2543Smrg  unsigned char *address;
4093706f2543Smrg  int reserved1;
4094706f2543Smrg  int reserved2;
4095706f2543Smrg} DGAModeRec, *DGAModePtr;
4096706f2543Smrg	</programlisting>
4097706f2543Smrg
4098706f2543Smrg	<variablelist>
4099706f2543Smrg	  <varlistentry>
4100706f2543Smrg	    <term><structfield>num</structfield></term>
4101706f2543Smrg	    <listitem><para>
4102706f2543Smrg	 Can be ignored.  The DGA DDX will assign these numbers.
4103706f2543Smrg	      </para></listitem></varlistentry>
4104706f2543Smrg
4105706f2543Smrg	  <varlistentry>
4106706f2543Smrg	    <term><structfield>mode</structfield></term>
4107706f2543Smrg	    <listitem><para>
4108706f2543Smrg	A pointer to the <structname>DisplayModeRec</structname> for this mode.
4109706f2543Smrg	      </para></listitem></varlistentry>
4110706f2543Smrg
4111706f2543Smrg	  <varlistentry>
4112706f2543Smrg	    <term><structfield>flags</structfield></term>
4113706f2543Smrg	      <listitem><para>
4114706f2543Smrg	The following flags are defined and may be OR'd together:
4115706f2543Smrg
4116706f2543Smrg		  <variablelist>
4117706f2543Smrg		    <varlistentry>
4118706f2543Smrg		      <term><constant>DGA_CONCURRENT_ACCESS</constant></term>
4119706f2543Smrg		      <listitem><para>
4120706f2543Smrg            Indicates that the driver supports concurrent graphics
4121706f2543Smrg            accelerator and linear framebuffer access.
4122706f2543Smrg
4123706f2543Smrg			</para></listitem></varlistentry>
4124706f2543Smrg
4125706f2543Smrg		    <varlistentry>
4126706f2543Smrg		      <term><constant>DGA_FILL_RECT
4127706f2543Smrg			  DGA_BLIT_RECT
4128706f2543Smrg			  DGA_BLIT_RECT_TRANS</constant></term>
4129706f2543Smrg		      <listitem><para>
4130706f2543Smrg	    Indicates that the driver supports the FillRect, BlitRect
4131706f2543Smrg            or BlitTransRect functions in this mode.
4132706f2543Smrg
4133706f2543Smrg			</para></listitem></varlistentry>
4134706f2543Smrg
4135706f2543Smrg		    <varlistentry>
4136706f2543Smrg		      <term><constant>DGA_PIXMAP_AVAILABLE</constant></term>
4137706f2543Smrg		      <listitem><para>
4138706f2543Smrg	    Indicates that Xlib may be used on the framebuffer.
4139706f2543Smrg            This flag will usually be set unless the driver wishes
4140706f2543Smrg            to prohibit this for some reason.
4141706f2543Smrg
4142706f2543Smrg			</para></listitem></varlistentry>
4143706f2543Smrg
4144706f2543Smrg		    <varlistentry>
4145706f2543Smrg		      <term><constant>DGA_INTERLACED
4146706f2543Smrg			  DGA_DOUBLESCAN</constant></term>
4147706f2543Smrg		      <listitem><para>
4148706f2543Smrg            Indicates that these are interlaced or double scan modes.
4149706f2543Smrg
4150706f2543Smrg			</para></listitem></varlistentry>
4151706f2543Smrg		  </variablelist>
4152706f2543Smrg		</para></listitem></varlistentry>
4153706f2543Smrg
4154706f2543Smrg	  <varlistentry>
4155706f2543Smrg	    <term><structfield>imageWidth
4156706f2543Smrg		imageHeight</structfield></term>
4157706f2543Smrg	    <listitem><para>
4158706f2543Smrg		    These are the dimensions of the linear framebuffer
4159706f2543Smrg                     accessible by the client.
4160706f2543Smrg
4161706f2543Smrg	      </para></listitem></varlistentry>
4162706f2543Smrg
4163706f2543Smrg	  <varlistentry>
4164706f2543Smrg	    <term><structfield>pixmapWidth
4165706f2543Smrg		pixmapHeight</structfield></term>
4166706f2543Smrg	    <listitem><para>
4167706f2543Smrg		     These are the dimensions of the area of the
4168706f2543Smrg                     framebuffer accessible by the graphics accelerator.
4169706f2543Smrg
4170706f2543Smrg	      </para></listitem></varlistentry>
4171706f2543Smrg
4172706f2543Smrg	  <varlistentry>
4173706f2543Smrg	    <term><structfield>bytesPerScanline</structfield></term>
4174706f2543Smrg	    <listitem><para>
4175706f2543Smrg		      Pitch of the framebuffer in bytes.
4176706f2543Smrg
4177706f2543Smrg	      </para></listitem></varlistentry>
4178706f2543Smrg
4179706f2543Smrg	  <varlistentry>
4180706f2543Smrg	    <term><structfield>byteOrder</structfield></term>
4181706f2543Smrg	    <listitem><para>
4182706f2543Smrg		     Usually the same as
4183706f2543Smrg		     <structfield>pScrn-&gt;imageByteOrder</structfield>.
4184706f2543Smrg
4185706f2543Smrg	      </para></listitem></varlistentry>
4186706f2543Smrg
4187706f2543Smrg	  <varlistentry>
4188706f2543Smrg	    <term><structfield>depth</structfield></term>
4189706f2543Smrg	    <listitem><para>
4190706f2543Smrg		     The depth of the framebuffer in this mode.
4191706f2543Smrg
4192706f2543Smrg	      </para></listitem></varlistentry>
4193706f2543Smrg
4194706f2543Smrg	  <varlistentry>
4195706f2543Smrg	    <term><structfield>bitsPerPixel</structfield></term>
4196706f2543Smrg	    <listitem><para>
4197706f2543Smrg		      The number of bits per pixel in this mode.
4198706f2543Smrg
4199706f2543Smrg	      </para></listitem></varlistentry>
4200706f2543Smrg
4201706f2543Smrg	  <varlistentry>
4202706f2543Smrg	    <term><structfield>red_mask</structfield></term>
4203706f2543Smrg	    <term><structfield>green_mask</structfield></term>
4204706f2543Smrg	    <term><structfield>blue_mask</structfield></term>
4205706f2543Smrg	    <listitem><para>
4206706f2543Smrg		      The RGB masks for this mode, if applicable.
4207706f2543Smrg
4208706f2543Smrg	      </para></listitem></varlistentry>
4209706f2543Smrg
4210706f2543Smrg	  <varlistentry>
4211706f2543Smrg	    <term><structfield>viewportWidth</structfield></term>
4212706f2543Smrg	    <term><structfield>viewportHeight</structfield></term>
4213706f2543Smrg	    <listitem><para>
4214706f2543Smrg		      Dimensions of the visible part of the framebuffer.
4215706f2543Smrg		      Usually <structfield>mode-&gt;HDisplay</structfield> and
4216706f2543Smrg		      <structfield>mode-&gt;VDisplay</structfield>.
4217706f2543Smrg
4218706f2543Smrg	      </para></listitem></varlistentry>
4219706f2543Smrg
4220706f2543Smrg	  <varlistentry>
4221706f2543Smrg	    <term><structfield>xViewportStep
4222706f2543Smrg		yViewportStep</structfield></term>
4223706f2543Smrg	    <listitem><para>
4224706f2543Smrg		     The granularity of x and y viewport positions that
4225706f2543Smrg                     the driver supports in this mode.
4226706f2543Smrg
4227706f2543Smrg	      </para></listitem></varlistentry>
4228706f2543Smrg
4229706f2543Smrg	  <varlistentry>
4230706f2543Smrg	    <term><structfield>maxViewportX
4231706f2543Smrg		maxViewportY</structfield></term>
4232706f2543Smrg	    <listitem><para>
4233706f2543Smrg		      The maximum viewport position supported by the
4234706f2543Smrg                       driver in this mode.
4235706f2543Smrg	      </para></listitem></varlistentry>
4236706f2543Smrg
4237706f2543Smrg	  <varlistentry>
4238706f2543Smrg	    <term><structfield>viewportFlags</structfield></term>
4239706f2543Smrg	    <listitem><para>
4240706f2543Smrg		     The following may be OR'd together:
4241706f2543Smrg
4242706f2543Smrg		<variablelist>
4243706f2543Smrg		  <varlistentry>
4244706f2543Smrg		    <term><constant>DGA_FLIP_IMMEDIATE</constant></term>
4245706f2543Smrg		    <listitem><para>
4246706f2543Smrg		The driver supports immediate viewport changes.
4247706f2543Smrg		      </para></listitem></varlistentry>
4248706f2543Smrg
4249706f2543Smrg		  <varlistentry>
4250706f2543Smrg		    <term><constant>DGA_FLIP_RETRACE</constant></term>
4251706f2543Smrg
4252706f2543Smrg		    <listitem><para>
4253706f2543Smrg		The driver supports viewport changes at retrace.
4254706f2543Smrg		      </para></listitem></varlistentry>
4255706f2543Smrg		  </variablelist>
4256706f2543Smrg	      </para></listitem></varlistentry>
4257706f2543Smrg
4258706f2543Smrg	  <varlistentry>
4259706f2543Smrg	    <term><structfield>offset</structfield></term>
4260706f2543Smrg	    <listitem><para>
4261706f2543Smrg	        The offset into the linear framebuffer that corresponds to
4262706f2543Smrg                pixel (0,0) for this mode.
4263706f2543Smrg	      </para></listitem></varlistentry>
4264706f2543Smrg
4265706f2543Smrg	  <varlistentry>
4266706f2543Smrg	    <term><structfield>address</structfield></term>
4267706f2543Smrg	    <listitem><para>
4268706f2543Smrg                The virtual address of the framebuffer as mapped by the driver.
4269706f2543Smrg                This is needed when DGA_PIXMAP_AVAILABLE is set.
4270706f2543Smrg	      </para></listitem></varlistentry>
4271706f2543Smrg
4272706f2543Smrg	</variablelist>
4273706f2543Smrg
4274706f2543Smrg	<programlisting>
4275706f2543Smrg/** The DGAFunctionRec **/
4276706f2543Smrg
4277706f2543Smrgtypedef struct {
4278706f2543Smrg  Bool (*OpenFramebuffer)(
4279706f2543Smrg       ScrnInfoPtr pScrn,
4280706f2543Smrg       char **name,
4281706f2543Smrg       unsigned char **mem,
4282706f2543Smrg       int *size,
4283706f2543Smrg       int *offset,
4284706f2543Smrg       int *extra
4285706f2543Smrg  );
4286706f2543Smrg  void (*CloseFramebuffer)(ScrnInfoPtr pScrn);
4287706f2543Smrg  Bool (*SetMode)(ScrnInfoPtr pScrn, DGAModePtr pMode);
4288706f2543Smrg  void (*SetViewport)(ScrnInfoPtr pScrn, int x, int y, int flags);
4289706f2543Smrg  int  (*GetViewport)(ScrnInfoPtr pScrn);
4290706f2543Smrg  void (*Sync)(ScrnInfoPtr);
4291706f2543Smrg  void (*FillRect)(
4292706f2543Smrg       ScrnInfoPtr pScrn,
4293706f2543Smrg       int x, int y, int w, int h,
4294706f2543Smrg       unsigned long color
4295706f2543Smrg  );
4296706f2543Smrg  void (*BlitRect)(
4297706f2543Smrg       ScrnInfoPtr pScrn,
4298706f2543Smrg       int srcx, int srcy,
4299706f2543Smrg       int w, int h,
4300706f2543Smrg       int dstx, int dsty
4301706f2543Smrg  );
4302706f2543Smrg  void (*BlitTransRect)(
4303706f2543Smrg       ScrnInfoPtr pScrn,
4304706f2543Smrg       int srcx, int srcy,
4305706f2543Smrg       int w, int h,
4306706f2543Smrg       int dstx, int dsty,
4307706f2543Smrg       unsigned long color
4308706f2543Smrg  );
4309706f2543Smrg} DGAFunctionRec, *DGAFunctionPtr;
4310706f2543Smrg	</programlisting>
4311706f2543Smrg
4312706f2543Smrg
4313706f2543Smrg	<blockquote><para>
4314706f2543Smrg	    <programlisting>
4315706f2543Smrg    Bool OpenFramebuffer (pScrn, name, mem, size, offset, extra);
4316706f2543Smrg	    </programlisting>
4317706f2543Smrg	    <blockquote><para>
4318706f2543Smrg      <function>OpenFramebuffer()</function> should pass the client everything
4319706f2543Smrg      it needs to know to be able to open the framebuffer.  These
4320706f2543Smrg      parameters are OS specific and their meanings are to be interpreted
4321706f2543Smrg      by an OS specific client library.
4322706f2543Smrg
4323706f2543Smrg		<variablelist>
4324706f2543Smrg		  <varlistentry>
4325706f2543Smrg		    <term><parameter>name</parameter></term>
4326706f2543Smrg		    <listitem><para>
4327706f2543Smrg	      The name of the device to open or <constant>NULL</constant> if
4328706f2543Smrg	      there is no special device to open.  A <constant>NULL</constant>
4329706f2543Smrg	      name tells the client that it should open whatever device
4330706f2543Smrg	      one would usually open to access physical memory.
4331706f2543Smrg		      </para></listitem></varlistentry>
4332706f2543Smrg
4333706f2543Smrg		  <varlistentry>
4334706f2543Smrg		    <term><parameter>mem</parameter></term>
4335706f2543Smrg		    <listitem><para>
4336706f2543Smrg	      The physical address of the start of the framebuffer.
4337706f2543Smrg		      </para></listitem></varlistentry>
4338706f2543Smrg
4339706f2543Smrg		  <varlistentry>
4340706f2543Smrg		    <term><parameter>size</parameter></term>
4341706f2543Smrg		    <listitem><para>
4342706f2543Smrg	      The size of the framebuffer in bytes.
4343706f2543Smrg		      </para></listitem></varlistentry>
4344706f2543Smrg
4345706f2543Smrg		  <varlistentry>
4346706f2543Smrg		    <term><parameter>offset</parameter></term>
4347706f2543Smrg		    <listitem><para>
4348706f2543Smrg	      Any offset into the device, if applicable.
4349706f2543Smrg		      </para></listitem></varlistentry>
4350706f2543Smrg
4351706f2543Smrg		  <varlistentry>
4352706f2543Smrg		    <term><parameter>flags</parameter></term>
4353706f2543Smrg		    <listitem><para>
4354706f2543Smrg	      Any additional information that the client may need.
4355706f2543Smrg	      Currently, only the <constant>DGA_NEED_ROOT</constant> flag is
4356706f2543Smrg	      defined.
4357706f2543Smrg		      </para></listitem></varlistentry>
4358706f2543Smrg
4359706f2543Smrg		</variablelist>
4360706f2543Smrg	      </para></blockquote>
4361706f2543Smrg	  </para></blockquote>
4362706f2543Smrg
4363706f2543Smrg	<blockquote><para>
4364706f2543Smrg	    <programlisting>
4365706f2543Smrg    void CloseFramebuffer (pScrn);
4366706f2543Smrg	    </programlisting>
4367706f2543Smrg	    <blockquote><para>
4368706f2543Smrg      <function>CloseFramebuffer()</function> merely informs the driver (if it
4369706f2543Smrg      even cares) that client no longer needs to access the framebuffer
4370706f2543Smrg      directly.  This function is optional.
4371706f2543Smrg	      </para>
4372706f2543Smrg
4373706f2543Smrg	    </blockquote></para></blockquote>
4374706f2543Smrg
4375706f2543Smrg	<blockquote><para>
4376706f2543Smrg	    <programlisting>
4377706f2543Smrg    Bool SetMode (pScrn, pMode);
4378706f2543Smrg	    </programlisting>
4379706f2543Smrg	    <blockquote><para>
4380706f2543Smrg      <function>SetMode()</function> tells the driver to initialize the mode
4381706f2543Smrg      passed to it.  If <parameter>pMode</parameter> is <constant>NULL</constant>,
4382706f2543Smrg      then the driver should restore the original pre-DGA mode.
4383706f2543Smrg	      </para>
4384706f2543Smrg
4385706f2543Smrg	    </blockquote></para></blockquote>
4386706f2543Smrg
4387706f2543Smrg	<blockquote><para>
4388706f2543Smrg	    <programlisting>
4389706f2543Smrg    void SetViewport (pScrn, x, y, flags);
4390706f2543Smrg	    </programlisting>
4391706f2543Smrg	    <blockquote><para>
4392706f2543Smrg      <function>SetViewport()</function> tells the driver to make the upper
4393706f2543Smrg      left-hand corner of the visible screen correspond to coordinate
4394706f2543Smrg      <literal remap="tt">(x,y)</literal> on the framebuffer.  <parameter>flags</parameter>
4395706f2543Smrg      currently defined are:
4396706f2543Smrg
4397706f2543Smrg		<variablelist>
4398706f2543Smrg		  <varlistentry>
4399706f2543Smrg		    <term><constant>DGA_FLIP_IMMEDIATE</constant></term>
4400706f2543Smrg		    <listitem><para>
4401706f2543Smrg	    The viewport change should occur immediately.
4402706f2543Smrg		      </para></listitem></varlistentry>
4403706f2543Smrg
4404706f2543Smrg		  <varlistentry>
4405706f2543Smrg		    <term><constant>DGA_FLIP_RETRACE</constant></term>
4406706f2543Smrg		    <listitem><para>
4407706f2543Smrg	    The viewport change should occur at the
4408706f2543Smrg            vertical retrace, but this function should
4409706f2543Smrg            return sooner if possible.
4410706f2543Smrg			</para></listitem></varlistentry>
4411706f2543Smrg		</variablelist>
4412706f2543Smrg	      </para>
4413706f2543Smrg
4414706f2543Smrg	      <para>
4415706f2543Smrg      The <literal remap="tt">(x,y)</literal> locations will be passed as the client
4416706f2543Smrg      specified them, however, the driver is expected to round these
4417706f2543Smrg      locations down to the next supported location as specified by the
4418706f2543Smrg      <structfield>xViewportStep</structfield> and <structfield>yViewportStep</structfield>
4419706f2543Smrg      for the current mode.
4420706f2543Smrg	      </para>
4421706f2543Smrg	    </blockquote></para></blockquote>
4422706f2543Smrg
4423706f2543Smrg	<blockquote><para>
4424706f2543Smrg	    <programlisting>
4425706f2543Smrg    int GetViewport (pScrn);
4426706f2543Smrg	    </programlisting>
4427706f2543Smrg	    <blockquote><para>
4428706f2543Smrg      <function>GetViewport()</function> gets the current page flip status.
4429706f2543Smrg      Set bits in the returned int correspond to viewport change requests
4430706f2543Smrg      still pending.  For instance, set bit zero if the last SetViewport
4431706f2543Smrg      request is still pending, bit one if the one before that is still
4432706f2543Smrg      pending, etc.
4433706f2543Smrg	      </para>
4434706f2543Smrg
4435706f2543Smrg	    </blockquote></para></blockquote>
4436706f2543Smrg
4437706f2543Smrg	<blockquote><para>
4438706f2543Smrg	    <programlisting>
4439706f2543Smrg    void Sync (pScrn);
4440706f2543Smrg	    </programlisting>
4441706f2543Smrg	    <blockquote><para>
4442706f2543Smrg      This function should ensure that any graphics accelerator operations
4443706f2543Smrg      have finished.  This function should not return until the graphics
4444706f2543Smrg      accelerator is idle.
4445706f2543Smrg	      </para>
4446706f2543Smrg
4447706f2543Smrg	    </blockquote></para></blockquote>
4448706f2543Smrg
4449706f2543Smrg	<blockquote><para>
4450706f2543Smrg	    <programlisting>
4451706f2543Smrg    void FillRect (pScrn, x, y, w, h, color);
4452706f2543Smrg	    </programlisting>
4453706f2543Smrg	    <blockquote><para>
4454706f2543Smrg      This optional function should fill a rectangle
4455706f2543Smrg      <parameter>w&nbsp;&times;&nbsp;h</parameter> located at
4456706f2543Smrg      <parameter>(x,y)</parameter> in the given color.
4457706f2543Smrg	      </para>
4458706f2543Smrg
4459706f2543Smrg	    </blockquote></para></blockquote>
4460706f2543Smrg
4461706f2543Smrg	<blockquote><para>
4462706f2543Smrg	    <programlisting>
4463706f2543Smrg    void BlitRect (pScrn, srcx, srcy, w, h, dstx, dsty);
4464706f2543Smrg	    </programlisting>
4465706f2543Smrg	    <blockquote><para>
4466706f2543Smrg      This optional function should copy an area
4467706f2543Smrg      <parameter>w&nbsp;&times;&nbsp;h</parameter> located at
4468706f2543Smrg      <parameter>(srcx,srcy)</parameter> to location <parameter>(dstx,dsty)</parameter>.
4469706f2543Smrg      This function will need to handle copy directions as appropriate.
4470706f2543Smrg	      </para>
4471706f2543Smrg
4472706f2543Smrg	    </blockquote></para></blockquote>
4473706f2543Smrg
4474706f2543Smrg	<blockquote><para>
4475706f2543Smrg	    <programlisting>
4476706f2543Smrg    void BlitTransRect (pScrn, srcx, srcy, w, h, dstx, dsty, color);
4477706f2543Smrg	    </programlisting>
4478706f2543Smrg	    <blockquote><para>
4479706f2543Smrg      This optional function is the same as BlitRect except that pixels
4480706f2543Smrg      in the source corresponding to the color key <parameter>color</parameter>
4481706f2543Smrg      should be skipped.
4482706f2543Smrg	      </para>
4483706f2543Smrg
4484706f2543Smrg	    </blockquote></para></blockquote>
4485706f2543Smrg    </para></blockquote>
4486706f2543Smrg
4487706f2543Smrg  </sect1>
4488706f2543Smrg
4489706f2543Smrg  <sect1>
4490706f2543Smrg    <title>The XFree86 X Video Extension (Xv) Device Dependent Layer</title>
4491706f2543Smrg
4492706f2543Smrg    <para>
4493706f2543SmrgXFree86 offers the X Video Extension which allows clients to treat video
4494706f2543Smrgas any another primitive and <quote>Put</quote> video into drawables.  By default,
4495706f2543Smrgthe extension reports no video adaptors as being available since the
4496706f2543SmrgDDX layer has not been initialized.  The driver can initialize the DDX
4497706f2543Smrglayer by filling out one or more <literal remap="tt">XF86VideoAdaptorRecs</literal>
4498706f2543Smrgas described later in this document and passing a list of
4499706f2543Smrg<literal remap="tt">XF86VideoAdaptorPtr</literal> pointers to the following function:
4500706f2543Smrg
4501706f2543Smrg      <programlisting>
4502706f2543Smrg    Bool xf86XVScreenInit(ScreenPtr pScreen,
4503706f2543Smrg                          XF86VideoAdaptorPtr *adaptPtrs,
4504706f2543Smrg                          int num);
4505706f2543Smrg      </programlisting>
4506706f2543Smrg    </para>
4507706f2543Smrg
4508706f2543Smrg    <para>
4509706f2543SmrgAfter doing this, the extension will report video adaptors as being
4510706f2543Smrgavailable, providing the data in their respective
4511706f2543Smrg<literal remap="tt">XF86VideoAdaptorRecs</literal> was valid.
4512706f2543Smrg<function>xf86XVScreenInit()</function> <emphasis>copies</emphasis> data from the structure
4513706f2543Smrgpassed to it so the driver may free it after the initialization.  At
4514706f2543Smrgthe moment, the DDX only supports rendering into Window drawables.
4515706f2543SmrgPixmap rendering will be supported after a sufficient survey of suitable
4516706f2543Smrghardware is completed.
4517706f2543Smrg    </para>
4518706f2543Smrg
4519706f2543Smrg    <para>
4520706f2543SmrgThe <structname>XF86VideoAdaptorRec</structname>:
4521706f2543Smrg
4522706f2543Smrg      <programlisting>
4523706f2543Smrgtypedef struct {
4524706f2543Smrg	unsigned int type;
4525706f2543Smrg	int flags;
4526706f2543Smrg	char *name;
4527706f2543Smrg	int nEncodings;
4528706f2543Smrg	XF86VideoEncodingPtr pEncodings;
4529706f2543Smrg	int nFormats;
4530706f2543Smrg	XF86VideoFormatPtr pFormats;
4531706f2543Smrg	int nPorts;
4532706f2543Smrg	DevUnion *pPortPrivates;
4533706f2543Smrg	int nAttributes;
4534706f2543Smrg	XF86AttributePtr pAttributes;
4535706f2543Smrg	int nImages;
4536706f2543Smrg	XF86ImagePtr pImages;
4537706f2543Smrg	PutVideoFuncPtr PutVideo;
4538706f2543Smrg	PutStillFuncPtr PutStill;
4539706f2543Smrg	GetVideoFuncPtr GetVideo;
4540706f2543Smrg	GetStillFuncPtr GetStill;
4541706f2543Smrg	StopVideoFuncPtr StopVideo;
4542706f2543Smrg	SetPortAttributeFuncPtr SetPortAttribute;
4543706f2543Smrg	GetPortAttributeFuncPtr GetPortAttribute;
4544706f2543Smrg	QueryBestSizeFuncPtr QueryBestSize;
4545706f2543Smrg	PutImageFuncPtr PutImage;
4546706f2543Smrg	QueryImageAttributesFuncPtr QueryImageAttributes;
4547706f2543Smrg} XF86VideoAdaptorRec, *XF86VideoAdaptorPtr;
4548706f2543Smrg      </programlisting></para>
4549706f2543Smrg
4550706f2543Smrg    <para>
4551706f2543SmrgEach adaptor will have its own XF86VideoAdaptorRec.  The fields are
4552706f2543Smrgas follows:
4553706f2543Smrg
4554706f2543Smrg      <variablelist>
4555706f2543Smrg	<varlistentry>
4556706f2543Smrg	  <term><structfield>type</structfield></term>
4557706f2543Smrg	  <listitem><para>
4558706f2543Smrg	This can be any of the following flags OR'd together.
4559706f2543Smrg
4560706f2543Smrg	      <variablelist>
4561706f2543Smrg		<varlistentry>
4562706f2543Smrg		  <term><constant>XvInputMask</constant>
4563706f2543Smrg		    <constant>XvOutputMask</constant></term>
4564706f2543Smrg		  <listitem><para>
4565706f2543Smrg	    These refer to the target drawable and are similar to a Window's
4566706f2543Smrg	    class. <literal remap="tt">XvInputMask</literal> indicates that the adaptor
4567706f2543Smrg	    can put video into a drawable.  <literal remap="tt">XvOutputMask</literal>
4568706f2543Smrg	    indicates that the adaptor can get video from a drawable.
4569706f2543Smrg		    </para></listitem></varlistentry>
4570706f2543Smrg
4571706f2543Smrg		<varlistentry>
4572706f2543Smrg		  <term><constant>XvVideoMask</constant>
4573706f2543Smrg		    <constant>XvStillMask</constant>
4574706f2543Smrg		    <constant>XvImageMask</constant></term>
4575706f2543Smrg		  <listitem><para>
4576706f2543Smrg	    These indicate that the adaptor supports video, still or
4577706f2543Smrg	    image primitives respectively.
4578706f2543Smrg		    </para></listitem></varlistentry>
4579706f2543Smrg
4580706f2543Smrg		<varlistentry>
4581706f2543Smrg		  <term><constant>XvWindowMask</constant>
4582706f2543Smrg		    <constant>XvPixmapMask</constant></term>
4583706f2543Smrg		  <listitem><para>
4584706f2543Smrg	    These indicate the types of drawables the adaptor is capable
4585706f2543Smrg	    of rendering into.  At the moment, Pixmap rendering is not
4586706f2543Smrg	    supported and the <constant>XvPixmapMask</constant> flag is ignored.
4587706f2543Smrg		    </para></listitem></varlistentry>
4588706f2543Smrg	      </variablelist>
4589706f2543Smrg
4590706f2543Smrg	    </para></listitem></varlistentry>
4591706f2543Smrg
4592706f2543Smrg	<varlistentry>
4593706f2543Smrg	  <term><structfield>flags</structfield></term>
4594706f2543Smrg	  <listitem><para>
4595706f2543Smrg	Currently, the following flags are defined:
4596706f2543Smrg
4597706f2543Smrg	      <variablelist>
4598706f2543Smrg		<varlistentry>
4599706f2543Smrg		  <term><constant>VIDEO_NO_CLIPPING</constant></term>
4600706f2543Smrg		  <listitem><para>
4601706f2543Smrg	   This indicates that the video adaptor does not support
4602706f2543Smrg	   clipping.  The driver will never receive <quote>Put</quote> requests
4603706f2543Smrg	   where less than the entire area determined by
4604706f2543Smrg	   <parameter>drw_x</parameter>, <parameter>drw_y</parameter>,
4605706f2543Smrg	   <parameter>drw_w</parameter> and <parameter>drw_h</parameter> is visible.
4606706f2543Smrg	   This flag does not apply to <quote>Get</quote> requests.  Hardware
4607706f2543Smrg	   that is incapable of clipping <quote>Gets</quote> may punt or get
4608706f2543Smrg	   the extents of the clipping region passed to it.
4609706f2543Smrg		    </para></listitem>
4610706f2543Smrg
4611706f2543Smrg		</varlistentry>
4612706f2543Smrg
4613706f2543Smrg		<varlistentry>
4614706f2543Smrg		  <term><constant>VIDEO_INVERT_CLIPLIST</constant></term>
4615706f2543Smrg		  <listitem><para>
4616706f2543Smrg	   This indicates that the video driver requires the clip
4617706f2543Smrg	   list to contain the regions which are obscured rather
4618706f2543Smrg	   than the regions which are are visible.
4619706f2543Smrg		    </para></listitem>
4620706f2543Smrg
4621706f2543Smrg		</varlistentry>
4622706f2543Smrg
4623706f2543Smrg		<varlistentry>
4624706f2543Smrg		  <term><constant>VIDEO_OVERLAID_STILLS</constant></term>
4625706f2543Smrg		  <listitem><para>
4626706f2543Smrg	   Implementing PutStill for hardware that does video as an
4627706f2543Smrg	   overlay can be awkward since it's unclear how long to leave
4628706f2543Smrg	   the video up for.  When this flag is set, StopVideo will be
4629706f2543Smrg	   called whenever the destination gets clipped or moved so that
4630706f2543Smrg	   the still can be left up until then.
4631706f2543Smrg		    </para></listitem>
4632706f2543Smrg
4633706f2543Smrg		</varlistentry>
4634706f2543Smrg
4635706f2543Smrg		<varlistentry>
4636706f2543Smrg		  <term><constant>VIDEO_OVERLAID_IMAGES</constant></term>
4637706f2543Smrg		  <listitem><para>
4638706f2543Smrg	   Same as <constant>VIDEO_OVERLAID_STILLS</constant> but for images.
4639706f2543Smrg		    </para></listitem>
4640706f2543Smrg		</varlistentry>
4641706f2543Smrg
4642706f2543Smrg		<varlistentry>
4643706f2543Smrg		  <term><constant>VIDEO_CLIP_TO_VIEWPORT</constant></term>
4644706f2543Smrg		  <listitem><para>
4645706f2543Smrg	    Indicates that the clip region passed to the driver functions
4646706f2543Smrg	    should be clipped to the visible portion of the screen in the
4647706f2543Smrg	    case where the viewport is smaller than the virtual desktop.
4648706f2543Smrg		    </para></listitem></varlistentry>
4649706f2543Smrg
4650706f2543Smrg	      </variablelist>
4651706f2543Smrg	    </para></listitem></varlistentry>
4652706f2543Smrg
4653706f2543Smrg	<varlistentry>
4654706f2543Smrg	  <term><structfield>name</structfield></term>
4655706f2543Smrg	  <listitem><para>
4656706f2543Smrg	The name of the adaptor.
4657706f2543Smrg	    </para></listitem></varlistentry>
4658706f2543Smrg
4659706f2543Smrg
4660706f2543Smrg	<varlistentry>
4661706f2543Smrg	  <term><structfield>nEncodings</structfield>
4662706f2543Smrg	    <structfield>pEncodings</structfield></term>
4663706f2543Smrg	  <listitem><para>
4664706f2543Smrg	The number of encodings the adaptor is capable of and pointer
4665706f2543Smrg	to the <structname>XF86VideoEncodingRec</structname> array.  The
4666706f2543Smrg	<structname>XF86VideoEncodingRec</structname> is described later on.
4667706f2543Smrg	For drivers that only support XvImages there should be an encoding
4668706f2543Smrg	named "XV_IMAGE" and the width and height should specify
4669706f2543Smrg	the maximum size source image supported.
4670706f2543Smrg	  </para></listitem></varlistentry>
4671706f2543Smrg
4672706f2543Smrg
4673706f2543Smrg	<varlistentry>
4674706f2543Smrg	  <term><structfield>nFormats</structfield>
4675706f2543Smrg	      <structfield>pFormats</structfield></term>
4676706f2543Smrg	  <listitem><para>
4677706f2543Smrg	The number of formats the adaptor is capable of and pointer to
4678706f2543Smrg	the <structname>XF86VideoFormatRec</structname> array.  The
4679706f2543Smrg	<structname>XF86VideoFormatRec</structname> is described later on.
4680706f2543Smrg	    </para></listitem></varlistentry>
4681706f2543Smrg
4682706f2543Smrg
4683706f2543Smrg	<varlistentry>
4684706f2543Smrg	  <term><structfield>nPorts</structfield>
4685706f2543Smrg	    <structfield>pPortPrivates</structfield></term>
4686706f2543Smrg	  <listitem><para>
4687706f2543Smrg	The number of ports is the number of separate data streams which
4688706f2543Smrg	the adaptor can handle simultaneously.  If you have more than
4689706f2543Smrg	one port, the adaptor is expected to be able to render into more
4690706f2543Smrg	than one window at a time.  <structfield>pPortPrivates</structfield> is
4691706f2543Smrg	an array of pointers or ints - one for each port.  A port's
4692706f2543Smrg	private data will be passed to the driver any time the port is
4693706f2543Smrg	requested to do something like put the video or stop the video.
4694706f2543Smrg	In the case where there may be many ports, this enables the
4695706f2543Smrg	driver to know which port the request is intended for.  Most
4696706f2543Smrg	commonly, this will contain a pointer to the data structure
4697706f2543Smrg	containing information about the port.  In Xv, all ports on
4698706f2543Smrg	a particular adaptor are expected to be identical in their
4699706f2543Smrg	functionality.
4700706f2543Smrg	    </para></listitem></varlistentry>
4701706f2543Smrg
4702706f2543Smrg
4703706f2543Smrg	<varlistentry>
4704706f2543Smrg	  <term><structfield>nAttributes</structfield>
4705706f2543Smrg	    <structfield>pAttributes</structfield></term>
4706706f2543Smrg	  <listitem><para>
4707706f2543Smrg	The number of attributes recognized by the adaptor and a pointer to
4708706f2543Smrg	the array of <structname>XF86AttributeRecs</structname>.  The
4709706f2543Smrg	<structname>XF86AttributeRec</structname> is described later on.
4710706f2543Smrg	    </para></listitem></varlistentry>
4711706f2543Smrg
4712706f2543Smrg
4713706f2543Smrg	<varlistentry>
4714706f2543Smrg	  <term><structfield>nImages</structfield>
4715706f2543Smrg	    <structfield>pImages</structfield></term>
4716706f2543Smrg	  <listitem><para>
4717706f2543Smrg	The number of <structname>XF86ImageRecs</structname> supported by the adaptor
4718706f2543Smrg	and a pointer to the array of <structname>XF86ImageRecs</structname>. The
4719706f2543Smrg	<structname>XF86ImageRec</structname> is described later on.
4720706f2543Smrg	    </para></listitem></varlistentry>
4721706f2543Smrg
4722706f2543Smrg
4723706f2543Smrg	<varlistentry>
4724706f2543Smrg	  <term><structfield>
4725706f2543Smrg     PutVideo PutStill GetVideo GetStill StopVideo
4726706f2543Smrg     SetPortAttribute GetPortAttribute QueryBestSize PutImage
4727706f2543Smrg     QueryImageAttributes
4728706f2543Smrg	    </structfield></term>
4729706f2543Smrg	  <listitem><para>
4730706f2543Smrg	These functions define the DDX-&gt;driver interface.  In each
4731706f2543Smrg	case, the pointer <parameter>data</parameter> is passed to the driver.
4732706f2543Smrg	This is the port private for that port as described above.  All
4733706f2543Smrg	fields are required except under the following conditions:
4734706f2543Smrg
4735706f2543Smrg	      <orderedlist>
4736706f2543Smrg		<listitem><para>
4737706f2543Smrg	     <structfield>PutVideo</structfield>, <structfield>PutStill</structfield> and
4738706f2543Smrg	     the image routines <structfield>PutImage</structfield> and
4739706f2543Smrg	     <structfield>QueryImageAttributes</structfield> are not required when the
4740706f2543Smrg	     adaptor type does not contain <constant>XvInputMask</constant>.
4741706f2543Smrg		  </para></listitem>
4742706f2543Smrg
4743706f2543Smrg		<listitem><para>
4744706f2543Smrg	     <structfield>GetVideo</structfield> and <structfield>GetStill</structfield>
4745706f2543Smrg	     are not required when the adaptor type does not contain
4746706f2543Smrg	     <constant>XvOutputMask</constant>.
4747706f2543Smrg		  </para></listitem>
4748706f2543Smrg
4749706f2543Smrg		<listitem><para>
4750706f2543Smrg	     <structfield>GetVideo</structfield> and <structfield>PutVideo</structfield>
4751706f2543Smrg	     are not required when the adaptor type does not contain
4752706f2543Smrg	     <constant>XvVideoMask</constant>.
4753706f2543Smrg		  </para></listitem>
4754706f2543Smrg
4755706f2543Smrg		<listitem><para>
4756706f2543Smrg	     <structfield>GetStill</structfield> and <structfield>PutStill</structfield>
4757706f2543Smrg	     are not required when the adaptor type does not contain
4758706f2543Smrg	     <constant>XvStillMask</constant>.
4759706f2543Smrg		  </para></listitem>
4760706f2543Smrg
4761706f2543Smrg		<listitem><para>
4762706f2543Smrg	     <structfield>PutImage</structfield> and <structfield>QueryImageAttributes</structfield>
4763706f2543Smrg	     are not required when the adaptor type does not contain
4764706f2543Smrg	     <constant>XvImageMask</constant>.
4765706f2543Smrg		  </para></listitem>
4766706f2543Smrg
4767706f2543Smrg	      </orderedlist>
4768706f2543Smrg
4769706f2543Smrg	    </para>
4770706f2543Smrg
4771706f2543Smrg	    <para>
4772706f2543Smrg	With the exception of <structfield>QueryImageAttributes</structfield>, these
4773706f2543Smrg	functions should return <constant>Success</constant> if the operation was
4774706f2543Smrg	completed successfully.  They can return <constant>XvBadAlloc</constant>
4775706f2543Smrg	otherwise. <structfield>QueryImageAttributes</structfield> returns the size
4776706f2543Smrg	of the XvImage queried.
4777706f2543Smrg	    </para>
4778706f2543Smrg
4779706f2543Smrg	    <para>
4780706f2543Smrg	If the <constant>VIDEO_NO_CLIPPING</constant>
4781706f2543Smrg	flag is set, the <literal remap="tt">clipBoxes</literal> may be ignored by
4782706f2543Smrg	the driver.  <literal remap="tt">ClipBoxes</literal> is an <literal remap="tt">X-Y</literal>
4783706f2543Smrg	banded region identical to those used throughout the server.
4784706f2543Smrg	The clipBoxes represent the visible portions of the area determined
4785706f2543Smrg	by <literal remap="tt">drw_x</literal>, <literal remap="tt">drw_y</literal>,
4786706f2543Smrg	<literal remap="tt">drw_w</literal> and <literal remap="tt">drw_h</literal> in the Get/Put
4787706f2543Smrg	function.  The boxes are in screen coordinates, are guaranteed
4788706f2543Smrg	not to overlap and an empty region will never be passed.
4789706f2543Smrg	If the driver has specified <constant>VIDEO_INVERT_CLIPLIST</constant>,
4790706f2543Smrg	<literal remap="tt">clipBoxes</literal> will indicate the areas of the primitive
4791706f2543Smrg	which are obscured rather than the areas visible.
4792706f2543Smrg
4793706f2543Smrg	    </para></listitem></varlistentry>
4794706f2543Smrg      </variablelist>
4795706f2543Smrg
4796706f2543Smrg      <blockquote><para>
4797706f2543Smrg	  <programlisting>
4798706f2543Smrg    typedef  int (* PutVideoFuncPtr)( ScrnInfoPtr pScrn,
4799706f2543Smrg                   short vid_x, short vid_y, short drw_x, short drw_y,
4800706f2543Smrg                   short vid_w, short vid_h, short drw_w, short drw_h,
4801706f2543Smrg                   RegionPtr clipBoxes, pointer data );
4802706f2543Smrg	  </programlisting>
4803706f2543Smrg	      <blockquote><para>
4804706f2543Smrg	  This indicates that the driver should take a subsection
4805706f2543Smrg	  <parameter>vid_w</parameter> by <parameter>vid_h</parameter> at location
4806706f2543Smrg	  <parameter>(vid_x,vid_y)</parameter> from the video stream and direct
4807706f2543Smrg	  it into the rectangle <parameter>drw_w</parameter> by <parameter>drw_h</parameter>
4808706f2543Smrg	  at location <parameter>(drw_x,drw_y)</parameter> on the screen, scaling as
4809706f2543Smrg	  necessary.  Due to the large variations in capabilities of
4810706f2543Smrg	  the various hardware expected to be used with this extension,
4811706f2543Smrg	  it is not expected that all hardware will be able to do this
4812706f2543Smrg	  exactly as described.  In that case the driver should just do
4813706f2543Smrg	  <quote>the best it can,</quote> scaling as closely to the target rectangle
4814706f2543Smrg	  as it can without rendering outside of it.  In the worst case,
4815706f2543Smrg	  the driver can opt to just not turn on the video.
4816706f2543Smrg	      </para>
4817706f2543Smrg
4818706f2543Smrg	    </blockquote></para></blockquote>
4819706f2543Smrg
4820706f2543Smrg	  <blockquote><para>
4821706f2543Smrg	      <programlisting>
4822706f2543Smrg    typedef  int (* PutStillFuncPtr)( ScrnInfoPtr pScrn,
4823706f2543Smrg                   short vid_x, short vid_y, short drw_x, short drw_y,
4824706f2543Smrg                   short vid_w, short vid_h, short drw_w, short drw_h,
4825706f2543Smrg                   RegionPtr clipBoxes, pointer data );
4826706f2543Smrg	      </programlisting>
4827706f2543Smrg	      <blockquote><para>
4828706f2543Smrg	  This is same as <structfield>PutVideo</structfield> except that the driver
4829706f2543Smrg	  should place only one frame from the stream on the screen.
4830706f2543Smrg	      </para>
4831706f2543Smrg
4832706f2543Smrg	    </blockquote></para></blockquote>
4833706f2543Smrg
4834706f2543Smrg	  <blockquote><para>
4835706f2543Smrg	      <programlisting>
4836706f2543Smrg    typedef int (* GetVideoFuncPtr)( ScrnInfoPtr pScrn,
4837706f2543Smrg                  short vid_x, short vid_y, short drw_x, short drw_y,
4838706f2543Smrg                  short vid_w, short vid_h, short drw_w, short drw_h,
4839706f2543Smrg                  RegionPtr clipBoxes, pointer data );
4840706f2543Smrg	      </programlisting>
4841706f2543Smrg	      <blockquote><para>
4842706f2543Smrg	  This is same as <structfield>PutVideo</structfield> except that the driver
4843706f2543Smrg	  gets video from the screen and outputs it.  The driver should
4844706f2543Smrg	  do the best it can to get the requested dimensions correct
4845706f2543Smrg	  without reading from an area larger than requested.
4846706f2543Smrg	      </para>
4847706f2543Smrg
4848706f2543Smrg	    </blockquote></para></blockquote>
4849706f2543Smrg
4850706f2543Smrg	  <blockquote><para>
4851706f2543Smrg	      <programlisting>
4852706f2543Smrg    typedef int (* GetStillFuncPtr)( ScrnInfoPtr pScrn,
4853706f2543Smrg                  short vid_x, short vid_y, short drw_x, short drw_y,
4854706f2543Smrg                  short vid_w, short vid_h, short drw_w, short drw_h,
4855706f2543Smrg                  RegionPtr clipBoxes, pointer data );
4856706f2543Smrg	      </programlisting>
4857706f2543Smrg	      <blockquote><para>
4858706f2543Smrg	  This is the same as <literal remap="tt">GetVideo</literal> except that the
4859706f2543Smrg	  driver should place only one frame from the screen into the
4860706f2543Smrg	  output stream.
4861706f2543Smrg	      </para>
4862706f2543Smrg
4863706f2543Smrg	    </blockquote></para></blockquote>
4864706f2543Smrg
4865706f2543Smrg	  <blockquote><para>
4866706f2543Smrg	      <programlisting>
4867706f2543Smrg    typedef void (* StopVideoFuncPtr)(ScrnInfoPtr pScrn,
4868706f2543Smrg                                      pointer data, Bool cleanup);
4869706f2543Smrg	      </programlisting>
4870706f2543Smrg	      <blockquote><para>
4871706f2543Smrg	  This indicates the driver should stop displaying the video.
4872706f2543Smrg	  This is used to stop both input and output video.  The
4873706f2543Smrg	  <parameter>cleanup</parameter> field indicates that the video is
4874706f2543Smrg	  being stopped because the client requested it to stop or
4875706f2543Smrg	  because the server is exiting the current VT.  In that case
4876706f2543Smrg	  the driver should deallocate any offscreen memory areas (if
4877706f2543Smrg	  there are any) being used to put the video to the screen.  If
4878706f2543Smrg	  <parameter>cleanup</parameter> is not set, the video is being stopped
4879706f2543Smrg	  temporarily due to clipping or moving of the window, etc...
4880706f2543Smrg	  and video will likely be restarted soon so the driver should
4881706f2543Smrg	  not deallocate any offscreen areas associated with that port.
4882706f2543Smrg	      </para>
4883706f2543Smrg
4884706f2543Smrg	    </blockquote></para></blockquote>
4885706f2543Smrg	  <blockquote><para>
4886706f2543Smrg	      <programlisting>
4887706f2543Smrg    typedef int (* SetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
4888706f2543Smrg                                Atom attribute,INT32 value, pointer data);
4889706f2543Smrg	      </programlisting>
4890706f2543Smrg
4891706f2543Smrg	      <programlisting>
4892706f2543Smrg    typedef int (* GetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
4893706f2543Smrg                                Atom attribute,INT32 *value, pointer data);
4894706f2543Smrg	      </programlisting>
4895706f2543Smrg	      <blockquote><para>
4896706f2543Smrg	  A port may have particular attributes such as hue,
4897706f2543Smrg	  saturation, brightness or contrast.  Xv clients set and
4898706f2543Smrg	  get these attribute values by sending attribute strings
4899706f2543Smrg	  (Atoms) to the server.  Such requests end up at these
4900706f2543Smrg	  driver functions.  It is recommended that the driver provide
4901706f2543Smrg	  at least the following attributes mentioned in the Xv client
4902706f2543Smrg	  library docs:
4903706f2543Smrg		<literallayout><constant>
4904706f2543Smrg		XV_ENCODING
4905706f2543Smrg		XV_HUE
4906706f2543Smrg		XV_SATURATION
4907706f2543Smrg		XV_BRIGHTNESS
4908706f2543Smrg  		XV_CONTRAST
4909706f2543Smrg		  </constant></literallayout>
4910706f2543Smrg	  but the driver may recognize as many atoms as it wishes.  If
4911706f2543Smrg	  a requested attribute is unknown by the driver it should return
4912706f2543Smrg	  <constant>BadMatch</constant>.  <constant>XV_ENCODING</constant> is the
4913706f2543Smrg	  attribute intended to let the client specify which video
4914706f2543Smrg	  encoding the particular port should be using (see the description
4915706f2543Smrg	  of <structname>XF86VideoEncodingRec</structname> below).  If the
4916706f2543Smrg	  requested encoding is unsupported, the driver should return
4917706f2543Smrg	  <constant>XvBadEncoding</constant>.  If the value lies outside the
4918706f2543Smrg	  advertised range <constant>BadValue</constant> may be returned.
4919706f2543Smrg	  <constant>Success</constant> should be returned otherwise.
4920706f2543Smrg	      </para>
4921706f2543Smrg
4922706f2543Smrg	    </blockquote></para></blockquote>
4923706f2543Smrg
4924706f2543Smrg	  <blockquote><para>
4925706f2543Smrg	    <programlisting>
4926706f2543Smrg    typedef void (* QueryBestSizeFuncPtr)(ScrnInfoPtr pScrn,
4927706f2543Smrg                   Bool motion, short vid_w, short vid_h,
4928706f2543Smrg                   short drw_w, short drw_h,
4929706f2543Smrg                   unsigned int *p_w, unsigned int *p_h, pointer data);
4930706f2543Smrg	    </programlisting>
4931706f2543Smrg	    <blockquote><para>
4932706f2543Smrg	   <function>QueryBestSize</function> provides the client with a way
4933706f2543Smrg	   to query what the destination dimensions would end up being
4934706f2543Smrg	   if they were to request that an area
4935706f2543Smrg	   <parameter>vid_w</parameter> by <parameter>vid_h</parameter> from the video
4936706f2543Smrg	   stream be scaled to rectangle of
4937706f2543Smrg	   <parameter>drw_w</parameter> by <parameter>drw_h</parameter> on the screen.
4938706f2543Smrg	   Since it is not expected that all hardware will be able to
4939706f2543Smrg	   get the target dimensions exactly, it is important that the
4940706f2543Smrg	   driver provide this function.
4941706f2543Smrg	      </para>
4942706f2543Smrg
4943706f2543Smrg	    </blockquote></para></blockquote>
4944706f2543Smrg
4945706f2543Smrg	<blockquote><para>
4946706f2543Smrg	    <programlisting>
4947706f2543Smrg    typedef  int (* PutImageFuncPtr)( ScrnInfoPtr pScrn,
4948706f2543Smrg                   short src_x, short src_y, short drw_x, short drw_y,
4949706f2543Smrg                   short src_w, short src_h, short drw_w, short drw_h,
4950706f2543Smrg                   int image, char *buf, short width, short height,
4951706f2543Smrg                   Bool sync, RegionPtr clipBoxes, pointer data );
4952706f2543Smrg	      </programlisting>
4953706f2543Smrg	      <blockquote><para>
4954706f2543Smrg	  This is similar to <structfield>PutStill</structfield> except that the
4955706f2543Smrg	  source of the video is not a port but the data stored in a system
4956706f2543Smrg	  memory buffer at <parameter>buf</parameter>.  The data is in the format
4957706f2543Smrg	  indicated by the <parameter>image</parameter> descriptor and represents a
4958706f2543Smrg	  source of size <parameter>width</parameter> by <parameter>height</parameter>.
4959706f2543Smrg	  If <parameter>sync</parameter> is TRUE the driver should not return
4960706f2543Smrg	  from this function until it is through reading the data
4961706f2543Smrg	  from <parameter>buf</parameter>.  Returning when <parameter>sync</parameter>
4962706f2543Smrg	  is TRUE indicates that it is safe for the data at <parameter>buf</parameter>
4963706f2543Smrg	  to be replaced, freed, or modified.
4964706f2543Smrg	      </para>
4965706f2543Smrg
4966706f2543Smrg	    </blockquote></para></blockquote>
4967706f2543Smrg
4968706f2543Smrg	<blockquote><para>
4969706f2543Smrg	    <programlisting>
4970706f2543Smrg    typedef  int (* QueryImageAttributesFuncPtr)( ScrnInfoPtr pScrn,
4971706f2543Smrg                                int image, short *width, short *height,
4972706f2543Smrg                                int *pitches, int *offsets);
4973706f2543Smrg	    </programlisting>
4974706f2543Smrg	    <blockquote><para>
4975706f2543Smrg	  This function is called to let the driver specify how data for
4976706f2543Smrg	  a particular <parameter>image</parameter> of size <parameter>width</parameter>
4977706f2543Smrg	  by <parameter>height</parameter> should be stored.  Sometimes only
4978706f2543Smrg	  the size and corrected width and height are needed.  In that
4979706f2543Smrg	  case <parameter>pitches</parameter> and <parameter>offsets</parameter> are
4980706f2543Smrg	  NULL.  The size of the memory required for the image is returned
4981706f2543Smrg	  by this function.  The <parameter>width</parameter> and
4982706f2543Smrg	  <parameter>height</parameter> of the requested image can be altered by
4983706f2543Smrg	  the driver to reflect format limitations (such as component
4984706f2543Smrg	  sampling periods that are larger than one).  If
4985706f2543Smrg	  <parameter>pitches</parameter> and <parameter>offsets</parameter> are not NULL,
4986706f2543Smrg	  these will be arrays with as many elements in them as there
4987706f2543Smrg	  are planes in the <parameter>image</parameter> format.  The driver
4988706f2543Smrg	  should specify the pitch (in bytes) of each scanline in the
4989706f2543Smrg	  particular plane as well as the offset to that plane (in bytes)
4990706f2543Smrg	  from the beginning of the image.
4991706f2543Smrg	      </para>
4992706f2543Smrg
4993706f2543Smrg	  </blockquote></para></blockquote>
4994706f2543Smrg    </para>
4995706f2543Smrg
4996706f2543Smrg    <para>
4997706f2543SmrgThe XF86VideoEncodingRec:
4998706f2543Smrg
4999706f2543Smrg      <blockquote><para>
5000706f2543Smrg	  <programlisting>
5001706f2543Smrgtypedef struct {
5002706f2543Smrg	int id;
5003706f2543Smrg	char *name;
5004706f2543Smrg	unsigned short width, height;
5005706f2543Smrg	XvRationalRec rate;
5006706f2543Smrg} XF86VideoEncodingRec, *XF86VideoEncodingPtr;
5007706f2543Smrg
5008706f2543Smrg	  </programlisting>
5009706f2543Smrg	  <blockquote><para>
5010706f2543Smrg   The <structname>XF86VideoEncodingRec</structname> specifies what encodings
5011706f2543Smrg   the adaptor can support.  Most of this data is just informational
5012706f2543Smrg   and for the client's benefit, and is what will be reported by
5013706f2543Smrg   <function>XvQueryEncodings</function>.  The <parameter>id</parameter> field is
5014706f2543Smrg   expected to be a unique identifier to allow the client to request a
5015706f2543Smrg   certain encoding via the <constant>XV_ENCODING</constant> attribute string.
5016706f2543Smrg
5017706f2543Smrg	    </para>
5018706f2543Smrg	  </blockquote></para></blockquote>
5019706f2543Smrg    </para>
5020706f2543Smrg
5021706f2543Smrg    <para>
5022706f2543SmrgThe XF86VideoFormatRec:
5023706f2543Smrg
5024706f2543Smrg      <blockquote><para>
5025706f2543Smrg	  <programlisting>
5026706f2543Smrgtypedef struct {
5027706f2543Smrg	char  depth;
5028706f2543Smrg	short class;
5029706f2543Smrg} XF86VideoFormatRec, *XF86VideoFormatPtr;
5030706f2543Smrg
5031706f2543Smrg	  </programlisting>
5032706f2543Smrg	  <blockquote><para>
5033706f2543Smrg    This specifies what visuals the video is viewable in.
5034706f2543Smrg    <parameter>depth</parameter> is the depth of the visual (not bpp).
5035706f2543Smrg    <parameter>class</parameter> is the visual class such as
5036706f2543Smrg    <constant>TrueColor</constant>, <constant>DirectColor</constant> or
5037706f2543Smrg    <constant>PseudoColor</constant>.  Initialization of an adaptor will fail
5038706f2543Smrg    if none of the visuals on that screen are supported.
5039706f2543Smrg	    </para>
5040706f2543Smrg
5041706f2543Smrg	  </blockquote></para></blockquote>
5042706f2543Smrg    </para>
5043706f2543Smrg
5044706f2543Smrg    <para>
5045706f2543SmrgThe XF86AttributeRec:
5046706f2543Smrg
5047706f2543Smrg      <blockquote><para>
5048706f2543Smrg	  <programlisting>
5049706f2543Smrgtypedef struct {
5050706f2543Smrg	int   flags;
5051706f2543Smrg	int   min_value;
5052706f2543Smrg	int   max_value;
5053706f2543Smrg	char  *name;
5054706f2543Smrg} XF86AttributeListRec, *XF86AttributeListPtr;
5055706f2543Smrg
5056706f2543Smrg	  </programlisting>
5057706f2543Smrg	  <blockquote><para>
5058706f2543Smrg   Each adaptor may have an array of these advertising the attributes
5059706f2543Smrg   for its ports.  Currently defined flags are <literal remap="tt">XvGettable</literal>
5060706f2543Smrg   and <literal remap="tt">XvSettable</literal> which may be OR'd together indicating that
5061706f2543Smrg   attribute is <quote>gettable</quote> or <quote>settable</quote> by the client.  The
5062706f2543Smrg   <literal remap="tt">min</literal> and <literal remap="tt">max</literal> field specify the valid range
5063706f2543Smrg   for the value.  <literal remap="tt">Name</literal> is a text string describing the
5064706f2543Smrg   attribute by name.
5065706f2543Smrg	    </para>
5066706f2543Smrg
5067706f2543Smrg	  </blockquote></para></blockquote>
5068706f2543Smrg
5069706f2543Smrg    </para>
5070706f2543Smrg
5071706f2543Smrg    <para>
5072706f2543SmrgThe XF86ImageRec:
5073706f2543Smrg
5074706f2543Smrg	<blockquote><para>
5075706f2543Smrg	    <programlisting>
5076706f2543Smrgtypedef struct {
5077706f2543Smrg	int id;
5078706f2543Smrg	int type;
5079706f2543Smrg	int byte_order;
5080706f2543Smrg	char guid[16];
5081706f2543Smrg	int bits_per_pixel;
5082706f2543Smrg	int format;
5083706f2543Smrg	int num_planes;
5084706f2543Smrg
5085706f2543Smrg	/* for RGB formats */
5086706f2543Smrg	int depth;
5087706f2543Smrg	unsigned int red_mask;
5088706f2543Smrg	unsigned int green_mask;
5089706f2543Smrg	unsigned int blue_mask;
5090706f2543Smrg
5091706f2543Smrg	/* for YUV formats */
5092706f2543Smrg	unsigned int y_sample_bits;
5093706f2543Smrg	unsigned int u_sample_bits;
5094706f2543Smrg	unsigned int v_sample_bits;
5095706f2543Smrg	unsigned int horz_y_period;
5096706f2543Smrg	unsigned int horz_u_period;
5097706f2543Smrg	unsigned int horz_v_period;
5098706f2543Smrg	unsigned int vert_y_period;
5099706f2543Smrg	unsigned int vert_u_period;
5100706f2543Smrg	unsigned int vert_v_period;
5101706f2543Smrg	char component_order[32];
5102706f2543Smrg	int scanline_order;
5103706f2543Smrg} XF86ImageRec, *XF86ImagePtr;
5104706f2543Smrg
5105706f2543Smrg	    </programlisting>
5106706f2543Smrg	    <blockquote><para>
5107706f2543Smrg   XF86ImageRec describes how video source data is laid out in memory.
5108706f2543Smrg   The fields are as follows:
5109706f2543Smrg
5110706f2543Smrg		<variablelist>
5111706f2543Smrg		  <varlistentry>
5112706f2543Smrg		    <term><structfield>id</structfield></term>
5113706f2543Smrg		    <listitem><para>
5114706f2543Smrg	This is a unique descriptor for the format.  It is often good to
5115706f2543Smrg        set this value to the FOURCC for the format when applicable.
5116706f2543Smrg		      </para></listitem></varlistentry>
5117706f2543Smrg
5118706f2543Smrg		  <varlistentry>
5119706f2543Smrg		    <term><structfield>type</structfield></term>
5120706f2543Smrg		    <listitem><para>
5121706f2543Smrg	This is <constant>XvRGB</constant> or <constant>XvYUV</constant>.
5122706f2543Smrg		      </para></listitem></varlistentry>
5123706f2543Smrg
5124706f2543Smrg		  <varlistentry>
5125706f2543Smrg		    <term><structfield>byte_order</structfield></term>
5126706f2543Smrg		    <listitem><para>
5127706f2543Smrg	This is <constant>LSBFirst</constant> or <constant>MSBFirst</constant>.
5128706f2543Smrg		      </para></listitem></varlistentry>
5129706f2543Smrg
5130706f2543Smrg		  <varlistentry>
5131706f2543Smrg		    <term><structfield>guid</structfield></term>
5132706f2543Smrg		    <listitem><para>
5133706f2543Smrg	This is the Globally Unique IDentifier for the format.  When
5134706f2543Smrg	not applicable, all characters should be NULL.
5135706f2543Smrg		      </para></listitem></varlistentry>
5136706f2543Smrg
5137706f2543Smrg		  <varlistentry>
5138706f2543Smrg		    <term><structfield>bits_per_pixel</structfield></term>
5139706f2543Smrg		    <listitem><para>
5140706f2543Smrg	The number of bits taken up (but not necessarily used) by each
5141706f2543Smrg	pixel.  Note that for some planar formats which have fractional
5142706f2543Smrg	bits per pixel (such as IF09) this number may be rounded _down_.
5143706f2543Smrg		      </para></listitem></varlistentry>
5144706f2543Smrg
5145706f2543Smrg		  <varlistentry>
5146706f2543Smrg		    <term><structfield>format</structfield></term>
5147706f2543Smrg		    <listitem><para>
5148706f2543Smrg	This is <constant>XvPlanar</constant> or <constant>XvPacked</constant>.
5149706f2543Smrg		      </para></listitem></varlistentry>
5150706f2543Smrg
5151706f2543Smrg		  <varlistentry>
5152706f2543Smrg		    <term><structfield>num_planes</structfield></term>
5153706f2543Smrg		    <listitem><para>
5154706f2543Smrg	The number of planes in planar formats.  This should be set to
5155706f2543Smrg	one for packed formats.
5156706f2543Smrg		      </para></listitem></varlistentry>
5157706f2543Smrg
5158706f2543Smrg		  <varlistentry>
5159706f2543Smrg		    <term><structfield>depth</structfield></term>
5160706f2543Smrg		    <listitem><para>
5161706f2543Smrg	The significant bits per pixel in RGB formats (analgous to the
5162706f2543Smrg	depth of a pixmap format).
5163706f2543Smrg		      </para></listitem></varlistentry>
5164706f2543Smrg
5165706f2543Smrg		  <varlistentry>
5166706f2543Smrg		    <term><structfield>red_mask</structfield></term>
5167706f2543Smrg		    <term><structfield>green_mask</structfield></term>
5168706f2543Smrg		    <term><structfield>blue_mask</structfield></term>
5169706f2543Smrg		    <listitem><para>
5170706f2543Smrg	The red, green and blue bitmasks for packed RGB formats.
5171706f2543Smrg		      </para></listitem></varlistentry>
5172706f2543Smrg
5173706f2543Smrg		  <varlistentry>
5174706f2543Smrg		    <term><structfield>y_sample_bits</structfield></term>
5175706f2543Smrg		    <term><structfield>u_sample_bits</structfield></term>
5176706f2543Smrg		    <term><structfield>v_sample_bits</structfield></term>
5177706f2543Smrg		    <listitem><para>
5178706f2543Smrg	The y, u and v sample sizes (in bits).
5179706f2543Smrg		      </para></listitem></varlistentry>
5180706f2543Smrg
5181706f2543Smrg		  <varlistentry>
5182706f2543Smrg		    <term><structfield>horz_y_period</structfield></term>
5183706f2543Smrg		    <term><structfield>horz_u_period</structfield></term>
5184706f2543Smrg		    <term><structfield>horz_v_period</structfield></term>
5185706f2543Smrg		    <listitem><para>
5186706f2543Smrg	The y, u and v sampling periods in the horizontal direction.
5187706f2543Smrg		      </para></listitem></varlistentry>
5188706f2543Smrg
5189706f2543Smrg		  <varlistentry>
5190706f2543Smrg		    <term><structfield>vert_y_period</structfield></term>
5191706f2543Smrg		    <term><structfield>vert_u_period</structfield></term>
5192706f2543Smrg		    <term><structfield>vert_v_period</structfield></term>
5193706f2543Smrg		    <listitem><para>
5194706f2543Smrg	The y, u and v sampling periods in the vertical direction.
5195706f2543Smrg		      </para></listitem></varlistentry>
5196706f2543Smrg
5197706f2543Smrg		  <varlistentry>
5198706f2543Smrg		    <term><structfield>component_order</structfield></term>
5199706f2543Smrg		    <listitem><para>
5200706f2543Smrg	Uppercase ascii characters representing the order that
5201706f2543Smrg	samples are stored within packed formats.  For planar formats
5202706f2543Smrg	this represents the ordering of the planes.  Unused characters
5203706f2543Smrg	in the 32 byte string should be set to NULL.
5204706f2543Smrg		      </para></listitem></varlistentry>
5205706f2543Smrg
5206706f2543Smrg		  <varlistentry>
5207706f2543Smrg		    <term><structfield>scanline_order</structfield></term>
5208706f2543Smrg		    <listitem><para>
5209706f2543Smrg	This is <constant>XvTopToBottom</constant> or <constant>XvBottomToTop</constant>.
5210706f2543Smrg		      </para></listitem></varlistentry>
5211706f2543Smrg
5212706f2543Smrg		  </variablelist>
5213706f2543Smrg	    </para>
5214706f2543Smrg
5215706f2543Smrg	    <para>
5216706f2543Smrg  Since some formats (particular some planar YUV formats) may not
5217706f2543Smrgbe completely defined by the parameters above, the guid, when
5218706f2543Smrgavailable, should provide the most accurate description of the
5219706f2543Smrgformat.
5220706f2543Smrg	    </para>
5221706f2543Smrg
5222706f2543Smrg	  </blockquote></para></blockquote>
5223706f2543Smrg    </para>
5224706f2543Smrg  </sect1>
5225706f2543Smrg
5226706f2543Smrg  <sect1>
5227706f2543Smrg    <title>The Loader</title>
5228706f2543Smrg
5229706f2543Smrg    <para>
5230706f2543SmrgThis section describes the interfaces to the module loader.  The loader
5231706f2543Smrginterfaces can be divided into two groups: those that are only available to
5232706f2543Smrgthe XFree86 common layer, and those that are also available to modules.
5233706f2543Smrg    </para>
5234706f2543Smrg
5235706f2543Smrg    <sect2>
5236706f2543Smrg      <title>Loader Overview</title>
5237706f2543Smrg
5238706f2543Smrg      <para>
5239706f2543SmrgThe loader is capable of loading modules in a range of object formats,
5240706f2543Smrgand knowledge of these formats is built in to the loader.  Knowledge of
5241706f2543Smrgnew object formats can be added to the loader in a straightforward
5242706f2543Smrgmanner.  This makes it possible to provide OS-independent modules (for
5243706f2543Smrga given CPU architecture type).  In addition to this, the loader can
5244706f2543Smrgload modules via the OS-provided <function>dlopen(3)</function> service where
5245706f2543Smrgavailable.  Such modules are not platform independent, and the semantics
5246706f2543Smrgof <function>dlopen()</function> on most systems results in significant
5247706f2543Smrglimitations in the use of modules of this type.  Support for
5248706f2543Smrg<function>dlopen()</function> modules in the loader is primarily for
5249706f2543Smrgexperimental and development purposes.
5250706f2543Smrg      </para>
5251706f2543Smrg
5252706f2543Smrg      <para>
5253706f2543SmrgSymbols exported by the loader (on behalf of the core X server) to
5254706f2543Smrgmodules are determined at compile time.  Only those symbols explicitly
5255706f2543Smrgexported are available to modules.  All external symbols of loaded
5256706f2543Smrgmodules are exported to other modules, and to the core X server.  The
5257706f2543Smrgloader can be requested to check for unresolved symbols at any time,
5258706f2543Smrgand the action to be taken for unresolved symbols can be controlled by
5259706f2543Smrgthe caller of the loader.  Typically the caller identifies which symbols
5260706f2543Smrgcan safely remain unresolved and which cannot.
5261706f2543Smrg      </para>
5262706f2543Smrg
5263706f2543Smrg      <para>
5264706f2543SmrgNOTE:  Now that ISO-C allows pointers to functions and pointers to data to
5265706f2543Smrghave different internal representations, some of the following interfaces
5266706f2543Smrgwill need to be revisited.
5267706f2543Smrg      </para>
5268706f2543Smrg    </sect2>
5269706f2543Smrg
5270706f2543Smrg    <sect2>
5271706f2543Smrg      <title>Semi-private Loader Interface</title>
5272706f2543Smrg
5273706f2543Smrg      <para>
5274706f2543SmrgThe following is the semi-private loader interface that is available to the
5275706f2543SmrgXFree86 common layer.
5276706f2543Smrg      </para>
5277706f2543Smrg
5278706f2543Smrg      <blockquote><para>
5279706f2543Smrg	  <programlisting>
5280706f2543Smrg    void LoaderInit(void);
5281706f2543Smrg	  </programlisting>
5282706f2543Smrg	  <blockquote><para>
5283706f2543Smrg    The <function>LoaderInit()</function> function initialises the loader,
5284706f2543Smrg    and it must be called once before calling any other loader functions.
5285706f2543Smrg    This function initialises the tables of exported symbols, and anything
5286706f2543Smrg    else that might need to be initialised.
5287706f2543Smrg	    </para>
5288706f2543Smrg
5289706f2543Smrg	  </blockquote></para></blockquote>
5290706f2543Smrg
5291706f2543Smrg      <blockquote><para>
5292706f2543Smrg	  <programlisting>
5293706f2543Smrg    void LoaderSetPath(const char *path);
5294706f2543Smrg	  </programlisting>
5295706f2543Smrg	  <blockquote><para>
5296706f2543Smrg    The <function>LoaderSetPath()</function> function initialises a default
5297706f2543Smrg    module search path.  This must be called if calls to other functions
5298706f2543Smrg    are to be made without explicitly specifying a module search path.
5299706f2543Smrg    The search path <parameter>path</parameter> must be a string of one or more
5300706f2543Smrg    comma separated absolute paths.  Modules are expected to be located
5301706f2543Smrg    below these paths, possibly in subdirectories of these paths.
5302706f2543Smrg	    </para>
5303706f2543Smrg
5304706f2543Smrg	  </blockquote></para></blockquote>
5305706f2543Smrg
5306706f2543Smrg      <blockquote><para>
5307706f2543Smrg	  <programlisting>
5308706f2543Smrg    pointer LoadModule(const char *module, const char *path,
5309706f2543Smrg                       const char **subdirlist, const char **patternlist,
5310706f2543Smrg                       pointer options, const XF86ModReqInfo * modreq,
5311706f2543Smrg                       int *errmaj, int *errmin);
5312706f2543Smrg	  </programlisting>
5313706f2543Smrg	  <blockquote><para>
5314706f2543Smrg    The <function>LoadModule()</function> function loads the module called
5315706f2543Smrg    <parameter>module</parameter>.  The return value is a module handle, and
5316706f2543Smrg    may be used in future calls to the loader that require a reference
5317706f2543Smrg    to a loaded module.  The module name <parameter>module</parameter> is
5318706f2543Smrg    normally the module's canonical name, which doesn't contain any
5319706f2543Smrg    directory path information, or any object/library file prefixes of
5320706f2543Smrg    suffixes.  Currently a full pathname and/or filename is also accepted.
5321706f2543Smrg    This might change.  The other parameters are:
5322706f2543Smrg
5323706f2543Smrg	      <variablelist>
5324706f2543Smrg		<varlistentry>
5325706f2543Smrg		  <term><parameter>path</parameter></term>
5326706f2543Smrg		  <listitem><para>
5327706f2543Smrg		  An optional comma-separated list of module search paths.
5328706f2543Smrg		  When <constant>NULL</constant>, the default search path is used.
5329706f2543Smrg		    </para></listitem></varlistentry>
5330706f2543Smrg
5331706f2543Smrg
5332706f2543Smrg		<varlistentry>
5333706f2543Smrg		  <term><parameter>subdirlist</parameter></term>
5334706f2543Smrg		  <listitem><para>
5335706f2543Smrg		  An optional <constant>NULL</constant> terminated list of
5336706f2543Smrg		  subdirectories to search.  When <constant>NULL</constant>,
5337706f2543Smrg		  the default built-in list is used (refer to
5338706f2543Smrg		  <varname>stdSubdirs</varname> in <filename>loadmod.c</filename>).
5339706f2543Smrg		  The default list is also substituted for entries in
5340706f2543Smrg		  <parameter>subdirlist</parameter> with the value
5341706f2543Smrg		  <constant>DEFAULT_LIST</constant>.  This makes is possible
5342706f2543Smrg		  to augment the default list instead of replacing it.
5343706f2543Smrg		  Subdir elements must be relative, and must not contain
5344706f2543Smrg		  <literal remap="tt">".."</literal>.  If any violate this requirement,
5345706f2543Smrg		  the load fails.
5346706f2543Smrg		    </para></listitem></varlistentry>
5347706f2543Smrg
5348706f2543Smrg
5349706f2543Smrg		<varlistentry>
5350706f2543Smrg		  <term><parameter>patternlist</parameter></term>
5351706f2543Smrg		  <listitem><para>
5352706f2543Smrg		  An optional <constant>NULL</constant> terminated list of
5353706f2543Smrg		  POSIX regular expressions used to connect module
5354706f2543Smrg		  filenames with canonical module names.  Each regex
5355706f2543Smrg		  should contain exactly one subexpression that corresponds
5356706f2543Smrg		  to the canonical module name.  When <constant>NULL</constant>,
5357706f2543Smrg		  the default built-in list is used (refer to
5358706f2543Smrg		  <varname>stdPatterns</varname> in
5359706f2543Smrg		  <filename>loadmod.c</filename>).  The default list is also
5360706f2543Smrg		  substituted for entries in <parameter>patternlist</parameter>
5361706f2543Smrg		  with the value <constant>DEFAULT_LIST</constant>.  This
5362706f2543Smrg		  makes it possible to augment the default list instead
5363706f2543Smrg		  of replacing it.
5364706f2543Smrg		    </para></listitem></varlistentry>
5365706f2543Smrg
5366706f2543Smrg
5367706f2543Smrg		<varlistentry>
5368706f2543Smrg		  <term><parameter>options</parameter></term>
5369706f2543Smrg		  <listitem><para>
5370706f2543Smrg		  An optional parameter that is passed to the newly
5371706f2543Smrg		  loaded module's <literal remap="tt">SetupProc</literal> function
5372706f2543Smrg		  (if it has one).  This argument is normally a
5373706f2543Smrg		  <constant>NULL</constant> terminated list of
5374706f2543Smrg		  <structname>Options</structname>, and must be interpreted that
5375706f2543Smrg		  way by modules loaded directly by the XFree86 common
5376706f2543Smrg		  layer.  However, it may be used for application-specific
5377706f2543Smrg		  parameter passing in other situations.
5378706f2543Smrg		    </para>
5379706f2543Smrg
5380706f2543Smrg		    <para>
5381706f2543Smrg		  When loading <quote>external</quote> modules (modules that don't
5382706f2543Smrg		  have the standard entry point, for example a
5383706f2543Smrg		  special shared library) the options parameter can be
5384706f2543Smrg		  set to <constant>EXTERN_MODULE</constant> to tell the
5385706f2543Smrg		  loader not to reject the module when it doesn't find
5386706f2543Smrg		  the standard entry point.
5387706f2543Smrg		    </para></listitem></varlistentry>
5388706f2543Smrg
5389706f2543Smrg
5390706f2543Smrg		<varlistentry>
5391706f2543Smrg		  <term><parameter>modreq</parameter></term>
5392706f2543Smrg		  <listitem><para>
5393706f2543Smrg		  An optional <structname>XF86ModReqInfo*</structname> containing
5394706f2543Smrg		  version/ABI/vendor information to requirements to
5395706f2543Smrg		  check the newly loaded module against.  The main
5396706f2543Smrg		  purpose of this is to allow the loader to verify that
5397706f2543Smrg		  a module of the correct type/version before running
5398706f2543Smrg		  its <function>SetupProc</function> function.
5399706f2543Smrg		      </para>
5400706f2543Smrg
5401706f2543Smrg		    <para>
5402706f2543Smrg		  The <literal remap="tt">XF86ModReqInfo</literal> struct is defined
5403706f2543Smrg		  as follows:
5404706f2543Smrg		      <programlisting>
5405706f2543Smrgtypedef struct {
5406706f2543Smrg	CARD8        majorversion;  /* MAJOR_UNSPEC */
5407706f2543Smrg	CARD8        minorversion;  /* MINOR_UNSPEC */
5408706f2543Smrg	CARD16       patchlevel;    /* PATCH_UNSPEC */
5409706f2543Smrg	const char * abiclass;      /* ABI_CLASS_NONE */
5410706f2543Smrg	CARD32       abiversion;    /* ABI_VERS_UNSPEC */
5411706f2543Smrg	const char * moduleclass;   /* MOD_CLASS_NONE */
5412706f2543Smrg} XF86ModReqInfo;
5413706f2543Smrg			</programlisting>
5414706f2543Smrg
5415706f2543Smrg		  The information here is compared against the equivalent
5416706f2543Smrg		  information in the module's
5417706f2543Smrg		  <structname>XF86ModuleVersionInfo</structname> record (which
5418706f2543Smrg		  is described below).  The values in comments above
5419706f2543Smrg		  indicate <quote>don't care</quote> settings for each of the fields.
5420706f2543Smrg		  The comparisons made are as follows:
5421706f2543Smrg
5422706f2543Smrg		      <variablelist>
5423706f2543Smrg			<varlistentry>
5424706f2543Smrg			  <term><structfield>majorversion</structfield></term>
5425706f2543Smrg			  <listitem><para>
5426706f2543Smrg				   Must match the module's majorversion
5427706f2543Smrg				   exactly.
5428706f2543Smrg			    </para></listitem></varlistentry>
5429706f2543Smrg
5430706f2543Smrg			<varlistentry>
5431706f2543Smrg			  <term><structfield>minorversion</structfield></term>
5432706f2543Smrg			  <listitem><para>
5433706f2543Smrg				   The module's minor version must be
5434706f2543Smrg				   no less than this value.  This
5435706f2543Smrg				   comparison is only made if
5436706f2543Smrg				   <structfield>majorversion</structfield> is
5437706f2543Smrg				   specified and matches.
5438706f2543Smrg			    </para></listitem></varlistentry>
5439706f2543Smrg
5440706f2543Smrg			<varlistentry>
5441706f2543Smrg			  <term><structfield>patchlevel</structfield></term>
5442706f2543Smrg			  <listitem><para>
5443706f2543Smrg				   The module's patchlevel must be no
5444706f2543Smrg				   less than this value.  This comparison
5445706f2543Smrg				   is only made if
5446706f2543Smrg				   <structfield>minorversion</structfield> is
5447706f2543Smrg				   specified and matches.
5448706f2543Smrg			    </para></listitem></varlistentry>
5449706f2543Smrg
5450706f2543Smrg			<varlistentry>
5451706f2543Smrg			  <term><structfield>abiclass</structfield></term>
5452706f2543Smrg			  <listitem><para>
5453706f2543Smrg				   String must match the module's abiclass
5454706f2543Smrg				   string.
5455706f2543Smrg			    </para></listitem></varlistentry>
5456706f2543Smrg
5457706f2543Smrg			<varlistentry>
5458706f2543Smrg			  <term><structfield>abiversion</structfield></term>
5459706f2543Smrg			  <listitem><para>
5460706f2543Smrg				   Must be consistent with the module's
5461706f2543Smrg				   abiversion (major equal, minor no
5462706f2543Smrg				   older).
5463706f2543Smrg			    </para></listitem></varlistentry>
5464706f2543Smrg
5465706f2543Smrg			<varlistentry>
5466706f2543Smrg			  <term><structfield>moduleclass</structfield></term>
5467706f2543Smrg			  <listitem><para>
5468706f2543Smrg				   String must match the module's
5469706f2543Smrg				   moduleclass string.
5470706f2543Smrg			    </para></listitem></varlistentry>
5471706f2543Smrg
5472706f2543Smrg		      </variablelist>
5473706f2543Smrg		    </para></listitem></varlistentry>
5474706f2543Smrg
5475706f2543Smrg		<varlistentry>
5476706f2543Smrg		  <term><parameter>errmaj</parameter></term>
5477706f2543Smrg		  <listitem><para>
5478706f2543Smrg		  An optional pointer to a variable holding the major
5479706f2543Smrg		  part or the error code.  When provided,
5480706f2543Smrg		  <parameter>*errmaj</parameter> is filled in when
5481706f2543Smrg		  <function>LoadModule()</function> fails.
5482706f2543Smrg		    </para></listitem></varlistentry>
5483706f2543Smrg
5484706f2543Smrg		<varlistentry>
5485706f2543Smrg		  <term><parameter>errmin</parameter></term>
5486706f2543Smrg		  <listitem><para>
5487706f2543Smrg		  Like <parameter>errmaj</parameter>, but for the minor part
5488706f2543Smrg		  of the error code.
5489706f2543Smrg		    </para></listitem></varlistentry>
5490706f2543Smrg
5491706f2543Smrg	      </variablelist>
5492706f2543Smrg
5493706f2543Smrg	    </para></blockquote>
5494706f2543Smrg	</para></blockquote>
5495706f2543Smrg
5496706f2543Smrg      <blockquote><para>
5497706f2543Smrg	  <programlisting>
5498706f2543Smrg    void UnloadModule(pointer mod);
5499706f2543Smrg	  </programlisting>
5500706f2543Smrg	  <blockquote><para>
5501706f2543Smrg    This function unloads the module referred to by the handle mod.
5502706f2543Smrg    All child modules are also unloaded recursively.  This function must
5503706f2543Smrg    not be used to directly unload modules that are child modules (i.e.,
5504706f2543Smrg    those that have been loaded with the <function>LoadSubModule()</function>
5505706f2543Smrg    described below).
5506706f2543Smrg	    </para>
5507706f2543Smrg
5508706f2543Smrg	  </blockquote></para></blockquote>
5509706f2543Smrg    </sect2>
5510706f2543Smrg
5511706f2543Smrg    <sect2>
5512706f2543Smrg      <title>Module Requirements</title>
5513706f2543Smrg
5514706f2543Smrg      <para>
5515706f2543SmrgModules must provide information about themselves to the loader, and
5516706f2543Smrgmay optionally provide entry points for "setup" and "teardown" functions
5517706f2543Smrg(those two functions are referred to here as <function>SetupProc</function>
5518706f2543Smrgand <function>TearDownProc</function>).
5519706f2543Smrg      </para>
5520706f2543Smrg
5521706f2543Smrg      <para>
5522706f2543SmrgThe module information is contained in the
5523706f2543Smrg<structname>XF86ModuleVersionInfo</structname> struct, which is defined as follows:
5524706f2543Smrg
5525706f2543Smrg	<programlisting>
5526706f2543Smrgtypedef struct {
5527706f2543Smrg    const char * modname;      /* name of module, e.g. "foo" */
5528706f2543Smrg    const char * vendor;       /* vendor specific string */
5529706f2543Smrg    CARD32       _modinfo1_;   /* constant MODINFOSTRING1/2 to find */
5530706f2543Smrg    CARD32       _modinfo2_;   /* infoarea with a binary editor/sign tool */
5531706f2543Smrg    CARD32       xf86version;  /* contains XF86_VERSION_CURRENT */
5532706f2543Smrg    CARD8        majorversion; /* module-specific major version */
5533706f2543Smrg    CARD8        minorversion; /* module-specific minor version */
5534706f2543Smrg    CARD16       patchlevel;   /* module-specific patch level */
5535706f2543Smrg    const char * abiclass;     /* ABI class that the module uses */
5536706f2543Smrg    CARD32       abiversion;   /* ABI version */
5537706f2543Smrg    const char * moduleclass;  /* module class */
5538706f2543Smrg    CARD32       checksum[4];  /* contains a digital signature of the */
5539706f2543Smrg                               /* version info structure */
5540706f2543Smrg} XF86ModuleVersionInfo;
5541706f2543Smrg	</programlisting>
5542706f2543Smrg
5543706f2543SmrgThe fields are used as follows:
5544706f2543Smrg
5545706f2543Smrg	<variablelist>
5546706f2543Smrg	  <varlistentry>
5547706f2543Smrg	    <term><structfield>modname</structfield></term>
5548706f2543Smrg	    <listitem><para>
5549706f2543Smrg		The module's name.  This field is currently only for
5550706f2543Smrg		informational purposes, but the loader may be modified
5551706f2543Smrg		in future to require it to match the module's canonical
5552706f2543Smrg                name.
5553706f2543Smrg	      </para></listitem></varlistentry>
5554706f2543Smrg
5555706f2543Smrg
5556706f2543Smrg	  <varlistentry>
5557706f2543Smrg	    <term><structfield>vendor</structfield></term>
5558706f2543Smrg	    <listitem><para>
5559706f2543Smrg		The module vendor.  This field is for informational purposes
5560706f2543Smrg                only.
5561706f2543Smrg	      </para></listitem></varlistentry>
5562706f2543Smrg
5563706f2543Smrg
5564706f2543Smrg	  <varlistentry>
5565706f2543Smrg	    <term><structfield>_modinfo1_</structfield></term>
5566706f2543Smrg	    <listitem><para>
5567706f2543Smrg		This field holds the first part of a signature that can
5568706f2543Smrg                be used to locate this structure in the binary.  It should
5569706f2543Smrg		always be initialised to <constant>MODINFOSTRING1</constant>.
5570706f2543Smrg	      </para></listitem></varlistentry>
5571706f2543Smrg
5572706f2543Smrg
5573706f2543Smrg	  <varlistentry>
5574706f2543Smrg	    <term><structfield>_modinfo2_</structfield></term>
5575706f2543Smrg	    <listitem><para>
5576706f2543Smrg		This field holds the second part of a signature that can
5577706f2543Smrg                be used to locate this structure in the binary.  It should
5578706f2543Smrg		always be initialised to <constant>MODINFOSTRING2</constant>.
5579706f2543Smrg	      </para></listitem></varlistentry>
5580706f2543Smrg
5581706f2543Smrg
5582706f2543Smrg	  <varlistentry>
5583706f2543Smrg	    <term><structfield>xf86version</structfield></term>
5584706f2543Smrg	    <listitem><para>
5585706f2543Smrg		The XFree86 version against which the module was compiled.
5586706f2543Smrg                This is mostly for informational/diagnostic purposes.  It
5587706f2543Smrg		should be initialised to <constant>XF86_VERSION_CURRENT</constant>, which is
5588706f2543Smrg		defined in <filename>xf86Version.h</filename>.
5589706f2543Smrg	      </para></listitem></varlistentry>
5590706f2543Smrg
5591706f2543Smrg
5592706f2543Smrg	  <varlistentry>
5593706f2543Smrg	    <term><structfield>majorversion</structfield></term>
5594706f2543Smrg	    <listitem><para>
5595706f2543Smrg		The module-specific major version.  For modules where this
5596706f2543Smrg		version is used for more than simply informational
5597706f2543Smrg		purposes, the major version should only change (be
5598706f2543Smrg		incremented) when ABI incompatibilities are introduced,
5599706f2543Smrg		or ABI components are removed.
5600706f2543Smrg	      </para></listitem></varlistentry>
5601706f2543Smrg
5602706f2543Smrg
5603706f2543Smrg	  <varlistentry>
5604706f2543Smrg	    <term><structfield>minorversion</structfield></term>
5605706f2543Smrg	    <listitem><para>
5606706f2543Smrg		The module-specific minor version.  For modules where this
5607706f2543Smrg		version is used for more than simply informational
5608706f2543Smrg		purposes, the minor version should only change (be
5609706f2543Smrg		incremented) when ABI additions are made in a backward
5610706f2543Smrg		compatible way.  It should be reset to zero when the major
5611706f2543Smrg                version is increased.
5612706f2543Smrg	      </para></listitem></varlistentry>
5613706f2543Smrg
5614706f2543Smrg
5615706f2543Smrg	  <varlistentry>
5616706f2543Smrg	    <term><structfield>patchlevel</structfield></term>
5617706f2543Smrg	    <listitem><para>
5618706f2543Smrg		The module-specific patch level.  The patch level should
5619706f2543Smrg		increase with new revisions of the module where there
5620706f2543Smrg		are no ABI changes, and it should be reset to zero when
5621706f2543Smrg		the minor version is increased.
5622706f2543Smrg	      </para></listitem></varlistentry>
5623706f2543Smrg
5624706f2543Smrg
5625706f2543Smrg	  <varlistentry>
5626706f2543Smrg	    <term><structfield>abiclass</structfield></term>
5627706f2543Smrg	    <listitem><para>
5628706f2543Smrg		The ABI class that the module requires.  The class is
5629706f2543Smrg                specified as a string for easy extensibility.  It should
5630706f2543Smrg		indicate which (if any) of the X server's built-in ABI
5631706f2543Smrg		classes that the module relies on, or a third-party ABI
5632706f2543Smrg                if appropriate.  Built-in ABI classes currently defined are:
5633706f2543Smrg
5634706f2543Smrg		<variablelist>
5635706f2543Smrg		  <varlistentry>
5636706f2543Smrg		    <term><constant>ABI_CLASS_NONE</constant></term>
5637706f2543Smrg		    <listitem><para>no class
5638706f2543Smrg		      </para></listitem></varlistentry>
5639706f2543Smrg		  <varlistentry>
5640706f2543Smrg		    <term><constant>ABI_CLASS_ANSIC</constant></term>
5641706f2543Smrg		    <listitem><para>only requires the ANSI C interfaces
5642706f2543Smrg		      </para></listitem></varlistentry>
5643706f2543Smrg		  <varlistentry>
5644706f2543Smrg		    <term><constant>ABI_CLASS_VIDEODRV</constant></term>
5645706f2543Smrg		    <listitem><para>requires the video driver ABI
5646706f2543Smrg		      </para></listitem></varlistentry>
5647706f2543Smrg		  <varlistentry>
5648706f2543Smrg		    <term><constant>ABI_CLASS_XINPUT</constant></term>
5649706f2543Smrg		    <listitem><para>requires the XInput driver ABI
5650706f2543Smrg		      </para></listitem></varlistentry>
5651706f2543Smrg		  <varlistentry>
5652706f2543Smrg		    <term><constant>ABI_CLASS_EXTENSION</constant></term>
5653706f2543Smrg		    <listitem><para>requires the extension module ABI
5654706f2543Smrg		      </para></listitem></varlistentry>
5655706f2543Smrg		  <varlistentry>
5656706f2543Smrg		    <term><constant>ABI_CLASS_FONT</constant></term>
5657706f2543Smrg		    <listitem><para>requires the font module ABI
5658706f2543Smrg		      </para></listitem></varlistentry>
5659706f2543Smrg		</variablelist>
5660706f2543Smrg
5661706f2543Smrg	      </para></listitem></varlistentry>
5662706f2543Smrg
5663706f2543Smrg	  <varlistentry>
5664706f2543Smrg	    <term><structfield>abiversion</structfield></term>
5665706f2543Smrg	    <listitem><para>
5666706f2543Smrg		The version of abiclass that the module requires.  The
5667706f2543Smrg		version consists of major and minor components.  The
5668706f2543Smrg		major version must match and the minor version must be
5669706f2543Smrg		no newer than that provided by the server or parent
5670706f2543Smrg		module.  Version identifiers for the built-in classes
5671706f2543Smrg		currently defined are:
5672706f2543Smrg
5673706f2543Smrg		<literallayout><constant>
5674706f2543Smrg                   ABI_ANSIC_VERSION
5675706f2543Smrg                   ABI_VIDEODRV_VERSION
5676706f2543Smrg                   ABI_XINPUT_VERSION
5677706f2543Smrg                   ABI_EXTENSION_VERSION
5678706f2543Smrg                   ABI_FONT_VERSION
5679706f2543Smrg		  </constant></literallayout>
5680706f2543Smrg
5681706f2543Smrg	      </para></listitem></varlistentry>
5682706f2543Smrg
5683706f2543Smrg	  <varlistentry>
5684706f2543Smrg	    <term><structfield>moduleclass</structfield></term>
5685706f2543Smrg	    <listitem><para>
5686706f2543Smrg		This is similar to the abiclass field, except that it
5687706f2543Smrg		defines the type of module rather than the ABI it
5688706f2543Smrg		requires.  For example, although all video drivers require
5689706f2543Smrg		the video driver ABI, not all modules that require the
5690706f2543Smrg		video driver ABI are video drivers.  This distinction
5691706f2543Smrg		can be made with the moduleclass.  Currently pre-defined
5692706f2543Smrg		module classes are:
5693706f2543Smrg
5694706f2543Smrg		<literallayout><constant>
5695706f2543Smrg                   MOD_CLASS_NONE
5696706f2543Smrg                   MOD_CLASS_VIDEODRV
5697706f2543Smrg                   MOD_CLASS_XINPUT
5698706f2543Smrg                   MOD_CLASS_FONT
5699706f2543Smrg                   MOD_CLASS_EXTENSION
5700706f2543Smrg		  </constant></literallayout>
5701706f2543Smrg
5702706f2543Smrg	      </para></listitem></varlistentry>
5703706f2543Smrg
5704706f2543Smrg	  <varlistentry>
5705706f2543Smrg	    <term><structfield>checksum</structfield></term>
5706706f2543Smrg	    <listitem><para>
5707706f2543Smrg		Not currently used.
5708706f2543Smrg	      </para></listitem></varlistentry>
5709706f2543Smrg
5710706f2543Smrg	</variablelist>
5711706f2543Smrg      </para>
5712706f2543Smrg
5713706f2543Smrg      <para>
5714706f2543SmrgThe module version information, and the optional <function>SetupProc</function>
5715706f2543Smrgand <function>TearDownProc</function> entry points are found by the loader
5716706f2543Smrgby locating a data object in the module called "modnameModuleData",
5717706f2543Smrgwhere "modname" is the canonical name of the module.  Modules must
5718706f2543Smrgcontain such a data object, and it must be declared with global scope,
5719706f2543Smrgbe compile-time initialised, and is of the following type:
5720706f2543Smrg
5721706f2543Smrg	<programlisting>
5722706f2543Smrgtypedef struct {
5723706f2543Smrg    XF86ModuleVersionInfo *     vers;
5724706f2543Smrg    ModuleSetupProc             setup;
5725706f2543Smrg    ModuleTearDownProc          teardown;
5726706f2543Smrg} XF86ModuleData;
5727706f2543Smrg	</programlisting>
5728706f2543Smrg      </para>
5729706f2543Smrg
5730706f2543Smrg      <para>
5731706f2543SmrgThe vers parameter must be initialised to a pointer to a correctly
5732706f2543Smrginitialised <structname>XF86ModuleVersionInfo</structname> struct.  The other
5733706f2543Smrgtwo parameter are optional, and should be initialised to
5734706f2543Smrg<constant>NULL</constant> when not required.  The other parameters are defined
5735706f2543Smrgas
5736706f2543Smrg
5737706f2543Smrg	<blockquote><para>
5738706f2543Smrg	    <programlisting>
5739706f2543Smrg    typedef pointer (*ModuleSetupProc)(pointer, pointer, int *, int *);
5740706f2543Smrg
5741706f2543Smrg    typedef void (*ModuleTearDownProc)(pointer);
5742706f2543Smrg
5743706f2543Smrg    pointer SetupProc(pointer module, pointer options,
5744706f2543Smrg                      int *errmaj, int *errmin);
5745706f2543Smrg	    </programlisting>
5746706f2543Smrg	    <blockquote><para>
5747706f2543Smrg    When defined, this function is called by the loader after successfully
5748706f2543Smrg    loading a module.  module is a handle for the newly loaded module,
5749706f2543Smrg    and maybe used by the <function>SetupProc</function> if it calls other
5750706f2543Smrg    loader functions that require a reference to it.   The remaining
5751706f2543Smrg    arguments are those that were passed to the
5752706f2543Smrg    <function>LoadModule()</function> (or <function>LoadSubModule()</function>),
5753706f2543Smrg    and are described above. When the <function>SetupProc</function> is
5754706f2543Smrg    successful it must return a non-<constant>NULL</constant> value.  The
5755706f2543Smrg    loader checks this, and if it is <constant>NULL</constant> it unloads
5756706f2543Smrg    the module and reports the failure to the caller of
5757706f2543Smrg    <function>LoadModule()</function>.  If the <function>SetupProc</function>
5758706f2543Smrg    does things that need to be undone when the module is unloaded,
5759706f2543Smrg    it should define a <function>TearDownProc</function>, and return a
5760706f2543Smrg    pointer that the <function>TearDownProc</function> can use to undo what
5761706f2543Smrg    has been done.
5762706f2543Smrg	      </para>
5763706f2543Smrg
5764706f2543Smrg	      <para>
5765706f2543Smrg    When a module is loaded multiple times, the <function>SetupProc</function>
5766706f2543Smrg    is called once for each time it is loaded.
5767706f2543Smrg	      </para>
5768706f2543Smrg
5769706f2543Smrg	    </blockquote></para></blockquote>
5770706f2543Smrg
5771706f2543Smrg	<blockquote><para>
5772706f2543Smrg	    <programlisting>
5773706f2543Smrg    void TearDownProc(pointer tearDownData);
5774706f2543Smrg	    </programlisting>
5775706f2543Smrg	    <blockquote><para>
5776706f2543Smrg    When defined, this function is called when the loader unloads a
5777706f2543Smrg    module.  The <parameter>tearDownData</parameter> parameter is the return
5778706f2543Smrg    value of the <function>SetupProc()</function> that was called when the
5779706f2543Smrg    module was loaded.  The purpose of this function is to clean up
5780706f2543Smrg    before the module is unloaded (for example, by freeing allocated
5781706f2543Smrg    resources).
5782706f2543Smrg	      </para>
5783706f2543Smrg
5784706f2543Smrg	    </blockquote></para></blockquote>
5785706f2543Smrg      </para>
5786706f2543Smrg    </sect2>
5787706f2543Smrg
5788706f2543Smrg    <sect2>
5789706f2543Smrg      <title>Public Loader Interface</title>
5790706f2543Smrg
5791706f2543Smrg      <para>
5792706f2543SmrgThe following is the Loader interface that is available to any part of
5793706f2543Smrgthe server, and may also be used from within modules.
5794706f2543Smrg      </para>
5795706f2543Smrg
5796706f2543Smrg      <blockquote><para>
5797706f2543Smrg	  <programlisting>
5798706f2543Smrg    pointer LoadSubModule(pointer parent, const char *module,
5799706f2543Smrg                          const char **subdirlist, const char **patternlist,
5800706f2543Smrg                          pointer options, const XF86ModReqInfo * modreq,
5801706f2543Smrg                          int *errmaj, int *errmin);
5802706f2543Smrg	  </programlisting>
5803706f2543Smrg	  <blockquote><para>
5804706f2543Smrg    This function is like the <function>LoadModule()</function> function
5805706f2543Smrg    described above, except that the module loaded is registered as a
5806706f2543Smrg    child of the calling module.  The <parameter>parent</parameter> parameter
5807706f2543Smrg    is the calling module's handle.  Modules loaded with this function
5808706f2543Smrg    are automatically unloaded when the parent module is unloaded.  The
5809706f2543Smrg    other difference is that the path parameter may not be specified.
5810706f2543Smrg    The module search path used for modules loaded with this function
5811706f2543Smrg    is the default search path as initialised with
5812706f2543Smrg    <function>LoaderSetPath()</function>.
5813706f2543Smrg	    </para>
5814706f2543Smrg
5815706f2543Smrg	  </blockquote></para></blockquote>
5816706f2543Smrg
5817706f2543Smrg      <blockquote><para>
5818706f2543Smrg	  <programlisting>
5819706f2543Smrg    void UnloadSubModule(pointer module);
5820706f2543Smrg	  </programlisting>
5821706f2543Smrg	  <blockquote><para>
5822706f2543Smrg    This function unloads the module with handle <parameter>module</parameter>.
5823706f2543Smrg    If that module itself has children, they are also unloaded.  It is
5824706f2543Smrg    like <function>UnloadModule()</function>, except that it is safe to use
5825706f2543Smrg    for unloading child modules.
5826706f2543Smrg	    </para>
5827706f2543Smrg
5828706f2543Smrg	  </blockquote></para></blockquote>
5829706f2543Smrg
5830706f2543Smrg      <blockquote><para>
5831706f2543Smrg	  <programlisting>
5832706f2543Smrg    pointer LoaderSymbol(const char *symbol);
5833706f2543Smrg	  </programlisting>
5834706f2543Smrg	<blockquote><para>
5835706f2543Smrg    This function returns the address of the symbol with name
5836706f2543Smrg    <parameter>symbol</parameter>.  This may be used to locate a module entry
5837706f2543Smrg    point with a known name.
5838706f2543Smrg	    </para>
5839706f2543Smrg
5840706f2543Smrg	  </blockquote></para></blockquote>
5841706f2543Smrg
5842706f2543Smrg      <blockquote><para>
5843706f2543Smrg	  <programlisting>
5844706f2543Smrg    char **LoaderlistDirs(const char **subdirlist,
5845706f2543Smrg                          const char **patternlist);
5846706f2543Smrg	  </programlisting>
5847706f2543Smrg	  <blockquote><para>
5848706f2543Smrg    This function returns a <constant>NULL</constant> terminated list of
5849706f2543Smrg    canonical modules names for modules found in the default module
5850706f2543Smrg    search path.  The <parameter>subdirlist</parameter> and
5851706f2543Smrg    <parameter>patternlist</parameter> parameters are as described above, and
5852706f2543Smrg    can be used to control the locations and names that are searched.
5853706f2543Smrg    If no modules are found, the return value is <constant>NULL</constant>.
5854706f2543Smrg    The returned list should be freed by calling
5855706f2543Smrg    <function>LoaderFreeDirList()</function> when it is no longer needed.
5856706f2543Smrg	    </para>
5857706f2543Smrg
5858706f2543Smrg	  </blockquote></para></blockquote>
5859706f2543Smrg
5860706f2543Smrg      <blockquote><para>
5861706f2543Smrg	  <programlisting>
5862706f2543Smrg    void LoaderFreeDirList(char **list);
5863706f2543Smrg	  </programlisting>
5864706f2543Smrg	  <blockquote><para>
5865706f2543Smrg    This function frees a module list created by
5866706f2543Smrg    <function>LoaderlistDirs()</function>.
5867706f2543Smrg	    </para>
5868706f2543Smrg
5869706f2543Smrg	  </blockquote></para></blockquote>
5870706f2543Smrg
5871706f2543Smrg      <blockquote><para>
5872706f2543Smrg	  <programlisting>
5873706f2543Smrg    void LoaderReqSymLists(const char **list0, ...);
5874706f2543Smrg	  </programlisting>
5875706f2543Smrg	  <blockquote><para>
5876706f2543Smrg    This function allows the registration of required symbols with the
5877706f2543Smrg    loader.  It is normally used by a caller of
5878706f2543Smrg    <function>LoadSubModule()</function>.  If any symbols registered in this
5879706f2543Smrg    way are found to be unresolved when
5880706f2543Smrg    <function>LoaderCheckUnresolved()</function> is called then
5881706f2543Smrg    <function>LoaderCheckUnresolved()</function> will report a failure.
5882706f2543Smrg    The function takes one or more <constant>NULL</constant> terminated
5883706f2543Smrg    lists of symbols.  The end of the argument list is indicated by a
5884706f2543Smrg    <constant>NULL</constant> argument.
5885706f2543Smrg	    </para>
5886706f2543Smrg
5887706f2543Smrg	  </blockquote></para></blockquote>
5888706f2543Smrg
5889706f2543Smrg      <blockquote><para>
5890706f2543Smrg	  <programlisting>
5891706f2543Smrg    void LoaderReqSymbols(const char *sym0, ...);
5892706f2543Smrg	  </programlisting>
5893706f2543Smrg	<blockquote><para>
5894706f2543Smrg    This function is like <function>LoaderReqSymLists()</function> except
5895706f2543Smrg    that its arguments are symbols rather than lists of symbols.  This
5896706f2543Smrg    function is more convenient when single functions are to be registered,
5897706f2543Smrg    especially when the single function might depend on runtime factors.
5898706f2543Smrg    The end of the argument list is indicated by a <constant>NULL</constant>
5899706f2543Smrg    argument.
5900706f2543Smrg	    </para>
5901706f2543Smrg
5902706f2543Smrg	  </blockquote></para></blockquote>
5903706f2543Smrg
5904706f2543Smrg      <blockquote><para>
5905706f2543Smrg	  <programlisting>
5906706f2543Smrg    void LoaderRefSymLists(const char **list0, ...);
5907706f2543Smrg	  </programlisting>
5908706f2543Smrg	  <blockquote><para>
5909706f2543Smrg    This function allows the registration of possibly unresolved symbols
5910706f2543Smrg    with the loader.  When <function>LoaderCheckUnresolved()</function> is
5911706f2543Smrg    run it won't generate warnings for symbols registered in this way
5912706f2543Smrg    unless they were also registered as required symbols.
5913706f2543Smrg    The function takes one or more <constant>NULL</constant> terminated
5914706f2543Smrg    lists of symbols.  The end of the argument list is indicated by a
5915706f2543Smrg    <constant>NULL</constant> argument.
5916706f2543Smrg	    </para>
5917706f2543Smrg
5918706f2543Smrg	  </blockquote></para></blockquote>
5919706f2543Smrg
5920706f2543Smrg      <blockquote><para>
5921706f2543Smrg	  <programlisting>
5922706f2543Smrg    void LoaderRefSymbols(const char *sym0, ...);
5923706f2543Smrg	  </programlisting>
5924706f2543Smrg	  <blockquote><para>
5925706f2543Smrg    This function is like <function>LoaderRefSymLists()</function> except
5926706f2543Smrg    that its arguments are symbols rather than lists of symbols.  This
5927706f2543Smrg    function is more convenient when single functions are to be registered,
5928706f2543Smrg    especially when the single function might depend on runtime factors.
5929706f2543Smrg    The end of the argument list is indicated by a <constant>NULL</constant>
5930706f2543Smrg    argument.
5931706f2543Smrg	    </para>
5932706f2543Smrg
5933706f2543Smrg	  </blockquote></para></blockquote>
5934706f2543Smrg
5935706f2543Smrg      <blockquote><para>
5936706f2543Smrg	  <programlisting>
5937706f2543Smrg    int LoaderCheckUnresolved(int delayflag);
5938706f2543Smrg	  </programlisting>
5939706f2543Smrg	  <blockquote><para>
5940706f2543Smrg    This function checks for unresolved symbols.  It generates warnings
5941706f2543Smrg    for unresolved symbols that have not been registered with
5942706f2543Smrg    <function>LoaderRefSymLists()</function>, and maps them to a dummy
5943706f2543Smrg    function.  This behaviour may change in future.  If unresolved
5944706f2543Smrg    symbols are found that have been registered with
5945706f2543Smrg    <function>LoaderReqSymLists()</function> or
5946706f2543Smrg    <function>LoaderReqSymbols()</function> then this function returns a
5947706f2543Smrg    non-zero value.  If none of these symbols are unresolved the return
5948706f2543Smrg    value is zero, indicating success.
5949706f2543Smrg	    </para>
5950706f2543Smrg
5951706f2543Smrg	    <para>
5952706f2543Smrg    The <parameter>delayflag</parameter> parameter should normally be set to
5953706f2543Smrg    <constant>LD_RESOLV_IFDONE</constant>.
5954706f2543Smrg	    </para>
5955706f2543Smrg
5956706f2543Smrg	  </blockquote></para></blockquote>
5957706f2543Smrg
5958706f2543Smrg      <blockquote><para>
5959706f2543Smrg	  <programlisting>
5960706f2543Smrg    LoaderErrorMsg(const char *name, const char *modname,
5961706f2543Smrg                   int errmaj, int errmin);
5962706f2543Smrg	  </programlisting>
5963706f2543Smrg	  <blockquote><para>
5964706f2543Smrg    This function prints an error message that includes the text <quote>Failed
5965706f2543Smrg    to load module</quote>, the module name <parameter>modname</parameter>, a message
5966706f2543Smrg    specific to the <parameter>errmaj</parameter> value, and the value if
5967706f2543Smrg    <parameter>errmin</parameter>.  If <parameter>name</parameter> is
5968706f2543Smrg    non-<constant>NULL</constant>, it is printed as an identifying prefix
5969706f2543Smrg    to the message (followed by a <quote>:</quote>).
5970706f2543Smrg	    </para>
5971706f2543Smrg
5972706f2543Smrg	  </blockquote></para></blockquote>
5973706f2543Smrg    </sect2>
5974706f2543Smrg
5975706f2543Smrg    <sect2>
5976706f2543Smrg      <title>Special Registration Functions</title>
5977706f2543Smrg
5978706f2543Smrg      <para>
5979706f2543SmrgThe loader contains some functions for registering some classes of modules.
5980706f2543SmrgThese may be moved out of the loader at some point.
5981706f2543Smrg      </para>
5982706f2543Smrg
5983706f2543Smrg      <blockquote><para>
5984706f2543Smrg	  <programlisting>
5985706f2543Smrg    void LoadExtension(ExtensionModule *ext);
5986706f2543Smrg	  </programlisting>
5987706f2543Smrg	  <blockquote><para>
5988706f2543Smrg    This registers the entry points for the extension identified by
5989706f2543Smrg    <parameter>ext</parameter>.  The <structname>ExtensionModule</structname> struct is
5990706f2543Smrg    defined as:
5991706f2543Smrg
5992706f2543Smrg	      <programlisting>
5993706f2543Smrgtypedef struct {
5994706f2543Smrg    InitExtension       initFunc;
5995706f2543Smrg    char *              name;
5996706f2543Smrg    Bool                *disablePtr;
5997706f2543Smrg    InitExtension       setupFunc;
5998706f2543Smrg} ExtensionModule;
5999706f2543Smrg	      </programlisting>
6000706f2543Smrg	    </para>
6001706f2543Smrg
6002706f2543Smrg	  </blockquote></para></blockquote>
6003706f2543Smrg
6004706f2543Smrg      <blockquote><para>
6005706f2543Smrg	  <programlisting>
6006706f2543Smrg    void LoadFont(FontModule *font);
6007706f2543Smrg	  </programlisting>
6008706f2543Smrg	  <blockquote><para>
6009706f2543Smrg    This registers the entry points for the font rasteriser module
6010706f2543Smrg    identified by <parameter>font</parameter>.  The <structname>FontModule</structname>
6011706f2543Smrg    struct is defined as:
6012706f2543Smrg
6013706f2543Smrg	      <programlisting>
6014706f2543Smrg typedef struct {
6015706f2543Smrg    InitFont    initFunc;
6016706f2543Smrg    char *      name;
6017706f2543Smrg    pointer     module;
6018706f2543Smrg} FontModule;
6019706f2543Smrg	      </programlisting>
6020706f2543Smrg	    </para>
6021706f2543Smrg
6022706f2543Smrg	  </blockquote></para></blockquote>
6023706f2543Smrg
6024706f2543Smrg    </sect2>
6025706f2543Smrg
6026706f2543Smrg  </sect1>
6027706f2543Smrg
6028706f2543Smrg  <sect1>
6029706f2543Smrg    <title>Helper Functions</title>
6030706f2543Smrg
6031706f2543Smrg    <para>
6032706f2543SmrgThis section describe <quote>helper</quote> functions that video driver
6033706f2543Smrgmight find useful.  While video drivers are not required to use any of
6034706f2543Smrgthese to be considered <quote>compliant</quote>, the use of appropriate helpers is
6035706f2543Smrgstrongly encouraged to improve the consistency of driver behaviour.
6036706f2543Smrg    </para>
6037706f2543Smrg
6038706f2543Smrg    <sect2>
6039706f2543Smrg      <title>Functions for printing messages</title>
6040706f2543Smrg
6041706f2543Smrg      <blockquote><para>
6042706f2543Smrg	  <programlisting>
6043706f2543Smrg    ErrorF(const char *format, ...);
6044706f2543Smrg	  </programlisting>
6045706f2543Smrg	  <blockquote><para>
6046706f2543Smrg      This is the basic function for writing to the error log (typically
6047706f2543Smrg      stderr and/or a log file).  Video drivers should usually avoid
6048706f2543Smrg      using this directly in favour of the more specialised functions
6049706f2543Smrg      described below.  This function is useful for printing messages
6050706f2543Smrg      while debugging a driver.
6051706f2543Smrg	    </para>
6052706f2543Smrg
6053706f2543Smrg	  </blockquote></para></blockquote>
6054706f2543Smrg
6055706f2543Smrg      <blockquote><para>
6056706f2543Smrg	  <programlisting>
6057706f2543Smrg    FatalError(const char *format, ...);
6058706f2543Smrg	  </programlisting>
6059706f2543Smrg	  <blockquote><para>
6060706f2543Smrg      This prints a message and causes the Xserver to abort.  It should
6061706f2543Smrg      rarely be used within a video driver, as most error conditions
6062706f2543Smrg      should be flagged by the return values of the driver functions.
6063706f2543Smrg      This allows the higher layers to decide how to proceed.  In rare
6064706f2543Smrg      cases, this can be used within a driver if a fatal unexpected
6065706f2543Smrg      condition is found.
6066706f2543Smrg	    </para>
6067706f2543Smrg
6068706f2543Smrg	  </blockquote></para></blockquote>
6069706f2543Smrg
6070706f2543Smrg      <blockquote><para>
6071706f2543Smrg	  <programlisting>
6072706f2543Smrg    xf86ErrorF(const char *format, ...);
6073706f2543Smrg	  </programlisting>
6074706f2543Smrg	  <blockquote><para>
6075706f2543Smrg      This is like <function>ErrorF()</function>, except that the message is
6076706f2543Smrg      only printed when the Xserver's verbosity level is set to the
6077706f2543Smrg      default (<constant>1</constant>) or higher.  It means that the messages
6078706f2543Smrg      are not printed when the server is started with the
6079706f2543Smrg      <option>-quiet</option> flag.  Typically this function would only be
6080706f2543Smrg      used for continuing messages started with one of the more specialised
6081706f2543Smrg      functions described below.
6082706f2543Smrg	    </para>
6083706f2543Smrg
6084706f2543Smrg	  </blockquote></para></blockquote>
6085706f2543Smrg
6086706f2543Smrg      <blockquote><para>
6087706f2543Smrg	  <programlisting>
6088706f2543Smrg    xf86ErrorFVerb(int verb, const char *format, ...);
6089706f2543Smrg	  </programlisting>
6090706f2543Smrg	  <blockquote><para>
6091706f2543Smrg      Like <function>xf86ErrorF()</function>, except the minimum verbosity
6092706f2543Smrg      level for which the message is to be printed is given explicitly.
6093706f2543Smrg      Passing a <parameter>verb</parameter> value of zero means the message
6094706f2543Smrg      is always printed.  A value higher than <constant>1</constant> can be
6095706f2543Smrg      used for information would normally not be needed, but which might
6096706f2543Smrg      be useful when diagnosing problems.
6097706f2543Smrg	    </para>
6098706f2543Smrg
6099706f2543Smrg	  </blockquote></para></blockquote>
6100706f2543Smrg
6101706f2543Smrg
6102706f2543Smrg      <blockquote><para>
6103706f2543Smrg	  <programlisting>
6104706f2543Smrg    xf86Msg(MessageType type, const char *format, ...);
6105706f2543Smrg	  </programlisting>
6106706f2543Smrg	  <blockquote><para>
6107706f2543Smrg      This is like <function>xf86ErrorF()</function>, except that the message
6108706f2543Smrg      is prefixed with a marker determined by the value of
6109706f2543Smrg      <parameter>type</parameter>.  The marker is used to indicate the type of
6110706f2543Smrg      message (warning, error, probed value, config value, etc).  Note
6111706f2543Smrg      the <varname>xf86Verbose</varname> value is ignored for messages of
6112706f2543Smrg      type <constant>X_ERROR</constant>.
6113706f2543Smrg	    </para>
6114706f2543Smrg
6115706f2543Smrg	    <para>
6116706f2543Smrg      The marker values are:
6117706f2543Smrg
6118706f2543Smrg	      <variablelist>
6119706f2543Smrg		<varlistentry>
6120706f2543Smrg		  <term><constant>X_PROBED</constant></term>
6121706f2543Smrg		  <listitem><para>Value was probed.
6122706f2543Smrg		    </para></listitem></varlistentry>
6123706f2543Smrg		<varlistentry>
6124706f2543Smrg		  <term><constant>X_CONFIG</constant></term>
6125706f2543Smrg		  <listitem><para>Value was given in the config file.
6126706f2543Smrg		    </para></listitem></varlistentry>
6127706f2543Smrg		<varlistentry>
6128706f2543Smrg		  <term><constant>X_DEFAULT</constant></term>
6129706f2543Smrg		  <listitem><para>Value is a default.
6130706f2543Smrg		    </para></listitem></varlistentry>
6131706f2543Smrg		<varlistentry>
6132706f2543Smrg		  <term><constant>X_CMDLINE</constant></term>
6133706f2543Smrg		  <listitem><para>Value was given on the command line.
6134706f2543Smrg		    </para></listitem></varlistentry>
6135706f2543Smrg		<varlistentry>
6136706f2543Smrg		  <term><constant>X_NOTICE</constant></term>
6137706f2543Smrg		  <listitem><para>Notice.
6138706f2543Smrg		    </para></listitem></varlistentry>
6139706f2543Smrg		<varlistentry>
6140706f2543Smrg		  <term><constant>X_ERROR</constant></term>
6141706f2543Smrg		  <listitem><para>Error message.
6142706f2543Smrg		    </para></listitem></varlistentry>
6143706f2543Smrg		<varlistentry>
6144706f2543Smrg		  <term><constant>X_WARNING</constant></term>
6145706f2543Smrg		  <listitem><para>Warning message.
6146706f2543Smrg		    </para></listitem></varlistentry>
6147706f2543Smrg		<varlistentry>
6148706f2543Smrg		  <term><constant>X_INFO</constant></term>
6149706f2543Smrg		  <listitem><para>Informational message.
6150706f2543Smrg		    </para></listitem></varlistentry>
6151706f2543Smrg		<varlistentry>
6152706f2543Smrg		  <term><constant>X_NONE</constant></term>
6153706f2543Smrg		  <listitem><para>No prefix.
6154706f2543Smrg		    </para></listitem></varlistentry>
6155706f2543Smrg		<varlistentry>
6156706f2543Smrg		  <term><constant>X_NOT_IMPLEMENTED</constant></term>
6157706f2543Smrg		  <listitem><para>The message relates to functionality
6158706f2543Smrg		      that is not yetimplemented.
6159706f2543Smrg		    </para></listitem></varlistentry>
6160706f2543Smrg		</variablelist>
6161706f2543Smrg
6162706f2543Smrg	    </para>
6163706f2543Smrg
6164706f2543Smrg	  </blockquote></para></blockquote>
6165706f2543Smrg
6166706f2543Smrg      <blockquote><para>
6167706f2543Smrg	  <programlisting>
6168706f2543Smrg    xf86MsgVerb(MessageType type, int verb, const char *format, ...);
6169706f2543Smrg	  </programlisting>
6170706f2543Smrg	  <blockquote><para>
6171706f2543Smrg      Like <function>xf86Msg()</function>, but with the verbosity level given
6172706f2543Smrg      explicitly.
6173706f2543Smrg	    </para>
6174706f2543Smrg
6175706f2543Smrg	  </blockquote></para></blockquote>
6176706f2543Smrg
6177706f2543Smrg      <blockquote><para>
6178706f2543Smrg	  <programlisting>
6179706f2543Smrg    xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...);
6180706f2543Smrg	  </programlisting>
6181706f2543Smrg	  <blockquote><para>
6182706f2543Smrg      This is like <function>xf86Msg()</function> except that the driver's
6183706f2543Smrg      name (the <structfield>name</structfield> field of the
6184706f2543Smrg      <structname>ScrnInfoRec</structname>) followed by the
6185706f2543Smrg      <parameter>scrnIndex</parameter> in parentheses is printed following the
6186706f2543Smrg      prefix.  This should be used by video drivers in most cases as it
6187706f2543Smrg      clearly indicates which driver/screen the message is for.  If
6188706f2543Smrg      <parameter>scrnIndex</parameter> is negative, this function behaves
6189706f2543Smrg      exactly like <function>xf86Msg()</function>.
6190706f2543Smrg	    </para>
6191706f2543Smrg
6192706f2543Smrg	    <para>
6193706f2543Smrg      NOTE: This function can only be used after the
6194706f2543Smrg      <structname>ScrnInfoRec</structname> and its <structfield>name</structfield> field
6195706f2543Smrg      have been allocated.  Normally, this means that it can not be
6196706f2543Smrg      used before the END of the <function>ChipProbe()</function> function.
6197706f2543Smrg      Prior to that, use <function>xf86Msg()</function>, providing the
6198706f2543Smrg      driver's name explicitly.  No screen number can be supplied at
6199706f2543Smrg      that point.
6200706f2543Smrg	    </para>
6201706f2543Smrg
6202706f2543Smrg	  </blockquote></para></blockquote>
6203706f2543Smrg
6204706f2543Smrg      <blockquote><para>
6205706f2543Smrg	  <programlisting>
6206706f2543Smrg    xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb,
6207706f2543Smrg                                const char *format, ...);
6208706f2543Smrg	  </programlisting>
6209706f2543Smrg	  <blockquote><para>
6210706f2543Smrg      Like <function>xf86DrvMsg()</function>, but with the verbosity level
6211706f2543Smrg      given explicitly.
6212706f2543Smrg	    </para>
6213706f2543Smrg
6214706f2543Smrg	  </blockquote></para></blockquote>
6215706f2543Smrg    </sect2>
6216706f2543Smrg
6217706f2543Smrg
6218706f2543Smrg    <sect2>
6219706f2543Smrg      <title>Functions for setting values based on command line and config file</title>
6220706f2543Smrg
6221706f2543Smrg      <blockquote><para>
6222706f2543Smrg	  <programlisting>
6223706f2543Smrg    Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp,
6224706f2543Smrg
6225706f2543Smrg                                int fbbpp, int depth24flags);
6226706f2543Smrg	  </programlisting>
6227706f2543Smrg	  <blockquote><para>
6228706f2543Smrg      This function sets the <structfield>depth</structfield>, <structfield>pixmapBPP</structfield> and <structfield>bitsPerPixel</structfield> fields
6229706f2543Smrg      of the <structname>ScrnInfoRec</structname>.  It also determines the defaults for display-wide
6230706f2543Smrg      attributes and pixmap formats the screen will support, and finds
6231706f2543Smrg      the Display subsection that matches the depth/bpp.  This function
6232706f2543Smrg      should normally be called very early from the
6233706f2543Smrg      <function>ChipPreInit()</function> function.
6234706f2543Smrg	    </para>
6235706f2543Smrg
6236706f2543Smrg	    <para>
6237706f2543Smrg      It requires that the <structfield>confScreen</structfield> field of the <structname>ScrnInfoRec</structname> be
6238706f2543Smrg      initialised prior to calling it.  This is done by the XFree86
6239706f2543Smrg      common layer prior to calling <function>ChipPreInit()</function>.
6240706f2543Smrg	    </para>
6241706f2543Smrg
6242706f2543Smrg	    <para>
6243706f2543Smrg      The parameters passed are:
6244706f2543Smrg
6245706f2543Smrg	      <variablelist>
6246706f2543Smrg		<varlistentry>
6247706f2543Smrg		  <term><parameter>depth</parameter></term>
6248706f2543Smrg		  <listitem><para>
6249706f2543Smrg		driver's preferred default depth if no other is given.
6250706f2543Smrg                If zero, use the overall server default.
6251706f2543Smrg		    </para></listitem></varlistentry>
6252706f2543Smrg
6253706f2543Smrg		<varlistentry>
6254706f2543Smrg		  <term><parameter>bpp</parameter></term>
6255706f2543Smrg		  <listitem><para>
6256706f2543Smrg		Same, but for the pixmap bpp.
6257706f2543Smrg		    </para></listitem></varlistentry>
6258706f2543Smrg
6259706f2543Smrg		<varlistentry>
6260706f2543Smrg		  <term><parameter>fbbpp</parameter></term>
6261706f2543Smrg		  <listitem><para>
6262706f2543Smrg		Same, but for the framebuffer bpp.
6263706f2543Smrg		    </para></listitem></varlistentry>
6264706f2543Smrg
6265706f2543Smrg		<varlistentry>
6266706f2543Smrg		  <term><parameter>depth24flags</parameter></term>
6267706f2543Smrg		  <listitem><para>
6268706f2543Smrg		Flags that indicate the level of 24/32bpp support
6269706f2543Smrg                and whether conversion between different framebuffer
6270706f2543Smrg                and pixmap formats is supported.  The flags for this
6271706f2543Smrg                argument are defined as follows, and multiple flags
6272706f2543Smrg                may be ORed together:
6273706f2543Smrg
6274706f2543Smrg		      <variablelist>
6275706f2543Smrg			<varlistentry>
6276706f2543Smrg			  <term><constant>NoDepth24Support</constant></term>
6277706f2543Smrg			  <listitem><para>No depth 24 formats supported
6278706f2543Smrg			    </para></listitem></varlistentry>
6279706f2543Smrg			<varlistentry>
6280706f2543Smrg			  <term><constant>Support24bppFb</constant></term>
6281706f2543Smrg			  <listitem><para>24bpp framebuffer supported
6282706f2543Smrg			    </para></listitem></varlistentry>
6283706f2543Smrg			<varlistentry>
6284706f2543Smrg			  <term><constant>Support32bppFb</constant></term>
6285706f2543Smrg			  <listitem><para>32bpp framebuffer supported
6286706f2543Smrg			    </para></listitem></varlistentry>
6287706f2543Smrg			<varlistentry>
6288706f2543Smrg			  <term><constant>SupportConvert24to32</constant></term>
6289706f2543Smrg			  <listitem><para>Can convert 24bpp pixmap to 32bpp fb
6290706f2543Smrg			    </para></listitem></varlistentry>
6291706f2543Smrg			<varlistentry>
6292706f2543Smrg			  <term><constant>SupportConvert32to24</constant></term>
6293706f2543Smrg			  <listitem><para>Can convert 32bpp pixmap to 24bpp fb
6294706f2543Smrg			    </para></listitem></varlistentry>
6295706f2543Smrg			<varlistentry>
6296706f2543Smrg			  <term><constant>ForceConvert24to32</constant></term>
6297706f2543Smrg			  <listitem><para>Force 24bpp pixmap to 32bpp fb conversion
6298706f2543Smrg			    </para></listitem></varlistentry>
6299706f2543Smrg			<varlistentry>
6300706f2543Smrg			  <term><constant>ForceConvert32to24</constant></term>
6301706f2543Smrg			  <listitem><para>Force 32bpp pixmap to 24bpp fb conversion
6302706f2543Smrg			    </para></listitem></varlistentry>
6303706f2543Smrg		      </variablelist>
6304706f2543Smrg		    </para></listitem></varlistentry>
6305706f2543Smrg
6306706f2543Smrg	      </variablelist>
6307706f2543Smrg	    </para>
6308706f2543Smrg
6309706f2543Smrg	    <para>
6310706f2543Smrg      It uses the command line, config file, and default values in the
6311706f2543Smrg      correct order of precedence to determine the depth and bpp values.
6312706f2543Smrg      It is up to the driver to check the results to see that it supports
6313706f2543Smrg      them.  If not the <function>ChipPreInit()</function> function should
6314706f2543Smrg      return <constant>FALSE</constant>.
6315706f2543Smrg	    </para>
6316706f2543Smrg
6317706f2543Smrg	    <para>
6318706f2543Smrg      If only one of depth/bpp is given, the other is set to a reasonable
6319706f2543Smrg      (and consistent) default.
6320706f2543Smrg	    </para>
6321706f2543Smrg
6322706f2543Smrg	    <para>
6323706f2543Smrg      If a driver finds that the initial <parameter>depth24flags</parameter>
6324706f2543Smrg      it uses later results in a fb format that requires more video
6325706f2543Smrg      memory than is available it may call this function a second time
6326706f2543Smrg      with a different <parameter>depth24flags</parameter> setting.
6327706f2543Smrg	    </para>
6328706f2543Smrg
6329706f2543Smrg	    <para>
6330706f2543Smrg      On success, the return value is <constant>TRUE</constant>.  On failure
6331706f2543Smrg      it prints an error message and returns <constant>FALSE</constant>.
6332706f2543Smrg	    </para>
6333706f2543Smrg
6334706f2543Smrg	    <para>
6335706f2543Smrg      The following fields of the <structname>ScrnInfoRec</structname> are
6336706f2543Smrg      initialised by this function:
6337706f2543Smrg
6338706f2543Smrg	      <blockquote><para>
6339706f2543Smrg<structfield>depth</structfield>, <structfield>bitsPerPixel</structfield>,
6340706f2543Smrg<structfield>display</structfield>, <structfield>imageByteOrder</structfield>,
6341706f2543Smrg<structfield>bitmapScanlinePad</structfield>,
6342706f2543Smrg<structfield>bitmapScanlineUnit</structfield>, <structfield>bitmapBitOrder</structfield>,
6343706f2543Smrg<structfield>numFormats</structfield>, <structfield>formats</structfield>,
6344706f2543Smrg<structfield>fbFormat</structfield>.
6345706f2543Smrg		</para></blockquote>
6346706f2543Smrg	    </para>
6347706f2543Smrg
6348706f2543Smrg	  </blockquote></para></blockquote>
6349706f2543Smrg
6350706f2543Smrg      <blockquote><para>
6351706f2543Smrg	  <programlisting>
6352706f2543Smrg    void xf86PrintDepthBpp(scrnInfoPtr scrp);
6353706f2543Smrg	  </programlisting>
6354706f2543Smrg	  <blockquote><para>
6355706f2543Smrg      This function can be used to print out the depth and bpp settings.
6356706f2543Smrg      It should be called after the final call to
6357706f2543Smrg      <function>xf86SetDepthBpp()</function>.
6358706f2543Smrg	    </para>
6359706f2543Smrg
6360706f2543Smrg	  </blockquote></para></blockquote>
6361706f2543Smrg
6362706f2543Smrg      <blockquote><para>
6363706f2543Smrg	  <programlisting>
6364706f2543Smrg    Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask);
6365706f2543Smrg	  </programlisting>
6366706f2543Smrg	  <blockquote><para>
6367706f2543Smrg      This function sets the <structfield>weight</structfield>, <structfield>mask</structfield>,
6368706f2543Smrg      <structfield>offset</structfield> and <structfield>rgbBits</structfield> fields of the
6369706f2543Smrg      <structname>ScrnInfoRec</structname>.  It would normally be called fairly
6370706f2543Smrg      early in the <function>ChipPreInit()</function> function for
6371706f2543Smrg      depths&nbsp;&gt;&nbsp;8bpp.
6372706f2543Smrg	    </para>
6373706f2543Smrg
6374706f2543Smrg	    <para>
6375706f2543Smrg      It requires that the <structfield>depth</structfield> and
6376706f2543Smrg      <structfield>display</structfield> fields of the <structname>ScrnInfoRec</structname>
6377706f2543Smrg      be initialised prior to calling it.
6378706f2543Smrg	    </para>
6379706f2543Smrg
6380706f2543Smrg	    <para>
6381706f2543Smrg      The parameters passed are:
6382706f2543Smrg
6383706f2543Smrg	      <variablelist>
6384706f2543Smrg		<varlistentry>
6385706f2543Smrg		  <term><parameter>weight</parameter></term>
6386706f2543Smrg		  <listitem><para>
6387706f2543Smrg		driver's preferred default weight if no other is given.
6388706f2543Smrg                If zero, use the overall server default.
6389706f2543Smrg
6390706f2543Smrg		    </para></listitem></varlistentry>
6391706f2543Smrg
6392706f2543Smrg		<varlistentry>
6393706f2543Smrg		  <term><parameter>mask</parameter></term>
6394706f2543Smrg		  <listitem><para>
6395706f2543Smrg		Same, but for mask.
6396706f2543Smrg
6397706f2543Smrg		    </para></listitem></varlistentry>
6398706f2543Smrg	      </variablelist>
6399706f2543Smrg	    </para>
6400706f2543Smrg
6401706f2543Smrg	    <para>
6402706f2543Smrg      It uses the command line, config file, and default values in the
6403706f2543Smrg      correct order of precedence to determine the weight value.  It
6404706f2543Smrg      derives the mask and offset values from the weight and the defaults.
6405706f2543Smrg      It is up to the driver to check the results to see that it supports
6406706f2543Smrg      them.  If not the <function>ChipPreInit()</function> function should
6407706f2543Smrg      return <constant>FALSE</constant>.
6408706f2543Smrg	    </para>
6409706f2543Smrg
6410706f2543Smrg	    <para>
6411706f2543Smrg      On success, this function prints a message showing the weight
6412706f2543Smrg      values selected, and returns <constant>TRUE</constant>.
6413706f2543Smrg	    </para>
6414706f2543Smrg
6415706f2543Smrg	    <para>
6416706f2543Smrg      On failure it prints an error message and returns <constant>FALSE</constant>.
6417706f2543Smrg	    </para>
6418706f2543Smrg
6419706f2543Smrg	    <para>
6420706f2543Smrg      The following fields of the <structname>ScrnInfoRec</structname> are
6421706f2543Smrg      initialised by this function:
6422706f2543Smrg
6423706f2543Smrg	      <blockquote><para>
6424706f2543Smrg		  <structfield>weight</structfield>,
6425706f2543Smrg		  <structfield>mask</structfield>,
6426706f2543Smrg		  <structfield>offset</structfield>.
6427706f2543Smrg		</para></blockquote>
6428706f2543Smrg	    </para>
6429706f2543Smrg
6430706f2543Smrg	  </blockquote></para></blockquote>
6431706f2543Smrg
6432706f2543Smrg      <blockquote><para>
6433706f2543Smrg	  <programlisting>
6434706f2543Smrg    Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual);
6435706f2543Smrg	  </programlisting>
6436706f2543Smrg	  <blockquote><para>
6437706f2543Smrg      This function sets the <structfield>defaultVisual</structfield> field of the
6438706f2543Smrg      <structname>ScrnInfoRec</structname>.  It would normally be called fairly
6439706f2543Smrg      early from the <function>ChipPreInit()</function> function.
6440706f2543Smrg	    </para>
6441706f2543Smrg
6442706f2543Smrg	    <para>
6443706f2543Smrg      It requires that the <structfield>depth</structfield> and
6444706f2543Smrg      <structfield>display</structfield> fields of the <structname>ScrnInfoRec</structname>
6445706f2543Smrg      be initialised prior to calling it.
6446706f2543Smrg	    </para>
6447706f2543Smrg
6448706f2543Smrg	    <para>
6449706f2543Smrg      The parameters passed are:
6450706f2543Smrg
6451706f2543Smrg	      <variablelist>
6452706f2543Smrg		<varlistentry>
6453706f2543Smrg		  <term><parameter>visual</parameter></term>
6454706f2543Smrg		  <listitem><para>
6455706f2543Smrg		driver's preferred default visual if no other is given.
6456706f2543Smrg		If <constant>-1</constant>, use the overall server default.
6457706f2543Smrg		    </para></listitem></varlistentry>
6458706f2543Smrg
6459706f2543Smrg	      </variablelist>
6460706f2543Smrg	    </para>
6461706f2543Smrg
6462706f2543Smrg	    <para>
6463706f2543Smrg      It uses the command line, config file, and default values in the
6464706f2543Smrg      correct order of precedence to determine the default visual value.
6465706f2543Smrg      It is up to the driver to check the result to see that it supports
6466706f2543Smrg      it.  If not the <function>ChipPreInit()</function> function should
6467706f2543Smrg      return <constant>FALSE</constant>.
6468706f2543Smrg	    </para>
6469706f2543Smrg
6470706f2543Smrg	    <para>
6471706f2543Smrg      On success, this function prints a message showing the default visual
6472706f2543Smrg      selected, and returns <constant>TRUE</constant>.
6473706f2543Smrg	    </para>
6474706f2543Smrg
6475706f2543Smrg	    <para>
6476706f2543Smrg      On failure it prints an error message and returns <constant>FALSE</constant>.
6477706f2543Smrg	    </para>
6478706f2543Smrg
6479706f2543Smrg	  </blockquote></para></blockquote>
6480706f2543Smrg
6481706f2543Smrg      <blockquote><para>
6482706f2543Smrg	  <programlisting>
6483706f2543Smrg    Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma);
6484706f2543Smrg	  </programlisting>
6485706f2543Smrg	  <blockquote><para>
6486706f2543Smrg      This function sets the <structfield>gamma</structfield> field of the
6487706f2543Smrg      <structname>ScrnInfoRec</structname>.  It would normally be called fairly
6488706f2543Smrg      early from the <function>ChipPreInit()</function> function in cases
6489706f2543Smrg      where the driver supports gamma correction.
6490706f2543Smrg	    </para>
6491706f2543Smrg
6492706f2543Smrg	    <para>
6493706f2543Smrg      It requires that the <structfield>monitor</structfield> field of the
6494706f2543Smrg      <structname>ScrnInfoRec</structname> be initialised prior to calling it.
6495706f2543Smrg	    </para>
6496706f2543Smrg
6497706f2543Smrg	    <para>
6498706f2543Smrg      The parameters passed are:
6499706f2543Smrg
6500706f2543Smrg	      <variablelist>
6501706f2543Smrg		<varlistentry>
6502706f2543Smrg		  <term><parameter>gamma</parameter></term>
6503706f2543Smrg		  <listitem><para>
6504706f2543Smrg		driver's preferred default gamma if no other is given.
6505706f2543Smrg		If zero (<code>&lt; 0.01</code>), use the overall server
6506706f2543Smrg		default.
6507706f2543Smrg		    </para></listitem></varlistentry>
6508706f2543Smrg
6509706f2543Smrg	      </variablelist>
6510706f2543Smrg	    </para>
6511706f2543Smrg
6512706f2543Smrg	    <para>
6513706f2543Smrg      It uses the command line, config file, and default values in the
6514706f2543Smrg      correct order of precedence to determine the gamma value.  It is
6515706f2543Smrg      up to the driver to check the results to see that it supports
6516706f2543Smrg      them.  If not the <function>ChipPreInit()</function> function should
6517706f2543Smrg      return <constant>FALSE</constant>.
6518706f2543Smrg	    </para>
6519706f2543Smrg
6520706f2543Smrg	    <para>
6521706f2543Smrg      On success, this function prints a message showing the gamma
6522706f2543Smrg      value selected, and returns <constant>TRUE</constant>.
6523706f2543Smrg	    </para>
6524706f2543Smrg
6525706f2543Smrg	    <para>
6526706f2543Smrg      On failure it prints an error message and returns <constant>FALSE</constant>.
6527706f2543Smrg	    </para>
6528706f2543Smrg
6529706f2543Smrg	  </blockquote></para></blockquote>
6530706f2543Smrg
6531706f2543Smrg
6532706f2543Smrg      <blockquote><para>
6533706f2543Smrg	  <programlisting>
6534706f2543Smrg    void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y);
6535706f2543Smrg	  </programlisting>
6536706f2543Smrg	  <blockquote><para>
6537706f2543Smrg      This function sets the <structfield>xDpi</structfield> and <structfield>yDpi</structfield>
6538706f2543Smrg      fields of the <structname>ScrnInfoRec</structname>.  The driver can specify
6539706f2543Smrg      preferred defaults by setting <parameter>x</parameter> and <parameter>y</parameter>
6540706f2543Smrg      to non-zero values.  The <option>-dpi</option> command line option
6541706f2543Smrg      overrides all other settings.  Otherwise, if the
6542706f2543Smrg      <emphasis>DisplaySize</emphasis> entry is present in the screen's &k.monitor;
6543706f2543Smrg      config file section, it is used together with the virtual size to
6544706f2543Smrg      calculate the dpi values.  This function should be called after
6545706f2543Smrg      all the mode resolution has been done.
6546706f2543Smrg	    </para>
6547706f2543Smrg
6548706f2543Smrg	  </blockquote></para></blockquote>
6549706f2543Smrg
6550706f2543Smrg      <blockquote><para>
6551706f2543Smrg	  <programlisting>
6552706f2543Smrg    void xf86SetBlackWhitePixels(ScrnInfoPtr pScrn);
6553706f2543Smrg	  </programlisting>
6554706f2543Smrg	  <blockquote><para>
6555706f2543Smrg      This functions sets the <structfield>blackPixel</structfield> and
6556706f2543Smrg      <structfield>whitePixel</structfield> fields of the <structname>ScrnInfoRec</structname>
6557706f2543Smrg      according to whether or not the <option>-flipPixels</option> command
6558706f2543Smrg      line options is present.
6559706f2543Smrg	    </para>
6560706f2543Smrg
6561706f2543Smrg	  </blockquote></para></blockquote>
6562706f2543Smrg
6563706f2543Smrg      <blockquote><para>
6564706f2543Smrg	  <programlisting>
6565706f2543Smrg    const char *xf86GetVisualName(int visual);
6566706f2543Smrg	  </programlisting>
6567706f2543Smrg	  <blockquote><para>
6568706f2543Smrg      Returns a printable string with the visual name matching the
6569706f2543Smrg      numerical visual class provided.  If the value is outside the
6570706f2543Smrg      range of valid visual classes, <constant>NULL</constant> is returned.
6571706f2543Smrg	    </para>
6572706f2543Smrg
6573706f2543Smrg	  </blockquote></para></blockquote>
6574706f2543Smrg
6575706f2543Smrg    </sect2>
6576706f2543Smrg
6577706f2543Smrg    <sect2>
6578706f2543Smrg      <title>Primary Mode functions</title>
6579706f2543Smrg
6580706f2543Smrg      <para>
6581706f2543SmrgThe primary mode helper functions are those which would normally be
6582706f2543Smrgused by a driver, unless it has unusual requirements which cannot
6583706f2543Smrgbe catered for the by the helpers.
6584706f2543Smrg      </para>
6585706f2543Smrg
6586706f2543Smrg      <blockquote><para>
6587706f2543Smrg	  <programlisting>
6588706f2543Smrg    int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
6589706f2543Smrg                          char **modeNames, ClockRangePtr clockRanges,
6590706f2543Smrg                          int *linePitches, int minPitch, int maxPitch,
6591706f2543Smrg                          int pitchInc, int minHeight, int maxHeight,
6592706f2543Smrg                          int virtualX, int virtualY,
6593706f2543Smrg                          unsigned long apertureSize,
6594706f2543Smrg                          LookupModeFlags strategy);
6595706f2543Smrg	  </programlisting>
6596706f2543Smrg	  <blockquote><para>
6597706f2543Smrg      This function basically selects the set of modes to use based on
6598706f2543Smrg      those available and the various constraints.  It also sets some
6599706f2543Smrg      other related parameters.  It is normally called near the end of
6600706f2543Smrg      the <function>ChipPreInit()</function> function.
6601706f2543Smrg	    </para>
6602706f2543Smrg
6603706f2543Smrg	    <para>
6604706f2543Smrg      The parameters passed to the function are:
6605706f2543Smrg
6606706f2543Smrg	      <variablelist>
6607706f2543Smrg		<varlistentry>
6608706f2543Smrg		  <term><parameter>availModes</parameter></term>
6609706f2543Smrg		  <listitem><para>
6610706f2543Smrg		List of modes available for the monitor.
6611706f2543Smrg		    </para></listitem></varlistentry>
6612706f2543Smrg
6613706f2543Smrg		<varlistentry>
6614706f2543Smrg		  <term><parameter>modeNames</parameter></term>
6615706f2543Smrg		  <listitem><para>
6616706f2543Smrg		List of mode names that the screen is requesting.
6617706f2543Smrg		    </para></listitem></varlistentry>
6618706f2543Smrg
6619706f2543Smrg		<varlistentry>
6620706f2543Smrg		  <term><parameter>clockRanges</parameter></term>
6621706f2543Smrg		  <listitem><para>
6622706f2543Smrg		A list of clock ranges allowed by the driver.  Each
6623706f2543Smrg		range includes whether interlaced or multiscan modes
6624706f2543Smrg		are supported for that range.  See below for more on
6625706f2543Smrg		<parameter>clockRanges</parameter>.
6626706f2543Smrg		    </para></listitem></varlistentry>
6627706f2543Smrg
6628706f2543Smrg		<varlistentry>
6629706f2543Smrg		  <term><parameter>linePitches</parameter></term>
6630706f2543Smrg		  <listitem><para>
6631706f2543Smrg		List of line pitches supported by the driver.
6632706f2543Smrg		This is optional and should be <constant>NULL</constant> when
6633706f2543Smrg		not used.
6634706f2543Smrg		    </para></listitem></varlistentry>
6635706f2543Smrg
6636706f2543Smrg		<varlistentry>
6637706f2543Smrg		  <term><parameter>minPitch</parameter></term>
6638706f2543Smrg		  <listitem><para>
6639706f2543Smrg		Minimum line pitch supported by the driver.  This must
6640706f2543Smrg		be supplied when <parameter>linePitches</parameter> is
6641706f2543Smrg		<constant>NULL</constant>, and is ignored otherwise.
6642706f2543Smrg		    </para></listitem></varlistentry>
6643706f2543Smrg
6644706f2543Smrg		<varlistentry>
6645706f2543Smrg		  <term><parameter>maxPitch</parameter></term>
6646706f2543Smrg		  <listitem><para>
6647706f2543Smrg		Maximum line pitch supported by the driver.  This is
6648706f2543Smrg		required when <parameter>minPitch</parameter> is required.
6649706f2543Smrg		    </para></listitem></varlistentry>
6650706f2543Smrg
6651706f2543Smrg		<varlistentry>
6652706f2543Smrg		  <term><parameter>pitchInc</parameter></term>
6653706f2543Smrg		  <listitem><para>
6654706f2543Smrg		Granularity of horizontal pitch values as supported by
6655706f2543Smrg		the chipset.  This is expressed in bits.  This must be
6656706f2543Smrg		supplied.
6657706f2543Smrg		    </para></listitem></varlistentry>
6658706f2543Smrg
6659706f2543Smrg		<varlistentry>
6660706f2543Smrg		  <term><parameter>minHeight</parameter></term>
6661706f2543Smrg		  <listitem><para>
6662706f2543Smrg		minimum virtual height allowed.  If zero, no limit is
6663706f2543Smrg		imposed.
6664706f2543Smrg		    </para></listitem></varlistentry>
6665706f2543Smrg
6666706f2543Smrg		<varlistentry>
6667706f2543Smrg		  <term><parameter>maxHeight</parameter></term>
6668706f2543Smrg		  <listitem><para>
6669706f2543Smrg		maximum virtual height allowed.  If zero, no limit is
6670706f2543Smrg		imposed.
6671706f2543Smrg		    </para></listitem></varlistentry>
6672706f2543Smrg
6673706f2543Smrg		<varlistentry>
6674706f2543Smrg		  <term><parameter>virtualX</parameter></term>
6675706f2543Smrg		  <listitem><para>
6676706f2543Smrg		If greater than zero, this is the virtual width value
6677706f2543Smrg		that will be used.  Otherwise, the virtual width is
6678706f2543Smrg		chosen to be the smallest that can accommodate the modes
6679706f2543Smrg		selected.
6680706f2543Smrg		    </para></listitem></varlistentry>
6681706f2543Smrg
6682706f2543Smrg		<varlistentry>
6683706f2543Smrg		  <term><parameter>virtualY</parameter></term>
6684706f2543Smrg		  <listitem><para>
6685706f2543Smrg		If greater than zero, this is the virtual height value
6686706f2543Smrg		that will be used.  Otherwise, the virtual height is
6687706f2543Smrg		chosen to be the smallest that can accommodate the modes
6688706f2543Smrg		selected.
6689706f2543Smrg		    </para></listitem></varlistentry>
6690706f2543Smrg
6691706f2543Smrg		<varlistentry>
6692706f2543Smrg		  <term><parameter>apertureSize</parameter></term>
6693706f2543Smrg		  <listitem><para>
6694706f2543Smrg		The size (in bytes) of the aperture used to access video
6695706f2543Smrg		memory.
6696706f2543Smrg		    </para></listitem></varlistentry>
6697706f2543Smrg
6698706f2543Smrg		<varlistentry>
6699706f2543Smrg		  <term><parameter>strategy</parameter></term>
6700706f2543Smrg		  <listitem><para>
6701706f2543Smrg		The strategy to use when choosing from multiple modes
6702706f2543Smrg		with the same name.  The options are:
6703706f2543Smrg
6704706f2543Smrg		      <variablelist>
6705706f2543Smrg			<varlistentry>
6706706f2543Smrg			  <term><constant>LOOKUP_DEFAULT</constant></term>
6707706f2543Smrg			  <listitem><para>???
6708706f2543Smrg			    </para></listitem></varlistentry>
6709706f2543Smrg			<varlistentry>
6710706f2543Smrg			  <term><constant>LOOKUP_BEST_REFRESH</constant></term>
6711706f2543Smrg			  <listitem><para>mode with best refresh rate
6712706f2543Smrg			    </para></listitem></varlistentry>
6713706f2543Smrg			<varlistentry>
6714706f2543Smrg			  <term><constant>LOOKUP_CLOSEST_CLOCK</constant></term>
6715706f2543Smrg			  <listitem><para>mode with closest matching clock
6716706f2543Smrg			    </para></listitem></varlistentry>
6717706f2543Smrg			<varlistentry>
6718706f2543Smrg			  <term><constant>LOOKUP_LIST_ORDER</constant></term>
6719706f2543Smrg			  <listitem><para>first usable mode in list
6720706f2543Smrg			    </para></listitem></varlistentry>
6721706f2543Smrg		      </variablelist>
6722706f2543Smrg
6723706f2543Smrg		The following options can also be combined (OR'ed) with
6724706f2543Smrg		one of the above:
6725706f2543Smrg
6726706f2543Smrg		      <variablelist>
6727706f2543Smrg			<varlistentry>
6728706f2543Smrg			  <term><constant>LOOKUP_CLKDIV2</constant></term>
6729706f2543Smrg			  <listitem><para>Allow halved clocks
6730706f2543Smrg			    </para></listitem></varlistentry>
6731706f2543Smrg			<varlistentry>
6732706f2543Smrg			  <term><constant>LOOKUP_OPTIONAL_TOLERANCES</constant></term>
6733706f2543Smrg			  <listitem><para>
6734706f2543Smrg		      Allow missing horizontal sync and/or vertical refresh
6735706f2543Smrg		      ranges in the xorg.conf Monitor section
6736706f2543Smrg			    </para></listitem></varlistentry>
6737706f2543Smrg		      </variablelist>
6738706f2543Smrg
6739706f2543Smrg		<constant>LOOKUP_OPTIONAL_TOLERANCES</constant> should only be
6740706f2543Smrg		specified when the driver can ensure all modes it generates
6741706f2543Smrg		can sync on, or at least not damage, the monitor or digital
6742706f2543Smrg		flat panel.  Horizontal sync and/or vertical refresh ranges
6743706f2543Smrg		specified by the user will still be honoured (and acted upon).
6744706f2543Smrg
6745706f2543Smrg		    </para></listitem></varlistentry>
6746706f2543Smrg	      </variablelist>
6747706f2543Smrg	    </para>
6748706f2543Smrg
6749706f2543Smrg	    <para>
6750706f2543Smrg      This function requires that the following fields of the
6751706f2543Smrg      <structname>ScrnInfoRec</structname> are initialised prior to calling it:
6752706f2543Smrg
6753706f2543Smrg	      <variablelist>
6754706f2543Smrg		<varlistentry>
6755706f2543Smrg		  <term><structfield>clock[]</structfield></term>
6756706f2543Smrg		  <listitem><para>
6757706f2543Smrg		      List of discrete clocks (when non-programmable)
6758706f2543Smrg		    </para></listitem></varlistentry>
6759706f2543Smrg		<varlistentry>
6760706f2543Smrg		  <term><structfield>numClocks</structfield></term>
6761706f2543Smrg		  <listitem><para>
6762706f2543Smrg		      Number of discrete clocks (when non-programmable)
6763706f2543Smrg		    </para></listitem></varlistentry>
6764706f2543Smrg		<varlistentry>
6765706f2543Smrg		  <term><structfield>progClock</structfield></term>
6766706f2543Smrg		  <listitem><para>
6767706f2543Smrg		      Whether the clock is programmable or not
6768706f2543Smrg		    </para></listitem></varlistentry>
6769706f2543Smrg		<varlistentry>
6770706f2543Smrg		  <term><structfield>monitor</structfield></term>
6771706f2543Smrg		  <listitem><para>
6772706f2543Smrg		      Pointer to the applicable xorg.conf monitor section
6773706f2543Smrg		    </para></listitem></varlistentry>
6774706f2543Smrg		<varlistentry>
6775706f2543Smrg		  <term><structfield>fdFormat</structfield></term>
6776706f2543Smrg		  <listitem><para>
6777706f2543Smrg		      Format of the screen buffer
6778706f2543Smrg		    </para></listitem></varlistentry>
6779706f2543Smrg		<varlistentry>
6780706f2543Smrg		  <term><structfield>videoRam</structfield></term>
6781706f2543Smrg		  <listitem><para>
6782706f2543Smrg		      total video memory size (in bytes)
6783706f2543Smrg		    </para></listitem></varlistentry>
6784706f2543Smrg		<varlistentry>
6785706f2543Smrg		  <term><structfield>maxHValue</structfield></term>
6786706f2543Smrg		  <listitem><para>
6787706f2543Smrg		      Maximum horizontal timing value allowed
6788706f2543Smrg		    </para></listitem></varlistentry>
6789706f2543Smrg		<varlistentry>
6790706f2543Smrg		  <term><structfield>maxVValue</structfield></term>
6791706f2543Smrg		  <listitem><para>
6792706f2543Smrg		      Maximum vertical timing value allowed
6793706f2543Smrg		    </para></listitem></varlistentry>
6794706f2543Smrg		<varlistentry>
6795706f2543Smrg		  <term><structfield>xInc</structfield></term>
6796706f2543Smrg		  <listitem><para>
6797706f2543Smrg		      Horizontal timing increment in pixels (defaults to 8)
6798706f2543Smrg		    </para></listitem></varlistentry>
6799706f2543Smrg	      </variablelist>
6800706f2543Smrg	    </para>
6801706f2543Smrg
6802706f2543Smrg	    <para>
6803706f2543Smrg      This function fills in the following <structname>ScrnInfoRec</structname>
6804706f2543Smrg      fields:
6805706f2543Smrg
6806706f2543Smrg	      <variablelist>
6807706f2543Smrg		<varlistentry>
6808706f2543Smrg		  <term><structfield>modePool</structfield></term>
6809706f2543Smrg		  <listitem><para>
6810706f2543Smrg		A subset of the modes available to the monitor which
6811706f2543Smrg                are compatible with the driver.
6812706f2543Smrg		    </para></listitem></varlistentry>
6813706f2543Smrg
6814706f2543Smrg		<varlistentry>
6815706f2543Smrg		  <term><structfield>modes</structfield></term>
6816706f2543Smrg		  <listitem><para>
6817706f2543Smrg		One mode entry for each of the requested modes, with
6818706f2543Smrg                the status field of each filled in to indicate if
6819706f2543Smrg                the mode has been accepted or not.  This list of
6820706f2543Smrg                modes is a circular list.
6821706f2543Smrg		    </para></listitem></varlistentry>
6822706f2543Smrg
6823706f2543Smrg		<varlistentry>
6824706f2543Smrg		  <term><structfield>virtualX</structfield></term>
6825706f2543Smrg		  <listitem><para>
6826706f2543Smrg		The resulting virtual width.
6827706f2543Smrg		    </para></listitem></varlistentry>
6828706f2543Smrg
6829706f2543Smrg		<varlistentry>
6830706f2543Smrg		  <term><structfield>virtualY</structfield></term>
6831706f2543Smrg		  <listitem><para>
6832706f2543Smrg		The resulting virtual height.
6833706f2543Smrg		    </para></listitem></varlistentry>
6834706f2543Smrg
6835706f2543Smrg		<varlistentry>
6836706f2543Smrg		  <term><structfield>displayWidth</structfield></term>
6837706f2543Smrg		  <listitem><para>
6838706f2543Smrg		The resulting line pitch.
6839706f2543Smrg		    </para></listitem></varlistentry>
6840706f2543Smrg
6841706f2543Smrg		<varlistentry>
6842706f2543Smrg		  <term><structfield>virtualFrom</structfield></term>
6843706f2543Smrg		  <listitem><para>
6844706f2543Smrg		Where the virtual size was determined from.
6845706f2543Smrg		    </para></listitem></varlistentry>
6846706f2543Smrg
6847706f2543Smrg	      </variablelist>
6848706f2543Smrg	    </para>
6849706f2543Smrg
6850706f2543Smrg	    <para>
6851706f2543Smrg      The first stage of this function checks that the
6852706f2543Smrg      <parameter>virtualX</parameter> and <parameter>virtualY</parameter> values
6853706f2543Smrg      supplied (if greater than zero) are consistent with the line pitch
6854706f2543Smrg      and <parameter>maxHeight</parameter> limitations.  If not, an error
6855706f2543Smrg      message is printed, and the return value is <constant>-1</constant>.
6856706f2543Smrg	    </para>
6857706f2543Smrg
6858706f2543Smrg	    <para>
6859706f2543Smrg      The second stage sets up the mode pool, eliminating immediately
6860706f2543Smrg      any modes that exceed the driver's line pitch limits, and also
6861706f2543Smrg      the virtual width and height limits (if greater than zero).  For
6862706f2543Smrg      each mode removed an informational message is printed at verbosity
6863706f2543Smrg      level <constant>2</constant>.  If the mode pool ends up being empty,
6864706f2543Smrg      a warning message is printed, and the return value is
6865706f2543Smrg      <constant>0</constant>.
6866706f2543Smrg	    </para>
6867706f2543Smrg
6868706f2543Smrg	    <para>
6869706f2543Smrg      The final stage is to lookup each mode name, and fill in the remaining
6870706f2543Smrg      parameters.  If an error condition is encountered, a message is
6871706f2543Smrg      printed, and the return value is <constant>-1</constant>.  Otherwise,
6872706f2543Smrg      the return value is the number of valid modes found
6873706f2543Smrg      (<constant>0</constant> if none are found).
6874706f2543Smrg	    </para>
6875706f2543Smrg
6876706f2543Smrg	    <para>
6877706f2543Smrg      Even if the supplied mode names include duplicates, no two names will
6878706f2543Smrg      ever match the same mode.  Furthermore, if the supplied mode names do not
6879706f2543Smrg      yield a valid mode (including the case where no names are passed at all),
6880706f2543Smrg      the function will continue looking through the mode pool until it finds
6881706f2543Smrg      a mode that survives all checks, or until the mode pool is exhausted.
6882706f2543Smrg	    </para>
6883706f2543Smrg
6884706f2543Smrg	    <para>
6885706f2543Smrg      A message is only printed by this function when a fundamental
6886706f2543Smrg      problem is found.  It is intended that this function may be called
6887706f2543Smrg      more than once if there is more than one set of constraints that
6888706f2543Smrg      the driver can work within.
6889706f2543Smrg	    </para>
6890706f2543Smrg
6891706f2543Smrg	    <para>
6892706f2543Smrg      If this function returns <constant>-1</constant>, the
6893706f2543Smrg      <function>ChipPreInit()</function> function should return
6894706f2543Smrg      <constant>FALSE</constant>.
6895706f2543Smrg	    </para>
6896706f2543Smrg
6897706f2543Smrg	    <para>
6898706f2543Smrg      <parameter>clockRanges</parameter> is a linked list of clock ranges
6899706f2543Smrg      allowed by the driver.  If a mode doesn't fit in any of the defined
6900706f2543Smrg      <parameter>clockRanges</parameter>, it is rejected.  The first
6901706f2543Smrg      <literal remap="tt">clockRange</literal> that matches all requirements is used.
6902706f2543Smrg      This structure needs to be initialized to NULL when allocated.
6903706f2543Smrg	    </para>
6904706f2543Smrg
6905706f2543Smrg	    <para>
6906706f2543Smrg      <parameter>clockRanges</parameter> contains the following fields:
6907706f2543Smrg
6908706f2543Smrg	      <variablelist>
6909706f2543Smrg		<varlistentry>
6910706f2543Smrg		  <term><structfield>minClock</structfield></term>
6911706f2543Smrg		  <term><structfield>maxClock</structfield></term>
6912706f2543Smrg		  <listitem><para>
6913706f2543Smrg		The lower and upper mode clock bounds for which the rest
6914706f2543Smrg		of the <structname>clockRange</structname> parameters apply.
6915706f2543Smrg		Since these are the mode clocks, they are not scaled
6916706f2543Smrg		with the <structfield>ClockMulFactor</structfield> and
6917706f2543Smrg		<structfield>ClockDivFactor</structfield>.  It is up to the driver
6918706f2543Smrg		to adjust these values if they depend on the clock
6919706f2543Smrg		scaling factors.
6920706f2543Smrg		    </para></listitem></varlistentry>
6921706f2543Smrg
6922706f2543Smrg		<varlistentry>
6923706f2543Smrg		  <term><structfield>clockIndex</structfield></term>
6924706f2543Smrg		  <listitem><para>
6925706f2543Smrg		(not used yet) <constant>-1</constant> for programmable clocks
6926706f2543Smrg		    </para></listitem></varlistentry>
6927706f2543Smrg
6928706f2543Smrg		<varlistentry>
6929706f2543Smrg		  <term><structfield>interlaceAllowed</structfield></term>
6930706f2543Smrg		  <listitem><para>
6931706f2543Smrg		<constant>TRUE</constant> if interlacing is allowed for this
6932706f2543Smrg		range
6933706f2543Smrg		    </para></listitem></varlistentry>
6934706f2543Smrg
6935706f2543Smrg		<varlistentry>
6936706f2543Smrg		  <term><structfield>doubleScanAllowed</structfield></term>
6937706f2543Smrg		  <listitem><para>
6938706f2543Smrg		<constant>TRUE</constant> if doublescan or multiscan is allowed
6939706f2543Smrg		for this range
6940706f2543Smrg		    </para></listitem></varlistentry>
6941706f2543Smrg
6942706f2543Smrg		<varlistentry>
6943706f2543Smrg		  <term><structfield>ClockMulFactor</structfield></term>
6944706f2543Smrg		  <term><structfield>ClockDivFactor</structfield></term>
6945706f2543Smrg		  <listitem><para>
6946706f2543Smrg		Scaling factors that are applied to the mode clocks ONLY
6947706f2543Smrg		before selecting a clock index (when there is no
6948706f2543Smrg		programmable clock) or a <structfield>SynthClock</structfield>
6949706f2543Smrg		value.  This is useful for drivers that support pixel
6950706f2543Smrg		multiplexing or that need to scale the clocks because
6951706f2543Smrg		of hardware restrictions (like sending 24bpp data to an
6952706f2543Smrg		8 bit RAMDAC using a tripled clock).
6953706f2543Smrg		    </para>
6954706f2543Smrg
6955706f2543Smrg		    <para>
6956706f2543Smrg		Note that these parameters describe what must be done
6957706f2543Smrg		to the mode clock to achieve the data transport clock
6958706f2543Smrg		between graphics controller and RAMDAC.  For example
6959706f2543Smrg		for <literal remap="tt">2:1</literal> pixel multiplexing, two pixels
6960706f2543Smrg		are sent to the RAMDAC on each clock.  This allows the
6961706f2543Smrg		RAMDAC clock to be half of the actual pixel clock.
6962706f2543Smrg		Hence, <code>ClockMulFactor=1</code> and
6963706f2543Smrg		<code>ClockDivFactor=2</code>.  This means that the
6964706f2543Smrg		clock used for clock selection (ie, determining the
6965706f2543Smrg		correct clock index from the list of discrete clocks)
6966706f2543Smrg		or for the <structfield>SynthClock</structfield> field in case of
6967706f2543Smrg		a programmable clock is:  (<code>mode-&gt;Clock *
6968706f2543Smrg		ClockMulFactor) / ClockDivFactor</code>.
6969706f2543Smrg		    </para></listitem></varlistentry>
6970706f2543Smrg
6971706f2543Smrg		<varlistentry>
6972706f2543Smrg		  <term><structfield>PrivFlags</structfield></term>
6973706f2543Smrg		  <listitem><para>
6974706f2543Smrg		This field is copied into the
6975706f2543Smrg		<literal remap="tt">mode-&gt;PrivFlags</literal> field when this
6976706f2543Smrg		<literal remap="tt">clockRange</literal> is selected by
6977706f2543Smrg		<function>xf86ValidateModes()</function>.  It allows the
6978706f2543Smrg		driver to find out what clock range was selected, so it
6979706f2543Smrg		knows it needs to set up pixel multiplexing or any other
6980706f2543Smrg		range-dependent feature.  This field is purely
6981706f2543Smrg		driver-defined: it may contain flag bits, an index or
6982706f2543Smrg		anything else (as long as it is an <literal remap="tt">INT</literal>).
6983706f2543Smrg		    </para></listitem></varlistentry>
6984706f2543Smrg	      </variablelist>
6985706f2543Smrg	    </para>
6986706f2543Smrg
6987706f2543Smrg	    <para>
6988706f2543Smrg      Note that the <structfield>mode-&gt;SynthClock</structfield> field is always
6989706f2543Smrg      filled in by <function>xf86ValidateModes()</function>: it will contain
6990706f2543Smrg      the <quote>data transport clock</quote>, which is the clock that will have
6991706f2543Smrg      to be programmed in the chip when it has a programmable clock, or
6992706f2543Smrg      the clock that will be picked from the clocks list when it is not
6993706f2543Smrg      a programmable one.  Thus:
6994706f2543Smrg
6995706f2543Smrg	      <programlisting>
6996706f2543Smrg    mode-&gt;SynthClock = (mode-&gt;Clock * ClockMulFactor) / ClockDivFactor
6997706f2543Smrg	      </programlisting>
6998706f2543Smrg	    </para>
6999706f2543Smrg
7000706f2543Smrg	  </blockquote></para></blockquote>
7001706f2543Smrg
7002706f2543Smrg      <blockquote><para>
7003706f2543Smrg	  <programlisting>
7004706f2543Smrg    void xf86PruneDriverModes(ScrnInfoPtr scrp);
7005706f2543Smrg	  </programlisting>
7006706f2543Smrg	  <blockquote><para>
7007706f2543Smrg      This function deletes modes in the modes field of the
7008706f2543Smrg      <structname>ScrnInfoRec</structname> that have been marked as invalid.
7009706f2543Smrg      This is normally run after having run
7010706f2543Smrg      <function>xf86ValidateModes()</function> for the last time.  For each
7011706f2543Smrg      mode that is deleted, a warning message is printed out indicating
7012706f2543Smrg      the reason for it being deleted.
7013706f2543Smrg	    </para>
7014706f2543Smrg
7015706f2543Smrg	  </blockquote></para></blockquote>
7016706f2543Smrg
7017706f2543Smrg      <blockquote><para>
7018706f2543Smrg	  <programlisting>
7019706f2543Smrg    void xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags);
7020706f2543Smrg	  </programlisting>
7021706f2543Smrg	  <blockquote><para>
7022706f2543Smrg      This function fills in the <structname>Crtc*</structname> fields for all
7023706f2543Smrg      the modes in the <structfield>modes</structfield> field of the
7024706f2543Smrg      <structname>ScrnInfoRec</structname>.  The <parameter>adjustFlags</parameter>
7025706f2543Smrg      parameter determines how the vertical CRTC values are scaled for
7026706f2543Smrg      interlaced modes.  They are halved if it is
7027706f2543Smrg      <constant>INTERLACE_HALVE_V</constant>.  The vertical CRTC values are
7028706f2543Smrg      doubled for doublescan modes, and are further multiplied by the
7029706f2543Smrg      <literal remap="tt">VScan</literal> value.
7030706f2543Smrg	    </para>
7031706f2543Smrg
7032706f2543Smrg	    <para>
7033706f2543Smrg      This function is normally called after calling
7034706f2543Smrg      <function>xf86PruneDriverModes()</function>.
7035706f2543Smrg	    </para>
7036706f2543Smrg
7037706f2543Smrg	  </blockquote></para></blockquote>
7038706f2543Smrg
7039706f2543Smrg      <blockquote><para>
7040706f2543Smrg	  <programlisting>
7041706f2543Smrg    void xf86PrintModes(ScrnInfoPtr scrp);
7042706f2543Smrg	  </programlisting>
7043706f2543Smrg	  <blockquote><para>
7044706f2543Smrg      This function prints out the virtual size setting, and the line
7045706f2543Smrg      pitch being used.  It also prints out two lines for each mode being
7046706f2543Smrg      used.  The first line includes the mode's pixel clock, horizontal sync
7047706f2543Smrg      rate, refresh rate, and whether it is interlaced, doublescanned and/or
7048706f2543Smrg      multi-scanned.  The second line is the mode's Modeline.
7049706f2543Smrg	    </para>
7050706f2543Smrg
7051706f2543Smrg	    <para>
7052706f2543Smrg      This function is normally called after calling
7053706f2543Smrg      <function>xf86SetCrtcForModes()</function>.
7054706f2543Smrg	    </para>
7055706f2543Smrg
7056706f2543Smrg	  </blockquote></para></blockquote>
7057706f2543Smrg
7058706f2543Smrg    </sect2>
7059706f2543Smrg
7060706f2543Smrg    <sect2>
7061706f2543Smrg      <title>Secondary Mode functions</title>
7062706f2543Smrg
7063706f2543Smrg      <para>
7064706f2543SmrgThe secondary mode helper functions are functions which are normally
7065706f2543Smrgused by the primary mode helper functions, and which are not normally
7066706f2543Smrgcalled directly by a driver.  If a driver has unusual requirements
7067706f2543Smrgand needs to do its own mode validation, it might be able to make
7068706f2543Smrguse of some of these secondary mode helper functions.
7069706f2543Smrg      </para>
7070706f2543Smrg
7071706f2543Smrg      <blockquote><para>
7072706f2543Smrg	  <programlisting>
7073706f2543Smrg    int xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
7074706f2543Smrg                            int *divider);
7075706f2543Smrg	  </programlisting>
7076706f2543Smrg	  <blockquote><para>
7077706f2543Smrg      This function returns the index of the closest clock to the
7078706f2543Smrg      frequency <parameter>freq</parameter> given (in kHz).  It assumes that
7079706f2543Smrg      the number of clocks is greater than zero.  It requires that the
7080706f2543Smrg      <structfield>numClocks</structfield> and <structfield>clock</structfield> fields of the
7081706f2543Smrg      <structname>ScrnInfoRec</structname> are initialised.  The
7082706f2543Smrg      <structfield>allowDiv2</structfield> field determines if the clocks can be
7083706f2543Smrg      halved.  The <parameter>*divider</parameter> return value indicates
7084706f2543Smrg      whether clock division is used when determining the clock returned.
7085706f2543Smrg	    </para>
7086706f2543Smrg
7087706f2543Smrg	    <para>
7088706f2543Smrg      This function is only for non-programmable clocks.
7089706f2543Smrg	    </para>
7090706f2543Smrg
7091706f2543Smrg	  </blockquote></para></blockquote>
7092706f2543Smrg
7093706f2543Smrg      <blockquote><para>
7094706f2543Smrg	  <programlisting>
7095706f2543Smrg    const char *xf86ModeStatusToString(ModeStatus status);
7096706f2543Smrg	  </programlisting>
7097706f2543Smrg	  <blockquote><para>
7098706f2543Smrg      This function converts the <parameter>status</parameter> value to a
7099706f2543Smrg      descriptive printable string.
7100706f2543Smrg	    </para>
7101706f2543Smrg
7102706f2543Smrg	  </blockquote></para></blockquote>
7103706f2543Smrg
7104706f2543Smrg      <blockquote><para>
7105706f2543Smrg	  <programlisting>
7106706f2543Smrg    ModeStatus xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
7107706f2543Smrg                     ClockRangePtr clockRanges, LookupModeFlags strategy);
7108706f2543Smrg	  </programlisting>
7109706f2543Smrg	  <blockquote><para>
7110706f2543Smrg      This function takes a pointer to a mode with the name filled in,
7111706f2543Smrg      and looks for a mode in the <structfield>modePool</structfield> list which
7112706f2543Smrg      matches.  The parameters of the matching mode are filled in to
7113706f2543Smrg      <parameter>*modep</parameter>.  The <parameter>clockRanges</parameter> and
7114706f2543Smrg      <parameter>strategy</parameter> parameters are as for the
7115706f2543Smrg      <function>xf86ValidateModes()</function> function above.
7116706f2543Smrg	    </para>
7117706f2543Smrg
7118706f2543Smrg	    <para>
7119706f2543Smrg      This function requires the <structfield>modePool</structfield>,
7120706f2543Smrg      <structfield>clock[]</structfield>, <structfield>numClocks</structfield> and
7121706f2543Smrg      <structfield>progClock</structfield> fields of the <structname>ScrnInfoRec</structname>
7122706f2543Smrg      to be initialised before being called.
7123706f2543Smrg	    </para>
7124706f2543Smrg
7125706f2543Smrg	    <para>
7126706f2543Smrg      The return value is <constant>MODE_OK</constant> if a mode was found.
7127706f2543Smrg      Otherwise it indicates why a matching mode could not be found.
7128706f2543Smrg	    </para>
7129706f2543Smrg
7130706f2543Smrg	  </blockquote></para></blockquote>
7131706f2543Smrg
7132706f2543Smrg      <blockquote><para>
7133706f2543Smrg	  <programlisting>
7134706f2543Smrg    ModeStatus xf86InitialCheckModeForDriver(ScrnInfoPtr scrp,
7135706f2543Smrg                                DisplayModePtr mode, ClockRangePtr clockRanges,
7136706f2543Smrg                                LookupModeFlags strategy, int maxPitch,
7137706f2543Smrg                                int virtualX, int virtualY);
7138706f2543Smrg	  </programlisting>
7139706f2543Smrg	  <blockquote><para>
7140706f2543Smrg      This function checks the passed mode against some basic driver
7141706f2543Smrg      constraints.  Apart from the ones passed explicitly, the
7142706f2543Smrg      <structfield>maxHValue</structfield> and <structfield>maxVValue</structfield> fields of
7143706f2543Smrg      the <structname>ScrnInfoRec</structname> are also used.  If the
7144706f2543Smrg      <structfield>ValidMode</structfield> field of the <structname>ScrnInfoRec</structname>
7145706f2543Smrg      is set, that function is also called to check the mode.  Next, the
7146706f2543Smrg      mode is checked against the monitor's constraints.
7147706f2543Smrg	    </para>
7148706f2543Smrg
7149706f2543Smrg	    <para>
7150706f2543Smrg      If the mode is consistent with all constraints, the return value
7151706f2543Smrg      is <constant>MODE_OK</constant>.  Otherwise the return value indicates
7152706f2543Smrg      which constraint wasn't met.
7153706f2543Smrg	    </para>
7154706f2543Smrg
7155706f2543Smrg	  </blockquote></para></blockquote>
7156706f2543Smrg
7157706f2543Smrg      <blockquote><para>
7158706f2543Smrg	  <programlisting>
7159706f2543Smrg    void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode);
7160706f2543Smrg	  </programlisting>
7161706f2543Smrg	  <blockquote><para>
7162706f2543Smrg      This function deletes the <parameter>mode</parameter> given from the
7163706f2543Smrg      <parameter>modeList</parameter>.  It never prints any messages, so it is
7164706f2543Smrg      up to the caller to print a message if required.
7165706f2543Smrg	    </para>
7166706f2543Smrg
7167706f2543Smrg	  </blockquote></para></blockquote>
7168706f2543Smrg    </sect2>
7169706f2543Smrg
7170706f2543Smrg    <sect2>
7171706f2543Smrg      <title>Functions for handling strings and tokens</title>
7172706f2543Smrg
7173706f2543Smrg      <para>
7174706f2543Smrg    Tables associating strings and numerical tokens combined with the
7175706f2543Smrg    following functions provide a compact way of handling strings from
7176706f2543Smrg    the config file, and for converting tokens into printable strings.
7177706f2543Smrg    The table data structure is:
7178706f2543Smrg
7179706f2543Smrg	<programlisting>
7180706f2543Smrgtypedef struct {
7181706f2543Smrg    int                 token;
7182706f2543Smrg    const char *        name;
7183706f2543Smrg} SymTabRec, *SymTabPtr;
7184706f2543Smrg	</programlisting>
7185706f2543Smrg      </para>
7186706f2543Smrg
7187706f2543Smrg      <para>
7188706f2543Smrg    A table is an initialised array of <structname>SymTabRec</structname>.  The
7189706f2543Smrg    tokens must be non-negative integers.  Multiple names may be mapped
7190706f2543Smrg    to a single token.  The table is terminated with an element with a
7191706f2543Smrg    <structfield>token</structfield> value of <constant>-1</constant> and
7192706f2543Smrg    <constant>NULL</constant> for the <structfield>name</structfield>.
7193706f2543Smrg      </para>
7194706f2543Smrg
7195706f2543Smrg      <blockquote><para>
7196706f2543Smrg	  <programlisting>
7197706f2543Smrg    const char *xf86TokenToString(SymTabPtr table, int token);
7198706f2543Smrg	  </programlisting>
7199706f2543Smrg	  <blockquote><para>
7200706f2543Smrg      This function returns the first string in <parameter>table</parameter>
7201706f2543Smrg      that matches <parameter>token</parameter>.  If no match is found,
7202706f2543Smrg      <constant>NULL</constant> is returned (NOTE, older versions of this
7203706f2543Smrg      function would return the string "unknown" when no match is found).
7204706f2543Smrg	    </para>
7205706f2543Smrg
7206706f2543Smrg	  </blockquote></para></blockquote>
7207706f2543Smrg
7208706f2543Smrg      <blockquote><para>
7209706f2543Smrg	  <programlisting>
7210706f2543Smrg    int xf86StringToToken(SymTabPtr table, const char *string);
7211706f2543Smrg	  </programlisting>
7212706f2543Smrg	  <blockquote><para>
7213706f2543Smrg      This function returns the first token in <parameter>table</parameter>
7214706f2543Smrg      that matches <parameter>string</parameter>.  The
7215706f2543Smrg      <function>xf86NameCmp()</function> function is used to determine the
7216706f2543Smrg      match.  If no match is found, <constant>-1</constant> is returned.
7217706f2543Smrg	    </para>
7218706f2543Smrg
7219706f2543Smrg	  </blockquote></para></blockquote>
7220706f2543Smrg
7221706f2543Smrg    </sect2>
7222706f2543Smrg
7223706f2543Smrg    <sect2>
7224706f2543Smrg      <title>Functions for finding which config file entries to use</title>
7225706f2543Smrg
7226706f2543Smrg      <para>
7227706f2543Smrg    These functions can be used to select the appropriate config file
7228706f2543Smrg    entries that match the detected hardware.  They are described above
7229706f2543Smrg    in the <link linkend="probe">Probe</link> and
7230706f2543Smrg    <link linkend="avail">Available Functions</link> sections.
7231706f2543Smrg      </para>
7232706f2543Smrg
7233706f2543Smrg    </sect2>
7234706f2543Smrg
7235706f2543Smrg    <sect2>
7236706f2543Smrg      <title>Probing discrete clocks on old hardware</title>
7237706f2543Smrg
7238706f2543Smrg      <para>
7239706f2543Smrg    The <function>xf86GetClocks()</function> function may be used to assist
7240706f2543Smrg    in finding the discrete pixel clock values on older hardware.
7241706f2543Smrg      </para>
7242706f2543Smrg
7243706f2543Smrg      <blockquote><para>
7244706f2543Smrg	  <programlisting>
7245706f2543Smrg    void xf86GetClocks(ScrnInfoPtr pScrn, int num,
7246706f2543Smrg                       Bool (*ClockFunc)(ScrnInfoPtr, int),
7247706f2543Smrg                       void (*ProtectRegs)(ScrnInfoPtr, Bool),
7248706f2543Smrg                       void (*BlankScreen)(ScrnInfoPtr, Bool),
7249706f2543Smrg                       int vertsyncreg, int maskval, int knownclkindex,
7250706f2543Smrg                       int knownclkvalue);
7251706f2543Smrg	  </programlisting>
7252706f2543Smrg	  <blockquote><para>
7253706f2543Smrg      This function uses a comparative sampling method to measure the
7254706f2543Smrg      discrete pixel clock values.  The number of discrete clocks to
7255706f2543Smrg      measure is given by <parameter>num</parameter>.  <parameter>clockFunc</parameter>
7256706f2543Smrg      is a function that selects the <parameter>n</parameter>'th clock.  It
7257706f2543Smrg      should also save or restore any state affected by programming the
7258706f2543Smrg      clocks when the index passed is <constant>CLK_REG_SAVE</constant> or
7259706f2543Smrg      <constant>CLK_REG_RESTORE</constant>.  <parameter>ProtectRegs</parameter> is
7260706f2543Smrg      a function that does whatever is required to protect the hardware
7261706f2543Smrg      state while selecting a new clock.  <parameter>BlankScreen</parameter>
7262706f2543Smrg      is a function that blanks the screen.  <parameter>vertsyncreg</parameter>
7263706f2543Smrg      and <parameter>maskval</parameter> are the register and bitmask to
7264706f2543Smrg      check for the presence of vertical sync pulses.
7265706f2543Smrg      <parameter>knownclkindex</parameter> and <parameter>knownclkvalue</parameter>
7266706f2543Smrg      are the index and value of a known clock.  These are the known
7267706f2543Smrg      references on which the comparative measurements are based.  The
7268706f2543Smrg      number of clocks probed is set in <structfield>pScrn-&gt;numClocks</structfield>,
7269706f2543Smrg      and the probed clocks are set in the <structfield>pScrn-&gt;clock[]</structfield>
7270706f2543Smrg      array.  All of the clock values are in units of kHz.
7271706f2543Smrg	    </para>
7272706f2543Smrg
7273706f2543Smrg	  </blockquote></para></blockquote>
7274706f2543Smrg
7275706f2543Smrg      <blockquote><para>
7276706f2543Smrg	  <programlisting>
7277706f2543Smrg    void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from);
7278706f2543Smrg	  </programlisting>
7279706f2543Smrg	  <blockquote><para>
7280706f2543Smrg      Print out the pixel clocks <parameter>scrp-&gt;clock[]</parameter>.
7281706f2543Smrg      <parameter>from</parameter> indicates whether the clocks were probed
7282706f2543Smrg      or from the config file.
7283706f2543Smrg	    </para>
7284706f2543Smrg
7285706f2543Smrg	  </blockquote></para></blockquote>
7286706f2543Smrg    </sect2>
7287706f2543Smrg
7288706f2543Smrg    <sect2>
7289706f2543Smrg      <title>Other helper functions</title>
7290706f2543Smrg
7291706f2543Smrg      <blockquote><para>
7292706f2543Smrg	  <programlisting>
7293706f2543Smrg    Bool xf86IsUnblank(int mode);
7294706f2543Smrg	  </programlisting>
7295706f2543Smrg	  <blockquote><para>
7296706f2543Smrg      Returns <constant>TRUE</constant> when the screen saver mode specified
7297706f2543Smrg      by <parameter>mode</parameter> requires the screen be unblanked,
7298706f2543Smrg      and <constant>FALSE</constant> otherwise.  The screen saver modes that
7299706f2543Smrg      require blanking are <constant>SCREEN_SAVER_ON</constant> and
7300706f2543Smrg      <constant>SCREEN_SAVER_CYCLE</constant>, and the screen saver modes that
7301706f2543Smrg      require unblanking are <constant>SCREEN_SAVER_OFF</constant> and
7302706f2543Smrg      <constant>SCREEN_SAVER_FORCER</constant>.  Drivers may call this helper
7303706f2543Smrg      from their <function>SaveScreen()</function> function to interpret the
7304706f2543Smrg      screen saver modes.
7305706f2543Smrg	    </para>
7306706f2543Smrg
7307706f2543Smrg	  </blockquote></para></blockquote>
7308706f2543Smrg    </sect2>
7309706f2543Smrg  </sect1>
7310706f2543Smrg
7311706f2543Smrg  <sect1>
7312706f2543Smrg    <title>The vgahw module</title>
7313706f2543Smrg
7314706f2543Smrg    <para>
7315706f2543SmrgThe vgahw modules provides an interface for saving, restoring and
7316706f2543Smrgprogramming the standard VGA registers, and for handling VGA colourmaps.
7317706f2543Smrg    </para>
7318706f2543Smrg
7319706f2543Smrg    <sect2>
7320706f2543Smrg      <title>Data Structures</title>
7321706f2543Smrg
7322706f2543Smrg      <para>
7323706f2543Smrg    The public data structures used by the vgahw module are
7324706f2543Smrg    <structname>vgaRegRec</structname> and <structname>vgaHWRec</structname>.  They are
7325706f2543Smrg    defined in <filename>vgaHW.h.</filename>
7326706f2543Smrg      </para>
7327706f2543Smrg
7328706f2543Smrg    </sect2>
7329706f2543Smrg
7330706f2543Smrg    <sect2>
7331706f2543Smrg      <title>General vgahw Functions</title>
7332706f2543Smrg
7333706f2543Smrg      <blockquote><para>
7334706f2543Smrg	  <programlisting>
7335706f2543Smrg    Bool vgaHWGetHWRec(ScrnInfoPtr pScrn);
7336706f2543Smrg	  </programlisting>
7337706f2543Smrg	  <blockquote><para>
7338706f2543Smrg      This function allocates a <structname>vgaHWRec</structname> structure, and
7339706f2543Smrg      hooks it into the <structname>ScrnInfoRec</structname>'s
7340706f2543Smrg      <structfield>privates</structfield>.  Like all information hooked into the
7341706f2543Smrg      <structfield>privates</structfield>, it is persistent, and only needs to be
7342706f2543Smrg      allocated once per screen.  This function should normally be called
7343706f2543Smrg      from the driver's <function>ChipPreInit()</function> function.  The
7344706f2543Smrg      <structname>vgaHWRec</structname> is zero-allocated, and the following
7345706f2543Smrg      fields are explicitly initialised:
7346706f2543Smrg
7347706f2543Smrg	      <variablelist>
7348706f2543Smrg		<varlistentry>
7349706f2543Smrg		  <term><structfield>ModeReg.DAC[]</structfield></term>
7350706f2543Smrg		  <listitem><para>initialised with a default colourmap
7351706f2543Smrg		    </para></listitem></varlistentry>
7352706f2543Smrg		<varlistentry>
7353706f2543Smrg		  <term><structfield>ModeReg.Attribute[0x11]</structfield></term>
7354706f2543Smrg		  <listitem><para>initialised with the default overscan index
7355706f2543Smrg		    </para></listitem></varlistentry>
7356706f2543Smrg		<varlistentry>
7357706f2543Smrg		  <term><structfield>ShowOverscan</structfield></term>
7358706f2543Smrg		  <listitem><para>initialised according to the "ShowOverscan" option
7359706f2543Smrg		    </para></listitem></varlistentry>
7360706f2543Smrg		<varlistentry>
7361706f2543Smrg		  <term><structfield>paletteEnabled</structfield></term>
7362706f2543Smrg		  <listitem><para>initialised to FALSE
7363706f2543Smrg		    </para></listitem></varlistentry>
7364706f2543Smrg		<varlistentry>
7365706f2543Smrg		  <term><structfield>cmapSaved</structfield></term>
7366706f2543Smrg		  <listitem><para>initialised to FALSE
7367706f2543Smrg		    </para></listitem></varlistentry>
7368706f2543Smrg		<varlistentry>
7369706f2543Smrg		  <term><structfield>pScrn</structfield></term>
7370706f2543Smrg		  <listitem><para>initialised to pScrn
7371706f2543Smrg		    </para></listitem></varlistentry>
7372706f2543Smrg	      </variablelist>
7373706f2543Smrg	    </para>
7374706f2543Smrg
7375706f2543Smrg	    <para>
7376706f2543Smrg      In addition to the above, <function>vgaHWSetStdFuncs()</function> is
7377706f2543Smrg      called to initialise the register access function fields with the
7378706f2543Smrg      standard VGA set of functions.
7379706f2543Smrg	    </para>
7380706f2543Smrg
7381706f2543Smrg	    <para>
7382706f2543Smrg      Once allocated, a pointer to the <structname>vgaHWRec</structname> can be
7383706f2543Smrg      obtained from the <literal remap="tt">ScrnInfoPtr</literal> with the
7384706f2543Smrg      <literal remap="tt">VGAHWPTR(pScrn)</literal> macro.
7385706f2543Smrg	    </para>
7386706f2543Smrg
7387706f2543Smrg	  </blockquote></para></blockquote>
7388706f2543Smrg
7389706f2543Smrg      <blockquote><para>
7390706f2543Smrg	  <programlisting>
7391706f2543Smrg    void vgaHWFreeHWRec(ScrnInfoPtr pScrn);
7392706f2543Smrg	  </programlisting>
7393706f2543Smrg	  <blockquote><para>
7394706f2543Smrg      This function frees a <structname>vgaHWRec</structname> structure.  It
7395706f2543Smrg      should be called from a driver's <function>ChipFreeScreen()</function>
7396706f2543Smrg      function.
7397706f2543Smrg	    </para>
7398706f2543Smrg
7399706f2543Smrg	  </blockquote></para></blockquote>
7400706f2543Smrg
7401706f2543Smrg      <blockquote><para>
7402706f2543Smrg	  <programlisting>
7403706f2543Smrg    Bool vgaHWSetRegCounts(ScrnInfoPtr pScrn, int numCRTC,
7404706f2543Smrg                          int numSequencer, int numGraphics, int numAttribute);
7405706f2543Smrg	  </programlisting>
7406706f2543Smrg	  <blockquote><para>
7407706f2543Smrg      This function allows the number of CRTC, Sequencer, Graphics and
7408706f2543Smrg      Attribute registers to be changed.  This makes it possible for
7409706f2543Smrg      extended registers to be saved and restored with
7410706f2543Smrg      <function>vgaHWSave()</function> and <function>vgaHWRestore()</function>.
7411706f2543Smrg      This function should be called after a <structname>vgaHWRec</structname>
7412706f2543Smrg      has been allocated with <function>vgaHWGetHWRec()</function>.  The
7413706f2543Smrg      default values are defined in <filename>vgaHW.h</filename> as follows:
7414706f2543Smrg
7415706f2543Smrg	      <programlisting>
7416706f2543Smrg#define VGA_NUM_CRTC 25
7417706f2543Smrg#define VGA_NUM_SEQ   5
7418706f2543Smrg#define VGA_NUM_GFX   9
7419706f2543Smrg#define VGA_NUM_ATTR 21
7420706f2543Smrg	      </programlisting>
7421706f2543Smrg	    </para>
7422706f2543Smrg
7423706f2543Smrg	  </blockquote></para></blockquote>
7424706f2543Smrg
7425706f2543Smrg      <blockquote><para>
7426706f2543Smrg	  <programlisting>
7427706f2543Smrg    Bool vgaHWCopyReg(vgaRegPtr dst, vgaRegPtr src);
7428706f2543Smrg	  </programlisting>
7429706f2543Smrg	  <blockquote><para>
7430706f2543Smrg      This function copies the contents of the VGA saved registers in
7431706f2543Smrg      <parameter>src</parameter> to <parameter>dst</parameter>.  Note that it isn't
7432706f2543Smrg      possible to simply do this with <function>memcpy()</function> (or
7433706f2543Smrg      similar).  This function returns <constant>TRUE</constant> unless there
7434706f2543Smrg      is a problem allocating space for the <structfield>CRTC</structfield> and
7435706f2543Smrg      related fields in <parameter>dst</parameter>.
7436706f2543Smrg	    </para>
7437706f2543Smrg
7438706f2543Smrg	  </blockquote></para></blockquote>
7439706f2543Smrg
7440706f2543Smrg      <blockquote><para>
7441706f2543Smrg	  <programlisting>
7442706f2543Smrg    void vgaHWSetStdFuncs(vgaHWPtr hwp);
7443706f2543Smrg	  </programlisting>
7444706f2543Smrg	  <blockquote><para>
7445706f2543Smrg      This function initialises the register access function fields of
7446706f2543Smrg      <parameter>hwp</parameter> with the standard VGA set of functions.  This
7447706f2543Smrg      is called by <function>vgaHWGetHWRec()</function>, so there is usually
7448706f2543Smrg      no need to call this explicitly.  The register access functions
7449706f2543Smrg      are described below.  If the registers are shadowed in some other
7450706f2543Smrg      port I/O space (for example a PCI I/O region), these functions
7451706f2543Smrg      can be used to access the shadowed registers if
7452706f2543Smrg      <structfield>hwp-&gt;PIOOffset</structfield> is initialised with
7453706f2543Smrg      <literal remap="tt">offset</literal>, calculated in such a way that when the
7454706f2543Smrg      standard VGA I/O port value is added to it the correct offset into
7455706f2543Smrg      the PIO area results.  This value is initialised to zero in
7456706f2543Smrg      <function>vgaHWGetHWRec()</function>.  (Note: the PIOOffset functionality
7457706f2543Smrg      is present in XFree86 4.1.0 and later.)
7458706f2543Smrg	    </para>
7459706f2543Smrg
7460706f2543Smrg	  </blockquote></para></blockquote>
7461706f2543Smrg
7462706f2543Smrg      <blockquote><para>
7463706f2543Smrg	  <programlisting>
7464706f2543Smrg    void vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset);
7465706f2543Smrg	  </programlisting>
7466706f2543Smrg	  <blockquote><para>
7467706f2543Smrg      This function initialised the register access function fields of
7468706f2543Smrg      hwp with a generic MMIO set of functions.
7469706f2543Smrg      <structfield>hwp-&gt;MMIOBase</structfield> is initialised with
7470706f2543Smrg      <parameter>base</parameter>, which must be the virtual address that the
7471706f2543Smrg      start of MMIO area is mapped to.  <structfield>hwp-&gt;MMIOOffset</structfield>
7472706f2543Smrg      is initialised with <parameter>offset</parameter>, which must be calculated
7473706f2543Smrg      in such a way that when the standard VGA I/O port value is added
7474706f2543Smrg      to it the correct offset into the MMIO area results.  That means
7475706f2543Smrg      that these functions are only suitable when the VGA I/O ports are
7476706f2543Smrg      made available in a direct mapping to the MMIO space.  If that is
7477706f2543Smrg      not the case, the driver will need to provide its own register
7478706f2543Smrg      access functions.  The register access functions are described
7479706f2543Smrg      below.
7480706f2543Smrg	    </para>
7481706f2543Smrg
7482706f2543Smrg	  </blockquote></para></blockquote>
7483706f2543Smrg
7484706f2543Smrg      <blockquote><para>
7485706f2543Smrg	  <programlisting>
7486706f2543Smrg    Bool vgaHWMapMem(ScrnInfoPtr pScrn);
7487706f2543Smrg	  </programlisting>
7488706f2543Smrg	  <blockquote><para>
7489706f2543Smrg      This function maps the VGA memory window.  It requires that the
7490706f2543Smrg      <structname>vgaHWRec</structname> be allocated.  If a driver requires
7491706f2543Smrg      non-default <structfield>MapPhys</structfield> or <structfield>MapSize</structfield>
7492706f2543Smrg      settings (the physical location and size of the VGA memory window)
7493706f2543Smrg      then those fields of the <structname>vgaHWRec</structname> must be initialised
7494706f2543Smrg      before calling this function.  Otherwise, this function initialiases
7495706f2543Smrg      the default values of <constant>0xA0000</constant> for
7496706f2543Smrg      <structfield>MapPhys</structfield> and <code>(64&nbsp;*&nbsp;1024)</code> for
7497706f2543Smrg      <structfield>MapSize</structfield>.  This function must be called before
7498706f2543Smrg      attempting to save or restore the VGA state.  If the driver doesn't
7499706f2543Smrg      call it explicitly, the <function>vgaHWSave()</function> and
7500706f2543Smrg      <function>vgaHWRestore()</function> functions may call it if they need
7501706f2543Smrg      to access the VGA memory (in which case they will also call
7502706f2543Smrg      <function>vgaHWUnmapMem()</function> to unmap the VGA memory before
7503706f2543Smrg      exiting).
7504706f2543Smrg	    </para>
7505706f2543Smrg
7506706f2543Smrg	  </blockquote></para></blockquote>
7507706f2543Smrg
7508706f2543Smrg      <blockquote><para>
7509706f2543Smrg	  <programlisting>
7510706f2543Smrg    void vgaHWUnmapMem(ScrnInfoPtr pScrn);
7511706f2543Smrg	  </programlisting>
7512706f2543Smrg	  <blockquote><para>
7513706f2543Smrg      This function unmaps the VGA memory window.  It must only be called
7514706f2543Smrg      after the memory has been mapped.  The <structfield>Base</structfield> field
7515706f2543Smrg      of the <structname>vgaHWRec</structname> field is set to <constant>NULL</constant>
7516706f2543Smrg      to indicate that the memory is no longer mapped.
7517706f2543Smrg	    </para>
7518706f2543Smrg
7519706f2543Smrg	  </blockquote></para></blockquote>
7520706f2543Smrg
7521706f2543Smrg      <blockquote><para>
7522706f2543Smrg	  <programlisting>
7523706f2543Smrg    void vgaHWGetIOBase(vgaHWPtr hwp);
7524706f2543Smrg	  </programlisting>
7525706f2543Smrg	  <blockquote><para>
7526706f2543Smrg      This function initialises the <structfield>IOBase</structfield> field of the
7527706f2543Smrg      <structname>vgaHWRec</structname>.  This function must be called before
7528706f2543Smrg      using any other functions that access the video hardware.
7529706f2543Smrg	    </para>
7530706f2543Smrg
7531706f2543Smrg	    <para>
7532706f2543Smrg      A macro <function>VGAHW_GET_IOBASE()</function> is also available in
7533706f2543Smrg      <filename>vgaHW.h</filename> that returns the I/O base, and this may
7534706f2543Smrg      be used when the vgahw module is not loaded (for example, in the
7535706f2543Smrg      <function>ChipProbe()</function> function).
7536706f2543Smrg	    </para>
7537706f2543Smrg
7538706f2543Smrg	  </blockquote></para></blockquote>
7539706f2543Smrg
7540706f2543Smrg      <blockquote><para>
7541706f2543Smrg	  <programlisting>
7542706f2543Smrg    void vgaHWUnlock(vgaHWPtr hwp);
7543706f2543Smrg	  </programlisting>
7544706f2543Smrg	  <blockquote><para>
7545706f2543Smrg      This function unlocks the VGA <literal remap="tt">CRTC[0-7]</literal> registers,
7546706f2543Smrg      and must be called before attempting to write to those registers.
7547706f2543Smrg	    </para>
7548706f2543Smrg
7549706f2543Smrg	  </blockquote></para></blockquote>
7550706f2543Smrg
7551706f2543Smrg      <blockquote><para>
7552706f2543Smrg	  <programlisting>
7553706f2543Smrg    void vgaHWLock(vgaHWPtr hwp);
7554706f2543Smrg	  </programlisting>
7555706f2543Smrg	  <blockquote><para>
7556706f2543Smrg      This function locks the VGA <literal remap="tt">CRTC[0-7]</literal> registers.
7557706f2543Smrg	    </para>
7558706f2543Smrg
7559706f2543Smrg	  </blockquote></para></blockquote>
7560706f2543Smrg
7561706f2543Smrg      <blockquote><para>
7562706f2543Smrg	  <programlisting>
7563706f2543Smrg    void vgaHWEnable(vgaHWPtr hwp);
7564706f2543Smrg	  </programlisting>
7565706f2543Smrg	  <blockquote><para>
7566706f2543Smrg      This function enables the VGA subsystem.  (Note, this function is
7567706f2543Smrg      present in XFree86 4.1.0 and later.).
7568706f2543Smrg	    </para>
7569706f2543Smrg
7570706f2543Smrg	  </blockquote></para></blockquote>
7571706f2543Smrg
7572706f2543Smrg      <blockquote><para>
7573706f2543Smrg	  <programlisting>
7574706f2543Smrg    void vgaHWDisable(vgaHWPtr hwp);
7575706f2543Smrg	  </programlisting>
7576706f2543Smrg	  <blockquote><para>
7577706f2543Smrg      This function disables the VGA subsystem.  (Note, this function is
7578706f2543Smrg      present in XFree86 4.1.0 and later.).
7579706f2543Smrg	    </para>
7580706f2543Smrg
7581706f2543Smrg	  </blockquote></para></blockquote>
7582706f2543Smrg
7583706f2543Smrg      <blockquote><para>
7584706f2543Smrg	  <programlisting>
7585706f2543Smrg    void vgaHWSave(ScrnInfoPtr pScrn, vgaRegPtr save, int flags);
7586706f2543Smrg	  </programlisting>
7587706f2543Smrg	  <blockquote><para>
7588706f2543Smrg      This function saves the VGA state.  The state is written to the
7589706f2543Smrg      <structname>vgaRegRec</structname> pointed to by <parameter>save</parameter>.
7590706f2543Smrg      <parameter>flags</parameter> is set to one or more of the following flags
7591706f2543Smrg      ORed together:
7592706f2543Smrg
7593706f2543Smrg	      <variablelist>
7594706f2543Smrg		<varlistentry>
7595706f2543Smrg		  <term><constant>VGA_SR_MODE</constant></term>
7596706f2543Smrg		  <listitem><para>the mode setting registers are saved
7597706f2543Smrg		    </para></listitem></varlistentry>
7598706f2543Smrg		<varlistentry>
7599706f2543Smrg		  <term><constant>VGA_SR_FONTS</constant></term>
7600706f2543Smrg		  <listitem><para>the text mode font/text data is saved
7601706f2543Smrg		    </para></listitem></varlistentry>
7602706f2543Smrg		<varlistentry>
7603706f2543Smrg		  <term><constant>VGA_SR_CMAP</constant></term>
7604706f2543Smrg		  <listitem><para>the colourmap (LUT) is saved
7605706f2543Smrg		    </para></listitem></varlistentry>
7606706f2543Smrg		<varlistentry>
7607706f2543Smrg		  <term><constant>VGA_SR_ALL</constant></term>
7608706f2543Smrg		  <listitem><para>all of the above are saved
7609706f2543Smrg		    </para></listitem></varlistentry>
7610706f2543Smrg	      </variablelist>
7611706f2543Smrg	    </para>
7612706f2543Smrg
7613706f2543Smrg	    <para>
7614706f2543Smrg      The <structname>vgaHWRec</structname> and its <structfield>IOBase</structfield> fields
7615706f2543Smrg      must be initialised before this function is called.  If
7616706f2543Smrg      <constant>VGA_SR_FONTS</constant> is set in <parameter>flags</parameter>, the
7617706f2543Smrg      VGA memory window must be mapped.  If it isn't then
7618706f2543Smrg      <function>vgaHWMapMem()</function> will be called to map it, and
7619706f2543Smrg      <function>vgaHWUnmapMem()</function> will be called to unmap it
7620706f2543Smrg      afterwards.  <function>vgaHWSave()</function> uses the three functions
7621706f2543Smrg      below in the order <function>vgaHWSaveColormap()</function>,
7622706f2543Smrg      <function>vgaHWSaveMode()</function>, <function>vgaHWSaveFonts()</function> to
7623706f2543Smrg      carry out the different save phases.  It is undecided at this
7624706f2543Smrg      stage whether they will remain part of the vgahw module's public
7625706f2543Smrg      interface or not.
7626706f2543Smrg	    </para>
7627706f2543Smrg
7628706f2543Smrg	  </blockquote></para></blockquote>
7629706f2543Smrg
7630706f2543Smrg      <blockquote><para>
7631706f2543Smrg	  <programlisting>
7632706f2543Smrg    void vgaHWSaveMode(ScrnInfoPtr pScrn, vgaRegPtr save);
7633706f2543Smrg	  </programlisting>
7634706f2543Smrg	  <blockquote><para>
7635706f2543Smrg      This function saves the VGA mode registers.  They are saved to
7636706f2543Smrg      the <structname>vgaRegRec</structname> pointed to by <parameter>save</parameter>.
7637706f2543Smrg      The registers saved are:
7638706f2543Smrg
7639706f2543Smrg	      <literallayout>
7640706f2543Smrg        MiscOut
7641706f2543Smrg        CRTC[0-0x18]
7642706f2543Smrg        Attribute[0-0x14]
7643706f2543Smrg        Graphics[0-8]
7644706f2543Smrg        Sequencer[0-4]
7645706f2543Smrg	      </literallayout>
7646706f2543Smrg	    </para>
7647706f2543Smrg
7648706f2543Smrg	    <para>
7649706f2543Smrg    The number of registers actually saved may be modified by a prior call
7650706f2543Smrg    to <function>vgaHWSetRegCounts()</function>.
7651706f2543Smrg	    </para>
7652706f2543Smrg
7653706f2543Smrg	  </blockquote></para></blockquote>
7654706f2543Smrg
7655706f2543Smrg      <blockquote><para>
7656706f2543Smrg	  <programlisting>
7657706f2543Smrg    void vgaHWSaveFonts(ScrnInfoPtr pScrn, vgaRegPtr save);
7658706f2543Smrg	  </programlisting>
7659706f2543Smrg	  <blockquote><para>
7660706f2543Smrg      This function saves the text mode font and text data held in the
7661706f2543Smrg      video memory.  If called while in a graphics mode, no save is
7662706f2543Smrg      done.  The VGA memory window must be mapped with
7663706f2543Smrg      <function>vgaHWMapMem()</function> before to calling this function.
7664706f2543Smrg	    </para>
7665706f2543Smrg
7666706f2543Smrg	    <para>
7667706f2543Smrg      On some platforms, one or more of the font/text plane saves may be
7668706f2543Smrg      no-ops.  This is the case when the platform's VC driver already
7669706f2543Smrg      takes care of this.
7670706f2543Smrg	    </para>
7671706f2543Smrg
7672706f2543Smrg	  </blockquote></para></blockquote>
7673706f2543Smrg
7674706f2543Smrg      <blockquote><para>
7675706f2543Smrg	  <programlisting>
7676706f2543Smrg    void vgaHWSaveColormap(ScrnInfoPtr pScrn, vgaRegPtr save);
7677706f2543Smrg	  </programlisting>
7678706f2543Smrg	  <blockquote><para>
7679706f2543Smrg      This function saves the VGA colourmap (LUT).  Before saving it, it
7680706f2543Smrg      attempts to verify that the colourmap is readable.  In rare cases
7681706f2543Smrg      where it isn't readable, a default colourmap is saved instead.
7682706f2543Smrg	    </para>
7683706f2543Smrg
7684706f2543Smrg	  </blockquote></para></blockquote>
7685706f2543Smrg
7686706f2543Smrg      <blockquote><para>
7687706f2543Smrg	  <programlisting>
7688706f2543Smrg    void vgaHWRestore(ScrnInfoPtr pScrn, vgaRegPtr restore, int flags);
7689706f2543Smrg	  </programlisting>
7690706f2543Smrg	  <blockquote><para>
7691706f2543Smrg      This function programs the VGA state.  The state programmed is
7692706f2543Smrg      that contained in the <structname>vgaRegRec</structname> pointed to by
7693706f2543Smrg      <parameter>restore</parameter>.  <parameter>flags</parameter> is the same
7694706f2543Smrg      as described above for the <function>vgaHWSave()</function> function.
7695706f2543Smrg	    </para>
7696706f2543Smrg
7697706f2543Smrg	    <para>
7698706f2543Smrg      The <structname>vgaHWRec</structname> and its <structfield>IOBase</structfield> fields
7699706f2543Smrg      must be initialised before this function is called.  If
7700706f2543Smrg      <constant>VGA_SR_FONTS</constant> is set in <parameter>flags</parameter>, the
7701706f2543Smrg      VGA memory window must be mapped.  If it isn't then
7702706f2543Smrg      <function>vgaHWMapMem()</function> will be called to map it, and
7703706f2543Smrg      <function>vgaHWUnmapMem()</function> will be called to unmap it
7704706f2543Smrg      afterwards.  <function>vgaHWRestore()</function> uses the three functions
7705706f2543Smrg      below in the order <function>vgaHWRestoreFonts()</function>,
7706706f2543Smrg      <function>vgaHWRestoreMode()</function>,
7707706f2543Smrg      <function>vgaHWRestoreColormap()</function> to carry out the different
7708706f2543Smrg      restore phases.  It is undecided at this stage whether they will
7709706f2543Smrg      remain part of the vgahw module's public interface or not.
7710706f2543Smrg	    </para>
7711706f2543Smrg
7712706f2543Smrg	  </blockquote></para></blockquote>
7713706f2543Smrg
7714706f2543Smrg      <blockquote><para>
7715706f2543Smrg	  <programlisting>
7716706f2543Smrg    void vgaHWRestoreMode(ScrnInfoPtr pScrn, vgaRegPtr restore);
7717706f2543Smrg	  </programlisting>
7718706f2543Smrg	  <blockquote><para>
7719706f2543Smrg      This function restores the VGA mode registers.  They are restored
7720706f2543Smrg      from the data in the <structname>vgaRegRec</structname> pointed to by
7721706f2543Smrg      <parameter>restore</parameter>.  The registers restored are:
7722706f2543Smrg
7723706f2543Smrg	      <literallayout>
7724706f2543Smrg        MiscOut
7725706f2543Smrg        CRTC[0-0x18]
7726706f2543Smrg        Attribute[0-0x14]
7727706f2543Smrg        Graphics[0-8]
7728706f2543Smrg        Sequencer[0-4]
7729706f2543Smrg	      </literallayout>
7730706f2543Smrg	    </para>
7731706f2543Smrg
7732706f2543Smrg	    <para>
7733706f2543Smrg    The number of registers actually restored may be modified by a prior call
7734706f2543Smrg    to <function>vgaHWSetRegCounts()</function>.
7735706f2543Smrg	    </para>
7736706f2543Smrg
7737706f2543Smrg	  </blockquote></para></blockquote>
7738706f2543Smrg
7739706f2543Smrg      <blockquote><para>
7740706f2543Smrg	  <programlisting>
7741706f2543Smrg    void vgaHWRestoreFonts(ScrnInfoPtr pScrn, vgaRegPtr restore);
7742706f2543Smrg	  </programlisting>
7743706f2543Smrg	  <blockquote><para>
7744706f2543Smrg      This function restores the text mode font and text data to the
7745706f2543Smrg      video memory.  The VGA memory window must be mapped with
7746706f2543Smrg      <function>vgaHWMapMem()</function> before to calling this function.
7747706f2543Smrg	    </para>
7748706f2543Smrg
7749706f2543Smrg	    <para>
7750706f2543Smrg      On some platforms, one or more of the font/text plane restores
7751706f2543Smrg      may be no-ops.  This is the case when the platform's VC driver
7752706f2543Smrg      already takes care of this.
7753706f2543Smrg	    </para>
7754706f2543Smrg
7755706f2543Smrg	  </blockquote></para></blockquote>
7756706f2543Smrg
7757706f2543Smrg      <blockquote><para>
7758706f2543Smrg	  <programlisting>
7759706f2543Smrg    void vgaHWRestoreColormap(ScrnInfoPtr pScrn, vgaRegPtr restore);
7760706f2543Smrg	  </programlisting>
7761706f2543Smrg	  <blockquote><para>
7762706f2543Smrg      This function restores the VGA colourmap (LUT).
7763706f2543Smrg	    </para>
7764706f2543Smrg
7765706f2543Smrg	  </blockquote></para></blockquote>
7766706f2543Smrg
7767706f2543Smrg      <blockquote><para>
7768706f2543Smrg	  <programlisting>
7769706f2543Smrg    void vgaHWInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
7770706f2543Smrg	  </programlisting>
7771706f2543Smrg	  <blockquote><para>
7772706f2543Smrg      This function fills in the <structname>vgaHWRec</structname>'s
7773706f2543Smrg      <structfield>ModeReg</structfield> field with the values appropriate for
7774706f2543Smrg      programming the given video mode.  It requires that the
7775706f2543Smrg      <structname>ScrnInfoRec</structname>'s <structfield>depth</structfield> field is
7776706f2543Smrg      initialised, which determines how the registers are programmed.
7777706f2543Smrg	    </para>
7778706f2543Smrg
7779706f2543Smrg	  </blockquote></para></blockquote>
7780706f2543Smrg
7781706f2543Smrg      <blockquote><para>
7782706f2543Smrg	  <programlisting>
7783706f2543Smrg    void vgaHWSeqReset(vgaHWPtr hwp, Bool start);
7784706f2543Smrg	  </programlisting>
7785706f2543Smrg	  <blockquote><para>
7786706f2543Smrg      Do a VGA sequencer reset.  If start is <constant>TRUE</constant>, the
7787706f2543Smrg      reset is started.  If start is <constant>FALSE</constant>, the reset
7788706f2543Smrg      is ended.
7789706f2543Smrg	    </para>
7790706f2543Smrg
7791706f2543Smrg	  </blockquote></para></blockquote>
7792706f2543Smrg
7793706f2543Smrg      <blockquote><para>
7794706f2543Smrg	  <programlisting>
7795706f2543Smrg    void vgaHWProtect(ScrnInfoPtr pScrn, Bool on);
7796706f2543Smrg	  </programlisting>
7797706f2543Smrg	  <blockquote><para>
7798706f2543Smrg      This function protects VGA registers and memory from corruption
7799706f2543Smrg      during loads.  It is typically called with on set to
7800706f2543Smrg      <constant>TRUE</constant> before programming, and with on set to
7801706f2543Smrg      <constant>FALSE</constant> after programming.
7802706f2543Smrg	    </para>
7803706f2543Smrg
7804706f2543Smrg	  </blockquote></para></blockquote>
7805706f2543Smrg
7806706f2543Smrg      <blockquote><para>
7807706f2543Smrg	  <programlisting>
7808706f2543Smrg    Bool vgaHWSaveScreen(ScreenPtr pScreen, int mode);
7809706f2543Smrg	  </programlisting>
7810706f2543Smrg	  <blockquote><para>
7811706f2543Smrg      This function blanks and unblanks the screen.  It is blanked when
7812706f2543Smrg      <parameter>mode</parameter> is <constant>SCREEN_SAVER_ON</constant> or
7813706f2543Smrg      <constant>SCREEN_SAVER_CYCLE</constant>, and unblanked when
7814706f2543Smrg      <parameter>mode</parameter> is <constant>SCREEN_SAVER_OFF</constant> or
7815706f2543Smrg      <constant>SCREEN_SAVER_FORCER</constant>.
7816706f2543Smrg	    </para>
7817706f2543Smrg
7818706f2543Smrg	  </blockquote></para></blockquote>
7819706f2543Smrg
7820706f2543Smrg      <blockquote><para>
7821706f2543Smrg	  <programlisting>
7822706f2543Smrg    void vgaHWBlankScreen(ScrnInfoPtr pScrn, Bool on);
7823706f2543Smrg	  </programlisting>
7824706f2543Smrg	  <blockquote><para>
7825706f2543Smrg      This function blanks and unblanks the screen.  It is blanked when
7826706f2543Smrg      <parameter>on</parameter> is <constant>FALSE</constant>, and unblanked when
7827706f2543Smrg      <parameter>on</parameter> is <constant>TRUE</constant>.  This function is
7828706f2543Smrg      provided for use in cases where the <structname>ScrnInfoRec</structname>
7829706f2543Smrg      can't be derived from the <structname>ScreenRec</structname> (while probing
7830706f2543Smrg      for clocks, for example).
7831706f2543Smrg	    </para>
7832706f2543Smrg
7833706f2543Smrg	  </blockquote></para></blockquote>
7834706f2543Smrg
7835706f2543Smrg    </sect2>
7836706f2543Smrg
7837706f2543Smrg    <sect2>
7838706f2543Smrg      <title>VGA Colormap Functions</title>
7839706f2543Smrg
7840706f2543Smrg      <para>
7841706f2543Smrg    The vgahw module uses the standard colormap support (see the
7842706f2543Smrg    <link linkend="cmap">Colormap Handling</link> section.  This is initialised
7843706f2543Smrg    with the following function:
7844706f2543Smrg
7845706f2543Smrg	<blockquote><para>
7846706f2543Smrg	  <programlisting>
7847706f2543Smrg    Bool vgaHWHandleColormaps(ScreenPtr pScreen);
7848706f2543Smrg	    </programlisting>
7849706f2543Smrg	  </para></blockquote>
7850706f2543Smrg      </para>
7851706f2543Smrg
7852706f2543Smrg    </sect2>
7853706f2543Smrg
7854706f2543Smrg    <sect2>
7855706f2543Smrg      <title>VGA Register Access Functions</title>
7856706f2543Smrg
7857706f2543Smrg      <para>
7858706f2543Smrg    The vgahw module abstracts access to the standard VGA registers by
7859706f2543Smrg    using a set of functions held in the <structname>vgaHWRec</structname>.  When
7860706f2543Smrg    the <structname>vgaHWRec</structname> is created these function pointers are
7861706f2543Smrg    initialised with the set of standard VGA I/O register access functions.
7862706f2543Smrg    In addition to these, the vgahw module includes a basic set of MMIO
7863706f2543Smrg    register access functions, and the <structname>vgaHWRec</structname> function
7864706f2543Smrg    pointers can be initialised to these by calling the
7865706f2543Smrg    <function>vgaHWSetMmioFuncs()</function> function described above.  Some
7866706f2543Smrg    drivers/platforms may require a different set of functions for VGA
7867706f2543Smrg    access.  The access functions are described here.
7868706f2543Smrg      </para>
7869706f2543Smrg
7870706f2543Smrg
7871706f2543Smrg      <blockquote><para>
7872706f2543Smrg	  <programlisting>
7873706f2543Smrg    void writeCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value);
7874706f2543Smrg	  </programlisting>
7875706f2543Smrg	  <blockquote><para>
7876706f2543Smrg      Write <parameter>value</parameter> to CRTC register <parameter>index</parameter>.
7877706f2543Smrg	    </para>
7878706f2543Smrg
7879706f2543Smrg	  </blockquote></para></blockquote>
7880706f2543Smrg
7881706f2543Smrg      <blockquote><para>
7882706f2543Smrg	  <programlisting>
7883706f2543Smrg    CARD8 readCrtc(vgaHWPtr hwp, CARD8 index);
7884706f2543Smrg	  </programlisting>
7885706f2543Smrg	  <blockquote><para>
7886706f2543Smrg      Return the value read from CRTC register <parameter>index</parameter>.
7887706f2543Smrg	    </para>
7888706f2543Smrg
7889706f2543Smrg	  </blockquote></para></blockquote>
7890706f2543Smrg
7891706f2543Smrg      <blockquote><para>
7892706f2543Smrg	  <programlisting>
7893706f2543Smrg    void writeGr(vgaHWPtr hwp, CARD8 index, CARD8 value);
7894706f2543Smrg	  </programlisting>
7895706f2543Smrg	  <blockquote><para>
7896706f2543Smrg      Write <parameter>value</parameter> to Graphics Controller register
7897706f2543Smrg      <parameter>index</parameter>.
7898706f2543Smrg	    </para>
7899706f2543Smrg
7900706f2543Smrg	  </blockquote></para></blockquote>
7901706f2543Smrg
7902706f2543Smrg      <blockquote><para>
7903706f2543Smrg	  <programlisting>
7904706f2543Smrg    CARD8 readGR(vgaHWPtr hwp, CARD8 index);
7905706f2543Smrg	  </programlisting>
7906706f2543Smrg	  <blockquote><para>
7907706f2543Smrg      Return the value read from Graphics Controller register
7908706f2543Smrg      <parameter>index</parameter>.
7909706f2543Smrg	    </para>
7910706f2543Smrg
7911706f2543Smrg	  </blockquote></para></blockquote>
7912706f2543Smrg
7913706f2543Smrg      <blockquote><para>
7914706f2543Smrg	  <programlisting>
7915706f2543Smrg    void writeSeq(vgaHWPtr hwp, CARD8 index, CARD8, value);
7916706f2543Smrg	  </programlisting>
7917706f2543Smrg	  <blockquote><para>
7918706f2543Smrg      Write <parameter>value</parameter> to Sequencer register
7919706f2543Smrg      <parameter>index</parameter>.
7920706f2543Smrg	    </para>
7921706f2543Smrg
7922706f2543Smrg	  </blockquote></para></blockquote>
7923706f2543Smrg
7924706f2543Smrg      <blockquote><para>
7925706f2543Smrg	  <programlisting>
7926706f2543Smrg    CARD8 readSeq(vgaHWPtr hwp, CARD8 index);
7927706f2543Smrg	  </programlisting>
7928706f2543Smrg	  <blockquote><para>
7929706f2543Smrg      Return the value read from Sequencer register <parameter>index</parameter>.
7930706f2543Smrg	    </para>
7931706f2543Smrg
7932706f2543Smrg	  </blockquote></para></blockquote>
7933706f2543Smrg
7934706f2543Smrg      <blockquote><para>
7935706f2543Smrg	  <programlisting>
7936706f2543Smrg    void writeAttr(vgaHWPtr hwp, CARD8 index, CARD8, value);
7937706f2543Smrg	  </programlisting>
7938706f2543Smrg	  <blockquote><para>
7939706f2543Smrg      Write <parameter>value</parameter> to Attribute Controller register
7940706f2543Smrg      <parameter>index</parameter>.  When writing out the index value this
7941706f2543Smrg      function should set bit 5 (<constant>0x20</constant>) according to the
7942706f2543Smrg      setting of <structfield>hwp-&gt;paletteEnabled</structfield> in order to
7943706f2543Smrg      preserve the palette access state.  It should be cleared when
7944706f2543Smrg      <structfield>hwp-&gt;paletteEnabled</structfield> is <constant>TRUE</constant>
7945706f2543Smrg      and set when it is <constant>FALSE</constant>.
7946706f2543Smrg	    </para>
7947706f2543Smrg
7948706f2543Smrg	  </blockquote></para></blockquote>
7949706f2543Smrg
7950706f2543Smrg      <blockquote><para>
7951706f2543Smrg	  <programlisting>
7952706f2543Smrg    CARD8 readAttr(vgaHWPtr hwp, CARD8 index);
7953706f2543Smrg	  </programlisting>
7954706f2543Smrg	  <blockquote><para>
7955706f2543Smrg      Return the value read from Attribute Controller register
7956706f2543Smrg      <parameter>index</parameter>.  When writing out the index value this
7957706f2543Smrg      function should set bit 5 (<constant>0x20</constant>) according to the
7958706f2543Smrg      setting of <structfield>hwp-&gt;paletteEnabled</structfield> in order to
7959706f2543Smrg      preserve the palette access state.  It should be cleared when
7960706f2543Smrg      <structfield>hwp-&gt;paletteEnabled</structfield> is <constant>TRUE</constant>
7961706f2543Smrg      and set when it is <constant>FALSE</constant>.
7962706f2543Smrg	    </para>
7963706f2543Smrg
7964706f2543Smrg	  </blockquote></para></blockquote>
7965706f2543Smrg
7966706f2543Smrg      <blockquote><para>
7967706f2543Smrg	  <programlisting>
7968706f2543Smrg    void writeMiscOut(vgaHWPtr hwp, CARD8 value);
7969706f2543Smrg	  </programlisting>
7970706f2543Smrg	  <blockquote><para>
7971706f2543Smrg      Write <quote><parameter>value</parameter></quote> to the Miscellaneous Output register.
7972706f2543Smrg	    </para>
7973706f2543Smrg
7974706f2543Smrg	  </blockquote></para></blockquote>
7975706f2543Smrg
7976706f2543Smrg      <blockquote><para>
7977706f2543Smrg	  <programlisting>
7978706f2543Smrg    CARD8 readMiscOut(vgwHWPtr hwp);
7979706f2543Smrg	  </programlisting>
7980706f2543Smrg	  <blockquote><para>
7981706f2543Smrg      Return the value read from the Miscellaneous Output register.
7982706f2543Smrg	    </para>
7983706f2543Smrg
7984706f2543Smrg	  </blockquote></para></blockquote>
7985706f2543Smrg
7986706f2543Smrg      <blockquote><para>
7987706f2543Smrg	  <programlisting>
7988706f2543Smrg    void enablePalette(vgaHWPtr hwp);
7989706f2543Smrg	  </programlisting>
7990706f2543Smrg	  <blockquote><para>
7991706f2543Smrg      Clear the palette address source bit in the Attribute Controller
7992706f2543Smrg      index register and set <literal remap="tt">hwp-&gt;paletteEnabled</literal> to
7993706f2543Smrg      <constant>TRUE</constant>.
7994706f2543Smrg	    </para>
7995706f2543Smrg
7996706f2543Smrg	  </blockquote></para></blockquote>
7997706f2543Smrg
7998706f2543Smrg      <blockquote><para>
7999706f2543Smrg	  <programlisting>
8000706f2543Smrg    void disablePalette(vgaHWPtr hwp);
8001706f2543Smrg	  </programlisting>
8002706f2543Smrg	  <blockquote><para>
8003706f2543Smrg      Set the palette address source bit in the Attribute Controller
8004706f2543Smrg      index register and set <literal remap="tt">hwp-&gt;paletteEnabled</literal> to
8005706f2543Smrg      <constant>FALSE</constant>.
8006706f2543Smrg	    </para>
8007706f2543Smrg
8008706f2543Smrg	  </blockquote></para></blockquote>
8009706f2543Smrg
8010706f2543Smrg      <blockquote><para>
8011706f2543Smrg	  <programlisting>
8012706f2543Smrg    void writeDacMask(vgaHWPtr hwp, CARD8 value);
8013706f2543Smrg	  </programlisting>
8014706f2543Smrg	  <blockquote><para>
8015706f2543Smrg      Write <parameter>value</parameter> to the DAC Mask register.
8016706f2543Smrg	    </para>
8017706f2543Smrg
8018706f2543Smrg	  </blockquote></para></blockquote>
8019706f2543Smrg
8020706f2543Smrg      <blockquote><para>
8021706f2543Smrg	  <programlisting>
8022706f2543Smrg    CARD8 readDacMask(vgaHWptr hwp);
8023706f2543Smrg	  </programlisting>
8024706f2543Smrg	  <blockquote><para>
8025706f2543Smrg      Return the value read from the DAC Mask register.
8026706f2543Smrg	    </para>
8027706f2543Smrg
8028706f2543Smrg	  </blockquote></para></blockquote>
8029706f2543Smrg
8030706f2543Smrg      <blockquote><para>
8031706f2543Smrg	  <programlisting>
8032706f2543Smrg    void writeDacReadAddress(vgaHWPtr hwp, CARD8 value);
8033706f2543Smrg	  </programlisting>
8034706f2543Smrg	  <blockquote><para>
8035706f2543Smrg      Write <parameter>value</parameter> to the DAC Read Address register.
8036706f2543Smrg	    </para>
8037706f2543Smrg
8038706f2543Smrg	  </blockquote></para></blockquote>
8039706f2543Smrg
8040706f2543Smrg      <blockquote><para>
8041706f2543Smrg	  <programlisting>
8042706f2543Smrg    void writeDacWriteAddress(vgaHWPtr hwp, CARD8 value);
8043706f2543Smrg	  </programlisting>
8044706f2543Smrg	  <blockquote><para>
8045706f2543Smrg      Write <parameter>value</parameter> to the DAC Write Address register.
8046706f2543Smrg	    </para>
8047706f2543Smrg
8048706f2543Smrg	  </blockquote></para></blockquote>
8049706f2543Smrg
8050706f2543Smrg      <blockquote><para>
8051706f2543Smrg	  <programlisting>
8052706f2543Smrg    void writeDacData(vgaHWPtr hwp, CARD8 value);
8053706f2543Smrg	  </programlisting>
8054706f2543Smrg	  <blockquote><para>
8055706f2543Smrg      Write <parameter>value</parameter> to the DAC Data register.
8056706f2543Smrg	    </para>
8057706f2543Smrg
8058706f2543Smrg	  </blockquote></para></blockquote>
8059706f2543Smrg
8060706f2543Smrg      <blockquote><para>
8061706f2543Smrg	  <programlisting>
8062706f2543Smrg    CARD8 readDacData(vgaHWptr hwp);
8063706f2543Smrg	  </programlisting>
8064706f2543Smrg	  <blockquote><para>
8065706f2543Smrg      Return the value read from the DAC Data register.
8066706f2543Smrg	    </para>
8067706f2543Smrg
8068706f2543Smrg	  </blockquote></para></blockquote>
8069706f2543Smrg
8070706f2543Smrg      <blockquote><para>
8071706f2543Smrg	  <programlisting>
8072706f2543Smrg    CARD8 readEnable(vgaHWptr hwp);
8073706f2543Smrg	  </programlisting>
8074706f2543Smrg	  <blockquote><para>
8075706f2543Smrg      Return the value read from the VGA Enable register.  (Note: This
8076706f2543Smrg      function is present in XFree86 4.1.0 and later.)
8077706f2543Smrg	    </para>
8078706f2543Smrg
8079706f2543Smrg	  </blockquote></para></blockquote>
8080706f2543Smrg
8081706f2543Smrg      <blockquote><para>
8082706f2543Smrg	  <programlisting>
8083706f2543Smrg    void writeEnable(vgaHWPtr hwp, CARD8 value);
8084706f2543Smrg	  </programlisting>
8085706f2543Smrg	  <blockquote><para>
8086706f2543Smrg      Write <parameter>value</parameter> to the VGA Enable register.  (Note: This
8087706f2543Smrg      function is present in XFree86 4.1.0 and later.)
8088706f2543Smrg	    </para>
8089706f2543Smrg
8090706f2543Smrg	  </blockquote></para></blockquote>
8091706f2543Smrg    </sect2>
8092706f2543Smrg  </sect1>
8093706f2543Smrg
8094706f2543Smrg  <sect1 id="sample">
8095706f2543Smrg    <title>Some notes about writing a driver</title>
8096706f2543Smrg
8097706f2543Smrg    <note><para>NOTE: some parts of this are not up to date</para></note>
8098706f2543Smrg
8099706f2543Smrg    <para>
8100706f2543SmrgThe following is an outline for writing a basic unaccelerated driver
8101706f2543Smrgfor a PCI video card with a linear mapped framebuffer, and which has a
8102706f2543SmrgVGA core.  It is includes some general information that is relevant to
8103706f2543Smrgmost drivers (even those which don't fit that basic description).
8104706f2543Smrg    </para>
8105706f2543Smrg
8106706f2543Smrg    <para>
8107706f2543SmrgThe information here is based on the initial conversion of the Matrox
8108706f2543SmrgMillennium driver to the <quote>new design</quote>.  For a fleshing out and sample
8109706f2543Smrgimplementation of some of the bits outlined here, refer to that driver.
8110706f2543SmrgNote that this is an example only.  The approach used here will not be
8111706f2543Smrgappropriate for all drivers.
8112706f2543Smrg    </para>
8113706f2543Smrg
8114706f2543Smrg    <para>
8115706f2543SmrgEach driver must reserve a unique driver name, and a string that is used
8116706f2543Smrgto prefix all of its externally visible symbols.  This is to avoid name
8117706f2543Smrgspace clashes when loading multiple drivers.  The examples here are for
8118706f2543Smrgthe <quote>ZZZ</quote> driver, which uses the <quote>ZZZ</quote> or <quote>zzz</quote> prefix for its externally
8119706f2543Smrgvisible symbols.
8120706f2543Smrg    </para>
8121706f2543Smrg
8122706f2543Smrg    <sect2>
8123706f2543Smrg      <title>Include files</title>
8124706f2543Smrg
8125706f2543Smrg      <para>
8126706f2543Smrg  All drivers normally include the following headers:
8127706f2543Smrg	<literallayout><filename>
8128706f2543Smrg    "xf86.h"
8129706f2543Smrg    "xf86_OSproc.h"
8130706f2543Smrg    "xf86_ansic.h"
8131706f2543Smrg    "xf86Resources.h"
8132706f2543Smrg	  </filename></literallayout>
8133706f2543Smrg  Wherever inb/outb (and related things) are used the following should be
8134706f2543Smrg  included:
8135706f2543Smrg	<literallayout><filename>
8136706f2543Smrg    "compiler.h"
8137706f2543Smrg	  </filename></literallayout>
8138706f2543Smrg  Note: in drivers, this must be included after <filename>"xf86_ansic.h"</filename>.
8139706f2543Smrg      </para>
8140706f2543Smrg
8141706f2543Smrg      <para>
8142706f2543Smrg  Drivers that need to access PCI vendor/device definitions need this:
8143706f2543Smrg	<literallayout><filename>
8144706f2543Smrg    "xf86PciInfo.h"
8145706f2543Smrg	  </filename></literallayout>
8146706f2543Smrg      </para>
8147706f2543Smrg
8148706f2543Smrg      <para>
8149706f2543Smrg  Drivers that need to access the PCI config space need this:
8150706f2543Smrg	<literallayout><filename>
8151706f2543Smrg    "xf86Pci.h"
8152706f2543Smrg	  </filename></literallayout>
8153706f2543Smrg      </para>
8154706f2543Smrg
8155706f2543Smrg      <para>
8156706f2543Smrg  Drivers using the mi banking wrapper need:
8157706f2543Smrg
8158706f2543Smrg	<literallayout><filename>
8159706f2543Smrg    "mibank.h"
8160706f2543Smrg	  </filename></literallayout>
8161706f2543Smrg      </para>
8162706f2543Smrg
8163706f2543Smrg      <para>
8164706f2543Smrg  Drivers that initialise a SW cursor need this:
8165706f2543Smrg	<literallayout><filename>
8166706f2543Smrg    "mipointer.h"
8167706f2543Smrg	  </filename></literallayout>
8168706f2543Smrg      </para>
8169706f2543Smrg
8170706f2543Smrg      <para>
8171706f2543Smrg  All drivers implementing backing store need this:
8172706f2543Smrg	<literallayout><filename>
8173706f2543Smrg    "mibstore.h"
8174706f2543Smrg	  </filename></literallayout>
8175706f2543Smrg      </para>
8176706f2543Smrg
8177706f2543Smrg      <para>
8178706f2543Smrg  All drivers using the mi colourmap code need this:
8179706f2543Smrg	<literallayout><filename>
8180706f2543Smrg    "micmap.h"
8181706f2543Smrg	  </filename></literallayout>
8182706f2543Smrg      </para>
8183706f2543Smrg
8184706f2543Smrg      <para>
8185706f2543Smrg  If a driver uses the vgahw module, it needs this:
8186706f2543Smrg	<literallayout><filename>
8187706f2543Smrg    "vgaHW.h"
8188706f2543Smrg	  </filename></literallayout>
8189706f2543Smrg      </para>
8190706f2543Smrg
8191706f2543Smrg      <para>
8192706f2543Smrg  Drivers supporting VGA or Hercules monochrome screens need:
8193706f2543Smrg	<literallayout><filename>
8194706f2543Smrg    "xf1bpp.h"
8195706f2543Smrg	  </filename></literallayout>
8196706f2543Smrg      </para>
8197706f2543Smrg
8198706f2543Smrg      <para>
8199706f2543Smrg  Drivers supporting VGA or EGC 16-colour screens need:
8200706f2543Smrg	<literallayout><filename>
8201706f2543Smrg    "xf4bpp.h"
8202706f2543Smrg	  </filename></literallayout>
8203706f2543Smrg      </para>
8204706f2543Smrg
8205706f2543Smrg      <para>
8206706f2543Smrg  Drivers using cfb need:
8207706f2543Smrg	<programlisting>
8208706f2543Smrg    #define PSZ 8
8209706f2543Smrg    #include "cfb.h"
8210706f2543Smrg    #undef PSZ
8211706f2543Smrg	</programlisting>
8212706f2543Smrg      </para>
8213706f2543Smrg
8214706f2543Smrg      <para>
8215706f2543Smrg  Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
8216706f2543Smrg	<literallayout><filename>
8217706f2543Smrg    "cfb16.h"
8218706f2543Smrg    "cfb24.h"
8219706f2543Smrg    "cfb32.h"
8220706f2543Smrg	  </filename></literallayout>
8221706f2543Smrg      </para>
8222706f2543Smrg
8223706f2543Smrg      <para>
8224706f2543Smrg  The driver's own header file:
8225706f2543Smrg	<literallayout><filename>
8226706f2543Smrg    "zzz.h"
8227706f2543Smrg	  </filename></literallayout>
8228706f2543Smrg      </para>
8229706f2543Smrg
8230706f2543Smrg      <para>
8231706f2543Smrg  Drivers must NOT include the following:
8232706f2543Smrg
8233706f2543Smrg	<literallayout><filename>
8234706f2543Smrg    "xf86Priv.h"
8235706f2543Smrg    "xf86Privstr.h"
8236706f2543Smrg    "xf86_libc.h"
8237706f2543Smrg    "xf86_OSlib.h"
8238706f2543Smrg    "Xos.h"</filename>
8239706f2543Smrg    any OS header
8240706f2543Smrg	</literallayout>
8241706f2543Smrg      </para>
8242706f2543Smrg
8243706f2543Smrg    </sect2>
8244706f2543Smrg
8245706f2543Smrg    <sect2>
8246706f2543Smrg      <title>Data structures and initialisation</title>
8247706f2543Smrg
8248706f2543Smrg      <itemizedlist>
8249706f2543Smrg	<listitem>
8250706f2543Smrg	  <para>The following macros should be defined:
8251706f2543Smrg	    <programlisting>
8252706f2543Smrg#define VERSION &lt;version-as-an-int&gt;
8253706f2543Smrg#define ZZZ_NAME "ZZZ"         /* the name used to prefix messages */
8254706f2543Smrg#define ZZZ_DRIVER_NAME "zzz"  /* the driver name as used in config file */
8255706f2543Smrg#define ZZZ_MAJOR_VERSION &lt;int&gt;
8256706f2543Smrg#define ZZZ_MINOR_VERSION &lt;int&gt;
8257706f2543Smrg#define ZZZ_PATCHLEVEL    &lt;int&gt;
8258706f2543Smrg	    </programlisting>
8259706f2543Smrg	  </para>
8260706f2543Smrg	  <para>
8261706f2543Smrg    NOTE: <constant>ZZZ_DRIVER_NAME</constant> should match the name of the
8262706f2543Smrg    driver module without things like the "lib" prefix, the "_drv" suffix
8263706f2543Smrg    or filename extensions.
8264706f2543Smrg	  </para>
8265706f2543Smrg	</listitem>
8266706f2543Smrg
8267706f2543Smrg	<listitem>
8268706f2543Smrg	  <para>
8269706f2543Smrg    A DriverRec must be defined, which includes the functions required
8270706f2543Smrg    at the pre-probe phase.  The name of this DriverRec must be an
8271706f2543Smrg    upper-case version of ZZZ_DRIVER_NAME (for the purposes of static
8272706f2543Smrg    linking).
8273706f2543Smrg	    <programlisting>
8274706f2543SmrgDriverRec ZZZ = {
8275706f2543Smrg    VERSION,
8276706f2543Smrg    ZZZ_DRIVER_NAME,
8277706f2543Smrg    ZZZIdentify,
8278706f2543Smrg    ZZZProbe,
8279706f2543Smrg    ZZZAvailableOptions,
8280706f2543Smrg    NULL,
8281706f2543Smrg    0
8282706f2543Smrg};
8283706f2543Smrg	    </programlisting>
8284706f2543Smrg	  </para>
8285706f2543Smrg	</listitem>
8286706f2543Smrg
8287706f2543Smrg	<listitem>
8288706f2543Smrg	  <para>Define list of supported chips and their matching ID:
8289706f2543Smrg	    <programlisting>
8290706f2543Smrgstatic SymTabRec ZZZChipsets[] = {
8291706f2543Smrg    { PCI_CHIP_ZZZ1234, "zzz1234a" },
8292706f2543Smrg    { PCI_CHIP_ZZZ5678, "zzz5678a" },
8293706f2543Smrg    { -1,               NULL }
8294706f2543Smrg};
8295706f2543Smrg	    </programlisting>
8296706f2543Smrg	  </para>
8297706f2543Smrg	  <para>
8298706f2543Smrg    The token field may be any integer value that the driver may use to
8299706f2543Smrg    uniquely identify the supported chipsets.  For drivers that support
8300706f2543Smrg    only PCI devices using the PCI device IDs might be a natural choice,
8301706f2543Smrg    but this isn't mandatory.  For drivers that support both PCI and other
8302706f2543Smrg    devices (like ISA), some other ID should probably used.  When other
8303706f2543Smrg    IDs are used as the tokens it is recommended that the names be
8304706f2543Smrg    defined as an <type>enum</type> type.
8305706f2543Smrg	  </para>
8306706f2543Smrg	</listitem>
8307706f2543Smrg
8308706f2543Smrg	<listitem>
8309706f2543Smrg	  <para>
8310706f2543Smrg    If the driver uses the <function>xf86MatchPciInstances()</function>
8311706f2543Smrg    helper (recommended for drivers that support PCI cards) a list that
8312706f2543Smrg    maps PCI IDs to chip IDs and fixed resources must be defined:
8313706f2543Smrg	    <programlisting>
8314706f2543Smrgstatic PciChipsets ZZZPciChipsets[] = {
8315706f2543Smrg    { PCI_CHIP_ZZZ1234, PCI_CHIP_ZZZ1234, RES_SHARED_VGA },
8316706f2543Smrg    { PCI_CHIP_ZZZ5678, PCI_CHIP_ZZZ5678, RES_SHARED_VGA },
8317706f2543Smrg    { -1,               -1,               RES_UNDEFINED }
8318706f2543Smrg}
8319706f2543Smrg	    </programlisting>
8320706f2543Smrg	  </para>
8321706f2543Smrg	</listitem>
8322706f2543Smrg
8323706f2543Smrg	<listitem>
8324706f2543Smrg	  <para>
8325706f2543Smrg    Define the <structname>XF86ModuleVersionInfo</structname> struct for the
8326706f2543Smrg    driver.  This is required for the dynamically loaded version:
8327706f2543Smrg	    <programlisting>
8328706f2543Smrgstatic XF86ModuleVersionInfo zzzVersRec =
8329706f2543Smrg{
8330706f2543Smrg    "zzz",
8331706f2543Smrg    MODULEVENDORSTRING,
8332706f2543Smrg    MODINFOSTRING1,
8333706f2543Smrg    MODINFOSTRING2,
8334706f2543Smrg    XF86_VERSION_CURRENT,
8335706f2543Smrg    ZZZ_MAJOR_VERSION, ZZZ_MINOR_VERSION, ZZZ_PATCHLEVEL,
8336706f2543Smrg    ABI_CLASS_VIDEODRV,
8337706f2543Smrg    ABI_VIDEODRV_VERSION,
8338706f2543Smrg    MOD_CLASS_VIDEODRV,
8339706f2543Smrg    {0,0,0,0}
8340706f2543Smrg};
8341706f2543Smrg	    </programlisting>
8342706f2543Smrg	  </para>
8343706f2543Smrg	</listitem>
8344706f2543Smrg
8345706f2543Smrg	<listitem>
8346706f2543Smrg	  <para>
8347706f2543Smrg    Define a data structure to hold the driver's screen-specific data.
8348706f2543Smrg    This must be used instead of global variables.  This would be defined
8349706f2543Smrg    in the <filename>"zzz.h"</filename> file, something like:
8350706f2543Smrg	    <programlisting>
8351706f2543Smrgtypedef struct {
8352706f2543Smrg    type1  field1;
8353706f2543Smrg    type2  field2;
8354706f2543Smrg    int    fooHack;
8355706f2543Smrg    Bool   pciRetry;
8356706f2543Smrg    Bool   noAccel;
8357706f2543Smrg    Bool   hwCursor;
8358706f2543Smrg    CloseScreenProcPtr CloseScreen;
8359706f2543Smrg    OptionInfoPtr Options;
8360706f2543Smrg    ...
8361706f2543Smrg} ZZZRec, *ZZZPtr;
8362706f2543Smrg	    </programlisting>
8363706f2543Smrg	  </para>
8364706f2543Smrg	</listitem>
8365706f2543Smrg
8366706f2543Smrg	<listitem>
8367706f2543Smrg	  <para>
8368706f2543Smrg    Define the list of config file Options that the driver accepts.  For
8369706f2543Smrg    consistency between drivers those in the list of <quote>standard</quote> options
8370706f2543Smrg    should be used where appropriate before inventing new options.
8371706f2543Smrg
8372706f2543Smrg	    <programlisting>
8373706f2543Smrgtypedef enum {
8374706f2543Smrg    OPTION_FOO_HACK,
8375706f2543Smrg    OPTION_PCI_RETRY,
8376706f2543Smrg    OPTION_HW_CURSOR,
8377706f2543Smrg    OPTION_NOACCEL
8378706f2543Smrg} ZZZOpts;
8379706f2543Smrg
8380706f2543Smrgstatic const OptionInfoRec ZZZOptions[] = {
8381706f2543Smrg  { OPTION_FOO_HACK,  "FooHack",   OPTV_INTEGER, {0}, FALSE },
8382706f2543Smrg  { OPTION_PCI_RETRY, "PciRetry",  OPTV_BOOLEAN, {0}, FALSE },
8383706f2543Smrg  { OPTION_HW_CURSOR, "HWcursor",  OPTV_BOOLEAN, {0}, FALSE },
8384706f2543Smrg  { OPTION_NOACCEL,   "NoAccel",   OPTV_BOOLEAN, {0}, FALSE },
8385706f2543Smrg  { -1,               NULL,        OPTV_NONE,    {0}, FALSE }
8386706f2543Smrg};
8387706f2543Smrg	    </programlisting>
8388706f2543Smrg	  </para>
8389706f2543Smrg	</listitem>
8390706f2543Smrg      </itemizedlist>
8391706f2543Smrg    </sect2>
8392706f2543Smrg
8393706f2543Smrg    <sect2>
8394706f2543Smrg      <title>Functions</title>
8395706f2543Smrg
8396706f2543Smrg
8397706f2543Smrg      <sect3>
8398706f2543Smrg	<title>SetupProc</title>
8399706f2543Smrg
8400706f2543Smrg	<para>
8401706f2543Smrg    For dynamically loaded modules, a <varname>ModuleData</varname>
8402706f2543Smrg    variable is required.  It is should be the name of the driver
8403706f2543Smrg    prepended to "ModuleData".  A <function>Setup()</function> function is
8404706f2543Smrg    also required, which calls <function>xf86AddDriver()</function> to add
8405706f2543Smrg    the driver to the main list of drivers.
8406706f2543Smrg	</para>
8407706f2543Smrg
8408706f2543Smrg	<programlisting>
8409706f2543Smrgstatic MODULESETUPPROTO(zzzSetup);
8410706f2543Smrg
8411706f2543SmrgXF86ModuleData zzzModuleData = { &amp;zzzVersRec, zzzSetup, NULL };
8412706f2543Smrg
8413706f2543Smrgstatic pointer
8414706f2543SmrgzzzSetup(pointer module, pointer opts, int *errmaj, int *errmin)
8415706f2543Smrg{
8416706f2543Smrg    static Bool setupDone = FALSE;
8417706f2543Smrg
8418706f2543Smrg    /* This module should be loaded only once, but check to be sure. */
8419706f2543Smrg
8420706f2543Smrg    if (!setupDone) {
8421706f2543Smrg        /*
8422706f2543Smrg         * Modules that this driver always requires may be loaded
8423706f2543Smrg         * here  by calling LoadSubModule().
8424706f2543Smrg         */
8425706f2543Smrg
8426706f2543Smrg        setupDone = TRUE;
8427706f2543Smrg        xf86AddDriver(&amp;MGA, module, 0);
8428706f2543Smrg
8429706f2543Smrg        /*
8430706f2543Smrg         * The return value must be non-NULL on success even though
8431706f2543Smrg         * there is no TearDownProc.
8432706f2543Smrg         */
8433706f2543Smrg        return (pointer)1;
8434706f2543Smrg    } else {
8435706f2543Smrg        if (errmaj) *errmaj = LDR_ONCEONLY;
8436706f2543Smrg        return NULL;
8437706f2543Smrg    }
8438706f2543Smrg}
8439706f2543Smrg	</programlisting>
8440706f2543Smrg      </sect3>
8441706f2543Smrg
8442706f2543Smrg      <sect3>
8443706f2543Smrg	<title>GetRec, FreeRec</title>
8444706f2543Smrg
8445706f2543Smrg	<para>
8446706f2543Smrg    A function is usually required to allocate the driver's
8447706f2543Smrg    screen-specific data structure and hook it into the
8448706f2543Smrg    <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> field.
8449706f2543Smrg    The <structname>ScrnInfoRec</structname>'s <structfield>driverPrivate</structfield> is
8450706f2543Smrg    initialised to <constant>NULL</constant>, so it is easy to check if the
8451706f2543Smrg    initialisation has already been done.  After allocating it, initialise
8452706f2543Smrg    the fields.  By using <function>xnfcalloc()</function> to do the allocation
8453706f2543Smrg    it is zeroed, and if the allocation fails the server exits.
8454706f2543Smrg	</para>
8455706f2543Smrg
8456706f2543Smrg	<para>
8457706f2543Smrg    NOTE:
8458706f2543Smrg    When allocating structures from inside the driver which are defined
8459706f2543Smrg    on the common level it is important to initialize the structure to
8460706f2543Smrg    zero.
8461706f2543Smrg    Only this guarantees that the server remains source compatible to
8462706f2543Smrg    future changes in common level structures.
8463706f2543Smrg	</para>
8464706f2543Smrg
8465706f2543Smrg	<programlisting>
8466706f2543Smrgstatic Bool
8467706f2543SmrgZZZGetRec(ScrnInfoPtr pScrn)
8468706f2543Smrg{
8469706f2543Smrg    if (pScrn-&gt;driverPrivate != NULL)
8470706f2543Smrg        return TRUE;
8471706f2543Smrg    pScrn-&gt;driverPrivate = xnfcalloc(sizeof(ZZZRec), 1);
8472706f2543Smrg    /* Initialise as required */
8473706f2543Smrg    ...
8474706f2543Smrg    return TRUE;
8475706f2543Smrg}
8476706f2543Smrg	</programlisting>
8477706f2543Smrg
8478706f2543Smrg	<para>
8479706f2543Smrg    Define a macro in <filename>"zzz.h"</filename> which gets a pointer to
8480706f2543Smrg    the <structname>ZZZRec</structname> when given <parameter>pScrn</parameter>:
8481706f2543Smrg
8482706f2543Smrg	  <programlisting>
8483706f2543Smrg#define ZZZPTR(p) ((ZZZPtr)((p)-&gt;driverPrivate))
8484706f2543Smrg	  </programlisting>
8485706f2543Smrg	</para>
8486706f2543Smrg
8487706f2543Smrg	<para>
8488706f2543Smrg    Define a function to free the above, setting it to <constant>NULL</constant>
8489706f2543Smrg    once it has been freed:
8490706f2543Smrg
8491706f2543Smrg	  <programlisting>
8492706f2543Smrgstatic void
8493706f2543SmrgZZZFreeRec(ScrnInfoPtr pScrn)
8494706f2543Smrg{
8495706f2543Smrg    if (pScrn-&gt;driverPrivate == NULL)
8496706f2543Smrg        return;
8497706f2543Smrg    xfree(pScrn-&gt;driverPrivate);
8498706f2543Smrg    pScrn-&gt;driverPrivate = NULL;
8499706f2543Smrg}
8500706f2543Smrg	  </programlisting>
8501706f2543Smrg	</para>
8502706f2543Smrg      </sect3>
8503706f2543Smrg
8504706f2543Smrg      <sect3>
8505706f2543Smrg	<title>Identify</title>
8506706f2543Smrg
8507706f2543Smrg	<para>
8508706f2543Smrg    Define the <function>Identify()</function> function.  It is run before
8509706f2543Smrg    the Probe, and typically prints out an identifying message, which
8510706f2543Smrg    might include the chipsets it supports.  This function is mandatory:
8511706f2543Smrg
8512706f2543Smrg	  <programlisting>
8513706f2543Smrgstatic void
8514706f2543SmrgZZZIdentify(int flags)
8515706f2543Smrg{
8516706f2543Smrg    xf86PrintChipsets(ZZZ_NAME, "driver for ZZZ Tech chipsets",
8517706f2543Smrg                      ZZZChipsets);
8518706f2543Smrg}
8519706f2543Smrg	  </programlisting>
8520706f2543Smrg	</para>
8521706f2543Smrg      </sect3>
8522706f2543Smrg
8523706f2543Smrg      <sect3>
8524706f2543Smrg	<title>Probe</title>
8525706f2543Smrg
8526706f2543Smrg	<para>
8527706f2543Smrg    Define the <function>Probe()</function> function.  The purpose of this
8528706f2543Smrg    is to find all instances of the hardware that the driver supports,
8529706f2543Smrg    and for the ones not already claimed by another driver, claim the
8530706f2543Smrg    slot, and allocate a <structname>ScrnInfoRec</structname>.  This should be
8531706f2543Smrg    a minimal probe, and it should under no circumstances leave the
8532706f2543Smrg    state of the hardware changed.  Because a device is found, don't
8533706f2543Smrg    assume that it will be used.  Don't do any initialisations other
8534706f2543Smrg    than the required <structname>ScrnInfoRec</structname> initialisations.
8535706f2543Smrg    Don't allocate any new data structures.
8536706f2543Smrg	</para>
8537706f2543Smrg
8538706f2543Smrg	<para>
8539706f2543Smrg    This function is mandatory.
8540706f2543Smrg	</para>
8541706f2543Smrg
8542706f2543Smrg	<para>
8543706f2543Smrg    NOTE: The <function>xf86DrvMsg()</function> functions cannot be used from
8544706f2543Smrg    the Probe.
8545706f2543Smrg	</para>
8546706f2543Smrg
8547706f2543Smrg	<programlisting>
8548706f2543Smrgstatic Bool
8549706f2543SmrgZZZProbe(DriverPtr drv, int flags)
8550706f2543Smrg{
8551706f2543Smrg    Bool foundScreen = FALSE;
8552706f2543Smrg    int numDevSections, numUsed;
8553706f2543Smrg    GDevPtr *devSections;
8554706f2543Smrg    int *usedChips;
8555706f2543Smrg    int i;
8556706f2543Smrg
8557706f2543Smrg    /*
8558706f2543Smrg     * Find the config file Device sections that match this
8559706f2543Smrg     * driver, and return if there are none.
8560706f2543Smrg     */
8561706f2543Smrg    if ((numDevSections = xf86MatchDevice(ZZZ_DRIVER_NAME,
8562706f2543Smrg                                          &amp;devSections)) &lt;= 0) {
8563706f2543Smrg        return FALSE;
8564706f2543Smrg    }
8565706f2543Smrg
8566706f2543Smrg    /*
8567706f2543Smrg     * Since this is a PCI card, "probing" just amounts to checking
8568706f2543Smrg     * the PCI data that the server has already collected.  If there
8569706f2543Smrg     * is none, return.
8570706f2543Smrg     *
8571706f2543Smrg     * Although the config file is allowed to override things, it
8572706f2543Smrg     * is reasonable to not allow it to override the detection
8573706f2543Smrg     * of no PCI video cards.
8574706f2543Smrg     *
8575706f2543Smrg     * The provided xf86MatchPciInstances() helper takes care of
8576706f2543Smrg     * the details.
8577706f2543Smrg     */
8578706f2543Smrg    /* test if PCI bus present */
8579706f2543Smrg    if (xf86GetPciVideoInfo()) {
8580706f2543Smrg
8581706f2543Smrg        numUsed = xf86MatchPciInstances(ZZZ_NAME, PCI_VENDOR_ZZZ,
8582706f2543Smrg                            ZZZChipsets, ZZZPciChipsets, devSections,
8583706f2543Smrg                            numDevSections, drv, &amp;usedChips);
8584706f2543Smrg
8585706f2543Smrg        for (i = 0; i &lt; numUsed; i++) {
8586706f2543Smrg            ScrnInfoPtr pScrn = NULL;
8587706f2543Smrg            if ((pScrn = xf86ConfigPciEntity(pScrn, flags, usedChips[i],
8588706f2543Smrg                                             ZZZPciChipsets, NULL, NULL,
8589706f2543Smrg                                             NULL, NULL, NULL))) {
8590706f2543Smrg               /* Allocate a ScrnInfoRec */
8591706f2543Smrg               pScrn-&gt;driverVersion = VERSION;
8592706f2543Smrg               pScrn-&gt;driverName    = ZZZ_DRIVER_NAME;
8593706f2543Smrg               pScrn-&gt;name          = ZZZ_NAME;
8594706f2543Smrg               pScrn-&gt;Probe         = ZZZProbe;
8595706f2543Smrg               pScrn-&gt;PreInit       = ZZZPreInit;
8596706f2543Smrg               pScrn-&gt;ScreenInit    = ZZZScreenInit;
8597706f2543Smrg               pScrn-&gt;SwitchMode    = ZZZSwitchMode;
8598706f2543Smrg               pScrn-&gt;AdjustFrame   = ZZZAdjustFrame;
8599706f2543Smrg               pScrn-&gt;EnterVT       = ZZZEnterVT;
8600706f2543Smrg               pScrn-&gt;LeaveVT       = ZZZLeaveVT;
8601706f2543Smrg               pScrn-&gt;FreeScreen    = ZZZFreeScreen;
8602706f2543Smrg               pScrn-&gt;ValidMode     = ZZZValidMode;
8603706f2543Smrg               foundScreen = TRUE;
8604706f2543Smrg               /* add screen to entity */
8605706f2543Smrg           }
8606706f2543Smrg        }
8607706f2543Smrg        xfree(usedChips);
8608706f2543Smrg    }
8609706f2543Smrg
8610706f2543Smrg#ifdef HAS_ISA_DEVS
8611706f2543Smrg    /*
8612706f2543Smrg     * If the driver supports ISA hardware, the following block
8613706f2543Smrg     * can be included too.
8614706f2543Smrg     */
8615706f2543Smrg    numUsed = xf86MatchIsaInstances(ZZZ_NAME, ZZZChipsets,
8616706f2543Smrg                             ZZZIsaChipsets, drv, ZZZFindIsaDevice,
8617706f2543Smrg                             devSections, numDevSections, &amp;usedChips);
8618706f2543Smrg    for (i = 0; i &lt; numUsed; i++) {
8619706f2543Smrg        ScrnInfoPtr pScrn = NULL;
8620706f2543Smrg	if ((pScrn = xf86ConfigIsaEntity(pScrn, flags, usedChips[i],
8621706f2543Smrg					 ZZZIsaChipsets, NULL, NULL, NULL,
8622706f2543Smrg					 NULL, NULL))) {
8623706f2543Smrg            pScrn-&gt;driverVersion = VERSION;
8624706f2543Smrg            pScrn-&gt;driverName    = ZZZ_DRIVER_NAME;
8625706f2543Smrg            pScrn-&gt;name          = ZZZ_NAME;
8626706f2543Smrg            pScrn-&gt;Probe         = ZZZProbe;
8627706f2543Smrg            pScrn-&gt;PreInit       = ZZZPreInit;
8628706f2543Smrg            pScrn-&gt;ScreenInit    = ZZZScreenInit;
8629706f2543Smrg            pScrn-&gt;SwitchMode    = ZZZSwitchMode;
8630706f2543Smrg            pScrn-&gt;AdjustFrame   = ZZZAdjustFrame;
8631706f2543Smrg            pScrn-&gt;EnterVT       = ZZZEnterVT;
8632706f2543Smrg            pScrn-&gt;LeaveVT       = ZZZLeaveVT;
8633706f2543Smrg            pScrn-&gt;FreeScreen    = ZZZFreeScreen;
8634706f2543Smrg            pScrn-&gt;ValidMode     = ZZZValidMode;
8635706f2543Smrg            foundScreen = TRUE;
8636706f2543Smrg        }
8637706f2543Smrg    }
8638706f2543Smrg    xfree(usedChips);
8639706f2543Smrg#endif /* HAS_ISA_DEVS */
8640706f2543Smrg
8641706f2543Smrg    xfree(devSections);
8642706f2543Smrg    return foundScreen;
8643706f2543Smrg	</programlisting>
8644706f2543Smrg      </sect3>
8645706f2543Smrg
8646706f2543Smrg      <sect3>
8647706f2543Smrg	<title>AvailableOptions</title>
8648706f2543Smrg
8649706f2543Smrg	<para>
8650706f2543Smrg    Define the <function>AvailableOptions()</function> function. The purpose
8651706f2543Smrg    of this is to return the available driver options back to the
8652706f2543Smrg    -configure option, so that an xorg.conf file can be built and the
8653706f2543Smrg    user can see which options are available for them to use.
8654706f2543Smrg	</para>
8655706f2543Smrg      </sect3>
8656706f2543Smrg
8657706f2543Smrg      <sect3>
8658706f2543Smrg	<title>PreInit</title>
8659706f2543Smrg
8660706f2543Smrg	<para>
8661706f2543Smrg    Define the <function>PreInit()</function> function.  The purpose of
8662706f2543Smrg    this is to find all the information required to determine if the
8663706f2543Smrg    configuration is usable, and to initialise those parts of the
8664706f2543Smrg    <structname>ScrnInfoRec</structname> that can be set once at the beginning
8665706f2543Smrg    of the first server generation.  The information should be found in
8666706f2543Smrg    the least intrusive way possible.
8667706f2543Smrg	</para>
8668706f2543Smrg
8669706f2543Smrg	<para>
8670706f2543Smrg    This function is mandatory.
8671706f2543Smrg	</para>
8672706f2543Smrg
8673706f2543Smrg	<para>
8674706f2543Smrg    NOTES:
8675706f2543Smrg	  <orderedlist>
8676706f2543Smrg	    <listitem><para>
8677706f2543Smrg	 The <function>PreInit()</function> function is only called once
8678706f2543Smrg	 during the life of the X server (at the start of the first
8679706f2543Smrg	 generation).
8680706f2543Smrg	      </para></listitem>
8681706f2543Smrg
8682706f2543Smrg	    <listitem><para>
8683706f2543Smrg	 Data allocated here must be of the type that persists for
8684706f2543Smrg	 the life of the X server.  This means that data that hooks into
8685706f2543Smrg	 the <structname>ScrnInfoRec</structname>'s <structfield>privates</structfield>
8686706f2543Smrg	 field should be allocated here, but data that hooks into the
8687706f2543Smrg	 <structname>ScreenRec</structname>'s <structfield>devPrivates</structfield> field
8688706f2543Smrg	 should not be allocated here.  The <structfield>driverPrivate</structfield>
8689706f2543Smrg	 field should also be allocated here.
8690706f2543Smrg	      </para></listitem>
8691706f2543Smrg
8692706f2543Smrg	    <listitem><para>
8693706f2543Smrg	 Although the <structname>ScrnInfoRec</structname> has been allocated
8694706f2543Smrg	 before this function is called, the <structname>ScreenRec</structname>
8695706f2543Smrg	 has not been allocated.  That means that things requiring it
8696706f2543Smrg	 cannot be used in this function.
8697706f2543Smrg	      </para></listitem>
8698706f2543Smrg
8699706f2543Smrg	    <listitem><para>
8700706f2543Smrg	 Very little of the <structname>ScrnInfoRec</structname> has been
8701706f2543Smrg	 initialised when this function is called.  It is important to
8702706f2543Smrg	 get the order of doing things right in this function.
8703706f2543Smrg	      </para></listitem>
8704706f2543Smrg
8705706f2543Smrg	  </orderedlist>
8706706f2543Smrg	</para>
8707706f2543Smrg
8708706f2543Smrg	<programlisting>
8709706f2543Smrgstatic Bool
8710706f2543SmrgZZZPreInit(ScrnInfoPtr pScrn, int flags)
8711706f2543Smrg{
8712706f2543Smrg    /* Fill in the monitor field */
8713706f2543Smrg    pScrn-&gt;monitor = pScrn-&gt;confScreen-&gt;monitor;
8714706f2543Smrg
8715706f2543Smrg    /*
8716706f2543Smrg     * If using the vgahw module, it will typically be loaded
8717706f2543Smrg     * here by calling xf86LoadSubModule(pScrn, "vgahw");
8718706f2543Smrg     */
8719706f2543Smrg
8720706f2543Smrg    /*
8721706f2543Smrg     * Set the depth/bpp.  Use the globally preferred depth/bpp.  If the
8722706f2543Smrg     * driver has special default depth/bpp requirements, the defaults should
8723706f2543Smrg     * be specified here explicitly.
8724706f2543Smrg     * We support both 24bpp and 32bpp framebuffer layouts.
8725706f2543Smrg     * This sets pScrn-&gt;display also.
8726706f2543Smrg     */
8727706f2543Smrg    if (!xf86SetDepthBpp(pScrn, 0, 0, 0,
8728706f2543Smrg                         Support24bppFb | Support32bppFb)) {
8729706f2543Smrg        return FALSE;
8730706f2543Smrg    } else {
8731706f2543Smrg        if (depth/bpp isn't one we support) {
8732706f2543Smrg            print error message;
8733706f2543Smrg            return FALSE;
8734706f2543Smrg        }
8735706f2543Smrg    }
8736706f2543Smrg    /* Print out the depth/bpp that was set */
8737706f2543Smrg    xf86PrintDepthBpp(pScrn);
8738706f2543Smrg
8739706f2543Smrg    /* Set bits per RGB for 8bpp */
8740706f2543Smrg    if (pScrn-&gt;depth &lt;= 8) {
8741706f2543Smrg        /* Take into account a dac_6_bit option here */
8742706f2543Smrg        pScrn-&gt;rgbBits = 6 or 8;
8743706f2543Smrg    }
8744706f2543Smrg
8745706f2543Smrg    /*
8746706f2543Smrg     * xf86SetWeight() and xf86SetDefaultVisual() must be called
8747706f2543Smrg     * after pScrn-&gt;display is initialised.
8748706f2543Smrg     */
8749706f2543Smrg
8750706f2543Smrg    /* Set weight/mask/offset for depth &gt; 8 */
8751706f2543Smrg    if (pScrn-&gt;depth &gt; 8) {
8752706f2543Smrg        if (!xf86SetWeight(pScrn, defaultWeight, defaultMask)) {
8753706f2543Smrg            return FALSE;
8754706f2543Smrg        } else {
8755706f2543Smrg            if (weight isn't one we support) {
8756706f2543Smrg                print error message;
8757706f2543Smrg                return FALSE;
8758706f2543Smrg            }
8759706f2543Smrg        }
8760706f2543Smrg    }
8761706f2543Smrg
8762706f2543Smrg    /* Set the default visual. */
8763706f2543Smrg    if (!xf86SetDefaultVisual(pScrn, -1)) {
8764706f2543Smrg        return FALSE;
8765706f2543Smrg    } else {
8766706f2543Smrg        if (visual isn't one we support) {
8767706f2543Smrg            print error message;
8768706f2543Smrg            return FALSE;
8769706f2543Smrg        }
8770706f2543Smrg    }
8771706f2543Smrg
8772706f2543Smrg    /* If the driver supports gamma correction, set the gamma. */
8773706f2543Smrg    if (!xf86SetGamma(pScrn, default_gamma)) {
8774706f2543Smrg        return FALSE;
8775706f2543Smrg    }
8776706f2543Smrg
8777706f2543Smrg    /* This driver uses a programmable clock */
8778706f2543Smrg    pScrn-&gt;progClock = TRUE;
8779706f2543Smrg
8780706f2543Smrg    /* Allocate the ZZZRec driverPrivate */
8781706f2543Smrg    if (!ZZZGetRec(pScrn)) {
8782706f2543Smrg        return FALSE;
8783706f2543Smrg    }
8784706f2543Smrg
8785706f2543Smrg    pZzz = ZZZPTR(pScrn);
8786706f2543Smrg
8787706f2543Smrg    /* Collect all of the option flags (fill in pScrn-&gt;options) */
8788706f2543Smrg    xf86CollectOptions(pScrn, NULL);
8789706f2543Smrg
8790706f2543Smrg    /*
8791706f2543Smrg     * Process the options based on the information in ZZZOptions.
8792706f2543Smrg     * The results are written to pZzz-&gt;Options.  If all of the options
8793706f2543Smrg     * processing is done within this function a local variable "options"
8794706f2543Smrg     * can be used instead of pZzz-&gt;Options.
8795706f2543Smrg     */
8796706f2543Smrg    if (!(pZzz-&gt;Options = xalloc(sizeof(ZZZOptions))))
8797706f2543Smrg        return FALSE;
8798706f2543Smrg    (void)memcpy(pZzz-&gt;Options, ZZZOptions, sizeof(ZZZOptions));
8799706f2543Smrg    xf86ProcessOptions(pScrn-&gt;scrnIndex, pScrn-&gt;options, pZzz-&gt;Options);
8800706f2543Smrg
8801706f2543Smrg    /*
8802706f2543Smrg     * Set various fields of ScrnInfoRec and/or ZZZRec based on
8803706f2543Smrg     * the options found.
8804706f2543Smrg     */
8805706f2543Smrg    from = X_DEFAULT;
8806706f2543Smrg    pZzz-&gt;hwCursor = FALSE;
8807706f2543Smrg    if (xf86IsOptionSet(pZzz-&gt;Options, OPTION_HW_CURSOR)) {
8808706f2543Smrg        from = X_CONFIG;
8809706f2543Smrg        pZzz-&gt;hwCursor = TRUE;
8810706f2543Smrg    }
8811706f2543Smrg    xf86DrvMsg(pScrn-&gt;scrnIndex, from, "Using %s cursor\n",
8812706f2543Smrg               pZzz-&gt;hwCursor ? "HW" : "SW");
8813706f2543Smrg    if (xf86IsOptionSet(pZzz-&gt;Options, OPTION_NOACCEL)) {
8814706f2543Smrg        pZzz-&gt;noAccel = TRUE;
8815706f2543Smrg        xf86DrvMsg(pScrn-&gt;scrnIndex, X_CONFIG,
8816706f2543Smrg                   "Acceleration disabled\n");
8817706f2543Smrg    } else {
8818706f2543Smrg        pZzz-&gt;noAccel = FALSE;
8819706f2543Smrg    }
8820706f2543Smrg    if (xf86IsOptionSet(pZzz-&gt;Options, OPTION_PCI_RETRY)) {
8821706f2543Smrg        pZzz-&gt;UsePCIRetry = TRUE;
8822706f2543Smrg        xf86DrvMsg(pScrn-&gt;scrnIndex, X_CONFIG, "PCI retry enabled\n");
8823706f2543Smrg    }
8824706f2543Smrg    pZzz-&gt;fooHack = 0;
8825706f2543Smrg    if (xf86GetOptValInteger(pZzz-&gt;Options, OPTION_FOO_HACK,
8826706f2543Smrg                             &amp;pZzz-&gt;fooHack)) {
8827706f2543Smrg        xf86DrvMsg(pScrn-&gt;scrnIndex, X_CONFIG, "Foo Hack set to %d\n",
8828706f2543Smrg                   pZzz-&gt;fooHack);
8829706f2543Smrg    }
8830706f2543Smrg
8831706f2543Smrg    /*
8832706f2543Smrg     * Find the PCI slot(s) that this screen claimed in the probe.
8833706f2543Smrg     * In this case, exactly one is expected, so complain otherwise.
8834706f2543Smrg     * Note in this case we're not interested in the card types so
8835706f2543Smrg     * that parameter is set to NULL.
8836706f2543Smrg     */
8837706f2543Smrg    if ((i = xf86GetPciInfoForScreen(pScrn-&gt;scrnIndex, &amp;pciList, NULL))
8838706f2543Smrg        != 1) {
8839706f2543Smrg        print error message;
8840706f2543Smrg        ZZZFreeRec(pScrn);
8841706f2543Smrg        if (i &gt; 0)
8842706f2543Smrg            xfree(pciList);
8843706f2543Smrg        return FALSE;
8844706f2543Smrg    }
8845706f2543Smrg    /* Note that pciList should be freed below when no longer needed */
8846706f2543Smrg
8847706f2543Smrg    /*
8848706f2543Smrg     * Determine the chipset, allowing config file chipset and
8849706f2543Smrg     * chipid values to override the probed information.  The config
8850706f2543Smrg     * chipset value has precedence over its chipid value if both
8851706f2543Smrg     * are present.
8852706f2543Smrg     *
8853706f2543Smrg     * It isn't necessary to fill in pScrn-&gt;chipset if the driver
8854706f2543Smrg     * keeps track of the chipset in its ZZZRec.
8855706f2543Smrg     */
8856706f2543Smrg
8857706f2543Smrg    ...
8858706f2543Smrg
8859706f2543Smrg    /*
8860706f2543Smrg     * Determine video memory, fb base address, I/O addresses, etc,
8861706f2543Smrg     * allowing the config file to override probed values.
8862706f2543Smrg     *
8863706f2543Smrg     * Set the appropriate pScrn fields (videoRam is probably the
8864706f2543Smrg     * most important one that other code might require), and
8865706f2543Smrg     * print out the settings.
8866706f2543Smrg     */
8867706f2543Smrg
8868706f2543Smrg    ...
8869706f2543Smrg
8870706f2543Smrg    /* Initialise a clockRanges list. */
8871706f2543Smrg
8872706f2543Smrg    ...
8873706f2543Smrg
8874706f2543Smrg    /* Set any other chipset specific things in the ZZZRec */
8875706f2543Smrg
8876706f2543Smrg    ...
8877706f2543Smrg
8878706f2543Smrg    /* Select valid modes from those available */
8879706f2543Smrg
8880706f2543Smrg    i = xf86ValidateModes(pScrn, pScrn-&gt;monitor-&gt;Modes,
8881706f2543Smrg                          pScrn-&gt;display-&gt;modes, clockRanges,
8882706f2543Smrg                          NULL, minPitch, maxPitch, rounding,
8883706f2543Smrg                          minHeight, maxHeight,
8884706f2543Smrg                          pScrn-&gt;display-&gt;virtualX,
8885706f2543Smrg                          pScrn-&gt;display-&gt;virtualY,
8886706f2543Smrg                          pScrn-&gt;videoRam * 1024,
8887706f2543Smrg                          LOOKUP_BEST_REFRESH);
8888706f2543Smrg    if (i == -1) {
8889706f2543Smrg        ZZZFreeRec(pScrn);
8890706f2543Smrg        return FALSE;
8891706f2543Smrg    }
8892706f2543Smrg
8893706f2543Smrg    /* Prune the modes marked as invalid */
8894706f2543Smrg
8895706f2543Smrg    xf86PruneDriverModes(pScrn);
8896706f2543Smrg
8897706f2543Smrg    /* If no valid modes, return */
8898706f2543Smrg
8899706f2543Smrg    if (i == 0 || pScrn-&gt;modes == NULL) {
8900706f2543Smrg        print error message;
8901706f2543Smrg        ZZZFreeRec(pScrn);
8902706f2543Smrg        return FALSE;
8903706f2543Smrg    }
8904706f2543Smrg
8905706f2543Smrg    /*
8906706f2543Smrg     * Initialise the CRTC fields for the modes.  This driver expects
8907706f2543Smrg     * vertical values to be halved for interlaced modes.
8908706f2543Smrg     */
8909706f2543Smrg    xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V);
8910706f2543Smrg
8911706f2543Smrg    /* Set the current mode to the first in the list. */
8912706f2543Smrg    pScrn-&gt;currentMode = pScrn-&gt;modes;
8913706f2543Smrg
8914706f2543Smrg    /* Print the list of modes being used. */
8915706f2543Smrg    xf86PrintModes(pScrn);
8916706f2543Smrg
8917706f2543Smrg    /* Set the DPI */
8918706f2543Smrg    xf86SetDpi(pScrn, 0, 0);
8919706f2543Smrg
8920706f2543Smrg    /* Load bpp-specific modules */
8921706f2543Smrg    switch (pScrn-&gt;bitsPerPixel) {
8922706f2543Smrg    case 1:
8923706f2543Smrg        mod = "xf1bpp";
8924706f2543Smrg        break;
8925706f2543Smrg    case 4:
8926706f2543Smrg        mod = "xf4bpp";
8927706f2543Smrg        break;
8928706f2543Smrg    case 8:
8929706f2543Smrg        mod = "cfb";
8930706f2543Smrg        break;
8931706f2543Smrg    case 16:
8932706f2543Smrg        mod = "cfb16";
8933706f2543Smrg        break;
8934706f2543Smrg    case 24:
8935706f2543Smrg        mod = "cfb24";
8936706f2543Smrg        break;
8937706f2543Smrg    case 32:
8938706f2543Smrg        mod = "cfb32";
8939706f2543Smrg        break;
8940706f2543Smrg    }
8941706f2543Smrg    if (mod &amp;&amp; !xf86LoadSubModule(pScrn, mod))
8942706f2543Smrg        ZZZFreeRec(pScrn);
8943706f2543Smrg        return FALSE;
8944706f2543Smrg
8945706f2543Smrg    /* Load XAA if needed */
8946706f2543Smrg    if (!pZzz-&gt;noAccel || pZzz-&gt;hwCursor)
8947706f2543Smrg        if (!xf86LoadSubModule(pScrn, "xaa")) {
8948706f2543Smrg            ZZZFreeRec(pScrn);
8949706f2543Smrg            return FALSE;
8950706f2543Smrg        }
8951706f2543Smrg
8952706f2543Smrg    /* Done */
8953706f2543Smrg    return TRUE;
8954706f2543Smrg}
8955706f2543Smrg	</programlisting>
8956706f2543Smrg      </sect3>
8957706f2543Smrg
8958706f2543Smrg      <sect3>
8959706f2543Smrg	<title>MapMem, UnmapMem</title>
8960706f2543Smrg
8961706f2543Smrg	<para>
8962706f2543Smrg    Define functions to map and unmap the video memory and any other
8963706f2543Smrg    memory apertures required.  These functions are not mandatory, but
8964706f2543Smrg    it is often useful to have such functions.
8965706f2543Smrg	</para>
8966706f2543Smrg
8967706f2543Smrg	<programlisting>
8968706f2543Smrgstatic Bool
8969706f2543SmrgZZZMapMem(ScrnInfoPtr pScrn)
8970706f2543Smrg{
8971706f2543Smrg    /* Call xf86MapPciMem() to map each PCI memory area */
8972706f2543Smrg    ...
8973706f2543Smrg    return TRUE or FALSE;
8974706f2543Smrg}
8975706f2543Smrg
8976706f2543Smrgstatic Bool
8977706f2543SmrgZZZUnmapMem(ScrnInfoPtr pScrn)
8978706f2543Smrg{
8979706f2543Smrg    /* Call xf86UnMapVidMem() to unmap each memory area */
8980706f2543Smrg    ...
8981706f2543Smrg    return TRUE or FALSE;
8982706f2543Smrg}
8983706f2543Smrg	</programlisting>
8984706f2543Smrg      </sect3>
8985706f2543Smrg
8986706f2543Smrg      <sect3>
8987706f2543Smrg	<title>Save, Restore</title>
8988706f2543Smrg
8989706f2543Smrg	<para>
8990706f2543Smrg    Define functions to save and restore the original video state.  These
8991706f2543Smrg    functions are not mandatory, but are often useful.
8992706f2543Smrg	</para>
8993706f2543Smrg
8994706f2543Smrg	<programlisting>
8995706f2543Smrgstatic void
8996706f2543SmrgZZZSave(ScrnInfoPtr pScrn)
8997706f2543Smrg{
8998706f2543Smrg    /*
8999706f2543Smrg     * Save state into per-screen data structures.
9000706f2543Smrg     * If using the vgahw module, vgaHWSave will typically be
9001706f2543Smrg     * called here.
9002706f2543Smrg     */
9003706f2543Smrg    ...
9004706f2543Smrg}
9005706f2543Smrg
9006706f2543Smrgstatic void
9007706f2543SmrgZZZRestore(ScrnInfoPtr pScrn)
9008706f2543Smrg{
9009706f2543Smrg    /*
9010706f2543Smrg     * Restore state from per-screen data structures.
9011706f2543Smrg     * If using the vgahw module, vgaHWRestore will typically be
9012706f2543Smrg     * called here.
9013706f2543Smrg     */
9014706f2543Smrg    ...
9015706f2543Smrg}
9016706f2543Smrg	</programlisting>
9017706f2543Smrg      </sect3>
9018706f2543Smrg
9019706f2543Smrg      <sect3>
9020706f2543Smrg	<title>ModeInit</title>
9021706f2543Smrg
9022706f2543Smrg	<para>
9023706f2543Smrg    Define a function to initialise a new video mode.  This function isn't
9024706f2543Smrg    mandatory, but is often useful.
9025706f2543Smrg	</para>
9026706f2543Smrg
9027706f2543Smrg	<programlisting>
9028706f2543Smrgstatic Bool
9029706f2543SmrgZZZModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
9030706f2543Smrg{
9031706f2543Smrg    /*
9032706f2543Smrg     * Program a video mode.  If using the vgahw module,
9033706f2543Smrg     * vgaHWInit and vgaRestore will typically be called here.
9034706f2543Smrg     * Once up to the point where there can't be a failure
9035706f2543Smrg     * set pScrn-&gt;vtSema to TRUE.
9036706f2543Smrg     */
9037706f2543Smrg    ...
9038706f2543Smrg}
9039706f2543Smrg	</programlisting>
9040706f2543Smrg      </sect3>
9041706f2543Smrg
9042706f2543Smrg      <sect3>
9043706f2543Smrg	<title>ScreenInit</title>
9044706f2543Smrg
9045706f2543Smrg	<para>
9046706f2543Smrg    Define the <function>ScreenInit()</function> function.  This is called
9047706f2543Smrg    at the start of each server generation, and should fill in as much
9048706f2543Smrg    of the <structname>ScreenRec</structname> as possible as well as any other
9049706f2543Smrg    data that is initialised once per generation.  It should initialise
9050706f2543Smrg    the framebuffer layers it is using, and initialise the initial video
9051706f2543Smrg    mode.
9052706f2543Smrg	</para>
9053706f2543Smrg
9054706f2543Smrg	<para>
9055706f2543Smrg    This function is mandatory.
9056706f2543Smrg	</para>
9057706f2543Smrg
9058706f2543Smrg	<para>
9059706f2543Smrg    NOTE: The <structname>ScreenRec</structname> (<parameter>pScreen</parameter>) is
9060706f2543Smrg	  passed to this driver, but it and the
9061706f2543Smrg	  <varname>ScrnInfoRecs</varname> are not yet hooked into each
9062706f2543Smrg	  other.  This means that in this function, and functions it
9063706f2543Smrg	  calls, one cannot be found from the other.
9064706f2543Smrg	</para>
9065706f2543Smrg
9066706f2543Smrg	<programlisting>
9067706f2543Smrgstatic Bool
9068706f2543SmrgZZZScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
9069706f2543Smrg{
9070706f2543Smrg    /* Get the ScrnInfoRec */
9071706f2543Smrg    pScrn = xf86Screens[pScreen-&gt;myNum];
9072706f2543Smrg
9073706f2543Smrg    /*
9074706f2543Smrg     * If using the vgahw module, its data structures and related
9075706f2543Smrg     * things are typically initialised/mapped here.
9076706f2543Smrg     */
9077706f2543Smrg
9078706f2543Smrg    /* Save the current video state */
9079706f2543Smrg    ZZZSave(pScrn);
9080706f2543Smrg
9081706f2543Smrg    /* Initialise the first mode */
9082706f2543Smrg    ZZZModeInit(pScrn, pScrn-&gt;currentMode);
9083706f2543Smrg
9084706f2543Smrg    /* Set the viewport if supported */
9085706f2543Smrg
9086706f2543Smrg    ZZZAdjustFrame(scrnIndex, pScrn-&gt;frameX0, pScrn-&gt;frameY0, 0);
9087706f2543Smrg
9088706f2543Smrg    /*
9089706f2543Smrg     * Setup the screen's visuals, and initialise the framebuffer
9090706f2543Smrg     * code.
9091706f2543Smrg     */
9092706f2543Smrg
9093706f2543Smrg    /* Reset the visual list */
9094706f2543Smrg    miClearVisualTypes();
9095706f2543Smrg
9096706f2543Smrg    /*
9097706f2543Smrg     * Setup the visuals supported.  This driver only supports
9098706f2543Smrg     * TrueColor for bpp &gt; 8, so the default set of visuals isn't
9099706f2543Smrg     * acceptable.  To deal with this, call miSetVisualTypes with
9100706f2543Smrg     * the appropriate visual mask.
9101706f2543Smrg     */
9102706f2543Smrg
9103706f2543Smrg    if (pScrn-&gt;bitsPerPixel &gt; 8) {
9104706f2543Smrg        if (!miSetVisualTypes(pScrn-&gt;depth, TrueColorMask,
9105706f2543Smrg                              pScrn-&gt;rgbBits, pScrn-&gt;defaultVisual))
9106706f2543Smrg            return FALSE;
9107706f2543Smrg    } else {
9108706f2543Smrg        if (!miSetVisualTypes(pScrn-&gt;depth,
9109706f2543Smrg                              miGetDefaultVisualMask(pScrn-&gt;depth),
9110706f2543Smrg                              pScrn-&gt;rgbBits, pScrn-&gt;defaultVisual))
9111706f2543Smrg            return FALSE;
9112706f2543Smrg    }
9113706f2543Smrg
9114706f2543Smrg    /*
9115706f2543Smrg     * Initialise the framebuffer.
9116706f2543Smrg     */
9117706f2543Smrg
9118706f2543Smrg    switch (pScrn-&gt;bitsPerPixel) {
9119706f2543Smrg    case 1:
9120706f2543Smrg        ret = xf1bppScreenInit(pScreen, FbBase,
9121706f2543Smrg                               pScrn-&gt;virtualX, pScrn-&gt;virtualY,
9122706f2543Smrg                               pScrn-&gt;xDpi, pScrn-&gt;yDpi,
9123706f2543Smrg                               pScrn-&gt;displayWidth);
9124706f2543Smrg        break;
9125706f2543Smrg    case 4:
9126706f2543Smrg        ret = xf4bppScreenInit(pScreen, FbBase,
9127706f2543Smrg                               pScrn-&gt;virtualX, pScrn-&gt;virtualY,
9128706f2543Smrg                               pScrn-&gt;xDpi, pScrn-&gt;yDpi,
9129706f2543Smrg                               pScrn-&gt;displayWidth);
9130706f2543Smrg        break;
9131706f2543Smrg    case 8:
9132706f2543Smrg        ret = cfbScreenInit(pScreen, FbBase,
9133706f2543Smrg                            pScrn-&gt;virtualX, pScrn-&gt;virtualY,
9134706f2543Smrg                            pScrn-&gt;xDpi, pScrn-&gt;yDpi,
9135706f2543Smrg                            pScrn-&gt;displayWidth);
9136706f2543Smrg        break;
9137706f2543Smrg    case 16:
9138706f2543Smrg        ret = cfb16ScreenInit(pScreen, FbBase,
9139706f2543Smrg                              pScrn-&gt;virtualX, pScrn-&gt;virtualY,
9140706f2543Smrg                              pScrn-&gt;xDpi, pScrn-&gt;yDpi,
9141706f2543Smrg                              pScrn-&gt;displayWidth);
9142706f2543Smrg        break;
9143706f2543Smrg    case 24:
9144706f2543Smrg        ret = cfb24ScreenInit(pScreen, FbBase,
9145706f2543Smrg                              pScrn-&gt;virtualX, pScrn-&gt;virtualY,
9146706f2543Smrg                              pScrn-&gt;xDpi, pScrn-&gt;yDpi,
9147706f2543Smrg                              pScrn-&gt;displayWidth);
9148706f2543Smrg        break;
9149706f2543Smrg    case 32:
9150706f2543Smrg        ret = cfb32ScreenInit(pScreen, FbBase,
9151706f2543Smrg                              pScrn-&gt;virtualX, pScrn-&gt;virtualY,
9152706f2543Smrg                              pScrn-&gt;xDpi, pScrn-&gt;yDpi,
9153706f2543Smrg                              pScrn-&gt;displayWidth);
9154706f2543Smrg        break;
9155706f2543Smrg    default:
9156706f2543Smrg        print a message about an internal error;
9157706f2543Smrg        ret = FALSE;
9158706f2543Smrg        break;
9159706f2543Smrg    }
9160706f2543Smrg
9161706f2543Smrg    if (!ret)
9162706f2543Smrg        return FALSE;
9163706f2543Smrg
9164706f2543Smrg    /* Override the default mask/offset settings */
9165706f2543Smrg    if (pScrn-&gt;bitsPerPixel &gt; 8) {
9166706f2543Smrg        for (i = 0, visual = pScreen-&gt;visuals;
9167706f2543Smrg             i &lt; pScreen-&gt;numVisuals; i++, visual++) {
9168706f2543Smrg            if ((visual-&gt;class | DynamicClass) == DirectColor) {
9169706f2543Smrg                visual-&gt;offsetRed = pScrn-&gt;offset.red;
9170706f2543Smrg                visual-&gt;offsetGreen = pScrn-&gt;offset.green;
9171706f2543Smrg                visual-&gt;offsetBlue = pScrn-&gt;offset.blue;
9172706f2543Smrg                visual-&gt;redMask = pScrn-&gt;mask.red;
9173706f2543Smrg                visual-&gt;greenMask = pScrn-&gt;mask.green;
9174706f2543Smrg                visual-&gt;blueMask = pScrn-&gt;mask.blue;
9175706f2543Smrg            }
9176706f2543Smrg        }
9177706f2543Smrg    }
9178706f2543Smrg
9179706f2543Smrg    /*
9180706f2543Smrg     * If banking is needed, initialise an miBankInfoRec (defined in
9181706f2543Smrg     * "mibank.h"), and call miInitializeBanking().
9182706f2543Smrg     */
9183706f2543Smrg    if (!miInitializeBanking(pScreen, pScrn-&gt;virtualX, pScrn-&gt;virtualY,
9184706f2543Smrg                                     pScrn-&gt;displayWidth, pBankInfo))
9185706f2543Smrg        return FALSE;
9186706f2543Smrg
9187706f2543Smrg    /*
9188706f2543Smrg     * If backing store is to be supported (as is usually the case),
9189706f2543Smrg     * initialise it.
9190706f2543Smrg     */
9191706f2543Smrg    miInitializeBackingStore(pScreen);
9192706f2543Smrg
9193706f2543Smrg    /*
9194706f2543Smrg     * Set initial black &amp; white colourmap indices.
9195706f2543Smrg     */
9196706f2543Smrg    xf86SetBlackWhitePixels(pScreen);
9197706f2543Smrg
9198706f2543Smrg    /*
9199706f2543Smrg     * Install colourmap functions.  If using the vgahw module,
9200706f2543Smrg     * vgaHandleColormaps would usually be called here.
9201706f2543Smrg     */
9202706f2543Smrg
9203706f2543Smrg    ...
9204706f2543Smrg
9205706f2543Smrg    /*
9206706f2543Smrg     * Initialise cursor functions.  This example is for the mi
9207706f2543Smrg     * software cursor.
9208706f2543Smrg     */
9209706f2543Smrg    miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
9210706f2543Smrg
9211706f2543Smrg    /* Initialise the default colourmap */
9212706f2543Smrg    switch (pScrn-&gt;depth) {
9213706f2543Smrg    case 1:
9214706f2543Smrg        if (!xf1bppCreateDefColormap(pScreen))
9215706f2543Smrg            return FALSE;
9216706f2543Smrg        break;
9217706f2543Smrg    case 4:
9218706f2543Smrg        if (!xf4bppCreateDefColormap(pScreen))
9219706f2543Smrg            return FALSE;
9220706f2543Smrg        break;
9221706f2543Smrg    default:
9222706f2543Smrg        if (!cfbCreateDefColormap(pScreen))
9223706f2543Smrg            return FALSE;
9224706f2543Smrg        break;
9225706f2543Smrg    }
9226706f2543Smrg
9227706f2543Smrg    /*
9228706f2543Smrg     * Wrap the CloseScreen vector and set SaveScreen.
9229706f2543Smrg     */
9230706f2543Smrg    ZZZPTR(pScrn)-&gt;CloseScreen = pScreen-&gt;CloseScreen;
9231706f2543Smrg    pScreen-&gt;CloseScreen = ZZZCloseScreen;
9232706f2543Smrg    pScreen-&gt;SaveScreen = ZZZSaveScreen;
9233706f2543Smrg
9234706f2543Smrg    /* Report any unused options (only for the first generation) */
9235706f2543Smrg    if (serverGeneration == 1) {
9236706f2543Smrg        xf86ShowUnusedOptions(pScrn-&gt;scrnIndex, pScrn-&gt;options);
9237706f2543Smrg    }
9238706f2543Smrg
9239706f2543Smrg    /* Done */
9240706f2543Smrg    return TRUE;
9241706f2543Smrg}
9242706f2543Smrg	</programlisting>
9243706f2543Smrg      </sect3>
9244706f2543Smrg
9245706f2543Smrg      <sect3>
9246706f2543Smrg	<title>SwitchMode</title>
9247706f2543Smrg
9248706f2543Smrg	<para>
9249706f2543Smrg    Define the <function>SwitchMode()</function> function if mode switching
9250706f2543Smrg    is supported by the driver.
9251706f2543Smrg	</para>
9252706f2543Smrg
9253706f2543Smrg	<programlisting>
9254706f2543Smrgstatic Bool
9255706f2543SmrgZZZSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
9256706f2543Smrg{
9257706f2543Smrg    return ZZZModeInit(xf86Screens[scrnIndex], mode);
9258706f2543Smrg}
9259706f2543Smrg	</programlisting>
9260706f2543Smrg      </sect3>
9261706f2543Smrg
9262706f2543Smrg      <sect3>
9263706f2543Smrg	<title>AdjustFrame</title>
9264706f2543Smrg
9265706f2543Smrg	<para>
9266706f2543Smrg    Define the <function>AdjustFrame()</function> function if the driver
9267706f2543Smrg    supports this.
9268706f2543Smrg	</para>
9269706f2543Smrg
9270706f2543Smrg	<programlisting>
9271706f2543Smrgstatic void
9272706f2543SmrgZZZAdjustFrame(int scrnIndex, int x, int y, int flags)
9273706f2543Smrg{
9274706f2543Smrg    /* Adjust the viewport */
9275706f2543Smrg}
9276706f2543Smrg	</programlisting>
9277706f2543Smrg      </sect3>
9278706f2543Smrg
9279706f2543Smrg      <sect3>
9280706f2543Smrg	<title>EnterVT, LeaveVT</title>
9281706f2543Smrg
9282706f2543Smrg	<para>
9283706f2543Smrg    Define the <function>EnterVT()</function> and <function>LeaveVT()</function>
9284706f2543Smrg    functions.
9285706f2543Smrg	</para>
9286706f2543Smrg
9287706f2543Smrg	<para>
9288706f2543Smrg    These functions are mandatory.
9289706f2543Smrg	</para>
9290706f2543Smrg
9291706f2543Smrg	<programlisting>
9292706f2543Smrgstatic Bool
9293706f2543SmrgZZZEnterVT(int scrnIndex, int flags)
9294706f2543Smrg{
9295706f2543Smrg    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
9296706f2543Smrg    return ZZZModeInit(pScrn, pScrn-&gt;currentMode);
9297706f2543Smrg}
9298706f2543Smrg
9299706f2543Smrgstatic void
9300706f2543SmrgZZZLeaveVT(int scrnIndex, int flags)
9301706f2543Smrg{
9302706f2543Smrg    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
9303706f2543Smrg    ZZZRestore(pScrn);
9304706f2543Smrg}
9305706f2543Smrg	</programlisting>
9306706f2543Smrg      </sect3>
9307706f2543Smrg
9308706f2543Smrg      <sect3>
9309706f2543Smrg	<title>CloseScreen</title>
9310706f2543Smrg
9311706f2543Smrg	<para>
9312706f2543Smrg    Define the <function>CloseScreen()</function> function:
9313706f2543Smrg	</para>
9314706f2543Smrg
9315706f2543Smrg	<para>
9316706f2543Smrg    This function is mandatory.  Note that it unwraps the previously
9317706f2543Smrg    wrapped <structfield>pScreen-&gt;CloseScreen</structfield>, and finishes by
9318706f2543Smrg    calling it.
9319706f2543Smrg	</para>
9320706f2543Smrg
9321706f2543Smrg	<programlisting>
9322706f2543Smrgstatic Bool
9323706f2543SmrgZZZCloseScreen(int scrnIndex, ScreenPtr pScreen)
9324706f2543Smrg{
9325706f2543Smrg    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
9326706f2543Smrg    if (pScrn-&gt;vtSema) {
9327706f2543Smrg        ZZZRestore(pScrn);
9328706f2543Smrg        ZZZUnmapMem(pScrn);
9329706f2543Smrg    }
9330706f2543Smrg    pScrn-&gt;vtSema = FALSE;
9331706f2543Smrg    pScreen-&gt;CloseScreen = ZZZPTR(pScrn)-&gt;CloseScreen;
9332706f2543Smrg    return (*pScreen-&gt;CloseScreen)(scrnIndex, pScreen);
9333706f2543Smrg}
9334706f2543Smrg	</programlisting>
9335706f2543Smrg      </sect3>
9336706f2543Smrg
9337706f2543Smrg      <sect3>
9338706f2543Smrg	<title>SaveScreen</title>
9339706f2543Smrg
9340706f2543Smrg	<para>
9341706f2543Smrg    Define the <function>SaveScreen()</function> function (the screen
9342706f2543Smrg    blanking function).  When using the vgahw module, this will typically
9343706f2543Smrg    be:
9344706f2543Smrg
9345706f2543Smrg	  <programlisting>
9346706f2543Smrgstatic Bool
9347706f2543SmrgZZZSaveScreen(ScreenPtr pScreen, int mode)
9348706f2543Smrg{
9349706f2543Smrg    return vgaHWSaveScreen(pScreen, mode);
9350706f2543Smrg}
9351706f2543Smrg	  </programlisting>
9352706f2543Smrg	</para>
9353706f2543Smrg
9354706f2543Smrg	<para>
9355706f2543Smrg    This function is mandatory.  Before modifying any hardware register
9356706f2543Smrg    directly this function needs to make sure that the Xserver is active
9357706f2543Smrg    by checking if <parameter>pScrn</parameter> is non-NULL and for
9358706f2543Smrg    <literal remap="tt">pScrn-&gt;vtSema == TRUE</literal>.
9359706f2543Smrg	</para>
9360706f2543Smrg      </sect3>
9361706f2543Smrg
9362706f2543Smrg      <sect3>
9363706f2543Smrg	<title>FreeScreen</title>
9364706f2543Smrg
9365706f2543Smrg	<para>
9366706f2543Smrg    Define the <function>FreeScreen()</function> function.  This function
9367706f2543Smrg    is optional.  It should be defined if the <structname>ScrnInfoRec</structname>
9368706f2543Smrg    <structfield>driverPrivate</structfield> field is used so that it can be freed
9369706f2543Smrg    when a screen is deleted by the common layer for reasons possibly
9370706f2543Smrg    beyond the driver's control.  This function is not used in during
9371706f2543Smrg    normal (error free) operation.  The per-generation data is freed by
9372706f2543Smrg    the <function>CloseScreen()</function> function.
9373706f2543Smrg	</para>
9374706f2543Smrg
9375706f2543Smrg	<programlisting>
9376706f2543Smrgstatic void
9377706f2543SmrgZZZFreeScreen(int scrnIndex, int flags)
9378706f2543Smrg{
9379706f2543Smrg    /*
9380706f2543Smrg     * If the vgahw module is used vgaHWFreeHWRec() would be called
9381706f2543Smrg     * here.
9382706f2543Smrg     */
9383706f2543Smrg    ZZZFreeRec(xf86Screens[scrnIndex]);
9384706f2543Smrg}
9385706f2543Smrg
9386706f2543Smrg	</programlisting>
9387706f2543Smrg
9388706f2543Smrg      </sect3>
9389706f2543Smrg
9390706f2543Smrg    </sect2>
9391706f2543Smrg
9392706f2543Smrg  </sect1>
9393706f2543Smrg
9394706f2543Smrg</article>
9395