~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/doc/DESIGN

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
                   XFree86 X server ``New Design'' (DRAFT)
 
2
 
 
3
                          The XFree86 Project, Inc
 
4
 
 
5
                        Last modified 2003 January 22
 
6
 
 
7
NOTE: This is a DRAFT document, and the interfaces described here are subject
 
8
to change without notice.
 
9
 
 
10
1.  Preface
 
11
 
 
12
The broad design principles are:
 
13
 
 
14
   o keep it reasonable
 
15
 
 
16
        o We cannot rewrite the complete server
 
17
 
 
18
        o We don't want to re-invent the wheel
 
19
 
 
20
   o keep it modular
 
21
 
 
22
        o As many things as possible should go into modules
 
23
 
 
24
        o The basic loader binary should be minimal
 
25
 
 
26
        o A clean design with well defined layering is important
 
27
 
 
28
        o DDX specific global variables are a nono
 
29
 
 
30
        o The structure should be flexible enough to allow future extensions
 
31
 
 
32
        o  The structure should minimize duplication of common code
 
33
 
 
34
   o keep important features in mind
 
35
 
 
36
        o multiple screens, including multiple instances of drivers
 
37
 
 
38
        o mixing different color depths and visuals on different and ideally
 
39
          even on the same screen
 
40
 
 
41
        o better control of the PCI device used
 
42
 
 
43
        o better config file parser
 
44
 
 
45
        o get rid of all VGA compatibility assumptions
 
46
 
 
47
Unless we find major deficiencies in the DIX layer, we should avoid making
 
48
changes there.
 
49
 
 
50
2.  The XF86Config File
 
51
 
 
52
The XF86Config file format is similar to the old format, with the following
 
53
changes:
 
54
 
 
55
2.1  Device section
 
56
 
 
57
The Device sections are similar to what they used to be, and describe hard-
 
58
ware-specific information for a single video card.  Device Some new keywords
 
59
are added:
 
60
 
 
61
      Driver "drivername"
 
62
            Specifies the name of the driver to be used for the card.  This
 
63
            is mandatory.
 
64
 
 
65
      BusID "busslot"
 
66
            Specifies uniquely the location of the card on the bus.  The pur-
 
67
            pose is to identify particular cards in a multi-headed configura-
 
68
            tion.  The format of the argument is intentionally vague, and may
 
69
            be architecture dependent.  For a PCI bus, it is something like
 
70
            "bus:slot:func".
 
71
 
 
72
A Device section is considered ``active'' if there is a reference to it in an
 
73
active Screen section.
 
74
 
 
75
2.2  Screen section
 
76
 
 
77
The Screen sections are similar to what they used to be.  They no longer have
 
78
a Driver keyword, but an Identifier keyword is added.  (The Driver keyword
 
79
may be accepted in place of the Identifier keyword for compatibility pur-
 
80
poses.)  The identifier can be used to identify which screen is to be active
 
81
when multiple Screen sections are present.  It is possible to specify the
 
82
active screen from the command line.  A default is chosen in the absence of
 
83
one being specified.  A Screen section is considered ``active'' if there is a
 
84
reference to it either from the command line, or from an active ServerLayout
 
85
section.
 
86
 
 
87
2.3  InputDevice section
 
88
 
 
89
The InputDevice section is a new section that describes configuration infor-
 
90
mation for input devices.  It replaces the old Keyboard, Pointer and XInput
 
91
sections.  Like the Device section, it has two mandatory keywords: Identifier
 
92
and Driver.  For compatibility purposes the old Keyboard and Pointer sections
 
93
are converted by the parser into InputDevice sections as follows:
 
94
 
 
95
      Keyboard
 
96
            Identifier "Implicit Core Keyboard"
 
97
 
 
98
            Driver "keyboard"
 
99
 
 
100
      Pointer
 
101
            Identifier "Implicit Core Pointer"
 
102
 
 
103
            Driver "mouse"
 
104
 
 
105
An InputDevice section is considered active if there is a reference to it in
 
106
an active ServerLayout section.  An InputDevice section may also be refer-
 
107
enced implicitly if there is no ServerLayout section, if the -screen command
 
108
line options is used, or if the ServerLayout section doesn't reference any
 
109
InputDevice sections.  In this case, the first sections with drivers "key-
 
110
board" and "mouse" are used as the core keyboard and pointer respectively.
 
111
 
 
112
2.4  ServerLayout section
 
113
 
 
114
The ServerLayout section is a new section that is used to identify which
 
115
Screen sections are to be used in a multi-headed configuration, and the rela-
 
116
tive layout of those screens.  It also identifies which InputDevice sections
 
117
are to be used.  Each ServerLayout section has an identifier, a list of
 
118
Screen section identifiers, and a list of InputDevice section identifiers.
 
119
ServerFlags options may also be included in a ServerLayout section, making it
 
120
possible to override the global values in the ServerFlags section.
 
121
 
 
122
A ServerLayout section can be made active by being referenced on the command
 
123
line.  In the absence of this, a default will be chosen (the first one
 
124
found).  The screen names may optionally be followed by a number specifying
 
125
the preferred screen number, and optionally by information specifying the
 
126
physical positioning of the screen, either in absolute terms or relative to
 
127
another screen (or screens).  When no screen number is specified, they are
 
128
numbered according to the order in which they are listed.  The old (now obso-
 
129
lete) method of providing the positioning information is to give the names of
 
130
the four adjacent screens.  The order of these is top, bottom, left, right.
 
131
Here is an example of a ServerLayout section for two screens using the old
 
132
method, with the second located to the right of the first:
 
133
 
 
134
           Section "ServerLayout"
 
135
             Identifier "Main Layout"
 
136
             Screen     0 "Screen 1" ""  ""  ""  "Screen 2"
 
137
             Screen     1 "Screen 2"
 
138
             Screen     "Screen 3"
 
139
           EndSection
 
140
 
 
141
The preferred way of specifying the layout is to explicitly specify the
 
142
screen's location in absolute terms or relative to another screen.
 
143
 
 
144
In the absolute case, the upper left corner's coordinates are given after the
 
145
Absolute keyword.  If the coordinates are omitted, a value of (0,0) is
 
146
assumed.  An example of absolute positioning follows:
 
147
 
 
148
           Section "ServerLayout"
 
149
             Identifier "Main Layout"
 
150
             Screen     0 "Screen 1" Absolute 0 0
 
151
             Screen     1 "Screen 2" Absolute 1024 0
 
152
             Screen     "Screen 3" Absolute 2048 0
 
153
           EndSection
 
154
 
 
155
In the relative case, the position is specified by either using one of the
 
156
following keywords followed by the name of the reference screen:
 
157
 
 
158
     RightOf
 
159
 
 
160
     LeftOf
 
161
 
 
162
     Above
 
163
 
 
164
     Below
 
165
 
 
166
     Relative
 
167
 
 
168
When the Relative keyword is used, the reference screen name is followed by
 
169
the coordinates of the new screen's origin relative to reference screen.  The
 
170
following example shows how to use some of the relative positioning options.
 
171
 
 
172
           Section "ServerLayout"
 
173
             Identifier "Main Layout"
 
174
             Screen     0 "Screen 1"
 
175
             Screen     1 "Screen 2" RightOf "Screen 1"
 
176
             Screen     "Screen 3" Relative "Screen 1" 2048 0
 
177
           EndSection
 
178
 
 
179
2.5  Options
 
180
 
 
181
Options are used more extensively.  They may appear in most sections now.
 
182
Options related to drivers can be present in the Screen, Device and Monitor
 
183
sections and the Display subsections.  The order of precedence is Display,
 
184
Screen, Monitor, Device.  Options have been extended to allow an optional
 
185
value to be specified in addition to the option name.  For more details about
 
186
options, see the Options (section 10., page 1) section for details.
 
187
 
 
188
3.  Driver Interface
 
189
 
 
190
The driver interface consists of a minimal set of entry points that are
 
191
required based on the external events that the driver must react to.  No non-
 
192
essential structure is imposed on the way they are used beyond that.  This is
 
193
a significant difference compared with the old design.
 
194
 
 
195
The entry points for drawing operations are already taken care of by the
 
196
framebuffer code (including, XAA).  Extensions and enhancements to frame-
 
197
buffer code are outside the scope of this document.
 
198
 
 
199
This approach to the driver interface provides good flexibility, but does
 
200
increase the complexity of drivers.  To help address this, the XFree86 common
 
201
layer provides a set of ``helper'' functions to take care of things that most
 
202
drivers need.  These helpers help minimise the amount of code duplication
 
203
between drivers.  The use of helper functions by drivers is however optional,
 
204
though encouraged.  The basic philosophy behind the helper functions is that
 
205
they should be useful to many drivers, that they should balance this against
 
206
the complexity of their interface.  It is inevitable that some drivers may
 
207
find some helpers unsuitable and need to provide their own code.
 
208
 
 
209
Events that a driver needs to react to are:
 
210
 
 
211
      ScreenInit
 
212
            An initialisation function is called from the DIX layer for each
 
213
            screen at the start of each server generation.
 
214
 
 
215
      Enter VT
 
216
            The server takes control of the console.
 
217
 
 
218
      Leave VT
 
219
            The server releases control of the console.
 
220
 
 
221
      Mode Switch
 
222
            Change video mode.
 
223
 
 
224
      ViewPort change
 
225
            Change the origin of the physical view port.
 
226
 
 
227
      ScreenSaver state change
 
228
            Screen saver activation/deactivation.
 
229
 
 
230
      CloseScreen
 
231
            A close screen function is called from the DIX layer for each
 
232
            screen at the end of each server generation.
 
233
 
 
234
In addition to these events, the following functions are required by the
 
235
XFree86 common layer:
 
236
 
 
237
      Identify
 
238
            Print a driver identifying message.
 
239
 
 
240
      Probe
 
241
            This is how a driver identifies if there is any hardware present
 
242
            that it knows how to drive.
 
243
 
 
244
      PreInit
 
245
            Process information from the XF86Config file, determine the full
 
246
            characteristics of the hardware, and determine if a valid config-
 
247
            uration is present.
 
248
 
 
249
The VidMode extension also requires:
 
250
 
 
251
      ValidMode
 
252
            Identify if a new mode is usable with the current configuration.
 
253
            The PreInit function (and/or helpers it calls) may also make use
 
254
            of the ValidMode function or something similar.
 
255
 
 
256
Other extensions may require other entry points.  The drivers will inform the
 
257
common layer of these in such cases.
 
258
 
 
259
4.  Resource Access Control Introduction
 
260
 
 
261
Graphics devices are accessed through ranges in I/O or memory space.  While
 
262
most modern graphics devices allow relocation of such ranges many of them
 
263
still require the use of well established interfaces such as VGA memory and
 
264
IO ranges or 8514/A IO ranges.  With modern buses (like PCI) it is possible
 
265
for multiple video devices to share access to these resources.  The RAC
 
266
(Resource Access Control) subsystem provides a mechanism for this.
 
267
 
 
268
4.1  Terms and Definitions
 
269
 
 
270
4.1.1  Bus
 
271
 
 
272
``Bus'' is ambiguous as it is used for different things: it may refer to
 
273
physical incompatible extension connectors in a computer system.  The RAC
 
274
system knows two such systems: The ISA bus and the PCI bus.  (On the software
 
275
level EISA, MCA and VL buses are currently treated like ISA buses).  ``Bus''
 
276
may also refer to logically different entities on a single bus system which
 
277
are connected via bridges.  A PCI system may have several distinct PCI buses
 
278
connecting each other by PCI-PCI bridges or to the host CPU by HOST-PCI
 
279
bridges.
 
280
 
 
281
Systems that host more than one bus system link these together using bridges.
 
282
Bridges are a concern to RAC as they might block or pass specific resources.
 
283
PCI-PCI bridges may be set up to pass VGA resources to the secondary bus.
 
284
PCI-ISA buses pass any resources not decoded on the primary PCI bus to the
 
285
ISA bus.  This way VGA resources (although exclusive on the ISA bus) can be
 
286
shared by ISA and PCI cards.  Currently HOST-PCI bridges are not yet handled
 
287
by RAC as they require specific drivers.
 
288
 
 
289
4.1.2  Entity
 
290
 
 
291
The smallest independently addressable unit on a system bus is referred to as
 
292
an entity.  So far we know ISA and PCI entities.  PCI entities can be located
 
293
on the PCI bus by an unique ID consisting of the bus, card and function num-
 
294
ber.
 
295
 
 
296
4.1.3  Resource
 
297
 
 
298
``Resource'' refers to a range of memory or I/O addresses an entity can
 
299
decode.
 
300
 
 
301
If a device is capable of disabling this decoding the resource is called
 
302
sharable.  For PCI devices a generic method is provided to control resource
 
303
decoding.  Other devices will have to provide a device specific function to
 
304
control decoding.
 
305
 
 
306
If the entity is capable of decoding this range at a different location this
 
307
resource is considered relocatable.
 
308
 
 
309
Resources which start at a specific address and occupy a single continuous
 
310
range are called block resources.
 
311
 
 
312
Alternatively resource addresses can be decoded in a way that they satisfy
 
313
the conditions:
 
314
 
 
315
                              address & mask == base
 
316
 
 
317
and
 
318
 
 
319
                                 base & mask == base
 
320
 
 
321
Resources addressed in such a way are called sparse resources.
 
322
 
 
323
4.1.4  Server States
 
324
 
 
325
The resource access control system knows two server states: the SETUP and the
 
326
OPERATING state.  The SETUP state is entered whenever a mode change takes
 
327
place or the server exits or does VT switching.  During this state all entity
 
328
resources are under resource access control.  During OPERATING state only
 
329
those entities are controlled which actually have shared resources that con-
 
330
flict with others.
 
331
 
 
332
5.  Control Flow in the Server and Mandatory Driver Functions
 
333
 
 
334
At the start of each server generation, main() (dix/main.c) calls the DDX
 
335
function InitOutput().  This is the first place that the DDX gets control.
 
336
InitOutput() is expected to fill in the global screenInfo struct, and one
 
337
screenInfo.screen[] entry for each screen present.  Here is what InitOutput()
 
338
does:
 
339
 
 
340
5.1  Parse the XF86Config file
 
341
 
 
342
This is done at the start of the first server generation only.
 
343
 
 
344
The XF86Config file is read in full, and the resulting information stored in
 
345
data structures.  None of the parsed information is processed at this point.
 
346
The parser data structures are opaque to the video drivers and to most of the
 
347
common layer code.
 
348
 
 
349
The entire file is parsed first to remove any section ordering requirements.
 
350
 
 
351
5.2  Initial processing of parsed information and command line options
 
352
 
 
353
This is done at the start of the first server generation only.
 
354
 
 
355
The initial processing is to determine paths like the ModulePath, etc, and to
 
356
determine which ServerLayout, Screen and Device sections are active.
 
357
 
 
358
5.3  Enable port I/O access
 
359
 
 
360
Port I/O access is controlled from the XFree86 common layer, and is ``all or
 
361
nothing''.  It is enabled prior to calling driver probes, at the start of
 
362
subsequent server generations, and when VT switching back to the Xserver.  It
 
363
is disabled at the end of server generations, and when VT switching away from
 
364
the Xserver.
 
365
 
 
366
The implementation details of this may vary on different platforms.
 
367
 
 
368
5.4  General bus probe
 
369
 
 
370
This is done at the start of the first server generation only.
 
371
 
 
372
In the case of ix86 machines, this will be a general PCI probe.  The full
 
373
information obtained here will be available to the drivers.  This information
 
374
persists for the life of the Xserver.  In the PCI case, the PCI information
 
375
for all video cards found is available by calling xf86GetPciVideoInfo().
 
376
 
 
377
     pciVideoPtr *xf86GetPciVideoInfo(void)
 
378
 
 
379
          returns a pointer to a list of pointers to pciVideoRec
 
380
          entries, of which there is one for each detected PCI
 
381
          video card.  The list is terminated with a NULL pointer.
 
382
          If no PCI video cards were detected, the return value is
 
383
          NULL.
 
384
 
 
385
After the bus probe, the resource broker is initialised.
 
386
 
 
387
5.5  Load initial set of modules
 
388
 
 
389
This is done at the start of the first server generation only.
 
390
 
 
391
The core server contains a list of mandatory modules.  These are loaded
 
392
first.  Currently the only module on this list is the bitmap font module.
 
393
 
 
394
The next set of modules loaded are those specified explicitly in the Module
 
395
section of the config file.
 
396
 
 
397
The final set of initial modules are the driver modules referenced by the
 
398
active Device and InputDevice sections in the config file.  Each of these
 
399
modules is loaded exactly once.
 
400
 
 
401
5.6  Register Video and Input Drivers
 
402
 
 
403
This is done at the start of the first server generation only.
 
404
 
 
405
When a driver module is loaded, the loader calls its Setup function.  For
 
406
video drivers, this function calls xf86AddDriver() to register the driver's
 
407
DriverRec, which contains a small set of essential details and driver entry
 
408
points required during the early phase of InitOutput().  xf86AddDriver() adds
 
409
it to the global xf86DriverList[] array.
 
410
 
 
411
The DriverRec contains the driver canonical name, the Identify(), Probe() and
 
412
AvailableOptions() function entry points as well as a pointer to the driver's
 
413
module (as returned from the loader when the driver was loaded) and a refer-
 
414
ence count which keeps track of how many screens are using the driver.  The
 
415
entry driver entry points are those required prior to the driver allocating
 
416
and filling in its ScrnInfoRec.
 
417
 
 
418
For a static server, the xf86DriverList[] array is initialised at build time,
 
419
and the loading of modules is not done.
 
420
 
 
421
A similar procedure is used for input drivers.  The input driver's Setup
 
422
function calls xf86AddInputDriver() to register the driver's InputDriverRec,
 
423
which contains a small set of essential details and driver entry points
 
424
required during the early phase of InitInput().  xf86AddInputDriver() adds it
 
425
to the global xf86InputDriverList[] array.  For a static server, the
 
426
xf86InputDriverList[] array is initialised at build time.
 
427
 
 
428
Both the xf86DriverList[] and xf86InputDriverList[] arrays have been ini-
 
429
tialised by the end of this stage.
 
430
 
 
431
Once all the drivers are registered, their ChipIdentify() functions are
 
432
called.
 
433
 
 
434
     void ChipIdentify(int flags)
 
435
 
 
436
          This is expected to print a message indicating the driver
 
437
          name, a short summary of what it supports, and a list of
 
438
          the chipset names that it supports.  It may use the
 
439
          xf86PrintChipsets() helper to do this.
 
440
 
 
441
     void xf86PrintChipsets(const char *drvname, const char *drvmsg,
 
442
 
 
443
               SymTabPtr chips)
 
444
 
 
445
          This function provides an easy way for a driver's ChipI-
 
446
          dentify function to format the identification message.
 
447
 
 
448
5.7  Initialise Access Control
 
449
 
 
450
This is done at the start of the first server generation only.
 
451
 
 
452
The Resource Access Control (RAC) subsystem is initialised before calling any
 
453
driver functions that may access hardware.  All generic bus information is
 
454
probed and saved (for restoration later).  All (shared resource) video
 
455
devices are disabled at the generic bus level, and a probe is done to find
 
456
the ``primary'' video device.  These devices remain disabled for the next
 
457
step.
 
458
 
 
459
5.8  Video Driver Probe
 
460
 
 
461
This is done at the start of the first server generation only.  The Chip-
 
462
Probe() function of each registered video driver is called.
 
463
 
 
464
     Bool ChipProbe(DriverPtr drv, int flags)
 
465
 
 
466
          The purpose of this is to identify all instances of hard-
 
467
          ware supported by the driver.  The flags value is cur-
 
468
          rently either 0, PROBE_DEFAULT or PROBE_DETECT.
 
469
          PROBE_DETECT is used if "-configure" or "-probe" command
 
470
          line arguments are given and indicates to the Probe()
 
471
          function that it should not configure the bus entities
 
472
          and that no XF86Config information is available.
 
473
 
 
474
          The probe must find the active device sections that match
 
475
          the driver by calling xf86MatchDevice().  The number of
 
476
          matches found limits the maximum number of instances for
 
477
          this driver.  If no matches are found, the function
 
478
          should return FALSE immediately.
 
479
 
 
480
          Devices that cannot be identified by using device-inde-
 
481
          pendent methods should be probed at this stage (keeping
 
482
          in mind that access to all resources that can be disabled
 
483
          in a device-independent way are disabled during this
 
484
          phase).  The probe must be a minimal probe.  It should
 
485
          just determine if there is a card present that the driver
 
486
          can drive.  It should use the least intrusive probe meth-
 
487
          ods possible.  It must not do anything that is not essen-
 
488
          tial, like probing for other details such as the amount
 
489
          of memory installed, etc.  It is recommended that the
 
490
          xf86MatchPciInstances() helper function be used for iden-
 
491
          tifying matching PCI devices, and similarly the
 
492
          xf86MatchIsaInstances() for ISA (non-PCI) devices (see
 
493
          the RAC (section 9., page 1) section).  These helpers
 
494
          also checks and claims the appropriate entity.  When not
 
495
          using the helper, that should be done with xf86CheckPciS-
 
496
          lot() and xf86ClaimPciSlot() for PCI devices and
 
497
          xf86ClaimIsaSlot() for ISA devices (see the RAC (section
 
498
          9., page 1) section).
 
499
 
 
500
          The probe must register all non-relocatable resources at
 
501
          this stage.  If a resource conflict is found between
 
502
          exclusive resources the driver will fail immediately.
 
503
          This is usually best done with the xf86ConfigPciEntity()
 
504
          helper function for PCI and xf86ConfigIsaEntity() for ISA
 
505
          (see the RAC (section 9., page 1) section).  It is possi-
 
506
          ble to register some entity specific functions with those
 
507
          helpers.  When not using the helpers, the xf86AddEntity-
 
508
          ToScreen() xf86ClaimFixedResources() and xf86SetEntity-
 
509
          Funcs() should be used instead (see the RAC (section 9.,
 
510
          page 1) section).
 
511
 
 
512
          If a chipset is specified in an active device section
 
513
          which the driver considers relevant (ie it has no driver
 
514
          specified, or the driver specified matches the driver
 
515
          doing the probe), the Probe must return FALSE if the
 
516
          chipset doesn't match one supported by the driver.
 
517
 
 
518
          If there are no active device sections that the driver
 
519
          considers relevant, it must return FALSE.
 
520
 
 
521
          Allocate a ScrnInfoRec for each active instance of the
 
522
          hardware found, and fill in the basic information,
 
523
          including the other driver entry points.   This is best
 
524
          done with the xf86ConfigIsaEntity() helper function for
 
525
          ISA instances or xf86ConfigPciEntity() for PCI instances.
 
526
          These functions allocate a ScrnInfoRec for active enti-
 
527
          ties. Optionally xf86AllocateScreen() function may also
 
528
          be used to allocate the ScrnInfoRec.  Any of these func-
 
529
          tions take care of initialising fields to defined
 
530
          ``unused'' values.
 
531
 
 
532
          Claim the entities for each instance of the hardware
 
533
          found.  This prevents other drivers from claiming the
 
534
          same hardware.
 
535
 
 
536
          Must leave hardware in the same state it found it in, and
 
537
          must not do any hardware initialisation.
 
538
 
 
539
          All detection can be overridden via the config file, and
 
540
          that parsed information is available to the driver at
 
541
          this stage.
 
542
 
 
543
          Returns TRUE if one or more instances are found, and
 
544
          FALSE otherwise.
 
545
 
 
546
     int xf86MatchDevice(const char *drivername,
 
547
 
 
548
               GDevPtr **driversectlist)
 
549
 
 
550
          This function takes the name of the driver and returns
 
551
          via driversectlist a list of device sections that match
 
552
          the driver name.  The function return value is the number
 
553
          of matches found.  If a fatal error is encountered the
 
554
          return value is -1.
 
555
 
 
556
          The caller should use xfree() to free *driversectlist
 
557
          when it is no longer needed.
 
558
 
 
559
     ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags)
 
560
 
 
561
          This function allocates a new ScrnInfoRec in the
 
562
          xf86Screens[] array.  This function is normally called by
 
563
          the video driver ChipProbe() functions.  The return value
 
564
          is a pointer to the newly allocated ScrnInfoRec.  The
 
565
          scrnIndex, origIndex, module and drv fields are ini-
 
566
          tialised.  The reference count in drv is incremented.
 
567
          The storage for any currently allocated ``privates''
 
568
          pointers is also allocated and the privates field ini-
 
569
          tialised (the privates data is of course not allocated or
 
570
          initialised).  This function never returns on failure.
 
571
          If the allocation fails, the server exits with a fatal
 
572
          error.  The flags value is not currently used, and should
 
573
          be set to zero.
 
574
 
 
575
At the completion of this, a list of ScrnInfoRecs have been allocated in the
 
576
xf86Screens[] array, and the associated entities and fixed resources have
 
577
been claimed.  The following ScrnInfoRec fields must be initialised at this
 
578
point:
 
579
 
 
580
                    driverVersion
 
581
                    driverName
 
582
                    scrnIndex(*)
 
583
                    origIndex(*)
 
584
                    drv(*)
 
585
                    module(*)
 
586
                    name
 
587
                    Probe
 
588
                    PreInit
 
589
                    ScreenInit
 
590
                    EnterVT
 
591
                    LeaveVT
 
592
                    numEntities
 
593
                    entityList
 
594
                    access
 
595
 
 
596
(*) These are initialised when the ScrnInfoRec is allocated, and not explic-
 
597
itly by the driver.
 
598
 
 
599
The following ScrnInfoRec fields must be initialised if the driver is going
 
600
to use them:
 
601
 
 
602
                    SwitchMode
 
603
                    AdjustFrame
 
604
                    FreeScreen
 
605
                    ValidMode
 
606
 
 
607
5.9  Matching Screens
 
608
 
 
609
This is done at the start of the first server generation only.
 
610
 
 
611
After the Probe phase is finished, there will be some number of ScrnInfoRecs.
 
612
These are then matched with the active Screen sections in the XF86Config, and
 
613
those not having an active Screen section are deleted.  If the number of
 
614
remaining screens is 0, InitOutput() sets screenInfo.numScreens to 0 and
 
615
returns.
 
616
 
 
617
At this point the following fields of the ScrnInfoRecs must be initialised:
 
618
 
 
619
                    confScreen
 
620
 
 
621
5.10  Allocate non-conflicting resources
 
622
 
 
623
This is done at the start of the first server generation only.
 
624
 
 
625
Before calling the drivers again, the resource information collected from the
 
626
Probe phase is processed.  This includes checking the extent of PCI resources
 
627
for the probed devices, and resolving any conflicts in the relocatable PCI
 
628
resources.  It also reports conflicts, checks bus routing issues, and any-
 
629
thing else that is needed to enable the entities for the next phase.
 
630
 
 
631
If any drivers registered an EntityInit() function during the Probe phase,
 
632
then they are called here.
 
633
 
 
634
5.11  Sort the Screens and pre-check Monitor Information
 
635
 
 
636
This is done at the start of the first server generation only.
 
637
 
 
638
The list of screens is sorted to match the ordering requested in the config
 
639
file.
 
640
 
 
641
The list of modes for each active monitor is checked against the monitor's
 
642
parameters.  Invalid modes are pruned.
 
643
 
 
644
5.12  PreInit
 
645
 
 
646
This is done at the start of the first server generation only.
 
647
 
 
648
For each ScrnInfoRec, enable access to the screens entities and call the
 
649
ChipPreInit() function.
 
650
 
 
651
     Bool ChipPreInit(ScrnInfoRec screen, int flags)
 
652
 
 
653
          The purpose of this function is to find out all the
 
654
          information required to determine if the configuration is
 
655
          usable, and to initialise those parts of the ScrnInfoRec
 
656
          that can be set once at the beginning of the first server
 
657
          generation.
 
658
 
 
659
          The number of entities registered for the screen should
 
660
          be checked against the expected number (most drivers
 
661
          expect only one).  The entity information for each of
 
662
          them should be retrieved (with xf86GetEntityInfo()) and
 
663
          checked for the correct bus type and that none of the
 
664
          sharable resources registered during the Probe phase was
 
665
          rejected.
 
666
 
 
667
          Access to resources for the entities that can be con-
 
668
          trolled in a device-independent way are enabled before
 
669
          this function is called.  If the driver needs to access
 
670
          any resources that it has disabled in an EntityInit()
 
671
          function that it registered, then it may enable them here
 
672
          providing that it disables them before this function
 
673
          returns.
 
674
 
 
675
          This includes probing for video memory, clocks, ramdac,
 
676
          and all other HW info that is needed.  It includes deter-
 
677
          mining the depth/bpp/visual and related info.  It
 
678
          includes validating and determining the set of video
 
679
          modes that will be used (and anything that is required to
 
680
          determine that).
 
681
 
 
682
          This information should be determined in the least intru-
 
683
          sive way possible.  The state of the HW must remain
 
684
          unchanged by this function.  Although video memory
 
685
          (including MMIO) may be mapped within this function, it
 
686
          must be unmapped before returning.  Driver specific
 
687
          information should be stored in a structure hooked into
 
688
          the ScrnInfoRec's driverPrivate field.  Any other modules
 
689
          which require persistent data (ie data that persists
 
690
          across server generations) should be initialised in this
 
691
          function, and they should allocate a ``privates'' index
 
692
          to hook their data into by calling xf86AllocateScrnInfo-
 
693
          PrivateIndex().  The ``privates'' data is persistent.
 
694
 
 
695
          Helper functions for some of these things are provided at
 
696
          the XFree86 common level, and the driver can choose to
 
697
          make use of them.
 
698
 
 
699
          All additional resources that the screen needs must be
 
700
          registered here.  This should be done with xf86Register-
 
701
          Resources().  If some of the fixed resources registered
 
702
          in the Probe phase are not needed or not decoded by the
 
703
          hardware when in the OPERATING server state, their status
 
704
          should be updated with xf86SetOperatingState().
 
705
 
 
706
          Modules may be loaded at any point in this function, and
 
707
          all modules that the driver will need must be loaded
 
708
          before the end of this function.  Either the
 
709
          xf86LoadSubModule() or the xf86LoadDrvSubModule() func-
 
710
          tion should be used to load modules depending on whether
 
711
          a ScrnInfoRec has been set up. A driver may unload a mod-
 
712
          ule within this function if it was only needed temporar-
 
713
          ily, and the xf86UnloadSubModule() function should be
 
714
          used to do that.  Otherwise there is no need to explic-
 
715
          itly unload modules because the loader takes care of mod-
 
716
          ule dependencies and will unload submodules automatically
 
717
          if/when the driver module is unloaded.
 
718
 
 
719
          The bulk of the ScrnInfoRec fields should be filled out
 
720
          in this function.
 
721
 
 
722
          ChipPreInit() returns FALSE when the configuration is
 
723
          unusable in some way (unsupported depth, no valid modes,
 
724
          not enough video memory, etc), and TRUE if it is usable.
 
725
 
 
726
          It is expected that if the ChipPreInit() function returns
 
727
          TRUE, then the only reasons that subsequent stages in the
 
728
          driver might fail are lack or resources (like xalloc
 
729
          failures).  All other possible reasons for failure should
 
730
          be determined by the ChipPreInit() function.
 
731
 
 
732
The ScrnInfoRecs for screens where the ChipPreInit() fails are removed.  If
 
733
none remain, InitOutput() sets screenInfo.numScreens to 0 and returns.
 
734
 
 
735
At this point, further fields of the ScrnInfoRecs would normally be filled
 
736
in.  Most are not strictly mandatory, but many are required by other layers
 
737
and/or helper functions that the driver may choose to use.  The documentation
 
738
for those layers and helper functions indicates which they require.
 
739
 
 
740
The following fields of the ScrnInfoRecs should be filled in if the driver is
 
741
going to use them:
 
742
 
 
743
                    monitor
 
744
                    display
 
745
                    depth
 
746
                    pixmapBPP
 
747
                    bitsPerPixel
 
748
                    weight                (>8bpp only)
 
749
                    mask                  (>8bpp only)
 
750
                    offset                (>8bpp only)
 
751
                    rgbBits               (8bpp only)
 
752
                    gamma
 
753
                    defaultVisual
 
754
                    maxHValue
 
755
                    maxVValue
 
756
                    virtualX
 
757
                    virtualY
 
758
                    displayWidth
 
759
                    frameX0
 
760
                    frameY0
 
761
                    frameX1
 
762
                    frameY1
 
763
                    zoomLocked
 
764
                    modePool
 
765
                    modes
 
766
                    currentMode
 
767
                    progClock             (TRUE if clock is programmable)
 
768
                    chipset
 
769
                    ramdac
 
770
                    clockchip
 
771
                    numClocks             (if not programmable)
 
772
                    clock[]               (if not programmable)
 
773
                    videoRam
 
774
                    biosBase
 
775
                    memBase
 
776
                    memClk
 
777
                    driverPrivate
 
778
                    chipID
 
779
                    chipRev
 
780
 
 
781
     pointer xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name): and
 
782
     pointer xf86LoadDrvSubModule(DriverPtr drv, const char *name):
 
783
 
 
784
          Load a module that a driver depends on.  This function
 
785
          loads the module name as a sub module of the driver.  The
 
786
          return value is a handle identifying the new module.  If
 
787
          the load fails, the return value will be NULL.  If a
 
788
          driver needs to explicitly unload a module it has loaded
 
789
          in this way, the return value must be saved and passed to
 
790
          xf86UnloadSubModule() when unloading.
 
791
 
 
792
     void xf86UnloadSubModule(pointer module)
 
793
 
 
794
          Unloads the module referenced by module.  module should
 
795
          be a pointer returned previously by xf86LoadSubModule()
 
796
          or xf86LoadDrvSubModule() .
 
797
 
 
798
5.13  Cleaning up Unused Drivers
 
799
 
 
800
At this point it is known which screens will be in use, and which drivers are
 
801
being used.  Unreferenced drivers (and modules they may have loaded) are
 
802
unloaded here.
 
803
 
 
804
5.14  Consistency Checks
 
805
 
 
806
The parameters that must be global to the server, like pixmap formats, bitmap
 
807
bit order, bitmap scanline unit and image byte order are compared for each of
 
808
the screens.  If a mismatch is found, the server exits with an appropriate
 
809
message.
 
810
 
 
811
5.15  Check if Resource Control is Needed
 
812
 
 
813
Determine if resource access control is needed.  This is the case if more
 
