home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 45 / cda45.iso / Linux / XFree86-4.0 / doc / DESIGN < prev    next >
Encoding:
Text File  |  2000-03-09  |  234.8 KB  |  6,258 lines

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