home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 August - Disc 2 / chip_20018102_hu.iso / linux / X-4.1.0 / doc / design < prev    next >
Text File  |  2001-06-27  |  244KB  |  6,340 lines

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