814
than one screen is used.  If necessary the RAC wrapper module is loaded.
 
815
 
 
816
5.16  AddScreen (ScreenInit)
 
817
 
 
818
At this point, the valid screens are known.  AddScreen() is called for each
 
819
of them, passing ChipScreenInit() as the argument.  AddScreen() is a DIX
 
820
function that allocates a new screenInfo.screen[] entry (aka pScreen), and
 
821
does some basic initialisation of it.  It then calls the ChipScreenInit()
 
822
function, with pScreen as one of its arguments.  If ChipScreenInit() returns
 
823
FALSE, AddScreen() returns -1.  Otherwise it returns the index of the screen.
 
824
AddScreen() should only fail because of programming errors or failure to
 
825
allocate resources (like memory).  All configuration problems should be
 
826
detected BEFORE this point.
 
827
 
 
828
     Bool ChipScreenInit(int index, ScreenPtr pScreen,
 
829
 
 
830
               int argc, char **argv)
 
831
 
 
832
          This is called at the start of each server generation.
 
833
 
 
834
          Fill in all of pScreen, possibly doing some of this by
 
835
          calling ScreenInit functions from other layers like mi,
 
836
          framebuffers (cfb, etc), and extensions.
 
837
 
 
838
          Decide which operations need to be placed under resource
 
839
          access control.  The classes of operations are the frame
 
840
          buffer operations (RAC_FB), the pointer operations
 
841
          (RAC_CURSOR), the viewport change operations (RAC_VIEW-
 
842
          PORT) and the colormap operations (RAC_COLORMAP).  Any
 
843
          operation that requires resources which might be disabled
 
844
          during OPERATING state should be set to use RAC.  This
 
845
          can be specified separately for memory and IO resources
 
846
          (the racMemFlags and racIoFlags fields of the ScrnInfoRec
 
847
          respectively).
 
848
 
 
849
          Map any video memory or other memory regions.
 
850
 
 
851
          Save the video card state.  Enough state must be saved so
 
852
          that the original state can later be restored.
 
853
 
 
854
          Initialise the initial video mode.  The ScrnInfoRec's
 
855
          vtSema field should be set to TRUE just prior to changing
 
856
          the video hardware's state.
 
857
 
 
858
The ChipScreenInit() function (or functions from other layers that it calls)
 
859
should allocate entries in the ScreenRec's devPrivates area by calling Allo-
 
860
cateScreenPrivateIndex() if it needs per-generation storage.  Since the
 
861
ScreenRec's devPrivates information is cleared for each server generation,
 
862
this is the correct place to initialise it.
 
863
 
 
864
After AddScreen() has successfully returned, the following ScrnInfoRec fields
 
865
are initialised:
 
866
 
 
867
                    pScreen
 
868
                    racMemFlags
 
869
                    racIoFlags
 
870
 
 
871
The ChipScreenInit() function should initialise the CloseScreen and Save-
 
872
Screen fields of pScreen.  The old value of pScreen->CloseScreen should be
 
873
saved as part of the driver's per-screen private data, allowing it to be
 
874
called from ChipCloseScreen().  This means that the existing CloseScreen()
 
875
function is wrapped.
 
876
 
 
877
5.17  Finalising RAC Initialisation
 
878
 
 
879
After all the ChipScreenInit() functions have been called, each screen has
 
880
registered its RAC requirements.  This information is used to determine which
 
881
shared resources are requested by more than one driver and set the access
 
882
functions accordingly.  This is done following these rules:
 
883
 
 
884
  1.  The sharable resources registered by each entity are compared.  If a
 
885
      resource is registered by more than one entity the entity will be
 
886
      marked to indicate that it needs to share this resources type (IO or
 
887
      MEM).
 
888
 
 
889
  2.  A resource marked ``disabled'' during OPERATING state will be ignored
 
890
      entirely.
 
891
 
 
892
  3.  A resource marked ``unused'' will only conflict with an overlapping
 
893
      resource of an other entity if the second is actually in use during
 
894
      OPERATING state.
 
895
 
 
896
  4.  If an ``unused'' resource was found to conflict but the entity does not
 
897
      use any other resource of this type the entire resource type will be
 
898
      disabled for that entity.
 
899
 
 
900
5.18  Finishing InitOutput()
 
901
 
 
902
At this point InitOutput() is finished, and all the screens have been setup
 
903
in their initial video mode.
 
904
 
 
905
5.19  Mode Switching
 
906
 
 
907
When a SwitchMode event is received, ChipSwitchMode() is called (when it
 
908
exists):
 
909
 
 
910
     Bool ChipSwitchMode(int index, DisplayModePtr mode, int flags)
 
911
 
 
912
          Initialises the new mode for the screen identified by
 
913
          index;.  The viewport may need to be adjusted also.
 
914
 
 
915
5.20  Changing Viewport
 
916
 
 
917
When a Change Viewport event is received, ChipAdjustFrame() is called (when
 
918
it exists):
 
919
 
 
920
     void ChipAdjustFrame(int index, int x, int y, int flags)
 
921
 
 
922
          Changes the viewport for the screen identified by index;.
 
923
 
 
924
          It should be noted that many chipsets impose restrictions
 
925
          on where the viewport may be placed in the virtual reso-
 
926
          lution, either for alignment reasons, or to prevent the
 
927
          start of the viewport from being positioned within a
 
928
          pixel (as can happen in a 24bpp mode).  After calculating
 
929
          the value the chipset's panning registers need to be set
 
930
          to for non-DGA modes, this function should recalculate
 
931
          the ScrnInfoRec's frameX0, frameY0, frameX1 and frameY1
 
932
          fields to correspond to that value.  If this is not done,
 
933
          switching to another mode might cause the position of a
 
934
          hardware cursor to change.
 
935
 
 
936
5.21  VT Switching
 
937
 
 
938
When a VT switch event is received, xf86VTSwitch() is called.  xf86VTSwitch()
 
939
does the following:
 
940
 
 
941
      On ENTER:
 
942
 
 
943
               o enable port I/O access
 
944
 
 
945
               o save and initialise the bus/resource state
 
946
 
 
947
               o enter the SETUP server state
 
948
 
 
949
               o calls ChipEnterVT() for each screen
 
950
 
 
951
               o enter the OPERATING server state
 
952
 
 
953
               o validate GCs
 
954
 
 
955
               o Restore fb from saved pixmap for each screen
 
956
 
 
957
               o Enable all input devices
 
958
 
 
959
      On LEAVE:
 
960
 
 
961
               o Save fb to pixmap for each screen
 
962
 
 
963
               o validate GCs
 
964
 
 
965
               o enter the SETUP server state
 
966
 
 
967
               o calls ChipLeaveVT() for each screen
 
968
 
 
969
               o disable all input devices
 
970
 
 
971
               o restore bus/resource state
 
972
 
 
973
               o disables port I/O access
 
974
 
 
975
     Bool ChipEnterVT(int index, int flags)
 
976
 
 
977
          This function should initialise the current video mode
 
978
          and initialise the viewport, turn on the HW cursor if
 
979
          appropriate, etc.
 
980
 
 
981
          Should it re-save the video state before initialising the
 
982
          video mode?
 
983
 
 
984
     void ChipLeaveVT(int index, int flags)
 
985
 
 
986
          This function should restore the saved video state.  If
 
987
          appropriate it should also turn off the HW cursor, and
 
988
          invalidate any pixmap/font caches.
 
989
 
 
990
     Optionally, ChipLeaveVT() may also unmap memory regions.  If so,
 
991
     ChipEnterVT() will need to remap them.  Additionally, if an aper-
 
992
     ture used to access video memory is unmapped and remapped in this
 
993
     fashion, ChipEnterVT() will also need to notify the framebuffer
 
994
     layers of the aperture's new location in virtual memory.  This is
 
995
     done with a call to the screen's ModifyPixmapHeader() function, as
 
996
     follows
 
997
 
 
998
          (*pScreen->ModifyPixmapHeader)(pScrn->ppix,
 
999
 
 
1000
                    -1, -1, -1, -1, -1, NewApertureAddress);
 
1001
 
 
1002
               where the ``ppix'' field in a ScrnInfoRec
 
1003
               points to the pixmap used by the screen's
 
1004
               SaveRestoreImage() function to hold the
 
1005
               screen's contents while switched out.
 
1006
 
 
1007
     Currently, aperture remapping, as described here, should not be
 
1008
     attempted if the driver uses the xf8_16bpp or xf8_32bpp framebuffer
 
1009
     layers.  A pending restructuring of VT switching will address this
 
1010
     restriction in the near future.
 
1011
 
 
1012
Other layers may wrap the ChipEnterVT() and ChipLeaveVT() functions if they
 
1013
need to take some action when these events are received.
 
1014
 
 
1015
5.22  End of server generation
 
1016
 
 
1017
At the end of each server generation, the DIX layer calls ChipCloseScreen()
 
1018
for each screen:
 
1019
 
 
1020
     Bool ChipCloseScreen(int index, ScreenPtr pScreen)
 
1021
 
 
1022
          This function should restore the saved video state and
 
1023
          unmap the memory regions.
 
1024
 
 
1025
          It should also free per-screen data structures allocated
 
1026
          by the driver.  Note that the persistent data held in the
 
1027
          ScrnInfoRec's driverPrivate field should not be freed
 
1028
          here because it is needed by subsequent server genera-
 
1029
          tions.
 
1030
 
 
1031
          The ScrnInfoRec's vtSema field should be set to FALSE
 
1032
          once the video HW state has been restored.
 
1033
 
 
1034
          Before freeing the per-screen driver data the saved Clos-
 
1035
          eScreen value should be restored to pScreen->CloseScreen,
 
1036
          and that function should be called after freeing the
 
1037
          data.
 
1038
 
 
1039
6.  Optional Driver Functions
 
1040
 
 
1041
The functions outlined here can be called from the XFree86 common layer, but
 
1042
their presence is optional.
 
1043
 
 
1044
6.1  Mode Validation
 
1045
 
 
1046
When a mode validation helper supplied by the XFree86-common layer is being
 
1047
used, it can be useful to provide a function to check for hw specific mode
 
1048
constraints:
 
1049
 
 
1050
     ModeStatus ChipValidMode(int index, DisplayModePtr mode,
 
1051
 
 
1052
               Bool verbose, int flags)
 
1053
 
 
1054
          Check the passed mode for hw-specific constraints, and
 
1055
          return the appropriate status value.
 
1056
 
 
1057
This function may also modify the effective timings and clock of the passed
 
1058
mode.  These have been stored in the mode's Crtc* and SynthClock elements,
 
1059
and have already been adjusted for interlacing, doublescanning, multiscanning
 
1060
and clock multipliers and dividers.  The function should not modify any other
 
1061
mode field, unless it wants to modify the mode timings reported to the user
 
1062
by xf86PrintModes().
 
1063
 
 
1064
The function is called once for every mode in the XF86Config Monitor section
 
1065
assigned to the screen, with flags set to MODECHECK_INITIAL.  It is subse-
 
1066
quently called for every mode in the XF86Config Display subsection assigned
 
1067
to the screen, with flags set to MODECHECK_FINAL.  In the second case, the
 
1068
mode will have successfully passed all other tests.  In addition, the ScrnIn-
 
1069
foRec's virtualX, virtualY and displayWidth fields will have been set as if
 
1070
the mode to be validated were to be the last mode accepted.
 
1071
 
 
1072
In effect, calls with MODECHECK_INITIAL are intended for checks that do not
 
1073
depend on any mode other than the one being validated, while calls with MOD-
 
1074
ECHECK_FINAL are intended for checks that may involve more than one mode.
 
1075
 
 
1076
6.2  Free screen data
 
1077
 
 
1078
When a screen is deleted prior to the completion of the ScreenInit phase the
 
1079
ChipFreeScreen() function is called when defined.
 
1080
 
 
1081
     void ChipFreeScreen(int scrnindex, int flags)
 
1082
 
 
1083
          Free any driver-allocated data that may have been allo-
 
1084
          cated up to and including an unsuccessful Chip-
 
1085
          ScreenInit() call.  This would predominantly be data
 
1086
          allocated by ChipPreInit() that persists across server
 
1087
          generations.  It would include the driverPrivate, and any
 
1088
          ``privates'' entries that modules may have allocated.
 
1089
 
 
1090
7.  Recommended driver functions
 
1091
 
 
1092
The functions outlined here are for internal use by the driver only.  They
 
1093
are entirely optional, and are never accessed directly from higher layers.
 
1094
The sample function declarations shown here are just examples.  The interface
 
1095
(if any) used is up to the driver.
 
1096
 
 
1097
7.1  Save
 
1098
 
 
1099
Save the video state.  This could be called from ChipScreenInit() and (possi-
 
1100
bly) ChipEnterVT().
 
1101
 
 
1102
     void ChipSave(ScrnInfoPtr pScrn)
 
1103
 
 
1104
          Saves the current state.  This will only be saving pre-
 
1105
          server states or states before returning to the server.
 
1106
          There is only one current saved state per screen and it
 
1107
          is stored in private storage in the screen.
 
1108
 
 
1109
7.2  Restore
 
1110
 
 
1111
Restore the original video state.  This could be called from the
 
1112
ChipLeaveVT() and ChipCloseScreen() functions.
 
1113
 
 
1114
     void ChipRestore(ScrnInfoPtr pScrn)
 
1115
 
 
1116
          Restores the saved state from the private storage.  Usu-
 
1117
          ally only used for restoring text modes.
 
1118
 
 
1119
7.3  Initialise Mode
 
1120
 
 
1121
Initialise a video mode.  This could be called from the ChipScreenInit(),
 
1122
ChipSwitchMode() and ChipEnterVT() functions.
 
1123
 
 
1124
     Bool ChipModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
 
1125
 
 
1126
          Programs the hardware for the given video mode.
 
1127
 
 
1128
8.  Data and Data Structures
 
1129
 
 
1130
8.1  Command line data
 
1131
 
 
1132
Command line options are typically global, and are stored in global vari-
 
1133
ables.  These variables are read-only and are available to drivers via a
 
1134
function call interface.  Most of these command line values are processed via
 
1135
helper functions to ensure that they are treated consistently by all drivers.
 
1136
The other means of access is provided for cases where the supplied helper
 
1137
functions might not be appropriate.
 
1138
 
 
1139
Some of them are:
 
1140
 
 
1141
              xf86Verbose               verbosity level
 
1142
              xf86Bpp                   -bpp from the command line
 
1143
              xf86Depth                 -depth from the command line
 
1144
              xf86Weight                -weight from the command line
 
1145
              xf86Gamma                 -{r,g,b,}gamma from the command line
 
1146
              xf86FlipPixels            -flippixels from the command line
 
1147
              xf86ProbeOnly             -probeonly from the command line
 
1148
              defaultColorVisualClass   -cc from the command line
 
1149
 
 
1150
If we ever do allow for screen-specific command line options, we may need to
 
1151
rethink this.
 
1152
 
 
1153
These can be accessed in a read-only manner by drivers with the following
 
1154
functions:
 
1155
 
 
1156
     int xf86GetVerbosity()
 
1157
 
 
1158
          Returns the value of xf86Verbose.
 
1159
 
 
1160
     int xf86GetDepth()
 
1161
 
 
1162
          Returns the -depth command line setting.  If not set on
 
1163
          the command line, -1 is returned.
 
1164
 
 
1165
     rgb xf86GetWeight()
 
1166
 
 
1167
          Returns the -weight command line setting.  If not set on
 
1168
          the command line, {0, 0, 0} is returned.
 
1169
 
 
1170
     Gamma xf86GetGamma()
 
1171
 
 
1172
          Returns the -gamma or -rgamma, -ggamma, -bgamma command
 
1173
          line settings.  If not set on the command line, {0.0,
 
1174
          0.0, 0.0} is returned.
 
1175
 
 
1176
     Bool xf86GetFlipPixels()
 
1177
 
 
1178
          Returns TRUE if -flippixels is present on the command
 
1179
          line, and FALSE otherwise.
 
1180
 
 
1181
     const char *xf86GetServerName()
 
1182
 
 
1183
          Returns the name of the X server from the command line.
 
1184
 
 
1185
8.2  Data handling
 
1186
 
 
1187
Config file data contains parts that are global, and parts that are Screen
 
1188
specific.  All of it is parsed into data structures that neither the drivers
 
1189
or most other parts of the server need to know about.
 
1190
 
 
1191
The global data is typically not required by drivers, and as such, most of it
 
1192
is stored in the private xf86InfoRec.
 
1193
 
 
1194
The screen-specific data collected from the config file is stored in screen,
 
1195
device, display, monitor-specific data structures that are separate from the
 
1196
ScrnInfoRecs, with the appropriate elements/fields hooked into the ScrnIn-
 
1197
foRecs as required.  The screen config data is held in confScreenRec, device
 
1198
data in the GDevRec, monitor data in the MonRec, and display data in the Dis-
 
1199
pRec.
 
1200
 
 
1201
The XFree86 common layer's screen specific data (the actual data in use for
 
1202
each screen) is held in the ScrnInfoRecs.  As has been outlined above, the
 
1203
ScrnInfoRecs are allocated at probe time, and it is the responsibility of the
 
1204
Drivers' Probe() and PreInit() functions to finish filling them in based on
 
1205
both data provided on the command line and data provided from the Config
 
1206
file.  The precedence for this is:
 
1207
 
 
1208
     command line  ->  config file  ->  probed/default data
 
1209
 
 
1210
For most things in this category there are helper functions that the drivers
 
1211
can use to ensure that the above precedence is consistently used.
 
1212
 
 
1213
As well as containing screen-specific data that the XFree86 common layer
 
1214
(including essential parts of the server infrastructure as well as helper
 
1215
functions) needs to access, it also contains some data that drivers use
 
1216
internally.  When considering whether to add a new field to the ScrnInfoRec,
 
1217
consider the balance between the convenience of things that lots of drivers
 
1218
need and the size/obscurity of the ScrnInfoRec.
 
1219
 
 
1220
Per-screen driver specific data that cannot be accommodated with the static
 
1221
ScrnInfoRec fields is held in a driver-defined data structure, a pointer to
 
1222
which is assigned to the ScrnInfoRec's driverPrivate field.  This is per-
 
1223
screen data that persists across server generations (as does the bulk of the
 
1224
static ScrnInfoRec data).  It would typically also include the video card's
 
1225
saved state.
 
1226
 
 
1227
Per-screen data for other modules that the driver uses (for example, the XAA
 
1228
module) that is reset for each server generation is hooked into the ScrnIn-
 
1229
foRec through it's privates field.
 
1230
 
 
1231
Once it has stabilised, the data structures and variables accessible to video
 
1232
drivers will be documented here.  In the meantime, those things defined in
 
1233
the xf86.h and xf86str.h files are visible to video drivers.  Things defined
 
1234
in xf86Priv.h and xf86Privstr.h are NOT intended to be visible to video
 
1235
drivers, and it is an error for a driver to include those files.
 
1236
 
 
1237
8.3  Accessing global data
 
1238
 
 
1239
Some other global state information that the drivers may access via functions
 
1240
is as follows:
 
1241
 
 
1242
     Bool xf86ServerIsExiting()
 
1243
 
 
1244
          Returns TRUE if the server is at the end of a generation
 
1245
          and is in the process of exiting, and FALSE otherwise.
 
1246
 
 
1247
     Bool xf86ServerIsResetting()
 
1248
 
 
1249
          Returns TRUE if the server is at the end of a generation
 
1250
          and is in the process of resetting, and FALSE otherwise.
 
1251
 
 
1252
     Bool xf86ServerIsInitialising()
 
1253
 
 
1254
          Returns TRUE if the server is at the beginning of a gen-
 
1255
          eration and is in the process of initialising, and FALSE
 
1256
          otherwise.
 
1257
 
 
1258
     Bool xf86ServerIsOnlyProbing()
 
1259
 
 
1260
          Returns TRUE if the -probeonly command line flag was
 
1261
          specified, and FALSE otherwise.
 
1262
 
 
1263
     Bool xf86CaughtSignal()
 
1264
 
 
1265
          Returns TRUE if the server has caught a signal, and FALSE
 
1266
          otherwise.
 
1267
 
 
1268
8.4  Allocating private data
 
1269
 
 
1270
A driver and any module it uses may allocate per-screen private storage in
 
1271
either the ScreenRec (DIX level) or ScrnInfoRec (XFree86 common layer level).
 
1272
ScreenRec storage persists only for a single server generation, and ScrnIn-
 
1273
foRec storage persists across generations for the lifetime of the server.
 
1274
 
 
1275
The ScreenRec devPrivates data must be reallocated/initialised at the start
 
1276
of each new generation.  This is normally done from the ChipScreenInit()
 
1277
function, and Init functions for other modules that it calls.  Data allocated
 
1278
in this way should be freed by the driver's ChipCloseScreen() functions, and
 
1279
Close functions for other modules that it calls.  A new devPrivates entry is
 
1280
allocated by calling the AllocateScreenPrivateIndex() function.
 
1281
 
 
1282
     int AllocateScreenPrivateIndex()
 
1283
 
 
1284
          This function allocates a new element in the devPrivates
 
1285
          field of all currently existing ScreenRecs.  The return
 
1286
          value is the index of this new element in the devPrivates
 
1287
          array.  The devPrivates field is of type DevUnion:
 
1288
 
 
1289
                       typedef union _DevUnion {
 
1290
                           pointer             ptr;
 
1291
                           long                val;
 
1292
                           unsigned long       uval;
 
1293
                           pointer             (*fptr)(void);
 
1294
                       } DevUnion;
 
1295
 
 
1296
          which allows the element to be used for any of the above
 
1297
          types.  It is commonly used as a pointer to data that the
 
1298
          caller allocates after the new index has been allocated.
 
1299
 
 
1300
          This function will return -1 when there is an error allo-
 
1301
          cating the new index.
 
1302
 
 
1303
The ScrnInfoRec privates data persists for the life of the server, so only
 
1304
needs to be allocated once.  This should be done from the ChipPreInit() func-
 
1305
tion, and Init functions for other modules that it calls.  Data allocated in
 
1306
this way should be freed by the driver's ChipFreeScreen() functions, and Free
 
1307
functions for other modules that it calls.  A new privates entry is allocated
 
1308
by calling the xf86AllocateScrnInfoPrivateIndex() function.
 
1309
 
 
1310
     int xf86AllocateScrnInfoPrivateIndex()
 
1311
 
 
1312
          This function allocates a new element in the privates
 
1313
          field of all currently existing ScrnInfoRecs.  The return
 
1314
          value is the index of this new element in the privates
 
1315
          array.  The privates field is of type DevUnion:
 
1316
 
 
1317
                       typedef union _DevUnion {
 
1318
                           pointer             ptr;
 
1319
                           long                val;
 
1320
                           unsigned long       uval;
 
1321
                           pointer             (*fptr)(void);
 
1322
                       } DevUnion;
 
1323
 
 
1324
          which allows the element to be used for any of the above
 
1325
          types.  It is commonly used as a pointer to data that the
 
1326
          caller allocates after the new index has been allocated.
 
1327
 
 
1328
          This function will not return when there is an error
 
1329
          allocating the new index.  When there is an error it will
 
1330
          cause the server to exit with a fatal error.  The similar
 
1331
          function for allocation privates in the ScreenRec (Allo-
 
1332
          cateScreenPrivateIndex()) differs in this respect by
 
1333
          returning -1 when the allocation fails.
 
1334
 
 
1335
9.  Keeping Track of Bus Resources
 
1336
 
 
1337
9.1  Theory of Operation
 
1338
 
 
1339
The XFree86 common layer has knowledge of generic access control mechanisms
 
1340
for devices on certain bus systems (currently the PCI bus) as well as of
 
1341
methods to enable or disable access to the buses itself.  Furthermore it can
 
1342
access information on resources decoded by these devices and if necessary
 
1343
modify it.
 
1344
 
 
1345
When first starting the Xserver collects all this information, saves it for
 
1346
restoration, checks it for consistency, and if necessary, corrects it.
 
1347
Finally it disables all resources on a generic level prior to calling any
 
1348
driver function.
 
1349
 
 
1350
When the Probe() function of each driver is called the device sections are
 
1351
matched against the devices found in the system.  The driver may probe
 
1352
devices at this stage that cannot be identified by using device independent
 
1353
methods.  Access to all resources that can be controlled in a device indepen-
 
1354
dent way is disabled.  The Probe() function should register all non-relocat-
 
1355
able resources at this stage.  If a resource conflict is found between exclu-
 
1356
sive resources the driver will fail immediately.  Optionally the driver might
 
1357
specify an EntityInit(), EntityLeave() and EntityEnter() function.
 
1358
 
 
1359
EntityInit() can be used to disable any shared resources that are not con-
 
1360
trolled by the generic access control functions.  It is called prior to the
 
1361
PreInit phase regardless if an entity is active or not.  When calling the
 
1362
EntityInit(), EntityEnter() and EntityLeave() functions the common level will
 
1363
disable access to all other entities on a generic level.  Since the common
 
1364
level has no knowledge of device specific methods to disable access to
 
1365
resources it cannot be guaranteed that certain resources are not decoded by
 
1366
any other entity until the EntityInit() or EntityEnter() phase is finished.
 
1367
Device drivers should therefore register all those resources which they are
 
1368
going to disable.  If these resources are never to be used by any driver
 
1369
function they may be flagged ResInit so that they can be removed from the
 
1370
resource list after processing all EntityInit() functions.  EntityEnter()
 
1371
should disable decoding of all resources which are not registered as exclu-
 
1372
sive and which are not handled by the generic access control in the common
 
1373
level.  The difference to EntityInit() is that the latter one is only called
 
1374
once during lifetime of the server.  It can therefore be used to set up vari-
 
1375
ables prior to disabling resources.  EntityLeave() should restore the origi-
 
1376
nal state when exiting the server or switching to a different VT.  It also
 
1377
needs to disable device specific access functions if they need to be disabled
 
1378
on server exit or VT switch.  The default state is to enable them before giv-
 
1379
ing up the VT.
 
1380
 
 
1381
In PreInit() phase each driver should check if any sharable resources it has
 
1382
registered during Probe() has been denied and take appropriate action which
 
1383
could simply be to fail.  If it needs to access resources it has disabled
 
1384
during EntitySetup() it can do so provided it has registered these and will
 
1385
disable them before returning from PreInit().  This also applies to all other
 
1386
driver functions.  Several functions are provided to request resource ranges,
 
1387
register these, correct PCI config space and add replacements for the generic
 
1388
access functions.  Resources may be marked ``disabled'' or ``unused'' during
 
1389
OPERATING stage.  Although these steps could also be performed in
 
1390
ScreenInit(), this is not desirable.
 
1391
 
 
1392
Following PreInit() phase the common level determines if resource access con-
 
1393
trol is needed.  This is the case if more than one screen is used.  If neces-
 
1394
sary the RAC wrapper module is loaded.  In ScreenInit() the drivers can
 
1395
decide which operations need to be placed under RAC.  Available are the frame
 
1396
buffer operations, the pointer operations and the colormap operations.  Any
 
1397
operation that requires resources which might be disabled during OPERATING
 
1398
state should be set to use RAC.  This can be specified separately for memory
 
1399
and IO resources.
 
1400
 
 
1401
When ScreenInit() phase is done the common level will determine which shared
 
1402
resources are requested by more than one driver and set the access functions
 
1403
accordingly.  This is done following these rules:
 
1404
 
 
1405
  1.  The sharable resources registered by each entity are compared.  If a
 
1406
      resource is registered by more than one entity the entity will be
 
1407
      marked to need to share this resources type (IO or MEM).
 
1408
 
 
1409
  2.  A resource marked ``disabled'' during OPERATING state will be ignored
 
1410
      entirely.
 
1411
 
 
1412
  3.  A resource marked ``unused'' will only conflicts with an overlapping
 
1413
      resource of an other entity if the second is actually in use during
 
1414
      OPERATING state.
 
1415
 
 
1416
  4.  If an ``unused'' resource was found to conflict however the entity does
 
1417
      not use any other resource of this type the entire resource type will
 
1418
      be disabled for that entity.
 
1419
 
 
1420
The driver has the choice among different ways to control access to certain
 
1421
resources:
 
1422
 
 
1423
  1.  It can rely on the generic access functions.  This is probably the most
 
1424
      common case.  Here the driver only needs to register any resource it is
 
1425
      going to use.
 
1426
 
 
1427
  2.  It can replace the generic access functions by driver specific ones.
 
1428
      This will mostly be used in cases where no generic access functions are
 
1429
      available.  In this case the driver has to make sure these resources
 
1430
      are disabled when entering the PreInit() stage.  Since the replacement
 
1431
      functions are registered in PreInit() the driver will have to enable
 
1432
      these resources itself if it needs to access them during this state.
 
1433
      The driver can specify if the replacement functions can control memory
 
1434
      and/or I/O resources separately.
 
1435
 
 
1436
  3.  The driver can enable resources itself when it needs them.  Each driver
 
1437
      function enabling them needs to disable them before it will return.
 
1438
      This should be used if a resource which can be controlled in a device
 
1439
      dependent way is only required during SETUP state.  This way it can be
 
1440
      marked ``unused'' during OPERATING state.
 
1441
 
 
1442
A resource which is decoded during OPERATING state however never accessed by
 
1443
the driver should be marked unused.
 
1444
 
 
1445
Since access switching latencies are an issue during Xserver operation, the
 
1446
common level attempts to minimize the number of entities that need to be
 
1447
placed under RAC control.  When a wrapped operation is called, the EnableAc-
 
1448
cess() function is called before control is passed on.  EnableAccess() checks
 
1449
if a screen is under access control.  If not it just establishes bus routing
 
1450
and returns.  If the screen needs to be under access control, EnableAccess()
 
1451
determines which resource types (MEM, IO) are required.  Then it tests if
 
1452
this access is already established.  If so it simply returns.  If not it dis-
 
1453
ables the currently established access, fixes bus routing and enables access
 
1454
to all entities registered for this screen.
 
1455
 
 
1456
Whenever a mode switch or a VT-switch is performed the common level will
 
1457
return to SETUP state.
 
1458
 
 
1459
9.2  Resource Types
 
1460
 
 
1461
Resource have certain properties.  When registering resources each range is
 
1462
accompanied by a flag consisting of the ORed flags of the different proper-
 
1463
ties the resource has.  Each resource range may be classified according to
 
1464
 
 
1465
   o its physical properties i.e., if it addresses memory (ResMem)  or I/O
 
1466
     space (ResIo),
 
1467
 
 
1468
   o if it addresses a block (ResBlock) or sparse (ResSparse) range,
 
1469
 
 
1470
   o its access properties.
 
1471
 
 
1472
There are two known access properties:
 
1473
 
 
1474
   o ResExclusive for resources which may not be shared with any other device
 
1475
     and
 
1476
 
 
1477
   o ResShared for resources which can be disabled and therefore can be
 
1478
     shared.
 
1479
 
 
1480
If it is necessary to test a resource against any type a generic access type
 
1481
ResAny is provided.  If this is set the resource will conflict with any
 
1482
resource of a different entity intersecting its range.  Further it can be
 
1483
specified that a resource is decoded however never used during any stage
 
1484
(ResUnused) or during OPERATING state (ResUnusedOpr).  A resource only visi-
 
1485
ble during the init functions (ie.  EntityInit(), EntityEnter() and
 
1486
EntityLeave() should be registered with the flag ResInit.  A resource that
 
1487
might conflict with background resource ranges may be flagged with ResBios.
 
1488
This might be useful when registering resources ranges that were assigned by
 
1489
the system Bios.
 
1490
 
 
1491
Several predefined resource lists are available for VGA and 8514/A resources
 
1492
in common/xf86Resources.h.
 
1493
 
 
1494
9.3  Available Functions
 
1495
 
 
1496
The functions provided for resource management are listed in their order of
 
1497
use in the driver.
 
1498
 
 
1499
9.3.1  Probe Phase
 
1500
 
 
1501
In this phase each driver detects those resources it is able to drive, cre-
 
1502
ates an entity record for each of them, registers non-relocatable resources
 
1503
and allocates screens and adds the resources to screens.
 
1504
 
 
1505
Two helper functions are provided for matching device sections in the
 
1506
XF86Config file to the devices:
 
1507
 
 
1508
     int xf86MatchPciInstances(const char *driverName, int vendorID,
 
1509
 
 
1510
               SymTabPtr chipsets, PciChipsets *PCIchipsets,
 
1511
 
 
1512
               GDevPtr *devList, int numDevs, DriverPtr drvp,
 
1513
 
 
1514
               int **foundEntities)
 
1515
 
 
1516
          This function finds matches between PCI cards that a
 
1517
          driver supports and config file device sections.  It is
 
1518
          intended for use in the ChipProbe() function of drivers
 
1519
          for PCI cards.  Only probed PCI devices with a vendor ID
 
1520
          matching vendorID are considered.  devList and numDevs
 
1521
          are typically those found from calling xf86MatchDevice(),
 
1522
          and represent the active config file device sections rel-
 
1523
          evant to the driver.  PCIchipsets is a table that pro-
 
1524
          vides a mapping between the PCI device IDs, the driver's
 
1525
          internal chipset tokens and a list of fixed resources.
 
1526
 
 
1527
          When a device section doesn't have a BusID entry it can
 
1528
          only match the primary video device.  Secondary devices
 
1529
          are only matched with device sections that have a match-
 
1530
          ing BusID entry.
 
1531
 
 
1532
          Once the preliminary matches have been found, a final
 
1533
          match is confirmed by checking if the chipset override,
 
1534
          ChipID override or probed PCI chipset type match one of
 
1535
          those given in the chipsets and PCIchipsets lists.  The
 
1536
          PCIchipsets list includes a list of the PCI device IDs
 
1537
          supported by the driver.  The list should be terminated
 
1538
          with an entry with PCI ID -1".  The chipsets list is a
 
1539
          table mapping the driver's internal chipset tokens to
 
1540
          names, and should be terminated with a NULL entry.  Only
 
1541
          those entries with a corresponding entry in the PCI-
 
1542
          chipsets list are considered.  The order of precedence
 
1543
          is: config file chipset, config file ChipID, probed PCI
 
1544
          device ID.
 
1545
 
 
1546
          In cases where a driver handles PCI chipsets with more
 
1547
          than one vendor ID, it may set vendorID to 0, and OR each
 
1548
          devID in the list with (the vendor ID << 16).
 
1549
 
 
1550
          Entity index numbers for confirmed matches are returned
 
1551
          as an array via foundEntities.  The PCI information,
 
1552
          chipset token and device section for each match are found
 
1553
          in the EntityInfoRec referenced by the indices.
 
1554
 
 
1555
          The function return value is the number of confirmed
 
1556
          matches.  A return value of -1 indicates an internal
 
1557
          error.  The returned foundEntities array should be freed
 
1558
          by the driver with xfree() when it is no longer needed in
 
1559
          cases where the return value is greater than zero.
 
1560
 
 
1561
     int xf86MatchIsaInstances(const char *driverName,
 
1562
 
 
1563
               SymTabPtr chipsets, IsaChipsets *ISAchipsets,
 
1564
 
 
1565
               DriverPtr drvp, FindIsaDevProc FindIsaDevice,
 
1566
 
 
1567
               GDevPtr *devList, int numDevs, int **foundEntities)
 
1568
 
 
1569
          This function finds matches between ISA cards that a
 
1570
          driver supports and config file device sections.  It is
 
1571
          intended for use in the ChipProbe() function of drivers
 
1572
          for ISA cards.  devList and numDevs are typically those
 
1573
          found from calling xf86MatchDevice(), and represent the
 
1574
          active config file device sections relevant to the
 
1575
          driver.  ISAchipsets is a table that provides a mapping
 
1576
          between the driver's internal chipset tokens and the
 
1577
          resource classes.  FindIsaDevice is a driver-provided
 
1578
          function that probes the hardware and returns the chipset
 
1579
          token corresponding to what was detected, and -1 if noth-
 
1580
          ing was detected.
 
1581
 
 
1582
          If the config file device section contains a chipset
 
1583
          entry, then it is checked against the chipsets list.
 
1584
          When no chipset entry is present, the FindIsaDevice func-
 
1585
          tion is called instead.
 
1586
 
 
1587
          Entity index numbers for confirmed matches are returned
 
1588
          as an array via foundEntities.  The chipset token and
 
1589
          device section for each match are found in the EntityIn-
 
1590
          foRec referenced by the indices.
 
1591
 
 
1592
          The function return value is the number of confirmed
 
1593
          matches.  A return value of -1 indicates an internal
 
1594
          error.  The returned foundEntities array should be freed
 
1595
          by the driver with xfree() when it is no longer needed in
 
1596
          cases where the return value is greater than zero.
 
1597
 
 
1598
These two helper functions make use of several core functions that are avail-
 
1599
able at the driver level:
 
1600
 
 
1601
     Bool xf86ParsePciBusString(const char *busID, int *bus,
 
1602
 
 
1603
               int *device, int *func)
 
1604
 
 
1605
          Takes a BusID string, and if it is in the correct format,
 
1606
          returns the PCI bus, device, func values that it indi-
 
1607
          cates.  The format of the string is expected to be
 
1608
          "PCI:bus:device:func" where each of `bus', `device' and
 
1609
          `func' are decimal integers.  The ":func" part may be
 
1610
          omitted, and the func value assumed to be zero, but this
 
1611
          isn't encouraged.  The "PCI" prefix may also be omitted.
 
1612
          The prefix "AGP" is currently equivalent to the "PCI"
 
1613
          prefix.  If the string isn't a valid PCI BusID, the
 
1614
          return value is FALSE.
 
1615
 
 
1616
     Bool xf86ComparePciBusString(const char *busID, int bus,
 
1617
 
 
1618
               int device, int func)
 
1619
 
 
1620
          Compares a BusID string with PCI bus, device, func val-
 
1621
          ues.  If they match TRUE is returned, and FALSE if they
 
1622
          don't.
 
1623
 
 
1624
     Bool xf86ParseIsaBusString(const char *busID)
 
1625
 
 
1626
          Compares a BusID string with the ISA bus ID string ("ISA"
 
1627
          or "ISA:").  If they match TRUE is returned, and FALSE if
 
1628
          they don't.
 
1629
 
 
1630
     Bool xf86CheckPciSlot(int bus, int device, int func)
 
1631
 
 
1632
          Checks if the PCI slot bus:device:func has been claimed.
 
1633
          If so, it returns FALSE, and otherwise TRUE.
 
1634
 
 
1635
     int xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp,
 
1636
 
 
1637
               int chipset, GDevPtr dev, Bool active)
 
1638
 
 
1639
          This function is used to claim a PCI slot, allocate the
 
1640
          associated entity record and initialise their data struc-
 
1641
          tures.  The return value is the index of the newly allo-
 
1642
          cated entity record, or -1 if the claim fails.  This
 
1643
          function should always succeed if xf86CheckPciSlot()
 
1644
          returned TRUE for the same PCI slot.
 
1645
 
 
1646
     Bool xf86IsPrimaryPci(void)
 
1647
 
 
1648
          This function returns TRUE if the primary card is a PCI
 
1649
          device, and FALSE otherwise.
 
1650
 
 
1651
     int xf86ClaimIsaSlot(DriverPtr drvp, int chipset,
 
1652
 
 
1653
               GDevPtr dev, Bool active)
 
1654
 
 
1655
          This allocates an entity record entity and initialise the
 
1656
          data structures.  The return value is the index of the
 
1657
          newly allocated entity record.
 
1658
 
 
1659
     Bool xf86IsPrimaryIsa(void)
 
1660
 
 
1661
          This function returns TRUE if the primary card is an ISA
 
1662
          (non-PCI) device, and FALSE otherwise.
 
1663
 
 
1664
Two helper functions are provided to aid configuring entities:
 
1665
 
 
1666
     ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn,
 
1667
 
 
1668
               int scrnFlag, int entityIndex,
 
1669
 
 
1670
               PciChipsets *p_chip,
 
1671
 
 
1672
               resList res, EntityProc init,
 
1673
 
 
1674
               EntityProc enter, EntityProc leave,
 
1675
 
 
1676
               pointer private)
 
1677
 
 
1678
     ScrnInfoPtr xf86ConfigIsaEntity(ScrnInfoPtr pScrn,
 
1679
 
 
1680
               int scrnFlag, int entityIndex,
 
1681
 
 
1682
               IsaChipsets *i_chip,
 
1683
 
 
1684
               resList res, EntityProc init,
 
1685
 
 
1686
               EntityProc enter, EntityProc leave,
 
1687
 
 
1688
               pointer private)
 
1689
 
 
1690
          These functions are used to register the non-relocatable
 
1691
          resources for an entity, and the optional entity-specific
 
1692
          Init, Enter and Leave functions.  Usually the list of
 
1693
          fixed resources is obtained from the Isa/PciChipsets
 
1694
          lists.  However an additional list of resources may be
 
1695
          passed.  Generally this is not required.  For active
 
1696
          entities a ScrnInfoRec is allocated if the pScrn argument
 
1697
          is NULL.  The return value is TRUE when successful.  The
 
1698
          init, enter, leave functions are defined as follows:
 
1699
 
 
1700
               typedef void (*EntityProc)(int entityIndex,
 
1701
 
 
1702
                         pointer private)
 
1703
 
 
1704
          They are passed the entity index and a pointer to a pri-
 
1705
          vate scratch area.  This can be set up during Probe() and
 
1706
          its address can be passed to xf86ConfigIsaEntity() and
 
1707
          xf86ConfigPciEntity() as the last argument.
 
1708
 
 
1709
These two helper functions make use of several core functions that are avail-
 
1710
able at the driver level:
 
1711
 
 
1712
     void xf86ClaimFixedResources(resList list, int entityIndex)
 
1713
 
 
1714
          This function registers the non-relocatable resources
 
1715
          which cannot be disabled and which therefore would cause
 
1716
          the server to fail immediately if they were found to con-
 
1717
          flict.  It also records non-relocatable but sharable
 
1718
          resources for processing after the Probe() phase.
 
1719
 
 
1720
     Bool xf86SetEntityFuncs(int entityIndex, EntityProc init,
 
1721
 
 
1722
               EntityProc enter, EntityProc leave, pointer)
 
1723
 
 
1724
          This function registers with an entity the init, enter,
 
1725
          leave functions along with the pointer to their private
 
1726
          area.
 
1727
 
 
1728
     void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex)
 
1729
 
 
1730
          This function associates the entity referenced by enti-
 
1731
          tyIndex with the screen.
 
1732
 
 
1733
9.3.2  PreInit Phase
 
1734
 
 
1735
During this phase the remaining resources should be registered.  PreInit()
 
1736
should call xf86GetEntityInfo() to obtain a pointer to an EntityInfoRec for
 
1737
each entity it is able to drive and check if any resource are listed in its
 
1738
resources field.  If resources registered in the Probe phase have been
 
1739
rejected in the post-Probe phase (resources is non-NULL), then the driver
 
1740
should decide if it can continue without using these or if it should fail.
 
1741
 
 
1742
     EntityInfoPtr xf86GetEntityInfo(int entityIndex)
 
1743
 
 
1744
          This function returns a pointer to the EntityInfoRec ref-
 
1745
          erenced by entityIndex.  The returned EntityInfoRec
 
1746
          should be freed with xfree() when no longer needed.
 
1747
 
 
1748
Several functions are provided to simplify resource registration:
 
1749
 
 
1750
     Bool xf86IsEntityPrimary(int entityIndex)
 
1751
 
 
1752
          This function returns TRUE if the entity referenced by
 
1753
          entityIndex is the primary display device (i.e., the one
 
1754
          initialised at boot time and used in text mode).
 
1755
     Bool xf86IsScreenPrimary(int scrnIndex)
 
1756
 
 
1757
          This function returns TRUE if the primary entity is reg-
 
1758
          istered with the screen referenced by scrnIndex.
 
1759
 
 
1760
     pciVideoPtr xf86GetPciInfoForEntity(int entityIndex)
 
1761
 
 
1762
          This function returns a pointer to the pciVideoRec for
 
1763
          the specified entity.  If the entity is not a PCI device,
 
1764
          NULL is returned.
 
1765
 
 
1766
The primary function for registration of resources is:
 
1767
 
 
1768
     resPtr xf86RegisterResources(int entityIndex, resList list,
 
1769
 
 
1770
               int access)
 
1771
 
 
1772
          This function tries to register the resources in list.
 
1773
          If list is NULL it tries to determine the resources auto-
 
1774
          matically.  This only works for entities that provide a
 
1775
          generic way to read out the resource ranges they decode.
 
1776
          So far this is only the case for PCI devices.  By default
 
1777
          the PCI resources are registered as shared (ResShared) if
 
1778
          the driver wants to set a different access type it can do
 
1779
          so by specifying the access flags in the third argument.
 
1780
          A value of 0 means to use the default settings.  If for
 
1781
          any reason the resource broker is not able to register
 
1782
          some of the requested resources the function will return
 
1783
          a pointer to a list of the failed ones.  In this case the
 
1784
          driver may be able to move the resource to different
 
1785
          locations.  In case of PCI bus entities this is done by
 
1786
          passing the list of failed resources to xf86ReallocateP-
 
1787
          ciResources().  When the registration succeeds, the
 
1788
          return value is NULL.
 
1789
 
 
1790
     resPtr xf86ReallocatePciResources(int entityIndex, resPtr pRes)
 
1791
 
 
1792
          This function takes a list of PCI resources that need to
 
1793
          be reallocated and returns NULL when all relocations are
 
1794
          successful.  xf86RegisterResources() should be called
 
1795
          again to register the relocated resources with the bro-
 
1796
          ker.  If the reallocation fails, a list of the resources
 
1797
          that could not be relocated is returned.
 
1798
 
 
1799
Two functions are provided to obtain a resource range of a given type:
 
1800
 
 
1801
     resRange xf86GetBlock(long type, memType size,
 
1802
 
 
1803
               memType window_start, memType window_end,
 
1804
 
 
1805
               memType align_mask, resPtr avoid)
 
1806
 
 
1807
          This function tries to find a block range of size size
 
1808
          and type type in a window bound by window_start and win-
 
1809
          dow_end with the alignment specified in align_mask.
 
1810
          Optionally a list of resource ranges which should be
 
1811
          avoided within the window can be supplied.  On failure a
 
1812
          zero-length range of type ResEnd will be returned.
 
1813
 
 
1814
     resRange xf86GetSparse(long type, memType fixed_bits,
 
1815
 
 
1816
               memType decode_mask, memType address_mask,
 
1817
 
 
1818
               resPtr avoid)
 
1819
 
 
1820
          This function is like the previous one, but attempts to
 
1821
          find a sparse range instead of a block range.  Here three
 
1822
          values have to be specified: the address_mask which marks
 
1823
          all bits of the mask part of the address, the decode_mask
 
1824
          which masks out the bits which are hardcoded and are
 
1825
          therefore not available for relocation and the values of
 
1826
          the fixed bits.  The function tries to find a base that
 
1827
          satisfies the given condition.  If the function fails it
 
1828
          will return a zero range of type ResEnd.  Optionally it
 
1829
          might be passed a list of resource ranges to avoid.
 
1830
 
 
1831
Some PCI devices are broken in the sense that they return invalid size infor-
 
1832
mation for a certain resource.  In this case the driver can supply the cor-
 
1833
rect size and make sure that the resource range allocated for the card is
 
1834
large enough to hold the address range decoded by the card.  The function
 
1835
xf86FixPciResource() can be used to do this:
 
1836
 
 
1837
     Bool xf86FixPciResource(int entityIndex, unsigned int prt,
 
1838
 
 
1839
               CARD32 alignment, long type)
 
1840
 
 
1841
          This function fixes a PCI resource allocation.  The prt
 
1842
          parameter contains the number of the PCI base register
 
1843
          that needs to be fixed (0-5, and 6 for the BIOS base reg-
 
1844
          ister).  The size is specified by the alignment.  Since
 
1845
          PCI resources need to span an integral range of size 2^n,
 
1846
          the alignment also specifies the number of addresses that
 
1847
          will be decoded.  If the driver specifies a type mask it
 
1848
          can override the default type for PCI resources which is
 
1849
          ResShared.  The resource broker needs to know that to
 
1850
          find a matching resource range.  This function should be
 
1851
          called before calling xf86RegisterResources().  The
 
1852
          return value is TRUE when the function succeeds.
 
1853
 
 
1854
     Bool xf86CheckPciMemBase(pciVideoPtr pPci, memType base)
 
1855
 
 
1856
          This function checks that the memory base address speci-
 
1857
          fied matches one of the PCI base address register values
 
1858
          for the given PCI device.  This is mostly used to check
 
1859
          that an externally provided base address (e.g., from a
 
1860
          config file) matches an actual value allocated to a
 
1861
          device.
 
1862
 
 
1863
The driver may replace the generic access control functions for an entity.
 
1864
This is done with the xf86SetAccessFuncs():
 
1865
 
 
1866
     void xf86SetAccessFuncs(EntityInfoPtr pEnt,
 
1867
 
 
1868
               xf86SetAccessFuncPtr funcs,
 
1869
 
 
1870
               xf86SetAccessFuncPtr oldFuncs)
 
1871
 
 
1872
          with:
 
1873
 
 
1874
                typedef struct {
 
1875
                    xf86AccessPtr mem;
 
1876
                    xf86AccessPtr io;
 
1877
                    xf86AccessPtr io_mem;
 
1878
                } xf86SetAccessFuncRec, *xf86SetAccessFuncPtr;
 
1879
 
 
1880
          The driver can pass three functions: one for I/O access,
 
1881
          one for memory access and one for combined memory and I/O
 
1882
          access.  If the memory access and combined access func-
 
1883
          tions are identical the common level assumes that the
 
1884
          memory access cannot be controlled independently of I/O
 
1885
          access, if the I/O access function and the combined
 
1886
          access functions are the same it is assumed that I/O can
 
1887
          not be controlled independently.  If memory and I/O have
 
1888
          to be controlled together all three values should be the
 
1889
          same.  If a non NULL value is passed as third argument it
 
1890
          is interpreted as an address where to store the old
 
1891
          access record.  If the third argument is NULL it will be
 
1892
          assumed that the generic access should be enabled before
 
1893
          replacing the access functions.  Otherwise it will be
 
1894
          disabled.  The driver may enable them itself using the
 
1895
          returned values.  It should do this from its replacement
 
1896
          access functions as the generic access may be disabled by
 
1897
          the common level on certain occasions.  If replacement
 
1898
          functions are specified they must control all resources
 
1899
          of the specific type registered for the entity.
 
1900
 
 
1901
To find out if a specific resource range conflicts with another resource the
 
1902
xf86ChkConflict() function may be used:
 
1903
 
 
1904
     memType xf86ChkConflict(resRange *rgp, int entityIndex)
 
1905
 
 
1906
          This function checks if the resource range rgp of for the
 
1907
          specified entity conflicts with with another resource.
 
1908
          If a conflict is found, the address of the start of the
 
1909
          conflict is returned.  The return value is zero when
 
1910
          there is no conflict.
 
1911
 
 
1912
The OPERATING state properties of previously registered fixed resources can
 
1913
be set with the xf86SetOperatingState() function:
 
1914
 
 
1915
     resPtr xf86SetOperatingState(resList list, int entityIndex,
 
1916
 
 
1917
               int mask)
 
1918
 
 
1919
          This function is used to set the status of a resource
 
1920
          during OPERATING state.  list holds a list to which mask
 
1921
          is to be applied.  The parameter mask may have the value
 
1922
          ResUnusedOpr and ResDisableOpr.  The first one should be
 
1923
          used if a resource isn't used by the driver during OPER-
 
1924
          ATING state although it is decoded by the device, while
 
1925
          the latter one indicates that the resource is not decoded
 
1926
          during OPERATING state.  Note that the resource ranges
 
1927
          have to match those specified during registration.  If a
 
1928
          range has been specified starting at A and ending at B
 
1929
          and suppose C us a value satisfying A < C < B one may not
 
1930
          specify the resource range (A,B) by splitting it into two
 
1931
          ranges (A,C) and (C,B).
 
1932
 
 
1933
The following two functions are provided for special cases:
 
1934
 
 
1935
     void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex)
 
1936
 
 
1937
          This function may be used to remove an entity from a
 
1938
          screen.  This only makes sense if a screen has more than
 
1939
          one entity assigned or the screen is to be deleted.  No
 
1940
          test is made if the screen has any entities left.
 
1941
 
 
1942
     void xf86DeallocateResourcesForEntity(int entityIndex, long type)
 
1943
 
 
1944
          This function deallocates all resources of a given type
 
1945
          registered for a certain entity from the resource broker
 
1946
          list.
 
1947
 
 
1948
9.3.3  ScreenInit Phase
 
1949
 
 
1950
All that is required in this phase is to setup the RAC flags.  Note that it
 
1951
is also permissible to set these flags up in the PreInit phase.  The RAC
 
1952
flags are held in the racIoFlags and racMemFlags fields of the ScrnInfoRec
 
1953
for each screen.  They specify which graphics operations might require the
 
1954
use of shared resources.  This can be specified separately for memory and I/O
 
1955
resources.  The available flags are defined in rac/xf86RAC.h.  They are:
 
1956
 
 
1957
RAC_FB
 
1958
 
 
1959
     for framebuffer operations (including hw acceleration)
 
1960
 
 
1961
RAC_CURSOR
 
1962
 
 
1963
     for Cursor operations (??? I'm not sure if we need this for SW cur-
 
1964
     sor it depends on which level the sw cursor is drawn)
 
1965
 
 
1966
RAC_COLORMAP
 
1967
 
 
1968
     for colormap operations
 
1969
 
 
1970
RAC_VIEWPORT
 
1971
 
 
1972
     for the call to ChipAdjustFrame()
 
1973
 
 
1974
The flags are ORed together.
 
1975
 
 
1976
10.  Config file ``Option'' entries
 
1977
 
 
1978
Option entries are permitted in most sections and subsections of the config
 
1979
file.  There are two forms of option entries:
 
1980
 
 
1981
      Option "option-name"
 
1982
            A boolean option.
 
1983
 
 
1984
      Option "option-name" "option-value"
 
1985
            An option with an arbitrary value.
 
1986
 
 
1987
The option entries are handled by the parser, and a list of the parsed
 
1988
options is included with each of the appropriate data structures that the
 
1989
drivers have access to.  The data structures used to hold the option informa-
 
1990
tion are opaque to the driver, and a driver must not access the option data
 
1991
directly.  Instead, the common layer provides a set of functions that may be
 
1992
used to access, check and manipulate the option data.
 
1993
 
 
1994
First, the low level option handling functions.  In most cases drivers would
 
1995
not need to use these directly.
 
1996
 
 
1997
     pointer xf86FindOption(pointer options, const char *name)
 
1998
 
 
1999
          Takes a list of options and an option name, and returns a
 
2000
          handle for the first option entry in the list matching
 
2001
          the name.  Returns NULL if no match is found.
 
2002
     char *xf86FindOptionValue(pointer options, const char *name)
 
2003
 
 
2004
          Takes a list of options and an option name, and returns
 
2005
          the value associated with the first option entry in the
 
2006
          list matching the name.  If the matching option has no
 
2007
          value, an empty string ("") is returned.  Returns NULL if
 
2008
          no match is found.
 
2009
 
 
2010
     void xf86MarkOptionUsed(pointer option)
 
2011
 
 
2012
          Takes a handle for an option, and marks that option as
 
2013
          used.
 
2014
 
 
2015
     void xf86MarkOptionUsedByName(pointer options, const char *name)
 
2016
 
 
2017
          Takes a list of options and an option name and marks the
 
2018
          first option entry in the list matching the name as used.
 
2019
 
 
2020
Next, the higher level functions that most drivers would use.
 
2021
 
 
2022
     void xf86CollectOptions(ScrnInfoPtr pScrn, pointer extraOpts)
 
2023
 
 
2024
          Collect the options from each of the config file sections
 
2025
          used by the screen (pScrn) and return the merged list as
 
2026
          pScrn->options.  This function requires that pScrn->conf-
 
2027
          Screen, pScrn->display, pScrn->monitor, pScrn->numEnti-
 
2028
          ties, and pScrn->entityList are initialised.  extraOpts
 
2029
          may optionally be set to an additional list of options to
 
2030
          be combined with the others.  The order of precedence for
 
2031
          options is extraOpts, display, confScreen, monitor,
 
2032
          device.
 
2033
 
 
2034
     void xf86ProcessOptions(int scrnIndex, pointer options,
 
2035
 
 
2036
               OptionInfoPtr optinfo)
 
2037
 
 
2038
          Processes a list of options according to the information
 
2039
          in the array of OptionInfoRecs (optinfo).  The resulting
 
2040
          information is stored in the value fields of the appro-
 
2041
          priate optinfo entries.  The found fields are set to TRUE
 
2042
          when an option with a value of the correct type if found,
 
2043
          and FALSE otherwise.  The type field is used to determine
 
2044
          the expected value type for each option.  Each option in
 
2045
          the list of options for which there is a name match (but
 
2046
          not necessarily a value type match) is marked as used.
 
2047
          Warning messages are printed when option values don't
 
2048
          match the types specified in the optinfo data.
 
2049
 
 
2050
          NOTE: If this function is called before a driver's screen
 
2051
          number is known (e.g., from the ChipProbe() function) a
 
2052
          scrnIndex value of -1 should be used.
 
2053
 
 
2054
          NOTE 2: Given that this function stores into the Option-
 
2055
          InfoRecs pointed to by optinfo, the caller should ensure
 
2056
          the OptionInfoRecs are (re-)initialised before the call,
 
2057
          especially if the caller expects to use the predefined
 
2058
          option values as defaults.
 
2059
 
 
2060
          The OptionInfoRec is defined as follows:
 
2061
 
 
2062
                     typedef struct {
 
2063
                         double freq;
 
2064
                         int units;
 
2065
                     } OptFrequency;
 
2066
 
 
2067
                     typedef union {
 
2068
                         unsigned long       num;
 
2069
                         char *              str;
 
2070
                         double              realnum;
 
2071
                         Bool                bool;
 
2072
                         OptFrequency        freq;
 
2073
                     } ValueUnion;
 
2074
 
 
2075
                     typedef enum {
 
2076
                         OPTV_NONE = 0,
 
2077
                         OPTV_INTEGER,
 
2078
                         OPTV_STRING,  /* a non-empty string */
 
2079
                         OPTV_ANYSTR,  /* Any string, including an empty one */
 
2080
                         OPTV_REAL,
 
2081
                         OPTV_BOOLEAN,
 
2082
                         OPTV_FREQ
 
2083
                     } OptionValueType;
 
2084
 
 
2085
                     typedef enum {
 
2086
                         OPTUNITS_HZ = 1,
 
2087
                         OPTUNITS_KHZ,
 
2088
                         OPTUNITS_MHZ
 
2089
                     } OptFreqUnits;
 
2090
 
 
2091
                     typedef struct {
 
2092
                         int                 token;
 
2093
                         const char*         name;
 
2094
                         OptionValueType     type;
 
2095
                         ValueUnion          value;
 
2096
                         Bool                found;
 
2097
                     } OptionInfoRec, *OptionInfoPtr;
 
2098
 
 
2099
          OPTV_FREQ can be used for options values that are fre-
 
2100
          quencies.  These values are a floating point number with
 
2101
          an optional unit name appended.  The unit name can be one
 
2102
          of "Hz", "kHz", "k", "MHz", "M".  The multiplier associ-
 
2103
          ated with the unit is stored in freq.units, and the
 
2104
          scaled frequency is stored in freq.freq.  When no unit is
 
2105
          specified, freq.units is set to 0, and freq.freq is
 
2106
          unscaled.
 
2107
 
 
2108
          Typical usage is to setup an array of OptionInfoRecs with
 
2109
          all fields initialised.  The value and found fields get
 
2110
          set by xf86ProcessOptions().  For cases where the value
 
2111
          parsing is more complex, the driver should specify
 
2112
          OPTV_STRING, and parse the string itself.  An example of
 
2113
          using this option handling is included in the Sample
 
2114
          Driver (section 20., page 1) section.
 
2115
 
 
2116
     void xf86ShowUnusedOptions(int scrnIndex, pointer options)
 
2117
 
 
2118
          Prints out warning messages for each option in the list
 
2119
          of options that isn't marked as used.  This is intended
 
2120
          to show options that the driver hasn't recognised.  It
 
2121
          would normally be called near the end of the Chip-
 
2122
          ScreenInit() function, but only when serverGenera-
 
2123
          tion == 1.
 
2124
 
 
2125
     OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table,
 
2126
 
 
2127
               int token)
 
2128
 
 
2129
          Returns a pointer to the OptionInfoRec in table with a
 
2130
          token field matching token.  Returns NULL if no match is
 
2131
          found.
 
2132
 
 
2133
     Bool xf86IsOptionSet(const OptionInfoRec *table, int token)
 
2134
 
 
2135
          Returns the found field of the OptionInfoRec in table
 
2136
          with a token field matching token.  This can be used for
 
2137
          options of all types.  Note that for options of type
 
2138
          OPTV_BOOLEAN, it isn't sufficient to check this to deter-
 
2139
          mine the value of the option.  Returns FALSE if no match
 
2140
          is found.
 
2141
 
 
2142
     char *xf86GetOptValString(const OptionInfoRec *table, int token)
 
2143
 
 
2144
          Returns the value.str field of the OptionInfoRec in table
 
2145
          with a token field matching token.  Returns NULL if no
 
2146
          match is found.
 
2147
 
 
2148
     Bool xf86GetOptValInteger(const OptionInfoRec *table, int token,
 
2149
 
 
2150
               int *value)
 
2151
 
 
2152
          Returns via *value the value.num field of the OptionIn-
 
2153
          foRec in table with a token field matching token.  *value
 
2154
          is only changed when a match is found so it can be safely
 
2155
          initialised with a default prior to calling this func-
 
2156
          tion.  The function return value is as for xf86IsOption-
 
2157
          Set().
 
2158
 
 
2159
     Bool xf86GetOptValULong(const OptionInfoRec *table, int token,
 
2160
 
 
2161
               unsigned long *value)
 
2162
 
 
2163
          Like xf86GetOptValInteger(), except the value is treated
 
2164
          as an unsigned long.
 
2165
 
 
2166
     Bool xf86GetOptValReal(const OptionInfoRec *table, int token,
 
2167
 
 
2168
               double *value)
 
2169
 
 
2170
          Like xf86GetOptValInteger(), except that value.realnum is
 
2171
          used.
 
2172
 
 
2173
     Bool xf86GetOptValFreq(const OptionInfoRec *table, int token,
 
2174
 
 
2175
               OptFreqUnits expectedUnits, double *value)
 
2176
 
 
2177
          Like xf86GetOptValInteger(), except that the value.freq
 
2178
          data is returned.  The frequency value is scaled to the
 
2179
          units indicated by expectedUnits.  The scaling is exact
 
2180
          when the units were specified explicitly in the option's
 
2181
          value.  Otherwise, the expectedUnits field is used as a
 
2182
          hint when doing the scaling.  In this case, values larger
 
2183
          than 1000 are assumed to have be specified in the next
 
2184
          smallest units.  For example, if the Option value is
 
2185
          "10000" and expectedUnits is OPTUNITS_MHZ, the value
 
2186
          returned is 10.
 
2187
 
 
2188
     Bool xf86GetOptValBool(const OptionInfoRec *table, int token, Bool
 
2189
     *value)
 
2190
 
 
2191
          This function is used to check boolean options
 
2192
          (OPTV_BOOLEAN).  If the function return value is FALSE,
 
2193
          it means the option wasn't set.  Otherwise *value is set
 
2194
          to the boolean value indicated by the option's value.  No
 
2195
          option value is interpreted as TRUE.  Option values mean-
 
2196
          ing TRUE are "1", "yes", "on", "true", and option values
 
2197
          meaning FALSE are "0", "no", "off", "false".  Option
 
2198
          names both with the "no" prefix in their names, and with
 
2199
          that prefix removed are also checked and handled in the
 
2200
          obvious way.  *value is not changed when the option isn't
 
2201
          present.  It should normally be set to a default value
 
2202
          before calling this function.
 
2203
 
 
2204
     Bool xf86ReturnOptValBool(const OptionInfoRec *table, int token,
 
2205
     Bool def)
 
2206
 
 
2207
          This function is used to check boolean options
 
2208
          (OPTV_BOOLEAN).  If the option is set, its value is
 
2209
          returned.  If the options is not set, the default value
 
2210
          specified by def is returned.  The option interpretation
 
2211
          is the same as for xf86GetOptValBool().
 
2212
 
 
2213
     int xf86NameCmp(const char *s1, const char *s2)
 
2214
 
 
2215
          This function should be used when comparing strings from
 
2216
          the config file with expected values.  It works like str-
 
2217
          cmp(), but is not case sensitive and space, tab, and `_'
 
2218
          characters are ignored in the comparison.  The use of
 
2219
          this function isn't restricted to parsing option values.
 
2220
          It may be used anywhere where this functionality
 
2221
          required.
 
2222
 
 
2223
11.  Modules, Drivers, Include Files and Interface Issues
 
2224
 
 
2225
NOTE: this section is incomplete.
 
2226
 
 
2227
11.1  Include files
 
2228
 
 
2229
The following include files are typically required by video drivers:
 
2230
 
 
2231
     All drivers should include these:
 
2232
 
 
2233
          "xf86.h"
 
2234
 
 
2235
          "xf86_OSproc.h"
 
2236
 
 
2237
          "xf86_ansic.h"
 
2238
 
 
2239
          "xf86Resources.h"
 
2240
 
 
2241
     Wherever inb/outb (and related things) are used the following
 
2242
     should be included:
 
2243
 
 
2244
          "compiler.h"
 
2245
 
 
2246
     Note: in drivers, this must be included after "xf86_ansic.h".
 
2247
 
 
2248
     Drivers that need to access PCI vendor/device definitions need
 
2249
     this:
 
2250
 
 
2251
          "xf86PciInfo.h"
 
2252
 
 
2253
     Drivers that need to access the PCI config space need this:
 
2254
 
 
2255
          "xf86Pci.h"
 
2256
 
 
2257
     Drivers that initialise a SW cursor need this:
 
2258
 
 
2259
          "mipointer.h"
 
2260
 
 
2261
     All drivers implementing backing store need this:
 
2262
 
 
2263
          "mibstore.h"
 
2264
 
 
2265
     All drivers using the mi colourmap code need this:
 
2266
 
 
2267
          "micmap.h"
 
2268
 
 
2269
     If a driver uses the vgahw module, it needs this:
 
2270
 
 
2271
          "vgaHW.h"
 
2272
 
 
2273
     Drivers supporting VGA or Hercules monochrome screens need:
 
2274
 
 
2275
          "xf1bpp.h"
 
2276
 
 
2277
     Drivers supporting VGA or EGC 16-colour screens need:
 
2278
 
 
2279
          "xf4bpp.h"
 
2280
 
 
2281
     Drivers using cfb need:
 
2282
 
 
2283
          #define PSZ 8
 
2284
 
 
2285
          #include "cfb.h"
 
2286
 
 
2287
          #undef PSZ
 
2288
 
 
2289
     Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
 
2290
 
 
2291
          "cfb16.h"
 
2292
 
 
2293
          "cfb24.h"
 
2294
 
 
2295
          "cfb32.h"
 
2296
 
 
2297
     If a driver uses XAA, it needs these:
 
2298
 
 
2299
          "xaa.h"
 
2300
 
 
2301
          "xaalocal.h"
 
2302
 
 
2303
     If a driver uses the fb manager, it needs this:
 
2304
 
 
2305
          "xf86fbman.h"
 
2306
 
 
2307
Non-driver modules should include "xf86_ansic.h" to get the correct wrapping
 
2308
of ANSI C/libc functions.
 
2309
 
 
2310
All modules must NOT include any system include files, or the following:
 
2311
 
 
2312
     "xf86Priv.h"
 
2313
 
 
2314
     "xf86Privstr.h"
 
2315
 
 
2316
     "xf86_OSlib.h"
 
2317
 
 
2318
     "Xos.h"
 
2319
 
 
2320
In addition, "xf86_libc.h" must not be included explicitly.  It is included
 
2321
implicitly by "xf86_ansic.h".
 
2322
 
 
2323
12.  Offscreen Memory Manager
 
2324
 
 
2325
Management of offscreen video memory may be handled by the XFree86 frame-
 
2326
buffer manager.  Once the offscreen memory manager is running, drivers or
 
2327
extensions may allocate, free or resize areas of offscreen video memory using
 
2328
the following functions (definitions taken from xf86fbman.h):
 
2329
 
 
2330
         typedef struct _FBArea {
 
2331
             ScreenPtr    pScreen;
 
2332
             BoxRec       box;
 
2333
             int          granularity;
 
2334
             void         (*MoveAreaCallback)(struct _FBArea*, struct _FBArea*)
 
2335
             void         (*RemoveAreaCallback)(struct _FBArea*)
 
2336
             DevUnion     devPrivate;
 
2337
         } FBArea, *FBAreaPtr;
 
2338
 
 
2339
         typedef void (*MoveAreaCallbackProcPtr)(FBAreaPtr from, FBAreaPtr to)
 
2340
         typedef void (*RemoveAreaCallbackProcPtr)(FBAreaPtr)
 
2341
 
 
2342
         FBAreaPtr xf86AllocateOffscreenArea (
 
2343
             ScreenPtr pScreen,
 
2344
             int width, int height,
 
2345
             int granularity,
 
2346
             MoveAreaCallbackProcPtr MoveAreaCallback,
 
2347
             RemoveAreaCallbackProcPtr RemoveAreaCallback,
 
2348
             pointer privData
 
2349
         )
 
2350
 
 
2351
         void xf86FreeOffscreenArea (FBAreaPtr area)
 
2352
 
 
2353
         Bool xf86ResizeOffscreenArea (
 
2354
          FBAreaPtr area
 
2355
          int w, int h
 
2356
         )
 
2357
 
 
2358
The function:
 
2359
 
 
2360
     Bool xf86FBManagerRunning(ScreenPtr pScreen)
 
2361
 
 
2362
can be used by an extension to check if the driver has initialized the memory
 
2363
manager.  The manager is not available if this returns FALSE and the func-
 
2364
tions above will all fail.
 
2365
 
 
2366
xf86AllocateOffscreenArea() can be used to request a rectangle of dimensions
 
2367
width x height (in pixels) from unused offscreen memory.  granularity speci-
 
2368
fies that the leftmost edge of the rectangle must lie on some multiple of
 
2369
granularity pixels.  A granularity of zero means the same thing as a granu-
 
2370
larity of one - no alignment preference.  A MoveAreaCallback can be provided
 
2371
to notify the requester when the offscreen area is moved.  If no MoveArea-
 
2372
Callback is supplied then the area is considered to be immovable.  The priv-
 
2373
Data field will be stored in the manager's internal structure for that allo-
 
2374
cated area and will be returned to the requester in the FBArea passed via the
 
2375
MoveAreaCallback.  An optional RemoveAreaCallback is provided.  If the driver
 
2376
provides this it indicates that the area should be allocated with a lower
 
2377
priority.  Such an area may be removed when a higher priority request (one
 
2378
that doesn't have a RemoveAreaCallback) is made.  When this function is
 
2379
called, the driver will have an opportunity to do whatever cleanup it needs
 
2380
to do to deal with the loss of the area, but it must finish its cleanup
 
2381
before the function exits since the offscreen memory manager will free the
 
2382
area immediately after.
 
2383
 
 
2384
xf86AllocateOffscreenArea() returns NULL if it was unable to allocate the
 
2385
requested area.  When no longer needed, areas should be freed with xf86Free-
 
2386
OffscreenArea().
 
2387
 
 
2388
xf86ResizeOffscreenArea() resizes an existing FBArea.  xf86ResizeOff-
 
2389
screenArea() returns TRUE if the resize was successful.  If xf86ResizeOff-
 
2390
screenArea() returns FALSE, the original FBArea is left unmodified.  Resizing
 
2391
an area maintains the area's original granularity, devPrivate, and MoveArea-
 
2392
Callback.  xf86ResizeOffscreenArea() has considerably less overhead than
 
2393
freeing the old area then reallocating the new size, so it should be used
 
2394
whenever possible.
 
2395
 
 
2396
The function:
 
2397
 
 
2398
     Bool xf86QueryLargestOffscreenArea(
 
2399
 
 
2400
               ScreenPtr pScreen,
 
2401
 
 
2402
               int *width, int *height,
 
2403
 
 
2404
               int granularity,
 
2405
 
 
2406
               int preferences,
 
2407
 
 
2408
               int priority
 
2409
 
 
2410
     )
 
2411
 
 
2412
is provided to query the width and height of the largest single FBArea allo-
 
2413
catable given a particular priority.  preferences can be one of the following
 
2414
to indicate whether width, height or area should be considered when determin-
 
2415
ing which is the largest single FBArea available.
 
2416
 
 
2417
     FAVOR_AREA_THEN_WIDTH
 
2418
 
 
2419
     FAVOR_AREA_THEN_HEIGHT
 
2420
 
 
2421
     FAVOR_WIDTH_THEN_AREA
 
2422
 
 
2423
     FAVOR_HEIGHT_THEN_AREA
 
2424
 
 
2425
priority is one of the following:
 
2426
 
 
2427
     PRIORITY_LOW
 
2428
 
 
2429
          Return the largest block available without stealing any-
 
2430
          one else's space.  This corresponds to the priority of
 
2431
          allocating a FBArea when a RemoveAreaCallback is pro-
 
2432
          vided.
 
2433
 
 
2434
     PRIORITY_NORMAL
 
2435
 
 
2436
          Return the largest block available if it is acceptable to
 
2437
          steal a lower priority area from someone.  This corre-
 
2438
          sponds to the priority of allocating a FBArea without
 
2439
          providing a RemoveAreaCallback.
 
2440
 
 
2441
     PRIORITY_EXTREME
 
2442
 
 
2443
          Return the largest block available if all FBAreas that
 
2444
          aren't locked down were expunged from memory first.  This
 
2445
          corresponds to any allocation made directly after a call
 
2446
          to xf86PurgeUnlockedOffscreenAreas().
 
2447
 
 
2448
The function:
 
2449
 
 
2450
     Bool xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
 
2451
 
 
2452
is provided as an extreme method to free up offscreen memory.  This will
 
2453
remove all removable FBArea allocations.
 
2454
 
 
2455
Initialization of the XFree86 framebuffer manager is done via
 
2456
 
 
2457
     Bool xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox)
 
2458
 
 
2459
FullBox represents the area of the framebuffer that the manager is allowed to
 
2460
manage.  This is typically a box with a width of pScrn->displayWidth and a
 
2461
height of as many lines as can be fit within the total video memory, however,
 
2462
the driver can reserve areas at the extremities by passing a smaller area to
 
2463
the manager.
 
2464
 
 
2465
xf86InitFBManager() must be called before XAA is initialized since XAA uses
 
2466
the manager for it's pixmap cache.
 
2467
 
 
2468
An alternative function is provided to allow the driver to initialize the
 
2469
framebuffer manager with a Region rather than a box.
 
2470
 
 
2471
     Bool xf86InitFBManagerRegion(ScreenPtr pScreen,
 
2472
 
 
2473
               RegionPtr FullRegion)
 
2474
 
 
2475
xf86InitFBManagerRegion(), unlike xf86InitFBManager(), does not remove the
 
2476
area used for the visible screen so that area should not be included in the
 
2477
region passed to the function.  xf86InitFBManagerRegion() is useful when non-
 
2478
contiguous areas are available to be managed, and is required when multiple
 
2479
framebuffers are stored in video memory (as in the case where an overlay of a
 
2480
different depth is stored as a second framebuffer in offscreen memory).
 
2481
 
 
2482
13.  Colormap Handling
 
2483
 
 
2484
A generic colormap handling layer is provided within the XFree86 common
 
2485
layer.  This layer takes care of most of the details, and only requires a
 
2486
function from the driver that loads the hardware palette when required.  To
 
2487
use the colormap layer, a driver calls the xf86HandleColormaps() function.
 
2488
 
 
2489
     Bool xf86HandleColormaps(ScreenPtr pScreen, int maxColors,
 
2490
 
 
2491
               int sigRGBbits, LoadPaletteFuncPtr loadPalette,
 
2492
 
 
2493
               SetOverscanFuncPtr setOverscan, unsigned int flags)
 
2494
 
 
2495
          This function must be called after the default colormap
 
2496
          has been initialised.  The pScrn->gamma field must also
 
2497
          be initialised, preferably by calling xf86SetGamma().
 
2498
          maxColors is the number of entries in the palette.
 
2499
          sigRGBbits is the size in bits of each color component in
 
2500
          the DAC's palette.  loadPalette is a driver-provided
 
2501
          function for loading a colormap into the hardware, and is
 
2502
          described below.  setOverscan is an optional function
 
2503
          that may be provided when the overscan color is an index
 
2504
          from the standard LUT and when it needs to be adjusted to
 
2505
          keep it as close to black as possible.  The setOverscan
 
2506
          function programs the overscan index.  It shouldn't nor-
 
2507
          mally be used for depths other than 8.  setOverscan
 
2508
          should be set to NULL when it isn't needed.  flags may be
 
2509
          set to the following (which may be ORed together):
 
2510
 
 
2511
          CMAP_PALETTED_TRUECOLOR
 
2512
 
 
2513
               the TrueColor visual is paletted and is just a
 
2514
               special case of DirectColor.  This flag is only
 
2515
               valid for bpp > 8.
 
2516
 
 
2517
          CMAP_RELOAD_ON_MODE_SWITCH
 
2518
 
 
2519
               reload the colormap automatically after mode
 
2520
               switches.  This is useful for when the driver
 
2521
               is resetting the hardware during mode switches
 
2522
               and corrupting or erasing the hardware palette.
 
2523
 
 
2524
          CMAP_LOAD_EVEN_IF_OFFSCREEN
 
2525
 
 
2526
               reload the colormap even if the screen is
 
2527
               switched out of the server's VC.  The palette
 
2528
               is not reloaded when the screen is switched
 
2529
               back in, nor after mode switches.  This is use-
 
2530
               ful when the driver needs to keep track of
 
2531
               palette changes.
 
2532
 
 
2533
          The colormap layer normally reloads the palette after VT
 
2534
          enters so it is not necessary for the driver to save and
 
2535
          restore the palette when switching VTs.  The driver must,
 
2536
          however, still save the initial palette during server
 
2537
          start up and restore it during server exit.
 
2538
 
 
2539
     void LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
 
2540
 
 
2541
               LOCO *colors, VisualPtr pVisual)
 
2542
 
 
2543
          LoadPalette() is a driver-provided function for loading a
 
2544
          colormap into hardware.  colors is the array of RGB val-
 
2545
          ues that represent the full colormap.  indices is a list
 
2546
          of index values into the colors array.  These indices
 
2547
          indicate the entries that need to be updated.  numColors
 
2548
          is the number of the indices to be updated.
 
2549
 
 
2550
     void SetOverscan(ScrnInfoPtr pScrn, int overscan)
 
2551
 
 
2552
          SetOverscan() is a driver-provided function for program-
 
2553
          ming the overscan index.  As described above, it is nor-
 
2554
          mally only appropriate for LUT modes where all colormap
 
2555
          entries are available for the display, but where one of
 
2556
          them is also used for the overscan (typically 8bpp for
 
2557
          VGA compatible LUTs).  It isn't required in cases where
 
2558
          the overscan area is never visible.
 
2559
 
 
2560
14.  DPMS Extension
 
2561
 
 
2562
Support code for the DPMS extension is included in the XFree86 common layer.
 
2563
This code provides an interface between the main extension code, and a means
 
2564
for drivers to initialise DPMS when they support it.  One function is avail-
 
2565
able to drivers to do this initialisation, and it is always available, even
 
2566
when the DPMS extension is not supported by the core server (in which case it
 
2567
returns a failure result).
 
2568
 
 
2569
     Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
 
2570
 
 
2571
          This function registers a driver's DPMS level programming
 
2572
          function set.  It also checks pScrn->options for the
 
2573
          "dpms" option, and when present marks DPMS as being
 
2574
          enabled for that screen.  The set function is called
 
2575
          whenever the DPMS level changes, and is used to program
 
2576
          the requested level.  flags is currently not used, and
 
2577
          should be 0.  If the initialisation fails for any reason,
 
2578
          including when there is no DPMS support in the core
 
2579
          server, the function returns FALSE.
 
2580
 
 
2581
Drivers that implement DPMS support must provide the following function, that
 
2582
gets called when the DPMS level is changed:
 
2583
 
 
2584
     void ChipDPMSSet(ScrnInfoPtr pScrn, int level, int flags)
 
2585
 
 
2586
          Program the DPMS level specified by level.  Valid values
 
2587
          of level are DPMSModeOn, DPMSModeStandby, DPMSModeSus-
 
2588
          pend, DPMSModeOff.  These values are defined in "exten-
 
2589
          sions/dpms.h".
 
2590
 
 
2591
15.  DGA Extension
 
2592
 
 
2593
Drivers can support the XFree86 Direct Graphics Architecture (DGA) by filling
 
2594
out a structure of function pointers and a list of modes and passing them to
 
2595
DGAInit.
 
2596
 
 
2597
     Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs,
 
2598
 
 
2599
               DGAModePtr modes, int num)
 
2600
 
 
2601
               /** The DGAModeRec **/
 
2602
 
 
2603
               typedef struct {
 
2604
                 int num;
 
2605
                 DisplayModePtr mode;
 
2606
                 int flags;
 
2607
                 int imageWidth;
 
2608
                 int imageHeight;
 
2609
                 int pixmapWidth;
 
2610
                 int pixmapHeight;
 
2611
                 int bytesPerScanline;
 
2612
                 int byteOrder;
 
2613
                 int depth;
 
2614
                 int bitsPerPixel;
 
2615
                 unsigned long red_mask;
 
2616
                 unsigned long green_mask;
 
2617
                 unsigned long blue_mask;
 
2618
                 int viewportWidth;
 
2619
                 int viewportHeight;
 
2620
                 int xViewportStep;
 
2621
                 int yViewportStep;
 
2622
                 int maxViewportX;
 
2623
                 int maxViewportY;
 
2624
                 int viewportFlags;
 
2625
                 int offset;
 
2626
                 unsigned char *address;
 
2627
                 int reserved1;
 
2628
                 int reserved2;
 
2629
               } DGAModeRec, *DGAModePtr;
 
2630
 
 
2631
          num
 
2632
 
 
2633
               Can be ignored.  The DGA DDX will assign these
 
2634
               numbers.
 
2635
 
 
2636
          mode
 
2637
 
 
2638
               A pointer to the DisplayModeRec for this mode.
 
2639
 
 
2640
          flags
 
2641
 
 
2642
               The following flags are defined and may be OR'd
 
2643
               together:
 
2644
 
 
2645
               DGA_CONCURRENT_ACCESS
 
2646
 
 
2647
                    Indicates that the driver supports
 
2648
                    concurrent graphics accelerator and
 
2649
                    linear framebuffer access.
 
2650
 
 
2651
               DGA_FILL_RECT
 
2652
 
 
2653
               DGA_BLIT_RECT
 
2654
 
 
2655
               DGA_BLIT_RECT_TRANS
 
2656
 
 
2657
                    Indicates that the driver supports
 
2658
                    the FillRect, BlitRect or BlitTran-
 
2659
                    sRect functions in this mode.
 
2660
 
 
2661
               DGA_PIXMAP_AVAILABLE
 
2662
 
 
2663
                    Indicates that Xlib may be used on
 
2664
                    the framebuffer.  This flag will usu-
 
2665
                    ally be set unless the driver wishes
 
2666
                    to prohibit this for some reason.
 
2667
 
 
2668
               DGA_INTERLACED
 
2669
 
 
2670
               DGA_DOUBLESCAN
 
2671
 
 
2672
                    Indicates that these are interlaced
 
2673
                    or double scan modes.
 
2674
 
 
2675
          imageWidth
 
2676
 
 
2677
          imageHeight
 
2678
 
 
2679
               These are the dimensions of the linear frame-
 
2680
               buffer accessible by the client.
 
2681
 
 
2682
          pixmapWidth
 
2683
 
 
2684
          pixmapHeight
 
2685
 
 
2686
               These are the dimensions of the area of the
 
2687
               framebuffer accessible by the graphics acceler-
 
2688
               ator.
 
2689
 
 
2690
          bytesPerScanline
 
2691
 
 
2692
               Pitch of the framebuffer in bytes.
 
2693
 
 
2694
          byteOrder
 
2695
 
 
2696
               Usually the same as pScrn->imageByteOrder.
 
2697
 
 
2698
          depth
 
2699
 
 
2700
               The depth of the framebuffer in this mode.
 
2701
 
 
2702
          bitsPerPixel
 
2703
 
 
2704
               The number of bits per pixel in this mode.
 
2705
 
 
2706
          red_mask
 
2707
 
 
2708
          green_mask
 
2709
 
 
2710
          blue_mask
 
2711
 
 
2712
               The RGB masks for this mode, if applicable.
 
2713
 
 
2714
          viewportWidth
 
2715
 
 
2716
          viewportHeight
 
2717
 
 
2718
               Dimensions of the visible part of the frame-
 
2719
               buffer.  Usually mode->HDisplay and mode->VDis-
 
2720
               play.
 
2721
 
 
2722
          xViewportStep
 
2723
 
 
2724
          yViewportStep
 
2725
 
 
2726
               The granularity of x and y viewport positions
 
2727
               that the driver supports in this mode.
 
2728
 
 
2729
          maxViewportX
 
2730
 
 
2731
          maxViewportY
 
2732
 
 
2733
               The maximum viewport position supported by the
 
2734
               driver in this mode.
 
2735
 
 
2736
          viewportFlags
 
2737
 
 
2738
               The following may be OR'd together:
 
2739
 
 
2740
               DGA_FLIP_IMMEDIATE
 
2741
 
 
2742
                    The driver supports immediate view-
 
2743
                    port changes.
 
2744
 
 
2745
               DGA_FLIP_RETRACE
 
2746
 
 
2747
                    The driver supports viewport changes
 
2748
                    at retrace.
 
2749
 
 
2750
          offset
 
2751
 
 
2752
               The offset into the linear framebuffer that
 
2753
               corresponds to pixel (0,0) for this mode.
 
2754
 
 
2755
          address
 
2756
 
 
2757
               The virtual address of the framebuffer as
 
2758
               mapped by the driver.  This is needed when
 
2759
               DGA_PIXMAP_AVAILABLE is set.
 
2760
 
 
2761
               /** The DGAFunctionRec **/
 
2762
 
 
2763
               typedef struct {
 
2764
                 Bool (*OpenFramebuffer)(
 
2765
                      ScrnInfoPtr pScrn,
 
2766
                      char **name,
 
2767
                      unsigned char **mem,
 
2768
                      int *size,
 
2769
                      int *offset,
 
2770
                      int *extra
 
2771
                 );
 
2772
                 void (*CloseFramebuffer)(ScrnInfoPtr pScrn);
 
2773
                 Bool (*SetMode)(ScrnInfoPtr pScrn, DGAModePtr pMode);
 
2774
                 void (*SetViewport)(ScrnInfoPtr pScrn, int x, int y, int flags);
 
2775
                 int  (*GetViewport)(ScrnInfoPtr pScrn);
 
2776
                 void (*Sync)(ScrnInfoPtr);
 
2777
                 void (*FillRect)(
 
2778
                      ScrnInfoPtr pScrn,
 
2779
                      int x, int y, int w, int h,
 
2780
                      unsigned long color
 
2781
                 );
 
2782
                 void (*BlitRect)(
 
2783
                      ScrnInfoPtr pScrn,
 
2784
                      int srcx, int srcy,
 
2785
                      int w, int h,
 
2786
                      int dstx, int dsty
 
2787
                 );
 
2788
                 void (*BlitTransRect)(
 
2789
                      ScrnInfoPtr pScrn,
 
2790
                      int srcx, int srcy,
 
2791
                      int w, int h,
 
2792
                      int dstx, int dsty,
 
2793
                      unsigned long color
 
2794
                 );
 
2795
               } DGAFunctionRec, *DGAFunctionPtr;
 
2796
 
 
2797
     Bool OpenFramebuffer (pScrn, name, mem, size, offset, extra)
 
2798
 
 
2799
          OpenFramebuffer() should pass the client everything it
 
2800
          needs to know to be able to open the framebuffer.  These
 
2801
          parameters are OS specific and their meanings are to be
 
2802
          interpreted by an OS specific client library.
 
2803
 
 
2804
          name
 
2805
 
 
2806
               The name of the device to open or NULL if there
 
2807
               is no special device to open.  A NULL name
 
2808
               tells the client that it should open whatever
 
2809
               device one would usually open to access physi-
 
2810
               cal memory.
 
2811
 
 
2812
          mem
 
2813
 
 
2814
               The physical address of the start of the frame-
 
2815
               buffer.
 
2816
 
 
2817
          size
 
2818
 
 
2819
               The size of the framebuffer in bytes.
 
2820
 
 
2821
          offset
 
2822
 
 
2823
               Any offset into the device, if applicable.
 
2824
 
 
2825
          flags
 
2826
 
 
2827
               Any additional information that the client may
 
2828
               need.  Currently, only the DGA_NEED_ROOT flag
 
2829
               is defined.
 
2830
 
 
2831
     void CloseFramebuffer (pScrn)
 
2832
 
 
2833
          CloseFramebuffer() merely informs the driver (if it even
 
2834
          cares) that client no longer needs to access the frame-
 
2835
          buffer directly.  This function is optional.
 
2836
 
 
2837
     Bool SetMode (pScrn, pMode)
 
2838
 
 
2839
          SetMode() tells the driver to initialize the mode passed
 
2840
          to it.  If pMode is NULL, then the driver should restore
 
2841
          the original pre-DGA mode.
 
2842
 
 
2843
     void SetViewport (pScrn, x, y, flags)
 
2844
 
 
2845
          SetViewport() tells the driver to make the upper left-
 
2846
          hand corner of the visible screen correspond to coordi-
 
2847
          nate (x,y) on the framebuffer.  Flags currently defined
 
2848
          are:
 
2849
 
 
2850
          DGA_FLIP_IMMEDIATE
 
2851
 
 
2852
               The viewport change should occur immediately.
 
2853
 
 
2854
          DGA_FLIP_RETRACE
 
2855
 
 
2856
               The viewport change should occur at the verti-
 
2857
               cal retrace, but this function should return
 
2858
               sooner if possible.
 
2859
 
 
2860
          The (x,y) locations will be passed as the client speci-
 
2861
          fied them, however, the driver is expected to round these
 
2862
          locations down to the next supported location as speci-
 
2863
          fied by the xViewportStep and yViewportStep for the cur-
 
2864
          rent mode.
 
2865
 
 
2866
     int GetViewport (pScrn)
 
2867
 
 
2868
          GetViewport() gets the current page flip status.  Set
 
2869
          bits in the returned int correspond to viewport change
 
2870
          requests still pending.  For instance, set bit zero if
 
2871
          the last SetViewport request is still pending, bit one if
 
2872
          the one before that is still pending, etc.
 
2873
 
 
2874
     void Sync (pScrn)
 
2875
 
 
2876
          This function should ensure that any graphics accelerator
 
2877
          operations have finished.  This function should not
 
2878
          return until the graphics accelerator is idle.
 
2879
 
 
2880
     void FillRect (pScrn, x, y, w, h, color)
 
2881
 
 
2882
          This optional function should fill a rectangle w � h
 
2883
          located at (x,y) in the given color.
 
2884
 
 
2885
     void BlitRect (pScrn, srcx, srcy, w, h, dstx, dsty)
 
2886
 
 
2887
          This optional function should copy an area w � h located
 
2888
          at (srcx,srcy) to location (dstx,dsty).  This function
 
2889
          will need to handle copy directions as appropriate.
 
2890
 
 
2891
     void BlitTransRect (pScrn, srcx, srcy, w, h, dstx, dsty, color)
 
2892
 
 
2893
          This optional function is the same as BlitRect except
 
2894
          that pixels in the source corresponding to the color key
 
2895
          color should be skipped.
 
2896
 
 
2897
16.  The XFree86 X Video Extension (Xv) Device Dependent Layer
 
2898
 
 
2899
XFree86 offers the X Video Extension which allows clients to treat video as
 
2900
any another primitive and ``Put'' video into drawables.  By default, the
 
2901
extension reports no video adaptors as being available since the DDX layer
 
2902
has not been initialized.  The driver can initialize the DDX layer by filling
 
2903
out one or more XF86VideoAdaptorRecs as described later in this document and
 
2904
passing a list of XF86VideoAdaptorPtr pointers to the following function:
 
2905
 
 
2906
     Bool xf86XVScreenInit(
 
2907
 
 
2908
               ScreenPtr pScreen,
 
2909
 
 
2910
               XF86VideoAdaptorPtr *adaptPtrs,
 
2911
 
 
2912
               int num)
 
2913
 
 
2914
After doing this, the extension will report video adaptors as being avail-
 
2915
able, providing the data in their respective XF86VideoAdaptorRecs was valid.
 
2916
xf86XVScreenInit() copies data from the structure passed to it so the driver
 
2917
may free it after the initialization.  At the moment, the DDX only supports
 
2918
rendering into Window drawables.  Pixmap rendering will be supported after a
 
2919
sufficient survey of suitable hardware is completed.
 
2920
 
 
2921
The XF86VideoAdaptorRec:
 
2922
 
 
2923
          typedef struct {
 
2924
               unsigned int type;
 
2925
               int flags;
 
2926
               char *name;
 
2927
               int nEncodings;
 
2928
               XF86VideoEncodingPtr pEncodings;
 
2929
               int nFormats;
 
2930
               XF86VideoFormatPtr pFormats;
 
2931
               int nPorts;
 
2932
               DevUnion *pPortPrivates;
 
2933
               int nAttributes;
 
2934
               XF86AttributePtr pAttributes;
 
2935
               int nImages;
 
2936
               XF86ImagePtr pImages;
 
2937
               PutVideoFuncPtr PutVideo;
 
2938
               PutStillFuncPtr PutStill;
 
2939
               GetVideoFuncPtr GetVideo;
 
2940
               GetStillFuncPtr GetStill;
 
2941
               StopVideoFuncPtr StopVideo;
 
2942
               SetPortAttributeFuncPtr SetPortAttribute;
 
2943
               GetPortAttributeFuncPtr GetPortAttribute;
 
2944
               QueryBestSizeFuncPtr QueryBestSize;
 
2945
               PutImageFuncPtr PutImage;
 
2946
               QueryImageAttributesFuncPtr QueryImageAttributes;
 
2947
          } XF86VideoAdaptorRec, *XF86VideoAdaptorPtr;
 
2948
 
 
2949
     Each adaptor will have its own XF86VideoAdaptorRec.  The fields are
 
2950
     as follows:
 
2951
 
 
2952
     type
 
2953
 
 
2954
          This can be any of the following flags OR'd together.
 
2955
 
 
2956
          XvInputMask XvOutputMask
 
2957
 
 
2958
               These refer to the target drawable and are sim-
 
2959
               ilar to a Window's class. XvInputMask indicates
 
2960
               that the adaptor can put video into a drawable.
 
2961
               XvOutputMask indicates that the adaptor can get
 
2962
               video from a drawable.
 
2963
 
 
2964
          XvVideoMask XvStillMask XvImageMask
 
2965
 
 
2966
               These indicate that the adaptor supports video,
 
2967
               still or image primitives respectively.
 
2968
 
 
2969
          XvWindowMask XvPixmapMask
 
2970
 
 
2971
               These indicate the types of drawables the adap-
 
2972
               tor is capable of rendering into.  At the
 
2973
               moment, Pixmap rendering is not supported and
 
2974
               the XvPixmapMask flag is ignored.
 
2975
 
 
2976
     flags
 
2977
 
 
2978
          Currently, the following flags are defined:
 
2979
 
 
2980
          VIDEO_NO_CLIPPING
 
2981
 
 
2982
               This indicates that the video adaptor does not
 
2983
               support clipping.  The driver will never
 
2984
               receive ``Put'' requests where less than the
 
2985
               entire area determined by drw_x, drw_y, drw_w
 
2986
               and drw_h is visible.  This flag does not apply
 
2987
               to ``Get'' requests.  Hardware that is inca-
 
2988
               pable of clipping ``Gets'' may punt or get the
 
2989
               extents of the clipping region passed to it.
 
2990
 
 
2991
          VIDEO_INVERT_CLIPLIST
 
2992
 
 
2993
               This indicates that the video driver requires
 
2994
               the clip list to contain the regions which are
 
2995
               obscured rather than the regions which are are
 
2996
               visible.
 
2997
 
 
2998
          VIDEO_OVERLAID_STILLS
 
2999
 
 
3000
               Implementing PutStill for hardware that does
 
3001
               video as an overlay can be awkward since it's
 
3002
               unclear how long to leave the video up for.
 
3003
               When this flag is set, StopVideo will be called
 
3004
               whenever the destination gets clipped or moved
 
3005
               so that the still can be left up until then.
 
3006
 
 
3007
          VIDEO_OVERLAID_IMAGES
 
3008
 
 
3009
               Same as VIDEO_OVERLAID_STILLS but for images.
 
3010
 
 
3011
          VIDEO_CLIP_TO_VIEWPORT
 
3012
 
 
3013
               Indicates that the clip region passed to the
 
3014
               driver functions should be clipped to the visi-
 
3015
               ble portion of the screen in the case where the
 
3016
               viewport is smaller than the virtual desktop.
 
3017
 
 
3018
     name
 
3019
 
 
3020
          The name of the adaptor.
 
3021
 
 
3022
     nEncodings
 
3023
 
 
3024
     pEncodings
 
3025
 
 
3026
          The number of encodings the adaptor is capable of and
 
3027
          pointer to the XF86VideoEncodingRec array.  The
 
3028
          XF86VideoEncodingRec is described later on.  For drivers
 
3029
          that only support XvImages there should be an encoding
 
3030
          named "XV_IMAGE" and the width and height should specify
 
3031
          the maximum size source image supported.
 
3032
 
 
3033
     nFormats
 
3034
 
 
3035
     pFormats
 
3036
 
 
3037
          The number of formats the adaptor is capable of and
 
3038
          pointer to the XF86VideoFormatRec array.  The XF86Video-
 
3039
          FormatRec is described later on.
 
3040
 
 
3041
     nPorts
 
3042
 
 
3043
     pPortPrivates
 
3044
 
 
3045
          The number of ports is the number of separate data
 
3046
          streams which the adaptor can handle simultaneously.  If
 
3047
          you have more than one port, the adaptor is expected to
 
3048
          be able to render into more than one window at a time.
 
3049
          pPortPrivates is an array of pointers or ints - one for
 
3050
          each port.  A port's private data will be passed to the
 
3051
          driver any time the port is requested to do something
 
3052
          like put the video or stop the video.  In the case where
 
3053
          there may be many ports, this enables the driver to know
 
3054
          which port the request is intended for.  Most commonly,
 
3055
          this will contain a pointer to the data structure con-
 
3056
          taining information about the port.  In Xv, all ports on
 
3057
          a particular adaptor are expected to be identical in
 
3058
          their functionality.
 
3059
 
 
3060
     nAttributes
 
3061
 
 
3062
     pAttributes
 
3063
 
 
3064
          The number of attributes recognized by the adaptor and a
 
3065
          pointer to the array of XF86AttributeRecs.  The
 
3066
          XF86AttributeRec is described later on.
 
3067
 
 
3068
     nImages
 
3069
 
 
3070
     pImages
 
3071
 
 
3072
          The number of XF86ImageRecs supported by the adaptor and
 
3073
          a pointer to the array of XF86ImageRecs. The XF86ImageRec
 
3074
          is described later on.
 
3075
 
 
3076
     PutVideo PutStill GetVideo GetStill StopVideo SetPortAttribute Get-
 
3077
     PortAttribute QueryBestSize PutImage QueryImageAttributes
 
3078
 
 
3079
          These functions define the DDX->driver interface.  In
 
3080
          each case, the pointer data is passed to the driver.
 
3081
          This is the port private for that port as described
 
3082
          above.  All fields are required except under the follow-
 
3083
          ing conditions:
 
3084
 
 
3085
            1.  PutVideo, PutStill and the image routines PutImage
 
3086
                and QueryImageAttributes are not required when the
 
3087
                adaptor type does not contain XvInputMask.
 
3088
 
 
3089
            2.  GetVideo and GetStill are not required when the
 
3090
                adaptor type does not contain XvOutputMask.
 
3091
 
 
3092
            3.  GetVideo and PutVideo are not required when the
 
3093
                adaptor type does not contain XvVideoMask.
 
3094
 
 
3095
            4.  GetStill and PutStill are not required when the
 
3096
                adaptor type does not contain XvStillMask.
 
3097
 
 
3098
            5.  PutImage and QueryImageAttributes are not required
 
3099
                when the adaptor type does not contain XvImageMask.
 
3100
 
 
3101
          With the exception of QueryImageAttributes, these func-
 
3102
          tions should return Success if the operation was com-
 
3103
          pleted successfully.  They can return XvBadAlloc other-
 
3104
          wise. QueryImageAttributes returns the size of the XvIm-
 
3105
          age queried.
 
3106
 
 
3107
          If the VIDEO_NO_CLIPPING flag is set, the clipBoxes may
 
3108
          be ignored by the driver.  ClipBoxes is an X-Y banded
 
3109
          region identical to those used throughout the server.
 
3110
          The clipBoxes represent the visible portions of the area
 
3111
          determined by drw_x, drw_y, drw_w and drw_h in the
 
3112
          Get/Put function.  The boxes are in screen coordinates,
 
3113
          are guaranteed not to overlap and an empty region will
 
3114
          never be passed.  If the driver has specified
 
3115
          VIDEO_INVERT_CLIPLIST, clipBoxes will indicate the areas
 
3116
          of the primitive which are obscured rather than the areas
 
3117
          visible.
 
3118
 
 
3119
     typedef  int (* PutVideoFuncPtr)( ScrnInfoPtr pScrn,
 
3120
 
 
3121
               short vid_x, short vid_y, short drw_x, short drw_y,
 
3122
 
 
3123
               short vid_w, short vid_h, short drw_w, short drw_h,
 
3124
 
 
3125
               RegionPtr clipBoxes, pointer data )
 
3126
 
 
3127
          This indicates that the driver should take a subsection
 
3128
          vid_w by vid_h at location (vid_x,vid_y) from the video
 
3129
          stream and direct it into the rectangle drw_w by drw_h at
 
3130
          location (drw_x,drw_y) on the screen, scaling as neces-
 
3131
          sary.  Due to the large variations in capabilities of the
 
3132
          various hardware expected to be used with this extension,
 
3133
          it is not expected that all hardware will be able to do
 
3134
          this exactly as described.  In that case the driver
 
3135
          should just do ``the best it can,'' scaling as closely to
 
3136
          the target rectangle as it can without rendering outside
 
3137
          of it.  In the worst case, the driver can opt to just not
 
3138
          turn on the video.
 
3139
 
 
3140
     typedef  int (* PutStillFuncPtr)( ScrnInfoPtr pScrn,
 
3141
 
 
3142
               short vid_x, short vid_y, short drw_x, short drw_y,
 
3143
 
 
3144
               short vid_w, short vid_h, short drw_w, short drw_h,
 
3145
 
 
3146
               RegionPtr clipBoxes, pointer data )
 
3147
 
 
3148
          This is same as PutVideo except that the driver should
 
3149
          place only one frame from the stream on the screen.
 
3150
 
 
3151
     typedef int (* GetVideoFuncPtr)( ScrnInfoPtr pScrn,
 
3152
 
 
3153
               short vid_x, short vid_y, short drw_x, short drw_y,
 
3154
 
 
3155
               short vid_w, short vid_h, short drw_w, short drw_h,
 
3156
 
 
3157
               RegionPtr clipBoxes, pointer data )
 
3158
 
 
3159
          This is same as PutVideo except that the driver gets
 
3160
          video from the screen and outputs it.  The driver should
 
3161
          do the best it can to get the requested dimensions cor-
 
3162
          rect without reading from an area larger than requested.
 
3163
 
 
3164
     typedef int (* GetStillFuncPtr)( ScrnInfoPtr pScrn,
 
3165
 
 
3166
               short vid_x, short vid_y, short drw_x, short drw_y,
 
3167
 
 
3168
               short vid_w, short vid_h, short drw_w, short drw_h,
 
3169
 
 
3170
               RegionPtr clipBoxes, pointer data )
 
3171
 
 
3172
          This is the same as GetVideo except that the driver
 
3173
          should place only one frame from the screen into the out-
 
3174
          put stream.
 
3175
 
 
3176
     typedef void (* StopVideoFuncPtr)(ScrnInfoPtr pScrn,
 
3177
 
 
3178
               pointer data, Bool cleanup)
 
3179
 
 
3180
          This indicates the driver should stop displaying the
 
3181
          video.  This is used to stop both input and output video.
 
3182
          The cleanup field indicates that the video is being
 
3183
          stopped because the client requested it to stop or
 
3184
          because the server is exiting the current VT.  In that
 
3185
          case the driver should deallocate any offscreen memory
 
3186
          areas (if there are any) being used to put the video to
 
3187
          the screen.  If cleanup is not set, the video is being
 
3188
          stopped temporarily due to clipping or moving of the win-
 
3189
          dow, etc...  and video will likely be restarted soon so
 
3190
          the driver should not deallocate any offscreen areas
 
3191
          associated with that port.
 
3192
 
 
3193
     typedef int (* SetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
 
3194
 
 
3195
               Atom attribute,INT32 value, pointer data)
 
3196
 
 
3197
     typedef int (* GetPortAttributeFuncPtr)(ScrnInfoPtr pScrn,
 
3198
 
 
3199
               Atom attribute,INT32 *value, pointer data)
 
3200
 
 
3201
          A port may have particular attributes such as hue, satu-
 
3202
          ration, brightness or contrast.  Xv clients set and get
 
3203
          these attribute values by sending attribute strings
 
3204
          (Atoms) to the server.  Such requests end up at these
 
3205
          driver functions.  It is recommended that the driver pro-
 
3206
          vide at least the following attributes mentioned in the
 
3207
          Xv client library docs:
 
3208
 
 
3209
               XV_ENCODING
 
3210
 
 
3211
               XV_HUE
 
3212
 
 
3213
               XV_SATURATION
 
3214
 
 
3215
               XV_BRIGHTNESS
 
3216
 
 
3217
               XV_CONTRAST
 
3218
 
 
3219
          but the driver may recognize as many atoms as it wishes.
 
3220
          If a requested attribute is unknown by the driver it
 
3221
          should return BadMatch.  XV_ENCODING is the attribute
 
3222
          intended to let the client specify which video encoding
 
3223
          the particular port should be using (see the description
 
3224
          of XF86VideoEncodingRec below).  If the requested encod-
 
3225
          ing is unsupported, the driver should return XvBadEncod-
 
3226
          ing.  If the value lies outside the advertised range Bad-
 
3227
          Value may be returned.  Success should be returned other-
 
3228
          wise.
 
3229
 
 
3230
     typedef void (* QueryBestSizeFuncPtr)(ScrnInfoPtr pScrn,
 
3231
 
 
3232
               Bool motion, short vid_w, short vid_h,
 
3233
 
 
3234
               short drw_w, short drw_h,
 
3235
 
 
3236
               unsigned int *p_w, unsigned int *p_h, pointer data)
 
3237
 
 
3238
          QueryBestSize provides the client with a way to query
 
3239
          what the destination dimensions would end up being if
 
3240
          they were to request that an area vid_w by vid_h from the
 
3241
          video stream be scaled to rectangle of drw_w by drw_h on
 
3242
          the screen.  Since it is not expected that all hardware
 
3243
          will be able to get the target dimensions exactly, it is
 
3244
          important that the driver provide this function.
 
3245
 
 
3246
     typedef  int (* PutImageFuncPtr)( ScrnInfoPtr pScrn,
 
3247
 
 
3248
               short src_x, short src_y, short drw_x, short drw_y,
 
3249
 
 
3250
               short src_w, short src_h, short drw_w, short drw_h,
 
3251
 
 
3252
               int image, char *buf, short width, short height,
 
3253
 
 
3254
               Bool sync, RegionPtr clipBoxes, pointer data )
 
3255
 
 
3256
          This is similar to PutStill except that the source of the
 
3257
          video is not a port but the data stored in a system mem-
 
3258
          ory buffer at buf.  The data is in the format indicated
 
3259
          by the image descriptor and represents a source of size
 
3260
          width by height.  If sync is TRUE the driver should not
 
3261
          return from this function until it is through reading the
 
3262
          data from buf.  Returning when sync is TRUE indicates
 
3263
          that it is safe for the data at buf to be replaced,
 
3264
          freed, or modified.
 
3265
 
 
3266
     typedef  int (* QueryImageAttributesFuncPtr)( ScrnInfoPtr pScrn,
 
3267
 
 
3268
               int image, short *width, short *height,
 
3269
 
 
3270
               int *pitches, int *offsets)
 
3271
 
 
3272
          This function is called to let the driver specify how
 
3273
          data for a particular image of size width by height
 
3274
          should be stored.  Sometimes only the size and corrected
 
3275
          width and height are needed.  In that case pitches and
 
3276
          offsets are NULL.  The size of the memory required for
 
3277
          the image is returned by this function.  The width and
 
3278
          height of the requested image can be altered by the
 
3279
          driver to reflect format limitations (such as component
 
3280
          sampling periods that are larger than one).  If pitches
 
3281
          and offsets are not NULL, these will be arrays with as
 
3282
          many elements in them as there are planes in the image
 
3283
          format.  The driver should specify the pitch (in bytes)
 
3284
          of each scanline in the particular plane as well as the
 
3285
          offset to that plane (in bytes) from the beginning of the
 
3286
          image.
 
3287
 
 
3288
The XF86VideoEncodingRec:
 
3289
 
 
3290
          typedef struct {
 
3291
               int id;
 
3292
               char *name;
 
3293
               unsigned short width, height;
 
3294
               XvRationalRec rate;
 
3295
          } XF86VideoEncodingRec, *XF86VideoEncodingPtr;
 
3296
 
 
3297
     The XF86VideoEncodingRec specifies what encodings the adaptor can
 
3298
     support.  Most of this data is just informational and for the
 
3299
     client's benefit, and is what will be reported by XvQueryEncodings.
 
3300
     The id field is expected to be a unique identifier to allow the
 
3301
     client to request a certain encoding via the XV_ENCODING attribute
 
3302
     string.
 
3303
 
 
3304
The XF86VideoFormatRec:
 
3305
 
 
3306
          typedef struct {
 
3307
               char  depth;
 
3308
               short class;
 
3309
          } XF86VideoFormatRec, *XF86VideoFormatPtr;
 
3310
 
 
3311
     This specifies what visuals the video is viewable in.  depth is the
 
3312
     depth of the visual (not bpp).  class is the visual class such as
 
3313
     TrueColor, DirectColor or PseudoColor.  Initialization of an adap-
 
3314
     tor will fail if none of the visuals on that screen are supported.
 
3315
 
 
3316
The XF86AttributeRec:
 
3317
 
 
3318
          typedef struct {
 
3319
               int   flags;
 
3320
               int   min_value;
 
3321
               int   max_value;
 
3322
               char  *name;
 
3323
          } XF86AttributeListRec, *XF86AttributeListPtr;
 
3324
     Each adaptor may have an array of these advertising the attributes
 
3325
     for its ports.  Currently defined flags are XvGettable and XvSet-
 
3326
     table which may be OR'd together indicating that attribute is
 
3327
     ``gettable'' or ``settable'' by the client.  The min and max field
 
3328
     specify the valid range for the value.  Name is a text string
 
3329
     describing the attribute by name.
 
3330
 
 
3331
The XF86ImageRec:
 
3332
 
 
3333
          typedef struct {
 
3334
               int id;
 
3335
               int type;
 
3336
               int byte_order;
 
3337
               char guid[16];
 
3338
               int bits_per_pixel;
 
3339
               int format;
 
3340
               int num_planes;
 
3341
 
 
3342
               /* for RGB formats */
 
3343
               int depth;
 
3344
               unsigned int red_mask;
 
3345
               unsigned int green_mask;
 
3346
               unsigned int blue_mask;
 
3347
 
 
3348
               /* for YUV formats */
 
3349
               unsigned int y_sample_bits;
 
3350
               unsigned int u_sample_bits;
 
3351
               unsigned int v_sample_bits;
 
3352
               unsigned int horz_y_period;
 
3353
               unsigned int horz_u_period;
 
3354
               unsigned int horz_v_period;
 
3355
               unsigned int vert_y_period;
 
3356
               unsigned int vert_u_period;
 
3357
               unsigned int vert_v_period;
 
3358
               char component_order[32];
 
3359
               int scanline_order;
 
3360
          } XF86ImageRec, *XF86ImagePtr;
 
3361
 
 
3362
     XF86ImageRec describes how video source data is laid out in memory.
 
3363
     The fields are as follows:
 
3364
 
 
3365
     id
 
3366
 
 
3367
          This is a unique descriptor for the format.  It is often
 
3368
          good to set this value to the FOURCC for the format when
 
3369
          applicable.
 
3370
 
 
3371
     type
 
3372
 
 
3373
          This is XvRGB or XvYUV.
 
3374
 
 
3375
     byte_order
 
3376
 
 
3377
          This is LSBFirst or MSBFirst.
 
3378
 
 
3379
     guid
 
3380
 
 
3381
          This is the Globally Unique IDentifier for the format.
 
3382
          When not applicable, all characters should be NULL.
 
3383
 
 
3384
     bits_per_pixel
 
3385
 
 
3386
          The number of bits taken up (but not necessarily used) by
 
3387
          each pixel.  Note that for some planar formats which have
 
3388
          fractional bits per pixel (such as IF09) this number may
 
3389
          be rounded _down_.
 
3390
 
 
3391
     format
 
3392
 
 
3393
          This is XvPlanar or XvPacked.
 
3394
 
 
3395
     num_planes
 
3396
 
 
3397
          The number of planes in planar formats.  This should be
 
3398
          set to one for packed formats.
 
3399
 
 
3400
     depth
 
3401
 
 
3402
          The significant bits per pixel in RGB formats (analgous
 
3403
          to the depth of a pixmap format).
 
3404
 
 
3405
     red_mask green_mask blue_mask
 
3406
 
 
3407
          The red, green and blue bitmasks for packed RGB formats.
 
3408
 
 
3409
     y_sample_bits u_sample_bits v_sample_bits
 
3410
 
 
3411
          The y, u and v sample sizes (in bits).
 
3412
 
 
3413
     horz_y_period horz_u_period horz_v_period
 
3414
 
 
3415
          The y, u and v sampling periods in the horizontal direc-
 
3416
          tion.
 
3417
 
 
3418
     vert_y_period vert_u_period vert_v_period
 
3419
 
 
3420
          The y, u and v sampling periods in the vertical direc-
 
3421
          tion.
 
3422
 
 
3423
     component_order
 
3424
 
 
3425
          Uppercase ascii characters representing the order that
 
3426
          samples are stored within packed formats.  For planar
 
3427
          formats this represents the ordering of the planes.
 
3428
          Unused characters in the 32 byte string should be set to
 
3429
          NULL.
 
3430
 
 
3431
     scanline_order
 
3432
 
 
3433
          This is XvTopToBottom or XvBottomToTop.
 
3434
 
 
3435
     Since some formats (particular some planar YUV formats) may not be
 
3436
     completely defined by the parameters above, the guid, when avail-
 
3437
     able, should provide the most accurate description of the format.
 
3438
 
 
3439
17.  The Loader
 
3440
 
 
3441
This section describes the interfaces to the module loader.  The loader
 
3442
interfaces can be divided into two groups: those that are only available to
 
3443
the XFree86 common layer, and those that are also available to modules.
 
3444
 
 
3445
17.1  Loader Overview
 
3446
 
 
3447
The loader is capable of loading modules in a range of object formats, and
 
3448
knowledge of these formats is built in to the loader.  Knowledge of new
 
3449
object formats can be added to the loader in a straightforward manner.  This
 
3450
makes it possible to provide OS-independent modules (for a given CPU archi-
 
3451
tecture type).  In addition to this, the loader can load modules via the OS-
 
3452
provided dlopen(3) service where available.  Such modules are not platform
 
3453
independent, and the semantics of dlopen() on most systems results in signif-
 
3454
icant limitations in the use of modules of this type.  Support for dlopen()
 
3455
modules in the loader is primarily for experimental and development purposes.
 
3456
 
 
3457
Symbols exported by the loader (on behalf of the core X server) to modules
 
3458
are determined at compile time.  Only those symbols explicitly exported are
 
3459
available to modules.  All external symbols of loaded modules are exported to
 
3460
other modules, and to the core X server.  The loader can be requested to
 
3461
check for unresolved symbols at any time, and the action to be taken for
 
3462
unresolved symbols can be controlled by the caller of the loader.  Typically
 
3463
the caller identifies which symbols can safely remain unresolved and which
 
3464
cannot.
 
3465
 
 
3466
NOTE:  Now that ISO-C allows pointers to functions and pointers to data to
 
3467
have different internal representations, some of the following interfaces
 
3468
will need to be revisited.
 
3469
 
 
3470
17.2  Semi-private Loader Interface
 
3471
 
 
3472
The following is the semi-private loader interface that is available to the
 
3473
XFree86 common layer.
 
3474
 
 
3475
     void LoaderInit(void)
 
3476
 
 
3477
          The LoaderInit() function initialises the loader, and it
 
3478
          must be called once before calling any other loader func-
 
3479
          tions.  This function initialises the tables of exported
 
3480
          symbols, and anything else that might need to be ini-
 
3481
          tialised.
 
3482
 
 
3483
     void LoaderSetPath(const char *path)
 
3484
 
 
3485
          The LoaderSetPath() function initialises a default module
 
3486
          search path.  This must be called if calls to other func-
 
3487
          tions are to be made without explicitly specifying a mod-
 
3488
          ule search path.  The search path path must be a string
 
3489
          of one or more comma separated absolute paths.  Modules
 
3490
          are expected to be located below these paths, possibly in
 
3491
          subdirectories of these paths.
 
3492
 
 
3493
     pointer LoadModule(const char *module, const char *path,
 
3494
 
 
3495
               const char **subdirlist, const char **patternlist,
 
3496
 
 
3497
               pointer options, const XF86ModReqInfo * modreq,
 
3498
 
 
3499
               int *errmaj, int *errmin)
 
3500
 
 
3501
          The LoadModule() function loads the module called module.
 
3502
          The return value is a module handle, and may be used in
 
3503
          future calls to the loader that require a reference to a
 
3504
          loaded module.  The module name module is normally the
 
3505
          module's canonical name, which doesn't contain any direc-
 
3506
          tory path information, or any object/library file pre-
 
3507
          fixes of suffixes.  Currently a full pathname and/or
 
3508
          filename is also accepted.  This might change.  The other
 
3509
          parameters are:
 
3510
 
 
3511
          path
 
3512
 
 
3513
               An optional comma-separated list of module
 
3514
               search paths.  When NULL, the default search
 
3515
               path is used.
 
3516
 
 
3517
          subdirlist
 
3518
 
 
3519
               An optional NULL terminated list of subdirecto-
 
3520
               ries to search.  When NULL, the default built-
 
3521
               in list is used (refer to stdSubdirs in load-
 
3522
               mod.c).  The default list is also substituted
 
3523
               for entries in subdirlist with the value
 
3524
               DEFAULT_LIST.  This makes is possible to aug-
 
3525
               ment the default list instead of replacing it.
 
3526
               Subdir elements must be relative, and must not
 
3527
               contain "..".  If any violate this requirement,
 
3528
               the load fails.
 
3529
 
 
3530
          patternlist
 
3531
 
 
3532
               An optional NULL terminated list of POSIX regu-
 
3533
               lar expressions used to connect module file-
 
3534
               names with canonical module names.  Each regex
 
3535
               should contain exactly one subexpression that
 
3536
               corresponds to the canonical module name.  When
 
3537
               NULL, the default built-in list is used (refer
 
3538
               to stdPatterns in loadmod.c).  The default list
 
3539
               is also substituted for entries in patternlist
 
3540
               with the value DEFAULT_LIST.  This makes it
 
3541
               possible to augment the default list instead of
 
3542
               replacing it.
 
3543
 
 
3544
          options
 
3545
 
 
3546
               An optional parameter that is passed to the
 
3547
               newly loaded module's SetupProc function (if it
 
3548
               has one).  This argument is normally a NULL
 
3549
               terminated list of Options, and must be inter-
 
3550
               preted that way by modules loaded directly by
 
3551
               the XFree86 common layer.  However, it may be
 
3552
               used for application-specific parameter passing
 
3553
               in other situations.
 
3554
 
 
3555
               When loading ``external'' modules (modules that
 
3556
               don't have the standard entry point, for exam-
 
3557
               ple a special shared library) the options
 
3558
               parameter can be set to EXTERN_MODULE to tell
 
3559
               the loader not to reject the module when it
 
3560
               doesn't find the standard entry point.
 
3561
 
 
3562
          modreq
 
3563
 
 
3564
               An optional XF86ModReqInfo* containing ver-
 
3565
               sion/ABI/vendor information to requirements to
 
3566
               check the newly loaded module against.  The
 
3567
               main purpose of this is to allow the loader to
 
3568
               verify that a module of the correct type/ver-
 
3569
               sion before running its SetupProc function.
 
3570
               The XF86ModReqInfo struct is defined as fol-
 
3571
               lows:
 
3572
 
 
3573
                    typedef struct {
 
3574
                         CARD8        majorversion;  /* MAJOR_UNSPEC */
 
3575
                         CARD8        minorversion;  /* MINOR_UNSPEC */
 
3576
                         CARD16       patchlevel;    /* PATCH_UNSPEC */
 
3577
                         const char * abiclass;      /* ABI_CLASS_NONE */
 
3578
                         CARD32       abiversion;    /* ABI_VERS_UNSPEC */
 
3579
                         const char * moduleclass;   /* MOD_CLASS_NONE */
 
3580
                    } XF86ModReqInfo;
 
3581
 
 
3582
               The information here is compared against the
 
3583
               equivalent information in the module's XF86Mod-
 
3584
               uleVersionInfo record (which is described
 
3585
               below).  The values in comments above indicate
 
3586
               ``don't care'' settings for each of the fields.
 
3587
               The comparisons made are as follows:
 
3588
 
 
3589
               majorversion
 
3590
 
 
3591
                    Must match the module's majorversion
 
3592
                    exactly.
 
3593
 
 
3594
               minorversion
 
3595
 
 
3596
                    The module's minor version must be no
 
3597
                    less than this value.  This compari-
 
3598
                    son is only made if majorversion is
 
3599
                    specified and matches.
 
3600
 
 
3601
               patchlevel
 
3602
 
 
3603
                    The module's patchlevel must be no
 
3604
                    less than this value.  This compari-
 
3605
                    son is only made if minorversion is
 
3606
                    specified and matches.
 
3607
 
 
3608
               abiclass
 
3609
 
 
3610
                    String must match the module's abi-
 
3611
                    class string.
 
3612
 
 
3613
               abiversion
 
3614
 
 
3615
                    Must be consistent with the module's
 
3616
                    abiversion (major equal, minor no
 
3617
                    older).
 
3618
 
 
3619
               moduleclass
 
3620
 
 
3621
                    String must match the module's mod-
 
3622
                    uleclass string.
 
3623
 
 
3624
          errmaj
 
3625
 
 
3626
               An optional pointer to a variable holding the
 
3627
               major part or the error code.  When provided,
 
3628
               *errmaj is filled in when LoadModule() fails.
 
3629
 
 
3630
          errmin
 
3631
 
 
3632
               Like errmaj, but for the minor part of the
 
3633
               error code.
 
3634
 
 
3635
     void UnloadModule(pointer mod)
 
3636
 
 
3637
          This function unloads the module referred to by the han-
 
3638
          dle mod.  All child modules are also unloaded recur-
 
3639
          sively.  This function must not be used to directly
 
3640
          unload modules that are child modules (i.e., those that
 
3641
          have been loaded with the LoadSubModule() described
 
3642
          below).
 
3643
 
 
3644
17.3  Module Requirements
 
3645
 
 
3646
Modules must provide information about themselves to the loader, and may
 
3647
optionally provide entry points for "setup" and "teardown" functions (those
 
3648
two functions are referred to here as SetupProc and TearDownProc).
 
3649
 
 
3650
The module information is contained in the XF86ModuleVersionInfo struct,
 
3651
which is defined as follows:
 
3652
 
 
3653
          typedef struct {
 
3654
              const char * modname;      /* name of module, e.g. "foo" */
 
3655
              const char * vendor;       /* vendor specific string */
 
3656
              CARD32       _modinfo1_;   /* constant MODINFOSTRING1/2 to find */
 
3657
              CARD32       _modinfo2_;   /* infoarea with a binary editor/sign tool */
 
3658
              CARD32       xf86version;  /* contains XF86_VERSION_CURRENT */
 
3659
              CARD8        majorversion; /* module-specific major version */
 
3660
              CARD8        minorversion; /* module-specific minor version */
 
3661
              CARD16       patchlevel;   /* module-specific patch level */
 
3662
              const char * abiclass;     /* ABI class that the module uses */
 
3663
              CARD32       abiversion;   /* ABI version */
 
3664
              const char * moduleclass;  /* module class */
 
3665
              CARD32       checksum[4];  /* contains a digital signature of the */
 
3666
                                         /* version info structure */
 
3667
          } XF86ModuleVersionInfo;
 
3668
 
 
3669
     The fields are used as follows:
 
3670
 
 
3671
     modname
 
3672
 
 
3673
          The module's name.  This field is currently only for
 
3674
          informational purposes, but the loader may be modified in
 
3675
          future to require it to match the module's canonical
 
3676
          name.
 
3677
 
 
3678
     vendor
 
3679
 
 
3680
          The module vendor.  This field is for informational pur-
 
3681
          poses only.
 
3682
 
 
3683
     _modinfo1_
 
3684
 
 
3685
          This field holds the first part of a signature that can
 
3686
          be used to locate this structure in the binary.  It
 
3687
          should always be initialised to MODINFOSTRING1.
 
3688
 
 
3689
     _modinfo2_
 
3690
 
 
3691
          This field holds the second part of a signature that can
 
3692
          be used to locate this structure in the binary.  It
 
3693
          should always be initialised to MODINFOSTRING2.
 
3694
 
 
3695
     xf86version
 
3696
 
 
3697
          The XFree86 version against which the module was com-
 
3698
          piled.  This is mostly for informational/diagnostic pur-
 
3699
          poses.  It should be initialised to XF86_VERSION_CURRENT,
 
3700
          which is defined in xf86Version.h.
 
3701
 
 
3702
     majorversion
 
3703
 
 
3704
          The module-specific major version.  For modules where
 
3705
          this version is used for more than simply informational
 
3706
          purposes, the major version should only change (be incre-
 
3707
          mented) when ABI incompatibilities are introduced, or ABI
 
3708
          components are removed.
 
3709
 
 
3710
     minorversion
 
3711
 
 
3712
          The module-specific minor version.  For modules where
 
3713
          this version is used for more than simply informational
 
3714
          purposes, the minor version should only change (be incre-
 
3715
          mented) when ABI additions are made in a backward compat-
 
3716
          ible way.  It should be reset to zero when the major ver-
 
3717
          sion is increased.
 
3718
 
 
3719
     patchlevel
 
3720
 
 
3721
          The module-specific patch level.  The patch level should
 
3722
          increase with new revisions of the module where there are
 
3723
          no ABI changes, and it should be reset to zero when the
 
3724
          minor version is increased.
 
3725
 
 
3726
     abiclass
 
3727
 
 
3728
          The ABI class that the module requires.  The class is
 
3729
          specified as a string for easy extensibility.  It should
 
3730
          indicate which (if any) of the X server's built-in ABI
 
3731
          classes that the module relies on, or a third-party ABI
 
3732
          if appropriate.  Built-in ABI classes currently defined
 
3733
          are:
 
3734
               ABI_CLASS_NONE
 
3735
                    no class
 
3736
 
 
3737
               ABI_CLASS_ANSIC
 
3738
 
 
3739
                    only requires the ANSI C interfaces
 
3740
 
 
3741
               ABI_CLASS_VIDEODRV
 
3742
 
 
3743
                    requires the video driver ABI
 
3744
 
 
3745
               ABI_CLASS_XINPUT
 
3746
 
 
3747
                    requires the XInput driver ABI
 
3748
 
 
3749
               ABI_CLASS_EXTENSION
 
3750
 
 
3751
                    requires the extension module ABI
 
3752
 
 
3753
               ABI_CLASS_FONT
 
3754
 
 
3755
                    requires the font module ABI
 
3756
 
 
3757
     abiversion
 
3758
 
 
3759
          The version of abiclass that the module requires.  The
 
3760
          version consists of major and minor components.  The
 
3761
          major version must match and the minor version must be no
 
3762
          newer than that provided by the server or parent module.
 
3763
          Version identifiers for the built-in classes currently
 
3764
          defined are:
 
3765
               ABI_ANSIC_VERSION
 
3766
 
 
3767
               ABI_VIDEODRV_VERSION
 
3768
 
 
3769
               ABI_XINPUT_VERSION
 
3770
 
 
3771
               ABI_EXTENSION_VERSION
 
3772
 
 
3773
               ABI_FONT_VERSION
 
3774
 
 
3775
     moduleclass
 
3776
 
 
3777
          This is similar to the abiclass field, except that it
 
3778
          defines the type of module rather than the ABI it
 
3779
          requires.  For example, although all video drivers
 
3780
          require the video driver ABI, not all modules that
 
3781
          require the video driver ABI are video drivers.  This
 
3782
          distinction can be made with the moduleclass.  Currently
 
3783
          pre-defined module classes are:
 
3784
 
 
3785
               MOD_CLASS_NONE
 
3786
 
 
3787
               MOD_CLASS_VIDEODRV
 
3788
 
 
3789
               MOD_CLASS_XINPUT
 
3790
 
 
3791
               MOD_CLASS_FONT
 
3792
 
 
3793
               MOD_CLASS_EXTENSION
 
3794
 
 
3795
     checksum
 
3796
 
 
3797
          Not currently used.
 
3798
 
 
3799
The module version information, and the optional SetupProc and TearDownProc
 
3800
entry points are found by the loader by locating a data object in the module
 
3801
called "modnameModuleData", where "modname" is the canonical name of the mod-
 
3802
ule.  Modules must contain such a data object, and it must be declared with
 
3803
global scope, be compile-time initialised, and is of the following type:
 
3804
 
 
3805
          typedef struct {
 
3806
              XF86ModuleVersionInfo *     vers;
 
3807
              ModuleSetupProc             setup;
 
3808
              ModuleTearDownProc          teardown;
 
3809
          } XF86ModuleData;
 
3810
 
 
3811
The vers parameter must be initialised to a pointer to a correctly ini-
 
3812
tialised XF86ModuleVersionInfo struct.  The other two parameter are optional,
 
3813
and should be initialised to NULL when not required.  The other parameters
 
3814
are defined as
 
3815
 
 
3816
     typedef pointer (*ModuleSetupProc)(pointer, pointer, int *, int *)
 
3817
 
 
3818
     typedef void (*ModuleTearDownProc)(pointer)
 
3819
 
 
3820
     pointer SetupProc(pointer module, pointer options,
 
3821
 
 
3822
               int *errmaj, int *errmin)
 
3823
 
 
3824
          When defined, this function is called by the loader after
 
3825
          successfully loading a module.  module is a handle for
 
3826
          the newly loaded module, and maybe used by the SetupProc
 
3827
          if it calls other loader functions that require a refer-
 
3828
          ence to it.   The remaining arguments are those that were
 
3829
          passed to the LoadModule() (or LoadSubModule()), and are
 
3830
          described above. When the SetupProc is successful it must
 
3831
          return a non-NULL value.  The loader checks this, and if
 
3832
          it is NULL it unloads the module and reports the failure
 
3833
          to the caller of LoadModule().  If the SetupProc does
 
3834
          things that need to be undone when the module is
 
3835
          unloaded, it should define a TearDownProc, and return a
 
3836
          pointer that the TearDownProc can use to undo what has
 
3837
          been done.
 
3838
 
 
3839
          When a module is loaded multiple times, the SetupProc is
 
3840
          called once for each time it is loaded.
 
3841
 
 
3842
     void TearDownProc(pointer tearDownData)
 
3843
 
 
3844
          When defined, this function is called when the loader
 
3845
          unloads a module.  The tearDownData parameter is the
 
3846
          return value of the SetupProc() that was called when the
 
3847
          module was loaded.  The purpose of this function is to
 
3848
          clean up before the module is unloaded (for example, by
 
3849
          freeing allocated resources).
 
3850
 
 
3851
17.4  Public Loader Interface
 
3852
 
 
3853
The following is the Loader interface that is available to any part of the
 
3854
server, and may also be used from within modules.
 
3855
 
 
3856
     pointer LoadSubModule(pointer parent, const char *module,
 
3857
 
 
3858
               const char **subdirlist, const char **patternlist,
 
3859
 
 
3860
               pointer options, const XF86ModReqInfo * modreq,
 
3861
 
 
3862
               int *errmaj, int *errmin)
 
3863
 
 
3864
          This function is like the LoadModule() function described
 
3865
          above, except that the module loaded is registered as a
 
3866
          child of the calling module.  The parent parameter is the
 
3867
          calling module's handle.  Modules loaded with this func-
 
3868
          tion are automatically unloaded when the parent module is
 
3869
          unloaded.  The other difference is that the path parame-
 
3870
          ter may not be specified.  The module search path used
 
3871
          for modules loaded with this function is the default
 
3872
          search path as initialised with LoaderSetPath().
 
3873
 
 
3874
     void UnloadSubModule(pointer module)
 
3875
 
 
3876
          This function unloads the module with handle module.  If
 
3877
          that module itself has children, they are also unloaded.
 
3878
          It is like UnloadModule(), except that it is safe to use
 
3879
          for unloading child modules.
 
3880
 
 
3881
     pointer LoaderSymbol(const char *symbol)
 
3882
 
 
3883
          This function returns the address of the symbol with name
 
3884
          symbol.  This may be used to locate a module entry point
 
3885
          with a known name.
 
3886
 
 
3887
     char **LoaderlistDirs(const char **subdirlist,
 
3888
 
 
3889
               const char **patternlist)
 
3890
 
 
3891
          This function returns a NULL terminated list of canonical
 
3892
          modules names for modules found in the default module
 
3893
          search path.  The subdirlist and patternlist parameters
 
3894
          are as described above, and can be used to control the
 
3895
          locations and names that are searched.  If no modules are
 
3896
          found, the return value is NULL.  The returned list
 
3897
          should be freed by calling LoaderFreeDirList() when it is
 
3898
          no longer needed.
 
3899
 
 
3900
     void LoaderFreeDirList(char **list)
 
3901
 
 
3902
          This function frees a module list created by Loaderlist-
 
3903
          Dirs().
 
3904
 
 
3905
     void LoaderReqSymLists(const char **list0, ...)
 
3906
 
 
3907
          This function allows the registration of required symbols
 
3908
          with the loader.  It is normally used by a caller of
 
3909
          LoadSubModule().  If any symbols registered in this way
 
3910
          are found to be unresolved when LoaderCheckUnresolved()
 
3911
          is called then LoaderCheckUnresolved() will report a
 
3912
          failure.  The function takes one or more NULL terminated
 
3913
          lists of symbols.  The end of the argument list is indi-
 
3914
          cated by a NULL argument.
 
3915
 
 
3916
     void LoaderReqSymbols(const char *sym0, ...)
 
3917
 
 
3918
          This function is like LoaderReqSymLists() except that its
 
3919
          arguments are symbols rather than lists of symbols.  This
 
3920
          function is more convenient when single functions are to
 
3921
          be registered, especially when the single function might
 
3922
          depend on runtime factors.  The end of the argument list
 
3923
          is indicated by a NULL argument.
 
3924
 
 
3925
     void LoaderRefSymLists(const char **list0, ...)
 
3926
 
 
3927
          This function allows the registration of possibly unre-
 
3928
          solved symbols with the loader.  When LoaderCheckUnre-
 
3929
          solved() is run it won't generate warnings for symbols
 
3930
          registered in this way unless they were also registered
 
3931
          as required symbols.  The function takes one or more NULL
 
3932
          terminated lists of symbols.  The end of the argument
 
3933
          list is indicated by a NULL argument.
 
3934
 
 
3935
     void LoaderRefSymbols(const char *sym0, ...)
 
3936
 
 
3937
          This function is like LoaderRefSymLists() except that its
 
3938
          arguments are symbols rather than lists of symbols.  This
 
3939
          function is more convenient when single functions are to
 
3940
          be registered, especially when the single function might
 
3941
          depend on runtime factors.  The end of the argument list
 
3942
          is indicated by a NULL argument.
 
3943
 
 
3944
     int LoaderCheckUnresolved(int delayflag)
 
3945
 
 
3946
          This function checks for unresolved symbols.  It gener-
 
3947
          ates warnings for unresolved symbols that have not been
 
3948
          registered with LoaderRefSymLists(), and maps them to a
 
3949
          dummy function.  This behaviour may change in future.  If
 
3950
          unresolved symbols are found that have been registered
 
3951
          with LoaderReqSymLists() or LoaderReqSymbols() then this
 
3952
          function returns a non-zero value.  If none of these sym-
 
3953
          bols are unresolved the return value is zero, indicating
 
3954
          success.
 
3955
 
 
3956
          The delayflag parameter should normally be set to
 
3957
          LD_RESOLV_IFDONE.
 
3958
 
 
3959
     LoaderErrorMsg(const char *name, const char *modname,
 
3960
 
 
3961
               int errmaj, int errmin)
 
3962
 
 
3963
          This function prints an error message that includes the
 
3964
          text ``Failed to load module'', the module name modname,
 
3965
          a message specific to the errmaj value, and the value if
 
3966
          errmin.  If name is non-NULL, it is printed as an identi-
 
3967
          fying prefix to the message (followed by a `:').
 
3968
 
 
3969
17.5  Special Registration Functions
 
3970
 
 
3971
The loader contains some functions for registering some classes of modules.
 
3972
These may be moved out of the loader at some point.
 
3973
 
 
3974
     void LoadExtension(ExtensionModule *ext)
 
3975
 
 
3976
          This registers the entry points for the extension identi-
 
3977
          fied by ext.  The ExtensionModule struct is defined as:
 
3978
 
 
3979
                    typedef struct {
 
3980
                        InitExtension       initFunc;
 
3981
                        char *              name;
 
3982
                        Bool                *disablePtr;
 
3983
                        InitExtension       setupFunc;
 
3984
                    } ExtensionModule;
 
3985
 
 
3986
     void LoadFont(FontModule *font)
 
3987
 
 
3988
          This registers the entry points for the font rasteriser
 
3989
          module identified by font.  The FontModule struct is
 
3990
          defined as:
 
3991
 
 
3992
                    typedef struct {
 
3993
                        InitFont    initFunc;
 
3994
                        char *      name;
 
3995
                        pointer     module;
 
3996
                    } FontModule;
 
3997
 
 
3998
18.  Helper Functions
 
3999
 
 
4000
This section describe ``helper'' functions that video driver might find use-
 
4001
ful.  While video drivers are not required to use any of these to be consid-
 
4002
ered ``compliant'', the use of appropriate helpers is strongly encouraged to
 
4003
improve the consistency of driver behaviour.
 
4004
 
 
4005
18.1  Functions for printing messages
 
4006
 
 
4007
     ErrorF(const char *format, ...)
 
4008
 
 
4009
          This is the basic function for writing to the error log
 
4010
          (typically stderr and/or a log file).  Video drivers
 
4011
          should usually avoid using this directly in favour of the
 
4012
          more specialised functions described below.  This func-
 
4013
          tion is useful for printing messages while debugging a
 
4014
          driver.
 
4015
 
 
4016
     FatalError(const char *format, ...)
 
4017
 
 
4018
          This prints a message and causes the Xserver to abort.
 
4019
          It should rarely be used within a video driver, as most
 
4020
          error conditions should be flagged by the return values
 
4021
          of the driver functions.  This allows the higher layers
 
4022
          to decide how to proceed.  In rare cases, this can be
 
4023
          used within a driver if a fatal unexpected condition is
 
4024
          found.
 
4025
 
 
4026
     xf86ErrorF(const char *format, ...)
 
4027
 
 
4028
          This is like ErrorF(), except that the message is only
 
4029
          printed when the Xserver's verbosity level is set to the
 
4030
          default (1) or higher.  It means that the messages are
 
4031
          not printed when the server is started with the -quiet
 
4032
          flag.  Typically this function would only be used for
 
4033
          continuing messages started with one of the more spe-
 
4034
          cialised functions described below.
 
4035
 
 
4036
     xf86ErrorFVerb(int verb, const char *format, ...)
 
4037
 
 
4038
          Like xf86ErrorF(), except the minimum verbosity level for
 
4039
          which the message is to be printed is given explicitly.
 
4040
          Passing a verb value of zero means the message is always
 
4041
          printed.  A value higher than 1 can be used for informa-
 
4042
          tion would normally not be needed, but which might be
 
4043
          useful when diagnosing problems.
 
4044
 
 
4045
     xf86Msg(MessageType type, const char *format, ...)
 
4046
 
 
4047
          This is like xf86ErrorF(), except that the message is
 
4048
          prefixed with a marker determined by the value of type.
 
4049
          The marker is used to indicate the type of message (warn-
 
4050
          ing, error, probed value, config value, etc).  Note the
 
4051
          xf86Verbose value is ignored for messages of type
 
4052
          X_ERROR.
 
4053
 
 
4054
          The marker values are:
 
4055
 
 
4056
               X_PROBED
 
4057
 
 
4058
                    Value was probed.
 
4059
 
 
4060
               X_CONFIG
 
4061
 
 
4062
                    Value was given in the config file.
 
4063
 
 
4064
               X_DEFAULT
 
4065
 
 
4066
                    Value is a default.
 
4067
 
 
4068
               X_CMDLINE
 
4069
 
 
4070
                    Value was given on the command line.
 
4071
 
 
4072
               X_NOTICE
 
4073
 
 
4074
                    Notice.
 
4075
 
 
4076
               X_ERROR
 
4077
 
 
4078
                    Error message.
 
4079
 
 
4080
               X_WARNING
 
4081
 
 
4082
                    Warning message.
 
4083
 
 
4084
               X_INFO
 
4085
 
 
4086
                    Informational message.
 
4087
 
 
4088
               X_NONE
 
4089
 
 
4090
                    No prefix.
 
4091
 
 
4092
               X_NOT_IMPLEMENTED
 
4093
 
 
4094
                    The message relates to functionality
 
4095
                    that is not yet implemented.
 
4096
 
 
4097
     xf86MsgVerb(MessageType type, int verb, const char *format, ...)
 
4098
 
 
4099
          Like xf86Msg(), but with the verbosity level given
 
4100
          explicitly.
 
4101
 
 
4102
     xf86DrvMsg(int scrnIndex, MessageType type, const char *format,
 
4103
     ...)
 
4104
 
 
4105
          This is like xf86Msg() except that the driver's name (the
 
4106
          name field of the ScrnInfoRec) followed by the scrnIndex
 
4107
          in parentheses is printed following the prefix.  This
 
4108
          should be used by video drivers in most cases as it
 
4109
          clearly indicates which driver/screen the message is for.
 
4110
          If scrnIndex is negative, this function behaves exactly
 
4111
          like xf86Msg().
 
4112
          NOTE: This function can only be used after the ScrnIn-
 
4113
          foRec and its name field have been allocated.  Normally,
 
4114
          this means that it can not be used before the END of the
 
4115
          ChipProbe() function.  Prior to that, use xf86Msg(), pro-
 
4116
          viding the driver's name explicitly.  No screen number
 
4117
          can be supplied at that point.
 
4118
 
 
4119
     xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb,
 
4120
 
 
4121
               const char *format, ...)
 
4122
 
 
4123
          Like xf86DrvMsg(), but with the verbosity level given
 
4124
          explicitly.
 
4125
 
 
4126
18.2  Functions for setting values based on command line and config file
 
4127
 
 
4128
     Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp,
 
4129
 
 
4130
               int fbbpp, int depth24flags)
 
4131
 
 
4132
          This function sets the depth, pixmapBPP and bitsPerPixel
 
4133
          fields of the ScrnInfoRec.  It also determines the
 
4134
          defaults for display-wide attributes and pixmap formats
 
4135
          the screen will support, and finds the Display subsection
 
4136
          that matches the depth/bpp.  This function should nor-
 
4137
          mally be called very early from the ChipPreInit() func-
 
4138
          tion.
 
4139
          It requires that the confScreen field of the ScrnInfoRec
 
4140
          be initialised prior to calling it.  This is done by the
 
4141
          XFree86 common layer prior to calling ChipPreInit().
 
4142
 
 
4143
          The parameters passed are:
 
4144
 
 
4145
          depth
 
4146
 
 
4147
               driver's preferred default depth if no other is
 
4148
               given.  If zero, use the overall server
 
4149
               default.
 
4150
 
 
4151
          bpp
 
4152
 
 
4153
               Same, but for the pixmap bpp.
 
4154
 
 
4155
          fbbpp
 
4156
 
 
4157
               Same, but for the framebuffer bpp.
 
4158
 
 
4159
          depth24flags
 
4160
 
 
4161
               Flags that indicate the level of 24/32bpp sup-
 
4162
               port and whether conversion between different
 
4163
               framebuffer and pixmap formats is supported.
 
4164
               The flags for this argument are defined as fol-
 
4165
               lows, and multiple flags may be ORed together:
 
4166
 
 
4167
               NoDepth24Support
 
4168
                    No depth 24 formats supported
 
4169
 
 
4170
               Support24bppFb
 
4171
 
 
4172
                    24bpp framebuffer supported
 
4173
 
 
4174
               Support32bppFb
 
4175
 
 
4176
                    32bpp framebuffer supported
 
4177
 
 
4178
               SupportConvert24to32
 
4179
 
 
4180
                    Can convert 24bpp pixmap to 32bpp fb
 
4181
 
 
4182
               SupportConvert32to24
 
4183
 
 
4184
                    Can convert 32bpp pixmap to 24bpp fb
 
4185
 
 
4186
               ForceConvert24to32
 
4187
 
 
4188
                    Force 24bpp pixmap to 32bpp fb con-
 
4189
                    version
 
4190
 
 
4191
               ForceConvert32to24
 
4192
 
 
4193
                    Force 32bpp pixmap to 24bpp fb con-
 
4194
                    version
 
4195
 
 
4196
          It uses the command line, config file, and default values
 
4197
          in the correct order of precedence to determine the depth
 
4198
          and bpp values.  It is up to the driver to check the
 
4199
          results to see that it supports them.  If not the Chip-
 
4200
          PreInit() function should return FALSE.
 
4201
 
 
4202
          If only one of depth/bpp is given, the other is set to a
 
4203
          reasonable (and consistent) default.
 
4204
 
 
4205
          If a driver finds that the initial depth24flags it uses
 
4206
          later results in a fb format that requires more video
 
4207
          memory than is available it may call this function a sec-
 
4208
          ond time with a different depth24flags setting.
 
4209
 
 
4210
          On success, the return value is TRUE.  On failure it
 
4211
          prints an error message and returns FALSE.
 
4212
 
 
4213
          The following fields of the ScrnInfoRec are initialised
 
4214
          by this function:
 
4215
 
 
4216
               depth, bitsPerPixel, display, imageByteOrder,
 
4217
               bitmapScanlinePad, bitmapScanlineUnit, bitmap-
 
4218
               BitOrder, numFormats, formats, fbFormat.
 
4219
 
 
4220
     void xf86PrintDepthBpp(scrnInfoPtr scrp)
 
4221
 
 
4222
          This function can be used to print out the depth and bpp
 
4223
          settings.  It should be called after the final call to
 
4224
          xf86SetDepthBpp().
 
4225
 
 
4226
     Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask)
 
4227
 
 
4228
          This function sets the weight, mask, offset and rgbBits
 
4229
          fields of the ScrnInfoRec.  It would normally be called
 
4230
          fairly early in the ChipPreInit() function for
 
4231
          depths > 8bpp.
 
4232
 
 
4233
          It requires that the depth and display fields of the
 
4234
          ScrnInfoRec be initialised prior to calling it.
 
4235
          The parameters passed are:
 
4236
 
 
4237
          weight
 
4238
 
 
4239
               driver's preferred default weight if no other
 
4240
               is given.  If zero, use the overall server
 
4241
               default.
 
4242
 
 
4243
          mask
 
4244
 
 
4245
               Same, but for mask.
 
4246
 
 
4247
          It uses the command line, config file, and default values
 
4248
          in the correct order of precedence to determine the
 
4249
          weight value.  It derives the mask and offset values from
 
4250
          the weight and the defaults.  It is up to the driver to
 
4251
          check the results to see that it supports them.  If not
 
4252
          the ChipPreInit() function should return FALSE.
 
4253
 
 
4254
          On success, this function prints a message showing the
 
4255
          weight values selected, and returns TRUE.
 
4256
 
 
4257
          On failure it prints an error message and returns FALSE.
 
4258
 
 
4259
          The following fields of the ScrnInfoRec are initialised
 
4260
          by this function:
 
4261
 
 
4262
               weight, mask, offset.
 
4263
 
 
4264
     Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual)
 
4265
 
 
4266
          This function sets the defaultVisual field of the ScrnIn-
 
4267
          foRec.  It would normally be called fairly early from the
 
4268
          ChipPreInit() function.
 
4269
 
 
4270
          It requires that the depth and display fields of the
 
4271
          ScrnInfoRec be initialised prior to calling it.
 
4272
 
 
4273
          The parameters passed are:
 
4274
 
 
4275
          visual
 
4276
 
 
4277
               driver's preferred default visual if no other
 
4278
               is given.  If -1, use the overall server
 
4279
               default.
 
4280
 
 
4281
          It uses the command line, config file, and default values
 
4282
          in the correct order of precedence to determine the
 
4283
          default visual value.  It is up to the driver to check
 
4284
          the result to see that it supports it.  If not the Chip-
 
4285
          PreInit() function should return FALSE.
 
4286
 
 
4287
          On success, this function prints a message showing the
 
4288
          default visual selected, and returns TRUE.
 
4289
 
 
4290
          On failure it prints an error message and returns FALSE.
 
4291
 
 
4292
     Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma)
 
4293
 
 
4294
          This function sets the gamma field of the ScrnInfoRec.
 
4295
          It would normally be called fairly early from the Chip-
 
4296
          PreInit() function in cases where the driver supports
 
4297
          gamma correction.
 
4298
 
 
4299
          It requires that the monitor field of the ScrnInfoRec be
 
4300
          initialised prior to calling it.
 
4301
          The parameters passed are:
 
4302
 
 
4303
          gamma
 
4304
 
 
4305
               driver's preferred default gamma if no other is
 
4306
               given.  If zero (< 0.01), use the overall
 
4307
               server default.
 
4308
 
 
4309
          It uses the command line, config file, and default values
 
4310
          in the correct order of precedence to determine the gamma
 
4311
          value.  It is up to the driver to check the results to
 
4312
          see that it supports them.  If not the ChipPreInit()
 
4313
          function should return FALSE.
 
4314
 
 
4315
          On success, this function prints a message showing the
 
4316
          gamma value selected, and returns TRUE.
 
4317
 
 
4318
          On failure it prints an error message and returns FALSE.
 
4319
 
 
4320
     void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y)
 
4321
 
 
4322
          This function sets the xDpi and yDpi fields of the Scrn-
 
4323
          InfoRec.  The driver can specify preferred defaults by
 
4324
          setting x and y to non-zero values.  The -dpi command
 
4325
          line option overrides all other settings.  Otherwise, if
 
4326
          the DisplaySize entry is present in the screen's Monitor
 
4327
          config file section, it is used together with the virtual
 
4328
          size to calculate the dpi values.  This function should
 
4329
          be called after all the mode resolution has been done.
 
4330
 
 
4331
     void xf86SetBlackWhitePixels(ScrnInfoPtr pScrn)
 
4332
 
 
4333
          This functions sets the blackPixel and whitePixel fields
 
4334
          of the ScrnInfoRec according to whether or not the -flip-
 
4335
          Pixels command line options is present.
 
4336
 
 
4337
     const char *xf86GetVisualName(int visual)
 
4338
 
 
4339
          Returns a printable string with the visual name matching
 
4340
          the numerical visual class provided.  If the value is
 
4341
          outside the range of valid visual classes, NULL is
 
4342
          returned.
 
4343
 
 
4344
18.3  Primary Mode functions
 
4345
 
 
4346
The primary mode helper functions are those which would normally be used by a
 
4347
driver, unless it has unusual requirements which cannot be catered for the by
 
4348
the helpers.
 
4349
 
 
4350
     int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
 
4351
 
 
4352
               char **modeNames, ClockRangePtr clockRanges,
 
4353
 
 
4354
               int *linePitches, int minPitch, int maxPitch,
 
4355
 
 
4356
               int pitchInc, int minHeight, int maxHeight,
 
4357
 
 
4358
               int virtualX, int virtualY,
 
4359
 
 
4360
               unsigned long apertureSize,
 
4361
 
 
4362
               LookupModeFlags strategy)
 
4363
 
 
4364
          This function basically selects the set of modes to use
 
4365
          based on those available and the various constraints.  It
 
4366
          also sets some other related parameters.  It is normally
 
4367
          called near the end of the ChipPreInit() function.
 
4368
 
 
4369
          The parameters passed to the function are:
 
4370
          availModes
 
4371
 
 
4372
               List of modes available for the monitor.
 
4373
 
 
4374
          modeNames
 
4375
 
 
4376
               List of mode names that the screen is request-
 
4377
               ing.
 
4378
 
 
4379
          clockRanges
 
4380
 
 
4381
               A list of clock ranges allowed by the driver.
 
4382
               Each range includes whether interlaced or mul-
 
4383
               tiscan modes are supported for that range.  See
 
4384
               below for more on clockRanges.
 
4385
 
 
4386
          linePitches
 
4387
 
 
4388
               List of line pitches supported by the driver.
 
4389
               This is optional and should be NULL when not
 
4390
               used.
 
4391
 
 
4392
          minPitch
 
4393
 
 
4394
               Minimum line pitch supported by the driver.
 
4395
               This must be supplied when linePitches is NULL,
 
4396
               and is ignored otherwise.
 
4397
 
 
4398
          maxPitch
 
4399
 
 
4400
               Maximum line pitch supported by the driver.
 
4401
               This is required when minPitch is required.
 
4402
 
 
4403
          pitchInc
 
4404
 
 
4405
               Granularity of horizontal pitch values as sup-
 
4406
               ported by the chipset.  This is expressed in
 
4407
               bits.  This must be supplied.
 
4408
 
 
4409
          minHeight
 
4410
 
 
4411
               minimum virtual height allowed.  If zero, no
 
4412
               limit is imposed.
 
4413
 
 
4414
          maxHeight
 
4415
 
 
4416
               maximum virtual height allowed.  If zero, no
 
4417
               limit is imposed.
 
4418
 
 
4419
          virtualX
 
4420
 
 
4421
               If greater than zero, this is the virtual width
 
4422
               value that will be used.  Otherwise, the vir-
 
4423
               tual width is chosen to be the smallest that
 
4424
               can accommodate the modes selected.
 
4425
 
 
4426
          virtualY
 
4427
 
 
4428
               If greater than zero, this is the virtual
 
4429
               height value that will be used.  Otherwise, the
 
4430
               virtual height is chosen to be the smallest
 
4431
               that can accommodate the modes selected.
 
4432
 
 
4433
          apertureSize
 
4434
 
 
4435
               The size (in bytes) of the aperture used to
 
4436
               access video memory.
 
4437
 
 
4438
          strategy
 
4439
 
 
4440
               The strategy to use when choosing from multiple
 
4441
               modes with the same name.  The options are:
 
4442
 
 
4443
               LOOKUP_DEFAULT
 
4444
 
 
4445
                    ???
 
4446
 
 
4447
               LOOKUP_BEST_REFRESH
 
4448
 
 
4449
                    mode with best refresh rate
 
4450
 
 
4451
               LOOKUP_CLOSEST_CLOCK
 
4452
 
 
4453
                    mode with closest matching clock
 
4454
 
 
4455
               LOOKUP_LIST_ORDER
 
4456
 
 
4457
                    first usable mode in list
 
4458
 
 
4459
               The following options can also be combined
 
4460
               (OR'ed) with one of the above:
 
4461
 
 
4462
               LOOKUP_CLKDIV2
 
4463
 
 
4464
                    Allow halved clocks
 
4465
 
 
4466
               LOOKUP_OPTIONAL_TOLERANCES
 
4467
 
 
4468
                    Allow missing horizontal sync and/or
 
4469
                    vertical refresh ranges in the
 
4470
                    XF86Config Monitor section
 
4471
 
 
4472
               LOOKUP_OPTIONAL_TOLERANCES should only be spec-
 
4473
               ified when the driver can ensure all modes it
 
4474
               generates can sync on, or at least not damage,
 
4475
               the monitor or digital flat panel.  Horizontal
 
4476
               sync and/or vertical refresh ranges specified
 
4477
               by the user will still be honoured (and acted
 
4478
               upon).
 
4479
 
 
4480
          This function requires that the following fields of the
 
4481
          ScrnInfoRec are initialised prior to calling it:
 
4482
 
 
4483
          clock[]
 
4484
 
 
4485
               List of discrete clocks (when non-programmable)
 
4486
 
 
4487
          numClocks
 
4488
 
 
4489
               Number of discrete clocks (when non-pro-
 
4490
               grammable)
 
4491
 
 
4492
          progClock
 
4493
 
 
4494
               Whether the clock is programmable or not
 
4495
 
 
4496
          monitor
 
4497
 
 
4498
               Pointer to the applicable XF86Config monitor
 
4499
               section
 
4500
 
 
4501
          fdFormat
 
4502
 
 
4503
               Format of the screen buffer
 
4504
 
 
4505
          videoRam
 
4506
 
 
4507
               total video memory size (in bytes)
 
4508
 
 
4509
          maxHValue
 
4510
 
 
4511
               Maximum horizontal timing value allowed
 
4512
 
 
4513
          maxVValue
 
4514
 
 
4515
               Maximum vertical timing value allowed
 
4516
 
 
4517
          xInc
 
4518
 
 
4519
               Horizontal timing increment in pixels (defaults
 
4520
               to 8)
 
4521
 
 
4522
          This function fills in the following ScrnInfoRec fields:
 
4523
 
 
4524
          modePool
 
4525
 
 
4526
               A subset of the modes available to the monitor
 
4527
               which are compatible with the driver.
 
4528
 
 
4529
          modes
 
4530
 
 
4531
               One mode entry for each of the requested modes,
 
4532
               with the status field of each filled in to
 
4533
               indicate if the mode has been accepted or not.
 
4534
               This list of modes is a circular list.
 
4535
 
 
4536
          virtualX
 
4537
 
 
4538
               The resulting virtual width.
 
4539
 
 
4540
          virtualY
 
4541
 
 
4542
               The resulting virtual height.
 
4543
 
 
4544
          displayWidth
 
4545
 
 
4546
               The resulting line pitch.
 
4547
 
 
4548
          virtualFrom
 
4549
 
 
4550
               Where the virtual size was determined from.
 
4551
 
 
4552
          The first stage of this function checks that the virtualX
 
4553
          and virtualY values supplied (if greater than zero) are
 
4554
          consistent with the line pitch and maxHeight limitations.
 
4555
          If not, an error message is printed, and the return value
 
4556
          is -1.
 
4557
 
 
4558
          The second stage sets up the mode pool, eliminating imme-
 
4559
          diately any modes that exceed the driver's line pitch
 
4560
          limits, and also the virtual width and height limits (if
 
4561
          greater than zero).  For each mode removed an informa-
 
4562
          tional message is printed at verbosity level 2.  If the
 
4563
          mode pool ends up being empty, a warning message is
 
4564
          printed, and the return value is 0.
 
4565
 
 
4566
          The final stage is to lookup each mode name, and fill in
 
4567
          the remaining parameters.  If an error condition is
 
4568
          encountered, a message is printed, and the return value
 
4569
          is -1.  Otherwise, the return value is the number of
 
4570
          valid modes found (0 if none are found).
 
4571
 
 
4572
          Even if the supplied mode names include duplicates, no
 
4573
          two names will ever match the same mode.  Furthermore, if
 
4574
          the supplied mode names do not yield a valid mode
 
4575
          (including the case where no names are passed at all),
 
4576
          the function will continue looking through the mode pool
 
4577
          until it finds a mode that survives all checks, or until
 
4578
          the mode pool is exhausted.
 
4579
 
 
4580
          A message is only printed by this function when a funda-
 
4581
          mental problem is found.  It is intended that this func-
 
4582
          tion may be called more than once if there is more than
 
4583
          one set of constraints that the driver can work within.
 
4584
 
 
4585
          If this function returns -1, the ChipPreInit() function
 
4586
          should return FALSE.
 
4587
 
 
4588
          clockRanges is a linked list of clock ranges allowed by
 
4589
          the driver.  If a mode doesn't fit in any of the defined
 
4590
          clockRanges, it is rejected.  The first clockRange that
 
4591
          matches all requirements is used.  This structure needs
 
4592
          to be initialized to NULL when allocated.
 
4593
 
 
4594
          clockRanges contains the following fields:
 
4595
 
 
4596
          minClock
 
4597
 
 
4598
          maxClock
 
4599
 
 
4600
               The lower and upper mode clock bounds for which
 
4601
               the rest of the clockRange parameters apply.
 
4602
               Since these are the mode clocks, they are not
 
4603
               scaled with the ClockMulFactor and ClockDivFac-
 
4604
               tor.  It is up to the driver to adjust these
 
4605
               values if they depend on the clock scaling fac-
 
4606
               tors.
 
4607
 
 
4608
          clockIndex
 
4609
 
 
4610
               (not used yet) -1 for programmable clocks
 
4611
 
 
4612
          interlaceAllowed
 
4613
 
 
4614
               TRUE if interlacing is allowed for this range
 
4615
 
 
4616
          doubleScanAllowed
 
4617
 
 
4618
               TRUE if doublescan or multiscan is allowed for
 
4619
               this range
 
4620
 
 
4621
          ClockMulFactor
 
4622
 
 
4623
          ClockDivFactor
 
4624
 
 
4625
               Scaling factors that are applied to the mode
 
4626
               clocks ONLY before selecting a clock index
 
4627
               (when there is no programmable clock) or a Syn-
 
4628
               thClock value.  This is useful for drivers that
 
4629
               support pixel multiplexing or that need to
 
4630
               scale the clocks because of hardware restric-
 
4631
               tions (like sending 24bpp data to an 8 bit RAM-
 
4632
               DAC using a tripled clock).
 
4633
 
 
4634
               Note that these parameters describe what must
 
4635
               be done to the mode clock to achieve the data
 
4636
               transport clock between graphics controller and
 
4637
               RAMDAC.  For example for 2:1 pixel multiplex-
 
4638
               ing, two pixels are sent to the RAMDAC on each
 
4639
               clock.  This allows the RAMDAC clock to be half
 
4640
               of the actual pixel clock.  Hence, ClockMulFac-
 
4641
               tor=1 and ClockDivFactor=2.  This means that
 
4642
               the clock used for clock selection (ie, deter-
 
4643
               mining the correct clock index from the list of
 
4644
               discrete clocks) or for the SynthClock field in
 
4645
               case of a programmable clock is:  (mode->Clock
 
4646
               * ClockMulFactor) / ClockDivFactor.
 
4647
 
 
4648
          PrivFlags
 
4649
 
 
4650
               This field is copied into the mode->PrivFlags
 
4651
               field when this clockRange is selected by
 
4652
               xf86ValidateModes().  It allows the driver to
 
4653
               find out what clock range was selected, so it
 
4654
               knows it needs to set up pixel multiplexing or
 
4655
               any other range-dependent feature.  This field
 
4656
               is purely driver-defined: it may contain flag
 
4657
               bits, an index or anything else (as long as it
 
4658
               is an INT).
 
4659
 
 
4660
          Note that the mode->SynthClock field is always filled in
 
4661
          by xf86ValidateModes(): it will contain the ``data trans-
 
4662
          port clock'', which is the clock that will have to be
 
4663
          programmed in the chip when it has a programmable clock,
 
4664
          or the clock that will be picked from the clocks list
 
4665
          when it is not a programmable one.  Thus:
 
4666
 
 
4667
          mode->SynthClock =
 
4668
 
 
4669
                    (mode->Clock * ClockMulFactor) / ClockDivFactor
 
4670
 
 
4671
     void xf86PruneDriverModes(ScrnInfoPtr scrp)
 
4672
 
 
4673
          This function deletes modes in the modes field of the
 
4674
          ScrnInfoRec that have been marked as invalid.  This is
 
4675
          normally run after having run xf86ValidateModes() for the
 
4676
          last time.  For each mode that is deleted, a warning mes-
 
4677
          sage is printed out indicating the reason for it being
 
4678
          deleted.
 
4679
 
 
4680
     void xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags)
 
4681
 
 
4682
          This function fills in the Crtc* fields for all the modes
 
4683
          in the modes field of the ScrnInfoRec.  The adjustFlags
 
4684
          parameter determines how the vertical CRTC values are
 
4685
          scaled for interlaced modes.  They are halved if it is
 
4686
          INTERLACE_HALVE_V.  The vertical CRTC values are doubled
 
4687
          for doublescan modes, and are further multiplied by the
 
4688
          VScan value.
 
4689
 
 
4690
          This function is normally called after calling
 
4691
          xf86PruneDriverModes().
 
4692
 
 
4693
     void xf86PrintModes(ScrnInfoPtr scrp)
 
4694
 
 
4695
          This function prints out the virtual size setting, and
 
4696
          the line pitch being used.  It also prints out two lines
 
4697
          for each mode being used.  The first line includes the
 
4698
          mode's pixel clock, horizontal sync rate, refresh rate,
 
4699
          and whether it is interlaced, doublescanned and/or multi-
 
4700
          scanned.  The second line is the mode's Modeline.
 
4701
          This function is normally called after calling
 
4702
          xf86SetCrtcForModes().
 
4703
 
 
4704
18.4  Secondary Mode functions
 
4705
 
 
4706
The secondary mode helper functions are functions which are normally used by
 
4707
the primary mode helper functions, and which are not normally called directly
 
4708
by a driver.  If a driver has unusual requirements and needs to do its own
 
4709
mode validation, it might be able to make use of some of these secondary mode
 
4710
helper functions.
 
4711
 
 
4712
     int xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
 
4713
 
 
4714
               int *divider)
 
4715
 
 
4716
          This function returns the index of the closest clock to
 
4717
          the frequency freq given (in kHz).  It assumes that the
 
4718
          number of clocks is greater than zero.  It requires that
 
4719
          the numClocks and clock fields of the ScrnInfoRec are
 
4720
          initialised.  The allowDiv2 field determines if the
 
4721
          clocks can be halved.  The *divider return value indi-
 
4722
          cates whether clock division is used when determining the
 
4723
          clock returned.
 
4724
 
 
4725
          This function is only for non-programmable clocks.
 
4726
 
 
4727
     const char *xf86ModeStatusToString(ModeStatus status)
 
4728
 
 
4729
          This function converts the status value to a descriptive
 
4730
          printable string.
 
4731
 
 
4732
     ModeStatus xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
 
4733
 
 
4734
               ClockRangePtr clockRanges, LookupModeFlags strategy)
 
4735
 
 
4736
          This function takes a pointer to a mode with the name
 
4737
          filled in, and looks for a mode in the modePool list
 
4738
          which matches.  The parameters of the matching mode are
 
4739
          filled in to *modep.  The clockRanges and strategy param-
 
4740
          eters are as for the xf86ValidateModes() function above.
 
4741
 
 
4742
          This function requires the modePool, clock[], numClocks
 
4743
          and progClock fields of the ScrnInfoRec to be initialised
 
4744
          before being called.
 
4745
 
 
4746
          The return value is MODE_OK if a mode was found.  Other-
 
4747
          wise it indicates why a matching mode could not be found.
 
4748
 
 
4749
     ModeStatus xf86InitialCheckModeForDriver(ScrnInfoPtr scrp,
 
4750
 
 
4751
               DisplayModePtr mode, ClockRangePtr clockRanges,
 
4752
 
 
4753
               LookupModeFlags strategy, int maxPitch,
 
4754
 
 
4755
               int virtualX, int virtualY)
 
4756
 
 
4757
          This function checks the passed mode against some basic
 
4758
          driver constraints.  Apart from the ones passed explic-
 
4759
          itly, the maxHValue and maxVValue fields of the ScrnIn-
 
4760
          foRec are also used.  If the ValidMode field of the Scrn-
 
4761
          InfoRec is set, that function is also called to check the
 
4762
          mode.  Next, the mode is checked against the monitor's
 
4763
          constraints.
 
4764
 
 
4765
          If the mode is consistent with all constraints, the
 
4766
          return value is MODE_OK.  Otherwise the return value
 
4767
          indicates which constraint wasn't met.
 
4768
 
 
4769
     void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode)
 
4770
 
 
4771
          This function deletes the mode given from the modeList.
 
4772
          It never prints any messages, so it is up to the caller
 
4773
          to print a message if required.
 
4774
 
 
4775
18.5  Functions for handling strings and tokens
 
4776
 
 
4777
Tables associating strings and numerical tokens combined with the following
 
4778
functions provide a compact way of handling strings from the config file, and
 
4779
for converting tokens into printable strings.  The table data structure is:
 
4780
 
 
4781
          typedef struct {
 
4782
              int                 token;
 
4783
              const char *        name;
 
4784
          } SymTabRec, *SymTabPtr;
 
4785
 
 
4786
A table is an initialised array of SymTabRec.  The tokens must be non-nega-
 
4787
tive integers.  Multiple names may be mapped to a single token.  The table is
 
4788
terminated with an element with a token value of -1 and NULL for the name.
 
4789
 
 
4790
     const char *xf86TokenToString(SymTabPtr table, int token)
 
4791
 
 
4792
          This function returns the first string in table that
 
4793
          matches token.  If no match is found, NULL is returned
 
4794
          (NOTE, older versions of this function would return the
 
4795
          string "unknown" when no match is found).
 
4796
 
 
4797
     int xf86StringToToken(SymTabPtr table, const char *string)
 
4798
 
 
4799
          This function returns the first token in table that
 
4800
          matches string.  The xf86NameCmp() function is used to
 
4801
          determine the match.  If no match is found, -1 is
 
4802
          returned.
 
4803
 
 
4804
18.6  Functions for finding which config file entries to use
 
4805
 
 
4806
These functions can be used to select the appropriate config file entries
 
4807
that match the detected hardware.  They are described above in the Probe
 
4808
(section 5.8, page 1) and Available Functions (section 9.3, page 1) sections.
 
4809
 
 
4810
18.7  Probing discrete clocks on old hardware
 
4811
 
 
4812
The xf86GetClocks() function may be used to assist in finding the discrete
 
4813
pixel clock values on older hardware.
 
4814
 
 
4815
     void xf86GetClocks(ScrnInfoPtr pScrn, int num,
 
4816
 
 
4817
               Bool (*ClockFunc)(ScrnInfoPtr, int),
 
4818
 
 
4819
               void (*ProtectRegs)(ScrnInfoPtr, Bool),
 
4820
 
 
4821
               void (*BlankScreen)(ScrnInfoPtr, Bool),
 
4822
 
 
4823
               int vertsyncreg, int maskval, int knownclkindex,
 
4824
 
 
4825
               int knownclkvalue)
 
4826
 
 
4827
          This function uses a comparative sampling method to mea-
 
4828
          sure the discrete pixel clock values.  The number of dis-
 
4829
          crete clocks to measure is given by num.  clockFunc is a
 
4830
          function that selects the n'th clock.  It should also
 
4831
          save or restore any state affected by programming the
 
4832
          clocks when the index passed is CLK_REG_SAVE or
 
4833
          CLK_REG_RESTORE.  ProtectRegs is a function that does
 
4834
          whatever is required to protect the hardware state while
 
4835
          selecting a new clock.  BlankScreen is a function that
 
4836
          blanks the screen.  vertsyncreg and maskval are the reg-
 
4837
          ister and bitmask to check for the presence of vertical
 
4838
          sync pulses.  knownclkindex and knownclkvalue are the
 
4839
          index and value of a known clock.  These are the known
 
4840
          references on which the comparative measurements are
 
4841
          based.  The number of clocks probed is set in pScrn->num-
 
4842
          Clocks, and the probed clocks are set in the
 
4843
          pScrn->clock[] array.  All of the clock values are in
 
4844
          units of kHz.
 
4845
 
 
4846
     void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from)
 
4847
 
 
4848
          Print out the pixel clocks scrp->clock[].  from indicates
 
4849
          whether the clocks were probed or from the config file.
 
4850
 
 
4851
18.8  Other helper functions
 
4852
 
 
4853
     Bool xf86IsUnblank(int mode)
 
4854
 
 
4855
          Returns TRUE when the screen saver mode specified by mode
 
4856
          requires the screen be unblanked, and FALSE otherwise.
 
4857
          The screen saver modes that require blanking are
 
4858
          SCREEN_SAVER_ON and SCREEN_SAVER_CYCLE, and the screen
 
4859
          saver modes that require unblanking are SCREEN_SAVER_OFF
 
4860
          and SCREEN_SAVER_FORCER.  Drivers may call this helper
 
4861
          from their SaveScreen() function to interpret the screen
 
4862
          saver modes.
 
4863
 
 
4864
19.  The vgahw module
 
4865
 
 
4866
The vgahw modules provides an interface for saving, restoring and programming
 
4867
the standard VGA registers, and for handling VGA colourmaps.
 
4868
 
 
4869
19.1  Data Structures
 
4870
 
 
4871
The public data structures used by the vgahw module are vgaRegRec and vgaH-
 
4872
WRec.  They are defined in vgaHW.h.
 
4873
 
 
4874
19.2  General vgahw Functions
 
4875
 
 
4876
     Bool vgaHWGetHWRec(ScrnInfoPtr pScrn)
 
4877
 
 
4878
          This function allocates a vgaHWRec structure, and hooks
 
4879
          it into the ScrnInfoRec's privates.  Like all information
 
4880
          hooked into the privates, it is persistent, and only
 
4881
          needs to be allocated once per screen.  This function
 
4882
          should normally be called from the driver's ChipPreInit()
 
4883
          function.  The vgaHWRec is zero-allocated, and the fol-
 
4884
          lowing fields are explicitly initialised:
 
4885
          ModeReg.DAC[]
 
4886
 
 
4887
               initialised with a default colourmap
 
4888
 
 
4889
          ModeReg.Attribute[0x11]
 
4890
 
 
4891
               initialised with the default overscan index
 
4892
 
 
4893
          ShowOverscan
 
4894
 
 
4895
               initialised according to the "ShowOverscan"
 
4896
               option
 
4897
 
 
4898
          paletteEnabled
 
4899
 
 
4900
               initialised to FALSE
 
4901
 
 
4902
          cmapSaved
 
4903
 
 
4904
               initialised to FALSE
 
4905
 
 
4906
          pScrn
 
4907
 
 
4908
               initialised to pScrn
 
4909
 
 
4910
          In addition to the above, vgaHWSetStdFuncs() is called to
 
4911
          initialise the register access function fields with the
 
4912
          standard VGA set of functions.
 
4913
 
 
4914
          Once allocated, a pointer to the vgaHWRec can be obtained
 
4915
          from the ScrnInfoPtr with the VGAHWPTR(pScrn) macro.
 
4916
 
 
4917
     void vgaHWFreeHWRec(ScrnInfoPtr pScrn)
 
4918
 
 
4919
          This function frees a vgaHWRec structure.  It should be
 
4920
          called from a driver's ChipFreeScreen() function.
 
4921
 
 
4922
     Bool vgaHWSetRegCounts(ScrnInfoPtr pScrn, int numCRTC,
 
4923
 
 
4924
               int numSequencer, int numGraphics, int numAttribute)
 
4925
 
 
4926
          This function allows the number of CRTC, Sequencer,
 
4927
          Graphics and Attribute registers to be changed.  This
 
4928
          makes it possible for extended registers to be saved and
 
4929
          restored with vgaHWSave() and vgaHWRestore().  This func-
 
4930
          tion should be called after a vgaHWRec has been allocated
 
4931
          with vgaHWGetHWRec().  The default values are defined in
 
4932
          vgaHW.h as follows:
 
4933
 
 
4934
                    #define VGA_NUM_CRTC 25
 
4935
                    #define VGA_NUM_SEQ   5
 
4936
                    #define VGA_NUM_GFX   9
 
4937
                    #define VGA_NUM_ATTR 21
 
4938
 
 
4939
     Bool vgaHWCopyReg(vgaRegPtr dst, vgaRegPtr src)
 
4940
 
 
4941
          This function copies the contents of the VGA saved regis-
 
4942
          ters in src to dst.  Note that it isn't possible to sim-
 
4943
          ply do this with memcpy() (or similar).  This function
 
4944
          returns TRUE unless there is a problem allocating space
 
4945
          for the CRTC and related fields in dst.
 
4946
 
 
4947
     void vgaHWSetStdFuncs(vgaHWPtr hwp)
 
4948
 
 
4949
          This function initialises the register access function
 
4950
          fields of hwp with the standard VGA set of functions.
 
4951
          This is called by vgaHWGetHWRec(), so there is usually no
 
4952
          need to call this explicitly.  The register access func-
 
4953
          tions are described below.  If the registers are shadowed
 
4954
          in some other port I/O space (for example a PCI I/O
 
4955
          region), these functions can be used to access the shad-
 
4956
          owed registers if hwp->PIOOffset is initialised with off-
 
4957
          set, calculated in such a way that when the standard VGA
 
4958
          I/O port value is added to it the correct offset into the
 
4959
          PIO area results.  This value is initialised to zero in
 
4960
          vgaHWGetHWRec().  (Note: the PIOOffset functionality is
 
4961
          present in XFree86 4.1.0 and later.)
 
4962
 
 
4963
     void vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset)
 
4964
 
 
4965
          This function initialised the register access function
 
4966
          fields of hwp with a generic MMIO set of functions.
 
4967
          hwp->MMIOBase is initialised with base, which must be the
 
4968
          virtual address that the start of MMIO area is mapped to.
 
4969
          hwp->MMIOOffset is initialised with offset, which must be
 
4970
          calculated in such a way that when the standard VGA I/O
 
4971
          port value is added to it the correct offset into the
 
4972
          MMIO area results.  That means that these functions are
 
4973
          only suitable when the VGA I/O ports are made available
 
4974
          in a direct mapping to the MMIO space.  If that is not
 
4975
          the case, the driver will need to provide its own regis-
 
4976
          ter access functions.  The register access functions are
 
4977
          described below.
 
4978
 
 
4979
     Bool vgaHWMapMem(ScrnInfoPtr pScrn)
 
4980
 
 
4981
          This function maps the VGA memory window.  It requires
 
4982
          that the vgaHWRec be allocated.  If a driver requires
 
4983
          non-default MapPhys or MapSize settings (the physical
 
4984
          location and size of the VGA memory window) then those
 
4985
          fields of the vgaHWRec must be initialised before calling
 
4986
          this function.  Otherwise, this function initialiases the
 
4987
          default values of 0xA0000 for MapPhys and (64 * 1024) for
 
4988
          MapSize.  This function must be called before attempting
 
4989
          to save or restore the VGA state.  If the driver doesn't
 
4990
          call it explicitly, the vgaHWSave() and vgaHWRestore()
 
4991
          functions may call it if they need to access the VGA mem-
 
4992
          ory (in which case they will also call vgaHWUnmapMem() to
 
4993
          unmap the VGA memory before exiting).
 
4994
 
 
4995
     void vgaHWUnmapMem(ScrnInfoPtr pScrn)
 
4996
 
 
4997
          This function unmaps the VGA memory window.  It must only
 
4998
          be called after the memory has been mapped.  The Base
 
4999
          field of the vgaHWRec field is set to NULL to indicate
 
5000
          that the memory is no longer mapped.
 
5001
 
 
5002
     void vgaHWGetIOBase(vgaHWPtr hwp)
 
5003
 
 
5004
          This function initialises the IOBase field of the vgaH-
 
5005
          WRec.  This function must be called before using any
 
5006
          other functions that access the video hardware.
 
5007
 
 
5008
          A macro VGAHW_GET_IOBASE() is also available in vgaHW.h
 
5009
          that returns the I/O base, and this may be used when the
 
5010
          vgahw module is not loaded (for example, in the Chip-
 
5011
          Probe() function).
 
5012
 
 
5013
     void vgaHWUnlock(vgaHWPtr hwp)
 
5014
 
 
5015
          This function unlocks the VGA CRTC[0-7] registers, and
 
5016
          must be called before attempting to write to those regis-
 
5017
          ters.
 
5018
 
 
5019
     void vgaHWLock(vgaHWPtr hwp)
 
5020
 
 
5021
          This function locks the VGA CRTC[0-7] registers.
 
5022
 
 
5023
     void vgaHWEnable(vgaHWPtr hwp)
 
5024
 
 
5025
          This function enables the VGA subsystem.  (Note, this
 
5026
          function is present in XFree86 4.1.0 and later.).
 
5027
 
 
5028
     void vgaHWDisable(vgaHWPtr hwp)
 
5029
 
 
5030
          This function disables the VGA subsystem.  (Note, this
 
5031
          function is present in XFree86 4.1.0 and later.).
 
5032
 
 
5033
     void vgaHWSave(ScrnInfoPtr pScrn, vgaRegPtr save, int flags)
 
5034
 
 
5035
          This function saves the VGA state.  The state is written
 
5036
          to the vgaRegRec pointed to by save.  flags is set to one
 
5037
          or more of the following flags ORed together:
 
5038
 
 
5039
          VGA_SR_MODE
 
5040
 
 
5041
               the mode setting registers are saved
 
5042
 
 
5043
          VGA_SR_FONTS
 
5044
 
 
5045
               the text mode font/text data is saved
 
5046
 
 
5047
          VGA_SR_CMAP
 
5048
 
 
5049
               the colourmap (LUT) is saved
 
5050
 
 
5051
          VGA_SR_ALL
 
5052
 
 
5053
               all of the above are saved
 
5054
 
 
5055
          The vgaHWRec and its IOBase fields must be initialised
 
5056
          before this function is called.  If VGA_SR_FONTS is set
 
5057
          in flags, the VGA memory window must be mapped.  If it
 
5058
          isn't then vgaHWMapMem() will be called to map it, and
 
5059
          vgaHWUnmapMem() will be called to unmap it afterwards.
 
5060
          vgaHWSave() uses the three functions below in the order
 
5061
          vgaHWSaveColormap(), vgaHWSaveMode(), vgaHWSaveFonts() to
 
5062
          carry out the different save phases.  It is undecided at
 
5063
          this stage whether they will remain part of the vgahw
 
5064
          module's public interface or not.
 
5065
 
 
5066
     void vgaHWSaveMode(ScrnInfoPtr pScrn, vgaRegPtr save)
 
5067
 
 
5068
          This function saves the VGA mode registers.  They are
 
5069
          saved to the vgaRegRec pointed to by save.  The registers
 
5070
          saved are:
 
5071
 
 
5072
               MiscOut
 
5073
 
 
5074
               CRTC[0-0x18]
 
5075
 
 
5076
               Attribute[0-0x14]
 
5077
 
 
5078
               Graphics[0-8]
 
5079
 
 
5080
               Sequencer[0-4]
 
5081
 
 
5082
          The number of registers actually saved may be modified by
 
5083
          a prior call to vgaHWSetRegCounts().
 
5084
 
 
5085
     void vgaHWSaveFonts(ScrnInfoPtr pScrn, vgaRegPtr save)
 
5086
 
 
5087
          This function saves the text mode font and text data held
 
5088
          in the video memory.  If called while in a graphics mode,
 
5089
          no save is done.  The VGA memory window must be mapped
 
5090
          with vgaHWMapMem() before to calling this function.
 
5091
 
 
5092
          On some platforms, one or more of the font/text plane
 
5093
          saves may be no-ops.  This is the case when the plat-
 
5094
          form's VC driver already takes care of this.
 
5095
 
 
5096
     void vgaHWSaveColormap(ScrnInfoPtr pScrn, vgaRegPtr save)
 
5097
 
 
5098
          This function saves the VGA colourmap (LUT).  Before sav-
 
5099
          ing it, it attempts to verify that the colourmap is read-
 
5100
          able.  In rare cases where it isn't readable, a default
 
5101
          colourmap is saved instead.
 
5102
 
 
5103
     void vgaHWRestore(ScrnInfoPtr pScrn, vgaRegPtr restore, int flags)
 
5104
 
 
5105
          This function programs the VGA state.  The state pro-
 
5106
          grammed is that contained in the vgaRegRec pointed to by
 
5107
          restore.  flags is the same as described above for the
 
5108
          vgaHWSave() function.
 
5109
 
 
5110
          The vgaHWRec and its IOBase fields must be initialised
 
5111
          before this function is called.  If VGA_SR_FONTS is set
 
5112
          in flags, the VGA memory window must be mapped.  If it
 
5113
          isn't then vgaHWMapMem() will be called to map it, and
 
5114
          vgaHWUnmapMem() will be called to unmap it afterwards.
 
5115
          vgaHWRestore() uses the three functions below in the
 
5116
          order vgaHWRestoreFonts(), vgaHWRestoreMode(), vgaHWRe-
 
5117
          storeColormap() to carry out the different restore
 
5118
          phases.  It is undecided at this stage whether they will
 
5119
          remain part of the vgahw module's public interface or
 
5120
          not.
 
5121
 
 
5122
     void vgaHWRestoreMode(ScrnInfoPtr pScrn, vgaRegPtr restore)
 
5123
 
 
5124
          This function restores the VGA mode registers.  They are
 
5125
          restored from the data in the vgaRegRec pointed to by
 
5126
          restore.  The registers restored are:
 
5127
 
 
5128
               MiscOut
 
5129
 
 
5130
               CRTC[0-0x18]
 
5131
 
 
5132
               Attribute[0-0x14]
 
5133
 
 
5134
               Graphics[0-8]
 
5135
 
 
5136
               Sequencer[0-4]
 
5137
 
 
5138
          The number of registers actually restored may be modified
 
5139
          by a prior call to vgaHWSetRegCounts().
 
5140
 
 
5141
     void vgaHWRestoreFonts(ScrnInfoPtr pScrn, vgaRegPtr restore)
 
5142
 
 
5143
          This function restores the text mode font and text data
 
5144
          to the video memory.  The VGA memory window must be
 
5145
          mapped with vgaHWMapMem() before to calling this func-
 
5146
          tion.
 
5147
 
 
5148
          On some platforms, one or more of the font/text plane
 
5149
          restores may be no-ops.  This is the case when the plat-
 
5150
          form's VC driver already takes care of this.
 
5151
 
 
5152
     void vgaHWRestoreColormap(ScrnInfoPtr pScrn, vgaRegPtr restore)
 
5153
 
 
5154
          This function restores the VGA colourmap (LUT).
 
5155
 
 
5156
     void vgaHWInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
 
5157
 
 
5158
          This function fills in the vgaHWRec's ModeReg field with
 
5159
          the values appropriate for programming the given video
 
5160
          mode.  It requires that the ScrnInfoRec's depth field is
 
5161
          initialised, which determines how the registers are pro-
 
5162
          grammed.
 
5163
 
 
5164
     void vgaHWSeqReset(vgaHWPtr hwp, Bool start)
 
5165
 
 
5166
          Do a VGA sequencer reset.  If start is TRUE, the reset is
 
5167
          started.  If start is FALSE, the reset is ended.
 
5168
 
 
5169
     void vgaHWProtect(ScrnInfoPtr pScrn, Bool on)
 
5170
 
 
5171
          This function protects VGA registers and memory from cor-
 
5172
          ruption during loads.  It is typically called with on set
 
5173
          to TRUE before programming, and with on set to FALSE
 
5174
          after programming.
 
5175
 
 
5176
     Bool vgaHWSaveScreen(ScreenPtr pScreen, int mode)
 
5177
 
 
5178
          This function blanks and unblanks the screen.  It is
 
5179
          blanked when mode is SCREEN_SAVER_ON or
 
5180
          SCREEN_SAVER_CYCLE, and unblanked when mode is
 
5181
          SCREEN_SAVER_OFF or SCREEN_SAVER_FORCER.
 
5182
 
 
5183
     void vgaHWBlankScreen(ScrnInfoPtr pScrn, Bool on)
 
5184
 
 
5185
          This function blanks and unblanks the screen.  It is
 
5186
          blanked when on is FALSE, and unblanked when on is TRUE.
 
5187
          This function is provided for use in cases where the
 
5188
          ScrnInfoRec can't be derived from the ScreenRec (while
 
5189
          probing for clocks, for example).
 
5190
 
 
5191
19.3  VGA Colormap Functions
 
5192
 
 
5193
The vgahw module uses the standard colormap support (see the Colormap Han-
 
5194
dling (section 13., page 1) section.  This is initialised with the following
 
5195
function:
 
5196
 
 
5197
     Bool vgaHWHandleColormaps(ScreenPtr pScreen)
 
5198
 
 
5199
19.4  VGA Register Access Functions
 
5200
 
 
5201
The vgahw module abstracts access to the standard VGA registers by using a
 
5202
set of functions held in the vgaHWRec.  When the vgaHWRec is created these
 
5203
function pointers are initialised with the set of standard VGA I/O register
 
5204
access functions.  In addition to these, the vgahw module includes a basic
 
5205
set of MMIO register access functions, and the vgaHWRec function pointers can
 
5206
be initialised to these by calling the vgaHWSetMmioFuncs() function described
 
5207
above.  Some drivers/platforms may require a different set of functions for
 
5208
VGA access.  The access functions are described here.
 
5209
 
 
5210
     void writeCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value)
 
5211
 
 
5212
          Write value to CRTC register index.
 
5213
 
 
5214
     CARD8 readCrtc(vgaHWPtr hwp, CARD8 index)
 
5215
 
 
5216
          Return the value read from CRTC register index.
 
5217
 
 
5218
     void writeGr(vgaHWPtr hwp, CARD8 index, CARD8 value)
 
5219
 
 
5220
          Write value to Graphics Controller register index.
 
5221
 
 
5222
     CARD8 readGR(vgaHWPtr hwp, CARD8 index)
 
5223
 
 
5224
          Return the value read from Graphics Controller register
 
5225
          index.
 
5226
 
 
5227
     void writeSeq(vgaHWPtr hwp, CARD8 index, CARD8, value)
 
5228
 
 
5229
          Write value to Sequencer register index.
 
5230
 
 
5231
     CARD8 readSeq(vgaHWPtr hwp, CARD8 index)
 
5232
 
 
5233
          Return the value read from Sequencer register index.
 
5234
 
 
5235
     void writeAttr(vgaHWPtr hwp, CARD8 index, CARD8, value)
 
5236
 
 
5237
          Write value to Attribute Controller register index.  When
 
5238
          writing out the index value this function should set bit
 
5239
          5 (0x20) according to the setting of hwp->paletteEnabled
 
5240
          in order to preserve the palette access state.  It should
 
5241
          be cleared when hwp->paletteEnabled is TRUE and set when
 
5242
          it is FALSE.
 
5243
 
 
5244
     CARD8 readAttr(vgaHWPtr hwp, CARD8 index)
 
5245
 
 
5246
          Return the value read from Attribute Controller register
 
5247
          index.  When writing out the index value this function
 
5248
          should set bit 5 (0x20) according to the setting of
 
5249
          hwp->paletteEnabled in order to preserve the palette
 
5250
          access state.  It should be cleared when hwp->paletteEn-
 
5251
          abled is TRUE and set when it is FALSE.
 
5252
 
 
5253
     void writeMiscOut(vgaHWPtr hwp, CARD8 value)
 
5254
 
 
5255
          Write `value' to the Miscellaneous Output register.
 
5256
 
 
5257
     CARD8 readMiscOut(vgwHWPtr hwp)
 
5258
 
 
5259
          Return the value read from the Miscellaneous Output reg-
 
5260
          ister.
 
5261
 
 
5262
     void enablePalette(vgaHWPtr hwp)
 
5263
 
 
5264
          Clear the palette address source bit in the Attribute
 
5265
          Controller index register and set hwp->paletteEnabled to
 
5266
          TRUE.
 
5267
 
 
5268
     void disablePalette(vgaHWPtr hwp)
 
5269
 
 
5270
          Set the palette address source bit in the Attribute Con-
 
5271
          troller index register and set hwp->paletteEnabled to
 
5272
          FALSE.
 
5273
 
 
5274
     void writeDacMask(vgaHWPtr hwp, CARD8 value)
 
5275
 
 
5276
          Write value to the DAC Mask register.
 
5277
 
 
5278
     CARD8 readDacMask(vgaHWptr hwp)
 
5279
 
 
5280
          Return the value read from the DAC Mask register.
 
5281
 
 
5282
     void writeDacReadAddress(vgaHWPtr hwp, CARD8 value)
 
5283
 
 
5284
          Write value to the DAC Read Address register.
 
5285
 
 
5286
     void writeDacWriteAddress(vgaHWPtr hwp, CARD8 value)
 
5287
 
 
5288
          Write value to the DAC Write Address register.
 
5289
 
 
5290
     void writeDacData(vgaHWPtr hwp, CARD8 value)
 
5291
 
 
5292
          Write value to the DAC Data register.
 
5293
 
 
5294
     CARD8 readDacData(vgaHWptr hwp)
 
5295
 
 
5296
          Return the value read from the DAC Data register.
 
5297
 
 
5298
     CARD8 readEnable(vgaHWptr hwp)
 
5299
 
 
5300
          Return the value read from the VGA Enable register.
 
5301
          (Note: This function is present in XFree86 4.1.0 and
 
5302
          later.)
 
5303
 
 
5304
     void writeEnable(vgaHWPtr hwp, CARD8 value)
 
5305
 
 
5306
          Write value to the VGA Enable register.  (Note: This
 
5307
          function is present in XFree86 4.1.0 and later.)
 
5308
 
 
5309
20.  Some notes about writing a driver
 
5310
 
 
5311
NOTE: some parts of this are not up to date
 
5312
 
 
5313
The following is an outline for writing a basic unaccelerated driver for a
 
5314
PCI video card with a linear mapped framebuffer, and which has a VGA core.
 
5315
It is includes some general information that is relevant to most drivers
 
5316
(even those which don't fit that basic description).
 
5317
 
 
5318
The information here is based on the initial conversion of the Matrox Millen-
 
5319
nium driver to the ``new design''.  For a fleshing out and sample implementa-
 
5320
tion of some of the bits outlined here, refer to that driver.  Note that this
 
5321
is an example only.  The approach used here will not be appropriate for all
 
5322
drivers.
 
5323
 
 
5324
Each driver must reserve a unique driver name, and a string that is used to
 
5325
prefix all of its externally visible symbols.  This is to avoid name space
 
5326
clashes when loading multiple drivers.  The examples here are for the ``ZZZ''
 
5327
driver, which uses the ``ZZZ'' or ``zzz'' prefix for its externally visible
 
5328
symbols.
 
5329
 
 
5330
20.1  Include files
 
5331
 
 
5332
All drivers normally include the following headers:
 
5333
 
 
5334
     "xf86.h"
 
5335
 
 
5336
     "xf86_OSproc.h"
 
5337
 
 
5338
     "xf86_ansic.h"
 
5339
 
 
5340
     "xf86Resources.h"
 
5341
 
 
5342
Wherever inb/outb (and related things) are used the following should be
 
5343
included:
 
5344
 
 
5345
     "compiler.h"
 
5346
 
 
5347
Note: in drivers, this must be included after "xf86_ansic.h".
 
5348
 
 
5349
Drivers that need to access PCI vendor/device definitions need this:
 
5350
 
 
5351
     "xf86PciInfo.h"
 
5352
 
 
5353
Drivers that need to access the PCI config space need this:
 
5354
 
 
5355
     "xf86Pci.h"
 
5356
 
 
5357
Drivers using the mi banking wrapper need:
 
5358
 
 
5359
     "mibank.h"
 
5360
 
 
5361
Drivers that initialise a SW cursor need this:
 
5362
 
 
5363
     "mipointer.h"
 
5364
 
 
5365
All drivers implementing backing store need this:
 
5366
 
 
5367
     "mibstore.h"
 
5368
 
 
5369
All drivers using the mi colourmap code need this:
 
5370
 
 
5371
     "micmap.h"
 
5372
 
 
5373
If a driver uses the vgahw module, it needs this:
 
5374
 
 
5375
     "vgaHW.h"
 
5376
 
 
5377
Drivers supporting VGA or Hercules monochrome screens need:
 
5378
 
 
5379
     "xf1bpp.h"
 
5380
 
 
5381
Drivers supporting VGA or EGC 16-colour screens need:
 
5382
 
 
5383
     "xf4bpp.h"
 
5384
 
 
5385
Drivers using cfb need:
 
5386
 
 
5387
     #define PSZ 8
 
5388
 
 
5389
     #include "cfb.h"
 
5390
 
 
5391
     #undef PSZ
 
5392
 
 
5393
Drivers supporting bpp 16, 24 or 32 with cfb need one or more of:
 
5394
 
 
5395
     "cfb16.h"
 
5396
 
 
5397
     "cfb24.h"
 
5398
 
 
5399
     "cfb32.h"
 
5400
 
 
5401
The driver's own header file:
 
5402
 
 
5403
     "zzz.h"
 
5404
 
 
5405
Drivers must NOT include the following:
 
5406
 
 
5407
     "xf86Priv.h"
 
5408
 
 
5409
     "xf86Privstr.h"
 
5410
 
 
5411
     "xf86_libc.h"
 
5412
 
 
5413
     "xf86_OSlib.h"
 
5414
 
 
5415
     "Xos.h"
 
5416
 
 
5417
     any OS header
 
5418
 
 
5419
20.2  Data structures and initialisation
 
5420
 
 
5421
   o The following macros should be defined:
 
5422
 
 
5423
          #define VERSION <version-as-an-int>
 
5424
          #define ZZZ_NAME "ZZZ"         /* the name used to prefix messages */
 
5425
          #define ZZZ_DRIVER_NAME "zzz"  /* the driver name as used in config file */
 
5426
          #define ZZZ_MAJOR_VERSION <int>
 
5427
          #define ZZZ_MINOR_VERSION <int>
 
5428
          #define ZZZ_PATCHLEVEL    <int>
 
5429
 
 
5430
     NOTE: ZZZ_DRIVER_NAME should match the name of the driver module without
 
5431
     things like the "lib" prefix, the "_drv" suffix or filename extensions.
 
5432
 
 
5433
   o A DriverRec must be defined, which includes the functions required at
 
5434
     the pre-probe phase.  The name of this DriverRec must be an upper-case
 
5435
     version of ZZZ_DRIVER_NAME (for the purposes of static linking).
 
5436
 
 
5437
          DriverRec ZZZ = {
 
5438
              VERSION,
 
5439
              ZZZ_DRIVER_NAME,
 
5440
              ZZZIdentify,
 
5441
              ZZZProbe,
 
5442
              ZZZAvailableOptions,
 
5443
              NULL,
 
5444
              0
 
5445
          };
 
5446
 
 
5447
   o Define list of supported chips and their matching ID:
 
5448
 
 
5449
          static SymTabRec ZZZChipsets[] = {
 
5450
              { PCI_CHIP_ZZZ1234, "zzz1234a" },
 
5451
              { PCI_CHIP_ZZZ5678, "zzz5678a" },
 
5452
              { -1,               NULL }
 
5453
          };
 
5454
 
 
5455
     The token field may be any integer value that the driver may use to
 
5456
     uniquely identify the supported chipsets.  For drivers that support only
 
5457
     PCI devices using the PCI device IDs might be a natural choice, but this
 
5458
     isn't mandatory.  For drivers that support both PCI and other devices
 
5459
     (like ISA), some other ID should probably used.  When other IDs are used
 
5460
     as the tokens it is recommended that the names be defined as an enum
 
5461
     type.
 
5462
 
 
5463
   o If the driver uses the xf86MatchPciInstances() helper (recommended for
 
5464
     drivers that support PCI cards) a list that maps PCI IDs to chip IDs and
 
5465
     fixed resources must be defined:
 
5466
 
 
5467
          static PciChipsets ZZZPciChipsets[] = {
 
5468
              { PCI_CHIP_ZZZ1234, PCI_CHIP_ZZZ1234, RES_SHARED_VGA },
 
5469
              { PCI_CHIP_ZZZ5678, PCI_CHIP_ZZZ5678, RES_SHARED_VGA },
 
5470
              { -1,               -1,               RES_UNDEFINED }
 
5471
          }
 
5472
 
 
5473
   o Define the XF86ModuleVersionInfo struct for the driver.  This is
 
5474
     required for the dynamically loaded version:
 
5475
 
 
5476
          #ifdef XFree86LOADER
 
5477
          static XF86ModuleVersionInfo zzzVersRec =
 
5478
          {
 
5479
              "zzz",
 
5480
              MODULEVENDORSTRING,
 
5481
              MODINFOSTRING1,
 
5482
              MODINFOSTRING2,
 
5483
              XF86_VERSION_CURRENT,
 
5484
              ZZZ_MAJOR_VERSION, ZZZ_MINOR_VERSION, ZZZ_PATCHLEVEL,
 
5485
              ABI_CLASS_VIDEODRV,
 
5486
              ABI_VIDEODRV_VERSION,
 
5487
              MOD_CLASS_VIDEODRV,
 
5488
              {0,0,0,0}
 
5489
          };
 
5490
          #endif
 
5491
 
 
5492
   o Define a data structure to hold the driver's screen-specific data.  This
 
5493
     must be used instead of global variables.  This would be defined in the
 
5494
     "zzz.h" file, something like:
 
5495
 
 
5496
          typedef struct {
 
5497
              type1  field1;
 
5498
              type2  field2;
 
5499
              int    fooHack;
 
5500
              Bool   pciRetry;
 
5501
              Bool   noAccel;
 
5502
              Bool   hwCursor;
 
5503
              CloseScreenProcPtr CloseScreen;
 
5504
              OptionInfoPtr Options;
 
5505
              ...
 
5506
          } ZZZRec, *ZZZPtr;
 
5507
 
 
5508
   o Define the list of config file Options that the driver accepts.  For
 
5509
     consistency between drivers those in the list of ``standard'' options
 
5510
     should be used where appropriate before inventing new options.
 
5511
 
 
5512
          typedef enum {
 
5513
              OPTION_FOO_HACK,
 
5514
              OPTION_PCI_RETRY,
 
5515
              OPTION_HW_CURSOR,
 
5516
              OPTION_NOACCEL
 
5517
          } ZZZOpts;
 
5518
 
 
5519
          static const OptionInfoRec ZZZOptions[] = {
 
5520
            { OPTION_FOO_HACK,  "FooHack",   OPTV_INTEGER, {0}, FALSE },
 
5521
            { OPTION_PCI_RETRY, "PciRetry",  OPTV_BOOLEAN, {0}, FALSE },
 
5522
            { OPTION_HW_CURSOR, "HWcursor",  OPTV_BOOLEAN, {0}, FALSE },
 
5523
            { OPTION_NOACCEL,   "NoAccel",   OPTV_BOOLEAN, {0}, FALSE },
 
5524
            { -1,               NULL,        OPTV_NONE,    {0}, FALSE }
 
5525
          };
 
5526
 
 
5527
20.3  Functions
 
5528
 
 
5529
20.3.1  SetupProc
 
5530
 
 
5531
For dynamically loaded modules, a ModuleData variable is required.  It is
 
5532
should be the name of the driver prepended to "ModuleData".  A Setup() func-
 
5533
tion is also required, which calls xf86AddDriver() to add the driver to the
 
5534
main list of drivers.
 
5535
 
 
5536
     #ifdef XFree86LOADER
 
5537
 
 
5538
     static MODULESETUPPROTO(mgaSetup);
 
5539
 
 
5540
     XF86ModuleData zzzModuleData = { &zzzVersRec, zzzSetup, NULL };
 
5541
 
 
5542
     static pointer
 
5543
     zzzSetup(pointer module, pointer opts, int *errmaj, int *errmin)
 
5544
     {
 
5545
         static Bool setupDone = FALSE;
 
5546
 
 
5547
         /* This module should be loaded only once, but check to be sure. */
 
5548
 
 
5549
         if (!setupDone) {
 
5550
             /*
 
5551
              * Modules that this driver always requires may be loaded
 
5552
              * here  by calling LoadSubModule().
 
5553
              */
 
5554
 
 
5555
             setupDone = TRUE;
 
5556
             xf86AddDriver(&MGA, module, 0);
 
5557
 
 
5558
             /*
 
5559
              * The return value must be non-NULL on success even though
 
5560
              * there is no TearDownProc.
 
5561
              */
 
5562
             return (pointer)1;
 
5563
         } else {
 
5564
             if (errmaj) *errmaj = LDR_ONCEONLY;
 
5565
             return NULL;
 
5566
         }
 
5567
     }
 
5568
     #endif
 
5569
 
 
5570
20.3.2  GetRec, FreeRec
 
5571
 
 
5572
A function is usually required to allocate the driver's screen-specific data
 
5573
structure and hook it into the ScrnInfoRec's driverPrivate field.  The Scrn-
 
5574
InfoRec's driverPrivate is initialised to NULL, so it is easy to check if the
 
5575
initialisation has already been done.  After allocating it, initialise the
 
5576
fields.  By using xnfcalloc() to do the allocation it is zeroed, and if the
 
5577
allocation fails the server exits.
 
5578
 
 
5579
NOTE: When allocating structures from inside the driver which are defined on
 
5580
the common level it is important to initialize the structure to zero.  Only
 
5581
this guarantees that the server remains source compatible to future changes
 
5582
in common level structures.
 
5583
 
 
5584
     static Bool
 
5585
     ZZZGetRec(ScrnInfoPtr pScrn)
 
5586
     {
 
5587
         if (pScrn->driverPrivate != NULL)
 
5588
             return TRUE;
 
5589
         pScrn->driverPrivate = xnfcalloc(sizeof(ZZZRec), 1);
 
5590
         /* Initialise as required */
 
5591
         ...
 
5592
         return TRUE;
 
5593
     }
 
5594
 
 
5595
Define a macro in "zzz.h" which gets a pointer to the ZZZRec when given
 
5596
pScrn:
 
5597
 
 
5598
     #define ZZZPTR(p) ((ZZZPtr)((p)->driverPrivate))
 
5599
 
 
5600
Define a function to free the above, setting it to NULL once it has been
 
5601
freed:
 
5602
 
 
5603
     static void
 
5604
     ZZZFreeRec(ScrnInfoPtr pScrn)
 
5605
     {
 
5606
         if (pScrn->driverPrivate == NULL)
 
5607
             return;
 
5608
         xfree(pScrn->driverPrivate);
 
5609
         pScrn->driverPrivate = NULL;
 
5610
     }
 
5611
 
 
5612
20.3.3  Identify
 
5613
 
 
5614
Define the Identify() function.  It is run before the Probe, and typically
 
5615
prints out an identifying message, which might include the chipsets it sup-
 
5616
ports.  This function is mandatory:
 
5617
 
 
5618
     static void
 
5619
     ZZZIdentify(int flags)
 
5620
     {
 
5621
         xf86PrintChipsets(ZZZ_NAME, "driver for ZZZ Tech chipsets",
 
5622
                           ZZZChipsets);
 
5623
     }
 
5624
 
 
5625
20.3.4  Probe
 
5626
 
 
5627
Define the Probe() function.  The purpose of this is to find all instances of
 
5628
the hardware that the driver supports, and for the ones not already claimed
 
5629
by another driver, claim the slot, and allocate a ScrnInfoRec.  This should
 
5630
be a minimal probe, and it should under no circumstances leave the state of
 
5631
the hardware changed.  Because a device is found, don't assume that it will
 
5632
be used.  Don't do any initialisations other than the required ScrnInfoRec
 
5633
initialisations.  Don't allocate any new data structures.
 
5634
 
 
5635
This function is mandatory.
 
5636
 
 
5637
NOTE: The xf86DrvMsg() functions cannot be used from the Probe.
 
5638
 
 
5639
     static Bool
 
5640
     ZZZProbe(DriverPtr drv, int flags)
 
5641
     {
 
5642
         Bool foundScreen = FALSE;
 
5643
         int numDevSections, numUsed;
 
5644
         GDevPtr *devSections;
 
5645
         int *usedChips;
 
5646
         int i;
 
5647
 
 
5648
         /*
 
5649
          * Find the config file Device sections that match this
 
5650
          * driver, and return if there are none.
 
5651
          */
 
5652
         if ((numDevSections = xf86MatchDevice(ZZZ_DRIVER_NAME,
 
5653
                                               &devSections)) <= 0) {
 
5654
             return FALSE;
 
5655
         }
 
5656
 
 
5657
         /*
 
5658
          * Since this is a PCI card, "probing" just amounts to checking
 
5659
          * the PCI data that the server has already collected.  If there
 
5660
          * is none, return.
 
5661
          *
 
5662
          * Although the config file is allowed to override things, it
 
5663
          * is reasonable to not allow it to override the detection
 
5664
          * of no PCI video cards.
 
5665
          *
 
5666
          * The provided xf86MatchPciInstances() helper takes care of
 
5667
          * the details.
 
5668
          */
 
5669
         /* test if PCI bus present */
 
5670
         if (xf86GetPciVideoInfo()) {
 
5671
 
 
5672
             numUsed = xf86MatchPciInstances(ZZZ_NAME, PCI_VENDOR_ZZZ,
 
5673
                                 ZZZChipsets, ZZZPciChipsets, devSections,
 
5674
                                 numDevSections, drv, &usedChips);
 
5675
 
 
5676
             for (i = 0; i < numUsed; i++) {
 
5677
                 ScrnInfoPtr pScrn = NULL;
 
5678
                 if ((pScrn = xf86ConfigPciEntity(pScrn, flags, usedChips[i],
 
5679
                                                  ZZZPciChipsets, NULL, NULL,
 
5680
                                                  NULL, NULL, NULL))) {
 
5681
                    /* Allocate a ScrnInfoRec */
 
5682
                    pScrn->driverVersion = VERSION;
 
5683
                    pScrn->driverName    = ZZZ_DRIVER_NAME;
 
5684
                    pScrn->name          = ZZZ_NAME;
 
5685
                    pScrn->Probe         = ZZZProbe;
 
5686
                    pScrn->PreInit       = ZZZPreInit;
 
5687
                    pScrn->ScreenInit    = ZZZScreenInit;
 
5688
                    pScrn->SwitchMode    = ZZZSwitchMode;
 
5689
                    pScrn->AdjustFrame   = ZZZAdjustFrame;
 
5690
                    pScrn->EnterVT       = ZZZEnterVT;
 
5691
                    pScrn->LeaveVT       = ZZZLeaveVT;
 
5692
                    pScrn->FreeScreen    = ZZZFreeScreen;
 
5693
                    pScrn->ValidMode     = ZZZValidMode;
 
5694
                    foundScreen = TRUE;
 
5695
                    /* add screen to entity */
 
5696
                }
 
5697
             }
 
5698
             xfree(usedChips);
 
5699
         }
 
5700
 
 
5701
     #ifdef HAS_ISA_DEVS
 
5702
         /*
 
5703
          * If the driver supports ISA hardware, the following block
 
5704
          * can be included too.
 
5705
          */
 
5706
         numUsed = xf86MatchIsaInstances(ZZZ_NAME, ZZZChipsets,
 
5707
                                  ZZZIsaChipsets, drv, ZZZFindIsaDevice,
 
5708
                                  devSections, numDevSections, &usedChips);
 
5709
         for (i = 0; i < numUsed; i++) {
 
5710
             ScrnInfoPtr pScrn = NULL;
 
5711
          if ((pScrn = xf86ConfigIsaEntity(pScrn, flags, usedChips[i],
 
5712
                               ZZZIsaChipsets, NULL, NULL, NULL,
 
5713
                               NULL, NULL))) {
 
5714
                 pScrn->driverVersion = VERSION;
 
5715
                 pScrn->driverName    = ZZZ_DRIVER_NAME;
 
5716
                 pScrn->name          = ZZZ_NAME;
 
5717
                 pScrn->Probe         = ZZZProbe;
 
5718
                 pScrn->PreInit       = ZZZPreInit;
 
5719
                 pScrn->ScreenInit    = ZZZScreenInit;
 
5720
                 pScrn->SwitchMode    = ZZZSwitchMode;
 
5721
                 pScrn->AdjustFrame   = ZZZAdjustFrame;
 
5722
                 pScrn->EnterVT       = ZZZEnterVT;
 
5723
                 pScrn->LeaveVT       = ZZZLeaveVT;
 
5724
                 pScrn->FreeScreen    = ZZZFreeScreen;
 
5725
                 pScrn->ValidMode     = ZZZValidMode;
 
5726
                 foundScreen = TRUE;
 
5727
             }
 
5728
         }
 
5729
         xfree(usedChips);
 
5730
     #endif /* HAS_ISA_DEVS */
 
5731
 
 
5732
         xfree(devSections);
 
5733
         return foundScreen;
 
5734
 
 
5735
20.3.5  AvailableOptions
 
5736
 
 
5737
Define the AvailableOptions() function. The purpose of this is to return the
 
5738
available driver options back to the -configure option, so that an XF86Config
 
5739
file can be built and the user can see which options are available for them
 
5740
to use.
 
5741
 
 
5742
20.3.6  PreInit
 
5743
 
 
5744
Define the PreInit() function.  The purpose of this is to find all the infor-
 
5745
mation required to determine if the configuration is usable, and to ini-
 
5746
tialise those parts of the ScrnInfoRec that can be set once at the beginning
 
5747
of the first server generation.  The information should be found in the least
 
5748
intrusive way possible.
 
5749
 
 
5750
This function is mandatory.
 
5751
 
 
5752
NOTES:
 
5753
 
 
5754
  1.  The PreInit() function is only called once during the life of the X
 
5755
      server (at the start of the first generation).
 
5756
 
 
5757
  2.  Data allocated here must be of the type that persists for the life of
 
5758
      the X server.  This means that data that hooks into the ScrnInfoRec's
 
5759
      privates field should be allocated here, but data that hooks into the
 
5760
      ScreenRec's devPrivates field should not be allocated here.  The
 
5761
      driverPrivate field should also be allocated here.
 
5762
 
 
5763
  3.  Although the ScrnInfoRec has been allocated before this function is
 
5764
      called, the ScreenRec has not been allocated.  That means that things
 
5765
      requiring it cannot be used in this function.
 
5766
 
 
5767
  4.  Very little of the ScrnInfoRec has been initialised when this function
 
5768
      is called.  It is important to get the order of doing things right in
 
5769
      this function.
 
5770
 
 
5771
     static Bool
 
5772
     ZZZPreInit(ScrnInfoPtr pScrn, int flags)
 
5773
     {
 
5774
         /* Fill in the monitor field */
 
5775
         pScrn->monitor = pScrn->confScreen->monitor;
 
5776
 
 
5777
         /*
 
5778
          * If using the vgahw module, it will typically be loaded
 
5779
          * here by calling xf86LoadSubModule(pScrn, "vgahw");
 
5780
          */
 
5781
 
 
5782
         /*
 
5783
          * Set the depth/bpp.  Our preferred default depth/bpp is 8, and
 
5784
          * we support both 24bpp and 32bpp framebuffer layouts.
 
5785
          * This sets pScrn->display also.
 
5786
          */
 
5787
         if (!xf86SetDepthBpp(pScrn, 8, 8, 8,
 
5788
                              Support24bppFb | Support32bppFb)) {
 
5789
             return FALSE;
 
5790
         } else {
 
5791
             if (depth/bpp isn't one we support) {
 
5792
                 print error message;
 
5793
                 return FALSE;
 
5794
             }
 
5795
         }
 
5796
         /* Print out the depth/bpp that was set */
 
5797
         xf86PrintDepthBpp(pScrn);
 
5798
 
 
5799
         /* Set bits per RGB for 8bpp */
 
5800
         if (pScrn->depth <= 8) {
 
5801
             /* Take into account a dac_6_bit option here */
 
5802
             pScrn->rgbBits = 6 or 8;
 
5803
         }
 
5804
 
 
5805
         /*
 
5806
          * xf86SetWeight() and xf86SetDefaultVisual() must be called
 
5807
          * after pScrn->display is initialised.
 
5808
          */
 
5809
 
 
5810
         /* Set weight/mask/offset for depth > 8 */
 
5811
         if (pScrn->depth > 8) {
 
5812
             if (!xf86SetWeight(pScrn, defaultWeight, defaultMask)) {
 
5813
                 return FALSE;
 
5814
             } else {
 
5815
                 if (weight isn't one we support) {
 
5816
                     print error message;
 
5817
                     return FALSE;
 
5818
                 }
 
5819
             }
 
5820
         }
 
5821
 
 
5822
         /* Set the default visual. */
 
5823
         if (!xf86SetDefaultVisual(pScrn, -1)) {
 
5824
             return FALSE;
 
5825
         } else {
 
5826
             if (visual isn't one we support) {
 
5827
                 print error message;
 
5828
                 return FALSE;
 
5829
             }
 
5830
         }
 
5831
 
 
5832
         /* If the driver supports gamma correction, set the gamma. */
 
5833
         if (!xf86SetGamma(pScrn, default_gamma)) {
 
5834
             return FALSE;
 
5835
         }
 
5836
 
 
5837
         /* This driver uses a programmable clock */
 
5838
         pScrn->progClock = TRUE;
 
5839
 
 
5840
         /* Allocate the ZZZRec driverPrivate */
 
5841
         if (!ZZZGetRec(pScrn)) {
 
5842
             return FALSE;
 
5843
         }
 
5844
 
 
5845
         pZzz = ZZZPTR(pScrn);
 
5846
 
 
5847
         /* Collect all of the option flags (fill in pScrn->options) */
 
5848
         xf86CollectOptions(pScrn, NULL);
 
5849
 
 
5850
         /*
 
5851
          * Process the options based on the information in ZZZOptions.
 
5852
          * The results are written to pZzz->Options.  If all of the options
 
5853
          * processing is done within this function a local variable "options"
 
5854
          * can be used instead of pZzz->Options.
 
5855
          */
 
5856
         if (!(pZzz->Options = xalloc(sizeof(ZZZOptions))))
 
5857
             return FALSE;
 
5858
         (void)memcpy(pZzz->Options, ZZZOptions, sizeof(ZZZOptions));
 
5859
         xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pZzz->Options);
 
5860
 
 
5861
         /*
 
5862
          * Set various fields of ScrnInfoRec and/or ZZZRec based on
 
5863
          * the options found.
 
5864
          */
 
5865
         from = X_DEFAULT;
 
5866
         pZzz->hwCursor = FALSE;
 
5867
         if (xf86IsOptionSet(pZzz->Options, OPTION_HW_CURSOR)) {
 
5868
             from = X_CONFIG;
 
5869
             pZzz->hwCursor = TRUE;
 
5870
         }
 
5871
         xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
 
5872
                    pZzz->hwCursor ? "HW" : "SW");
 
5873
         if (xf86IsOptionSet(pZzz->Options, OPTION_NOACCEL)) {
 
5874
             pZzz->noAccel = TRUE;
 
5875
             xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
 
5876
                        "Acceleration disabled\n");
 
5877
         } else {
 
5878
             pZzz->noAccel = FALSE;
 
5879
         }
 
5880
         if (xf86IsOptionSet(pZzz->Options, OPTION_PCI_RETRY)) {
 
5881
             pZzz->UsePCIRetry = TRUE;
 
5882
             xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "PCI retry enabled\n");
 
5883
         }
 
5884
         pZzz->fooHack = 0;
 
5885
         if (xf86GetOptValInteger(pZzz->Options, OPTION_FOO_HACK,
 
5886
                                  &pZzz->fooHack)) {
 
5887
             xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Foo Hack set to %d\n",
 
5888
                        pZzz->fooHack);
 
5889
         }
 
5890
 
 
5891
         /*
 
5892
          * Find the PCI slot(s) that this screen claimed in the probe.
 
5893
          * In this case, exactly one is expected, so complain otherwise.
 
5894
          * Note in this case we're not interested in the card types so
 
5895
          * that parameter is set to NULL.
 
5896
          */
 
5897
         if ((i = xf86GetPciInfoForScreen(pScrn->scrnIndex, &pciList, NULL))
 
5898
             != 1) {
 
5899
             print error message;
 
5900
             ZZZFreeRec(pScrn);
 
5901
             if (i > 0)
 
5902
                 xfree(pciList);
 
5903
             return FALSE;
 
5904
         }
 
5905
         /* Note that pciList should be freed below when no longer needed */
 
5906
 
 
5907
         /*
 
5908
          * Determine the chipset, allowing config file chipset and
 
5909
          * chipid values to override the probed information.  The config
 
5910
          * chipset value has precedence over its chipid value if both
 
5911
          * are present.
 
5912
          *
 
5913
          * It isn't necessary to fill in pScrn->chipset if the driver
 
5914
          * keeps track of the chipset in its ZZZRec.
 
5915
          */
 
5916
 
 
5917
         ...
 
5918
 
 
5919
         /*
 
5920
          * Determine video memory, fb base address, I/O addresses, etc,
 
5921
          * allowing the config file to override probed values.
 
5922
          *
 
5923
          * Set the appropriate pScrn fields (videoRam is probably the
 
5924
          * most important one that other code might require), and
 
5925
          * print out the settings.
 
5926
          */
 
5927
 
 
5928
         ...
 
5929
 
 
5930
         /* Initialise a clockRanges list. */
 
5931
 
 
5932
         ...
 
5933
 
 
5934
         /* Set any other chipset specific things in the ZZZRec */
 
5935
 
 
5936
         ...
 
5937
 
 
5938
         /* Select valid modes from those available */
 
5939
 
 
5940
         i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
 
5941
                               pScrn->display->modes, clockRanges,
 
5942
                               NULL, minPitch, maxPitch, rounding,
 
5943
                               minHeight, maxHeight,
 
5944
                               pScrn->display->virtualX,
 
5945
                               pScrn->display->virtualY,
 
5946
                               pScrn->videoRam * 1024,
 
5947
                               LOOKUP_BEST_REFRESH);
 
5948
         if (i == -1) {
 
5949
             ZZZFreeRec(pScrn);
 
5950
             return FALSE;
 
5951
         }
 
5952
 
 
5953
         /* Prune the modes marked as invalid */
 
5954
 
 
5955
         xf86PruneDriverModes(pScrn);
 
5956
 
 
5957
         /* If no valid modes, return */
 
5958
 
 
5959
         if (i == 0 || pScrn->modes == NULL) {
 
5960
             print error message;
 
5961
             ZZZFreeRec(pScrn);
 
5962
             return FALSE;
 
5963
         }
 
5964
 
 
5965
         /*
 
5966
          * Initialise the CRTC fields for the modes.  This driver expects
 
5967
          * vertical values to be halved for interlaced modes.
 
5968
          */
 
5969
         xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V);
 
5970
 
 
5971
         /* Set the current mode to the first in the list. */
 
5972
         pScrn->currentMode = pScrn->modes;
 
5973
 
 
5974
         /* Print the list of modes being used. */
 
5975
         xf86PrintModes(pScrn);
 
5976
 
 
5977
         /* Set the DPI */
 
5978
         xf86SetDpi(pScrn, 0, 0);
 
5979
 
 
5980
         /* Load bpp-specific modules */
 
5981
         switch (pScrn->bitsPerPixel) {
 
5982
         case 1:
 
5983
             mod = "xf1bpp";
 
5984
             break;
 
5985
         case 4:
 
5986
             mod = "xf4bpp";
 
5987
             break;
 
5988
         case 8:
 
5989
             mod = "cfb";
 
5990
             break;
 
5991
         case 16:
 
5992
             mod = "cfb16";
 
5993
             break;
 
5994
         case 24:
 
5995
             mod = "cfb24";
 
5996
             break;
 
5997
         case 32:
 
5998
             mod = "cfb32";
 
5999
             break;
 
6000
         }
 
6001
         if (mod && !xf86LoadSubModule(pScrn, mod))
 
6002
             ZZZFreeRec(pScrn);
 
6003
             return FALSE;
 
6004
 
 
6005
         /* Load XAA if needed */
 
6006
         if (!pZzz->noAccel || pZzz->hwCursor)
 
6007
             if (!xf86LoadSubModule(pScrn, "xaa")) {
 
6008
                 ZZZFreeRec(pScrn);
 
6009
                 return FALSE;
 
6010
             }
 
6011
 
 
6012
         /* Done */
 
6013
         return TRUE;
 
6014
     }
 
6015
 
 
6016
20.3.7  MapMem, UnmapMem
 
6017
 
 
6018
Define functions to map and unmap the video memory and any other memory aper-
 
6019
tures required.  These functions are not mandatory, but it is often useful to
 
6020
have such functions.
 
6021
 
 
6022
     static Bool
 
6023
     ZZZMapMem(ScrnInfoPtr pScrn)
 
6024
     {
 
6025
         /* Call xf86MapPciMem() to map each PCI memory area */
 
6026
         ...
 
6027
         return TRUE or FALSE;
 
6028
     }
 
6029
 
 
6030
     static Bool
 
6031
     ZZZUnmapMem(ScrnInfoPtr pScrn)
 
6032
     {
 
6033
         /* Call xf86UnMapVidMem() to unmap each memory area */
 
6034
         ...
 
6035
         return TRUE or FALSE;
 
6036
     }
 
6037
 
 
6038
20.3.8  Save, Restore
 
6039
 
 
6040
Define functions to save and restore the original video state.  These func-
 
6041
tions are not mandatory, but are often useful.
 
6042
 
 
6043
     static void
 
6044
     ZZZSave(ScrnInfoPtr pScrn)
 
6045
     {
 
6046
         /*
 
6047
          * Save state into per-screen data structures.
 
6048
          * If using the vgahw module, vgaHWSave will typically be
 
6049
          * called here.
 
6050
          */
 
6051
         ...
 
6052
     }
 
6053
 
 
6054
     static void
 
6055
     ZZZRestore(ScrnInfoPtr pScrn)
 
6056
     {
 
6057
         /*
 
6058
          * Restore state from per-screen data structures.
 
6059
          * If using the vgahw module, vgaHWRestore will typically be
 
6060
          * called here.
 
6061
          */
 
6062
         ...
 
6063
     }
 
6064
 
 
6065
20.3.9  ModeInit
 
6066
 
 
6067
Define a function to initialise a new video mode.  This function isn't manda-
 
6068
tory, but is often useful.
 
6069
 
 
6070
     static Bool
 
6071
     ZZZModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
 
6072
     {
 
6073
         /*
 
6074
          * Program a video mode.  If using the vgahw module,
 
6075
          * vgaHWInit and vgaRestore will typically be called here.
 
6076
          * Once up to the point where there can't be a failure
 
6077
          * set pScrn->vtSema to TRUE.
 
6078
          */
 
6079
         ...
 
6080
     }
 
6081
 
 
6082
20.3.10  ScreenInit
 
6083
 
 
6084
Define the ScreenInit() function.  This is called at the start of each server
 
6085
generation, and should fill in as much of the ScreenRec as possible as well
 
6086
as any other data that is initialised once per generation.  It should ini-
 
6087
tialise the framebuffer layers it is using, and initialise the initial video
 
6088
mode.
 
6089
 
 
6090
This function is mandatory.
 
6091
 
 
6092
NOTE: The ScreenRec (pScreen) is passed to this driver, but it and the Scrn-
 
6093
InfoRecs are not yet hooked into each other.  This means that in this func-
 
6094
tion, and functions it calls, one cannot be found from the other.
 
6095
 
 
6096
     static Bool
 
6097
     ZZZScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
6098
     {
 
6099
         /* Get the ScrnInfoRec */
 
6100
         pScrn = xf86Screens[pScreen->myNum];
 
6101
 
 
6102
         /*
 
6103
          * If using the vgahw module, its data structures and related
 
6104
          * things are typically initialised/mapped here.
 
6105
          */
 
6106
 
 
6107
         /* Save the current video state */
 
6108
         ZZZSave(pScrn);
 
6109
 
 
6110
         /* Initialise the first mode */
 
6111
         ZZZModeInit(pScrn, pScrn->currentMode);
 
6112
 
 
6113
         /* Set the viewport if supported */
 
6114
 
 
6115
         ZZZAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
6116
 
 
6117
         /*
 
6118
          * Setup the screen's visuals, and initialise the framebuffer
 
6119
          * code.
 
6120
          */
 
6121
 
 
6122
         /* Reset the visual list */
 
6123
         miClearVisualTypes();
 
6124
 
 
6125
         /*
 
6126
          * Setup the visuals supported.  This driver only supports
 
6127
          * TrueColor for bpp > 8, so the default set of visuals isn't
 
6128
          * acceptable.  To deal with this, call miSetVisualTypes with
 
6129
          * the appropriate visual mask.
 
6130
          */
 
6131
 
 
6132
         if (pScrn->bitsPerPixel > 8) {
 
6133
             if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
 
6134
                                   pScrn->rgbBits, pScrn->defaultVisual))
 
6135
                 return FALSE;
 
6136
         } else {
 
6137
             if (!miSetVisualTypes(pScrn->depth,
 
6138
                                   miGetDefaultVisualMask(pScrn->depth),
 
6139
                                   pScrn->rgbBits, pScrn->defaultVisual))
 
6140
                 return FALSE;
 
6141
         }
 
6142
 
 
6143
         /*
 
6144
          * Initialise the framebuffer.
 
6145
          */
 
6146
 
 
6147
         switch (pScrn->bitsPerPixel) {
 
6148
         case 1:
 
6149
             ret = xf1bppScreenInit(pScreen, FbBase,
 
6150
                                    pScrn->virtualX, pScrn->virtualY,
 
6151
                                    pScrn->xDpi, pScrn->yDpi,
 
6152
                                    pScrn->displayWidth);
 
6153
             break;
 
6154
         case 4:
 
6155
             ret = xf4bppScreenInit(pScreen, FbBase,
 
6156
                                    pScrn->virtualX, pScrn->virtualY,
 
6157
                                    pScrn->xDpi, pScrn->yDpi,
 
6158
                                    pScrn->displayWidth);
 
6159
             break;
 
6160
         case 8:
 
6161
             ret = cfbScreenInit(pScreen, FbBase,
 
6162
                                 pScrn->virtualX, pScrn->virtualY,
 
6163
                                 pScrn->xDpi, pScrn->yDpi,
 
6164
                                 pScrn->displayWidth);
 
6165
             break;
 
6166
         case 16:
 
6167
             ret = cfb16ScreenInit(pScreen, FbBase,
 
6168
                                   pScrn->virtualX, pScrn->virtualY,
 
6169
                                   pScrn->xDpi, pScrn->yDpi,
 
6170
                                   pScrn->displayWidth);
 
6171
             break;
 
6172
         case 24:
 
6173
             ret = cfb24ScreenInit(pScreen, FbBase,
 
6174
                                   pScrn->virtualX, pScrn->virtualY,
 
6175
                                   pScrn->xDpi, pScrn->yDpi,
 
6176
                                   pScrn->displayWidth);
 
6177
             break;
 
6178
         case 32:
 
6179
             ret = cfb32ScreenInit(pScreen, FbBase,
 
6180
                                   pScrn->virtualX, pScrn->virtualY,
 
6181
                                   pScrn->xDpi, pScrn->yDpi,
 
6182
                                   pScrn->displayWidth);
 
6183
             break;
 
6184
         default:
 
6185
             print a message about an internal error;
 
6186
             ret = FALSE;
 
6187
             break;
 
6188
         }
 
6189
 
 
6190
         if (!ret)
 
6191
             return FALSE;
 
6192
 
 
6193
         /* Override the default mask/offset settings */
 
6194
         if (pScrn->bitsPerPixel > 8) {
 
6195
             for (i = 0, visual = pScreen->visuals;
 
6196
                  i < pScreen->numVisuals; i++, visual++) {
 
6197
                 if ((visual->class | DynamicClass) == DirectColor) {
 
6198
                     visual->offsetRed = pScrn->offset.red;
 
6199
                     visual->offsetGreen = pScrn->offset.green;
 
6200
                     visual->offsetBlue = pScrn->offset.blue;
 
6201
                     visual->redMask = pScrn->mask.red;
 
6202
                     visual->greenMask = pScrn->mask.green;
 
6203
                     visual->blueMask = pScrn->mask.blue;
 
6204
                 }
 
6205
             }
 
6206
         }
 
6207
 
 
6208
         /*
 
6209
          * If banking is needed, initialise an miBankInfoRec (defined in
 
6210
          * "mibank.h"), and call miInitializeBanking().
 
6211
          */
 
6212
         if (!miInitializeBanking(pScreen, pScrn->virtualX, pScrn->virtualY,
 
6213
                                          pScrn->displayWidth, pBankInfo))
 
6214
             return FALSE;
 
6215
 
 
6216
         /*
 
6217
          * If backing store is to be supported (as is usually the case),
 
6218
          * initialise it.
 
6219
          */
 
6220
         miInitializeBackingStore(pScreen);
 
6221
 
 
6222
         /*
 
6223
          * Set initial black & white colourmap indices.
 
6224
          */
 
6225
         xf86SetBlackWhitePixels(pScreen);
 
6226
 
 
6227
         /*
 
6228
          * Install colourmap functions.  If using the vgahw module,
 
6229
          * vgaHandleColormaps would usually be called here.
 
6230
          */
 
6231
 
 
6232
         ...
 
6233
 
 
6234
         /*
 
6235
          * Initialise cursor functions.  This example is for the mi
 
6236
          * software cursor.
 
6237
          */
 
6238
         miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
6239
 
 
6240
         /* Initialise the default colourmap */
 
6241
         switch (pScrn->depth) {
 
6242
         case 1:
 
6243
             if (!xf1bppCreateDefColormap(pScreen))
 
6244
                 return FALSE;
 
6245
             break;
 
6246
         case 4:
 
6247
             if (!xf4bppCreateDefColormap(pScreen))
 
6248
                 return FALSE;
 
6249
             break;
 
6250
         default:
 
6251
             if (!cfbCreateDefColormap(pScreen))
 
6252
                 return FALSE;
 
6253
             break;
 
6254
         }
 
6255
 
 
6256
         /*
 
6257
          * Wrap the CloseScreen vector and set SaveScreen.
 
6258
          */
 
6259
         ZZZPTR(pScrn)->CloseScreen = pScreen->CloseScreen;
 
6260
         pScreen->CloseScreen = ZZZCloseScreen;
 
6261
         pScreen->SaveScreen = ZZZSaveScreen;
 
6262
 
 
6263
         /* Report any unused options (only for the first generation) */
 
6264
         if (serverGeneration == 1) {
 
6265
             xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
6266
         }
 
6267
 
 
6268
         /* Done */
 
6269
         return TRUE;
 
6270
     }
 
6271
 
 
6272
20.3.11  SwitchMode
 
6273
 
 
6274
Define the SwitchMode() function if mode switching is supported by the
 
6275
driver.
 
6276
 
 
6277
     static Bool
 
6278
     ZZZSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
 
6279
     {
 
6280
         return ZZZModeInit(xf86Screens[scrnIndex], mode);
 
6281
     }
 
6282
 
 
6283
20.3.12  AdjustFrame
 
6284
 
 
6285
Define the AdjustFrame() function if the driver supports this.
 
6286
 
 
6287
     static void
 
6288
     ZZZAdjustFrame(int scrnIndex, int x, int y, int flags)
 
6289
     {
 
6290
         /* Adjust the viewport */
 
6291
     }
 
6292
 
 
6293
20.3.13  EnterVT, LeaveVT
 
6294
 
 
6295
Define the EnterVT() and LeaveVT() functions.
 
6296
 
 
6297
These functions are mandatory.
 
6298
 
 
6299
     static Bool
 
6300
     ZZZEnterVT(int scrnIndex, int flags)
 
6301
     {
 
6302
         ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 
6303
         return ZZZModeInit(pScrn, pScrn->currentMode);
 
6304
     }
 
6305
 
 
6306
     static void
 
6307
     ZZZLeaveVT(int scrnIndex, int flags)
 
6308
     {
 
6309
         ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 
6310
         ZZZRestore(pScrn);
 
6311
     }
 
6312
 
 
6313
20.3.14  CloseScreen
 
6314
 
 
6315
Define the CloseScreen() function:
 
6316
 
 
6317
This function is mandatory.  Note that it unwraps the previously wrapped
 
6318
pScreen->CloseScreen, and finishes by calling it.
 
6319
 
 
6320
     static Bool
 
6321
     ZZZCloseScreen(int scrnIndex, ScreenPtr pScreen)
 
6322
     {
 
6323
         ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 
6324
         if (pScrn->vtSema) {
 
6325
             ZZZRestore(pScrn);
 
6326
             ZZZUnmapMem(pScrn);
 
6327
         }
 
6328
         pScrn->vtSema = FALSE;
 
6329
         pScreen->CloseScreen = ZZZPTR(pScrn)->CloseScreen;
 
6330
         return (*pScreen->CloseScreen)(scrnIndex, pScreen);
 
6331
     }
 
6332
 
 
6333
20.3.15  SaveScreen
 
6334
 
 
6335
Define the SaveScreen() function (the screen blanking function).  When using
 
6336
the vgahw module, this will typically be:
 
6337
 
 
6338
     static Bool
 
6339
     ZZZSaveScreen(ScreenPtr pScreen, int mode)
 
6340
     {
 
6341
         return vgaHWSaveScreen(pScreen, mode);
 
6342
     }
 
6343
 
 
6344
This function is mandatory.  Before modifying any hardware register directly
 
6345
this function needs to make sure that the Xserver is active by checking if
 
6346
pScrn is non-NULL and for pScrn->vtSema == TRUE.
 
6347
 
 
6348
20.3.16  FreeScreen
 
6349
 
 
6350
Define the FreeScreen() function.  This function is optional.  It should be
 
6351
defined if the ScrnInfoRec driverPrivate field is used so that it can be
 
6352
freed when a screen is deleted by the common layer for reasons possibly
 
6353
beyond the driver's control.  This function is not used in during normal
 
6354
(error free) operation.  The per-generation data is freed by the Clos-
 
6355
eScreen() function.
 
6356
 
 
6357
     static void
 
6358
     ZZZFreeScreen(int scrnIndex, int flags)
 
6359
     {
 
6360
         /*
 
6361
          * If the vgahw module is used vgaHWFreeHWRec() would be called
 
6362
          * here.
 
6363
          */
 
6364
         ZZZFreeRec(xf86Screens[scrnIndex]);
 
6365
     }
 
6366
 
 
6367
     Generated from XFree86: xc/programs/Xserver/hw/xfree86/doc/sgml/DESIGN.sgml,v 1.52 2003/02/25 19:31:00 dawes Exp $
 
6368
 
 
6369
 
 
6370
$XFree86: xc/programs/Xserver/hw/xfree86/doc/DESIGN,v 1.47 2003/02/25 21:32:33 dawes Exp $